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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
9 changes: 9 additions & 0 deletions .changeset/humble-trams-laugh.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Add `EnterpriseConnection` resource

`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`
8 changes: 4 additions & 4 deletions packages/clerk-js/bundlewatch.config.json
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Expand Down
141 changes: 141 additions & 0 deletions packages/clerk-js/src/core/resources/EnterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
import type {
EnterpriseConnectionJSON,
EnterpriseConnectionJSONSnapshot,
EnterpriseConnectionResource,
EnterpriseOAuthConfigJSON,
EnterpriseOAuthConfigResource,
EnterpriseSamlConnectionNestedJSON,
EnterpriseSamlConnectionNestedResource,
} from '@clerk/shared/types';

import { unixEpochToDate } from '../../utils/date';
import { BaseResource } from './Base';

function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
return {
id: data.id,
name: data.name,
active: data.active,
idpEntityId: data.idp_entity_id,
idpSsoUrl: data.idp_sso_url,
idpCertificate: data.idp_certificate,
idpMetadataUrl: data.idp_metadata_url,
idpMetadata: data.idp_metadata,
acsUrl: data.acs_url,
spEntityId: data.sp_entity_id,
spMetadataUrl: data.sp_metadata_url,
allowSubdomains: data.allow_subdomains,
allowIdpInitiated: data.allow_idp_initiated,
forceAuthn: data.force_authn,
};
}

function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
return {
id: data.id,
name: data.name,
active: data.active,
idp_entity_id: data.idpEntityId,
idp_sso_url: data.idpSsoUrl,
idp_certificate: data.idpCertificate,
idp_metadata_url: data.idpMetadataUrl,
idp_metadata: data.idpMetadata,
acs_url: data.acsUrl,
sp_entity_id: data.spEntityId,
sp_metadata_url: data.spMetadataUrl,
allow_subdomains: data.allowSubdomains,
allow_idp_initiated: data.allowIdpInitiated,
force_authn: data.forceAuthn,
};
}

function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
return {
id: data.id,
name: data.name,
clientId: data.client_id,
providerKey: data.provider_key,
discoveryUrl: data.discovery_url,
logoPublicUrl: data.logo_public_url,
requiresPkce: data.requires_pkce,
createdAt: unixEpochToDate(data.created_at),
updatedAt: unixEpochToDate(data.updated_at),
};
}

function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
return {
id: data.id,
name: data.name,
client_id: data.clientId,
provider_key: data.providerKey,
discovery_url: data.discoveryUrl,
logo_public_url: data.logoPublicUrl,
requires_pkce: data.requiresPkce,
created_at: data.createdAt?.getTime() ?? 0,
updated_at: data.updatedAt?.getTime() ?? 0,
};
}

export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
id!: string;
name!: string;
active!: boolean;
domains: string[] = [];
organizationId: string | null = null;
syncUserAttributes!: boolean;
disableAdditionalIdentifications!: boolean;
allowOrganizationAccountLinking!: boolean;
customAttributes: unknown[] = [];
oauthConfig: EnterpriseOAuthConfigResource | null = null;
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
createdAt: Date | null = null;
updatedAt: Date | null = null;

constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
if (!data) {
return this;
}

this.id = data.id;
this.name = data.name;
this.active = data.active;
this.domains = data.domains ?? [];
this.organizationId = data.organization_id ?? null;
this.syncUserAttributes = data.sync_user_attributes;
this.disableAdditionalIdentifications = data.disable_additional_identifications;
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
this.customAttributes = data.custom_attributes ?? [];
this.createdAt = unixEpochToDate(data.created_at);
this.updatedAt = unixEpochToDate(data.updated_at);

this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;

return this;
}

public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
return {
object: 'enterprise_connection',
id: this.id,
name: this.name,
active: this.active,
domains: this.domains,
organization_id: this.organizationId,
sync_user_attributes: this.syncUserAttributes,
disable_additional_identifications: this.disableAdditionalIdentifications,
allow_organization_account_linking: this.allowOrganizationAccountLinking,
custom_attributes: this.customAttributes,
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
created_at: this.createdAt?.getTime() ?? 0,
updated_at: this.updatedAt?.getTime() ?? 0,
};
}
}
12 changes: 6 additions & 6 deletions packages/clerk-js/src/core/resources/User.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,9 +9,9 @@ import type {
DeletedObjectJSON,
DeletedObjectResource,
EmailAddressResource,
EnterpriseAccountConnectionJSON,
EnterpriseAccountConnectionResource,
EnterpriseAccountResource,
EnterpriseConnectionJSON,
EnterpriseConnectionResource,
ExternalAccountJSON,
ExternalAccountResource,
GetEnterpriseConnectionsParams,
Expand DownExpand Up@@ -45,7 +45,7 @@ import {
DeletedObject,
EmailAddress,
EnterpriseAccount,
EnterpriseAccountConnection,
EnterpriseConnection,
ExternalAccount,
Image,
OrganizationMembership,
Expand DownExpand Up@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {

getEnterpriseConnections = async (
params?: GetEnterpriseConnectionsParams,
): Promise<EnterpriseAccountConnectionResource[]> => {
): Promise<EnterpriseConnectionResource[]> => {
const { withOrganizationAccountLinking } = params || {};

const json = (
Expand All@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
}
: {}),
})
)?.response as unknown as EnterpriseAccountConnectionJSON[];
)?.response as unknown as EnterpriseConnectionJSON[];

