cloudflare
Version:
The official TypeScript library for the Cloudflare API
164 lines • 6.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rules = exports.BaseRules = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../core/resource.js");
const pagination_1 = require("../../core/pagination.js");
const path_1 = require("../../internal/utils/path.js");
var BaseRules = /* @__PURE__ */ (() => {
class BaseRules extends resource_1.APIResource {
/**
* Creates a token validation rule for the zone.
*
* @example
* ```ts
* const tokenValidationRule =
* await client.tokenValidation.rules.create({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* action: 'log',
* description:
* 'Long description for Token Validation Rule',
* enabled: true,
* expression:
* 'is_jwt_valid("52973293-cb04-4a97-8f55-e7d2ad1107dd") or is_jwt_valid("46eab8d1-6376-45e3-968f-2c649d77d423")',
* selector: {},
* title: 'Example Token Validation Rule',
* });
* ```
*/
create(params, options) {
const { zone_id, ...body } = params;
return this._client.post((0, path_1.path) `/zones/${zone_id}/token_validation/rules`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Lists token validation rules for the zone, with filters for configuration,
* action, state, ID, and host.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const tokenValidationRule of client.tokenValidation.rules.list(
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { zone_id, ...query } = params;
return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/token_validation/rules`, (pagination_1.V4PagePaginationArray), { query, ...options });
}
/**
* Deletes a token validation rule from the zone.
*
* @example
* ```ts
* const rule = await client.tokenValidation.rules.delete(
* '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(ruleID, params, options) {
const { zone_id } = params;
return this._client.delete((0, path_1.path) `/zones/${zone_id}/token_validation/rules/${ruleID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Creates multiple token validation rules for the zone in one request.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const tokenValidationRule of client.tokenValidation.rules.bulkCreate(
* {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: [
* {
* action: 'log',
* description:
* 'Long description for Token Validation Rule',
* enabled: true,
* expression:
* 'is_jwt_valid("52973293-cb04-4a97-8f55-e7d2ad1107dd") or is_jwt_valid("46eab8d1-6376-45e3-968f-2c649d77d423")',
* selector: {},
* title: 'Example Token Validation Rule',
* },
* ],
* },
* )) {
* // ...
* }
* ```
*/
bulkCreate(params, options) {
const { zone_id, body } = params;
return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/token_validation/rules/bulk`, (pagination_1.SinglePage), { body: body, method: 'post', ...options });
}
/**
* Updates and reorders multiple token validation rules in one request, then
* returns the updated rules.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const tokenValidationRule of client.tokenValidation.rules.bulkEdit(
* {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: [{ id: '0d9bf70c-92e1-4bb3-9411-34a3bcc59003' }],
* },
* )) {
* // ...
* }
* ```
*/
bulkEdit(params, options) {
const { zone_id, body } = params;
return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/token_validation/rules/bulk`, (pagination_1.SinglePage), { body: body, method: 'patch', ...options });
}
/**
* Updates only the supplied fields on a token validation rule.
*
* @example
* ```ts
* const tokenValidationRule =
* await client.tokenValidation.rules.edit(
* '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
edit(ruleID, params, options) {
const { zone_id, ...body } = params;
return this._client.patch((0, path_1.path) `/zones/${zone_id}/token_validation/rules/${ruleID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Returns a token validation rule by ID.
*
* @example
* ```ts
* const tokenValidationRule =
* await client.tokenValidation.rules.get(
* '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(ruleID, params, options) {
const { zone_id } = params;
return this._client.get((0, path_1.path) `/zones/${zone_id}/token_validation/rules/${ruleID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseRules._key = Object.freeze([
'tokenValidation',
'rules',
]);
return BaseRules;
})();
exports.BaseRules = BaseRules;
class Rules extends BaseRules {
}
exports.Rules = Rules;
//# sourceMappingURL=rules.js.map