Skip to content

Commit 05684d4

Browse files
authored
Feat: Added Support for M2M Token Quota FF (#1164)
2 parents 9aa7a46 + 53309b1 commit 05684d4

File tree

3 files changed

+242
-0
lines changed

3 files changed

+242
-0
lines changed

src/management/__generated/managers/client-grants-manager.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import type { InitOverride, ApiResponse } from '../../../lib/runtime.js';
33
import type {
44
ClientGrant,
55
ClientGrantCreate,
6+
GetClientGrantOrganizations200Response,
67
GetClientGrants200Response,
78
PatchClientGrantsByIdRequest,
9+
GetClientGrantOrganizations200ResponseOneOf,
10+
GetClientGrantOrganizations200ResponseOneOfInner,
811
GetClientGrants200ResponseOneOf,
912
DeleteClientGrantsByIdRequest,
13+
GetClientGrantOrganizationsRequest,
1014
GetClientGrantsRequest,
1115
PatchClientGrantsByIdOperationRequest,
1216
} from '../models/index.js';
@@ -43,6 +47,63 @@ export class ClientGrantsManager extends BaseAPI {
4347
return runtime.VoidApiResponse.fromResponse(response);
4448
}
4549

50+
/**
51+
* Get the organizations associated to a client grant
52+
*
53+
* @throws {RequiredError}
54+
*/
55+
async getAllOrganizations(
56+
requestParameters: GetClientGrantOrganizationsRequest & { include_totals: true },
57+
initOverrides?: InitOverride
58+
): Promise<ApiResponse<GetClientGrantOrganizations200ResponseOneOf>>;
59+
async getAllOrganizations(
60+
requestParameters?: GetClientGrantOrganizationsRequest,
61+
initOverrides?: InitOverride
62+
): Promise<ApiResponse<Array<GetClientGrantOrganizations200ResponseOneOfInner>>>;
63+
async getAllOrganizations(
64+
requestParameters: GetClientGrantOrganizationsRequest,
65+
initOverrides?: InitOverride
66+
): Promise<ApiResponse<GetClientGrantOrganizations200Response>> {
67+
runtime.validateRequiredRequestParams(requestParameters, ['id']);
68+
69+
const queryParameters = runtime.applyQueryParams(requestParameters, [
70+
{
71+
key: 'page',
72+
config: {},
73+
},
74+
{
75+
key: 'per_page',
76+
config: {},
77+
},
78+
{
79+
key: 'include_totals',
80+
config: {},
81+
},
82+
{
83+
key: 'from',
84+
config: {},
85+
},
86+
{
87+
key: 'take',
88+
config: {},
89+
},
90+
]);
91+
92+
const response = await this.request(
93+
{
94+
path: `/client-grants/{id}/organizations`.replace(
95+
'{id}',
96+
encodeURIComponent(String(requestParameters.id))
97+
),
98+
method: 'GET',
99+
query: queryParameters,
100+
},
101+
initOverrides
102+
);
103+
104+
return runtime.JSONApiResponse.fromResponse(response);
105+
}
106+
46107
/**
47108
* Retrieve <a href="https://auth0.com/docs/api-auth/grant/client-credentials">client grants</a>.
48109
*

src/management/__generated/models/index.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5741,6 +5741,73 @@ export interface GetClientConnections200Response {
57415741
*/
57425742
next?: string;
57435743
}
5744+
/**
5745+
*
5746+
*/
5747+
export type GetClientGrantOrganizations200Response =
5748+
| Array<GetClientGrantOrganizations200ResponseOneOfInner>
5749+
| GetClientGrantOrganizations200ResponseOneOf
5750+
| GetClientGrantOrganizations200ResponseOneOf1;
5751+
/**
5752+
*
5753+
*/
5754+
export interface GetClientGrantOrganizations200ResponseOneOf {
5755+
/**
5756+
*/
5757+
start?: number;
5758+
/**
5759+
*/
5760+
limit?: number;
5761+
/**
5762+
*/
5763+
total?: number;
5764+
/**
5765+
*/
5766+
organizations?: Array<GetClientGrantOrganizations200ResponseOneOfInner>;
5767+
}
5768+
/**
5769+
*
5770+
*/
5771+
export interface GetClientGrantOrganizations200ResponseOneOf1 {
5772+
/**
5773+
* Opaque identifier for use with the <i>from</i> query parameter for the next page of results.<br/>This identifier is valid for 24 hours.
5774+
*
5775+
*/
5776+
next?: string;
5777+
/**
5778+
*/
5779+
organizations?: Array<GetClientGrantOrganizations200ResponseOneOfInner>;
5780+
}
5781+
/**
5782+
*
5783+
*/
5784+
export interface GetClientGrantOrganizations200ResponseOneOfInner {
5785+
[key: string]: any | any;
5786+
/**
5787+
* Organization identifier.
5788+
*
5789+
*/
5790+
id?: string;
5791+
/**
5792+
* The name of this organization.
5793+
*
5794+
*/
5795+
name?: string;
5796+
/**
5797+
* Friendly name of this organization.
5798+
*
5799+
*/
5800+
display_name?: string;
5801+
/**
5802+
*/
5803+
branding?: OrganizationBranding;
5804+
/**
5805+
*/
5806+
metadata?: OrganizationMetadata;
5807+
/**
5808+
*/
5809+
token_quota?: TokenQuota;
5810+
}
57445811
/**
57455812
*
57465813
*/
@@ -9925,6 +9992,40 @@ export interface LogLocationInfo {
99259992
*/
99269993
continent_code: string;
99279994
}
9995+
/**
9996+
* Theme defines how to style the login pages.
9997+
*/
9998+
export interface OrganizationBranding {
9999+
/**
10000+
* URL of logo to display on login page.
10001+
*
10002+
*/
10003+
logo_url?: string;
10004+
/**
10005+
*/
10006+
colors?: OrganizationBrandingColors;
10007+
}
10008+
/**
10009+
* Color scheme used to customize the login pages.
10010+
*/
10011+
export interface OrganizationBrandingColors {
10012+
/**
10013+
* HEX Color for primary elements.
10014+
*
10015+
*/
10016+
primary: string;
10017+
/**
10018+
* HEX Color for background.
10019+
*
10020+
*/
10021+
page_background: string;
10022+
}
10023+
/**
10024+
* Metadata associated with the organization, in the form of an object with string values (max 255 chars). Maximum of 25 metadata properties allowed.
10025+
*/
10026+
export interface OrganizationMetadata {
10027+
[key: string]: any;
10028+
}
992810029
/**
992910030
*
993010031
*/
@@ -19247,6 +19348,41 @@ export interface DeleteClientGrantsByIdRequest {
1924719348
*/
1924819349
id: string;
1924919350
}
19351+
/**
19352+
*
19353+
*/
19354+
export interface GetClientGrantOrganizationsRequest {
19355+
/**
19356+
* ID of the client grant
19357+
*
19358+
*/
19359+
id: string;
19360+
/**
19361+
* Page index of the results to return. First page is 0.
19362+
*
19363+
*/
19364+
page?: number;
19365+
/**
19366+
* Number of results per page. Defaults to 50.
19367+
*
19368+
*/
19369+
per_page?: number;
19370+
/**
19371+
* Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
19372+
*
19373+
*/
19374+
include_totals?: boolean;
19375+
/**
19376+
* Optional Id from which to start selection.
19377+
*
19378+
*/
19379+
from?: string;
19380+
/**
19381+
* Number of results per page. Defaults to 50.
19382+
*
19383+
*/
19384+
take?: number;
19385+
}
1925019386

