From dadc11d3ed4e5917495070f23bf80fff63542c58 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Wed, 11 Jun 2025 14:46:40 +0530 Subject: [PATCH] Add getEnabledConnections method and related types to ClientsManager --- .../__generated/managers/clients-manager.ts | 64 +++++++ src/management/__generated/models/index.ts | 119 +++++++++++++ test/management/client.test.ts | 168 +++++++++++++++++- 3 files changed, 350 insertions(+), 1 deletion(-) diff --git a/src/management/__generated/managers/clients-manager.ts b/src/management/__generated/managers/clients-manager.ts index 24098e10cd..dfb8e51829 100644 --- a/src/management/__generated/managers/clients-manager.ts +++ b/src/management/__generated/managers/clients-manager.ts @@ -4,6 +4,7 @@ import type { Client, ClientCreate, ClientUpdate, + GetClientConnections200Response, GetClients200Response, GetCredentials200ResponseInner, PatchCredentialsByCredentialIdRequest, @@ -11,6 +12,7 @@ import type { GetClients200ResponseOneOf, DeleteClientsByIdRequest, DeleteCredentialsByCredentialIdRequest, + GetClientConnectionsRequest, GetClientsRequest, GetClientsByIdRequest, GetCredentialsRequest, @@ -78,6 +80,68 @@ export class ClientsManager extends BaseAPI { return runtime.VoidApiResponse.fromResponse(response); } + /** + * Retrieve all connections that are enabled for the specified Application, using checkpoint pagination. A list of fields to include or exclude for each connection may also be specified. + * + * + * Get enabled connections for a client + * + * @throws {RequiredError} + */ + async getEnabledConnections( + requestParameters: GetClientConnectionsRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['client_id']); + + const queryParameters = runtime.applyQueryParams(requestParameters, [ + { + key: 'strategy', + config: { + isArray: true, + isCollectionFormatMulti: true, + }, + }, + { + key: 'from', + config: {}, + }, + { + key: 'take', + config: {}, + }, + { + key: 'fields', + config: {}, + }, + { + key: 'include_fields', + config: {}, + }, + ]); + + const response = await this.request( + { + path: `/clients/{client_id}/connections`.replace( + '{client_id}', + encodeURIComponent(String(requestParameters.client_id)) + ), + method: 'GET', + query: queryParameters, + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + /** * Retrieve clients (applications and SSO integrations) matching provided filters. A list of fields to include or exclude may also be specified. * For more information, read Applications in Auth0 and Single Sign-On. diff --git a/src/management/__generated/models/index.ts b/src/management/__generated/models/index.ts index 051e25d9b8..57cb7d0d39 100644 --- a/src/management/__generated/models/index.ts +++ b/src/management/__generated/models/index.ts @@ -5477,6 +5477,20 @@ export type GetBruteForceProtection200ResponseModeEnum = * */ export type GetBruteForceProtection200ResponseAllowlistInner = any; +/** + * + */ +export interface GetClientConnections200Response { + [key: string]: any | any; + /** + */ + connections: Array; + /** + * Encoded next token + * + */ + next?: string; +} /** * */ @@ -18114,6 +18128,111 @@ export interface DeleteCredentialsByCredentialIdRequest { */ credential_id: string; } + +/** + * + */ +export const GetClientConnectionsStrategyEnum = { + ad: 'ad', + adfs: 'adfs', + amazon: 'amazon', + apple: 'apple', + dropbox: 'dropbox', + bitbucket: 'bitbucket', + aol: 'aol', + auth0_oidc: 'auth0-oidc', + auth0: 'auth0', + baidu: 'baidu', + bitly: 'bitly', + box: 'box', + custom: 'custom', + daccount: 'daccount', + dwolla: 'dwolla', + email: 'email', + evernote_sandbox: 'evernote-sandbox', + evernote: 'evernote', + exact: 'exact', + facebook: 'facebook', + fitbit: 'fitbit', + flickr: 'flickr', + github: 'github', + google_apps: 'google-apps', + google_oauth2: 'google-oauth2', + instagram: 'instagram', + ip: 'ip', + line: 'line', + linkedin: 'linkedin', + miicard: 'miicard', + oauth1: 'oauth1', + oauth2: 'oauth2', + office365: 'office365', + oidc: 'oidc', + okta: 'okta', + paypal: 'paypal', + paypal_sandbox: 'paypal-sandbox', + pingfederate: 'pingfederate', + planningcenter: 'planningcenter', + renren: 'renren', + salesforce_community: 'salesforce-community', + salesforce_sandbox: 'salesforce-sandbox', + salesforce: 'salesforce', + samlp: 'samlp', + sharepoint: 'sharepoint', + shopify: 'shopify', + sms: 'sms', + soundcloud: 'soundcloud', + thecity_sandbox: 'thecity-sandbox', + thecity: 'thecity', + thirtysevensignals: 'thirtysevensignals', + twitter: 'twitter', + untappd: 'untappd', + vkontakte: 'vkontakte', + waad: 'waad', + weibo: 'weibo', + windowslive: 'windowslive', + wordpress: 'wordpress', + yahoo: 'yahoo', + yammer: 'yammer', + yandex: 'yandex', +} as const; +export type GetClientConnectionsStrategyEnum = + (typeof GetClientConnectionsStrategyEnum)[keyof typeof GetClientConnectionsStrategyEnum]; + +/** + * + */ +export interface GetClientConnectionsRequest { + /** + * ID of the client for which to retrieve enabled connections. + * + */ + client_id: string; + /** + * Provide strategies to only retrieve connections with such strategies + * + */ + strategy?: Array; + /** + * Optional Id from which to start selection. + * + */ + from?: string; + /** + * Number of results per page. Defaults to 50. + * + */ + take?: number; + /** + * A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields + * + */ + fields?: string; + /** + * true if the fields specified are to be included in the result, false otherwise (defaults to true) + * + */ + include_fields?: boolean; +} /** * */ diff --git a/test/management/client.test.ts b/test/management/client.test.ts index c3fee039cb..f4de9620c1 100644 --- a/test/management/client.test.ts +++ b/test/management/client.test.ts @@ -13,6 +13,7 @@ import { PostCredentialsRequest, ManagementClient, GetClientsRequest, + GetClientConnectionsStrategyEnum, } from '../../src/index.js'; import { RequiredError } from '../../src/lib/errors.js'; @@ -36,7 +37,20 @@ describe('ClientsManager', () => { }); describe('instance', () => { - const methods = ['getAll', 'get', 'create', 'update', 'delete']; + const methods = [ + 'getAll', + 'get', + 'create', + 'update', + 'delete', + 'rotateClientSecret', + 'getCredentials', + 'getCredential', + 'createCredential', + 'updateCredential', + 'deleteCredential', + 'getEnabledConnections', + ]; methods.forEach((method) => { it(`should have a ${method} method`, () => { @@ -818,4 +832,156 @@ describe('ClientsManager', () => { }); }); }); + + describe('#getEnabledConnections', () => { + const clientId = 'client_123'; + const baseConnection = { + id: 'con_UJfFHnhzQJDdCA8l', + options: { + scope: ['email', 'openid'], + scripts: { fetchUserProfile: 'function( { return callback(null) }' }, + icon_url: 'https://cdn.paypal.com/assets/logo.png', + tokenURL: 'https://api.paypal.com/v1/oauth2/token', + client_id: '1234567', + pkce_enabled: false, + client_secret: '1234567', + customHeaders: { bar: 'try', faz: 'b43' }, + authorizationURL: 'https://www.paypal.com/signin/authorize', + set_user_root_attributes: 'on_first_login', + }, + strategy: 'oauth2', + name: 'Acceptance232445533', + is_domain_connection: false, + realms: ['Acceptance232445533'], + }; + const response = { connections: [baseConnection] }; + let request: nock.Scope; + + beforeEach(() => { + request = nock(API_URL).get(`/clients/${clientId}/connections`).reply(200, response); + }); + + it('should return a promise if no callback is given', (done) => { + clients + .getEnabledConnections({ client_id: clientId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should perform a GET request to /api/v2/clients/:client_id/connections', (done) => { + clients.getEnabledConnections({ client_id: clientId }).then(() => { + expect(request.isDone()).toBe(true); + done(); + }); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).get(`/clients/${clientId}/connections`).reply(500, {}); + clients.getEnabledConnections({ client_id: clientId }).catch((err) => { + expect(err).toBeDefined(); + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + const request = nock(API_URL) + .get(`/clients/${clientId}/connections`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + clients.getEnabledConnections({ client_id: clientId }).then(() => { + expect(request.isDone()).toBe(true); + done(); + }); + }); + + it('should pass the parameters in the query-string', (done) => { + nock.cleanAll(); + const client_id = clientId; + const queryParameters = { + strategy: [GetClientConnectionsStrategyEnum.oauth2], + from: '', + take: 1, + }; + const nockQuery = { + strategy: GetClientConnectionsStrategyEnum.oauth2, + from: '', + take: 1, + }; + const apiResponse = { + connections: [baseConnection], + next: 'next_token_123', + }; + const request = nock(API_URL) + .get(`/clients/${client_id}/connections`) + .query(nockQuery) + .reply(200, apiResponse); + clients.getEnabledConnections({ client_id, ...queryParameters }).then((res) => { + expect(request.isDone()).toBe(true); + expect(res.data).toBeDefined(); + expect(Array.isArray(res.data.connections)).toBe(true); + expect(res.data.connections[0]).toMatchObject(baseConnection); + done(); + }); + }); + + it('should send correct query params and handle object response with connections array', (done) => { + const queryParameters = { + strategy: [GetClientConnectionsStrategyEnum.oauth2], + from: 'prev_token_123', + take: 1, + }; + const nockQuery = { + strategy: GetClientConnectionsStrategyEnum.oauth2, + from: 'prev_token_123', + take: 1, + }; + const apiResponse = { + connections: [baseConnection], + next: 'next_token_123', + }; + const request = nock(API_URL) + .get(`/clients/${clientId}/connections`) + .query(nockQuery) + .reply(200, apiResponse); + clients.getEnabledConnections({ client_id: clientId, ...queryParameters }).then((res) => { + expect(request.isDone()).toBe(true); + expect(res.data).toBeDefined(); + expect(Array.isArray(res.data.connections)).toBe(true); + expect(res.data.connections[0]).toMatchObject(baseConnection); + expect(res.data.next).toBe('next_token_123'); + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + const client_id = clientId; + const responseObj = { connections: [baseConnection] }; + nock.cleanAll(); + const request = nock(API_URL) + .get(`/clients/${client_id}/connections`) + .reply(200, responseObj); + clients.getEnabledConnections({ client_id }).then((res) => { + expect(request.isDone()).toBe(true); + expect(res.data).toBeDefined(); + expect(Array.isArray(res.data.connections)).toBe(true); + expect(res.data.connections[0]).toMatchObject(baseConnection); + done(); + }); + }); + + it('should handle API responses with a connections array', (done) => { + nock.cleanAll(); + const apiResponse = { connections: [baseConnection] }; + const request = nock(API_URL).get(`/clients/${clientId}/connections`).reply(200, apiResponse); + clients.getEnabledConnections({ client_id: clientId }).then((res) => { + expect(request.isDone()).toBe(true); + expect(res.data).toBeDefined(); + expect(Array.isArray(res.data.connections)).toBe(true); + expect(res.data.connections[0]).toMatchObject(baseConnection); + done(); + }); + }); + }); });