UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

130 lines 5.3 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from 'cloudflare/resource'; import { isRequestOptions } from 'cloudflare/core'; import { CloudflareError } from 'cloudflare/error'; import * as PoliciesAPI from 'cloudflare/resources/zero-trust/access/applications/policies'; import { SinglePage } from 'cloudflare/pagination'; export class Policies extends APIResource { /** * Create a new Access policy for an application. */ create(uuid, params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new 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(`/${accountOrZone}/${accountOrZoneId}/access/apps/${uuid}/policies`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Update a configured Access policy. */ update(uuid1, uuid, params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new 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(`/${accountOrZone}/${accountOrZoneId}/access/apps/${uuid1}/policies/${uuid}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } list(uuid, params = {}, options) { if (isRequestOptions(params)) { return this.list(uuid, {}, params); } const { account_id, zone_id } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new 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(`/${accountOrZone}/${accountOrZoneId}/access/apps/${uuid}/policies`, ZeroTrustPoliciesSinglePage, options); } delete(uuid1, uuid, params = {}, options) { if (isRequestOptions(params)) { return this.delete(uuid1, uuid, {}, params); } const { account_id, zone_id } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new 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(`/${accountOrZone}/${accountOrZoneId}/access/apps/${uuid1}/policies/${uuid}`, options)._thenUnwrap((obj) => obj.result); } get(uuid1, uuid, params = {}, options) { if (isRequestOptions(params)) { return this.get(uuid1, uuid, {}, params); } const { account_id, zone_id } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new 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(`/${accountOrZone}/${accountOrZoneId}/access/apps/${uuid1}/policies/${uuid}`, options)._thenUnwrap((obj) => obj.result); } } export class ZeroTrustPoliciesSinglePage extends SinglePage { } (function (Policies) { Policies.ZeroTrustPoliciesSinglePage = PoliciesAPI.ZeroTrustPoliciesSinglePage; })(Policies || (Policies = {})); //# sourceMappingURL=policies.mjs.map