From fa24b25cdaa74e59418e07e518c24faf2899e2fb Mon Sep 17 00:00:00 2001 From: Laura Beatris Date: Wed, 3 Jun 2026 21:43:33 -0300 Subject: [PATCH 1/4] Remove enterprise connection mutations under `/me` scope --- packages/clerk-js/src/core/resources/User.ts | 43 --- .../src/core/resources/__tests__/User.test.ts | 255 ------------------ .../hooks/useUserEnterpriseConnections.tsx | 45 +--- packages/shared/src/types/user.ts | 14 +- 4 files changed, 2 insertions(+), 355 deletions(-) diff --git a/packages/clerk-js/src/core/resources/User.ts b/packages/clerk-js/src/core/resources/User.ts index a88775a87ca..0eebd76f7dc 100644 --- a/packages/clerk-js/src/core/resources/User.ts +++ b/packages/clerk-js/src/core/resources/User.ts @@ -5,7 +5,6 @@ import type { ClerkPaginatedResponse, CreateEmailAddressParams, CreateExternalAccountParams, - CreateOrganizationEnterpriseConnectionParams, CreatePhoneNumberParams, CreateWeb3WalletParams, DeletedObjectJSON, @@ -34,7 +33,6 @@ import type { SetProfileImageParams, TOTPJSON, TOTPResource, - UpdateOrganizationEnterpriseConnectionParams, UpdateUserMetadataParams, UpdateUserParams, UpdateUserPasswordParams, @@ -47,7 +45,6 @@ import type { import { convertPageToOffsetSearchParams } from '../../utils/convertPageToOffsetSearchParams'; import { unixEpochToDate } from '../../utils/date'; -import { toEnterpriseConnectionBody } from '../../utils/enterpriseConnection'; import { normalizeUnsafeMetadata } from '../../utils/resourceParams'; import { eventBus, events } from '../events'; import { addPaymentMethod, getPaymentMethods, initializePaymentMethod } from '../modules/billing'; @@ -336,46 +333,6 @@ export class User extends BaseResource implements UserResource { return (json || []).map(connection => new EnterpriseConnection(connection)); }; - createEnterpriseConnection = async ( - params: CreateOrganizationEnterpriseConnectionParams, - ): Promise => { - const json = ( - await BaseResource._fetch({ - path: `${this.path()}/enterprise_connections`, - method: 'POST', - body: toEnterpriseConnectionBody(params) as any, - }) - )?.response as unknown as EnterpriseConnectionJSON; - - return new EnterpriseConnection(json); - }; - - updateEnterpriseConnection = async ( - enterpriseConnectionId: string, - params: UpdateOrganizationEnterpriseConnectionParams, - ): Promise => { - const json = ( - await BaseResource._fetch({ - path: `${this.path()}/enterprise_connections/${enterpriseConnectionId}`, - method: 'PATCH', - body: toEnterpriseConnectionBody(params) as any, - }) - )?.response as unknown as EnterpriseConnectionJSON; - - return new EnterpriseConnection(json); - }; - - deleteEnterpriseConnection = async (enterpriseConnectionId: string): Promise => { - const json = ( - await BaseResource._fetch({ - path: `${this.path()}/enterprise_connections/${enterpriseConnectionId}`, - method: 'DELETE', - }) - )?.response as unknown as DeletedObjectJSON; - - return new DeletedObject(json); - }; - createEnterpriseConnectionTestRun = async ( enterpriseConnectionId: string, ): Promise => { diff --git a/packages/clerk-js/src/core/resources/__tests__/User.test.ts b/packages/clerk-js/src/core/resources/__tests__/User.test.ts index 20e8074cf16..6a3aa0e85aa 100644 --- a/packages/clerk-js/src/core/resources/__tests__/User.test.ts +++ b/packages/clerk-js/src/core/resources/__tests__/User.test.ts @@ -139,261 +139,6 @@ describe('User', () => { expect(connections[0].allowOrganizationAccountLinking).toBe(true); }); - it('creates an enterprise connection', async () => { - const enterpriseConnectionJSON = { - id: 'ec_new', - object: 'enterprise_connection' as const, - name: 'New SSO', - active: true, - provider: 'saml_okta', - logo_public_url: null, - domains: ['acme.com'], - organization_id: null, - sync_user_attributes: true, - disable_additional_identifications: false, - allow_organization_account_linking: false, - custom_attributes: [], - oauth_config: null, - saml_connection: null, - created_at: 1234567890, - updated_at: 1234567890, - }; - - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: enterpriseConnectionJSON })); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - const conn = await user.createEnterpriseConnection({ - provider: 'saml_okta', - name: 'New SSO', - organizationId: 'org_1', - saml: { idpEntityId: 'https://idp.example.com' }, - }); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'POST', - path: '/me/enterprise_connections', - body: { - provider: 'saml_okta', - name: 'New SSO', - organization_id: 'org_1', - saml_idp_entity_id: 'https://idp.example.com', - }, - }); - - expect(conn.id).toBe('ec_new'); - expect(conn.name).toBe('New SSO'); - }); - - it('updates an enterprise connection', async () => { - const enterpriseConnectionJSON = { - id: 'ec_123', - object: 'enterprise_connection' as const, - name: 'Updated', - active: false, - provider: 'saml_okta', - logo_public_url: null, - domains: ['acme.com'], - organization_id: null, - sync_user_attributes: true, - disable_additional_identifications: false, - allow_organization_account_linking: false, - custom_attributes: [], - oauth_config: null, - saml_connection: null, - created_at: 1234567890, - updated_at: 1234567900, - }; - - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: enterpriseConnectionJSON })); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - await user.updateEnterpriseConnection('ec_123', { - name: 'Updated', - active: false, - syncUserAttributes: true, - }); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'PATCH', - path: '/me/enterprise_connections/ec_123', - body: { - name: 'Updated', - active: false, - sync_user_attributes: true, - }, - }); - }); - - it('preserves `saml.attributeMapping` and `saml.customAttributes` keys when creating an enterprise connection', async () => { - BaseResource._fetch = vi.fn().mockReturnValue( - Promise.resolve({ - response: { - id: 'ec_new', - object: 'enterprise_connection' as const, - name: 'New SSO', - active: true, - provider: 'saml_okta', - logo_public_url: null, - domains: [], - organization_id: null, - sync_user_attributes: true, - disable_additional_identifications: false, - allow_organization_account_linking: false, - custom_attributes: [], - oauth_config: null, - saml_connection: null, - created_at: 1, - updated_at: 1, - }, - }), - ); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - await user.createEnterpriseConnection({ - provider: 'saml_okta', - name: 'New SSO', - saml: { - idpEntityId: 'https://idp.example.com', - attributeMapping: { - emailAddress: 'mail', - firstName: 'givenName', - 'custom:role': 'role', - }, - }, - }); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'POST', - path: '/me/enterprise_connections', - body: { - provider: 'saml_okta', - name: 'New SSO', - saml_idp_entity_id: 'https://idp.example.com', - saml_attribute_mapping: { - emailAddress: 'mail', - firstName: 'givenName', - 'custom:role': 'role', - }, - }, - }); - }); - - it('preserves `customAttributes` and `saml.attributeMapping` keys when updating an enterprise connection', async () => { - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue( - Promise.resolve({ - response: { - id: 'ec_123', - object: 'enterprise_connection' as const, - name: 'Updated', - active: true, - provider: 'saml_okta', - logo_public_url: null, - domains: [], - organization_id: null, - sync_user_attributes: true, - disable_additional_identifications: false, - allow_organization_account_linking: false, - custom_attributes: [], - oauth_config: null, - saml_connection: null, - created_at: 1, - updated_at: 2, - }, - }), - ); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - await user.updateEnterpriseConnection('ec_123', { - customAttributes: { - MyClaim: 'x', - CustomValue: 'y', - nestedCamelKey: { innerCamelKey: 'z' }, - }, - saml: { - attributeMapping: { - emailAddress: 'mail', - firstName: 'givenName', - }, - }, - }); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'PATCH', - path: '/me/enterprise_connections/ec_123', - body: { - custom_attributes: { - MyClaim: 'x', - CustomValue: 'y', - nestedCamelKey: { innerCamelKey: 'z' }, - }, - saml_attribute_mapping: { - emailAddress: 'mail', - firstName: 'givenName', - }, - }, - }); - }); - - it('deletes an enterprise connection', async () => { - const deletedJSON = { - object: 'enterprise_connection', - id: 'ec_123', - deleted: true, - }; - - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: deletedJSON })); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - const result = await user.deleteEnterpriseConnection('ec_123'); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'DELETE', - path: '/me/enterprise_connections/ec_123', - }); - - expect(result.id).toBe('ec_123'); - expect(result.deleted).toBe(true); - }); - it('creates an enterprise connection test run', async () => { // @ts-ignore BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: { url: 'https://example.com/test' } })); diff --git a/packages/shared/src/react/hooks/useUserEnterpriseConnections.tsx b/packages/shared/src/react/hooks/useUserEnterpriseConnections.tsx index a80e03213b1..681e33ea2e8 100644 --- a/packages/shared/src/react/hooks/useUserEnterpriseConnections.tsx +++ b/packages/shared/src/react/hooks/useUserEnterpriseConnections.tsx @@ -1,11 +1,6 @@ import { useCallback } from 'react'; -import type { DeletedObjectResource } from '../../types/deletedObject'; -import type { - CreateMeEnterpriseConnectionParams, - EnterpriseConnectionResource, - UpdateMeEnterpriseConnectionParams, -} from '../../types/enterpriseConnection'; +import type { EnterpriseConnectionResource } from '../../types/enterpriseConnection'; import { useClerkInstanceContext } from '../contexts'; import { defineKeepPreviousDataFn } from '../query/keep-previous-data'; import { useClerkQueryClient } from '../query/use-clerk-query-client'; @@ -25,14 +20,6 @@ export type UseUserEnterpriseConnectionsReturn = { error: Error | null; isLoading: boolean; isFetching: boolean; - createEnterpriseConnection: ( - params: CreateMeEnterpriseConnectionParams, - ) => Promise; - updateEnterpriseConnection: ( - enterpriseConnectionId: string, - params: UpdateMeEnterpriseConnectionParams, - ) => Promise; - deleteEnterpriseConnection: (enterpriseConnectionId: string) => Promise; revalidate: () => Promise; }; @@ -74,41 +61,11 @@ function useUserEnterpriseConnections( [queryClient, stableKey], ); - const createEnterpriseConnection = useCallback( - async (createParams: CreateMeEnterpriseConnectionParams) => { - const created = await user?.createEnterpriseConnection(createParams); - await revalidate(); - return created; - }, - [user, revalidate], - ); - - const updateEnterpriseConnection = useCallback( - async (enterpriseConnectionId: string, updateParams: UpdateMeEnterpriseConnectionParams) => { - const updated = await user?.updateEnterpriseConnection(enterpriseConnectionId, updateParams); - await revalidate(); - return updated; - }, - [user, revalidate], - ); - - const deleteEnterpriseConnection = useCallback( - async (enterpriseConnectionId: string) => { - const deleted = await user?.deleteEnterpriseConnection(enterpriseConnectionId); - await revalidate(); - return deleted; - }, - [user, revalidate], - ); - return { data: query.data, error: query.error ?? null, isLoading: query.isLoading, isFetching: query.isFetching, - createEnterpriseConnection, - updateEnterpriseConnection, - deleteEnterpriseConnection, revalidate, }; } diff --git a/packages/shared/src/types/user.ts b/packages/shared/src/types/user.ts index f3e8905be64..96494c54461 100644 --- a/packages/shared/src/types/user.ts +++ b/packages/shared/src/types/user.ts @@ -3,11 +3,7 @@ import type { BillingPayerMethods } from './billing'; import type { DeletedObjectResource } from './deletedObject'; import type { EmailAddressResource } from './emailAddress'; import type { EnterpriseAccountResource } from './enterpriseAccount'; -import type { - CreateOrganizationEnterpriseConnectionParams, - EnterpriseConnectionResource, - UpdateOrganizationEnterpriseConnectionParams, -} from './enterpriseConnection'; +import type { EnterpriseConnectionResource } from './enterpriseConnection'; import type { EnterpriseConnectionTestRunInitResource, EnterpriseConnectionTestRunResource, @@ -307,14 +303,6 @@ export interface UserResource extends ClerkResource, BillingPayerMethods { */ leaveOrganization: (organizationId: string) => Promise; getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise; - createEnterpriseConnection: ( - params: CreateOrganizationEnterpriseConnectionParams, - ) => Promise; - updateEnterpriseConnection: ( - enterpriseConnectionId: string, - params: UpdateOrganizationEnterpriseConnectionParams, - ) => Promise; - deleteEnterpriseConnection: (enterpriseConnectionId: string) => Promise; createEnterpriseConnectionTestRun: ( enterpriseConnectionId: string, ) => Promise; From 232905270ff3e6af67c12beab1b66bb118d53ed0 Mon Sep 17 00:00:00 2001 From: Laura Beatris Date: Wed, 3 Jun 2026 21:45:17 -0300 Subject: [PATCH 2/4] Add changeset --- .changeset/quick-pugs-tap.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/quick-pugs-tap.md diff --git a/.changeset/quick-pugs-tap.md b/.changeset/quick-pugs-tap.md new file mode 100644 index 00000000000..d43e2f58d1d --- /dev/null +++ b/.changeset/quick-pugs-tap.md @@ -0,0 +1,8 @@ +--- +'@clerk/clerk-js': patch +'@clerk/shared': patch +--- + +Remove deprecated `createEnterpriseConnection`, `updateEnterpriseConnection`, and `deleteEnterpriseConnection` methods from the `User` resource in favor of `Organization` scoped ones + +`ConfigureSSO` was previously the only consumer but since it hasn't been released GA yet, these changes won't break existing production clients From 69573c2ddad2c476f0c385ed85bc621ef5891484 Mon Sep 17 00:00:00 2001 From: Laura Beatris Date: Mon, 8 Jun 2026 14:55:07 -0300 Subject: [PATCH 3/4] Add JSDocs for `User.getEnterpriseConnections` --- packages/shared/src/types/user.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/shared/src/types/user.ts b/packages/shared/src/types/user.ts index 96494c54461..13efbbdc79c 100644 --- a/packages/shared/src/types/user.ts +++ b/packages/shared/src/types/user.ts @@ -302,6 +302,11 @@ export interface UserResource extends ClerkResource, BillingPayerMethods { * @returns A [`DeletedObjectResource`](https://clerk.com/docs/reference/types/deleted-object-resource) object. */ leaveOrganization: (organizationId: string) => Promise; + /** + * Get the enterprise connections for the current user. This method is not intended for public use. + * Currently some customers use this to get enterprise connections for account linking purposes. + * @hidden + */ getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise; createEnterpriseConnectionTestRun: ( enterpriseConnectionId: string, From 4b94fc5f1777d8c1be10fc16ae8faeef5654bc2d Mon Sep 17 00:00:00 2001 From: Laura Beatris Date: Mon, 8 Jun 2026 15:00:37 -0300 Subject: [PATCH 4/4] Remove deprecated test runs methods from the `/me` path --- .changeset/quick-pugs-tap.md | 2 +- packages/clerk-js/src/core/resources/User.ts | 48 ------ .../src/core/resources/__tests__/User.test.ts | 66 --------- packages/shared/src/react/hooks/index.ts | 5 - .../useEnterpriseConnectionTestRuns.shared.ts | 31 ---- .../hooks/useEnterpriseConnectionTestRuns.tsx | 140 ------------------ packages/shared/src/types/user.ts | 12 -- 7 files changed, 1 insertion(+), 303 deletions(-) delete mode 100644 packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.shared.ts delete mode 100644 packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.tsx diff --git a/.changeset/quick-pugs-tap.md b/.changeset/quick-pugs-tap.md index d43e2f58d1d..9c763b798b2 100644 --- a/.changeset/quick-pugs-tap.md +++ b/.changeset/quick-pugs-tap.md @@ -3,6 +3,6 @@ '@clerk/shared': patch --- -Remove deprecated `createEnterpriseConnection`, `updateEnterpriseConnection`, and `deleteEnterpriseConnection` methods from the `User` resource in favor of `Organization` scoped ones +Remove deprecated `createEnterpriseConnection`, `updateEnterpriseConnection`, `deleteEnterpriseConnection`, `createEnterpriseConnectionTestRun`, and `getEnterpriseConnectionTestRuns` methods from the `User` resource in favor of `Organization` scoped ones. Also removes the unused internal `__internal_useEnterpriseConnectionTestRuns` hook. `ConfigureSSO` was previously the only consumer but since it hasn't been released GA yet, these changes won't break existing production clients diff --git a/packages/clerk-js/src/core/resources/User.ts b/packages/clerk-js/src/core/resources/User.ts index 0eebd76f7dc..76e2b01ef3c 100644 --- a/packages/clerk-js/src/core/resources/User.ts +++ b/packages/clerk-js/src/core/resources/User.ts @@ -2,7 +2,6 @@ import { getFullName } from '@clerk/shared/internal/clerk-js/user'; import type { BackupCodeJSON, BackupCodeResource, - ClerkPaginatedResponse, CreateEmailAddressParams, CreateExternalAccountParams, CreatePhoneNumberParams, @@ -13,15 +12,9 @@ import type { EnterpriseAccountResource, EnterpriseConnectionJSON, EnterpriseConnectionResource, - EnterpriseConnectionTestRunInitJSON, - EnterpriseConnectionTestRunInitResource, - EnterpriseConnectionTestRunJSON, - EnterpriseConnectionTestRunResource, - EnterpriseConnectionTestRunsPaginatedJSON, ExternalAccountJSON, ExternalAccountResource, GetEnterpriseConnectionsParams, - GetEnterpriseConnectionTestRunsParams, GetOrganizationMemberships, GetUserOrganizationInvitationsParams, GetUserOrganizationSuggestionsParams, @@ -43,7 +36,6 @@ import type { Web3WalletResource, } from '@clerk/shared/types'; -import { convertPageToOffsetSearchParams } from '../../utils/convertPageToOffsetSearchParams'; import { unixEpochToDate } from '../../utils/date'; import { normalizeUnsafeMetadata } from '../../utils/resourceParams'; import { eventBus, events } from '../events'; @@ -55,7 +47,6 @@ import { EmailAddress, EnterpriseAccount, EnterpriseConnection, - EnterpriseConnectionTestRun, ExternalAccount, Image, OrganizationMembership, @@ -333,45 +324,6 @@ export class User extends BaseResource implements UserResource { return (json || []).map(connection => new EnterpriseConnection(connection)); }; - createEnterpriseConnectionTestRun = async ( - enterpriseConnectionId: string, - ): Promise => { - const json = ( - await BaseResource._fetch({ - path: `${this.path()}/enterprise_connections/${enterpriseConnectionId}/test_runs`, - method: 'POST', - }) - )?.response as unknown as EnterpriseConnectionTestRunInitJSON; - - return { url: json.url }; - }; - - getEnterpriseConnectionTestRuns = async ( - enterpriseConnectionId: string, - params?: GetEnterpriseConnectionTestRunsParams, - ): Promise> => { - const { status, ...rest } = params || {}; - const search = convertPageToOffsetSearchParams(rest); - if (status?.length) { - for (const s of status) { - search.append('status', s); - } - } - - const res = await BaseResource._fetch({ - path: `${this.path()}/enterprise_connections/${enterpriseConnectionId}/test_runs`, - method: 'GET', - search, - }); - - const payload = res?.response as unknown as EnterpriseConnectionTestRunsPaginatedJSON | undefined; - - return { - total_count: payload?.total_count ?? 0, - data: (payload?.data ?? []).map((row: EnterpriseConnectionTestRunJSON) => new EnterpriseConnectionTestRun(row)), - }; - }; - initializePaymentMethod: typeof initializePaymentMethod = params => { return initializePaymentMethod(params); }; diff --git a/packages/clerk-js/src/core/resources/__tests__/User.test.ts b/packages/clerk-js/src/core/resources/__tests__/User.test.ts index 6a3aa0e85aa..7dd237a3d5b 100644 --- a/packages/clerk-js/src/core/resources/__tests__/User.test.ts +++ b/packages/clerk-js/src/core/resources/__tests__/User.test.ts @@ -139,72 +139,6 @@ describe('User', () => { expect(connections[0].allowOrganizationAccountLinking).toBe(true); }); - it('creates an enterprise connection test run', async () => { - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: { url: 'https://example.com/test' } })); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - const init = await user.createEnterpriseConnectionTestRun('ec_123'); - - // @ts-ignore - expect(BaseResource._fetch).toHaveBeenCalledWith({ - method: 'POST', - path: '/me/enterprise_connections/ec_123/test_runs', - }); - - expect(init.url).toBe('https://example.com/test'); - }); - - it('lists enterprise connection test runs', async () => { - const paginated = { - data: [ - { - object: 'enterprise_connection_test_run' as const, - id: 'run_1', - status: 'success', - connection_type: 'saml' as const, - created_at: 1700000000000, - }, - ], - total_count: 1, - }; - - // @ts-ignore - BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: paginated })); - - const user = new User({ - email_addresses: [], - phone_numbers: [], - web3_wallets: [], - external_accounts: [], - } as unknown as UserJSON); - - const result = await user.getEnterpriseConnectionTestRuns('ec_123', { - initialPage: 1, - pageSize: 10, - status: ['pending', 'success'], - }); - - // @ts-ignore - const call = BaseResource._fetch.mock.calls[0][0]; - expect(call.method).toBe('GET'); - expect(call.path).toBe('/me/enterprise_connections/ec_123/test_runs'); - expect(call.search.get('limit')).toBe('10'); - expect(call.search.get('offset')).toBe('0'); - expect(call.search.getAll('status')).toEqual(['pending', 'success']); - - expect(result.total_count).toBe(1); - expect(result.data).toHaveLength(1); - expect(result.data[0].id).toBe('run_1'); - expect(result.data[0].connectionType).toBe('saml'); - }); - it('creates a web3 wallet', async () => { const targetWeb3Wallet = '0x0000000000000000000000000000000000000000'; const web3WalletJSON = { diff --git a/packages/shared/src/react/hooks/index.ts b/packages/shared/src/react/hooks/index.ts index 020bad2f0b3..e4ab76177bb 100644 --- a/packages/shared/src/react/hooks/index.ts +++ b/packages/shared/src/react/hooks/index.ts @@ -38,11 +38,6 @@ export type { UseUserEnterpriseConnectionsParams, UseUserEnterpriseConnectionsReturn, } from './useUserEnterpriseConnections'; -export { __internal_useEnterpriseConnectionTestRuns } from './useEnterpriseConnectionTestRuns'; -export type { - UseEnterpriseConnectionTestRunsParams, - UseEnterpriseConnectionTestRunsReturn, -} from './useEnterpriseConnectionTestRuns'; export { __internal_useOrganizationEnterpriseConnections } from './useOrganizationEnterpriseConnections'; export type { UseOrganizationEnterpriseConnectionsParams, diff --git a/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.shared.ts b/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.shared.ts deleted file mode 100644 index 8cd18085106..00000000000 --- a/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.shared.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { useMemo } from 'react'; - -import type { GetEnterpriseConnectionTestRunsParams } from '../../types/enterpriseConnectionTestRun'; -import { INTERNAL_STABLE_KEYS } from '../stable-keys'; -import { createCacheKeys } from './createCacheKeys'; - -/** - * @internal - */ -export function useEnterpriseConnectionTestRunsCacheKeys(params: { - userId: string | null; - enterpriseConnectionId: string | null; - args: GetEnterpriseConnectionTestRunsParams; -}) { - const { userId, enterpriseConnectionId, args } = params; - return useMemo(() => { - return createCacheKeys({ - stablePrefix: INTERNAL_STABLE_KEYS.ENTERPRISE_CONNECTION_TEST_RUNS_KEY, - authenticated: Boolean(userId), - tracked: { - userId: userId ?? null, - enterpriseConnectionId: enterpriseConnectionId ?? null, - }, - untracked: { - args, - }, - }); - // The args object is intentionally serialized via the consumer to keep stability. - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [userId, enterpriseConnectionId, JSON.stringify(args)]); -} diff --git a/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.tsx b/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.tsx deleted file mode 100644 index 6787312e9fe..00000000000 --- a/packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import { useCallback, useEffect, useState } from 'react'; - -import type { - EnterpriseConnectionTestRunResource, - GetEnterpriseConnectionTestRunsParams, -} from '../../types/enterpriseConnectionTestRun'; -import { useClerkInstanceContext } from '../contexts'; -import { useClerkQueryClient } from '../query/use-clerk-query-client'; -import { useClerkQuery } from '../query/useQuery'; -import { useUserBase } from './base/useUserBase'; -import { useClearQueriesOnSignOut } from './useClearQueriesOnSignOut'; -import { useEnterpriseConnectionTestRunsCacheKeys } from './useEnterpriseConnectionTestRuns.shared'; - -const DEFAULT_POLL_INTERVAL_MS = 2_000; - -export type UseEnterpriseConnectionTestRunsParams = { - enterpriseConnectionId: string | null; - /** - * Pass-through fetch parameters (pagination, status filter). - * Defaults to `{ initialPage: 1, pageSize: 10 }`. - */ - params?: GetEnterpriseConnectionTestRunsParams; - /** - * Polling interval (ms) applied between `revalidate()` and the moment the - * first record arrives in the response. - * - * @default 2000 - */ - pollIntervalMs?: number; - /** - * If `false`, the hook is dormant — no fetch, no polling. - * - * @default true - */ - enabled?: boolean; -}; - -export type UseEnterpriseConnectionTestRunsReturn = { - data: EnterpriseConnectionTestRunResource[] | undefined; - totalCount: number | undefined; - error: Error | null; - isLoading: boolean; - isFetching: boolean; - /** - * `true` while the hook is actively polling for the first record to appear - */ - isPolling: boolean; - /** - * Force a refetch and (if the list is currently empty) arm polling - */ - revalidate: () => Promise; -}; - -/** - * Subscribes to the list of enterprise-connection test runs for the signed-in user - * - * @internal - */ -function useEnterpriseConnectionTestRuns( - params: UseEnterpriseConnectionTestRunsParams, -): UseEnterpriseConnectionTestRunsReturn { - const { - enterpriseConnectionId, - params: fetchParams = { initialPage: 1, pageSize: 10 }, - pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, - enabled = true, - } = params; - - const clerk = useClerkInstanceContext(); - const user = useUserBase(); - const [queryClient] = useClerkQueryClient(); - - const { queryKey, invalidationKey, stableKey, authenticated } = useEnterpriseConnectionTestRunsCacheKeys({ - userId: user?.id ?? null, - enterpriseConnectionId, - args: fetchParams, - }); - - useClearQueriesOnSignOut({ - isSignedOut: user === null, - authenticated, - stableKeys: stableKey, - }); - - const queryEnabled = enabled && clerk.loaded && Boolean(user) && Boolean(enterpriseConnectionId); - - const [shouldPoll, setShouldPoll] = useState(false); - - const query = useClerkQuery({ - queryKey, - queryFn: () => { - if (!enterpriseConnectionId) { - throw new Error('enterpriseConnectionId is required to fetch test runs'); - } - return user?.getEnterpriseConnectionTestRuns(enterpriseConnectionId, fetchParams); - }, - refetchInterval: q => { - if (!shouldPoll) { - return false; - } - - const hasRows = (q.state.data?.data?.length ?? 0) > 0; - return hasRows ? false : pollIntervalMs; - }, - enabled: queryEnabled, - refetchIntervalInBackground: false, - refetchOnWindowFocus: false, - }); - - const hasRows = (query.data?.data?.length ?? 0) > 0; - - useEffect(() => { - if (shouldPoll && hasRows) { - setShouldPoll(false); - } - }, [shouldPoll, hasRows]); - - const revalidate = useCallback(async () => { - // Only arm polling when there is nothing in the list yet — once any record - // has been seen, this is a one-shot refetch. - if (!hasRows) { - setShouldPoll(true); - } - await queryClient.invalidateQueries({ queryKey: invalidationKey }); - }, [queryClient, invalidationKey, hasRows]); - - const isPolling = queryEnabled && shouldPoll && !hasRows; - - return { - data: query.data?.data, - totalCount: query.data?.total_count, - error: query.error ?? null, - isLoading: query.isLoading, - isFetching: query.isFetching, - isPolling, - revalidate, - }; -} - -export { useEnterpriseConnectionTestRuns as __internal_useEnterpriseConnectionTestRuns }; diff --git a/packages/shared/src/types/user.ts b/packages/shared/src/types/user.ts index 13efbbdc79c..ed595f1738c 100644 --- a/packages/shared/src/types/user.ts +++ b/packages/shared/src/types/user.ts @@ -4,11 +4,6 @@ import type { DeletedObjectResource } from './deletedObject'; import type { EmailAddressResource } from './emailAddress'; import type { EnterpriseAccountResource } from './enterpriseAccount'; import type { EnterpriseConnectionResource } from './enterpriseConnection'; -import type { - EnterpriseConnectionTestRunInitResource, - EnterpriseConnectionTestRunResource, - GetEnterpriseConnectionTestRunsParams, -} from './enterpriseConnectionTestRun'; import type { ExternalAccountResource } from './externalAccount'; import type { ImageResource } from './image'; import type { UserJSON } from './json'; @@ -308,13 +303,6 @@ export interface UserResource extends ClerkResource, BillingPayerMethods { * @hidden */ getEnterpriseConnections: (params?: GetEnterpriseConnectionsParams) => Promise; - createEnterpriseConnectionTestRun: ( - enterpriseConnectionId: string, - ) => Promise; - getEnterpriseConnectionTestRuns: ( - enterpriseConnectionId: string, - params?: GetEnterpriseConnectionTestRunsParams, - ) => Promise>; /** * Generates a TOTP secret for a user that can be used to register the application on the user's authenticator app of choice. If this method is called again (while still unverified), it replaces the previously generated secret. * @returns A [`TOTPResource`](https://clerk.com/docs/reference/types/totp-resource) object.