1925119387
/**
1925219388
*

test/management/client-grants.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,49 @@ describe('ClientGrantsManager', () => {
234234
});
235235
});
236236
});
237+
238+
describe('#getAllOrganizations', () => {
239+
const data = {
240+
id: 'client_grant_id',
241+
};
242+
243+
let scope: nock.Scope;
244+
245+
beforeEach(() => {
246+
scope = nock(API_URL).get(`/client-grants/${data.id}/organizations`).reply(200, []);
247+
});
248+
249+
it('should return a promise when no callback is given', (done) => {
250+
expect(grants.getAllOrganizations(data).then(() => done())).toBeInstanceOf(Promise);
251+
});
252+
253+
it('should perform a GET request to /api/v2/client-grants/client_grant_id/organizations', async () => {
254+
await grants.getAllOrganizations(data);
255+
expect(scope.isDone()).toBe(true);
256+
});
257+
258+
it('should pass any errors to the promise catch handler', async () => {
259+
nock.cleanAll();
260+
261+
nock(API_URL).get(`/client-grants/${data.id}/organizations`).reply(500, {});
262+
263+
try {
264+
await grants.getAllOrganizations(data);
265+
} catch (err) {
266+
expect(err).toBeDefined();
267+
}
268+
});
269+
270+
it('should include the token in the authorization header', async () => {
271+
nock.cleanAll();
272+
273+
const request = nock(API_URL)
274+
.get(`/client-grants/${data.id}/organizations`)
275+
.matchHeader('authorization', `Bearer ${token}`)
276+
.reply(200, []);
277+
278+
await grants.getAllOrganizations(data);
279+
expect(request.isDone()).toBe(true);
280+
});
281+
});
237282
});

0 commit comments

Comments
 (0)