cli.d.ts 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. /// <reference types="node" />
  2. import { Blob as Blob_2 } from 'buffer';
  3. import { ConnectionOptions } from 'tls';
  4. import { Duplex } from 'stream';
  5. import { EventEmitter } from 'events';
  6. import { IpcNetConnectOpts } from 'net';
  7. import type { Json } from 'miniflare';
  8. import { Readable } from 'stream';
  9. import { ReadableStream as ReadableStream_2 } from 'stream/web';
  10. import { Socket as Socket_2 } from 'net';
  11. import { TcpNetConnectOpts } from 'net';
  12. import { TlsOptions } from 'tls';
  13. import { TLSSocket } from 'tls';
  14. import { URL as URL_2 } from 'url';
  15. import { URLSearchParams as URLSearchParams_2 } from 'url';
  16. import { Writable } from 'stream';
  17. declare type AbortSignal_2 = unknown;
  18. declare interface BlobPropertyBag {
  19. type?: string
  20. endings?: 'native' | 'transparent'
  21. }
  22. declare type BodyInit_2 =
  23. | ArrayBuffer
  24. | AsyncIterable<Uint8Array>
  25. | Blob_2
  26. | FormData_2
  27. | Iterable<Uint8Array>
  28. | NodeJS.ArrayBufferView
  29. | URLSearchParams_2
  30. | null
  31. | string
  32. declare interface BodyMixin {
  33. readonly body: ReadableStream_2 | null
  34. readonly bodyUsed: boolean
  35. readonly arrayBuffer: () => Promise<ArrayBuffer>
  36. readonly blob: () => Promise<Blob_2>
  37. readonly formData: () => Promise<FormData_2>
  38. readonly json: () => Promise<unknown>
  39. readonly text: () => Promise<string>
  40. }
  41. declare class BodyReadable extends Readable {
  42. constructor(
  43. resume?: (this: Readable, size: number) => void | null,
  44. abort?: () => void | null,
  45. contentType?: string
  46. )
  47. /** Consumes and returns the body as a string
  48. * https://fetch.spec.whatwg.org/#dom-body-text
  49. */
  50. text(): Promise<string>
  51. /** Consumes and returns the body as a JavaScript Object
  52. * https://fetch.spec.whatwg.org/#dom-body-json
  53. */
  54. json(): Promise<any>
  55. /** Consumes and returns the body as a Blob
  56. * https://fetch.spec.whatwg.org/#dom-body-blob
  57. */
  58. blob(): Promise<Blob_2>
  59. /** Consumes and returns the body as an ArrayBuffer
  60. * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
  61. */
  62. arrayBuffer(): Promise<ArrayBuffer>
  63. /** Not implemented
  64. *
  65. * https://fetch.spec.whatwg.org/#dom-body-formdata
  66. */
  67. formData(): Promise<never>
  68. /** Returns true if the body is not null and the body has been consumed
  69. *
  70. * Otherwise, returns false
  71. *
  72. * https://fetch.spec.whatwg.org/#dom-body-bodyused
  73. */
  74. readonly bodyUsed: boolean
  75. /** Throws on node 16.6.0
  76. *
  77. * If body is null, it should return null as the body
  78. *
  79. * If body is not null, should return the body as a ReadableStream
  80. *
  81. * https://fetch.spec.whatwg.org/#dom-body-body
  82. */
  83. readonly body: never | undefined
  84. /** Dumps the response body by reading `limit` number of bytes.
  85. * @param opts.limit Number of bytes to read (optional) - Default: 262144
  86. */
  87. dump(opts?: { limit: number }): Promise<void>
  88. }
  89. declare function buildConnector (options?: buildConnector.BuildOptions): buildConnector.connector
  90. declare namespace buildConnector {
  91. type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & {
  92. maxCachedSessions?: number | null;
  93. socketPath?: string | null;
  94. timeout?: number | null;
  95. port?: number;
  96. keepAlive?: boolean | null;
  97. keepAliveInitialDelay?: number | null;
  98. }
  99. interface Options {
  100. hostname: string
  101. host?: string
  102. protocol: string
  103. port: string
  104. servername?: string
  105. localAddress?: string | null
  106. httpSocket?: Socket_2
  107. }
  108. type Callback = (...args: CallbackArgs) => void
  109. type CallbackArgs = [null, Socket_2 | TLSSocket] | [Error, null]
  110. type connector = connectorAsync | connectorSync
  111. interface connectorSync {
  112. (options: buildConnector.Options): Socket_2 | TLSSocket
  113. }
  114. interface connectorAsync {
  115. (options: buildConnector.Options, callback: buildConnector.Callback): void
  116. }
  117. }
  118. /**
  119. * An imported module.
  120. */
  121. declare interface CfModule {
  122. /**
  123. * The module name.
  124. *
  125. * @example
  126. * './src/index.js'
  127. */
  128. name: string;
  129. /**
  130. * The module content, usually JavaScript or WASM code.
  131. *
  132. * @example
  133. * export default {
  134. * async fetch(request) {
  135. * return new Response('Ok')
  136. * }
  137. * }
  138. */
  139. content: string | Buffer;
  140. /**
  141. * The module type.
  142. *
  143. * If absent, will default to the main module's type.
  144. */
  145. type?: CfModuleType;
  146. }
  147. /**
  148. * A module type.
  149. */
  150. declare type CfModuleType = "esm" | "commonjs" | "compiled-wasm" | "text" | "buffer";
  151. /** A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default. */
  152. declare class Client extends Dispatcher {
  153. constructor(url: string | URL_2, options?: Client.Options);
  154. /** Property to get and set the pipelining factor. */
  155. pipelining: number;
  156. /** `true` after `client.close()` has been called. */
  157. closed: boolean;
  158. /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
  159. destroyed: boolean;
  160. }
  161. declare namespace Client {
  162. interface Options {
  163. /** the timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */
  164. keepAliveTimeout?: number | null;
  165. /** the maximum allowed `idleTimeout` when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
  166. keepAliveMaxTimeout?: number | null;
  167. /** A number subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
  168. keepAliveTimeoutThreshold?: number | null;
  169. /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
  170. pipelining?: number | null;
  171. /** **/
  172. connect?: buildConnector.BuildOptions | buildConnector.connector | null;
  173. /** The maximum length of request headers in bytes. Default: `16384` (16KiB). */
  174. maxHeaderSize?: number | null;
  175. /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
  176. bodyTimeout?: number | null;
  177. /** The amount of time the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
  178. headersTimeout?: number | null;
  179. /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
  180. strictContentLength?: boolean;
  181. /** @deprecated use the connect option instead */
  182. tls?: TlsOptions | null;
  183. /** */
  184. maxRequestsPerClient?: number;
  185. /** Max response body size in bytes, -1 is disabled */
  186. maxResponseSize?: number | null;
  187. /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
  188. autoSelectFamily?: boolean;
  189. /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
  190. autoSelectFamilyAttemptTimeout?: number;
  191. interceptors?: {Client: readonly Dispatcher[] | undefined}
  192. }
  193. interface SocketInfo {
  194. localAddress?: string
  195. localPort?: number
  196. remoteAddress?: string
  197. remotePort?: number
  198. remoteFamily?: string
  199. timeout?: number
  200. bytesWritten?: number
  201. bytesRead?: number
  202. }
  203. }
  204. /**
  205. * The possible types for a `Rule`.
  206. */
  207. declare type ConfigModuleRuleType = "ESModule" | "CommonJS" | "CompiledWasm" | "Text" | "Data";
  208. declare type CustomDomainRoute = {
  209. pattern: string;
  210. custom_domain: boolean;
  211. };
  212. export declare function deleteMTlsCertificate(accountId: string, certificateId: string): Promise<unknown>;
  213. /**
  214. * Publish a directory to an account/project.
  215. * NOTE: You will need the `CLOUDFLARE_API_KEY` environment
  216. * variable set
  217. */
  218. declare function deploy({ directory, accountId, projectName, branch, skipCaching, commitMessage, commitHash, commitDirty, functionsDirectory: customFunctionsDirectory, bundle, }: PagesDeployOptions): Promise<{
  219. url: string;
  220. environment: "production" | "preview";
  221. id: string;
  222. project_id: string;
  223. project_name: string;
  224. build_config: {
  225. build_command: string;
  226. destination_dir: string;
  227. root_dir: string;
  228. web_analytics_tag?: string | undefined;
  229. web_analytics_token?: string | undefined;
  230. fast_builds?: boolean | undefined;
  231. };
  232. created_on: string;
  233. production_branch: string;
  234. deployment_trigger: {
  235. type: string;
  236. metadata: {
  237. branch: string;
  238. commit_hash: string;
  239. commit_message: string;
  240. };
  241. };
  242. latest_stage: {
  243. name: "build" | "deploy" | "queued" | "initialize" | "clone_repo";
  244. status: "active" | "idle" | "canceled" | "success" | "failure" | "skipped";
  245. started_on: string | null;
  246. ended_on: string | null;
  247. };
  248. stages: {
  249. name: "build" | "deploy" | "queued" | "initialize" | "clone_repo";
  250. status: "active" | "idle" | "canceled" | "success" | "failure" | "skipped";
  251. started_on: string | null;
  252. ended_on: string | null;
  253. }[];
  254. aliases: string[];
  255. modified_on: string;
  256. short_id: string;
  257. build_image_major_version: number;
  258. kv_namespaces?: any;
  259. source?: {
  260. type: "github" | "gitlab";
  261. config: {
  262. owner: string;
  263. repo_name: string;
  264. production_branch?: string | undefined;
  265. pr_comments_enabled?: boolean | undefined;
  266. deployments_enabled?: boolean | undefined;
  267. production_deployments_enabled?: boolean | undefined;
  268. preview_deployment_setting?: "none" | "all" | "custom" | undefined;
  269. preview_branch_includes?: string[] | undefined;
  270. preview_branch_excludes?: string[] | undefined;
  271. };
  272. } | undefined;
  273. env_vars?: any;
  274. durable_object_namespaces?: any;
  275. is_skipped?: boolean | undefined;
  276. files?: {
  277. [x: string]: string | undefined;
  278. } | undefined;
  279. }>;
  280. /**
  281. * Deprecated upload configuration.
  282. */
  283. declare interface DeprecatedUpload {
  284. /**
  285. * The format of the Worker script.
  286. *
  287. * @deprecated We infer the format automatically now.
  288. */
  289. format?: "modules" | "service-worker";
  290. /**
  291. * The directory you wish to upload your worker from,
  292. * relative to the wrangler.toml file.
  293. *
  294. * Defaults to the directory containing the wrangler.toml file.
  295. *
  296. * @deprecated
  297. */
  298. dir?: string;
  299. /**
  300. * The path to the Worker script, relative to `upload.dir`.
  301. *
  302. * @deprecated This will be replaced by a command line argument.
  303. */
  304. main?: string;
  305. /**
  306. * @deprecated This is now defined at the top level `rules` field.
  307. */
  308. rules?: Environment["rules"];
  309. }
  310. /** Dispatcher is the core API used to dispatch requests. */
  311. declare class Dispatcher extends EventEmitter {
  312. /** Dispatches a request. This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs. It is primarily intended for library developers who implement higher level APIs on top of this. */
  313. dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
  314. /** Starts two-way communications with the requested resource. */
  315. connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;
  316. connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
  317. /** Performs an HTTP request. */
  318. request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;
  319. request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
  320. /** For easy use with `stream.pipeline`. */
  321. pipeline(options: Dispatcher.PipelineOptions, handler: Dispatcher.PipelineHandler): Duplex;
  322. /** A faster version of `Dispatcher.request`. */
  323. stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory): Promise<Dispatcher.StreamData>;
  324. stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory, callback: (err: Error | null, data: Dispatcher.StreamData) => void): void;
  325. /** Upgrade to a different protocol. */
  326. upgrade(options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>;
  327. upgrade(options: Dispatcher.UpgradeOptions, callback: (err: Error | null, data: Dispatcher.UpgradeData) => void): void;
  328. /** Closes the client and gracefully waits for enqueued requests to complete before invoking the callback (or returning a promise if no callback is provided). */
  329. close(): Promise<void>;
  330. close(callback: () => void): void;
  331. /** Destroy the client abruptly with the given err. All the pending and running requests will be asynchronously aborted and error. Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided). Since this operation is asynchronously dispatched there might still be some progress on dispatched requests. */
  332. destroy(): Promise<void>;
  333. destroy(err: Error | null): Promise<void>;
  334. destroy(callback: () => void): void;
  335. destroy(err: Error | null, callback: () => void): void;
  336. on(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  337. on(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  338. on(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  339. on(eventName: 'drain', callback: (origin: URL_2) => void): this;
  340. once(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  341. once(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  342. once(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  343. once(eventName: 'drain', callback: (origin: URL_2) => void): this;
  344. off(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  345. off(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  346. off(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  347. off(eventName: 'drain', callback: (origin: URL_2) => void): this;
  348. addListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  349. addListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  350. addListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  351. addListener(eventName: 'drain', callback: (origin: URL_2) => void): this;
  352. removeListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  353. removeListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  354. removeListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  355. removeListener(eventName: 'drain', callback: (origin: URL_2) => void): this;
  356. prependListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  357. prependListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  358. prependListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  359. prependListener(eventName: 'drain', callback: (origin: URL_2) => void): this;
  360. prependOnceListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
  361. prependOnceListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  362. prependOnceListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
  363. prependOnceListener(eventName: 'drain', callback: (origin: URL_2) => void): this;
  364. listeners(eventName: 'connect'): ((origin: URL_2, targets: readonly Dispatcher[]) => void)[]
  365. listeners(eventName: 'disconnect'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
  366. listeners(eventName: 'connectionError'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
  367. listeners(eventName: 'drain'): ((origin: URL_2) => void)[];
  368. rawListeners(eventName: 'connect'): ((origin: URL_2, targets: readonly Dispatcher[]) => void)[]
  369. rawListeners(eventName: 'disconnect'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
  370. rawListeners(eventName: 'connectionError'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
  371. rawListeners(eventName: 'drain'): ((origin: URL_2) => void)[];
  372. emit(eventName: 'connect', origin: URL_2, targets: readonly Dispatcher[]): boolean;
  373. emit(eventName: 'disconnect', origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
  374. emit(eventName: 'connectionError', origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
  375. emit(eventName: 'drain', origin: URL_2): boolean;
  376. }
  377. declare namespace Dispatcher {
  378. interface DispatchOptions {
  379. origin?: string | URL_2;
  380. path: string;
  381. method: HttpMethod;
  382. /** Default: `null` */
  383. body?: string | Buffer | Uint8Array | Readable | null | FormData_2;
  384. /** Default: `null` */
  385. headers?: IncomingHttpHeaders | string[] | null;
  386. /** Query string params to be embedded in the request URL. Default: `null` */
  387. query?: Record<string, any>;
  388. /** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */
  389. idempotent?: boolean;
  390. /** Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received. */
  391. blocking?: boolean;
  392. /** Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`. Default: `method === 'CONNECT' || null`. */
  393. upgrade?: boolean | string | null;
  394. /** The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 300 seconds. */
  395. headersTimeout?: number | null;
  396. /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use 0 to disable it entirely. Defaults to 300 seconds. */
  397. bodyTimeout?: number | null;
  398. /** Whether the request should stablish a keep-alive or not. Default `false` */
  399. reset?: boolean;
  400. /** Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server. Defaults to false */
  401. throwOnError?: boolean;
  402. }
  403. interface ConnectOptions {
  404. path: string;
  405. /** Default: `null` */
  406. headers?: IncomingHttpHeaders | string[] | null;
  407. /** Default: `null` */
  408. signal?: AbortSignal_2 | EventEmitter | null;
  409. /** This argument parameter is passed through to `ConnectData` */
  410. opaque?: unknown;
  411. /** Default: 0 */
  412. maxRedirections?: number;
  413. /** Default: `null` */
  414. responseHeader?: 'raw' | null;
  415. }
  416. interface RequestOptions extends DispatchOptions {
  417. /** Default: `null` */
  418. opaque?: unknown;
  419. /** Default: `null` */
  420. signal?: AbortSignal_2 | EventEmitter | null;
  421. /** Default: 0 */
  422. maxRedirections?: number;
  423. /** Default: `null` */
  424. onInfo?: (info: { statusCode: number, headers: Record<string, string | string[]> }) => void;
  425. /** Default: `null` */
  426. responseHeader?: 'raw' | null;
  427. }
  428. interface PipelineOptions extends RequestOptions {
  429. /** `true` if the `handler` will return an object stream. Default: `false` */
  430. objectMode?: boolean;
  431. }
  432. interface UpgradeOptions {
  433. path: string;
  434. /** Default: `'GET'` */
  435. method?: string;
  436. /** Default: `null` */
  437. headers?: IncomingHttpHeaders | string[] | null;
  438. /** A string of comma separated protocols, in descending preference order. Default: `'Websocket'` */
  439. protocol?: string;
  440. /** Default: `null` */
  441. signal?: AbortSignal_2 | EventEmitter | null;
  442. /** Default: 0 */
  443. maxRedirections?: number;
  444. /** Default: `null` */
  445. responseHeader?: 'raw' | null;
  446. }
  447. interface ConnectData {
  448. statusCode: number;
  449. headers: IncomingHttpHeaders;
  450. socket: Duplex;
  451. opaque: unknown;
  452. }
  453. interface ResponseData {
  454. statusCode: number;
  455. headers: IncomingHttpHeaders;
  456. body: BodyReadable & BodyMixin;
  457. trailers: Record<string, string>;
  458. opaque: unknown;
  459. context: object;
  460. }
  461. interface PipelineHandlerData {
  462. statusCode: number;
  463. headers: IncomingHttpHeaders;
  464. opaque: unknown;
  465. body: BodyReadable;
  466. context: object;
  467. }
  468. interface StreamData {
  469. opaque: unknown;
  470. trailers: Record<string, string>;
  471. }
  472. interface UpgradeData {
  473. headers: IncomingHttpHeaders;
  474. socket: Duplex;
  475. opaque: unknown;
  476. }
  477. interface StreamFactoryData {
  478. statusCode: number;
  479. headers: IncomingHttpHeaders;
  480. opaque: unknown;
  481. context: object;
  482. }
  483. type StreamFactory = (data: StreamFactoryData) => Writable;
  484. interface DispatchHandlers {
  485. /** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
  486. onConnect?(abort: () => void): void;
  487. /** Invoked when an error has occurred. */
  488. onError?(err: Error): void;
  489. /** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
  490. onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
  491. /** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
  492. onHeaders?(statusCode: number, headers: Buffer[] | string[] | null, resume: () => void): boolean;
  493. /** Invoked when response payload data is received. */
  494. onData?(chunk: Buffer): boolean;
  495. /** Invoked when response payload and trailers have been received and the request has completed. */
  496. onComplete?(trailers: string[] | null): void;
  497. /** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
  498. onBodySent?(chunkSize: number, totalBytesSent: number): void;
  499. }
  500. type PipelineHandler = (data: PipelineHandlerData) => Readable;
  501. type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
  502. /**
  503. * @link https://fetch.spec.whatwg.org/#body-mixin
  504. */
  505. interface BodyMixin {
  506. readonly body?: never; // throws on node v16.6.0
  507. readonly bodyUsed: boolean;
  508. arrayBuffer(): Promise<ArrayBuffer>;
  509. blob(): Promise<Blob_2>;
  510. formData(): Promise<never>;
  511. json(): Promise<any>;
  512. text(): Promise<string>;
  513. }
  514. interface DispatchInterceptor {
  515. (dispatch: Dispatcher['dispatch']): Dispatcher['dispatch']
  516. }
  517. }
  518. declare interface DispatchNamespaceOutbound {
  519. /** Name of the service handling the outbound requests */
  520. service: string;
  521. /** (Optional) Name of the environment handling the outbound requests. */
  522. environment?: string;
  523. /** (Optional) List of parameter names, for sending context from your dispatch worker to the outbound handler */
  524. parameters?: string[];
  525. }
  526. declare type DurableObjectBindings = {
  527. /** The name of the binding used to refer to the Durable Object */
  528. name: string;
  529. /** The exported class name of the Durable Object */
  530. class_name: string;
  531. /** The script where the Durable Object is defined (if it's external to this worker) */
  532. script_name?: string;
  533. /** The service environment of the script_name to bind to */
  534. environment?: string;
  535. }[];
  536. declare interface EnablePagesAssetsServiceBindingOptions {
  537. proxyPort?: number;
  538. directory?: string;
  539. }
  540. /**
  541. * The `Environment` interface declares all the configuration fields that
  542. * can be specified for an environment.
  543. *
  544. * This could be the top-level default environment, or a specific named environment.
  545. */
  546. declare interface Environment extends EnvironmentInheritable, EnvironmentNonInheritable {
  547. }
  548. /**
  549. * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
  550. * that can be inherited (and overridden) from the top-level environment.
  551. */
  552. declare interface EnvironmentInheritable {
  553. /**
  554. * The name of your worker. Alphanumeric + dashes only.
  555. *
  556. * @inheritable
  557. */
  558. name: string | undefined;
  559. /**
  560. * This is the ID of the account associated with your zone.
  561. * You might have more than one account, so make sure to use
  562. * the ID of the account associated with the zone/route you
  563. * provide, if you provide one. It can also be specified through
  564. * the CLOUDFLARE_ACCOUNT_ID environment variable.
  565. *
  566. * @inheritable
  567. */
  568. account_id: string | undefined;
  569. /**
  570. * A date in the form yyyy-mm-dd, which will be used to determine
  571. * which version of the Workers runtime is used.
  572. *
  573. * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
  574. *
  575. * @inheritable
  576. */
  577. compatibility_date: string | undefined;
  578. /**
  579. * A list of flags that enable features from upcoming features of
  580. * the Workers runtime, usually used together with compatibility_flags.
  581. *
  582. * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
  583. *
  584. * @inheritable
  585. */
  586. compatibility_flags: string[];
  587. /**
  588. * The entrypoint/path to the JavaScript file that will be executed.
  589. */
  590. main: string | undefined;
  591. /**
  592. * The directory in which module rules should be evaluated in a `--no-bundle` worker
  593. * This defaults to dirname(main) when left undefined
  594. */
  595. base_dir: string | undefined;
  596. /**
  597. * Whether we use <name>.<subdomain>.workers.dev to
  598. * test and deploy your worker.
  599. *
  600. * @default `true` (This is a breaking change from Wrangler v1)
  601. * @breaking
  602. * @inheritable
  603. */
  604. workers_dev: boolean | undefined;
  605. /**
  606. * A list of routes that your worker should be published to.
  607. * Only one of `routes` or `route` is required.
  608. *
  609. * Only required when workers_dev is false, and there's no scheduled worker (see `triggers`)
  610. *
  611. * @inheritable
  612. */
  613. routes: Route[] | undefined;
  614. /**
  615. * A route that your worker should be published to. Literally
  616. * the same as routes, but only one.
  617. * Only one of `routes` or `route` is required.
  618. *
  619. * Only required when workers_dev is false, and there's no scheduled worker
  620. *
  621. * @inheritable
  622. */
  623. route: Route | undefined;
  624. /**
  625. * Path to a custom tsconfig
  626. */
  627. tsconfig: string | undefined;
  628. /**
  629. * The function to use to replace jsx syntax.
  630. *
  631. * @default `"React.createElement"`
  632. * @inheritable
  633. */
  634. jsx_factory: string;
  635. /**
  636. * The function to use to replace jsx fragment syntax.
  637. *
  638. * @default `"React.Fragment"`
  639. * @inheritable
  640. */
  641. jsx_fragment: string;
  642. /**
  643. * "Cron" definitions to trigger a worker's "scheduled" function.
  644. *
  645. * Lets you call workers periodically, much like a cron job.
  646. *
  647. * More details here https://developers.cloudflare.com/workers/platform/cron-triggers
  648. *
  649. * @default `{crons:[]}`
  650. * @inheritable
  651. */
  652. triggers: {
  653. crons: string[];
  654. };
  655. /**
  656. * Specifies the Usage Model for your Worker. There are two options -
  657. * [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
  658. * [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
  659. * For newly created Workers, if the Usage Model is omitted
  660. * it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
  661. * For existing Workers, if the Usage Model is omitted, it will be
  662. * set to the Usage Model configured in the dashboard for that Worker.
  663. *
  664. * @inheritable
  665. */
  666. usage_model: "bundled" | "unbound" | undefined;
  667. /**
  668. * An ordered list of rules that define which modules to import,
  669. * and what type to import them as. You will need to specify rules
  670. * to use Text, Data, and CompiledWasm modules, or when you wish to
  671. * have a .js file be treated as an ESModule instead of CommonJS.
  672. *
  673. * @inheritable
  674. */
  675. rules: Rule[];
  676. /**
  677. * Configures a custom build step to be run by Wrangler when building your Worker.
  678. *
  679. * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
  680. * for more details.
  681. *
  682. * @default {}
  683. */
  684. build: {
  685. /** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
  686. command?: string;
  687. /** The directory in which the command is executed. */
  688. cwd?: string;
  689. /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
  690. watch_dir?: string | string[];
  691. /**
  692. * Deprecated field previously used to configure the build and upload of the script.
  693. * @deprecated
  694. */
  695. upload?: DeprecatedUpload;
  696. };
  697. /**
  698. * Skip internal build steps and directly deploy script
  699. * @inheritable
  700. */
  701. no_bundle: boolean | undefined;
  702. /**
  703. * Minify the script before uploading.
  704. * @inheritable
  705. */
  706. minify: boolean | undefined;
  707. /**
  708. * Add polyfills for node builtin modules and globals
  709. * @inheritable
  710. */
  711. node_compat: boolean | undefined;
  712. /**
  713. * Specifies namespace bindings that are bound to this Worker environment.
  714. *
  715. * NOTE: This field is not automatically inherited from the top level environment,
  716. * and so must be specified in every named environment.
  717. *
  718. * @default `[]`
  719. * @nonInheritable
  720. */
  721. dispatch_namespaces: {
  722. /** The binding name used to refer to the bound service. */
  723. binding: string;
  724. /** The namespace to bind to. */
  725. namespace: string;
  726. /** Details about the outbound worker which will handle outbound requests from your namespace */
  727. outbound?: DispatchNamespaceOutbound;
  728. }[];
  729. /**
  730. * Designates this worker as an internal-only "first-party" worker.
  731. */
  732. first_party_worker: boolean | undefined;
  733. /**
  734. * TODO: remove this as it has been deprecated.
  735. *
  736. * This is just here for now because the `route` commands use it.
  737. * So we need to include it in this type so it is available.
  738. */
  739. zone_id?: string;
  740. /**
  741. * List of bindings that you will send to logfwdr
  742. *
  743. * @default `{bindings:[]}`
  744. * @inheritable
  745. */
  746. logfwdr: {
  747. bindings: {
  748. /** The binding name used to refer to logfwdr */
  749. name: string;
  750. /** The destination for this logged message */
  751. destination: string;
  752. }[];
  753. };
  754. /**
  755. * Send Trace Events from this worker to Workers Logpush.
  756. *
  757. * This will not configure a corresponding Logpush job automatically.
  758. *
  759. * For more information about Workers Logpush, see:
  760. * https://blog.cloudflare.com/logpush-for-workers/
  761. *
  762. * @inheritable
  763. */
  764. logpush: boolean | undefined;
  765. /**
  766. * Specify how the worker should be located to minimize round-trip time.
  767. *
  768. * More details: https://developers.cloudflare.com/workers/platform/smart-placement/
  769. */
  770. placement: {
  771. mode: "off" | "smart";
  772. } | undefined;
  773. }
  774. /**
  775. * The `EnvironmentNonInheritable` interface declares all the configuration fields for an environment
  776. * that cannot be inherited from the top-level environment, and must be defined specifically.
  777. *
  778. * If any of these fields are defined at the top-level then they should also be specifically defined
  779. * for each named environment.
  780. */
  781. declare interface EnvironmentNonInheritable {
  782. /**
  783. * A map of values to substitute when deploying your worker.
  784. *
  785. * NOTE: This field is not automatically inherited from the top level environment,
  786. * and so must be specified in every named environment.
  787. *
  788. * @default `{}`
  789. * @nonInheritable
  790. */
  791. define: Record<string, string>;
  792. /**
  793. * A map of environment variables to set when deploying your worker.
  794. *
  795. * NOTE: This field is not automatically inherited from the top level environment,
  796. * and so must be specified in every named environment.
  797. *
  798. * @default `{}`
  799. * @nonInheritable
  800. */
  801. vars: Record<string, string | Json>;
  802. /**
  803. * A list of durable objects that your worker should be bound to.
  804. *
  805. * For more information about Durable Objects, see the documentation at
  806. * https://developers.cloudflare.com/workers/learning/using-durable-objects
  807. *
  808. * NOTE: This field is not automatically inherited from the top level environment,
  809. * and so must be specified in every named environment.
  810. *
  811. * @default `{bindings:[]}`
  812. * @nonInheritable
  813. */
  814. durable_objects: {
  815. bindings: DurableObjectBindings;
  816. };
  817. /**
  818. * These specify any Workers KV Namespaces you want to
  819. * access from inside your Worker.
  820. *
  821. * To learn more about KV Namespaces,
  822. * see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
  823. *
  824. * NOTE: This field is not automatically inherited from the top level environment,
  825. * and so must be specified in every named environment.
  826. *
  827. * @default `[]`
  828. * @nonInheritable
  829. */
  830. kv_namespaces: {
  831. /** The binding name used to refer to the KV Namespace */
  832. binding: string;
  833. /** The ID of the KV namespace */
  834. id: string;
  835. /** The ID of the KV namespace used during `wrangler dev` */
  836. preview_id?: string;
  837. }[];
  838. /**
  839. * These specify bindings to send email from inside your Worker.
  840. *
  841. * NOTE: This field is not automatically inherited from the top level environment,
  842. * and so must be specified in every named environment.
  843. *
  844. * @default `[]`
  845. * @nonInheritable
  846. */
  847. send_email: {
  848. /** The binding name used to refer to the this binding */
  849. name: string;
  850. /** If this binding should be restricted to a specific verified address */
  851. destination_address?: string;
  852. /** If this binding should be restricted to a set of verified addresses */
  853. allowed_destination_addresses?: string[];
  854. }[];
  855. /**
  856. * Specifies Queues that are bound to this Worker environment.
  857. *
  858. * NOTE: This field is not automatically inherited from the top level environment,
  859. * and so must be specified in every named environment.
  860. *
  861. * @default `{}`
  862. * @nonInheritable
  863. */
  864. queues: {
  865. /** Producer bindings */
  866. producers?: {
  867. /** The binding name used to refer to the Queue in the worker. */
  868. binding: string;
  869. /** The name of this Queue. */
  870. queue: string;
  871. }[];
  872. /** Consumer configuration */
  873. consumers?: {
  874. /** The name of the queue from which this script should consume. */
  875. queue: string;
  876. /** The maximum number of messages per batch */
  877. max_batch_size?: number;
  878. /** The maximum number of seconds to wait to fill a batch with messages. */
  879. max_batch_timeout?: number;
  880. /** The maximum number of retries for each message. */
  881. max_retries?: number;
  882. /** The queue to send messages that failed to be consumed. */
  883. dead_letter_queue?: string;
  884. /** The maximum number of concurrent consumer Worker invocations. Leaving this unset will allow your consumer to scale to the maximum concurrency needed to keep up with the message backlog. */
  885. max_concurrency?: number | null;
  886. }[];
  887. };
  888. /**
  889. * Specifies R2 buckets that are bound to this Worker environment.
  890. *
  891. * NOTE: This field is not automatically inherited from the top level environment,
  892. * and so must be specified in every named environment.
  893. *
  894. * @default `[]`
  895. * @nonInheritable
  896. */
  897. r2_buckets: {
  898. /** The binding name used to refer to the R2 bucket in the worker. */
  899. binding: string;
  900. /** The name of this R2 bucket at the edge. */
  901. bucket_name: string;
  902. /** The preview name of this R2 bucket at the edge. */
  903. preview_bucket_name?: string;
  904. }[];
  905. /**
  906. * Specifies D1 databases that are bound to this Worker environment.
  907. *
  908. * NOTE: This field is not automatically inherited from the top level environment,
  909. * and so must be specified in every named environment.
  910. *
  911. * @default `[]`
  912. * @nonInheritable
  913. */
  914. d1_databases: {
  915. /** The binding name used to refer to the D1 database in the worker. */
  916. binding: string;
  917. /** The name of this D1 database. */
  918. database_name: string;
  919. /** The UUID of this D1 database (not required). */
  920. database_id: string;
  921. /** The UUID of this D1 database for Wrangler Dev (if specified). */
  922. preview_database_id?: string;
  923. /** The name of the migrations table for this D1 database (defaults to 'd1_migrations'). */
  924. migrations_table?: string;
  925. /** The path to the directory of migrations for this D1 database (defaults to './migrations'). */
  926. migrations_dir?: string;
  927. /** Internal use only. */
  928. database_internal_env?: string;
  929. }[];
  930. /**
  931. * Specifies Constellation projects that are bound to this Worker environment.
  932. *
  933. * NOTE: This field is not automatically inherited from the top level environment,
  934. * and so must be specified in every named environment.
  935. *
  936. * @default `[]`
  937. * @nonInheritable
  938. */
  939. constellation: {
  940. /** The binding name used to refer to the project in the worker. */
  941. binding: string;
  942. /** The id of the project. */
  943. project_id: string;
  944. }[];
  945. /**
  946. * Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
  947. *
  948. * NOTE: This field is not automatically inherited from the top level environment,
  949. * and so must be specified in every named environment.
  950. *
  951. * @default `[]`
  952. * @nonInheritable
  953. */
  954. services: {
  955. /** The binding name used to refer to the bound service. */
  956. binding: string;
  957. /** The name of the service. */
  958. service: string;
  959. /** The environment of the service (e.g. production, staging, etc). */
  960. environment?: string;
  961. }[] | undefined;
  962. /**
  963. * Specifies analytics engine datasets that are bound to this Worker environment.
  964. *
  965. * NOTE: This field is not automatically inherited from the top level environment,
  966. * and so must be specified in every named environment.
  967. *
  968. * @default `[]`
  969. * @nonInheritable
  970. */
  971. analytics_engine_datasets: {
  972. /** The binding name used to refer to the dataset in the worker. */
  973. binding: string;
  974. /** The name of this dataset to write to. */
  975. dataset?: string;
  976. }[];
  977. /**
  978. * A browser that will be usable from the worker.
  979. */
  980. browser: {
  981. binding: string;
  982. } | undefined;
  983. /**
  984. * "Unsafe" tables for features that aren't directly supported by wrangler.
  985. *
  986. * NOTE: This field is not automatically inherited from the top level environment,
  987. * and so must be specified in every named environment.
  988. *
  989. * @nonInheritable
  990. */
  991. unsafe: {
  992. /**
  993. * A set of bindings that should be put into a Worker's upload metadata without changes. These
  994. * can be used to implement bindings for features that haven't released and aren't supported
  995. * directly by wrangler or miniflare.
  996. */
  997. bindings?: {
  998. name: string;
  999. type: string;
  1000. [key: string]: unknown;
  1001. }[];
  1002. /**
  1003. * Arbitrary key/value pairs that will be included in the uploaded metadata. Values specified
  1004. * here will always be applied to metadata last, so can add new or override existing fields.
  1005. */
  1006. metadata?: {
  1007. [key: string]: string;
  1008. };
  1009. /**
  1010. * Used for internal capnp uploads for the Workers runtime
  1011. */
  1012. capnp?: {
  1013. base_path: string;
  1014. source_schemas: string[];
  1015. compiled_schema?: never;
  1016. } | {
  1017. base_path?: never;
  1018. source_schemas?: never;
  1019. compiled_schema: string;
  1020. };
  1021. };
  1022. mtls_certificates: {
  1023. /** The binding name used to refer to the certificate in the worker */
  1024. binding: string;
  1025. /** The uuid of the uploaded mTLS certificate */
  1026. certificate_id: string;
  1027. }[];
  1028. tail_consumers?: TailConsumer[];
  1029. }
  1030. declare namespace Errors {
  1031. class UndiciError extends Error { }
  1032. /** Connect timeout error. */
  1033. class ConnectTimeoutError extends UndiciError {
  1034. name: 'ConnectTimeoutError';
  1035. code: 'UND_ERR_CONNECT_TIMEOUT';
  1036. }
  1037. /** A header exceeds the `headersTimeout` option. */
  1038. class HeadersTimeoutError extends UndiciError {
  1039. name: 'HeadersTimeoutError';
  1040. code: 'UND_ERR_HEADERS_TIMEOUT';
  1041. }
  1042. /** Headers overflow error. */
  1043. class HeadersOverflowError extends UndiciError {
  1044. name: 'HeadersOverflowError'
  1045. code: 'UND_ERR_HEADERS_OVERFLOW'
  1046. }
  1047. /** A body exceeds the `bodyTimeout` option. */
  1048. class BodyTimeoutError extends UndiciError {
  1049. name: 'BodyTimeoutError';
  1050. code: 'UND_ERR_BODY_TIMEOUT';
  1051. }
  1052. class ResponseStatusCodeError extends UndiciError {
  1053. name: 'ResponseStatusCodeError';
  1054. code: 'UND_ERR_RESPONSE_STATUS_CODE';
  1055. body: null | Record<string, any> | string
  1056. status: number
  1057. statusCode: number
  1058. headers: IncomingHttpHeaders | string[] | null;
  1059. }
  1060. /** Passed an invalid argument. */
  1061. class InvalidArgumentError extends UndiciError {
  1062. name: 'InvalidArgumentError';
  1063. code: 'UND_ERR_INVALID_ARG';
  1064. }
  1065. /** Returned an invalid value. */
  1066. class InvalidReturnValueError extends UndiciError {
  1067. name: 'InvalidReturnValueError';
  1068. code: 'UND_ERR_INVALID_RETURN_VALUE';
  1069. }
  1070. /** The request has been aborted by the user. */
  1071. class RequestAbortedError extends UndiciError {
  1072. name: 'AbortError';
  1073. code: 'UND_ERR_ABORTED';
  1074. }
  1075. /** Expected error with reason. */
  1076. class InformationalError extends UndiciError {
  1077. name: 'InformationalError';
  1078. code: 'UND_ERR_INFO';
  1079. }
  1080. /** Request body length does not match content-length header. */
  1081. class RequestContentLengthMismatchError extends UndiciError {
  1082. name: 'RequestContentLengthMismatchError';
  1083. code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH';
  1084. }
  1085. /** Response body length does not match content-length header. */
  1086. class ResponseContentLengthMismatchError extends UndiciError {
  1087. name: 'ResponseContentLengthMismatchError';
  1088. code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH';
  1089. }
  1090. /** Trying to use a destroyed client. */
  1091. class ClientDestroyedError extends UndiciError {
  1092. name: 'ClientDestroyedError';
  1093. code: 'UND_ERR_DESTROYED';
  1094. }
  1095. /** Trying to use a closed client. */
  1096. class ClientClosedError extends UndiciError {
  1097. name: 'ClientClosedError';
  1098. code: 'UND_ERR_CLOSED';
  1099. }
  1100. /** There is an error with the socket. */
  1101. class SocketError extends UndiciError {
  1102. name: 'SocketError';
  1103. code: 'UND_ERR_SOCKET';
  1104. socket: Client.SocketInfo | null
  1105. }
  1106. /** Encountered unsupported functionality. */
  1107. class NotSupportedError extends UndiciError {
  1108. name: 'NotSupportedError';
  1109. code: 'UND_ERR_NOT_SUPPORTED';
  1110. }
  1111. /** No upstream has been added to the BalancedPool. */
  1112. class BalancedPoolMissingUpstreamError extends UndiciError {
  1113. name: 'MissingUpstreamError';
  1114. code: 'UND_ERR_BPL_MISSING_UPSTREAM';
  1115. }
  1116. class HTTPParserError extends UndiciError {
  1117. name: 'HTTPParserError';
  1118. code: string;
  1119. }
  1120. /** The response exceed the length allowed. */
  1121. class ResponseExceededMaxSizeError extends UndiciError {
  1122. name: 'ResponseExceededMaxSizeError';
  1123. code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
  1124. }
  1125. }
  1126. declare class File_2 extends Blob_2 {
  1127. /**
  1128. * Creates a new File instance.
  1129. *
  1130. * @param fileBits An `Array` strings, or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), [`ArrayBufferView`](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects, or a mix of any of such objects, that will be put inside the [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
  1131. * @param fileName The name of the file.
  1132. * @param options An options object containing optional attributes for the file.
  1133. */
  1134. constructor(fileBits: ReadonlyArray<string | NodeJS.ArrayBufferView | Blob_2>, fileName: string, options?: FilePropertyBag)
  1135. /**
  1136. * Name of the file referenced by the File object.
  1137. */
  1138. readonly name: string
  1139. /**
  1140. * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
  1141. */
  1142. readonly lastModified: number
  1143. readonly [Symbol.toStringTag]: string
  1144. }
  1145. declare interface FilePropertyBag extends BlobPropertyBag {
  1146. /**
  1147. * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
  1148. */
  1149. lastModified?: number
  1150. }
  1151. /**
  1152. * Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using fetch().
  1153. */
  1154. declare class FormData_2 {
  1155. /**
  1156. * Appends a new value onto an existing key inside a FormData object,
  1157. * or adds the key if it does not already exist.
  1158. *
  1159. * The difference between `set()` and `append()` is that if the specified key already exists, `set()` will overwrite all existing values with the new one, whereas `append()` will append the new value onto the end of the existing set of values.
  1160. *
  1161. * @param name The name of the field whose data is contained in `value`.
  1162. * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
  1163. or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
  1164. * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
  1165. */
  1166. append(name: string, value: unknown, fileName?: string): void
  1167. /**
  1168. * Set a new value for an existing key inside FormData,
  1169. * or add the new field if it does not already exist.
  1170. *
  1171. * @param name The name of the field whose data is contained in `value`.
  1172. * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
  1173. or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
  1174. * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
  1175. *
  1176. */
  1177. set(name: string, value: unknown, fileName?: string): void
  1178. /**
  1179. * Returns the first value associated with a given key from within a `FormData` object.
  1180. * If you expect multiple values and want all of them, use the `getAll()` method instead.
  1181. *
  1182. * @param {string} name A name of the value you want to retrieve.
  1183. *
  1184. * @returns A `FormDataEntryValue` containing the value. If the key doesn't exist, the method returns null.
  1185. */
  1186. get(name: string): FormDataEntryValue | null
  1187. /**
  1188. * Returns all the values associated with a given key from within a `FormData` object.
  1189. *
  1190. * @param {string} name A name of the value you want to retrieve.
  1191. *
  1192. * @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
  1193. */
  1194. getAll(name: string): FormDataEntryValue[]
  1195. /**
  1196. * Returns a boolean stating whether a `FormData` object contains a certain key.
  1197. *
  1198. * @param name A string representing the name of the key you want to test for.
  1199. *
  1200. * @return A boolean value.
  1201. */
  1202. has(name: string): boolean
  1203. /**
  1204. * Deletes a key and its value(s) from a `FormData` object.
  1205. *
  1206. * @param name The name of the key you want to delete.
  1207. */
  1208. delete(name: string): void
  1209. /**
  1210. * Executes given callback function for each field of the FormData instance
  1211. */
  1212. forEach: (
  1213. callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData_2) => void,
  1214. thisArg?: unknown
  1215. ) => void
  1216. /**
  1217. * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all keys contained in this `FormData` object.
  1218. * Each key is a `string`.
  1219. */
  1220. keys: () => SpecIterableIterator<string>
  1221. /**
  1222. * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all values contained in this object `FormData` object.
  1223. * Each value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
  1224. */
  1225. values: () => SpecIterableIterator<FormDataEntryValue>
  1226. /**
  1227. * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through the `FormData` key/value pairs.
  1228. * The key of each pair is a string; the value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
  1229. */
  1230. entries: () => SpecIterableIterator<[string, FormDataEntryValue]>
  1231. /**
  1232. * An alias for FormData#entries()
  1233. */
  1234. [Symbol.iterator]: () => SpecIterableIterator<[string, FormDataEntryValue]>
  1235. readonly [Symbol.toStringTag]: string
  1236. }
  1237. /**
  1238. * A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.
  1239. */
  1240. declare type FormDataEntryValue = string | File_2
  1241. /**
  1242. * fetches an mTLS certificate from the account mTLS certificate store by ID
  1243. */
  1244. export declare function getMTlsCertificate(accountId: string, id: string): Promise<MTlsCertificateResponse>;
  1245. /**
  1246. * fetches an mTLS certificate from the account mTLS certificate store by name. will throw an error if no certificates are found, or multiple are found with that name
  1247. */
  1248. export declare function getMTlsCertificateByName(accountId: string, name: string): Promise<MTlsCertificateResponse>;
  1249. declare class Headers_2 implements SpecIterable<[string, string]> {
  1250. constructor (init?: HeadersInit_2)
  1251. readonly append: (name: string, value: string) => void
  1252. readonly delete: (name: string) => void
  1253. readonly get: (name: string) => string | null
  1254. readonly has: (name: string) => boolean
  1255. readonly set: (name: string, value: string) => void
  1256. readonly getSetCookie: () => string[]
  1257. readonly forEach: (
  1258. callbackfn: (value: string, key: string, iterable: Headers_2) => void,
  1259. thisArg?: unknown
  1260. ) => void
  1261. readonly keys: () => SpecIterableIterator<string>
  1262. readonly values: () => SpecIterableIterator<string>
  1263. readonly entries: () => SpecIterableIterator<[string, string]>
  1264. readonly [Symbol.iterator]: () => SpecIterator<[string, string]>
  1265. }
  1266. declare type HeadersInit_2 = string[][] | Record<string, string | ReadonlyArray<string>> | Headers_2
  1267. /**
  1268. * The header type declaration of `undici`.
  1269. */
  1270. declare type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
  1271. /**
  1272. * lists mTLS certificates for an account. filtering by name is supported
  1273. */
  1274. export declare function listMTlsCertificates(accountId: string, filter: MTlsCertificateListFilter): Promise<MTlsCertificateResponse[]>;
  1275. /**
  1276. * details for uploading an mTLS certificate via the ssl api
  1277. */
  1278. declare interface MTlsCertificateBody {
  1279. certificateChain: string;
  1280. privateKey: string;
  1281. name?: string;
  1282. }
  1283. /**
  1284. * supported filters for listing mTLS certificates via the ssl api
  1285. */
  1286. declare interface MTlsCertificateListFilter {
  1287. name?: string;
  1288. }
  1289. /**
  1290. * the representation of an mTLS certificate in the account certificate store
  1291. */
  1292. declare interface MTlsCertificateResponse {
  1293. id: string;
  1294. name?: string;
  1295. ca: boolean;
  1296. certificates: string;
  1297. expires_on: string;
  1298. issuer: string;
  1299. serial_number: string;
  1300. signature: string;
  1301. uploaded_on: string;
  1302. }
  1303. /**
  1304. * details for uploading an mTLS certificate from disk
  1305. */
  1306. declare interface MTlsCertificateUploadDetails {
  1307. certificateChainFilename: string;
  1308. privateKeyFilename: string;
  1309. name?: string;
  1310. }
  1311. declare interface PagesDeployOptions {
  1312. /**
  1313. * Path to static assets to deploy to Pages
  1314. */
  1315. directory: string;
  1316. /**
  1317. * The Cloudflare Account ID that owns the project that's
  1318. * being published
  1319. */
  1320. accountId: string;
  1321. /**
  1322. * The name of the project to be published
  1323. */
  1324. projectName: string;
  1325. /**
  1326. * Branch name to use. Defaults to production branch
  1327. */
  1328. branch?: string;
  1329. /**
  1330. * Whether or not to skip local file upload result caching
  1331. */
  1332. skipCaching?: boolean;
  1333. /**
  1334. * Commit message associated to deployment
  1335. */
  1336. commitMessage?: string;
  1337. /**
  1338. * Commit hash associated to deployment
  1339. */
  1340. commitHash?: string;
  1341. /**
  1342. * Whether or not the deployment should be considered to be
  1343. * in a dirty commit state
  1344. */
  1345. commitDirty?: boolean;
  1346. /**
  1347. * Path to the project's functions directory. Default uses
  1348. * the current working directory + /functions since this is
  1349. * typically called in a CLI
  1350. */
  1351. functionsDirectory?: string;
  1352. /**
  1353. * Whether to run bundling on `_worker.js` before deploying.
  1354. * Default: true
  1355. */
  1356. bundle?: boolean;
  1357. }
  1358. declare type ReferrerPolicy =
  1359. | ''
  1360. | 'no-referrer'
  1361. | 'no-referrer-when-downgrade'
  1362. | 'origin'
  1363. | 'origin-when-cross-origin'
  1364. | 'same-origin'
  1365. | 'strict-origin'
  1366. | 'strict-origin-when-cross-origin'
  1367. | 'unsafe-url';
  1368. declare class Request_2 implements BodyMixin {
  1369. constructor (input: RequestInfo_2, init?: RequestInit_2)
  1370. readonly cache: RequestCache
  1371. readonly credentials: RequestCredentials
  1372. readonly destination: RequestDestination
  1373. readonly headers: Headers_2
  1374. readonly integrity: string
  1375. readonly method: string
  1376. readonly mode: RequestMode
  1377. readonly redirect: RequestRedirect
  1378. readonly referrerPolicy: string
  1379. readonly url: string
  1380. readonly keepalive: boolean
  1381. readonly signal: AbortSignal
  1382. readonly duplex: RequestDuplex
  1383. readonly body: ReadableStream_2 | null
  1384. readonly bodyUsed: boolean
  1385. readonly arrayBuffer: () => Promise<ArrayBuffer>
  1386. readonly blob: () => Promise<Blob_2>
  1387. readonly formData: () => Promise<FormData_2>
  1388. readonly json: () => Promise<unknown>
  1389. readonly text: () => Promise<string>
  1390. readonly clone: () => Request_2
  1391. }
  1392. declare type RequestCache =
  1393. | 'default'
  1394. | 'force-cache'
  1395. | 'no-cache'
  1396. | 'no-store'
  1397. | 'only-if-cached'
  1398. | 'reload'
  1399. declare type RequestCredentials = 'omit' | 'include' | 'same-origin'
  1400. declare type RequestDestination =
  1401. | ''
  1402. | 'audio'
  1403. | 'audioworklet'
  1404. | 'document'
  1405. | 'embed'
  1406. | 'font'
  1407. | 'image'
  1408. | 'manifest'
  1409. | 'object'
  1410. | 'paintworklet'
  1411. | 'report'
  1412. | 'script'
  1413. | 'sharedworker'
  1414. | 'style'
  1415. | 'track'
  1416. | 'video'
  1417. | 'worker'
  1418. | 'xslt'
  1419. declare type RequestDuplex = 'half'
  1420. declare type RequestInfo_2 = string | URL_2 | Request_2
  1421. declare interface RequestInit_2 {
  1422. method?: string
  1423. keepalive?: boolean
  1424. headers?: HeadersInit_2
  1425. body?: BodyInit_2
  1426. redirect?: RequestRedirect
  1427. integrity?: string
  1428. signal?: AbortSignal
  1429. credentials?: RequestCredentials
  1430. mode?: RequestMode
  1431. referrer?: string
  1432. referrerPolicy?: ReferrerPolicy
  1433. window?: null
  1434. dispatcher?: Dispatcher
  1435. duplex?: RequestDuplex
  1436. }
  1437. declare type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin'
  1438. declare type RequestRedirect = 'error' | 'follow' | 'manual'
  1439. declare class Response_2 implements BodyMixin {
  1440. constructor (body?: BodyInit_2, init?: ResponseInit_2)
  1441. readonly headers: Headers_2
  1442. readonly ok: boolean
  1443. readonly status: number
  1444. readonly statusText: string
  1445. readonly type: ResponseType
  1446. readonly url: string
  1447. readonly redirected: boolean
  1448. readonly body: ReadableStream_2 | null
  1449. readonly bodyUsed: boolean
  1450. readonly arrayBuffer: () => Promise<ArrayBuffer>
  1451. readonly blob: () => Promise<Blob_2>
  1452. readonly formData: () => Promise<FormData_2>
  1453. readonly json: () => Promise<unknown>
  1454. readonly text: () => Promise<string>
  1455. readonly clone: () => Response_2
  1456. static error (): Response_2
  1457. static json(data: any, init?: ResponseInit_2): Response_2
  1458. static redirect (url: string | URL_2, status: ResponseRedirectStatus): Response_2
  1459. }
  1460. declare interface ResponseInit_2 {
  1461. readonly status?: number
  1462. readonly statusText?: string
  1463. readonly headers?: HeadersInit_2
  1464. }
  1465. declare type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308
  1466. declare type ResponseType =
  1467. | 'basic'
  1468. | 'cors'
  1469. | 'default'
  1470. | 'error'
  1471. | 'opaque'
  1472. | 'opaqueredirect'
  1473. declare type Route = SimpleRoute | ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;
  1474. /**
  1475. * A bundling resolver rule, defining the modules type for paths that match the specified globs.
  1476. */
  1477. declare type Rule = {
  1478. type: ConfigModuleRuleType;
  1479. globs: string[];
  1480. fallthrough?: boolean;
  1481. };
  1482. declare type SimpleRoute = string;
  1483. declare interface SpecIterable<T> {
  1484. [Symbol.iterator](): SpecIterator<T>;
  1485. }
  1486. declare interface SpecIterableIterator<T> extends SpecIterator<T> {
  1487. [Symbol.iterator](): SpecIterableIterator<T>;
  1488. }
  1489. declare interface SpecIterator<T, TReturn = any, TNext = undefined> {
  1490. next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
  1491. }
  1492. declare type TailConsumer = {
  1493. /** The name of the service tail events will be forwarded to. */
  1494. service: string;
  1495. /** (Optional) The environt of the service. */
  1496. environment?: string;
  1497. };
  1498. /**
  1499. * unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
  1500. */
  1501. export declare function unstable_dev(script: string, options?: UnstableDevOptions, apiOptions?: unknown): Promise<UnstableDevWorker>;
  1502. export declare const unstable_pages: {
  1503. deploy: typeof deploy;
  1504. };
  1505. export declare interface UnstableDevOptions {
  1506. config?: string;
  1507. env?: string;
  1508. ip?: string;
  1509. port?: number;
  1510. bundle?: boolean;
  1511. inspectorPort?: number;
  1512. localProtocol?: "http" | "https";
  1513. assets?: string;
  1514. site?: string;
  1515. siteInclude?: string[];
  1516. siteExclude?: string[];
  1517. nodeCompat?: boolean;
  1518. compatibilityDate?: string;
  1519. compatibilityFlags?: string[];
  1520. persist?: boolean;
  1521. persistTo?: string;
  1522. vars?: Record<string, string | Json>;
  1523. kv?: {
  1524. binding: string;
  1525. id: string;
  1526. preview_id?: string;
  1527. }[];
  1528. durableObjects?: {
  1529. name: string;
  1530. class_name: string;
  1531. script_name?: string | undefined;
  1532. environment?: string | undefined;
  1533. }[];
  1534. r2?: {
  1535. binding: string;
  1536. bucket_name: string;
  1537. preview_bucket_name?: string;
  1538. }[];
  1539. moduleRoot?: string;
  1540. rules?: Rule[];
  1541. logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
  1542. inspect?: boolean;
  1543. local?: boolean;
  1544. accountId?: string;
  1545. experimental?: {
  1546. processEntrypoint?: boolean;
  1547. additionalModules?: CfModule[];
  1548. d1Databases?: Environment["d1_databases"];
  1549. disableExperimentalWarning?: boolean;
  1550. disableDevRegistry?: boolean;
  1551. enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
  1552. forceLocal?: boolean;
  1553. liveReload?: boolean;
  1554. showInteractiveDevSession?: boolean;
  1555. testMode?: boolean;
  1556. testScheduled?: boolean;
  1557. watch?: boolean;
  1558. };
  1559. }
  1560. export declare interface UnstableDevWorker {
  1561. port: number;
  1562. address: string;
  1563. stop: () => Promise<void>;
  1564. fetch: (input?: RequestInfo_2, init?: RequestInit_2) => Promise<Response_2>;
  1565. waitUntilExit: () => Promise<void>;
  1566. }
  1567. /**
  1568. * uploads an mTLS certificate and private key pair to the account mTLS certificate store
  1569. */
  1570. export declare function uploadMTlsCertificate(accountId: string, body: MTlsCertificateBody): Promise<MTlsCertificateResponse>;
  1571. /**
  1572. * reads an mTLS certificate and private key pair from disk and uploads it to the account mTLS certificate store
  1573. */
  1574. export declare function uploadMTlsCertificateFromFs(accountId: string, details: MTlsCertificateUploadDetails): Promise<MTlsCertificateResponse>;
  1575. declare type ZoneIdRoute = {
  1576. pattern: string;
  1577. zone_id: string;
  1578. custom_domain?: boolean;
  1579. };
  1580. declare type ZoneNameRoute = {
  1581. pattern: string;
  1582. zone_name: string;
  1583. custom_domain?: boolean;
  1584. };
  1585. export { }