UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

205 lines • 8.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IdentityProviders = exports.BaseIdentityProviders = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const SAMLCertificateAPI = tslib_1.__importStar(require("./saml-certificate.js")); const saml_certificate_1 = require("./saml-certificate.js"); const SCIMAPI = tslib_1.__importStar(require("./scim/scim.js")); const scim_1 = require("./scim/scim.js"); const error_1 = require("../../../core/error.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseIdentityProviders = /* @__PURE__ */ (() => { class BaseIdentityProviders extends resource_1.APIResource { /** * Adds a new identity provider to Access. * * @example * ```ts * const identityProvider = * await client.zeroTrust.identityProviders.create({ * config: {}, * name: 'Widget Corps IDP', * type: 'onetimepin', * account_id: 'account_id', * }); * ``` */ create(params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.post((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/identity_providers`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates a configured identity provider. * * @example * ```ts * const identityProvider = * await client.zeroTrust.identityProviders.update( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * config: {}, * name: 'Widget Corps IDP', * type: 'onetimepin', * account_id: 'account_id', * }, * ); * ``` */ update(identityProviderID, params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.put((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/identity_providers/${identityProviderID}`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Lists all configured identity providers. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const identityProviderListResponse of client.zeroTrust.identityProviders.list( * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(params = {}, options) { const { account_id, zone_id, ...query } = params ?? {}; if (!account_id && !zone_id) { throw new error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.getAPIList((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/identity_providers`, (pagination_1.V4PagePaginationArray), { query, ...options }); } /** * Deletes an identity provider from Access. * * @example * ```ts * const identityProvider = * await client.zeroTrust.identityProviders.delete( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * ); * ``` */ delete(identityProviderID, params = {}, options) { const { account_id, zone_id } = params ?? {}; if (!account_id && !zone_id) { throw new error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.delete((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/identity_providers/${identityProviderID}`, options)._thenUnwrap((obj) => obj.result); } /** * Fetches a configured identity provider. * * @example * ```ts * const identityProvider = * await client.zeroTrust.identityProviders.get( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * ); * ``` */ get(identityProviderID, params = {}, options) { const { account_id, zone_id } = params ?? {}; if (!account_id && !zone_id) { throw new error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.get((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/identity_providers/${identityProviderID}`, options)._thenUnwrap((obj) => obj.result); } } BaseIdentityProviders._key = Object.freeze([ 'zeroTrust', 'identityProviders', ]); return BaseIdentityProviders; })(); exports.BaseIdentityProviders = BaseIdentityProviders; var IdentityProviders = /* @__PURE__ */ (() => { class IdentityProviders extends BaseIdentityProviders { constructor() { super(...arguments); this.scim = new SCIMAPI.SCIM(this._client); this.samlCertificate = new SAMLCertificateAPI.SAMLCertificate(this._client); } } IdentityProviders.SCIM = scim_1.SCIM; IdentityProviders.BaseSCIM = scim_1.BaseSCIM; IdentityProviders.SAMLCertificate = saml_certificate_1.SAMLCertificate; IdentityProviders.BaseSAMLCertificate = saml_certificate_1.BaseSAMLCertificate; return IdentityProviders; })(); exports.IdentityProviders = IdentityProviders; //# sourceMappingURL=identity-providers.js.map