return (json || []).map(connection => new EnterpriseAccountConnection(connection));
return (json || []).map(connection => new EnterpriseConnection(connection));
Comment on lines +314 to +316

@coderabbitaicoderabbitaiBotMar 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash# Check test file for enterprise connection mock data
rg -n -A 30 'enterprise.*connection.*JSON' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# First, let's look at the test file to find enterprise connection related tests
rg -n -B 2 -A 20 'getEnterpriseConnections' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 806


🏁 Script executed:

# Find the EnterpriseConnectionJSON type definition
rg -n -B 2 -A 10 'interface EnterpriseConnectionJSON\|type EnterpriseConnectionJSON' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Also check what EnterpriseConnection class looks like
rg -n -B 2 -A 15 'class EnterpriseConnection\|export class EnterpriseConnection' packages/clerk-js/src/

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Look at the test setup before line 112 to see the mock data
sed -n '80,115p' packages/clerk-js/src/core/resources/__tests__/User.test.ts

Repository: clerk/javascript

Length of output: 1095


🏁 Script executed:

# Search for enterprise connection related types more broadly
rg -n 'EnterpriseConnectionJSON\|enterprise_connection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 42


🏁 Script executed:

# Search for EnterpriseConnection references in the codebase
rg -n 'class EnterpriseConnection' packages/clerk-js/src/ -t ts

Repository: clerk/javascript

Length of output: 220


🏁 Script executed:

# Find EnterpriseConnectionJSON type definition
fd -t f EnterpriseConnection.ts packages/clerk-js/src/ --exec head -150 {} \;

Repository: clerk/javascript

Length of output: 4987


🏁 Script executed:

# Search for EnterpriseConnectionJSON in type files
rg -n 'EnterpriseConnectionJSON' packages/clerk-js/src/ -t ts -B 2 -A 10

Repository: clerk/javascript

Length of output: 9696


Update test mock data to match the new EnterpriseConnectionJSON schema.

The test at packages/clerk-js/src/core/resources/__tests__/User.test.ts uses stale mock data with the old API structure. The mock includes fields like domain (string), protocol, and provider that don't exist in the new EnterpriseConnectionJSON type, which expects domains (array), saml_connection, and oauth_config objects instead.

