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. + *
read:connections scope and any one of read:clients or read:client_summary.
+ * from parameter. If there are more results, a next value is included in the response. You can use this for subsequent API calls. When next is no longer included in the response, no further results are remaining.
+ * 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();
+ });
+ });
+ });
});