@cloudflare/deploy-helpers 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,139 +1,55 @@
1
- import { ContainerNormalizedConfig } from '@cloudflare/containers-shared';
2
- import { FetchResultFetcher, FetchListResultFetcher, Logger, Config, Entry, AssetsOptions, CfPlacement, EphemeralDirectory, LegacyAssetPaths, Route, ComplianceConfig, ZoneIdRoute, ZoneNameRoute, CustomDomainRoute } from '@cloudflare/workers-utils';
3
- import { NodeJSCompatMode } from 'miniflare';
4
-
5
- /**
6
- * client needs to handle logger and fetch/auth implementation
7
- * these are passed into this package to handle any API requests/logs
8
- */
9
- type DeployHelpersContext = {
10
- fetchResult: FetchResultFetcher;
11
- fetchListResult: FetchListResultFetcher;
12
- logger: Logger;
13
- confirm: (text: string, options?: {
14
- defaultValue?: boolean;
15
- fallbackValue?: boolean;
16
- }) => Promise<boolean>;
17
- prompt: (text: string, options?: {
18
- defaultValue?: string;
19
- }) => Promise<string>;
20
- isNonInteractiveOrCI: () => boolean;
21
- };
1
+ import { D as DeployProps, W as WorkerBuildResult, V as VersionsUploadProps, T as TriggerProps, a as TriggerDeployment, S as SharedDeployVersionsProps } from './context-CBAALoQ9.mjs';
2
+ export { b as DeployHelpersContext, i as initDeployHelpersContext } from './context-CBAALoQ9.mjs';
3
+ export { InputWorkerSchema, ModuleType, OutputWorkerSchema, ParsedInputWorkerConfig, ParsedOutputWorkerConfig, convertToWranglerConfig } from '@cloudflare/config';
4
+ import { ContainerNormalizedConfig, ImageURIConfig } from '@cloudflare/containers-shared';
5
+ import * as _cloudflare_workers_utils from '@cloudflare/workers-utils';
6
+ import { Config, ComplianceConfig, LegacyAssetPaths, Binding, Route, ZoneIdRoute, ZoneNameRoute, CustomDomainRoute, CfPlacement, RawConfig, ConfigBindingFieldName, CfCapnp, CfModuleType, CfWorkerInit, CfScriptFormat, CfModule, AssetsOptions, ParseError, WorkerMetadataBinding, CfUserLimits, TailConsumer, StreamingTailConsumer, Observability, StartDevWorkerInput, CfTailConsumer, ContainerApp } from '@cloudflare/workers-utils';
7
+ import { FormData } from 'undici';
8
+ import { Options } from '@cspotcode/source-map-support';
9
+ import Protocol from 'devtools-protocol';
10
+ import { NodeJSCompatMode, WorkerRegistry } from 'miniflare';
11
+
22
12
  /**
23
- * Shared fields produced by merging CLI args with wrangler config.
24
- * After this point, no raw config/arg merging should happen.
25
- *
26
- * Use props for all resolved/merged values. Only access config directly
27
- * for raw values that aren't merged with CLI args (e.g., config.durable_objects,
28
- * config.unsafe, config.tail_consumers).
13
+ * Wrangler-specific functions injected into `deploy()`. These remain in
14
+ * wrangler because they depend on wrangler-only systems (account selection,
15
+ * metrics, the dev-mode worker registry, container orchestration, etc.).
29
16
  */
