UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

182 lines • 7.16 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../../core/resource.mjs"; import * as JobsAPI from "./jobs.mjs"; import { BaseJobs, Jobs } from "./jobs.mjs"; import { SinglePage } from "../../../../../core/pagination.mjs"; import { path } from "../../../../../internal/utils/path.mjs"; export var BaseWebhooks = /* @__PURE__ */ (() => { class BaseWebhooks extends APIResource { /** * Creates a new webhook configuration for sending finding notifications to * external endpoints. * * @example * ```ts * const webhook = * await client.zeroTrust.casb.posture.webhooks.create({ * account_id: '46148281d8a93d002ef242d8b0d5f9f6', * authentication_type: 'Bearer Auth', * destination_url: 'https://example.com/webhook', * label: 'Send to Slack', * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/data-security/posture/webhooks`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates an existing webhook configuration with new settings. * * @example * ```ts * const webhook = * await client.zeroTrust.casb.posture.webhooks.update( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { * account_id: '46148281d8a93d002ef242d8b0d5f9f6', * authentication_type: 'Bearer Auth', * destination_url: 'https://example.com/webhook', * label: 'Send to Slack', * status: 'enabled', * }, * ); * ``` */ update(webhookID, params, options) { const { account_id, ...body } = params; return this._client.put(path `/accounts/${account_id}/data-security/posture/webhooks/${webhookID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Retrieves all webhook configurations for the authenticated account. Returns an * array of webhook configurations that can be used to send finding notifications. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const webhookListResponse of client.zeroTrust.casb.posture.webhooks.list( * { account_id: '46148281d8a93d002ef242d8b0d5f9f6' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id } = params; return this._client.getAPIList(path `/accounts/${account_id}/data-security/posture/webhooks`, (SinglePage), options); } /** * Soft deletes a webhook configuration by its unique identifier. The webhook will * be marked as deleted and will no longer be available for use. * * @example * ```ts * const webhook = * await client.zeroTrust.casb.posture.webhooks.delete( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { account_id: '46148281d8a93d002ef242d8b0d5f9f6' }, * ); * ``` */ delete(webhookID, params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/data-security/posture/webhooks/${webhookID}`, options); } /** * Sends a test webhook event to the specified destination URL to verify the * webhook endpoint is reachable and properly configured. This allows customers to * validate their webhook configuration before creating the actual webhook * resource. * * The test payload includes: * * - event_type: "webhook.test" * - timestamp: Current UTC timestamp * - message: Test message indicating this is from Cloudflare CASB * - data: Object with test: true * * @example * ```ts * const response = * await client.zeroTrust.casb.posture.webhooks.evaluate({ * account_id: '46148281d8a93d002ef242d8b0d5f9f6', * authentication_type: 'Bearer Auth', * destination_url: 'https://example.com/webhook', * }); * ``` */ evaluate(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/data-security/posture/webhooks/evaluate`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Sends a test webhook event using an existing webhook configuration. This allows * customers to verify their webhook endpoint is still reachable and properly * configured after creating the webhook resource. * * The test payload includes: * * - event_type: "webhook.test" * - timestamp: Current UTC timestamp * - message: Test message indicating this is from Cloudflare CASB * - data: Object with test: true * * @example * ```ts * const response = * await client.zeroTrust.casb.posture.webhooks.evaluateExisting( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { account_id: '46148281d8a93d002ef242d8b0d5f9f6' }, * ); * ``` */ evaluateExisting(webhookID, params, options) { const { account_id } = params; return this._client.post(path `/accounts/${account_id}/data-security/posture/webhooks/${webhookID}/evaluate`, options)._thenUnwrap((obj) => obj.result); } /** * Retrieves a specific webhook configuration by its unique identifier. * * @example * ```ts * const webhook = * await client.zeroTrust.casb.posture.webhooks.get( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { account_id: '46148281d8a93d002ef242d8b0d5f9f6' }, * ); * ``` */ get(webhookID, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/data-security/posture/webhooks/${webhookID}`, options)._thenUnwrap((obj) => obj.result); } } BaseWebhooks._key = Object.freeze([ 'zeroTrust', 'casb', 'posture', 'webhooks', ]); return BaseWebhooks; })(); export var Webhooks = /* @__PURE__ */ (() => { class Webhooks extends BaseWebhooks { constructor() { super(...arguments); this.jobs = new JobsAPI.Jobs(this._client); } } Webhooks.Jobs = Jobs; Webhooks.BaseJobs = BaseJobs; return Webhooks; })(); //# sourceMappingURL=webhooks.mjs.map