Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/flat-teams-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': patch
'@clerk/backend': patch
'@clerk/types': patch
---

Add `enterpriseConnectionId` to `SamlAccount` and `EnterpriseAccount` resources
1 change: 1 addition & 0 deletions packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export interface SamlAccountJSON extends ClerkResourceJSON {
verification: VerificationJSON | null;
saml_connection: SamlAccountConnectionJSON | null;
last_authenticated_at: number | null;
enterprise_connection_id: string | null;
}

export interface IdentificationLinkJSON extends ClerkResourceJSON {
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/api/resources/SamlAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class SamlAccount {
* The date when the SAML account was last authenticated.
*/
readonly lastAuthenticatedAt: number | null,
/**
* The ID of the enterprise connection associated with this SAML account.
*/
readonly enterpriseConnectionId: string | null,
) {}

static fromJSON(data: SamlAccountJSON): SamlAccount {
Expand All @@ -61,6 +65,7 @@ export class SamlAccount {
data.verification && Verification.fromJSON(data.verification),
data.saml_connection && SamlAccountConnection.fromJSON(data.saml_connection),
data.last_authenticated_at ?? null,
data.enterprise_connection_id,
Comment on lines 63 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add nullish coalescing for type safety and consistency.

Line 68 is missing the nullish coalescing operator (?? null) that's used on line 67 for lastAuthenticatedAt. If data.enterprise_connection_id is undefined, it will pass undefined to the constructor, but the type signature expects string | null. This creates a type safety gap and inconsistency with the established pattern.

Apply this diff to fix the inconsistency:

     data.verification && Verification.fromJSON(data.verification),
     data.saml_connection && SamlAccountConnection.fromJSON(data.saml_connection),
     data.last_authenticated_at ?? null,
-    data.enterprise_connection_id,
+    data.enterprise_connection_id ?? null,
   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
data.last_authenticated_at ?? null,
data.enterprise_connection_id,
data.verification && Verification.fromJSON(data.verification),
data.saml_connection && SamlAccountConnection.fromJSON(data.saml_connection),
data.last_authenticated_at ?? null,
data.enterprise_connection_id ?? null,
);
🤖 Prompt for AI Agents
In packages/backend/src/api/resources/SamlAccount.ts around lines 67 to 68, the
constructor argument for enterprise_connection_id is missing nullish coalescing;
change the value passed from data.enterprise_connection_id to
data.enterprise_connection_id ?? null so it matches the pattern used for
last_authenticated_at and ensures the constructor receives string | null rather
than possibly undefined.

);
}
}
6 changes: 6 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class EnterpriseAccount extends BaseResource implements EnterpriseAccount
verification: VerificationResource | null = null;
enterpriseConnection: EnterpriseAccountConnectionResource | null = null;
lastAuthenticatedAt: Date | null = null;
enterpriseConnectionId: string | null = null;

public constructor(data: Partial<EnterpriseAccountJSON | EnterpriseAccountJSONSnapshot>, pathRoot: string);
public constructor(data: EnterpriseAccountJSON | EnterpriseAccountJSONSnapshot, pathRoot: string) {
Expand All @@ -48,6 +49,7 @@ export class EnterpriseAccount extends BaseResource implements EnterpriseAccount
this.lastName = data.last_name;
this.publicMetadata = data.public_metadata;
this.lastAuthenticatedAt = data.last_authenticated_at ? unixEpochToDate(data.last_authenticated_at) : null;
this.enterpriseConnectionId = data.enterprise_connection_id;
if (data.verification) {
this.verification = new Verification(data.verification);
}
Expand All @@ -74,6 +76,7 @@ export class EnterpriseAccount extends BaseResource implements EnterpriseAccount
verification: this.verification?.__internal_toSnapshot() || null,
enterprise_connection: this.enterpriseConnection?.__internal_toSnapshot() || null,
last_authenticated_at: this.lastAuthenticatedAt ? this.lastAuthenticatedAt.getTime() : null,
enterprise_connection_id: this.enterpriseConnectionId,
};
}
}
Expand All @@ -92,6 +95,7 @@ export class EnterpriseAccountConnection extends BaseResource implements Enterpr
syncUserAttributes!: boolean;
createdAt!: Date;
updatedAt!: Date;
enterpriseConnectionId: string | null = '';