30
- type SharedDeployVersionsProps = {
31
- config: Config;
32
- /** Merged from args.script/config.main/config.site.entry-point/config.assets. */
33
- entry: Entry;
34
- /** From config.rules. */
35
- rules: Config["rules"];
36
- /** Merged: --name arg ?? config.name, with CI override applied. */
37
- name: string;
38
- workerNameOverridden: boolean;
39
- /** Merged: --compatibility-date arg ?? config.compatibility_date. Still optional — validated as required in stage 4. */
40
- compatibilityDate: string | undefined;
41
- /** Merged: --compatibility-flags arg ?? config.compatibility_flags. */
42
- compatibilityFlags: string[];
43
- /** computed based on compat date and args */
44
- nodejsCompatMode: NodeJSCompatMode;
45
- /** Merged from --assets arg and config.assets. */
46
- assetsOptions: AssetsOptions | undefined;
47
- /** Merged: --jsx-factory arg || config.jsx_factory. */
48
- jsxFactory: string;
49
- /** Merged: --jsx-fragment arg || config.jsx_fragment. */
50
- jsxFragment: string;
51
- /** Merged: --tsconfig arg ?? config.tsconfig. */
52
- tsconfig: string | undefined;
53
- /** Merged: --minify arg ?? config.minify. */
54
- minify: boolean | undefined;
55
- /** Merged: !(--bundle arg ?? !config.no_bundle). */
56
- noBundle: boolean;
57
- /** Merged: --upload-source-maps arg ?? config.upload_source_maps. */
58
- uploadSourceMaps: boolean | undefined;
59
- /** Merged: --keep-vars arg || config.keep_vars. */
60
- keepVars: boolean;
61
- /** Merged from --site arg and config.site. */
62
- isWorkersSite: boolean;
63
- /** Merged: { ...config.define, ...--define arg }. CLI overrides config. */
64
- defines: Record<string, string>;
65
- /** Merged: { ...config.alias, ...--alias arg }. CLI overrides config. */
66
- alias: Record<string, string>;
67
- /**
68
- * Whether to use the deprecated service environments API path.
69
- * True only when config opts in (legacy_env: false) AND --env is specified.
70
- */
71
- useServiceEnvApiPath: boolean;
72
- placement: CfPlacement | undefined;
73
- /** Output directory for the bundled Worker. From --outdir arg or a temp directory. */
74
- destination: string | EphemeralDirectory;
75
- /** From --dry-run arg. */
76
- dryRun: boolean;
77
- /** From --env arg. */
78
- env: string | undefined;
79
- /** From --outdir arg. Already used to derive `destination`, but also needed for outdir README and noBundleWorker. */
80
- outdir: string | undefined;
81
- /** From --outfile arg. */
82
- outfile: string | undefined;
83
- /** From --tag arg. */
84
- tag: string | undefined;
85
- /** From --message arg. */
86
- message: string | undefined;
87
- /** From --secrets-file arg. */
88
- secretsFile: string | undefined;
89
- /** From collectKeyValues(--var arg). Pre-resolved key-value pairs. */
90
- var: Record<string, string>;
91
- /** From --experimental-auto-create arg. */
92
- experimentalAutoCreate: boolean;
93
- };
94
- type DeployProps = SharedDeployVersionsProps & {
95
- /** Discriminant for DeployProps vs VersionsUploadProps */
96
- command: "deploy";
97
- /** Merged from --site arg and config.site. */
98
- legacyAssetPaths: LegacyAssetPaths | undefined;
99
- /** Merged: --triggers arg ?? config.triggers.crons. */
100
- triggers: string[] | undefined;
101
- /** Merged: --routes arg ?? config.routes ?? config.route. AND --domains and custom_domains*/
102
- routes: Route[];
103
- /** Merged: --logpush arg ?? config.logpush. */
104
- logpush: boolean | undefined;
105
- containers: ContainerNormalizedConfig[];
106
- /** From --dispatch-namespace arg. Deploy-only (Workers for Platforms). */
107
- dispatchNamespace: string | undefined;
108
- /** From --strict arg. Deploy-only. */
109
- strict: boolean;
110
- /** From --metafile arg. Deploy-only. */
111
- metafile: string | boolean | undefined;
112
- /** From --old-asset-ttl arg. Deploy-only. */
113
- oldAssetTtl: number | undefined;
114
- };
115
- type VersionsUploadProps = SharedDeployVersionsProps & {
116
- /** Discriminant for DeployProps vs VersionsUploadProps */
117
- command: "versions upload";
118
- /** CLI-only (--preview-alias), or auto-generated from CI branch name. */
119
- previewAlias: string | undefined;
120
- };
121
- interface TriggerDeployment {
122
- targets: string[];
123
- error?: Error;
124
- }
125
- type TriggerProps = {
126
- config: Config;
127
- accountId: string;
128
- scriptName: string;
129
- env: string | undefined;
130
- crons: string[] | undefined;
131
- routes: Route[];
132
- useServiceEnvironments: boolean;
133
- firstDeploy: boolean;
17
+ type DeployCallbacks = {
18
+ syncWorkersSite: ((complianceConfig: ComplianceConfig, accountId: string | undefined, scriptName: string, siteAssets: LegacyAssetPaths | undefined, preview: boolean, dryRun: boolean | undefined, oldAssetTTL: number | undefined) => Promise<{
19
+ manifest: {
20
+ [filePath: string]: string;
21
+ } | undefined;
22
+ namespace: string | undefined;
23
+ }>) | undefined;
24
+ provisionBindings: ((bindings: Record<string, Binding>, accountId: string, scriptName: string, autoCreate: boolean, config: Config, requireRemote?: boolean) => Promise<void>) | undefined;
25
+ getNormalizedContainerOptions: ((config: Config, args: {
26
+ containersRollout?: "gradual" | "immediate" | "none";
27
+ dryRun?: boolean;
28
+ }) => Promise<ContainerNormalizedConfig[]>) | undefined;
29
+ buildContainer: ((containerConfig: Exclude<ContainerNormalizedConfig, ImageURIConfig>, imageTag: string, dryRun: boolean, pathToDocker: string) => Promise<unknown>) | undefined;
30
+ deployContainers: ((config: Config, normalisedContainerConfig: ContainerNormalizedConfig[], args: {
31
+ versionId: string;
32
+ accountId: string;
33
+ scriptName: string;
34
+ }) => Promise<void>) | undefined;
35
+ analyseBundle: ((workerBundle: string | FormData) => Promise<Record<string, unknown>>) | undefined;
134
36
  };
37
+ declare function deploy(props: DeployProps, config: Config, buildResult: WorkerBuildResult, callbacks: DeployCallbacks): Promise<{
38
+ sourceMapSize?: number;
39
+ versionId: string | null;
40
+ workerTag: string | null;
41
+ targets?: string[];
42
+ }>;
135
43
 
136
- declare function triggersDeploy(props: TriggerProps, ctx: DeployHelpersContext): Promise<string[] | void>;
44
+ type VersionsUploadCallbacks = Pick<DeployCallbacks, "provisionBindings" | "analyseBundle">;
45
+ declare function versionsUpload(props: VersionsUploadProps, config: Config, buildResult: WorkerBuildResult, callbacks: VersionsUploadCallbacks): Promise<{
46
+ versionId: string | null;
47
+ workerTag: string | null;
48
+ versionPreviewUrl?: string | undefined;
49
+ versionPreviewAliasUrl?: string | undefined;
50
+ }>;
51
+
52
+ declare function triggersDeploy(props: TriggerProps): Promise<string[] | void>;
137
53
  declare function getSubdomainValues(config_workers_dev: boolean | undefined, config_preview_urls: boolean | undefined, routes: Route[]): {
138
54
  workers_dev: boolean;
139
55
  preview_urls?: boolean;
@@ -152,7 +68,7 @@ type GetWorkersDevSubdomainOptions = {
152
68
  /**
153
69
  * Gets the <user-subdomain>.(fed.)workers.dev URL for the given account.
154
70
  */
155
- declare function getWorkersDevSubdomain(complianceConfig: ComplianceConfig, accountId: string, ctx: DeployHelpersContext, options?: GetWorkersDevSubdomainOptions): Promise<string>;
71
+ declare function getWorkersDevSubdomain(complianceConfig: ComplianceConfig, accountId: string, options?: GetWorkersDevSubdomainOptions): Promise<string>;
156
72
 
157
73
  interface Zone {
158
74
  id: string;
@@ -162,7 +78,7 @@ type ZoneIdCache = Map<string, Promise<string | null>>;
162
78
  declare function getZoneForRoute(complianceConfig: ComplianceConfig, from: {
163
79
  route: Route;
164
80
  accountId: string;
165
- }, ctx: DeployHelpersContext, zoneIdCache?: ZoneIdCache): Promise<Zone | undefined>;
81
+ }, zoneIdCache?: ZoneIdCache): Promise<Zone | undefined>;
166
82
  /**
167
83
  * Given something that resembles a host, try to infer a zone id from it.
168
84
  *
@@ -173,7 +89,7 @@ declare function getZoneForRoute(complianceConfig: ComplianceConfig, from: {
173
89
  declare function getZoneIdFromHost(complianceConfig: ComplianceConfig, from: {
174
90
  host: string;
175
91
  accountId: string;
176
- }, ctx: DeployHelpersContext, zoneIdCache?: ZoneIdCache): Promise<string>;
92
+ }, zoneIdCache?: ZoneIdCache): Promise<string>;
177
93
 
178
94
  type RouteObject = ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;
179
95
  type CustomDomain = {
@@ -208,8 +124,8 @@ declare function publishRoutes(complianceConfig: ComplianceConfig, routes: Route
208
124
  scriptName: string;
209
125
  useServiceEnvironments: boolean;
210
126
  accountId: string;
211
- }, ctx: DeployHelpersContext): Promise<string[]>;
212
- declare function publishCustomDomains(complianceConfig: ComplianceConfig, workerUrl: string, accountId: string, domains: Array<RouteObject>, ctx: DeployHelpersContext): Promise<TriggerDeployment>;
127
+ }): Promise<string[]>;
128
+ declare function publishCustomDomains(complianceConfig: ComplianceConfig, workerUrl: string, accountId: string, domains: Array<RouteObject>): Promise<TriggerDeployment>;
213
129
 
214
130
  interface PostQueueBody {
215
131
  queue_name: string;
@@ -281,14 +197,546 @@ interface PurgeQueueResponse {
281
197
  started_at: string;
282
198
  complete: boolean;
283
199
  }
284
- declare function listQueues(complianceConfig: ComplianceConfig, accountId: string, ctx: DeployHelpersContext, page?: number, name?: string): Promise<QueueResponse[]>;
285
- declare function getQueue(complianceConfig: ComplianceConfig, accountId: string, queueName: string, ctx: DeployHelpersContext): Promise<QueueResponse>;
286
- declare function postConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, body: PostTypedConsumerBody, ctx: DeployHelpersContext): Promise<TypedConsumerResponse>;
287
- declare function putConsumerById(complianceConfig: ComplianceConfig, accountId: string, queueId: string, consumerId: string, body: PostTypedConsumerBody, ctx: DeployHelpersContext): Promise<TypedConsumerResponse>;
288
- declare function putConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, scriptName: string, envName: string | undefined, body: PostTypedConsumerBody, ctx: DeployHelpersContext): Promise<TypedConsumerResponse>;
289
- declare function deletePullConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, ctx: DeployHelpersContext): Promise<void>;
290
- declare function listConsumers(complianceConfig: ComplianceConfig, accountId: string, queueName: string, ctx: DeployHelpersContext): Promise<Consumer[]>;
291
- declare function deleteWorkerConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, scriptName: string, envName: string | undefined, ctx: DeployHelpersContext): Promise<void>;
292
- declare function updateQueueConsumers(complianceConfig: ComplianceConfig, accountId: string, scriptName: string, config: Config, ctx: DeployHelpersContext): Promise<Promise<TriggerDeployment>[]>;
293
-
294
- export { type Consumer, type ConsumerSettings, type CustomDomain, type CustomDomainChangeset, type DeployHelpersContext, type DeployProps, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type Producer, type PurgeQueueBody, type PurgeQueueResponse, type QueueResponse, type QueueSettings, type RouteObject, type ScriptReference, type SharedDeployVersionsProps, type TriggerDeployment, type TriggerProps, type TypedConsumerResponse, type VersionsUploadProps, type Zone, type ZoneIdCache, deletePullConsumer, deleteWorkerConsumer, getQueue, getSubdomainValues, getSubdomainValuesAPIMock, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, listConsumers, listQueues, postConsumer, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderRoute, triggersDeploy, updateQueueConsumers };
200
+ declare function listQueues(complianceConfig: ComplianceConfig, accountId: string, page?: number, name?: string): Promise<QueueResponse[]>;
201
+ declare function getQueue(complianceConfig: ComplianceConfig, accountId: string, queueName: string): Promise<QueueResponse>;
202
+ declare function postConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, body: PostTypedConsumerBody): Promise<TypedConsumerResponse>;
203
+ declare function putConsumerById(complianceConfig: ComplianceConfig, accountId: string, queueId: string, consumerId: string, body: PostTypedConsumerBody): Promise<TypedConsumerResponse>;
204
+ declare function putConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, scriptName: string, envName: string | undefined, body: PostTypedConsumerBody): Promise<TypedConsumerResponse>;
205
+ declare function deletePullConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string): Promise<void>;
206
+ declare function listConsumers(complianceConfig: ComplianceConfig, accountId: string, queueName: string): Promise<Consumer[]>;
207
+ declare function deleteWorkerConsumer(complianceConfig: ComplianceConfig, accountId: string, queueName: string, scriptName: string, envName: string | undefined): Promise<void>;
208
+ declare function updateQueueConsumers(complianceConfig: ComplianceConfig, accountId: string, scriptName: string, config: Config): Promise<Promise<TriggerDeployment>[]>;
209
+ declare function ensureQueuesExistByConfig(config: Config, accountId: string): Promise<void>;
210
+
211
+ /**
212
+ * Parse placement out of a Config
213
+ */
214
+ declare function parseConfigPlacement(config: Config): CfPlacement | undefined;
215
+
216
+ /**
217
+ This is the error code from the Cloudflare API signaling that a worker could not be found on the target account
218
+ */
219
+ declare const WORKER_NOT_FOUND_ERR_CODE: 10007;
220
+ /**
221
+ This is the error code from the Cloudflare API signaling that a worker environment (legacy) could not be found on the target account
222
+ */
223
+ declare const WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE: 10090;
224
+ /**
225
+ This is the error message from the Cloudflare API signaling that a worker could not be found on the target account
226
+ */
227
+ declare const workerNotFoundErrorMessage = "This Worker does not exist on your account.";
228
+ /**
229
+ * Given an error from the Cloudflare API discerns whether it is caused by a worker that could not be found on the target account
230
+ *
231
+ * @param error The error object
232
+ * @returns true if the object represents an error from the Cloudflare API caused by a not found worker, false otherwise
233
+ */
234
+ declare function isWorkerNotFoundError(error: unknown): boolean;
235
+
236
+ /**
237
+ * Whether deprecated service environments are enabled.
238
+ */
239
+ declare function useServiceEnvironments(config: Config | {
240
+ legacy_env?: boolean;
241
+ legacy: {
242
+ useServiceEnvironments?: boolean;
243
+ };
244
+ }): boolean;
245
+
246
+ /**
247
+ * Cloudflare API error codes used by deploy-helpers.
248
+ */
249
+ /** The inherit binding references a binding that does not exist on the previous version. */
250
+ declare const INVALID_INHERIT_BINDING_CODE: 10057;
251
+
252
+ type SecretsValidationOptions = {
253
+ type: "deploy";
254
+ workerExists: boolean;
255
+ } | {
256
+ type: "upload";
257
+ };
258
+ /**
259
+ * When `secrets.required` is defined in config, validate the secrets exist on the Worker.
260
+ * For deploy, if the Worker doesn't exist yet, fail immediately.
261
+ * For upload, always add inherit bindings — the API handles the case where
262
+ * the Worker doesn't exist (versions upload cannot create new Workers).
263
+ * Secrets already provided (e.g. via --secrets-file) are excluded since
264
+ * they are part of the upload and don't need to be inherited.
265
+ */
266
+ declare function addRequiredSecretsInheritBindings(config: Config, bindings: Record<string, Binding>, options: SecretsValidationOptions): void;
267
+ /**
268
+ * Reformats API errors for strict inherit binding validation failures into
269
+ * user-friendly messages listing the missing required secrets.
270
+ * The API returns all missing inherit bindings at once, each as a separate
271
+ * error in response.errors, which maps to individual err.notes entries.
272
+ */
273
+ declare function handleMissingSecretsError(err: unknown, config: Config, options: SecretsValidationOptions): void;
274
+
275
+ type JsonLike = string | number | boolean | null | JsonLike[] | undefined | {
276
+ [id: string]: JsonLike;
277
+ };
278
+ /**
279
+ * Given two objects A and B that are Json serializable this function computes the difference between them
280
+ *
281
+ * The difference object includes:
282
+ * - fields in object B but not in object A included as `<fieldKey__added>`
283
+ * - fields in object A but not in object B included as `<fieldKey__deleted>`
284
+ * - fields present in both objects but modified as `<fieldKey>: { __old: <objectAValue>, __new: <objectBValue> }`
285
+ *
286
+ * Additionally the difference object contains a `toString` method that can be used to generate a string representation
287
+ * of the difference between the two objects (to be presented to users)
288
+ *
289
+ * @param jsonObjA The first target object
290
+ * @param jsonObjB The second target object
291
+ * @returns An object representing the diff between the two objects, or null if the objects are equal
292
+ */
293
+ declare function diffJsonObjects(jsonObjA: Record<string, JsonLike>, jsonObjB: Record<string, JsonLike>): Record<string, JsonLike> | null;
294
+ /**
295
+ * Given a diff object (generated by `diffJsonObjects`) this function computes whether the
296
+ * difference is non-destructive, i.e. if the second object only contained additions to the
297
+ * first one and no removal nor modifications.
298
+ *
299
+ * @param diff The difference object to use (generated by `diffJsonObjects`)
300
+ * @returns `true` if the difference is non-destructive, `false` if it is
301
+ */
302
+ declare function isNonDestructive(diff: JsonLike): boolean;
303
+ /**
304
+ * A modified value in json-diff is represented as an object with two properties:
305
+ * `__old` and `__new`. Where the former contains the old version of the value and
306
+ * the latter the new one.
307
+ * This utility, given an arbitrary value, discerns whether the value represents the
308
+ * diff of a modified value.
309
+ *
310
+ * @param value The target value to check
311
+ * @returns True if the value represents a value modified, false otherwise
312
+ */
313
+ declare function isModifiedDiffValue<T extends JsonLike>(value: unknown): value is {
314
+ __old: T;
315
+ __new: T;
316
+ };
317
+
318
+ /**
319
+ * Object representing the difference of two configuration objects.
320
+ */
321
+ type ConfigDiff = {
322
+ /** The actual (raw) computed diff of the two objects */
323
+ diff: Record<string, JsonLike> | null;
324
+ /**
325
+ * Flag indicating whether the difference includes some destructive changes.
326
+ *
327
+ * In other words, if the second config is not applying any change or only adding options, such diff is considered non destructive, on the other hand if the config is removing or modifying values it is considered destructive instead.
328
+ */
329
+ nonDestructive: boolean;
330
+ };
331
+ /**
332
+ * Computes the difference between a remote representation of a Worker's config and a local configuration.
333
+ *
334
+ * @param remoteConfig The remote representation of a Worker's config
335
+ * @param localResolvedConfig The local (resolved) config
336
+ * @returns Object containing the diffing information
337
+ */
338
+ declare function getRemoteConfigDiff(remoteConfig: RawConfig, localResolvedConfig: Config): ConfigDiff;
339
+ /**
340
+ * Given a config diff generates a patch object that can be passed to `experimental_patchConfig` to revert the
341
+ * changes in the config object that are described by the config diff.
342
+ *
343
+ * If the config is for a specific target environment, only the environment config object will be targeted for the patch.
344
+ *
345
+ * @param configDiff The target config diff
346
+ * @param targetEnvironment the target environment if any
347
+ * @returns The patch object to pass to `experimental_patchConfig` to revert the changes
348
+ */
349
+ declare function getConfigPatch(configDiff: {
350
+ diff: Record<string, JsonLike> | null;
351
+ nonDestructive: boolean;
352
+ }["diff"], targetEnvironment?: string | undefined): RawConfig;
353
+
354
+ declare function validateFileSecrets(content: unknown, jsonFilePath: string): content is Record<string, string | null>;
355
+ /** Error thrown when no input is provided to parseBulkInputToObject */
356
+ declare class NoInputError extends Error {
357
+ constructor();
358
+ }
359
+ /** Result from parsing bulk secret input without nullable values, including metadata for analytics */
360
+ type BulkInputResult = {
361
+ content: Record<string, string>;
362
+ secretSource: "file" | "stdin";
363
+ secretFormat: "json" | "dotenv";
364
+ };
365
+ /** Result from parsing bulk secret input with nullable values, including metadata for analytics */
366
+ type BulkInputNullableResult = {
367
+ content: Record<string, string | null>;
368
+ secretSource: "file" | "stdin";
369
+ secretFormat: "json" | "dotenv";
370
+ };
371
+ /** Override for callers that need non-nullable */
372
+ declare function parseBulkInputToObject(input?: string, includeNull?: false): Promise<BulkInputResult | undefined>;
373
+ /** Override for callers that need nullable */
374
+ declare function parseBulkInputToObject(input?: string, includeNull?: true): Promise<BulkInputNullableResult | undefined>;
375
+
376
+ interface ConvertBindingsOptions {
377
+ /**
378
+ * Use preview IDs (preview_id, preview_bucket_name, preview_database_id) instead of production IDs when resolving a binding ID.
379
+ * This means that the rest of Wrangler does not need to be aware of preview IDs, and can just use regular IDs.
380
+ */
381
+ usePreviewIds?: boolean;
382
+ /**
383
+ * Exclude bindings that Pages doesn't support
384
+ */
385
+ pages?: boolean;
386
+ }
387
+ /**
388
+ * Convert Config to the Record<string, Binding> format for consistent internal use.
389
+ */
390
+ declare function convertConfigToBindings(config: Partial<Pick<Config, ConfigBindingFieldName>>, options?: ConvertBindingsOptions): Record<string, Binding>;
391
+ declare function isUnsafeBindingType(type: string): type is `unsafe_${string}`;
392
+ /**
393
+ * What configuration key does this binding use for referring to it's binding name?
394
+ */
395
+ declare const nameBindings: readonly ["durable_object_namespace", "logfwdr", "ratelimit", "unsafe_ratelimit", "send_email"];
396
+ type FlatBinding<Type> = Extract<Binding, {
397
+ type: Type;
398
+ }> & (Type extends (typeof nameBindings)[number] ? {
399
+ name: string;
400
+ } : {
401
+ binding: string;
402
+ });
403
+ declare function extractBindingsOfType<Type extends Binding["type"]>(type: Type, bindings: Record<string, Binding> | undefined): FlatBinding<Type>[];
404
+ /**
405
+ * Get bindings from a Config object in the standard Record<string, Binding> format.
406
+ */
407
+ declare function getBindings(config: Config | undefined, options?: {
408
+ pages?: boolean;
409
+ }): Record<string, Binding>;
410
+
411
+ declare function handleUnsafeCapnp(capnp: CfCapnp): Buffer;
412
+
413
+ declare const moduleTypeMimeType: {
414
+ [type in CfModuleType]: string | undefined;
415
+ };
416
+ declare function fromMimeType(mimeType: string): CfModuleType;
417
+ /**
418
+ * Creates a `FormData` upload from Worker data and bindings
419
+ */
420
+ declare function createWorkerUploadForm(worker: Omit<CfWorkerInit, "bindings" | "rawBindings">, bindings: Record<string, Binding> | undefined, options?: {
421
+ dryRun?: true;
422
+ unsafe?: {
423
+ metadata?: Record<string, unknown>;
424
+ capnp?: CfCapnp;
425
+ };
426
+ }): FormData;
427
+
428
+ /**
429
+ * Inject bindings into the Worker to support Workers Sites. These are injected at the last minute so that
430
+ * they don't display in the output of `printBindings()`
431
+ */
432
+ declare function addWorkersSitesBindings(bindings: Record<string, Binding>, namespace: string | undefined, manifest: {
433
+ [filePath: string]: string;
434
+ } | undefined, format: CfScriptFormat): {
435
+ [x: string]: Binding;
436
+ };
437
+
438
+ declare function deployWfpUserWorker(dispatchNamespace: string, versionId: string | null): void;
439
+
440
+ declare function getDeployConfirmFunction(options: {
441
+ strictMode?: boolean;
442
+ }): (text: string) => Promise<boolean>;
443
+
444
+ /**
445
+ * Sanitizes a branch name to create a valid DNS label alias.
446
+ * Converts to lowercase, replaces invalid chars with dashes, removes consecutive dashes.
447
+ */
448
+ declare function sanitizeBranchName(branchName: string): string;
449
+ /**
450
+ * Gets the current branch name from CI environment or git.
451
+ */
452
+ declare function getBranchName(): string | undefined;
453
+ /**
454
+ * Creates a truncated alias with hash suffix when the branch name is too long.
455
+ * Hash from original branch name to preserve uniqueness.
456
+ */
457
+ declare function createTruncatedAlias(branchName: string, sanitizedAlias: string, availableSpace: number): string | undefined;
458
+ /**
459
+ * Generates a preview alias based on the current git branch.
460
+ * Alias must be <= 63 characters, alphanumeric + dashes only, and start with a letter.
461
+ * Returns undefined if not in a git directory or requirements cannot be met.
462
+ */
463
+ declare function generatePreviewAlias(scriptName: string): string | undefined;
464
+
465
+ type RetrieveSourceMapFunction = NonNullable<Options["retrieveSourceMap"]>;
466
+ declare function maybeRetrieveFileSourceMap(filePath?: string): ReturnType<RetrieveSourceMapFunction>;
467
+ declare function getSourceMappedStack(details: Protocol.Runtime.ExceptionDetails): string;
468
+ declare function getSourceMappedString(value: string, retrieveSourceMap?: RetrieveSourceMapFunction): string;
469
+
470
+ declare function printBundleSize(main: {
471
+ name: string;
472
+ content: string;
473
+ }, modules: CfModule[]): Promise<void>;
474
+
475
+ /**
476
+ * Computes and validates the Node.js compatibility mode we are running.
477
+ *
478
+ * NOTES:
479
+ * - The v2 mode is configured via `nodejs_compat_v2` compat flag or via `nodejs_compat` plus a compatibility date of Sept 23rd. 2024 or later.
480
+ * - See `EnvironmentInheritable` for `noBundle`.
481
+ *
482
+ * @param compatibilityDateStr The compatibility date
483
+ * @param compatibilityFlags The compatibility flags
484
+ * @param noBundle Whether to skip internal build steps and directly deploy script
485
+ *
486
+ */ declare function validateNodeCompatMode(compatibilityDateStr: string | undefined, // Default to some arbitrary old date
487
+ compatibilityFlags: string[], { noBundle, }: {
488
+ noBundle?: boolean;
489
+ }): NodeJSCompatMode;
490
+
491
+ declare const validateRoutes: (routes: Route[], assets: AssetsOptions | undefined) => void;
492
+
493
+ declare function hasDefinedEnvironments(config: Config): boolean;
494
+ declare function applyServiceAndEnvironmentTags(config: Config, tags: string[]): string[];
495
+ declare function warnOnErrorUpdatingServiceAndEnvironmentTags(): void;
496
+ declare function tagsAreEqual(a: string[], b: string[]): boolean;
497
+
498
+ declare function helpIfErrorIsSizeOrScriptStartup(err: unknown, dependencies: {
499
+ [path: string]: {
500
+ bytesInOutput: number;
501
+ };
502
+ }, workerBundle: FormData | string, projectRoot: string | undefined, analyseBundle?: (bundle: FormData | string) => Promise<unknown>): Promise<string | null>;
503
+ /**
504
+ * Returns a formatted error message that describes the script size error.
505
+ * It includes the largest dependencies if available.
506
+ */
507
+ declare function diagnoseScriptSizeError(err: ParseError, dependencies: {
508
+ [path: string]: {
509
+ bytesInOutput: number;
510
+ };
511
+ }): string;
512
+ /**
513
+ * Returns a formatted error message that describes the startup error.
514
+ * If profiling is successful, it will include a link to the generated CPU profile.
515
+ */
516
+ declare function diagnoseStartupError(err: ParseError, workerBundle: FormData | string, projectRoot: string | undefined, analyseBundle?: (bundle: FormData | string) => Promise<unknown>): Promise<string>;
517
+
518
+ type Percentage = number;
519
+ type UUID = string;
520
+ type VersionId = UUID;
521
+ type ApiDeployment = {
522
+ id: string;
523
+ source: "api" | string;
524
+ strategy: "percentage" | string;
525
+ author_email: string;
526
+ annotations?: Record<string, string>;
527
+ created_on: string;
528
+ versions: Array<{
529
+ version_id: VersionId;
530
+ percentage: Percentage;
531
+ }>;
532
+ };
533
+ type ApiVersion = {
534
+ id: VersionId;
535
+ number: number;
536
+ metadata: {
537
+ created_on: string;
538
+ modified_on: string;
539
+ source: "api" | string;
540
+ author_id: string;
541
+ author_email: string;
542
+ };
543
+ annotations?: {
544
+ "workers/triggered_by"?: "upload" | string;
545
+ "workers/message"?: string;
546
+ "workers/tag"?: string;
547
+ };
548
+ resources: {
549
+ bindings: WorkerMetadataBinding[];
550
+ script: {
551
+ etag: string;
552
+ handlers: string[] | null;
553
+ placement_mode?: "smart";
554
+ last_deployed_from: string;
555
+ };
556
+ script_runtime: {
557
+ compatibility_date?: string;
558
+ compatibility_flags?: string[];
559
+ usage_model: "bundled" | "unbound" | "standard";
560
+ limits: CfUserLimits;
561
+ };
562
+ };
563
+ startup_time_ms?: number;
564
+ };
565
+ type VersionCache = Map<VersionId, ApiVersion>;
566
+
567
+ declare function fetchVersion(complianceConfig: ComplianceConfig, accountId: string, workerName: string, versionId: VersionId, versionCache: VersionCache | undefined): Promise<ApiVersion>;
568
+ declare function fetchVersions(complianceConfig: ComplianceConfig, accountId: string, workerName: string, versionCache: VersionCache | undefined, versionIds: VersionId[]): Promise<ApiVersion[]>;
569
+ declare function fetchLatestDeployments(complianceConfig: ComplianceConfig, accountId: string, workerName: string): Promise<ApiDeployment[]>;
570
+ declare function fetchLatestDeployment(complianceConfig: ComplianceConfig, accountId: string, workerName: string): Promise<ApiDeployment | undefined>;
571
+ declare function fetchDeploymentVersions(complianceConfig: ComplianceConfig, accountId: string, workerName: string, deployment: ApiDeployment | undefined, versionCache: VersionCache): Promise<[ApiVersion[], Map<VersionId, Percentage>]>;
572
+ declare function fetchDeployableVersions(complianceConfig: ComplianceConfig, accountId: string, workerName: string, versionCache: VersionCache): Promise<ApiVersion[]>;
573
+ declare function createDeployment(complianceConfig: ComplianceConfig, accountId: string, workerName: string, versionTraffic: Map<VersionId, Percentage>, message: string | undefined, force: boolean | undefined): Promise<{
574
+ id: string;
575
+ }>;
576
+ type NonVersionedScriptSettings = {
577
+ logpush: boolean;
578
+ tags: string[] | null;
579
+ tail_consumers: TailConsumer[];
580
+ streaming_tail_consumers: StreamingTailConsumer[];
581
+ observability: Observability;
582
+ };
583
+ declare function patchNonVersionedScriptSettings(complianceConfig: ComplianceConfig, accountId: string, workerName: string, settings: Partial<NonVersionedScriptSettings>): Promise<Partial<NonVersionedScriptSettings>>;
584
+
585
+ type Workflow = {
586
+ name: string;
587
+ id: string;
588
+ created_on: string;
589
+ modified_on: string;
590
+ script_name: string;
591
+ class_name: string;
592
+ };
593
+ interface WorkflowConflict {
594
+ name: string;
595
+ currentOwner: string;
596
+ }
597
+ declare const WORKFLOW_NOT_FOUND_CODE = 10200;
598
+ declare function checkWorkflowConflicts(config: Config, accountId: string, scriptName: string): Promise<{
599
+ hasConflicts: false;
600
+ } | {
601
+ hasConflicts: true;
602
+ conflicts: WorkflowConflict[];
603
+ message: string;
604
+ }>;
605
+
606
+ type CustomDomainsRes = {
607
+ id: string;
608
+ zone_id: string;
609
+ zone_name: string;
610
+ hostname: string;
611
+ service: string;
612
+ environment: string;
613
+ cert_id: string;
614
+ enabled: boolean;
615
+ previews_enabled: boolean;
616
+ }[];
617
+ type WorkerSubdomainRes = {
618
+ enabled: boolean;
619
+ previews_enabled: boolean;
620
+ };
621
+ type CronTriggersRes = {
622
+ schedules: {
623
+ cron: string;
624
+ created_on: Date;
625
+ modified_on: Date;
626
+ }[];
627
+ };
628
+ type RoutesRes = {
629
+ id: string;
630
+ pattern: string;
631
+ zone_name: string;
632
+ script: string;
633
+ }[];
634
+ /**
635
+ * Downloads all information required to construct a Wrangler config file for a Worker from the API
636
+ */
637
+ declare function fetchWorkerConfig(accountId: string, workerName: string, environment: string): Promise<{
638
+ bindings: _cloudflare_workers_utils.WorkerMetadataBinding[];
639
+ routes: RoutesRes;
640
+ customDomains: CustomDomainsRes;
641
+ subdomainStatus: WorkerSubdomainRes;
642
+ serviceEnvMetadata: {
643
+ environment: string;
644
+ created_on: string;
645
+ modified_on: string;
646
+ script: {
647
+ id: string;
648
+ tag: string;
649
+ tags: string[];
650
+ etag: string;
651
+ handlers: string[];
652
+ modified_on: string;
653
+ created_on: string;
654
+ migration_tag: string;
655
+ usage_model: "bundled" | "unbound";
656
+ limits: {
657
+ cpu_ms: number;
658
+ subrequests: number;
659
+ };
660
+ compatibility_date: string;
661
+ compatibility_flags: string[];
662
+ last_deployed_from?: "wrangler" | "dash" | "api";
663
+ placement_mode?: "smart";
664
+ tail_consumers?: _cloudflare_workers_utils.TailConsumer[];
665
+ observability?: _cloudflare_workers_utils.Observability;
666
+ };
667
+ };
668
+ cronTriggers: CronTriggersRes;
669
+ }>;
670
+ /**
671
+ * Downloads all the remote information we can gather for a worker and from them generates a raw configuration object that
672
+ * approximates what a wrangler config object for the worker was/would have been.
673
+ */
674
+ declare function downloadWorkerConfig(workerName: string, environment: string, entrypoint: string, accountId: string): Promise<RawConfig>;
675
+
676
+ /**
677
+ * For a given Worker + migrations config, figure out which migrations
678
+ * to upload based on the current migration tag of the deployed Worker.
679
+ */
680
+ declare function getMigrationsToUpload(scriptName: string, props: {
681
+ accountId: string | undefined;
682
+ config: Config;
683
+ useServiceEnvironments: boolean | undefined;
684
+ env: string | undefined;
685
+ dispatchNamespace: string | undefined;
686
+ }): Promise<CfWorkerInit["migrations"]>;
687
+
688
+ declare function verifyWorkerMatchesCITag(complianceConfig: ComplianceConfig, accountId: string, workerName: string, configPath: string | undefined): Promise<void>;
689
+
690
+ declare function fetchSecrets(config: Config, accountId: string, environment: string | undefined): Promise<{
691
+ name: string;
692
+ type: string;
693
+ }[]>;
694
+ declare function checkRemoteSecretsOverride(config: Config, accountId: string, targetEnv: string | undefined): Promise<{
695
+ override: false;
696
+ } | {
697
+ override: true;
698
+ deployErrorMessage: string;
699
+ }>;
700
+
701
+ declare function confirmLatestDeploymentOverwrite(config: Config, accountId: string, scriptName: string): Promise<boolean>;
702
+ declare function printVersions(versions: ApiVersion[], traffic: Map<VersionId, Percentage>): void;
703
+
704
+ type PrintContext = {
705
+ log?: (message: string) => void;
706
+ registry?: WorkerRegistry | null;
707
+ local?: boolean;
708
+ isMultiWorker?: boolean;
709
+ remoteBindingsDisabled?: boolean;
710
+ name?: string;
711
+ provisioning?: boolean;
712
+ warnIfNoBindings?: boolean;
713
+ unsafeMetadata?: Record<string, unknown>;
714
+ };
715
+ /**
716
+ * Print all the bindings a worker would have access to.
717
+ * Accepts StartDevWorkerInput["bindings"] format
718
+ */
719
+ declare function printBindings(bindings: StartDevWorkerInput["bindings"], tailConsumers?: CfTailConsumer[], streamingTailConsumers?: CfTailConsumer[], containers?: ContainerApp[], context?: PrintContext): void;
720
+ /**
721
+ * Validates the user's `remote` setting for a given binding against the
722
+ * binding type's local-development capabilities (sourced from
723
+ * {@link getBindingLocalSupport}). Throws `UserError` for invalid combinations
724
+ * and emits warnings for valid-but-noteworthy ones.
725
+ */
726
+ declare function warnOrError(type: Binding["type"], remote: boolean | undefined): void;
727
+
728
+ type AssetManifest = {
729
+ [path: string]: {
730
+ hash: string;
731
+ size: number;
732
+ };
733
+ };
734
+ declare const syncAssets: (complianceConfig: ComplianceConfig, accountId: string | undefined, assetDirectory: string, scriptName: string, dispatchNamespace?: string) => Promise<string>;
735
+ declare const buildAssetManifest: (dir: string) => Promise<AssetManifest>;
736
+ declare function resolveAssetOptions({ assetsDir, main }: Pick<SharedDeployVersionsProps, "assetsDir" | "main">, config: Config): AssetsOptions | undefined;
737
+
738
+ declare const hashFile: (filepath: string) => string;
739
+
740
+ declare const isJwtExpired: (token: string) => boolean | undefined;
741
+
742
+ export { type ApiDeployment, type ApiVersion, type AssetManifest, type BulkInputNullableResult, type BulkInputResult, type Consumer, type ConsumerSettings, type CustomDomain, type CustomDomainChangeset, type DeployCallbacks, DeployProps, INVALID_INHERIT_BINDING_CODE, type JsonLike, NoInputError, type NonVersionedScriptSettings, type Percentage, type PostQueueBody, type PostQueueResponse, type PostTypedConsumerBody, type Producer, type PurgeQueueBody, type PurgeQueueResponse, type QueueResponse, type QueueSettings, type RetrieveSourceMapFunction, type RouteObject, type ScriptReference, SharedDeployVersionsProps, TriggerDeployment, TriggerProps, type TypedConsumerResponse, type VersionCache, type VersionId, type VersionsUploadCallbacks, VersionsUploadProps, WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE, WORKER_NOT_FOUND_ERR_CODE, WORKFLOW_NOT_FOUND_CODE, WorkerBuildResult, type Workflow, type WorkflowConflict, type Zone, type ZoneIdCache, addRequiredSecretsInheritBindings, addWorkersSitesBindings, applyServiceAndEnvironmentTags, buildAssetManifest, checkRemoteSecretsOverride, checkWorkflowConflicts, confirmLatestDeploymentOverwrite, convertConfigToBindings, createDeployment, createTruncatedAlias, createWorkerUploadForm, deletePullConsumer, deleteWorkerConsumer, deploy, deployWfpUserWorker, diagnoseScriptSizeError, diagnoseStartupError, diffJsonObjects, downloadWorkerConfig, ensureQueuesExistByConfig, extractBindingsOfType, fetchDeployableVersions, fetchDeploymentVersions, fetchLatestDeployment, fetchLatestDeployments, fetchSecrets, fetchVersion, fetchVersions, fetchWorkerConfig, fromMimeType, generatePreviewAlias, getBindings, getBranchName, getConfigPatch, getDeployConfirmFunction, getMigrationsToUpload, getQueue, getRemoteConfigDiff, getSourceMappedStack, getSourceMappedString, getSubdomainValues, getSubdomainValuesAPIMock, getWorkersDevSubdomain, getZoneForRoute, getZoneIdFromHost, handleMissingSecretsError, handleUnsafeCapnp, hasDefinedEnvironments, hashFile, helpIfErrorIsSizeOrScriptStartup, isJwtExpired, isModifiedDiffValue, isNonDestructive, isUnsafeBindingType, isWorkerNotFoundError, listConsumers, listQueues, maybeRetrieveFileSourceMap, moduleTypeMimeType, parseBulkInputToObject, parseConfigPlacement, patchNonVersionedScriptSettings, postConsumer, printBindings, printBundleSize, printVersions, publishCustomDomains, publishRoutes, putConsumer, putConsumerById, renderRoute, resolveAssetOptions, sanitizeBranchName, syncAssets, tagsAreEqual, triggersDeploy, updateQueueConsumers, useServiceEnvironments, validateFileSecrets, validateNodeCompatMode, validateRoutes, verifyWorkerMatchesCITag, versionsUpload, warnOnErrorUpdatingServiceAndEnvironmentTags, warnOrError, workerNotFoundErrorMessage };