|
| 1 | +import type { ClerkPaginationRequest } from '@clerk/shared/types'; |
| 2 | + |
| 3 | +import { joinPaths } from '../../util/path'; |
| 4 | +import type { EnterpriseConnection } from '../resources'; |
| 5 | +import type { PaginatedResourceResponse } from '../resources/Deserializer'; |
| 6 | +import { AbstractAPI } from './AbstractApi'; |
| 7 | + |
| 8 | +const basePath = '/enterprise_connections'; |
| 9 | + |
| 10 | +type EnterpriseConnectionListParams = ClerkPaginationRequest<{ |
| 11 | + organizationId?: string; |
| 12 | + active?: boolean; |
| 13 | +}>; |
| 14 | + |
| 15 | +export interface EnterpriseConnectionOidcParams { |
| 16 | + authUrl?: string; |
| 17 | + clientId?: string; |
| 18 | + clientSecret?: string; |
| 19 | + discoveryUrl?: string; |
| 20 | + requiresPkce?: boolean; |
| 21 | + tokenUrl?: string; |
| 22 | + userInfoUrl?: string; |
| 23 | +} |
| 24 | + |
| 25 | +export interface EnterpriseConnectionSamlAttributeMappingParams { |
| 26 | + userId?: string | null; |
| 27 | + emailAddress?: string | null; |
| 28 | + firstName?: string | null; |
| 29 | + lastName?: string | null; |
| 30 | +} |
| 31 | + |
| 32 | +export interface EnterpriseConnectionSamlParams { |
| 33 | + allowIdpInitiated?: boolean; |
| 34 | + allowSubdomains?: boolean; |
| 35 | + attributeMapping?: EnterpriseConnectionSamlAttributeMappingParams; |
| 36 | + forceAuthn?: boolean; |
| 37 | + idpCertificate?: string; |
| 38 | + idpEntityId?: string; |
| 39 | + idpMetadata?: string; |
| 40 | + idpMetadataUrl?: string; |
| 41 | + idpSsoUrl?: string; |
| 42 | +} |
| 43 | + |
| 44 | +type CreateEnterpriseConnectionParams = { |
| 45 | + name?: string; |
| 46 | + domains?: string[]; |
| 47 | + organizationId?: string; |
| 48 | + active?: boolean; |
| 49 | + syncUserAttributes?: boolean; |
| 50 | + oidc?: EnterpriseConnectionOidcParams; |
| 51 | + saml?: EnterpriseConnectionSamlParams; |
| 52 | +}; |
| 53 | + |
| 54 | +type UpdateEnterpriseConnectionParams = { |
| 55 | + name?: string; |
| 56 | + domains?: string[]; |
| 57 | + organizationId?: string; |
| 58 | + active?: boolean; |
| 59 | + syncUserAttributes?: boolean; |
| 60 | + provider?: string; |
| 61 | + oidc?: EnterpriseConnectionOidcParams; |
| 62 | + saml?: EnterpriseConnectionSamlParams; |
| 63 | +}; |
| 64 | + |
| 65 | +export class EnterpriseConnectionAPI extends AbstractAPI { |
| 66 | + public async createEnterpriseConnection(params: CreateEnterpriseConnectionParams) { |
| 67 | + return this.request<EnterpriseConnection>({ |
| 68 | + method: 'POST', |
| 69 | + path: basePath, |
| 70 | + bodyParams: params, |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + public async updateEnterpriseConnection(enterpriseConnectionId: string, params: UpdateEnterpriseConnectionParams) { |
| 75 | + this.requireId(enterpriseConnectionId); |
| 76 | + return this.request<EnterpriseConnection>({ |
| 77 | + method: 'PATCH', |
| 78 | + path: joinPaths(basePath, enterpriseConnectionId), |
| 79 | + bodyParams: params, |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + public async getEnterpriseConnectionList(params: EnterpriseConnectionListParams = {}) { |
| 84 | + return this.request<PaginatedResourceResponse<EnterpriseConnection[]>>({ |
| 85 | + method: 'GET', |
| 86 | + path: basePath, |
| 87 | + queryParams: params, |
| 88 | + }); |
| 89 | + } |
| 90 | + |
| 91 | + public async getEnterpriseConnection(enterpriseConnectionId: string) { |
| 92 | + this.requireId(enterpriseConnectionId); |
| 93 | + return this.request<EnterpriseConnection>({ |
| 94 | + method: 'GET', |
| 95 | + path: joinPaths(basePath, enterpriseConnectionId), |
| 96 | + }); |
| 97 | + } |
| 98 | + |
| 99 | + public async deleteEnterpriseConnection(enterpriseConnectionId: string) { |
| 100 | + this.requireId(enterpriseConnectionId); |
| 101 | + return this.request<EnterpriseConnection>({ |
| 102 | + method: 'DELETE', |
| 103 | + path: joinPaths(basePath, enterpriseConnectionId), |
| 104 | + }); |
| 105 | + } |
| 106 | +} |
0 commit comments