UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

160 lines 5.93 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../resource.mjs"; import { isRequestOptions } from "../../../core.mjs"; import { CloudflareError } from "../../../error.mjs"; import { V4PagePaginationArray } from "../../../pagination.mjs"; export class Groups extends APIResource { /** * Creates a new Access group. * * @example * ```ts * const group = await client.zeroTrust.access.groups.create({ * include: [ * { * group: { id: 'aa0a4aab-672b-4bdb-bc33-a59f1130a11f' }, * }, * ], * name: 'Allow devs', * account_id: 'account_id', * }); * ``` */ create(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/groups`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates a configured Access group. * * @example * ```ts * const group = await client.zeroTrust.access.groups.update( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * include: [ * { * group: { * id: 'aa0a4aab-672b-4bdb-bc33-a59f1130a11f', * }, * }, * ], * name: 'Allow devs', * account_id: 'account_id', * }, * ); * ``` */ update(groupId, 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/groups/${groupId}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } list(params = {}, options) { if (isRequestOptions(params)) { return this.list({}, params); } 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(`/${accountOrZone}/${accountOrZoneId}/access/groups`, GroupListResponsesV4PagePaginationArray, { query, ...options }); } delete(groupId, params = {}, options) { if (isRequestOptions(params)) { return this.delete(groupId, {}, 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/groups/${groupId}`, options)._thenUnwrap((obj) => obj.result); } get(groupId, params = {}, options) { if (isRequestOptions(params)) { return this.get(groupId, {}, 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/groups/${groupId}`, options)._thenUnwrap((obj) => obj.result); } } export class GroupListResponsesV4PagePaginationArray extends V4PagePaginationArray { } export class ZeroTrustGroupsV4PagePaginationArray extends V4PagePaginationArray { } Groups.GroupListResponsesV4PagePaginationArray = GroupListResponsesV4PagePaginationArray; //# sourceMappingURL=groups.mjs.map