Skip to content

Commit b8c73d3

Browse files
authored
chore(clerk-js,shared,ui): Add EnterpriseConnection resource (clerk#8175)
1 parent 5ddb747 commit b8c73d3

File tree

10 files changed

+272
-29
lines changed

10 files changed

+272
-29
lines changed

.changeset/humble-trams-laugh.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/shared': minor
4+
'@clerk/ui': minor
5+
---
6+
7+
Add `EnterpriseConnection` resource
8+
9+
`User.getEnterpriseConnections()` was wrongly typed as returning `EnterpriseAccountConnectionResource[]`, it now returns `EnterpriseConnectionResource[]`

packages/clerk-js/bundlewatch.config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"files": [
3-
{ "path": "./dist/clerk.js", "maxSize": "540KB" },
3+
{ "path": "./dist/clerk.js", "maxSize": "543KB" },
44
{ "path": "./dist/clerk.browser.js", "maxSize": "67KB" },
5-
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "108KB" },
6-
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "307KB" },
7-
{ "path": "./dist/clerk.native.js", "maxSize": "66KB" },
5+
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "110KB" },
6+
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "309KB" },
7+
{ "path": "./dist/clerk.native.js", "maxSize": "68KB" },
88
{ "path": "./dist/vendors*.js", "maxSize": "7KB" },
99
{ "path": "./dist/coinbase*.js", "maxSize": "36KB" },
1010
{ "path": "./dist/base-account-sdk*.js", "maxSize": "203KB" },
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import type {
2+
EnterpriseConnectionJSON,
3+
EnterpriseConnectionJSONSnapshot,
4+
EnterpriseConnectionResource,
5+
EnterpriseOAuthConfigJSON,
6+
EnterpriseOAuthConfigResource,
7+
EnterpriseSamlConnectionNestedJSON,
8+
EnterpriseSamlConnectionNestedResource,
9+
} from '@clerk/shared/types';
10+
11+
import { unixEpochToDate } from '../../utils/date';
12+
import { BaseResource } from './Base';
13+
14+
function samlNestedFromJSON(data: EnterpriseSamlConnectionNestedJSON): EnterpriseSamlConnectionNestedResource {
15+
return {
16+
id: data.id,
17+
name: data.name,
18+
active: data.active,
19+
idpEntityId: data.idp_entity_id,
20+
idpSsoUrl: data.idp_sso_url,
21+
idpCertificate: data.idp_certificate,
22+
idpMetadataUrl: data.idp_metadata_url,
23+
idpMetadata: data.idp_metadata,
24+
acsUrl: data.acs_url,
25+
spEntityId: data.sp_entity_id,
26+
spMetadataUrl: data.sp_metadata_url,
27+
allowSubdomains: data.allow_subdomains,
28+
allowIdpInitiated: data.allow_idp_initiated,
29+
forceAuthn: data.force_authn,
30+
};
31+
}
32+
33+
function samlNestedToJSON(data: EnterpriseSamlConnectionNestedResource): EnterpriseSamlConnectionNestedJSON {
34+
return {
35+
id: data.id,
36+
name: data.name,
37+
active: data.active,
38+
idp_entity_id: data.idpEntityId,
39+
idp_sso_url: data.idpSsoUrl,
40+
idp_certificate: data.idpCertificate,
41+
idp_metadata_url: data.idpMetadataUrl,
42+
idp_metadata: data.idpMetadata,
43+
acs_url: data.acsUrl,
44+
sp_entity_id: data.spEntityId,
45+
sp_metadata_url: data.spMetadataUrl,
46+
allow_subdomains: data.allowSubdomains,
47+
allow_idp_initiated: data.allowIdpInitiated,
48+
force_authn: data.forceAuthn,
49+
};
50+
}
51+
52+
function oauthConfigFromJSON(data: EnterpriseOAuthConfigJSON): EnterpriseOAuthConfigResource {
53+
return {
54+
id: data.id,
55+
name: data.name,
56+
clientId: data.client_id,
57+
providerKey: data.provider_key,
58+
discoveryUrl: data.discovery_url,
59+
logoPublicUrl: data.logo_public_url,
60+
requiresPkce: data.requires_pkce,
61+
createdAt: unixEpochToDate(data.created_at),
62+
updatedAt: unixEpochToDate(data.updated_at),
63+
};
64+
}
65+
66+
function oauthConfigToJSON(data: EnterpriseOAuthConfigResource): EnterpriseOAuthConfigJSON {
67+
return {
68+
id: data.id,
69+
name: data.name,
70+
client_id: data.clientId,
71+
provider_key: data.providerKey,
72+
discovery_url: data.discoveryUrl,
73+
logo_public_url: data.logoPublicUrl,
74+
requires_pkce: data.requiresPkce,
75+
created_at: data.createdAt?.getTime() ?? 0,
76+
updated_at: data.updatedAt?.getTime() ?? 0,
77+
};
78+
}
79+
80+
export class EnterpriseConnection extends BaseResource implements EnterpriseConnectionResource {
81+
id!: string;
82+
name!: string;
83+
active!: boolean;
84+
domains: string[] = [];
85+
organizationId: string | null = null;
86+
syncUserAttributes!: boolean;
87+
disableAdditionalIdentifications!: boolean;
88+
allowOrganizationAccountLinking!: boolean;
89+
customAttributes: unknown[] = [];
90+
oauthConfig: EnterpriseOAuthConfigResource | null = null;
91+
samlConnection: EnterpriseSamlConnectionNestedResource | null = null;
92+
createdAt: Date | null = null;
93+
updatedAt: Date | null = null;
94+
95+
constructor(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null) {
96+
super();
97+
this.fromJSON(data);
98+
}
99+
100+
protected fromJSON(data: EnterpriseConnectionJSON | EnterpriseConnectionJSONSnapshot | null): this {
101+
if (!data) {
102+
return this;
103+
}
104+
105+
this.id = data.id;
106+
this.name = data.name;
107+
this.active = data.active;
108+
this.domains = data.domains ?? [];
109+
this.organizationId = data.organization_id ?? null;
110+
this.syncUserAttributes = data.sync_user_attributes;
111+
this.disableAdditionalIdentifications = data.disable_additional_identifications;
112+
this.allowOrganizationAccountLinking = data.allow_organization_account_linking ?? false;
113+
this.customAttributes = data.custom_attributes ?? [];
114+
this.createdAt = unixEpochToDate(data.created_at);
115+
this.updatedAt = unixEpochToDate(data.updated_at);
116+
117+
this.samlConnection = data.saml_connection ? samlNestedFromJSON(data.saml_connection) : null;
118+
this.oauthConfig = data.oauth_config ? oauthConfigFromJSON(data.oauth_config) : null;
119+
120+
return this;
121+
}
122+
123+
public __internal_toSnapshot(): EnterpriseConnectionJSONSnapshot {
124+
return {
125+
object: 'enterprise_connection',
126+
id: this.id,
127+
name: this.name,
128+
active: this.active,
129+
domains: this.domains,
130+
organization_id: this.organizationId,
131+
sync_user_attributes: this.syncUserAttributes,
132+
disable_additional_identifications: this.disableAdditionalIdentifications,
133+
allow_organization_account_linking: this.allowOrganizationAccountLinking,
134+
custom_attributes: this.customAttributes,
135+
saml_connection: this.samlConnection ? samlNestedToJSON(this.samlConnection) : undefined,
136+
oauth_config: this.oauthConfig ? oauthConfigToJSON(this.oauthConfig) : undefined,
137+
created_at: this.createdAt?.getTime() ?? 0,
138+
updated_at: this.updatedAt?.getTime() ?? 0,
139+
};
140+
}
141+
}

