UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

88 lines • 3.5 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import * as VersionsAPI from "./versions.mjs"; import { BaseVersions, Versions, } from "./versions.mjs"; import { CloudflareError } from "../../../core/error.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BasePhases = /* @__PURE__ */ (() => { class BasePhases extends APIResource { /** * Updates an account or zone entry point ruleset, creating a new version. * * @example * ```ts * const phase = await client.rulesets.phases.update( * 'http_request_firewall_custom', * { account_id: 'account_id' }, * ); * ``` */ update(rulesetPhase, params, options) { const { account_id, zone_id, dry_run, ...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}/rulesets/phases/${rulesetPhase}/entrypoint`, { query: { dry_run }, body, ...options })._thenUnwrap((obj) => obj.result); } /** * Fetches the latest version of the account or zone entry point ruleset for a * given phase. * * @example * ```ts * const phase = await client.rulesets.phases.get( * 'http_request_firewall_custom', * { account_id: 'account_id' }, * ); * ``` */ get(rulesetPhase, 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}/rulesets/phases/${rulesetPhase}/entrypoint`, options)._thenUnwrap((obj) => obj.result); } } BasePhases._key = Object.freeze([ 'rulesets', 'phases', ]); return BasePhases; })(); export var Phases = /* @__PURE__ */ (() => { class Phases extends BasePhases { constructor() { super(...arguments); this.versions = new VersionsAPI.Versions(this._client); } } Phases.Versions = Versions; Phases.BaseVersions = BaseVersions; return Phases; })(); //# sourceMappingURL=phases.mjs.map