constructor(data: EnterpriseAccountConnectionJSON | EnterpriseAccountConnectionJSONSnapshot | null) {
super();
Expand All @@ -112,6 +116,7 @@ export class EnterpriseAccountConnection extends BaseResource implements Enterpr
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);
this.enterpriseConnectionId = data.enterprise_connection_id;
}

return this;
Expand All @@ -131,6 +136,7 @@ export class EnterpriseAccountConnection extends BaseResource implements Enterpr
allow_subdomains: this.allowSubdomains,
allow_idp_initiated: this.allowIdpInitiated,
disable_additional_identifications: this.disableAdditionalIdentifications,
enterprise_connection_id: this.enterpriseConnectionId,
created_at: this.createdAt.getTime(),
updated_at: this.updatedAt.getTime(),
};
Expand Down
3 changes: 3 additions & 0 deletions packages/clerk-js/src/core/resources/SamlAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class SamlAccount extends BaseResource implements SamlAccountResource {
verification: VerificationResource | null = null;
samlConnection: SamlAccountConnectionResource | null = null;
lastAuthenticatedAt: Date | null = null;
enterpriseConnectionId: string | null = null;

public constructor(data: Partial<SamlAccountJSON | SamlAccountJSONSnapshot>, pathRoot: string);
public constructor(data: SamlAccountJSON | SamlAccountJSONSnapshot, pathRoot: string) {
Expand All @@ -44,6 +45,7 @@ export class SamlAccount extends BaseResource implements SamlAccountResource {
this.emailAddress = data.email_address;
this.firstName = data.first_name;
this.lastName = data.last_name;
this.enterpriseConnectionId = data.enterprise_connection_id;

if (data.verification) {
this.verification = new Verification(data.verification);
Expand All @@ -70,6 +72,7 @@ export class SamlAccount extends BaseResource implements SamlAccountResource {
last_name: this.lastName,
verification: this.verification?.__internal_toSnapshot() || null,
saml_connection: this.samlConnection?.__internal_toSnapshot(),
enterprise_connection_id: this.enterpriseConnectionId,
last_authenticated_at: this.lastAuthenticatedAt ? this.lastAuthenticatedAt.getTime() : null,
};
}
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/enterpriseAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export interface EnterpriseAccountResource extends ClerkResource {
active: boolean;
emailAddress: string;
enterpriseConnection: EnterpriseAccountConnectionResource | null;
enterpriseConnectionId: string | null;
firstName: string | null;
lastName: string | null;
protocol: EnterpriseProtocol;
provider: EnterpriseProvider;
providerUserId: string | null;
publicMetadata: Record<string, unknown> | null;
verification: VerificationResource | null;
lastAuthenticatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseAccountJSONSnapshot;
}

Expand All @@ -33,5 +35,6 @@ export interface EnterpriseAccountConnectionResource extends ClerkResource {
protocol: EnterpriseProtocol;
provider: EnterpriseProvider;
syncUserAttributes: boolean;
enterpriseConnectionId: string | null;
__internal_toSnapshot: () => EnterpriseAccountConnectionJSONSnapshot;
}
3 changes: 3 additions & 0 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export interface EnterpriseAccountJSON extends ClerkResourceJSON {
public_metadata: Record<string, unknown>;
verification: VerificationJSON | null;
last_authenticated_at: number | null;
enterprise_connection_id: string | null;
}

export interface EnterpriseAccountConnectionJSON extends ClerkResourceJSON {
Expand All @@ -268,6 +269,7 @@ export interface EnterpriseAccountConnectionJSON extends ClerkResourceJSON {
sync_user_attributes: boolean;
created_at: number;
updated_at: number;
enterprise_connection_id: string | null;
}

export interface SamlAccountJSON extends ClerkResourceJSON {
Expand All @@ -281,6 +283,7 @@ export interface SamlAccountJSON extends ClerkResourceJSON {
verification?: VerificationJSON;
saml_connection?: SamlAccountConnectionJSON;
last_authenticated_at: number | null;
enterprise_connection_id: string | null;
}

export interface UserJSON extends ClerkResourceJSON {
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/samlAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ export interface SamlAccountResource extends ClerkResource {
lastName: string;
verification: VerificationResource | null;
samlConnection: SamlAccountConnectionResource | null;
lastAuthenticatedAt: Date | null;
enterpriseConnectionId: string | null;
__internal_toSnapshot: () => SamlAccountJSONSnapshot;
}
Loading