cloudflare
Version:
The official TypeScript library for the Cloudflare API
159 lines • 6.08 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { SinglePage, V4PagePaginationArray, } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseRules = /* @__PURE__ */ (() => {
class BaseRules extends 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(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(path `/zones/${zone_id}/token_validation/rules`, (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(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(path `/zones/${zone_id}/token_validation/rules/bulk`, (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(path `/zones/${zone_id}/token_validation/rules/bulk`, (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(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(path `/zones/${zone_id}/token_validation/rules/${ruleID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseRules._key = Object.freeze([
'tokenValidation',
'rules',
]);
return BaseRules;
})();
export class Rules extends BaseRules {
}
//# sourceMappingURL=rules.mjs.map