The test currently passes by coincidence because the EnterpriseConnection.fromJSON() implementation provides defaults for optional fields (domains ?? []), but the mock should be updated to reflect the actual API response structure to properly validate the new code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/clerk-js/src/core/resources/User.ts` around lines 314 - 316, Update
the mock response in the test at User.test.ts so it matches the new
EnterpriseConnectionJSON schema: replace any single "domain" string with
"domains" as an array (e.g. domains: []), remove obsolete fields like "protocol"
and "provider", and add the new nested objects "saml_connection" and/or
"oauth_config" (or minimal empty objects) as expected by
EnterpriseConnection.fromJSON/EnterpriseConnectionJSON; ensure the test mock
objects mirror the real API shape so the code paths in
EnterpriseConnection.fromJSON and the mapping in User (where it casts to
EnterpriseConnectionJSON[] and constructs new EnterpriseConnection(connection))
exercise the correct schema.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Missed this one, will raise a follow up PR to fix it alongside adding provider and logo_public_url properties to EnterpriseConnection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LauraBeatris, sounds good! Would you like me to open a GitHub issue to track these follow-up items:

  1. Update the User.test.ts mock data to match the new EnterpriseConnectionJSON schema (replace domain with domains: [], remove obsolete protocol/provider fields, add saml_connection/oauth_config nested objects).
  2. Add provider and logo_public_url properties to the EnterpriseConnection resource and its associated types.

🧠 Learnings used
Learnt from: wobsoriano
Repo: clerk/javascript PR: 7883
File: packages/backend/src/api/__tests__/M2MTokenApi.test.ts:414-419
Timestamp: 2026-02-24T18:03:27.067Z
Learning: In TypeScript files within the clerk/javascript repository, enforce explicit return type annotations for exported functions and public APIs, but allow internal test helper functions without explicit return types. This helps maintain API clarity and type safety for consumers while not burdening test helpers that are not part of the public surface.

};

initializePaymentMethod: typeof initializePaymentMethod = params => {
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/internal.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export * from './DeletedObject';
export * from './DisplayConfig';
export * from './EmailAddress';
export * from './EnterpriseAccount';
export * from './EnterpriseConnection';
export * from './Environment';
export * from './ExternalAccount';
export * from './Feature';
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
import { useClerkQuery } from '../clerk-rq/useQuery';
import { useClerkInstanceContext } from '../contexts';
Expand All@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
};

export type UseUserEnterpriseConnectionsReturn = {
data: EnterpriseAccountConnectionResource[] | undefined;
data: EnterpriseConnectionResource[] | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this count as a breaking change? Not saying we need to since this is just a TypeScript type change, but the change in type here seems significant enough to justify calling it out in the changelog. I assume the API has been returning something of the shape EnterpriseConnectionResource so at runtime I doubt this would break anything functional, but I can imagine this causing a TypeScript error if someone was previously using the EnterpriceAccountConnectionResource type.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We haven't released user.getEnterpriseConnections yet in production, so I expect no breaking changes on existing apps

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll clarify that type change behavior on the changelog as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated on 5e62ce7

error: Error | null;
isLoading: boolean;
isFetching: boolean;
Expand Down
95 changes: 95 additions & 0 deletions packages/shared/src/types/enterpriseConnection.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
object: 'enterprise_connection';
name: string;
active: boolean;
domains?: string[];
organization_id?: string | null;
sync_user_attributes: boolean;
disable_additional_identifications: boolean;
allow_organization_account_linking?: boolean;
custom_attributes?: unknown[];
oauth_config?: EnterpriseOAuthConfigJSON | null;
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
created_at: number;
updated_at: number;
}

export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;

export interface EnterpriseConnectionResource extends ClerkResource {
id: string;
name: string;
active: boolean;
domains: string[];
organizationId: string | null;
syncUserAttributes: boolean;
disableAdditionalIdentifications: boolean;
allowOrganizationAccountLinking: boolean;
customAttributes: unknown[];
oauthConfig: EnterpriseOAuthConfigResource | null;
samlConnection: EnterpriseSamlConnectionNestedResource | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
}

export interface EnterpriseSamlConnectionNestedJSON {
id: string;
name: string;
active: boolean;
idp_entity_id: string;
idp_sso_url: string;
idp_certificate: string;
idp_metadata_url: string;
idp_metadata: string;
acs_url: string;
sp_entity_id: string;
sp_metadata_url: string;
allow_subdomains: boolean;
allow_idp_initiated: boolean;
force_authn: boolean;
}

export interface EnterpriseSamlConnectionNestedResource {
id: string;
name: string;
active: boolean;
idpEntityId: string;
idpSsoUrl: string;
idpCertificate: string;
idpMetadataUrl: string;
idpMetadata: string;
acsUrl: string;
spEntityId: string;
spMetadataUrl: string;
allowSubdomains: boolean;
allowIdpInitiated: boolean;
forceAuthn: boolean;
}

export interface EnterpriseOAuthConfigJSON {
id: string;
name: string;
provider_key?: string;
client_id: string;
discovery_url?: string;
logo_public_url?: string | null;
requires_pkce?: boolean;
created_at: number;
updated_at: number;
}

export interface EnterpriseOAuthConfigResource {
id: string;
name: string;
clientId: string;
providerKey?: string;
discoveryUrl?: string;
logoPublicUrl?: string | null;
requiresPkce?: boolean;
createdAt: Date | null;
updatedAt: Date | null;
}
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './enterpriseConnection';
export type * from './environment';
export type * from './errors';
export type * from './externalAccount';
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/types/user.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
import type { BillingPayerMethods } from './billing';
import type { DeletedObjectResource } from './deletedObject';
import type { EmailAddressResource } from './emailAddress';
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseAccountResource } from './enterpriseAccount';
import type { EnterpriseConnectionResource } from './enterpriseConnection';
import type { ExternalAccountResource } from './externalAccount';
import type { ImageResource } from './image';
import type { UserJSON } from './json';
Expand DownExpand Up@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
createTOTP: () => Promise<TOTPResource>;
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
disableTOTP: () => Promise<DeletedObjectResource>;
Expand Down
Loading
Loading