cloudflare
Version:
The official TypeScript library for the Cloudflare API
181 lines • 6.92 kB
JavaScript
// 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 BaseGroups = /* @__PURE__ */ (() => {
class BaseGroups extends APIResource {
/**
* Creates a new Access group.
*
* @example
* ```ts
* const group = await client.zeroTrust.access.groups.create({
* include: [{ certificate: {} }],
* 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(path `/${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: [{ certificate: {} }],
* 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(path `/${accountOrZone}/${accountOrZoneId}/access/groups/${groupID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists all Access groups.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const groupListResponse of client.zeroTrust.access.groups.list(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
list(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/groups`, (V4PagePaginationArray), { query, ...options });
}
/**
* Deletes an Access group.
*
* @example
* ```ts
* const group = await client.zeroTrust.access.groups.delete(
* 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
* { account_id: 'account_id' },
* );
* ```
*/
delete(groupID, params = {}, options) {
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(path `/${accountOrZone}/${accountOrZoneId}/access/groups/${groupID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Fetches a single Access group.
*
* @example
* ```ts
* const group = await client.zeroTrust.access.groups.get(
* 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
* { account_id: 'account_id' },
* );
* ```
*/
get(groupID, params = {}, options) {
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(path `/${accountOrZone}/${accountOrZoneId}/access/groups/${groupID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseGroups._key = Object.freeze([
'zeroTrust',
'access',
'groups',
]);
return BaseGroups;
})();
export class Groups extends BaseGroups {
}
//# sourceMappingURL=groups.mjs.map