UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

166 lines • 6.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Organizations = exports.BaseOrganizations = 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 DOHAPI = tslib_1.__importStar(require("./doh.js")); const doh_1 = require("./doh.js"); const error_1 = require("../../../core/error.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseOrganizations = /* @__PURE__ */ (() => { class BaseOrganizations extends resource_1.APIResource { /** * Sets up a Zero Trust organization for your account or zone. * * @example * ```ts * const organization = * await client.zeroTrust.organizations.create({ * auth_domain: 'test.cloudflareaccess.com', * name: 'Widget Corps Internal Applications', * 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/organizations`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates the configuration for your Zero Trust organization. * * @example * ```ts * const organization = * await client.zeroTrust.organizations.update({ * account_id: 'account_id', * }); * ``` */ update(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/organizations`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns the configuration for your Zero Trust organization. * * @example * ```ts * const organizations = * await client.zeroTrust.organizations.list({ * account_id: 'account_id', * }); * ``` */ list(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/organizations`, options)._thenUnwrap((obj) => obj.result); } /** * Revokes a user's access across all applications. * * @example * ```ts * const response = * await client.zeroTrust.organizations.revokeUsers({ * email: 'test@example.com', * account_id: 'account_id', * }); * ``` */ revokeUsers(params, options) { const { account_id, zone_id, query_devices, ...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/organizations/revoke_user`, { query: { devices: query_devices }, body, ...options, })._thenUnwrap((obj) => obj.result); } } BaseOrganizations._key = Object.freeze([ 'zeroTrust', 'organizations', ]); return BaseOrganizations; })(); exports.BaseOrganizations = BaseOrganizations; var Organizations = /* @__PURE__ */ (() => { class Organizations extends BaseOrganizations { constructor() { super(...arguments); this.doh = new DOHAPI.DOH(this._client); } } Organizations.DOH = doh_1.DOH; Organizations.BaseDOH = doh_1.BaseDOH; return Organizations; })(); exports.Organizations = Organizations; //# sourceMappingURL=organizations.js.map