@@ -2,8 +2,20 @@ import type {
22 AddMemberParams ,
33 ClerkPaginatedResponse ,
44 ClerkResourceReloadParams ,
5+ CreateOrganizationEnterpriseConnectionParams ,
56 CreateOrganizationParams ,
7+ DeletedObjectJSON ,
8+ DeletedObjectResource ,
9+ EnterpriseConnectionJSON ,
10+ EnterpriseConnectionResource ,
11+ EnterpriseConnectionTestRunInitJSON ,
12+ EnterpriseConnectionTestRunInitResource ,
13+ EnterpriseConnectionTestRunJSON ,
14+ EnterpriseConnectionTestRunResource ,
15+ EnterpriseConnectionTestRunsPaginatedJSON ,
616 GetDomainsParams ,
17+ GetEnterpriseConnectionsParams ,
18+ GetEnterpriseConnectionTestRunsParams ,
719 GetInvitationsParams ,
820 GetMembershipRequestParams ,
921 GetMemberships ,
@@ -23,13 +35,22 @@ import type {
2335 RoleJSON ,
2436 SetOrganizationLogoParams ,
2537 UpdateMembershipParams ,
38+ UpdateOrganizationEnterpriseConnectionParams ,
2639 UpdateOrganizationParams ,
2740} from '@clerk/shared/types' ;
2841
2942import { convertPageToOffsetSearchParams } from '../../utils/convertPageToOffsetSearchParams' ;
3043import { unixEpochToDate } from '../../utils/date' ;
44+ import { toEnterpriseConnectionBody } from '../../utils/enterpriseConnection' ;
3145import { addPaymentMethod , getPaymentMethods , initializePaymentMethod } from '../modules/billing' ;
32- import { BaseResource , OrganizationInvitation , OrganizationMembership } from './internal' ;
46+ import {
47+ BaseResource ,
48+ DeletedObject ,
49+ EnterpriseConnection ,
50+ EnterpriseConnectionTestRun ,
51+ OrganizationInvitation ,
52+ OrganizationMembership ,
53+ } from './internal' ;
3354import { OrganizationDomain } from './OrganizationDomain' ;
3455import { OrganizationMembershipRequest } from './OrganizationMembershipRequest' ;
3556import { Role } from './Role' ;
@@ -142,6 +163,107 @@ export class Organization extends BaseResource implements OrganizationResource {
142163 return new OrganizationDomain ( json ) ;
143164 } ;
144165
166+ getEnterpriseConnections = async (
167+ params ?: GetEnterpriseConnectionsParams ,
168+ ) : Promise < EnterpriseConnectionResource [ ] > => {
169+ const { withOrganizationAccountLinking } = params || { } ;
170+
171+ const json = (
172+ await BaseResource . _fetch ( {
173+ path : `/organizations/${ this . id } /enterprise_connections` ,
174+ method : 'GET' ,
175+ ...( withOrganizationAccountLinking !== undefined
176+ ? {
177+ search : {
178+ with_organization_account_linking : String ( withOrganizationAccountLinking ) ,
179+ } ,
180+ }
181+ : { } ) ,
182+ } )
183+ ) ?. response as unknown as EnterpriseConnectionJSON [ ] ;
184+
185+ return ( json || [ ] ) . map ( connection => new EnterpriseConnection ( connection ) ) ;
186+ } ;
187+
188+ createEnterpriseConnection = async (
189+ params : CreateOrganizationEnterpriseConnectionParams ,
190+ ) : Promise < EnterpriseConnectionResource > => {
191+ const json = (
192+ await BaseResource . _fetch < EnterpriseConnectionJSON > ( {
193+ path : `/organizations/${ this . id } /enterprise_connections` ,
194+ method : 'POST' ,
195+ body : toEnterpriseConnectionBody ( params , { omitOrganizationId : true } ) as any ,
196+ } )
197+ ) ?. response as unknown as EnterpriseConnectionJSON ;
198+
199+ return new EnterpriseConnection ( json ) ;
200+ } ;
201+
202+ updateEnterpriseConnection = async (
203+ enterpriseConnectionId : string ,
204+ params : UpdateOrganizationEnterpriseConnectionParams ,
205+ ) : Promise < EnterpriseConnectionResource > => {
206+ const json = (
207+ await BaseResource . _fetch < EnterpriseConnectionJSON > ( {
208+ path : `/organizations/${ this . id } /enterprise_connections/${ enterpriseConnectionId } ` ,
209+ method : 'PATCH' ,
210+ body : toEnterpriseConnectionBody ( params , { omitOrganizationId : true } ) as any ,
211+ } )
212+ ) ?. response as unknown as EnterpriseConnectionJSON ;
213+
214+ return new EnterpriseConnection ( json ) ;
215+ } ;
216+
217+ deleteEnterpriseConnection = async ( enterpriseConnectionId : string ) : Promise < DeletedObjectResource > => {
218+ const json = (
219+ await BaseResource . _fetch < DeletedObjectJSON > ( {
220+ path : `/organizations/${ this . id } /enterprise_connections/${ enterpriseConnectionId } ` ,
221+ method : 'DELETE' ,
222+ } )
223+ ) ?. response as unknown as DeletedObjectJSON ;
224+
225+ return new DeletedObject ( json ) ;
226+ } ;
227+
228+ createEnterpriseConnectionTestRun = async (
229+ enterpriseConnectionId : string ,
230+ ) : Promise < EnterpriseConnectionTestRunInitResource > => {
231+ const json = (
232+ await BaseResource . _fetch ( {
233+ path : `/organizations/${ this . id } /enterprise_connections/${ enterpriseConnectionId } /test_runs` ,
234+ method : 'POST' ,
235+ } )
236+ ) ?. response as unknown as EnterpriseConnectionTestRunInitJSON ;
237+
238+ return { url : json . url } ;
239+ } ;
240+
241+ getEnterpriseConnectionTestRuns = async (
242+ enterpriseConnectionId : string ,
243+ params ?: GetEnterpriseConnectionTestRunsParams ,
244+ ) : Promise < ClerkPaginatedResponse < EnterpriseConnectionTestRunResource > > => {
245+ const { status, ...rest } = params || { } ;
246+ const search = convertPageToOffsetSearchParams ( rest ) ;
247+ if ( status ?. length ) {
248+ for ( const s of status ) {
249+ search . append ( 'status' , s ) ;
250+ }
251+ }
252+
253+ const res = await BaseResource . _fetch ( {
254+ path : `/organizations/${ this . id } /enterprise_connections/${ enterpriseConnectionId } /test_runs` ,
255+ method : 'GET' ,
256+ search,
257+ } ) ;
258+
259+ const payload = res ?. response as unknown as EnterpriseConnectionTestRunsPaginatedJSON | undefined ;
260+
261+ return {
262+ total_count : payload ?. total_count ?? 0 ,
263+ data : ( payload ?. data ?? [ ] ) . map ( ( row : EnterpriseConnectionTestRunJSON ) => new EnterpriseConnectionTestRun ( row ) ) ,
264+ } ;
265+ } ;
266+
145267 getMembershipRequests = async (
146268 getRequestParam ?: GetMembershipRequestParams ,
147269 ) : Promise < ClerkPaginatedResponse < OrganizationMembershipRequestResource > > => {
0 commit comments