packages/clerk-js/src/core/resources/User.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type {
99
DeletedObjectJSON,
1010
DeletedObjectResource,
1111
EmailAddressResource,
12-
EnterpriseAccountConnectionJSON,
13-
EnterpriseAccountConnectionResource,
1412
EnterpriseAccountResource,
13+
EnterpriseConnectionJSON,
14+
EnterpriseConnectionResource,
1515
ExternalAccountJSON,
1616
ExternalAccountResource,
1717
GetEnterpriseConnectionsParams,
@@ -45,7 +45,7 @@ import {
4545
DeletedObject,
4646
EmailAddress,
4747
EnterpriseAccount,
48-
EnterpriseAccountConnection,
48+
EnterpriseConnection,
4949
ExternalAccount,
5050
Image,
5151
OrganizationMembership,
@@ -296,7 +296,7 @@ export class User extends BaseResource implements UserResource {
296296

297297
getEnterpriseConnections = async (
298298
params?: GetEnterpriseConnectionsParams,
299-
): Promise<EnterpriseAccountConnectionResource[]> => {
299+
): Promise<EnterpriseConnectionResource[]> => {
300300
const { withOrganizationAccountLinking } = params || {};
301301

302302
const json = (
@@ -311,9 +311,9 @@ export class User extends BaseResource implements UserResource {
311311
}
312312
: {}),
313313
})
314-
)?.response as unknown as EnterpriseAccountConnectionJSON[];
314+
)?.response as unknown as EnterpriseConnectionJSON[];
315315

