UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

188 lines • 7.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Webhooks = exports.BaseWebhooks = void 0; const tslib_1 = require("../../../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../../../core/resource.js"); const JobsAPI = tslib_1.__importStar(require("./jobs.js")); const jobs_1 = require("./jobs.js"); const pagination_1 = require("../../../../../core/pagination.js"); const path_1 = require("../../../../../internal/utils/path.js"); var BaseWebhooks = /* @__PURE__ */ (() => { class BaseWebhooks extends resource_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/data-security/posture/webhooks`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/data-security/posture/webhooks/${webhookID}`, options)._thenUnwrap((obj) => obj.result); } } BaseWebhooks._key = Object.freeze([ 'zeroTrust', 'casb', 'posture', 'webhooks', ]); return BaseWebhooks; })(); exports.BaseWebhooks = BaseWebhooks; var Webhooks = /* @__PURE__ */ (() => { class Webhooks extends BaseWebhooks { constructor() { super(...arguments); this.jobs = new JobsAPI.Jobs(this._client); } } Webhooks.Jobs = jobs_1.Jobs; Webhooks.BaseJobs = jobs_1.BaseJobs; return Webhooks; })(); exports.Webhooks = Webhooks; //# sourceMappingURL=webhooks.js.map