UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

144 lines • 6.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventNotifications = exports.BaseEventNotifications = void 0; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const headers_1 = require("../../../internal/headers.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseEventNotifications = /* @__PURE__ */ (() => { class BaseEventNotifications extends resource_1.APIResource { /** * Creates rules that send notifications for matching R2 object events to the * specified Cloudflare Queue. Rules can filter objects by key prefix and suffix. * New rules are added to any existing rules for the queue; a rule that overlaps an * existing rule is rejected. * * @example * ```ts * const eventNotification = * await client.r2.buckets.eventNotifications.update( * 'queue_id', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * bucket_name: 'example-bucket', * rules: [{ actions: ['PutObject', 'CopyObject'] }], * }, * ); * ``` */ update(queueID, params, options) { const { account_id, bucket_name, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...body } = params; return this._client.put((0, path_1.path) `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, { body, ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Lists event notification rules for an R2 bucket, grouped by the Cloudflare Queue * that receives matching object events. * * @example * ```ts * const eventNotifications = * await client.r2.buckets.eventNotifications.list( * 'example-bucket', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ list(bucketName, params, options) { const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/event_notifications/r2/${bucketName}/configuration`, { ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Deletes the specified event notification rules for an R2 bucket and Cloudflare * Queue. Provide ruleIds in the request body to select rules. If no body is * provided, all rules for that bucket and queue are deleted. * * @example * ```ts * const eventNotification = * await client.r2.buckets.eventNotifications.delete( * 'queue_id', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * bucket_name: 'example-bucket', * }, * ); * ``` */ delete(queueID, params, options) { const { account_id, bucket_name, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, { ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Gets the event notification rules for the specified R2 bucket and Cloudflare * Queue. The response includes the queue's configuration and its array of rules. * * @example * ```ts * const eventNotification = * await client.r2.buckets.eventNotifications.get( * 'queue_id', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * bucket_name: 'example-bucket', * }, * ); * ``` */ get(queueID, params, options) { const { account_id, bucket_name, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, { ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } } BaseEventNotifications._key = Object.freeze([ 'r2', 'buckets', 'eventNotifications', ]); return BaseEventNotifications; })(); exports.BaseEventNotifications = BaseEventNotifications; class EventNotifications extends BaseEventNotifications { } exports.EventNotifications = EventNotifications; //# sourceMappingURL=event-notifications.js.map