UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

75 lines • 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Content = exports.BaseContent = 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 uploads_1 = require("../../../../../internal/uploads.js"); const path_1 = require("../../../../../internal/utils/path.js"); var BaseContent = /* @__PURE__ */ (() => { class BaseContent extends resource_1.APIResource { /** * Replace content for a script uploaded to a Workers for Platforms dispatch * namespace. * * @example * ```ts * const script = * await client.workersForPlatforms.dispatch.namespaces.scripts.content.update( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * dispatch_namespace: 'my-dispatch-namespace', * metadata: {}, * }, * ); * ``` */ update(scriptName, params, options) { const { account_id, dispatch_namespace, 'CF-WORKER-BODY-PART': cfWorkerBodyPart, 'CF-WORKER-MAIN-MODULE-PART': cfWorkerMainModulePart, ...body } = params; return this._client.put((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/content`, (0, uploads_1.multipartFormRequestOptions)({ body, ...options, headers: (0, headers_1.buildHeaders)([ { ...(cfWorkerBodyPart != null ? { 'CF-WORKER-BODY-PART': cfWorkerBodyPart } : undefined), ...(cfWorkerMainModulePart != null ? { 'CF-WORKER-MAIN-MODULE-PART': cfWorkerMainModulePart } : undefined), }, options?.headers, ]), }, this._client))._thenUnwrap((obj) => obj.result); } /** * Fetch content from a script uploaded to a Workers for Platforms dispatch * namespace. * * @example * ```ts * const content = * await client.workersForPlatforms.dispatch.namespaces.scripts.content.get( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * dispatch_namespace: 'my-dispatch-namespace', * }, * ); * * const data = await content.blob(); * console.log(data); * ``` */ get(scriptName, params, options) { const { account_id, dispatch_namespace } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/content`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: 'string' }, options?.headers]), __binaryResponse: true }); } } BaseContent._key = Object.freeze(['workersForPlatforms', 'dispatch', 'namespaces', 'scripts', 'content']); return BaseContent; })(); exports.BaseContent = BaseContent; class Content extends BaseContent { } exports.Content = Content; //# sourceMappingURL=content.js.map