UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

70 lines • 3.19 kB
// 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 { multipartFormRequestOptions } from "../../../../../internal/uploads.mjs"; import { path } from "../../../../../internal/utils/path.mjs"; export var BaseContent = /* @__PURE__ */ (() => { class BaseContent extends 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(path `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/content`, multipartFormRequestOptions({ body, ...options, headers: 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(path `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/content`, { ...options, headers: buildHeaders([{ Accept: 'string' }, options?.headers]), __binaryResponse: true }); } } BaseContent._key = Object.freeze(['workersForPlatforms', 'dispatch', 'namespaces', 'scripts', 'content']); return BaseContent; })(); export class Content extends BaseContent { } //# sourceMappingURL=content.mjs.map