UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

100 lines • 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CORS = exports.BaseCORS = 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 BaseCORS = /* @__PURE__ */ (() => { class BaseCORS extends resource_1.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((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}/cors`, { body, ...options, headers: (0, headers_1.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((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}/cors`, { ...options, headers: (0, headers_1.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((0, path_1.path) `/accounts/${account_id}/r2/buckets/${bucketName}/cors`, { ...options, headers: (0, headers_1.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; })(); exports.BaseCORS = BaseCORS; class CORS extends BaseCORS { } exports.CORS = CORS; //# sourceMappingURL=cors.js.map