@cloudflare/workers-utils 0.18.0 → 0.19.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.
@@ -1,4 +1,4 @@
1
- import { T as TailConsumer, au as WorkerMetadata, R as RawConfig } from './config-_M2XwEUI.mjs';
1
+ import { T as TailConsumer, au as WorkerMetadata, R as RawConfig } from './config-CnJQHRQs.mjs';
2
2
  import { AssetConfig } from '@cloudflare/workers-shared';
3
3
  import { Cloudflare } from 'cloudflare';
4
4
 
@@ -12,7 +12,7 @@ var UserError = class extends Error {
12
12
  constructor(message, options) {
13
13
  super(message, options);
14
14
  Object.setPrototypeOf(this, new.target.prototype);
15
- this.telemetryMessage = options?.telemetryMessage === true ? message : options?.telemetryMessage;
15
+ this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
16
16
  }
17
17
  };
18
18
  var DeprecationError = class extends UserError {
@@ -25,13 +25,14 @@ ${message}`, options);
25
25
  }
26
26
  };
27
27
  var FatalError = class extends UserError {
28
- constructor(message, code, options) {
29
- super(message, options);
30
- this.code = code;
31
- }
32
28
  static {
33
29
  __name(this, "FatalError");
34
30
  }
31
+ code;
32
+ constructor(message, options) {
33
+ super(message, options);
34
+ this.code = options.code;
35
+ }
35
36
  };
36
37
  var CommandLineArgsError = class extends UserError {
37
38
  static {
@@ -39,10 +40,6 @@ var CommandLineArgsError = class extends UserError {
39
40
  }
40
41
  };
41
42
  var JsonFriendlyFatalError = class extends FatalError {
42
- constructor(message, code, options) {
43
- super(message, code, options);
44
- this.code = code;
45
- }
46
43
  static {
47
44
  __name(this, "JsonFriendlyFatalError");
48
45
  }
@@ -57,16 +54,11 @@ var MissingConfigError = class extends Error {
57
54
  this.telemetryMessage = `Missing config value for ${key}`;
58
55
  }
59
56
  };
60
- function createFatalError(message, isJson, code, telemetryMessage) {
57
+ function createFatalError(message, isJson, options) {
61
58
  if (isJson) {
62
- return new JsonFriendlyFatalError(
63
- JSON.stringify(message),
64
- code,
65
- telemetryMessage
66
- );
67
- } else {
68
- return new FatalError(`${message}`, code, telemetryMessage);
59
+ return new JsonFriendlyFatalError(JSON.stringify(message), options);
69
60
  }
61
+ return new FatalError(`${message}`, options);
70
62
  }
71
63
  __name(createFatalError, "createFatalError");
72
64
 
@@ -2456,7 +2448,8 @@ function readFileSyncToBuffer(file2) {
2456
2448
  {
2457
2449
  text: message.replace(file2, resolve(file2))
2458
2450
  }
2459
- ]
2451
+ ],
2452
+ telemetryMessage: false
2460
2453
  });
2461
2454
  }
2462
2455
  }
@@ -2784,32 +2777,41 @@ function findRedirectedWranglerConfig(cwd, userConfigPath) {
2784
2777
  } catch (e) {
2785
2778
  throw new UserError(
2786
2779
  `Failed to parse the deploy configuration file at ${path.relative(".", deployConfigPath)}`,
2787
- { cause: e }
2780
+ { cause: e, telemetryMessage: false }
2788
2781
  );
2789
2782
  }
2790
2783
  if (!redirectedConfigPath) {
2791
- throw new UserError(esm_default`
2784
+ throw new UserError(
2785
+ esm_default`
2792
2786
  A deploy configuration file was found at "${path.relative(".", deployConfigPath)}".
2793
2787
  But this is not valid - the required "configPath" property was not found.
2794
2788
  Instead this file contains:
2795
2789
  \`\`\`
2796
2790
  ${deployConfigFile}
2797
2791
  \`\`\`
2798
- `);
2792
+ `,
2793
+ { telemetryMessage: false }
2794
+ );
2799
2795
  }
2800
2796
  if (!existsSync(redirectedConfigPath)) {
2801
- throw new UserError(esm_default`
2797
+ throw new UserError(
2798
+ esm_default`
2802
2799
  There is a deploy configuration at "${path.relative(".", deployConfigPath)}".
2803
2800
  But the redirected configuration path it points to, "${path.relative(".", redirectedConfigPath)}", does not exist.
2804
- `);
2801
+ `,
2802
+ { telemetryMessage: false }
2803
+ );
2805
2804
  }
2806
2805
  if (userConfigPath) {
2807
2806
  if (path.join(path.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) {
2808
- throw new UserError(esm_default`
2807
+ throw new UserError(
2808
+ esm_default`
2809
2809
  Found both a user configuration file at "${path.relative(".", userConfigPath)}"
2810
2810
  and a deploy configuration file at "${path.relative(".", deployConfigPath)}".
2811
2811
  But these do not share the same base path so it is not clear which should be used.
2812
- `);
2812
+ `,
2813
+ { telemetryMessage: false }
2814
+ );
2813
2815
  }
2814
2816
  }
2815
2817
  return {
@@ -1530,11 +1530,13 @@ interface EnvironmentNonInheritable {
1530
1530
  */
1531
1531
  vars: Record<string, string | Json>;
1532
1532
  /**
1533
- * Secrets configuration (experimental).
1533
+ * Secrets configuration.
1534
1534
  *
1535
1535
  * NOTE: This field is not automatically inherited from the top level environment,
1536
1536
  * and so must be specified in every named environment.
1537
1537
  *
1538
+ * For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#secrets-configuration-property
1539
+ *
1538
1540
  * @nonInheritable
1539
1541
  */
1540
1542
  secrets?: {
@@ -2123,7 +2125,7 @@ interface EnvironmentNonInheritable {
2123
2125
  binding: string;
2124
2126
  /** The Flagship app ID to bind to. */
2125
2127
  app_id: string;
2126
- /** Whether to use the remote Flagship service for flag evaluation in local dev. */
2128
+ /** Set to `true` to suppress the remote binding warning in local dev. Flagship bindings are always remote. */
2127
2129
  remote?: boolean;
2128
2130
  }[];
2129
2131
  /**
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { B as Binding, R as RawConfig, C as Config, W as WorkerMetadataBinding } from './config-_M2XwEUI.mjs';
2
- export { at as AssetConfigMetadata, A as Assets, ay as BinaryFile, q as CacheOptions, H as CfAIBinding, a0 as CfAISearch, $ as CfAISearchNamespace, ab as CfAnalyticsEngineDataset, a2 as CfArtifacts, ag as CfAssetsBinding, G as CfBrowserBinding, aj as CfCapnp, Y as CfD1Database, M as CfDataBlobBindings, ac as CfDispatchNamespace, N as CfDurableObject, al as CfDurableObjectMigrations, a4 as CfFlagship, a3 as CfHelloWorld, a7 as CfHyperdrive, I as CfImagesBinding, x as CfKvNamespace, ae as CfLogfwdr, af as CfLogfwdrBinding, ad as CfMTlsCertificate, J as CfMediaBinding, v as CfModule, u as CfModuleType, ah as CfPipeline, am as CfPlacement, V as CfQueue, X as CfR2Bucket, a6 as CfRateLimit, t as CfScriptFormat, a1 as CfSecretsStoreSecrets, y as CfSendEmailBindings, a8 as CfService, K as CfStreamBinding, an as CfTailConsumer, F as CfTextBlobBindings, ak as CfUnsafe, ai as CfUnsafeBinding, ao as CfUserLimits, w as CfVars, _ as CfVectorize, L as CfVersionMetadataBinding, aa as CfVpcNetwork, a9 as CfVpcService, z as CfWasmModuleBindings, aq as CfWorkerContext, ap as CfWorkerInit, a5 as CfWorkerLoader, ar as CfWorkerSourceMap, Q as CfWorkflow, i as CloudchamberConfig, c as ConfigFields, o as ConfigModuleRuleType, j as ContainerApp, s as ContainerEngine, g as CustomDomainRoute, p as DispatchNamespaceOutbound, r as DockerConfiguration, k as DurableObjectBindings, D as DurableObjectMigration, aC as ENVIRONMENT_TAG_PREFIX, E as Environment, m as EnvironmentNonInheritable, ax as File, aA as INHERIT_SYMBOL, aE as JSON_CONFIG_FORMATS, as as Json, O as Observability, aD as PATH_TO_DEPLOY_CONFIG, P as PreviewsConfig, b as RawDevConfig, d as RawEnvironment, a as RedirectedRawConfig, h as Route, n as Rule, aB as SERVICE_TAG_PREFIX, aw as ServiceFetch, av as ServiceMetadataRes, S as StreamingTailConsumer, T as TailConsumer, az as Trigger, U as UserLimits, au as WorkerMetadata, l as WorkflowBinding, Z as ZoneIdRoute, f as ZoneNameRoute, e as defaultWranglerConfig } from './config-_M2XwEUI.mjs';
1
+ import { B as Binding, R as RawConfig, C as Config, W as WorkerMetadataBinding } from './config-CnJQHRQs.mjs';
2
+ export { at as AssetConfigMetadata, A as Assets, ay as BinaryFile, q as CacheOptions, H as CfAIBinding, a0 as CfAISearch, $ as CfAISearchNamespace, ab as CfAnalyticsEngineDataset, a2 as CfArtifacts, ag as CfAssetsBinding, G as CfBrowserBinding, aj as CfCapnp, Y as CfD1Database, M as CfDataBlobBindings, ac as CfDispatchNamespace, N as CfDurableObject, al as CfDurableObjectMigrations, a4 as CfFlagship, a3 as CfHelloWorld, a7 as CfHyperdrive, I as CfImagesBinding, x as CfKvNamespace, ae as CfLogfwdr, af as CfLogfwdrBinding, ad as CfMTlsCertificate, J as CfMediaBinding, v as CfModule, u as CfModuleType, ah as CfPipeline, am as CfPlacement, V as CfQueue, X as CfR2Bucket, a6 as CfRateLimit, t as CfScriptFormat, a1 as CfSecretsStoreSecrets, y as CfSendEmailBindings, a8 as CfService, K as CfStreamBinding, an as CfTailConsumer, F as CfTextBlobBindings, ak as CfUnsafe, ai as CfUnsafeBinding, ao as CfUserLimits, w as CfVars, _ as CfVectorize, L as CfVersionMetadataBinding, aa as CfVpcNetwork, a9 as CfVpcService, z as CfWasmModuleBindings, aq as CfWorkerContext, ap as CfWorkerInit, a5 as CfWorkerLoader, ar as CfWorkerSourceMap, Q as CfWorkflow, i as CloudchamberConfig, c as ConfigFields, o as ConfigModuleRuleType, j as ContainerApp, s as ContainerEngine, g as CustomDomainRoute, p as DispatchNamespaceOutbound, r as DockerConfiguration, k as DurableObjectBindings, D as DurableObjectMigration, aC as ENVIRONMENT_TAG_PREFIX, E as Environment, m as EnvironmentNonInheritable, ax as File, aA as INHERIT_SYMBOL, aE as JSON_CONFIG_FORMATS, as as Json, O as Observability, aD as PATH_TO_DEPLOY_CONFIG, P as PreviewsConfig, b as RawDevConfig, d as RawEnvironment, a as RedirectedRawConfig, h as Route, n as Rule, aB as SERVICE_TAG_PREFIX, aw as ServiceFetch, av as ServiceMetadataRes, S as StreamingTailConsumer, T as TailConsumer, az as Trigger, U as UserLimits, au as WorkerMetadata, l as WorkflowBinding, Z as ZoneIdRoute, f as ZoneNameRoute, e as defaultWranglerConfig } from './config-CnJQHRQs.mjs';
3
3
  import * as jsoncParser from 'jsonc-parser';
4
4
  export { constructWranglerConfig } from './browser.mjs';
5
5
  export { Counter, MetricsRegistry } from './prometheus-metrics.mjs';
6
+ import { ChildProcess } from 'node:child_process';
6
7
  import '@cloudflare/workers-shared';
7
8
  import 'cloudflare';
8
9
 
@@ -181,7 +182,11 @@ declare class PatchConfigError extends Error {
181
182
  * Set to `true` to duplicate `message`.
182
183
  * */
183
184
  type TelemetryMessage = {
184
- telemetryMessage?: string | true;
185
+ telemetryMessage: string | boolean;
186
+ };
187
+ type UserErrorOptions = ErrorOptions & TelemetryMessage;
188
+ type FatalErrorOptions = UserErrorOptions & {
189
+ code?: number;
185
190
  };
186
191
  /**
187
192
  * Base class for errors where the user has done something wrong. These are not
@@ -191,14 +196,14 @@ type TelemetryMessage = {
191
196
  */
192
197
  declare class UserError extends Error {
193
198
  telemetryMessage: string | undefined;
194
- constructor(message?: string | undefined, options?: (ErrorOptions & TelemetryMessage) | undefined);
199
+ constructor(message: string, options: UserErrorOptions);
195
200
  }
196
201
  declare class DeprecationError extends UserError {
197
- constructor(message: string, options?: TelemetryMessage);
202
+ constructor(message: string, options: TelemetryMessage);
198
203
  }
199
204
  declare class FatalError extends UserError {
200
- readonly code?: number | undefined;
201
- constructor(message?: string, code?: number | undefined, options?: TelemetryMessage);
205
+ readonly code: number | undefined;
206
+ constructor(message: string, options: FatalErrorOptions);
202
207
  }
203
208
  declare class CommandLineArgsError extends UserError {
204
209
  }
@@ -207,12 +212,12 @@ declare class CommandLineArgsError extends UserError {
207
212
  *
208
213
  * To use, pass stringify'd json into the constructor like so:
209
214
  * ```js
210
- * throw new JsonFriendlyFatalError(JSON.stringify({ error: messageToDisplay });
215
+ * throw new JsonFriendlyFatalError(JSON.stringify({ error: messageToDisplay }), {
216
+ * telemetryMessage: false,
217
+ * });
211
218
  * ```
212
219
  */
213
220
  declare class JsonFriendlyFatalError extends FatalError {
214
- readonly code?: number | undefined;
215
- constructor(message?: string, code?: number | undefined, options?: TelemetryMessage);
216
221
  }
217
222
  declare class MissingConfigError extends Error {
218
223
  telemetryMessage: string | undefined;
@@ -223,14 +228,15 @@ declare class MissingConfigError extends Error {
223
228
  *
224
229
  * If `isJson` is true, then the `message` is JSON stringified.
225
230
  */
226
- declare function createFatalError(message: unknown, isJson: boolean, code?: number, telemetryMessage?: TelemetryMessage): Error;
231
+ declare function createFatalError(message: unknown, isJson: boolean, options: FatalErrorOptions): Error;
227
232
 
228
233
  type Message = {
229
234
  text: string;
230
235
  location?: Location;
231
236
  notes?: Message[];
232
237
  kind?: "warning" | "error";
233
- } & TelemetryMessage;
238
+ };
239
+ type MessageInit = Message & TelemetryMessage;
234
240
  type Location = ParseFile & {
235
241
  line: number;
236
242
  column: number;
@@ -250,13 +256,13 @@ declare class ParseError extends UserError implements Message {
250
256
  readonly notes: Message[];
251
257
  readonly location?: Location;
252
258
  readonly kind: "warning" | "error";
253
- constructor({ text, notes, location, kind, telemetryMessage }: Message);
259
+ constructor({ text, notes, location, kind, telemetryMessage }: MessageInit);
254
260
  }
255
261
  declare class APIError extends ParseError {
256
262
  #private;
257
263
  code?: number;
258
264
  accountTag?: string;
259
- constructor({ status, ...rest }: Message & {
265
+ constructor({ status, ...rest }: MessageInit & {
260
266
  status?: number;
261
267
  });
262
268
  get status(): number | undefined;
@@ -831,4 +837,54 @@ declare function removeDir(dirPath: string, options?: {
831
837
  */
832
838
  declare function removeDirSync(dirPath: string): void;
833
839
 
834
- export { APIError, Binding, COMPLIANCE_REGION_CONFIG_PUBLIC, COMPLIANCE_REGION_CONFIG_UNKNOWN, CommandLineArgsError, type CompatDate, type ComplianceConfig, Config, type ConfigBindingFieldName, type ConfigBindingOptions, DeprecationError, Diagnostics, FatalError, JsonFriendlyFatalError, type Location, type Message, MissingConfigError, type NormalizeAndValidateConfigArgs, type PackageJSON, ParseError, type ParseFile, PatchConfigError, RawConfig, type ResolveConfigPathOptions, type TelemetryMessage, UserError, WorkerMetadataBinding, assertNever, bucketFormatMessage, configFileName, configFormat, createFatalError, experimental_patchConfig, experimental_readRawConfig, findWranglerConfig, formatConfigSnippet, friendlyBindingNames, getBindingTypeFriendlyName, getBooleanEnvironmentVariableFactory, getBrowserRenderingHeadfulFromEnv, getBuildConditionsFromEnv, getBuildPlatformFromEnv, getC3CommandFromEnv, getCIGeneratePreviewAlias, getCIMatchTag, getCIOverrideName, getCIOverrideNetworkModeHost, getCfFetchEnabledFromEnv, getCfFetchPathFromEnv, getCloudflareApiBaseUrl, getCloudflareApiEnvironmentFromEnv, getCloudflareComplianceRegion, getCloudflareEnv, getCloudflareIncludeProcessEnvFromEnv, getCloudflareLoadDevVarsFromDotEnv, getCloudflaredPathFromEnv, getComplianceRegionSubdomain, getD1ExtraLocationChoices, getDisableConfigWatching, getDockerPath, getEnvironmentVariableFactory, getGlobalWranglerConfigPath, getLocalExplorerEnabledFromEnv, getOpenNextDeployFromEnv, getOutputFileDirectoryFromEnv, getOutputFilePathFromEnv, getRegistryPath, getSanitizeLogs, getSubdomainMixedStateCheckDisabled, getTodaysCompatDate, getTraceHeader, getWorkersCIBranchName, getWranglerCacheDirFromEnv, getWranglerHideBanner, getWranglerSendErrorReportsFromEnv, getWranglerSendMetricsFromEnv, hasProperty, indexLocation, isCompatDate, isDirectory, isDockerfile, isOptionalProperty, isPagesConfig, isRequiredProperty, isValidR2BucketName, mapWorkerMetadataBindings, normalizeAndValidateConfig, parseByteSize, parseHumanDuration, parseJSON, parseJSONC, parseNonHyphenedUuid, parsePackageJSON, parseTOML, readFileSync, readFileSyncToBuffer, removeDir, removeDirSync, resolveWranglerConfigPath, searchLocation, validatePagesConfig };
840
+ /**
841
+ * cloudflared binary management for Wrangler tunnel commands.
842
+ *
843
+ * This module handles downloading, caching, and running the cloudflared binary.
844
+ * It uses the Cloudflare update worker (update.argotunnel.com) to resolve
845
+ * the latest version and download URL, matching cloudflared's own update mechanism.
846
+ */
847
+
848
+ interface Logger {
849
+ log: typeof console.log;
850
+ warn: typeof console.warn;
851
+ debug: typeof console.debug;
852
+ }
853
+ /**
854
+ * Spawn cloudflared process with automatic binary management
855
+ */
856
+ declare function spawnCloudflared(args: string[], options?: {
857
+ stdio?: "inherit" | "pipe";
858
+ env?: Record<string, string>;
859
+ skipVersionCheck?: boolean;
860
+ confirmDownload?: (message: string) => Promise<boolean>;
861
+ logger?: Logger;
862
+ }): Promise<ChildProcess>;
863
+
864
+ interface TunnelResult {
865
+ publicUrl: URL;
866
+ }
867
+ interface Tunnel {
868
+ ready: () => Promise<TunnelResult>;
869
+ dispose: () => void;
870
+ extendExpiry: (ms?: number) => void;
871
+ }
872
+ interface TunnelOptions {
873
+ origin: URL;
874
+ timeoutMs?: number;
875
+ expiryMs?: number;
876
+ reminderIntervalMs?: number;
877
+ extendHint?: string;
878
+ logger?: Logger;
879
+ }
880
+ /**
881
+ * Start a Cloudflare Quick Tunnel for a local dev origin.
882
+ *
883
+ * Spawns `cloudflared tunnel --url <origin>` and waits for the public URL
884
+ * to appear in its stderr output. Returns a controller with a `ready()`
885
+ * promise that resolves once the tunnel URL is available, and a `dispose()`
886
+ * function to stop the tunnel.
887
+ */
888
+ declare function startTunnel(options: TunnelOptions): Tunnel;
889
+
890
+ export { APIError, Binding, COMPLIANCE_REGION_CONFIG_PUBLIC, COMPLIANCE_REGION_CONFIG_UNKNOWN, CommandLineArgsError, type CompatDate, type ComplianceConfig, Config, type ConfigBindingFieldName, type ConfigBindingOptions, DeprecationError, Diagnostics, FatalError, JsonFriendlyFatalError, type Location, type Message, MissingConfigError, type NormalizeAndValidateConfigArgs, type PackageJSON, ParseError, type ParseFile, PatchConfigError, RawConfig, type ResolveConfigPathOptions, type TelemetryMessage, type Tunnel, type TunnelOptions, UserError, WorkerMetadataBinding, assertNever, bucketFormatMessage, configFileName, configFormat, createFatalError, experimental_patchConfig, experimental_readRawConfig, findWranglerConfig, formatConfigSnippet, friendlyBindingNames, getBindingTypeFriendlyName, getBooleanEnvironmentVariableFactory, getBrowserRenderingHeadfulFromEnv, getBuildConditionsFromEnv, getBuildPlatformFromEnv, getC3CommandFromEnv, getCIGeneratePreviewAlias, getCIMatchTag, getCIOverrideName, getCIOverrideNetworkModeHost, getCfFetchEnabledFromEnv, getCfFetchPathFromEnv, getCloudflareApiBaseUrl, getCloudflareApiEnvironmentFromEnv, getCloudflareComplianceRegion, getCloudflareEnv, getCloudflareIncludeProcessEnvFromEnv, getCloudflareLoadDevVarsFromDotEnv, getCloudflaredPathFromEnv, getComplianceRegionSubdomain, getD1ExtraLocationChoices, getDisableConfigWatching, getDockerPath, getEnvironmentVariableFactory, getGlobalWranglerConfigPath, getLocalExplorerEnabledFromEnv, getOpenNextDeployFromEnv, getOutputFileDirectoryFromEnv, getOutputFilePathFromEnv, getRegistryPath, getSanitizeLogs, getSubdomainMixedStateCheckDisabled, getTodaysCompatDate, getTraceHeader, getWorkersCIBranchName, getWranglerCacheDirFromEnv, getWranglerHideBanner, getWranglerSendErrorReportsFromEnv, getWranglerSendMetricsFromEnv, hasProperty, indexLocation, isCompatDate, isDirectory, isDockerfile, isOptionalProperty, isPagesConfig, isRequiredProperty, isValidR2BucketName, mapWorkerMetadataBindings, normalizeAndValidateConfig, parseByteSize, parseHumanDuration, parseJSON, parseJSONC, parseNonHyphenedUuid, parsePackageJSON, parseTOML, readFileSync, readFileSyncToBuffer, removeDir, removeDirSync, resolveWranglerConfigPath, searchLocation, spawnCloudflared, startTunnel, validatePagesConfig };