UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

111 lines • 4.58 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 { buildHeaders } from "../../internal/headers.mjs"; import { path } from "../../internal/utils/path.mjs"; export var BaseVersions = /* @__PURE__ */ (() => { class BaseVersions extends APIResource { /** * Fetches the versions of an account or zone ruleset. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const versionListResponse of client.rulesets.versions.list( * '2f2feab2026849078ba485f918791bdc', * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(rulesetID, 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/${rulesetID}/versions`, (SinglePage), options); } /** * Deletes an existing version of an account or zone ruleset. * * @example * ```ts * await client.rulesets.versions.delete('1', { * ruleset_id: '2f2feab2026849078ba485f918791bdc', * account_id: 'account_id', * }); * ``` */ delete(rulesetVersion, params, options) { const { ruleset_id, account_id, zone_id, dry_run } = 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.delete(path `/${accountOrZone}/${accountOrZoneId}/rulesets/${ruleset_id}/versions/${rulesetVersion}`, { query: { dry_run }, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]) }); } /** * Fetches a specific version of an account or zone ruleset. * * @example * ```ts * const version = await client.rulesets.versions.get('1', { * ruleset_id: '2f2feab2026849078ba485f918791bdc', * account_id: 'account_id', * }); * ``` */ get(rulesetVersion, params, options) { const { ruleset_id, 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/${ruleset_id}/versions/${rulesetVersion}`, options)._thenUnwrap((obj) => obj.result); } } BaseVersions._key = Object.freeze([ 'rulesets', 'versions', ]); return BaseVersions; })(); export class Versions extends BaseVersions { } //# sourceMappingURL=versions.mjs.map