316-
return (json || []).map(connection => new EnterpriseAccountConnection(connection));
316+
return (json || []).map(connection => new EnterpriseConnection(connection));
317317
};
318318

319319
initializePaymentMethod: typeof initializePaymentMethod = params => {

packages/clerk-js/src/core/resources/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export * from './DeletedObject';
1616
export * from './DisplayConfig';
1717
export * from './EmailAddress';
1818
export * from './EnterpriseAccount';
19+
export * from './EnterpriseConnection';
1920
export * from './Environment';
2021
export * from './ExternalAccount';
2122
export * from './Feature';

packages/shared/src/react/hooks/useUserEnterpriseConnections.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EnterpriseAccountConnectionResource } from '../../types/enterpriseAccount';
1+
import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection';
22
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
33
import { useClerkQuery } from '../clerk-rq/useQuery';
44
import { useClerkInstanceContext } from '../contexts';
@@ -13,7 +13,7 @@ export type UseUserEnterpriseConnectionsParams = {
1313
};
1414

1515
export type UseUserEnterpriseConnectionsReturn = {
16-
data: EnterpriseAccountConnectionResource[] | undefined;
16+
data: EnterpriseConnectionResource[] | undefined;
1717
error: Error | null;
1818
isLoading: boolean;
1919
isFetching: boolean;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type { ClerkResourceJSON } from './json';
2+
import type { ClerkResource } from './resource';
3+
4+
export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
5+
object: 'enterprise_connection';
6+
name: string;
7+
active: boolean;
8+
domains?: string[];
9+
organization_id?: string | null;
10+
sync_user_attributes: boolean;
11+
disable_additional_identifications: boolean;
12+
allow_organization_account_linking?: boolean;
13+
custom_attributes?: unknown[];
14+
oauth_config?: EnterpriseOAuthConfigJSON | null;
15+
saml_connection?: EnterpriseSamlConnectionNestedJSON | null;
16+
created_at: number;
17+
updated_at: number;
18+
}
19+
20+
export type EnterpriseConnectionJSONSnapshot = EnterpriseConnectionJSON;
21+
22+
export interface EnterpriseConnectionResource extends ClerkResource {
23+
id: string;
24+
name: string;
25+
active: boolean;
26+
domains: string[];
27+
organizationId: string | null;
28+
syncUserAttributes: boolean;
29+
disableAdditionalIdentifications: boolean;
30+
allowOrganizationAccountLinking: boolean;
31+
customAttributes: unknown[];
32+
oauthConfig: EnterpriseOAuthConfigResource | null;
33+
samlConnection: EnterpriseSamlConnectionNestedResource | null;
34+
createdAt: Date | null;
35+
updatedAt: Date | null;
36+
__internal_toSnapshot: () => EnterpriseConnectionJSONSnapshot;
37+
}
38+
39+
export interface EnterpriseSamlConnectionNestedJSON {
40+
id: string;
41+
name: string;
42+
active: boolean;
43+
idp_entity_id: string;
44+
idp_sso_url: string;
45+
idp_certificate: string;
46+
idp_metadata_url: string;
47+
idp_metadata: string;
48+
acs_url: string;
49+
sp_entity_id: string;
50+
sp_metadata_url: string;
51+
allow_subdomains: boolean;
52+
allow_idp_initiated: boolean;
53+
force_authn: boolean;
54+
}
55+
56+
export interface EnterpriseSamlConnectionNestedResource {
57+
id: string;
58+
name: string;
59+
active: boolean;
60+
idpEntityId: string;
61+
idpSsoUrl: string;
62+
idpCertificate: string;
63+
idpMetadataUrl: string;
64+
idpMetadata: string;
65+
acsUrl: string;
66+
spEntityId: string;
67+
spMetadataUrl: string;
68+
allowSubdomains: boolean;
69+
allowIdpInitiated: boolean;
70+
forceAuthn: boolean;
71+
}
72+
73+
export interface EnterpriseOAuthConfigJSON {
74+
id: string;
75+
name: string;
76+
provider_key?: string;
77+
client_id: string;
78+
discovery_url?: string;
79+
logo_public_url?: string | null;
80+
requires_pkce?: boolean;
81+
created_at: number;
82+
updated_at: number;
83+
}
84+
85+
export interface EnterpriseOAuthConfigResource {
86+
id: string;
87+
name: string;
88+
clientId: string;
89+
providerKey?: string;
90+
discoveryUrl?: string;
91+
logoPublicUrl?: string | null;
92+
requiresPkce?: boolean;
93+
createdAt: Date | null;
94+
updatedAt: Date | null;
95+
}

