UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

129 lines • 5.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rules = exports.BaseRules = 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 path_1 = require("../../internal/utils/path.js"); var BaseRules = /* @__PURE__ */ (() => { class BaseRules extends resource_1.APIResource { /** * Adds a new rule to an account or zone ruleset. The rule will be added to the end * of the existing list of rules in the ruleset by default. * * @example * ```ts * const rule = await client.rulesets.rules.create( * '2f2feab2026849078ba485f918791bdc', * { account_id: 'account_id' }, * ); * ``` */ create(rulesetID, params, options) { const { account_id, zone_id, dry_run, ...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}/rulesets/${rulesetID}/rules`, { query: { dry_run }, body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Deletes an existing rule from an account or zone ruleset. * * @example * ```ts * const rule = await client.rulesets.rules.delete( * '3a03d665bac047339bb530ecb439a90d', * { * ruleset_id: '2f2feab2026849078ba485f918791bdc', * account_id: 'account_id', * }, * ); * ``` */ delete(ruleID, params, options) { const { ruleset_id, account_id, zone_id, dry_run } = 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}/rulesets/${ruleset_id}/rules/${ruleID}`, { query: { dry_run }, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates an existing rule in an account or zone ruleset. * * @example * ```ts * const response = await client.rulesets.rules.edit( * '3a03d665bac047339bb530ecb439a90d', * { * ruleset_id: '2f2feab2026849078ba485f918791bdc', * account_id: 'account_id', * }, * ); * ``` */ edit(ruleID, params, options) { const { ruleset_id, account_id, zone_id, dry_run, ...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}/rulesets/${ruleset_id}/rules/${ruleID}`, { query: { dry_run }, body, ...options, })._thenUnwrap((obj) => obj.result); } } BaseRules._key = Object.freeze([ 'rulesets', 'rules', ]); return BaseRules; })(); exports.BaseRules = BaseRules; class Rules extends BaseRules { } exports.Rules = Rules; //# sourceMappingURL=rules.js.map