UNPKG

auth0

Version:

Auth0 Node.js SDK for the Management API v2.

374 lines (373 loc) 25.7 kB
// This file was auto-generated by Fern from our API Definition. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs"; import * as core from "../../../../core/index.mjs"; import { mergeHeaders } from "../../../../core/headers.mjs"; import * as environments from "../../../../environments.mjs"; import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs"; import * as errors from "../../../../errors/index.mjs"; import * as Management from "../../../index.mjs"; export class TokenExchangeProfilesClient { constructor(options) { this._options = normalizeClientOptionsWithAuth(options); } /** * Retrieve a list of all Token Exchange Profiles available in your tenant. * * By using this feature, you agree to the applicable Free Trial terms in <a href="https://www.okta.com/legal/">Okta’s Master Subscription Agreement</a>. It is your responsibility to securely validate the user’s subject_token. See <a href="https://auth0.com/docs/authenticate/custom-token-exchange">User Guide</a> for more details. * * This endpoint supports Checkpoint pagination. To search by checkpoint, use the following parameters: * <ul> * <li><code>from</code>: Optional id from which to start selection.</li> * <li><code>take</code>: The total amount of entries to retrieve when using the from parameter. Defaults to 50.</li> * </ul> * * <b>Note</b>: The first time you call this endpoint using checkpoint pagination, omit the <code>from</code> parameter. If there are more results, a <code>next</code> value is included in the response. You can use this for subsequent API calls. When <code>next</code> is no longer included in the response, no pages are remaining. * * @param {Management.TokenExchangeProfilesListRequest} request * @param {TokenExchangeProfilesClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.tokenExchangeProfiles.list({ * from: "from", * take: 1 * }) */ list() { return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) { const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const { from: from_, take = 50 } = request; const _queryParams = {}; if (from_ !== undefined) { _queryParams["from"] = from_; } if (take !== undefined) { _queryParams["take"] = (_a = take === null || take === void 0 ? void 0 : take.toString()) !== null && _a !== void 0 ? _a : null; } const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = mergeHeaders(_authRequest.headers, (_b = this._options) === null || _b === void 0 ? void 0 : _b.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_c = this._options.fetcher) !== null && _c !== void 0 ? _c : core.fetcher)({ url: core.url.join((_e = (_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.ManagementEnvironment.Default, "token-exchange-profiles"), method: "GET", headers: _headers, queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams), timeoutMs: ((_h = (_f = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _f !== void 0 ? _f : (_g = this._options) === null || _g === void 0 ? void 0 : _g.timeoutInSeconds) !== null && _h !== void 0 ? _h : 60) * 1000, maxRetries: (_j = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _j !== void 0 ? _j : (_k = this._options) === null || _k === void 0 ? void 0 : _k.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_l = this._options) === null || _l === void 0 ? void 0 : _l.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/token-exchange-profiles"); })); const dataWithRawResponse = yield list(request).withRawResponse(); return new core.Page({ response: dataWithRawResponse.data, rawResponse: dataWithRawResponse.rawResponse, hasNextPage: (response) => (response === null || response === void 0 ? void 0 : response.next) != null && !(typeof (response === null || response === void 0 ? void 0 : response.next) === "string" && (response === null || response === void 0 ? void 0 : response.next) === ""), getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.token_exchange_profiles) !== null && _a !== void 0 ? _a : []; }, loadPage: (response) => { return list(core.setObjectProperty(request, "from", response === null || response === void 0 ? void 0 : response.next)); }, }); }); } /** * Create a new Token Exchange Profile within your tenant. * * By using this feature, you agree to the applicable Free Trial terms in <a href="https://www.okta.com/legal/">Okta’s Master Subscription Agreement</a>. It is your responsibility to securely validate the user’s subject_token. See <a href="https://auth0.com/docs/authenticate/custom-token-exchange">User Guide</a> for more details. * * @param {Management.CreateTokenExchangeProfileRequestContent} request * @param {TokenExchangeProfilesClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.ConflictError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.tokenExchangeProfiles.create({ * name: "name", * subject_token_type: "subject_token_type", * action_id: "action_id" * }) */ create(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions)); } __create(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, "token-exchange-profiles"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: Object.assign(Object.assign({}, request), { type: "custom_authentication" }), timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 409: throw new Management.ConflictError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/token-exchange-profiles"); }); } /** * Retrieve details about a single Token Exchange Profile specified by ID. * * By using this feature, you agree to the applicable Free Trial terms in <a href="https://www.okta.com/legal/">Okta’s Master Subscription Agreement</a>. It is your responsibility to securely validate the user’s subject_token. See <a href="https://auth0.com/docs/authenticate/custom-token-exchange">User Guide</a> for more details. * * @param {string} id - ID of the Token Exchange Profile to retrieve. * @param {TokenExchangeProfilesClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.NotFoundError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.tokenExchangeProfiles.get("id") */ get(id, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__get(id, requestOptions)); } __get(id, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `token-exchange-profiles/${core.url.encodePathParam(id)}`), method: "GET", headers: _headers, queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 404: throw new Management.NotFoundError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/token-exchange-profiles/{id}"); }); } /** * Delete a Token Exchange Profile within your tenant. * * By using this feature, you agree to the applicable Free Trial terms in <a href="https://www.okta.com/legal/">Okta's Master Subscription Agreement</a>. It is your responsibility to securely validate the user's subject_token. See <a href="https://auth0.com/docs/authenticate/custom-token-exchange">User Guide</a> for more details. * * * @param {string} id - ID of the Token Exchange Profile to delete. * @param {TokenExchangeProfilesClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.tokenExchangeProfiles.delete("id") */ delete(id, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__delete(id, requestOptions)); } __delete(id, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `token-exchange-profiles/${core.url.encodePathParam(id)}`), method: "DELETE", headers: _headers, queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: undefined, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/token-exchange-profiles/{id}"); }); } /** * Update a Token Exchange Profile within your tenant. * * By using this feature, you agree to the applicable Free Trial terms in <a href="https://www.okta.com/legal/">Okta's Master Subscription Agreement</a>. It is your responsibility to securely validate the user's subject_token. See <a href="https://auth0.com/docs/authenticate/custom-token-exchange">User Guide</a> for more details. * * * @param {string} id - ID of the Token Exchange Profile to update. * @param {Management.UpdateTokenExchangeProfileRequestContent} request * @param {TokenExchangeProfilesClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Management.BadRequestError} * @throws {@link Management.UnauthorizedError} * @throws {@link Management.ForbiddenError} * @throws {@link Management.NotFoundError} * @throws {@link Management.TooManyRequestsError} * * @example * await client.tokenExchangeProfiles.update("id") */ update(id, request = {}, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__update(id, request, requestOptions)); } __update(id_1) { return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); let _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ManagementEnvironment.Default, `token-exchange-profiles/${core.url.encodePathParam(id)}`), method: "PATCH", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: undefined, rawResponse: _response.rawResponse }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Management.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Management.UnauthorizedError(_response.error.body, _response.rawResponse); case 403: throw new Management.ForbiddenError(_response.error.body, _response.rawResponse); case 404: throw new Management.NotFoundError(_response.error.body, _response.rawResponse); case 429: throw new Management.TooManyRequestsError(_response.error.body, _response.rawResponse); default: throw new errors.ManagementError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return handleNonStatusCodeError(_response.error, _response.rawResponse, "PATCH", "/token-exchange-profiles/{id}"); }); } }