cloudflare
Version:
The official TypeScript library for the Cloudflare API
205 lines • 8.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rulesets = exports.BaseRulesets = void 0;
const tslib_1 = require("../../internal/tslib.js");
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../core/resource.js");
const RulesAPI = tslib_1.__importStar(require("./rules.js"));
const rules_1 = require("./rules.js");
const VersionsAPI = tslib_1.__importStar(require("./versions.js"));
const versions_1 = require("./versions.js");
const PhasesAPI = tslib_1.__importStar(require("./phases/phases.js"));
const phases_1 = require("./phases/phases.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 BaseRulesets = /* @__PURE__ */ (() => {
class BaseRulesets extends resource_1.APIResource {
/**
* Creates a ruleset.
*
* @example
* ```ts
* const ruleset = await client.rulesets.create({
* account_id: 'account_id',
* });
* ```
*/
create(params, options) {
const { account_id, zone_id, dry_run, ...body } = 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.post((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/rulesets`, {
query: { dry_run },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates an account or zone ruleset, creating a new version.
*
* @example
* ```ts
* const ruleset = await client.rulesets.update(
* '2f2feab2026849078ba485f918791bdc',
* { account_id: 'account_id' },
* );
* ```
*/
update(rulesetID, params, options) {
const { account_id, zone_id, dry_run, ...body } = 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.put((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/rulesets/${rulesetID}`, {
query: { dry_run },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Fetches all rulesets.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const rulesetListResponse of client.rulesets.list(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { account_id, zone_id, ...query } = 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`, (pagination_1.CursorPagination), { query, ...options });
}
/**
* Deletes all versions of an existing account or zone ruleset.
*
* @example
* ```ts
* await client.rulesets.delete(
* '2f2feab2026849078ba485f918791bdc',
* { account_id: 'account_id' },
* );
* ```
*/
delete(rulesetID, params = {}, options) {
const { 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/${rulesetID}`, {
query: { dry_run },
...options,
headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Fetches the latest version of an account or zone ruleset.
*
* @example
* ```ts
* const ruleset = await client.rulesets.get(
* '2f2feab2026849078ba485f918791bdc',
* { account_id: 'account_id' },
* );
* ```
*/
get(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.get((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/rulesets/${rulesetID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseRulesets._key = Object.freeze(['rulesets']);
return BaseRulesets;
})();
exports.BaseRulesets = BaseRulesets;
var Rulesets = /* @__PURE__ */ (() => {
class Rulesets extends BaseRulesets {
constructor() {
super(...arguments);
this.phases = new PhasesAPI.Phases(this._client);
this.rules = new RulesAPI.Rules(this._client);
this.versions = new VersionsAPI.Versions(this._client);
}
}
Rulesets.Phases = phases_1.Phases;
Rulesets.BasePhases = phases_1.BasePhases;
Rulesets.Rules = rules_1.Rules;
Rulesets.BaseRules = rules_1.BaseRules;
Rulesets.Versions = versions_1.Versions;
Rulesets.BaseVersions = versions_1.BaseVersions;
return Rulesets;
})();
exports.Rulesets = Rulesets;
//# sourceMappingURL=rulesets.js.map