UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

201 lines • 8.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Buckets = exports.BaseBuckets = 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 CORSAPI = tslib_1.__importStar(require("./cors.js")); const cors_1 = require("./cors.js"); const EventNotificationsAPI = tslib_1.__importStar(require("./event-notifications.js")); const event_notifications_1 = require("./event-notifications.js"); const LifecycleAPI = tslib_1.__importStar(require("./lifecycle.js")); const lifecycle_1 = require("./lifecycle.js"); const LocksAPI = tslib_1.__importStar(require("./locks.js")); const locks_1 = require("./locks.js"); const MetricsAPI = tslib_1.__importStar(require("./metrics.js")); const metrics_1 = require("./metrics.js"); const ObjectsAPI = tslib_1.__importStar(require("./objects.js")); const objects_1 = require("./objects.js"); const SippyAPI = tslib_1.__importStar(require("./sippy.js")); const sippy_1 = require("./sippy.js"); const DomainsAPI = tslib_1.__importStar(require("./domains/domains.js")); const domains_1 = require("./domains/domains.js"); const headers_1 = require("../../../internal/headers.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseBuckets = /* @__PURE__ */ (() => { class BaseBuckets extends resource_1.APIResource { /** * Creates an R2 bucket in the account and selected jurisdiction, with an optional * location hint and default storage class. * * @example * ```ts * const bucket = await client.r2.buckets.create({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * name: 'example-bucket', * }); * ``` */ create(params, options) { const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/r2/buckets`, { body, ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Lists a page of R2 buckets in the account and selected jurisdiction. Use the * returned cursor to retrieve the next page. * * @example * ```ts * const buckets = await client.r2.buckets.list({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ list(params, options) { const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...query } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/r2/buckets`, { query, ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Deletes an empty R2 bucket and its configuration. The bucket must have no * objects, no in-progress multipart uploads, and no event notification rules; * otherwise the request fails. * * @example * ```ts * const bucket = await client.r2.buckets.delete( * 'example-bucket', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(bucketName, params, options) { const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}`, { ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Changes the default storage class for newly uploaded objects in an existing R2 * bucket. Existing objects retain their storage class, and individual uploads can * override the bucket default. * * @example * ```ts * const bucket = await client.r2.buckets.edit( * 'example-bucket', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * storage_class: 'Standard', * }, * ); * ``` */ edit(bucketName, params, options) { const { account_id, storage_class, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.patch((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}`, { ...options, headers: (0, headers_1.buildHeaders)([ { 'cf-r2-storage-class': storage_class.toString(), ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } /** * Gets properties of an existing R2 bucket. * * @example * ```ts * const bucket = await client.r2.buckets.get( * 'example-bucket', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(bucketName, params, options) { const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}`, { ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfR2Jurisdiction?.toString() != null ? { 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() } : undefined), }, options?.headers, ]), })._thenUnwrap((obj) => obj.result); } } BaseBuckets._key = Object.freeze(['r2', 'buckets']); return BaseBuckets; })(); exports.BaseBuckets = BaseBuckets; var Buckets = /* @__PURE__ */ (() => { class Buckets extends BaseBuckets { constructor() { super(...arguments); this.lifecycle = new LifecycleAPI.Lifecycle(this._client); this.cors = new CORSAPI.CORS(this._client); this.domains = new DomainsAPI.Domains(this._client); this.eventNotifications = new EventNotificationsAPI.EventNotifications(this._client); this.locks = new LocksAPI.Locks(this._client); this.metrics = new MetricsAPI.Metrics(this._client); this.sippy = new SippyAPI.SippyResource(this._client); this.objects = new ObjectsAPI.Objects(this._client); } } Buckets.Lifecycle = lifecycle_1.Lifecycle; Buckets.BaseLifecycle = lifecycle_1.BaseLifecycle; Buckets.CORS = cors_1.CORS; Buckets.BaseCORS = cors_1.BaseCORS; Buckets.Domains = domains_1.Domains; Buckets.BaseDomains = domains_1.BaseDomains; Buckets.EventNotifications = event_notifications_1.EventNotifications; Buckets.BaseEventNotifications = event_notifications_1.BaseEventNotifications; Buckets.Locks = locks_1.Locks; Buckets.BaseLocks = locks_1.BaseLocks; Buckets.Metrics = metrics_1.Metrics; Buckets.BaseMetrics = metrics_1.BaseMetrics; Buckets.SippyResource = sippy_1.SippyResource; Buckets.BaseSippyResource = sippy_1.BaseSippyResource; Buckets.Objects = objects_1.Objects; Buckets.BaseObjects = objects_1.BaseObjects; return Buckets; })(); exports.Buckets = Buckets; //# sourceMappingURL=buckets.js.map