cloudflare
Version:
The official TypeScript library for the Cloudflare API
195 lines • 8.11 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as CORSAPI from "./cors.mjs";
import { BaseCORS, CORS, } from "./cors.mjs";
import * as EventNotificationsAPI from "./event-notifications.mjs";
import { BaseEventNotifications, EventNotifications, } from "./event-notifications.mjs";
import * as LifecycleAPI from "./lifecycle.mjs";
import { BaseLifecycle, Lifecycle, } from "./lifecycle.mjs";
import * as LocksAPI from "./locks.mjs";
import { BaseLocks, Locks, } from "./locks.mjs";
import * as MetricsAPI from "./metrics.mjs";
import { BaseMetrics, Metrics } from "./metrics.mjs";
import * as ObjectsAPI from "./objects.mjs";
import { BaseObjects, Objects, } from "./objects.mjs";
import * as SippyAPI from "./sippy.mjs";
import { BaseSippyResource, SippyResource, } from "./sippy.mjs";
import * as DomainsAPI from "./domains/domains.mjs";
import { BaseDomains, Domains } from "./domains/domains.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseBuckets = /* @__PURE__ */ (() => {
class BaseBuckets extends 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(path `/accounts/${account_id}/r2/buckets`, {
body,
...options,
headers: 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(path `/accounts/${account_id}/r2/buckets`, {
query,
...options,
headers: 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(path `/accounts/${account_id}/r2/buckets/${bucketName}`, {
...options,
headers: 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(path `/accounts/${account_id}/r2/buckets/${bucketName}`, {
...options,
headers: 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(path `/accounts/${account_id}/r2/buckets/${bucketName}`, {
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
})._thenUnwrap((obj) => obj.result);
}
}
BaseBuckets._key = Object.freeze(['r2', 'buckets']);
return BaseBuckets;
})();
export 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;
Buckets.BaseLifecycle = BaseLifecycle;
Buckets.CORS = CORS;
Buckets.BaseCORS = BaseCORS;
Buckets.Domains = Domains;
Buckets.BaseDomains = BaseDomains;
Buckets.EventNotifications = EventNotifications;
Buckets.BaseEventNotifications = BaseEventNotifications;
Buckets.Locks = Locks;
Buckets.BaseLocks = BaseLocks;
Buckets.Metrics = Metrics;
Buckets.BaseMetrics = BaseMetrics;
Buckets.SippyResource = SippyResource;
Buckets.BaseSippyResource = BaseSippyResource;
Buckets.Objects = Objects;
Buckets.BaseObjects = BaseObjects;
return Buckets;
})();
//# sourceMappingURL=buckets.mjs.map