packages/shared/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type * from './displayConfig';
1616
export type * from './elementIds';
1717
export type * from './emailAddress';
1818
export type * from './enterpriseAccount';
19+
export type * from './enterpriseConnection';
1920
export type * from './environment';
2021
export type * from './errors';
2122
export type * from './externalAccount';

packages/shared/src/types/user.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { BackupCodeResource } from './backupCode';
22
import type { BillingPayerMethods } from './billing';
33
import type { DeletedObjectResource } from './deletedObject';
44
import type { EmailAddressResource } from './emailAddress';
5-
import type { EnterpriseAccountConnectionResource, EnterpriseAccountResource } from './enterpriseAccount';
5+
import type { EnterpriseAccountResource } from './enterpriseAccount';
6+
import type { EnterpriseConnectionResource } from './enterpriseConnection';
67
import type { ExternalAccountResource } from './externalAccount';
78
import type { ImageResource } from './image';
89
import type { UserJSON } from './json';
@@ -118,7 +119,7 @@ export interface UserResource extends ClerkResource, BillingPayerMethods {
118119
) => Promise<ClerkPaginatedResponse<OrganizationSuggestionResource>>;
119120
getOrganizationCreationDefaults: () => Promise<OrganizationCreationDefaultsResource>;
120121
leaveOrganization: (organizationId: string) => Promise<DeletedObjectResource>;
121-
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseAccountConnectionResource[]>;
122+
getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise<EnterpriseConnectionResource[]>;
122123
createTOTP: () => Promise<TOTPResource>;
123124
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
124125
disableTOTP: () => Promise<DeletedObjectResource>;

0 commit comments

Comments
 (0)