UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

193 lines • 8.22 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import { CloudflareError } from "../../../../core/error.mjs"; import { V4PagePaginationArray, } from "../../../../core/pagination.mjs"; import { path } from "../../../../internal/utils/path.mjs"; export var BasePolicies = /* @__PURE__ */ (() => { class BasePolicies extends APIResource { /** * Creates a policy applying exclusive to a single application that defines the * users or groups who can reach it. We recommend creating a reusable policy * instead and subsequently referencing its ID in the application's 'policies' * array. * * @example * ```ts * const policy = * await client.zeroTrust.access.applications.policies.create( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * ); * ``` */ create(appID, 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(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}/policies`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates an Access policy specific to an application. To update a reusable * policy, use the /account or zones/{account or zone_id}/policies/{uid} endpoint. * * @example * ```ts * const policy = * await client.zeroTrust.access.applications.policies.update( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * app_id: 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * account_id: 'account_id', * mfa_config: { * allowed_authenticators: ['ssh_fido2_key'], * }, * }, * ); * ``` */ update(policyID, params, options) { const { app_id, 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(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${app_id}/policies/${policyID}`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Lists Access policies configured for an application. Returns both exclusively * scoped and reusable policies used by the application. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const policyListResponse of client.zeroTrust.access.applications.policies.list( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(appID, params = {}, options) { const { account_id, zone_id, ...query } = 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(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}/policies`, (V4PagePaginationArray), { query, ...options }); } /** * Deletes an Access policy specific to an application. To delete a reusable * policy, use the /account or zones/{account or zone_id}/policies/{uid} endpoint. * * @example * ```ts * const policy = * await client.zeroTrust.access.applications.policies.delete( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * app_id: 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * account_id: 'account_id', * }, * ); * ``` */ delete(policyID, params, options) { const { app_id, 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(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${app_id}/policies/${policyID}`, options)._thenUnwrap((obj) => obj.result); } /** * Fetches a single Access policy configured for an application. Returns both * exclusively owned and reusable policies used by the application. * * @example * ```ts * const policy = * await client.zeroTrust.access.applications.policies.get( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * app_id: 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * account_id: 'account_id', * }, * ); * ``` */ get(policyID, params, options) { const { app_id, 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(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${app_id}/policies/${policyID}`, options)._thenUnwrap((obj) => obj.result); } } BasePolicies._key = Object.freeze(['zeroTrust', 'access', 'applications', 'policies']); return BasePolicies; })(); export class Policies extends BasePolicies { } //# sourceMappingURL=policies.mjs.map