cloudflare
Version:
The official TypeScript library for the Cloudflare API
112 lines • 4.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Policies = exports.BasePolicies = 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 headers_1 = require("../../internal/headers.js");
const path_1 = require("../../internal/utils/path.js");
var BasePolicies = /* @__PURE__ */ (() => {
class BasePolicies extends resource_1.APIResource {
/**
* Creates a rule that applies a client-side security action when its filter
* expression matches.
*
* @example
* ```ts
* const policy = await client.pageShield.policies.create({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* action: 'allow',
* description: 'Checkout page CSP policy',
* enabled: true,
* expression:
* 'ends_with(http.request.uri.path, "/checkout")',
* value: "script-src 'none';",
* });
* ```
*/
create(params, options) {
const { zone_id, ...body } = params;
return this._client.post((0, path_1.path) `/zones/${zone_id}/page_shield/policies`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Updates the description, action, expression, enabled state, and policy value for
* a content security rule.
*
* @example
* ```ts
* const policy = await client.pageShield.policies.update(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
update(policyID, params, options) {
const { zone_id, ...body } = params;
return this._client.put((0, path_1.path) `/zones/${zone_id}/page_shield/policies/${policyID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists content security rules configured for the zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const policyListResponse of client.pageShield.policies.list(
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { zone_id } = params;
return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/page_shield/policies`, (pagination_1.SinglePage), options);
}
/**
* Permanently deletes a content security rule by ID.
*
* @example
* ```ts
* await client.pageShield.policies.delete(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(policyID, params, options) {
const { zone_id } = params;
return this._client.delete((0, path_1.path) `/zones/${zone_id}/page_shield/policies/${policyID}`, {
...options,
headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Returns a content security rule by ID.
*
* @example
* ```ts
* const policy = await client.pageShield.policies.get(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(policyID, params, options) {
const { zone_id } = params;
return this._client.get((0, path_1.path) `/zones/${zone_id}/page_shield/policies/${policyID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BasePolicies._key = Object.freeze([
'pageShield',
'policies',
]);
return BasePolicies;
})();
exports.BasePolicies = BasePolicies;
class Policies extends BasePolicies {
}
exports.Policies = Policies;
//# sourceMappingURL=policies.js.map