cloudflare
Version:
The official TypeScript library for the Cloudflare API
160 lines • 6.1 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as DOHAPI from "./doh.mjs";
import { BaseDOH, DOH } from "./doh.mjs";
import { CloudflareError } from "../../../core/error.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseOrganizations = /* @__PURE__ */ (() => {
class BaseOrganizations extends 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 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/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 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/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 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/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 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/organizations/revoke_user`, {
query: { devices: query_devices },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
}
BaseOrganizations._key = Object.freeze([
'zeroTrust',
'organizations',
]);
return BaseOrganizations;
})();
export var Organizations = /* @__PURE__ */ (() => {
class Organizations extends BaseOrganizations {
constructor() {
super(...arguments);
this.doh = new DOHAPI.DOH(this._client);
}
}
Organizations.DOH = DOH;
Organizations.BaseDOH = BaseDOH;
return Organizations;
})();
//# sourceMappingURL=organizations.mjs.map