cloudflare
Version:
The official TypeScript library for the Cloudflare API
157 lines • 6.26 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import { V4PagePaginationArray, } from "../../../core/pagination.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseContentPolicies = /* @__PURE__ */ (() => {
class BaseContentPolicies extends APIResource {
/**
* Creates a new content policy. Emails whose subject or body matches the pattern
* will be subject to the configured action.
*
* @example
* ```ts
* const contentPolicy =
* await client.emailSecurity.settings.contentPolicies.create(
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* enabled: true,
* name: 'Block phishing keywords',
* pattern: 'urgent.*verify.*account',
* targets: ['SUBJECT'],
* },
* );
* ```
*/
create(params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/email-security/settings/content_policies`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Returns a paginated list of content policies. These policies match against the
* subject or body of emails using a pattern. Supports filtering by name or enabled
* status, and searching across name and pattern fields.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const contentPolicyListResponse of client.emailSecurity.settings.contentPolicies.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList(path `/accounts/${account_id}/email-security/settings/content_policies`, (V4PagePaginationArray), { query, ...options });
}
/**
* Removes a content policy. After deletion, emails will no longer be evaluated
* against this pattern.
*
* @example
* ```ts
* const contentPolicy =
* await client.emailSecurity.settings.contentPolicies.delete(
* 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(policyID, params, options) {
const { account_id } = params;
return this._client.delete(path `/accounts/${account_id}/email-security/settings/content_policies/${policyID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Executes multiple content policy operations atomically: delete, partially
* update, replace, and create content policies in a single request. All four
* operation arrays (deletes, patches, puts, posts) are required and executed in
* order. Send empty arrays for unused operations.
*
* @example
* ```ts
* const response =
* await client.emailSecurity.settings.contentPolicies.batch(
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* deletes: [
* { id: 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415' },
* ],
* patches: [{}],
* posts: [
* {
* enabled: true,
* name: 'Block phishing keywords',
* pattern: 'urgent.*verify.*account',
* targets: ['SUBJECT'],
* },
* ],
* puts: [
* {
* enabled: true,
* name: 'Block phishing keywords',
* pattern: 'urgent.*verify.*account',
* targets: ['SUBJECT'],
* },
* ],
* },
* );
* ```
*/
batch(params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/email-security/settings/content_policies/batch`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates an existing content policy. Only provided fields will be modified.
*
* @example
* ```ts
* const response =
* await client.emailSecurity.settings.contentPolicies.edit(
* 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
edit(policyID, params, options) {
const { account_id, ...body } = params;
return this._client.patch(path `/accounts/${account_id}/email-security/settings/content_policies/${policyID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Retrieves details for a specific content policy including its pattern, targets,
* and metadata.
*
* @example
* ```ts
* const contentPolicy =
* await client.emailSecurity.settings.contentPolicies.get(
* 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(policyID, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/email-security/settings/content_policies/${policyID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseContentPolicies._key = Object.freeze([
'emailSecurity',
'settings',
'contentPolicies',
]);
return BaseContentPolicies;
})();
export class ContentPolicies extends BaseContentPolicies {
}
//# sourceMappingURL=content-policies.mjs.map