UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

116 lines • 4.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Versions = exports.BaseVersions = 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 headers_1 = require("../../internal/headers.js"); const path_1 = require("../../internal/utils/path.js"); var BaseVersions = /* @__PURE__ */ (() => { class BaseVersions extends resource_1.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 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}/rulesets/${rulesetID}/versions`, (pagination_1.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 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}/versions/${rulesetVersion}`, { query: { dry_run }, ...options, headers: (0, headers_1.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 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}/rulesets/${ruleset_id}/versions/${rulesetVersion}`, options)._thenUnwrap((obj) => obj.result); } } BaseVersions._key = Object.freeze([ 'rulesets', 'versions', ]); return BaseVersions; })(); exports.BaseVersions = BaseVersions; class Versions extends BaseVersions { } exports.Versions = Versions; //# sourceMappingURL=versions.js.map