UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

197 lines • 7.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccessRules = exports.BaseAccessRules = 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 BaseAccessRules = /* @__PURE__ */ (() => { class BaseAccessRules extends resource_1.APIResource { /** * Creates a new IP Access rule for an account or zone. The rule will apply to all * zones in the account or zone. * * Note: To create an IP Access rule that applies to a single zone, refer to the * [IP Access rules for a zone](#ip-access-rules-for-a-zone) endpoints. * * @example * ```ts * const accessRule = await client.firewall.accessRules.create( * { * configuration: {}, * mode: 'challenge', * account_id: 'account_id', * }, * ); * ``` */ create(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}/firewall/access_rules/rules`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Fetches IP Access rules of an account or zone. These rules apply to all the * zones in the account or zone. You can filter the results using several optional * parameters. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const accessRuleListResponse of client.firewall.accessRules.list( * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(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}/firewall/access_rules/rules`, (pagination_1.V4PagePaginationArray), { query, ...options }); } /** * Deletes an existing IP Access rule defined. * * Note: This operation will affect all zones in the account or zone. * * @example * ```ts * const accessRule = await client.firewall.accessRules.delete( * '023e105f4ecef8ad9ca31a8372d0c353', * { account_id: 'account_id' }, * ); * ``` */ delete(ruleID, params = {}, options) { const { 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}/firewall/access_rules/rules/${ruleID}`, options)._thenUnwrap((obj) => obj.result); } /** * Updates an IP Access rule defined. * * Note: This operation will affect all zones in the account or zone. * * @example * ```ts * const response = await client.firewall.accessRules.edit( * '023e105f4ecef8ad9ca31a8372d0c353', * { * configuration: {}, * mode: 'challenge', * account_id: 'account_id', * }, * ); * ``` */ edit(ruleID, 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.patch((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/firewall/access_rules/rules/${ruleID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Fetches the details of an IP Access rule defined. * * @example * ```ts * const accessRule = await client.firewall.accessRules.get( * '023e105f4ecef8ad9ca31a8372d0c353', * { account_id: 'account_id' }, * ); * ``` */ get(ruleID, params = {}, options) { const { 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}/firewall/access_rules/rules/${ruleID}`, options)._thenUnwrap((obj) => obj.result); } } BaseAccessRules._key = Object.freeze([ 'firewall', 'accessRules', ]); return BaseAccessRules; })(); exports.BaseAccessRules = BaseAccessRules; class AccessRules extends BaseAccessRules { } exports.AccessRules = AccessRules; //# sourceMappingURL=access-rules.js.map