// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../resource'; import * as Core from '../../../core'; import * as WorkersAPI from '../workers'; import * as ContentAPI from './content'; import { Content, ContentGetParams, ContentUpdateParams } from './content'; import * as DeploymentsAPI from './deployments'; import { Deployment, DeploymentCreateParams, DeploymentCreateResponse, DeploymentGetParams, DeploymentGetResponse, Deployments, } from './deployments'; import * as SchedulesAPI from './schedules'; import { Schedule, ScheduleGetParams, ScheduleGetResponse, ScheduleUpdateParams, ScheduleUpdateResponse, Schedules, } from './schedules'; import * as SecretsAPI from './secrets'; import { SecretDeleteParams, SecretDeleteResponse, SecretGetParams, SecretGetResponse, SecretListParams, SecretListResponse, SecretListResponsesSinglePage, SecretUpdateParams, SecretUpdateResponse, Secrets, } from './secrets'; import * as SettingsAPI from './settings'; import { SettingEditParams, SettingGetParams, Settings } from './settings'; import * as SubdomainAPI from './subdomain'; import { Subdomain, SubdomainCreateParams, SubdomainCreateResponse, SubdomainGetParams, SubdomainGetResponse, } from './subdomain'; import * as TailAPI from './tail'; import { ConsumerScript, Tail, TailCreateParams, TailCreateResponse, TailDeleteParams, TailDeleteResponse, TailGetParams, TailGetResponse, } from './tail'; import * as VersionsAPI from './versions'; import { VersionCreateParams, VersionCreateResponse, VersionGetParams, VersionGetResponse, VersionListParams, VersionListResponse, VersionListResponsesV4PagePagination, Versions, } from './versions'; import * as AssetsAPI from './assets/assets'; import { Assets as AssetsAPIAssets } from './assets/assets'; import { SinglePage } from '../../../pagination'; export class Scripts extends APIResource { assets: AssetsAPI.Assets = new AssetsAPI.Assets(this._client); subdomain: SubdomainAPI.Subdomain = new SubdomainAPI.Subdomain(this._client); schedules: SchedulesAPI.Schedules = new SchedulesAPI.Schedules(this._client); tail: TailAPI.Tail = new TailAPI.Tail(this._client); content: ContentAPI.Content = new ContentAPI.Content(this._client); settings: SettingsAPI.Settings = new SettingsAPI.Settings(this._client); deployments: DeploymentsAPI.Deployments = new DeploymentsAPI.Deployments(this._client); versions: VersionsAPI.Versions = new VersionsAPI.Versions(this._client); secrets: SecretsAPI.Secrets = new SecretsAPI.Secrets(this._client); /** * Upload a worker module. You can find more about the multipart metadata on our * docs: * https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/. */ update( scriptName: string, params: ScriptUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { const { account_id, ...body } = params; return ( this._client.put( `/accounts/${account_id}/workers/scripts/${scriptName}`, Core.maybeMultipartFormRequestOptions({ body, ...options, headers: { 'Content-Type': 'application/javascript', ...options?.headers }, }), ) as Core.APIPromise<{ result: ScriptUpdateResponse }> )._thenUnwrap((obj) => obj.result); } /** * Fetch a list of uploaded workers. */ list(params: ScriptListParams, options?: Core.RequestOptions): Core.PagePromise { const { account_id } = params; return this._client.getAPIList(`/accounts/${account_id}/workers/scripts`, ScriptsSinglePage, options); } /** * Delete your worker. This call has no response body on a successful delete. */ delete( scriptName: string, params: ScriptDeleteParams, options?: Core.RequestOptions, ): Core.APIPromise { const { account_id, force } = params; return this._client.delete(`/accounts/${account_id}/workers/scripts/${scriptName}`, { query: { force }, ...options, headers: { Accept: '*/*', ...options?.headers }, }); } /** * Fetch raw script content for your worker. Note this is the original script * content, not JSON encoded. */ get(scriptName: string, params: ScriptGetParams, options?: Core.RequestOptions): Core.APIPromise { const { account_id } = params; return this._client.get(`/accounts/${account_id}/workers/scripts/${scriptName}`, { ...options, headers: { Accept: 'application/javascript', ...options?.headers }, }); } } export class ScriptsSinglePage extends SinglePage