// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../../core/resource'; import * as WorkersAPI from '../../../../workers/workers'; import * as ScriptsAPI from '../../../../workers/scripts/scripts'; import * as TailAPI from '../../../../workers/scripts/tail'; import * as AssetUploadAPI from './asset-upload'; import { AssetUpload, AssetUploadCreateParams, AssetUploadCreateResponse, BaseAssetUpload, } from './asset-upload'; import * as BindingsAPI from './bindings'; import { BaseBindings, BindingGetParams, BindingGetResponse, BindingGetResponsesSinglePage, Bindings, } from './bindings'; import * as ContentAPI from './content'; import { BaseContent, Content, ContentGetParams, ContentUpdateParams } from './content'; import * as SecretsAPI from './secrets'; import { BaseSecrets, SecretBulkUpdateParams, SecretBulkUpdateResponse, SecretDeleteParams, SecretDeleteResponse, SecretGetParams, SecretGetResponse, SecretListParams, SecretListResponse, SecretListResponsesSinglePage, SecretUpdateParams, SecretUpdateResponse, Secrets, } from './secrets'; import * as SettingsAPI from './settings'; import { BaseSettings, SettingEditParams, SettingEditResponse, SettingGetParams, SettingGetResponse, Settings, } from './settings'; import * as TagsAPI from './tags'; import { BaseTags, TagDeleteParams, TagDeleteResponse, TagListParams, TagListResponse, TagListResponsesSinglePage, TagUpdateParams, TagUpdateResponse, TagUpdateResponsesSinglePage, Tags, } from './tags'; import { APIPromise } from '../../../../../core/api-promise'; import { type Uploadable } from '../../../../../core/uploads'; import { buildHeaders } from '../../../../../internal/headers'; import { RequestOptions } from '../../../../../internal/request-options'; import { maybeMultipartFormRequestOptions } from '../../../../../internal/uploads'; import { path } from '../../../../../internal/utils/path'; export class BaseScripts extends APIResource { static override readonly _key: readonly ['workersForPlatforms', 'dispatch', 'namespaces', 'scripts'] = Object.freeze(['workersForPlatforms', 'dispatch', 'namespaces', 'scripts'] as const); /** * Upload a worker module to a Workers for Platforms namespace. You can find more * about the multipart metadata on our docs: * https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/. * * @example * ```ts * const script = * await client.workersForPlatforms.dispatch.namespaces.scripts.update( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * dispatch_namespace: 'my-dispatch-namespace', * metadata: {}, * }, * ); * ``` */ update( scriptName: string, params: ScriptUpdateParams, options?: RequestOptions, ): APIPromise { const { account_id, dispatch_namespace, bindings_inherit, ...body } = params; return ( this._client.put( path`/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}`, maybeMultipartFormRequestOptions( { query: { bindings_inherit }, body, ...options, headers: buildHeaders([{ 'Content-Type': 'application/javascript' }, options?.headers]), }, this._client, ), ) as APIPromise<{ result: ScriptUpdateResponse }> )._thenUnwrap((obj) => obj.result); } /** * Delete a worker from a Workers for Platforms namespace. This call has no * response body on a successful delete. * * @example * ```ts * const script = * await client.workersForPlatforms.dispatch.namespaces.scripts.delete( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * dispatch_namespace: 'my-dispatch-namespace', * }, * ); * ``` */ delete( scriptName: string, params: ScriptDeleteParams, options?: RequestOptions, ): APIPromise { const { account_id, dispatch_namespace, force } = params; return ( this._client.delete( path`/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}`, { query: { force }, ...options }, ) as APIPromise<{ result: ScriptDeleteResponse | null }> )._thenUnwrap((obj) => obj.result); } /** * Fetch information about a script uploaded to a Workers for Platforms namespace. * * @example * ```ts * const script = * await client.workersForPlatforms.dispatch.namespaces.scripts.get( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * dispatch_namespace: 'my-dispatch-namespace', * }, * ); * ``` */ get(scriptName: string, params: ScriptGetParams, options?: RequestOptions): APIPromise