UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

84 lines • 3.35 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import { CloudflareError } from "../../../core/error.mjs"; import { SinglePage } from "../../../core/pagination.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BaseVersions = /* @__PURE__ */ (() => { class BaseVersions extends APIResource { /** * Fetches the versions of an account or zone entry point ruleset. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const versionListResponse of client.rulesets.phases.versions.list( * 'http_request_firewall_custom', * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(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.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/rulesets/phases/${rulesetPhase}/entrypoint/versions`, (SinglePage), options); } /** * Fetches a specific version of an account or zone entry point ruleset. * * @example * ```ts * const version = await client.rulesets.phases.versions.get( * '1', * { * ruleset_phase: 'http_request_firewall_custom', * account_id: 'account_id', * }, * ); * ``` */ get(rulesetVersion, params, options) { const { ruleset_phase, 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/${ruleset_phase}/entrypoint/versions/${rulesetVersion}`, options)._thenUnwrap((obj) => obj.result); } } BaseVersions._key = Object.freeze([ 'rulesets', 'phases', 'versions', ]); return BaseVersions; })(); export class Versions extends BaseVersions { } //# sourceMappingURL=versions.mjs.map