cloudflare
Version:
The official TypeScript library for the Cloudflare API
95 lines • 3.61 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 BaseCORS = /* @__PURE__ */ (() => {
class BaseCORS extends APIResource {
/**
* Replaces the Cross-Origin Resource Sharing (CORS) rules for an R2 bucket. Rules
* specify which origins, methods, and headers are allowed for browser requests to
* objects in the bucket.
*
* @example
* ```ts
* const cors = await client.r2.buckets.cors.update(
* 'example-bucket',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
update(bucketName, params, options) {
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...body } = params;
return this._client.put(path `/accounts/${account_id}/r2/buckets/${bucketName}/cors`, {
body,
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
})._thenUnwrap((obj) => obj.result);
}
/**
* Delete the CORS policy for a bucket.
*
* @example
* ```ts
* const cors = await client.r2.buckets.cors.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}/cors`, {
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
})._thenUnwrap((obj) => obj.result);
}
/**
* Get the CORS policy for a bucket.
*
* @example
* ```ts
* const cors = await client.r2.buckets.cors.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}/cors`, {
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
})._thenUnwrap((obj) => obj.result);
}
}
BaseCORS._key = Object.freeze([
'r2',
'buckets',
'cors',
]);
return BaseCORS;
})();
export class CORS extends BaseCORS {
}
//# sourceMappingURL=cors.mjs.map