cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
jacobbednarz-patch-1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/dispatchers/scripts.ts

483lines · modecode

1// File generated from our OpenAPI spec by Stainless.
2
3import * as Core from 'cloudflare/core';
4import { APIResource } from 'cloudflare/resource';
5import * as ScriptsAPI from 'cloudflare/resources/dispatchers/scripts';
6import { type Uploadable, maybeMultipartFormRequestOptions } from 'cloudflare/core';
7
8export class Scripts extends APIResource {
9 /**
10 * Fetch information about a script uploaded to a Workers for Platforms namespace.
11 */
12 retrieve(
13 accountId: string,
14 dispatchNamespace: string,
15 scriptName: string,
16 options?: Core.RequestOptions,
17 ): Core.APIPromise<ScriptRetrieveResponse> {
18 return (
19 this._client.get(
20 `/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${scriptName}`,
21 options,
22 ) as Core.APIPromise<{ result: ScriptRetrieveResponse }>
23 )._thenUnwrap((obj) => obj.result);
24 }
25
26 /**
27 * Upload a worker module to a Workers for Platforms namespace.
28 */
29 update(
30 accountId: string,
31 dispatchNamespace: string,
32 scriptName: string,
33 body: ScriptUpdateParams,
34 options?: Core.RequestOptions,
35 ): Core.APIPromise<ScriptUpdateResponse> {
36 return (
37 this._client.put(
38 `/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${scriptName}`,
39 maybeMultipartFormRequestOptions({ body, ...options }),
40 ) as Core.APIPromise<{ result: ScriptUpdateResponse }>
41 )._thenUnwrap((obj) => obj.result);
42 }
43
44 /**
45 * Delete a worker from a Workers for Platforms namespace. This call has no
46 * response body on a successful delete.
47 */
48 delete(
49 accountId: string,
50 dispatchNamespace: string,
51 scriptName: string,
52 params: ScriptDeleteParams,
53 options?: Core.RequestOptions,
54 ): Core.APIPromise<void> {
55 const { force } = params;
56 return this._client.delete(
57 `/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${scriptName}`,
58 { query: { force }, ...options, headers: { Accept: '*/*', ...options?.headers } },
59 );
60 }
61}
62
63/**
64 * Details about a worker uploaded to a Workers for Platforms namespace.
65 */
66export interface ScriptRetrieveResponse {
67 /**
68 * When the script was created.
69 */
70 created_on?: string;
71
72 /**
73 * Name of the Workers for Platforms dispatch namespace.
74 */
75 dispatch_namespace?: string;
76
77 /**
78 * When the script was last modified.
79 */
80 modified_on?: string;
81
82 script?: ScriptRetrieveResponse.Script;
83}
84
85export namespace ScriptRetrieveResponse {
86 export interface Script {
87 /**
88 * The id of the script in the Workers system. Usually the script name.
89 */
90 id?: string;
91
92 /**
93 * When the script was created.
94 */
95 created_on?: string;
96
97 /**
98 * Hashed script content, can be used in a If-None-Match header when updating.
99 */
100 etag?: string;
101
102 /**
103 * Whether Logpush is turned on for the Worker.
104 */
105 logpush?: boolean;
106
107 /**
108 * When the script was last modified.
109 */
110 modified_on?: string;
111
112 /**
113 * Deprecated. Deployment metadata for internal usage.
114 */
115 pipeline_hash?: string;
116
117 /**
118 * Specifies the placement mode for the Worker (e.g. 'smart').
119 */
120 placement_mode?: string;
121
122 /**
123 * List of Workers that will consume logs from the attached Worker.
124 */
125 tail_consumers?: Array<Script.TailConsumer>;
126
127 /**
128 * Specifies the usage model for the Worker (e.g. 'bundled' or 'unbound').
129 */
130 usage_model?: string;
131 }
132
133 export namespace Script {
134 /**
135 * A reference to a script that will consume logs from the attached Worker.
136 */
137 export interface TailConsumer {
138 /**
139 * Name of Worker that is to be the consumer.
140 */
141 service: string;
142
143 /**
144 * Optional environment if the Worker utilizes one.
145 */
146 environment?: string;
147
148 /**
149 * Optional dispatch namespace the script belongs to.
150 */
151 namespace?: string;
152 }
153 }
154}
155
156export interface ScriptUpdateResponse {
157 /**
158 * The id of the script in the Workers system. Usually the script name.
159 */
160 id?: string;
161
162 /**
163 * When the script was created.
164 */
165 created_on?: string;
166
167 /**
168 * Hashed script content, can be used in a If-None-Match header when updating.
169 */
170 etag?: string;
171
172 /**
173 * Whether Logpush is turned on for the Worker.
174 */
175 logpush?: boolean;
176
177 /**
178 * When the script was last modified.
179 */
180 modified_on?: string;
181
182 /**
183 * Deprecated. Deployment metadata for internal usage.
184 */
185 pipeline_hash?: string;
186
187 /**
188 * Specifies the placement mode for the Worker (e.g. 'smart').
189 */
190 placement_mode?: string;
191
192 /**
193 * List of Workers that will consume logs from the attached Worker.
194 */
195 tail_consumers?: Array<ScriptUpdateResponse.TailConsumer>;
196
197 /**
198 * Specifies the usage model for the Worker (e.g. 'bundled' or 'unbound').
199 */
200 usage_model?: string;
201}
202
203export namespace ScriptUpdateResponse {
204 /**
205 * A reference to a script that will consume logs from the attached Worker.
206 */
207 export interface TailConsumer {
208 /**
209 * Name of Worker that is to be the consumer.
210 */
211 service: string;
212
213 /**
214 * Optional environment if the Worker utilizes one.
215 */
216 environment?: string;
217
218 /**
219 * Optional dispatch namespace the script belongs to.
220 */
221 namespace?: string;
222 }
223}
224
225export type ScriptUpdateParams = ScriptUpdateParams.Variant0 | ScriptUpdateParams.Variant1;
226
227export namespace ScriptUpdateParams {
228 export interface Variant0 {
229 /**
230 * A module comprising a Worker script, often a javascript file. Multiple modules
231 * may be provided as separate named parts, but at least one module must be present
232 * and referenced in the metadata as `main_module` or `body_part` by part name.
233 */
234 '<any part name>'?: Array<Uploadable>;
235
236 /**
237 * JSON encoded metadata about the uploaded parts and Worker configuration.
238 */
239 metadata?: ScriptUpdateParams.Variant0.Metadata;
240 }
241
242 export namespace Variant0 {
243 /**
244 * JSON encoded metadata about the uploaded parts and Worker configuration.
245 */
246 export interface Metadata {
247 /**
248 * List of bindings available to the worker.
249 */
250 bindings?: Array<unknown>;
251
252 /**
253 * Name of the part in the multipart request that contains the script (e.g. the
254 * file adding a listener to the `fetch` event). Indicates a
255 * `service worker syntax` Worker.
256 */
257 body_part?: string;
258
259 /**
260 * Date indicating targeted support in the Workers runtime. Backwards incompatible
261 * fixes to the runtime following this date will not affect this Worker.
262 */
263 compatibility_date?: string;
264
265 /**
266 * Flags that enable or disable certain features in the Workers runtime. Used to
267 * enable upcoming features or opt in or out of specific changes not included in a
268 * `compatibility_date`.
269 */
270 compatibility_flags?: Array<string>;
271
272 /**
273 * List of binding types to keep from previous_upload.
274 */
275 keep_bindings?: Array<string>;
276
277 /**
278 * Whether Logpush is turned on for the Worker.
279 */
280 logpush?: boolean;
281
282 /**
283 * Name of the part in the multipart request that contains the main module (e.g.
284 * the file exporting a `fetch` handler). Indicates a `module syntax` Worker.
285 */
286 main_module?: string;
287
288 /**
289 * Migrations to apply for Durable Objects associated with this Worker.
290 */
291 migrations?: Metadata.WorkersSingleStepMigrations | Metadata.WorkersSteppedMigrations;
292
293 placement?: Metadata.Placement;
294
295 /**
296 * List of strings to use as tags for this Worker
297 */
298 tags?: Array<string>;
299
300 /**
301 * List of Workers that will consume logs from the attached Worker.
302 */
303 tail_consumers?: Array<Metadata.TailConsumer>;
304
305 /**
306 * Usage model to apply to invocations.
307 */
308 usage_model?: 'bundled' | 'unbound';
309
310 /**
311 * Key-value pairs to use as tags for this version of this Worker
312 */
313 version_tags?: unknown;
314 }
315
316 export namespace Metadata {
317 /**
318 * A single set of migrations to apply.
319 */
320 export interface WorkersSingleStepMigrations {
321 /**
322 * A list of classes to delete Durable Object namespaces from.
323 */
324 deleted_classes?: Array<string>;
325
326 /**
327 * A list of classes to create Durable Object namespaces from.
328 */
329 new_classes?: Array<string>;
330
331 /**
332 * Tag to set as the latest migration tag.
333 */
334 new_tag?: string;
335
336 /**
337 * Tag used to verify against the latest migration tag for this Worker. If they
338 * don't match, the upload is rejected.
339 */
340 old_tag?: string;
341
342 /**
343 * A list of classes with Durable Object namespaces that were renamed.
344 */
345 renamed_classes?: Array<WorkersSingleStepMigrations.RenamedClass>;
346
347 /**
348 * A list of transfers for Durable Object namespaces from a different Worker and
349 * class to a class defined in this Worker.
350 */
351 transferred_classes?: Array<WorkersSingleStepMigrations.TransferredClass>;
352 }
353
354 export namespace WorkersSingleStepMigrations {
355 export interface RenamedClass {
356 from?: string;
357
358 to?: string;
359 }
360
361 export interface TransferredClass {
362 from?: string;
363
364 from_script?: string;
365
366 to?: string;
367 }
368 }
369
370 export interface WorkersSteppedMigrations {
371 /**
372 * Tag to set as the latest migration tag.
373 */
374 new_tag?: string;
375
376 /**
377 * Tag used to verify against the latest migration tag for this Worker. If they
378 * don't match, the upload is rejected.
379 */
380 old_tag?: string;
381
382 /**
383 * Migrations to apply in order.
384 */
385 steps?: Array<WorkersSteppedMigrations.Step>;
386 }
387
388 export namespace WorkersSteppedMigrations {
389 export interface Step {
390 /**
391 * A list of classes to delete Durable Object namespaces from.
392 */
393 deleted_classes?: Array<string>;
394
395 /**
396 * A list of classes to create Durable Object namespaces from.
397 */
398 new_classes?: Array<string>;
399
400 /**
401 * A list of classes with Durable Object namespaces that were renamed.
402 */
403 renamed_classes?: Array<Step.RenamedClass>;
404
405 /**
406 * A list of transfers for Durable Object namespaces from a different Worker and
407 * class to a class defined in this Worker.
408 */
409 transferred_classes?: Array<Step.TransferredClass>;
410 }
411
412 export namespace Step {
413 export interface RenamedClass {
414 from?: string;
415
416 to?: string;
417 }
418
419 export interface TransferredClass {
420 from?: string;
421
422 from_script?: string;
423
424 to?: string;
425 }
426 }
427 }
428
429 export interface Placement {
430 /**
431 * Enables
432 * [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).
433 * Only `"smart"` is currently supported
434 */
435 mode?: 'smart';
436 }
437
438 /**
439 * A reference to a script that will consume logs from the attached Worker.
440 */
441 export interface TailConsumer {
442 /**
443 * Name of Worker that is to be the consumer.
444 */
445 service: string;
446
447 /**
448 * Optional environment if the Worker utilizes one.
449 */
450 environment?: string;
451
452 /**
453 * Optional dispatch namespace the script belongs to.
454 */
455 namespace?: string;
456 }
457 }
458 }
459
460 export interface Variant1 {
461 /**
462 * Rollback message to be associated with this deployment. Only parsed when query
463 * param `"rollback_to"` is present.
464 */
465 message?: string;
466 }
467}
468
469export interface ScriptDeleteParams {
470 /**
471 * If set to true, delete will not be stopped by associated service binding,
472 * durable object, or other binding. Any of these associated bindings/durable
473 * objects will be deleted along with the script.
474 */
475 force?: boolean;
476}
477
478export namespace Scripts {
479 export import ScriptRetrieveResponse = ScriptsAPI.ScriptRetrieveResponse;
480 export import ScriptUpdateResponse = ScriptsAPI.ScriptUpdateResponse;
481 export import ScriptUpdateParams = ScriptsAPI.ScriptUpdateParams;
482 export import ScriptDeleteParams = ScriptsAPI.ScriptDeleteParams;
483}
484