cloudflare
Version:
The official TypeScript library for the Cloudflare API
139 lines • 5.84 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseEventNotifications = /* @__PURE__ */ (() => {
class BaseEventNotifications extends 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(path `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, {
body,
...options,
headers: 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(path `/accounts/${account_id}/event_notifications/r2/${bucketName}/configuration`, {
...options,
headers: 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(path `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, {
...options,
headers: 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(path `/accounts/${account_id}/event_notifications/r2/${bucket_name}/configuration/queues/${queueID}`, {
...options,
headers: 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;
})();
export class EventNotifications extends BaseEventNotifications {
}
//# sourceMappingURL=event-notifications.mjs.map