cloudflare
Version:
The official TypeScript library for the Cloudflare API
198 lines • 8.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Policies = exports.BasePolicies = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../../core/resource.js");
const error_1 = require("../../../../core/error.js");
const pagination_1 = require("../../../../core/pagination.js");
const path_1 = require("../../../../internal/utils/path.js");
var BasePolicies = /* @__PURE__ */ (() => {
class BasePolicies extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}/policies`, (pagination_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/apps/${app_id}/policies/${policyID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BasePolicies._key = Object.freeze(['zeroTrust', 'access', 'applications', 'policies']);
return BasePolicies;
})();
exports.BasePolicies = BasePolicies;
class Policies extends BasePolicies {
}
exports.Policies = Policies;
//# sourceMappingURL=policies.js.map