cloudflare
Version:
The official TypeScript library for the Cloudflare API
89 lines • 3.6 kB
JavaScript
;
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 path_1 = require("../../../internal/utils/path.js");
var BaseVersions = /* @__PURE__ */ (() => {
class BaseVersions extends resource_1.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 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/phases/${rulesetPhase}/entrypoint/versions`, (pagination_1.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 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/phases/${ruleset_phase}/entrypoint/versions/${rulesetVersion}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseVersions._key = Object.freeze([
'rulesets',
'phases',
'versions',
]);
return BaseVersions;
})();
exports.BaseVersions = BaseVersions;
class Versions extends BaseVersions {
}
exports.Versions = Versions;
//# sourceMappingURL=versions.js.map