wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9

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.
Files changed (239) hide show
  1. package/README.md +16 -2
  2. package/bin/wrangler.js +31 -11
  3. package/miniflare-dist/index.mjs +1340 -330
  4. package/package.json +40 -13
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +238 -0
  7. package/src/__tests__/api-devregistry.test.js +64 -0
  8. package/src/__tests__/api.test.ts +80 -0
  9. package/src/__tests__/configuration.test.ts +683 -470
  10. package/src/__tests__/d1.test.ts +123 -0
  11. package/src/__tests__/delete.test.ts +263 -0
  12. package/src/__tests__/deployments.test.ts +105 -0
  13. package/src/__tests__/dev.test.tsx +453 -70
  14. package/src/__tests__/dialogs.test.tsx +40 -0
  15. package/src/__tests__/generate.test.ts +235 -0
  16. package/src/__tests__/get-host-from-url.test.ts +16 -0
  17. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  18. package/src/__tests__/helpers/mock-cfetch.ts +92 -26
  19. package/src/__tests__/helpers/mock-console.ts +11 -2
  20. package/src/__tests__/helpers/mock-dialogs.ts +1 -1
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  23. package/src/__tests__/helpers/mock-kv.ts +1 -1
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
  25. package/src/__tests__/helpers/mock-process.ts +8 -13
  26. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  27. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  28. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  29. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  30. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  31. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  32. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  33. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  34. package/src/__tests__/helpers/msw/index.ts +21 -0
  35. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  36. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  37. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  38. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  39. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  40. package/src/__tests__/index.test.ts +103 -97
  41. package/src/__tests__/init.test.ts +1484 -382
  42. package/src/__tests__/jest.setup.ts +88 -5
  43. package/src/__tests__/kv.test.ts +655 -540
  44. package/src/__tests__/logout.test.ts +47 -0
  45. package/src/__tests__/metrics.test.ts +95 -45
  46. package/src/__tests__/middleware.scheduled.test.ts +145 -0
  47. package/src/__tests__/middleware.test.ts +750 -0
  48. package/src/__tests__/pages-deployment-tail.test.ts +884 -0
  49. package/src/__tests__/pages.test.ts +1301 -119
  50. package/src/__tests__/paths.test.ts +39 -0
  51. package/src/__tests__/publish.test.ts +2266 -1180
  52. package/src/__tests__/pubsub.test.ts +211 -88
  53. package/src/__tests__/queues.test.ts +522 -0
  54. package/src/__tests__/r2.test.ts +363 -203
  55. package/src/__tests__/secret.test.ts +261 -59
  56. package/src/__tests__/tail.test.ts +352 -151
  57. package/src/__tests__/test-old-node-version.js +3 -3
  58. package/src/__tests__/tsconfig-sanity.ts +12 -0
  59. package/src/__tests__/tsconfig.json +8 -0
  60. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  61. package/src/__tests__/type-generation.test.ts +233 -0
  62. package/src/__tests__/user.test.ts +59 -73
  63. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  64. package/src/__tests__/validate-dev-props.test.ts +56 -0
  65. package/src/__tests__/whoami.test.tsx +114 -66
  66. package/src/__tests__/worker-namespace.test.ts +154 -155
  67. package/src/api/dev.ts +170 -38
  68. package/src/api/index.ts +1 -0
  69. package/src/bundle-reporter.tsx +41 -2
  70. package/src/bundle.ts +668 -81
  71. package/src/cfetch/index.ts +40 -3
  72. package/src/cfetch/internal.ts +144 -32
  73. package/src/cli.ts +4 -3
  74. package/src/config/config.ts +27 -3
  75. package/src/config/environment.ts +131 -7
  76. package/src/config/index.ts +128 -8
  77. package/src/config/validation-helpers.ts +19 -6
  78. package/src/config/validation.ts +411 -14
  79. package/src/config-cache.ts +3 -2
  80. package/src/create-worker-preview.ts +31 -6
  81. package/src/create-worker-upload-form.ts +84 -22
  82. package/src/d1/backups.tsx +223 -0
  83. package/src/d1/constants.ts +2 -0
  84. package/src/d1/create.tsx +63 -0
  85. package/src/d1/delete.tsx +56 -0
  86. package/src/d1/execute.tsx +352 -0
  87. package/src/d1/formatTimeAgo.ts +14 -0
  88. package/src/d1/index.ts +101 -0
  89. package/src/d1/list.tsx +48 -0
  90. package/src/d1/migrations/apply.tsx +196 -0
  91. package/src/d1/migrations/create.tsx +77 -0
  92. package/src/d1/migrations/helpers.ts +147 -0
  93. package/src/d1/migrations/index.tsx +3 -0
  94. package/src/d1/migrations/list.tsx +79 -0
  95. package/src/d1/migrations/options.ts +18 -0
  96. package/src/d1/options.ts +22 -0
  97. package/src/d1/types.tsx +24 -0
  98. package/src/d1/utils.ts +48 -0
  99. package/src/delete.ts +108 -0
  100. package/src/deployments.ts +83 -0
  101. package/src/deprecated/index.ts +145 -0
  102. package/src/dev/dev-vars.ts +11 -8
  103. package/src/dev/dev.tsx +220 -58
  104. package/src/dev/get-local-persistence-path.tsx +31 -0
  105. package/src/dev/local.tsx +740 -181
  106. package/src/dev/remote.tsx +340 -123
  107. package/src/dev/start-server.ts +543 -0
  108. package/src/dev/use-esbuild.ts +61 -7
  109. package/src/dev/validate-dev-props.ts +31 -0
  110. package/src/dev-registry.tsx +201 -0
  111. package/src/dev.tsx +614 -258
  112. package/src/dialogs.tsx +41 -8
  113. package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
  114. package/src/docs/index.ts +97 -0
  115. package/src/entry.ts +3 -2
  116. package/src/environment-variables/factory.ts +88 -0
  117. package/src/environment-variables/misc-variables.ts +30 -0
  118. package/src/generate/index.ts +300 -0
  119. package/src/git-client.ts +100 -7
  120. package/src/index.tsx +249 -1560
  121. package/src/init.ts +626 -150
  122. package/src/inspect.ts +137 -32
  123. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  124. package/src/is-interactive.ts +4 -0
  125. package/src/jest.d.ts +4 -0
  126. package/src/{kv.ts → kv/helpers.ts} +3 -3
  127. package/src/kv/index.ts +596 -0
  128. package/src/logger.ts +27 -8
  129. package/src/metrics/index.ts +1 -0
  130. package/src/metrics/metrics-config.ts +4 -4
  131. package/src/metrics/metrics-dispatcher.ts +1 -0
  132. package/src/metrics/metrics-usage-headers.ts +24 -0
  133. package/src/metrics/send-event.ts +13 -8
  134. package/src/miniflare-cli/assets.ts +172 -465
  135. package/src/miniflare-cli/index.ts +149 -24
  136. package/src/miniflare-cli/tsconfig.json +9 -0
  137. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  138. package/src/miniflare-cli/types.ts +11 -0
  139. package/src/module-collection.ts +12 -3
  140. package/src/pages/build.tsx +108 -42
  141. package/src/pages/constants.ts +11 -0
  142. package/src/pages/deployment-tails.tsx +284 -0
  143. package/src/pages/deployments.tsx +9 -31
  144. package/src/pages/dev.tsx +417 -108
  145. package/src/pages/errors.ts +66 -0
  146. package/src/pages/functions/buildPlugin.ts +86 -84
  147. package/src/pages/functions/buildWorker.ts +121 -106
  148. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  149. package/src/pages/functions/routes-consolidation.ts +73 -0
  150. package/src/pages/functions/routes-transformation.test.ts +282 -0
  151. package/src/pages/functions/routes-transformation.ts +115 -0
  152. package/src/pages/functions/routes-validation.test.ts +403 -0
  153. package/src/pages/functions/routes-validation.ts +202 -0
  154. package/src/pages/functions/tsconfig.json +8 -0
  155. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  156. package/src/pages/functions.tsx +82 -0
  157. package/src/pages/hash.tsx +13 -0
  158. package/src/pages/index.tsx +73 -55
  159. package/src/pages/projects.tsx +9 -3
  160. package/src/pages/prompt-select-project.tsx +31 -0
  161. package/src/pages/publish.tsx +183 -60
  162. package/src/pages/types.ts +1 -0
  163. package/src/pages/upload.tsx +107 -56
  164. package/src/pages/utils.ts +13 -2
  165. package/src/paths.ts +49 -4
  166. package/src/proxy.ts +375 -157
  167. package/src/publish/index.ts +270 -0
  168. package/src/{publish.ts → publish/publish.ts} +431 -188
  169. package/src/pubsub/pubsub-commands.tsx +4 -3
  170. package/src/queues/cli/commands/consumer/add.ts +71 -0
  171. package/src/queues/cli/commands/consumer/index.ts +22 -0
  172. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  173. package/src/queues/cli/commands/create.ts +25 -0
  174. package/src/queues/cli/commands/delete.ts +26 -0
  175. package/src/queues/cli/commands/index.ts +36 -0
  176. package/src/queues/cli/commands/list.ts +25 -0
  177. package/src/queues/client.ts +135 -0
  178. package/src/queues/utils.ts +18 -0
  179. package/src/r2/constants.ts +4 -0
  180. package/src/r2/helpers.ts +131 -0
  181. package/src/r2/index.ts +289 -0
  182. package/src/routes.ts +140 -0
  183. package/src/secret/index.ts +379 -0
  184. package/src/sites.tsx +3 -3
  185. package/src/tail/createTail.ts +379 -0
  186. package/src/tail/filters.ts +4 -6
  187. package/src/tail/index.ts +199 -284
  188. package/src/tail/printing.ts +43 -3
  189. package/src/tsconfig-sanity.ts +16 -0
  190. package/src/type-generation.ts +181 -0
  191. package/src/user/access.ts +68 -0
  192. package/src/user/auth-variables.ts +113 -0
  193. package/src/user/choose-account.tsx +1 -1
  194. package/src/user/index.ts +0 -1
  195. package/src/user/user.tsx +116 -49
  196. package/src/utils/collectKeyValues.ts +14 -0
  197. package/src/whoami.tsx +80 -2
  198. package/src/worker.ts +69 -9
  199. package/src/yargs-types.ts +24 -0
  200. package/src/zones.ts +124 -9
  201. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  202. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  203. package/templates/__tests__/tsconfig.json +8 -0
  204. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  205. package/templates/d1-beta-facade.js +205 -0
  206. package/templates/facade.d.ts +14 -0
  207. package/templates/first-party-worker-module-facade.ts +19 -0
  208. package/templates/format-dev-errors.ts +33 -0
  209. package/templates/init-tests/test-jest-new-worker.js +23 -0
  210. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  211. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  212. package/templates/middleware/common.ts +62 -0
  213. package/templates/middleware/loader-modules.ts +82 -0
  214. package/templates/middleware/loader-sw.ts +233 -0
  215. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  216. package/templates/middleware/middleware-pretty-error.ts +40 -0
  217. package/templates/middleware/middleware-scheduled.ts +15 -0
  218. package/templates/new-worker.js +1 -1
  219. package/templates/pages-dev-pipeline.ts +31 -0
  220. package/templates/pages-dev-util.ts +52 -0
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +21 -5
  223. package/templates/pages-template-worker.ts +37 -9
  224. package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
  225. package/templates/service-bindings-module-facade.js +54 -0
  226. package/templates/service-bindings-sw-facade.js +42 -0
  227. package/templates/tsconfig-sanity.ts +11 -0
  228. package/templates/tsconfig.init.json +106 -0
  229. package/templates/tsconfig.json +5 -102
  230. package/templates/tsconfig.tsbuildinfo +1 -0
  231. package/wrangler-dist/cli.d.ts +621 -42
  232. package/wrangler-dist/cli.js +144441 -102606
  233. package/src/environment-variables.ts +0 -35
  234. package/src/faye-websocket.d.ts +0 -6
  235. package/src/generate.ts +0 -33
  236. package/src/miniflare-cli/enum-keys.ts +0 -17
  237. package/src/preview.ts +0 -31
  238. package/src/r2.ts +0 -50
  239. package/src/user/env-vars.ts +0 -46
@@ -102,6 +102,14 @@ export function normalizeAndValidateConfig(
102
102
  "boolean"
103
103
  );
104
104
 
105
+ validateOptionalProperty(
106
+ diagnostics,
107
+ "",
108
+ "keep_vars",
109
+ rawConfig.keep_vars,
110
+ "boolean"
111
+ );
112
+
105
113
  // TODO: set the default to false to turn on service environments as the default
106
114
  const isLegacyEnv =
107
115
  (args as { "legacy-env": boolean | undefined })["legacy-env"] ??
@@ -182,6 +190,7 @@ export function normalizeAndValidateConfig(
182
190
  configPath,
183
191
  legacy_env: isLegacyEnv,
184
192
  send_metrics: rawConfig.send_metrics,
193
+ keep_vars: rawConfig.keep_vars,
185
194
  ...activeEnv,
186
195
  dev: normalizeAndValidateDev(diagnostics, rawConfig.dev ?? {}),
187
196
  migrations: normalizeAndValidateMigrations(
@@ -357,8 +366,9 @@ function normalizeAndValidateDev(
357
366
  rawDev: RawDevConfig
358
367
  ): DevConfig {
359
368
  const {
360
- ip = "localhost",
369
+ ip = "0.0.0.0",
361
370
  port,
371
+ inspector_port,
362
372
  local_protocol = "http",
363
373
  upstream_protocol = "https",
364
374
  host,
@@ -368,6 +378,13 @@ function normalizeAndValidateDev(
368
378
 
369
379
  validateOptionalProperty(diagnostics, "dev", "ip", ip, "string");
370
380
  validateOptionalProperty(diagnostics, "dev", "port", port, "number");
381
+ validateOptionalProperty(
382
+ diagnostics,
383
+ "dev",
384
+ "inspector_port",
385
+ inspector_port,
386
+ "number"
387
+ );
371
388
  validateOptionalProperty(
372
389
  diagnostics,
373
390
  "dev",
@@ -385,7 +402,7 @@ function normalizeAndValidateDev(
385
402
  ["http", "https"]
386
403
  );
387
404
  validateOptionalProperty(diagnostics, "dev", "host", host, "string");
388
- return { ip, port, local_protocol, upstream_protocol, host };
405
+ return { ip, port, inspector_port, local_protocol, upstream_protocol, host };
389
406
  }
390
407
 
391
408
  /**
@@ -590,25 +607,68 @@ function normalizeAndValidateAssets(
590
607
  diagnostics: Diagnostics,
591
608
  configPath: string | undefined,
592
609
  rawConfig: RawConfig
593
- ) {
594
- if (
595
- typeof rawConfig?.assets === "string" ||
596
- rawConfig?.assets === undefined
597
- ) {
598
- return rawConfig?.assets;
610
+ ): Config["assets"] {
611
+ // Even though the type doesn't say it,
612
+ // we allow for a string input in the config,
613
+ // so let's normalise it
614
+ if (typeof rawConfig?.assets === "string") {
615
+ return {
616
+ bucket: rawConfig.assets,
617
+ include: [],
618
+ exclude: [],
619
+ browser_TTL: undefined,
620
+ serve_single_page_app: false,
621
+ };
622
+ }
623
+
624
+ if (rawConfig?.assets === undefined) {
625
+ return undefined;
599
626
  }
600
627
 
601
- const { bucket, include = [], exclude = [], ...rest } = rawConfig.assets;
628
+ if (typeof rawConfig.assets !== "object") {
629
+ diagnostics.errors.push(
630
+ `Expected the \`assets\` field to be a string or an object, but got ${typeof rawConfig.assets}.`
631
+ );
632
+ return undefined;
633
+ }
634
+
635
+ const {
636
+ bucket,
637
+ include = [],
638
+ exclude = [],
639
+ browser_TTL,
640
+ serve_single_page_app,
641
+ ...rest
642
+ } = rawConfig.assets;
602
643
 
603
644
  validateAdditionalProperties(diagnostics, "assets", Object.keys(rest), []);
645
+
604
646
  validateRequiredProperty(diagnostics, "assets", "bucket", bucket, "string");
605
647
  validateTypedArray(diagnostics, "assets.include", include, "string");
606
648
  validateTypedArray(diagnostics, "assets.exclude", exclude, "string");
607
649
 
650
+ validateOptionalProperty(
651
+ diagnostics,
652
+ "assets",
653
+ "browser_TTL",
654
+ browser_TTL,
655
+ "number"
656
+ );
657
+
658
+ validateOptionalProperty(
659
+ diagnostics,
660
+ "assets",
661
+ "serve_single_page_app",
662
+ serve_single_page_app,
663
+ "boolean"
664
+ );
665
+
608
666
  return {
609
667
  bucket,
610
668
  include,
611
669
  exclude,
670
+ browser_TTL,
671
+ serve_single_page_app,
612
672
  };
613
673
  }
614
674
 
@@ -822,6 +882,13 @@ function normalizeAndValidateEnvironment(
822
882
  isLegacyEnv?: boolean,
823
883
  rawConfig?: RawConfig | undefined
824
884
  ): Environment {
885
+ deprecated(
886
+ diagnostics,
887
+ rawEnv,
888
+ "kv-namespaces",
889
+ `The "kv-namespaces" field is no longer supported, please rename to "kv_namespaces"`,
890
+ true
891
+ );
825
892
  deprecated(
826
893
  diagnostics,
827
894
  rawEnv,
@@ -831,6 +898,7 @@ function normalizeAndValidateEnvironment(
831
898
  );
832
899
 
833
900
  // The field "experimental_services" doesn't exist anymore in the config, but we still want to error about any older usage.
901
+
834
902
  deprecated(
835
903
  diagnostics,
836
904
  rawEnv,
@@ -841,7 +909,6 @@ function normalizeAndValidateEnvironment(
841
909
 
842
910
  experimental(diagnostics, rawEnv, "unsafe");
843
911
  experimental(diagnostics, rawEnv, "services");
844
- experimental(diagnostics, rawEnv, "worker_namespaces");
845
912
 
846
913
  const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
847
914
 
@@ -1007,6 +1074,16 @@ function normalizeAndValidateEnvironment(
1007
1074
  validateBindingArray(envName, validateKVBinding),
1008
1075
  []
1009
1076
  ),
1077
+ queues: notInheritable(
1078
+ diagnostics,
1079
+ topLevelEnv,
1080
+ rawConfig,
1081
+ rawEnv,
1082
+ envName,
1083
+ "queues",
1084
+ validateQueues(envName),
1085
+ { producers: [], consumers: [] }
1086
+ ),
1010
1087
  r2_buckets: notInheritable(
1011
1088
  diagnostics,
1012
1089
  topLevelEnv,
@@ -1017,6 +1094,16 @@ function normalizeAndValidateEnvironment(
1017
1094
  validateBindingArray(envName, validateR2Binding),
1018
1095
  []
1019
1096
  ),
1097
+ d1_databases: notInheritable(
1098
+ diagnostics,
1099
+ topLevelEnv,
1100
+ rawConfig,
1101
+ rawEnv,
1102
+ envName,
1103
+ "d1_databases",
1104
+ validateBindingArray(envName, validateD1Binding),
1105
+ []
1106
+ ),
1020
1107
  services: notInheritable(
1021
1108
  diagnostics,
1022
1109
  topLevelEnv,
@@ -1027,16 +1114,37 @@ function normalizeAndValidateEnvironment(
1027
1114
  validateBindingArray(envName, validateServiceBinding),
1028
1115
  []
1029
1116
  ),
1030
- worker_namespaces: notInheritable(
1117
+ analytics_engine_datasets: notInheritable(
1118
+ diagnostics,
1119
+ topLevelEnv,
1120
+ rawConfig,
1121
+ rawEnv,
1122
+ envName,
1123
+ "analytics_engine_datasets",
1124
+ validateBindingArray(envName, validateAnalyticsEngineBinding),
1125
+ []
1126
+ ),
1127
+ dispatch_namespaces: notInheritable(
1031
1128
  diagnostics,
1032
1129
  topLevelEnv,
1033
1130
  rawConfig,
1034
1131
  rawEnv,
1035
1132
  envName,
1036
- "worker_namespaces",
1133
+ "dispatch_namespaces",
1037
1134
  validateBindingArray(envName, validateWorkerNamespaceBinding),
1038
1135
  []
1039
1136
  ),
1137
+ logfwdr: inheritable(
1138
+ diagnostics,
1139
+ topLevelEnv,
1140
+ rawEnv,
1141
+ "logfwdr",
1142
+ validateBindingsProperty(envName, validateCflogfwdrBinding),
1143
+ {
1144
+ schema: undefined,
1145
+ bindings: [],
1146
+ }
1147
+ ),
1040
1148
  unsafe: notInheritable(
1041
1149
  diagnostics,
1042
1150
  topLevelEnv,
@@ -1074,6 +1182,22 @@ function normalizeAndValidateEnvironment(
1074
1182
  isBoolean,
1075
1183
  undefined
1076
1184
  ),
1185
+ first_party_worker: inheritable(
1186
+ diagnostics,
1187
+ topLevelEnv,
1188
+ rawEnv,
1189
+ "first_party_worker",
1190
+ isBoolean,
1191
+ undefined
1192
+ ),
1193
+ logpush: inheritable(
1194
+ diagnostics,
1195
+ topLevelEnv,
1196
+ rawEnv,
1197
+ "logpush",
1198
+ isBoolean,
1199
+ undefined
1200
+ ),
1077
1201
  };
1078
1202
 
1079
1203
  return environment;
@@ -1410,6 +1534,30 @@ const validateDurableObjectBinding: ValidatorFn = (
1410
1534
  return isValid;
1411
1535
  };
1412
1536
 
1537
+ const validateCflogfwdrBinding: ValidatorFn = (diagnostics, field, value) => {
1538
+ if (typeof value !== "object" || value === null) {
1539
+ diagnostics.errors.push(
1540
+ `Expected "${field}" to be an object but got ${JSON.stringify(value)}`
1541
+ );
1542
+ return false;
1543
+ }
1544
+
1545
+ let isValid = true;
1546
+ if (!isRequiredProperty(value, "name", "string")) {
1547
+ diagnostics.errors.push(`binding should have a string "name" field.`);
1548
+ isValid = false;
1549
+ }
1550
+
1551
+ if (!isRequiredProperty(value, "destination", "string")) {
1552
+ diagnostics.errors.push(
1553
+ `binding should have a string "destination" field.`
1554
+ );
1555
+ isValid = false;
1556
+ }
1557
+
1558
+ return isValid;
1559
+ };
1560
+
1413
1561
  /**
1414
1562
  * Check that the given field is a valid "unsafe" binding object.
1415
1563
  *
@@ -1438,8 +1586,10 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
1438
1586
  "text_blob",
1439
1587
  "kv_namespace",
1440
1588
  "durable_object_namespace",
1589
+ "d1_database",
1441
1590
  "r2_bucket",
1442
1591
  "service",
1592
+ "logfwdr",
1443
1593
  ];
1444
1594
 
1445
1595
  if (safeBindings.includes(value.type)) {
@@ -1528,7 +1678,10 @@ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
1528
1678
  );
1529
1679
  isValid = false;
1530
1680
  }
1531
- if (!isRequiredProperty(value, "id", "string")) {
1681
+ if (
1682
+ !isRequiredProperty(value, "id", "string") ||
1683
+ (value as { id: string }).id.length === 0
1684
+ ) {
1532
1685
  diagnostics.errors.push(
1533
1686
  `"${field}" bindings should have a string "id" field but got ${JSON.stringify(
1534
1687
  value
@@ -1547,6 +1700,47 @@ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
1547
1700
  return isValid;
1548
1701
  };
1549
1702
 
1703
+ const validateQueueBinding: ValidatorFn = (diagnostics, field, value) => {
1704
+ if (typeof value !== "object" || value === null) {
1705
+ diagnostics.errors.push(
1706
+ `"queue" bindings should be objects, but got ${JSON.stringify(value)}`
1707
+ );
1708
+ return false;
1709
+ }
1710
+
1711
+ if (
1712
+ !validateAdditionalProperties(diagnostics, field, Object.keys(value), [
1713
+ "binding",
1714
+ "queue",
1715
+ ])
1716
+ ) {
1717
+ return false;
1718
+ }
1719
+
1720
+ // Queue bindings must have a binding and queue.
1721
+ let isValid = true;
1722
+ if (!isRequiredProperty(value, "binding", "string")) {
1723
+ diagnostics.errors.push(
1724
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
1725
+ value
1726
+ )}.`
1727
+ );
1728
+ isValid = false;
1729
+ }
1730
+ if (
1731
+ !isRequiredProperty(value, "queue", "string") ||
1732
+ (value as { queue: string }).queue.length === 0
1733
+ ) {
1734
+ diagnostics.errors.push(
1735
+ `"${field}" bindings should have a string "queue" field but got ${JSON.stringify(
1736
+ value
1737
+ )}.`
1738
+ );
1739
+ isValid = false;
1740
+ }
1741
+ return isValid;
1742
+ };
1743
+
1550
1744
  const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
1551
1745
  if (typeof value !== "object" || value === null) {
1552
1746
  diagnostics.errors.push(
@@ -1566,7 +1760,10 @@ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
1566
1760
  );
1567
1761
  isValid = false;
1568
1762
  }
1569
- if (!isRequiredProperty(value, "bucket_name", "string")) {
1763
+ if (
1764
+ !isRequiredProperty(value, "bucket_name", "string") ||
1765
+ (value as { bucket_name: string }).bucket_name.length === 0
1766
+ ) {
1570
1767
  diagnostics.errors.push(
1571
1768
  `"${field}" bindings should have a string "bucket_name" field but got ${JSON.stringify(
1572
1769
  value
@@ -1585,6 +1782,53 @@ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
1585
1782
  return isValid;
1586
1783
  };
1587
1784
 
1785
+ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
1786
+ if (typeof value !== "object" || value === null) {
1787
+ diagnostics.errors.push(
1788
+ `"d1_databases" bindings should be objects, but got ${JSON.stringify(
1789
+ value
1790
+ )}`
1791
+ );
1792
+ return false;
1793
+ }
1794
+ let isValid = true;
1795
+ // D1 databases must have a binding and either a database_name or database_id.
1796
+ if (!isRequiredProperty(value, "binding", "string")) {
1797
+ diagnostics.errors.push(
1798
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
1799
+ value
1800
+ )}.`
1801
+ );
1802
+ isValid = false;
1803
+ }
1804
+ if (
1805
+ // TODO: allow name only, where we look up the ID dynamically
1806
+ // !isOptionalProperty(value, "database_name", "string") &&
1807
+ !isRequiredProperty(value, "database_id", "string")
1808
+ ) {
1809
+ diagnostics.errors.push(
1810
+ `"${field}" bindings must have a "database_id" field but got ${JSON.stringify(
1811
+ value
1812
+ )}.`
1813
+ );
1814
+ isValid = false;
1815
+ }
1816
+ if (!isOptionalProperty(value, "preview_database_id", "string")) {
1817
+ diagnostics.errors.push(
1818
+ `"${field}" bindings should, optionally, have a string "preview_database_id" field but got ${JSON.stringify(
1819
+ value
1820
+ )}.`
1821
+ );
1822
+ isValid = false;
1823
+ }
1824
+ if (isValid && !process.env.NO_D1_WARNING) {
1825
+ diagnostics.warnings.push(
1826
+ `D1 Bindings are currently in alpha to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose\nNote: set NO_D1_WARNING=true to hide this message`
1827
+ );
1828
+ }
1829
+ return isValid;
1830
+ };
1831
+
1588
1832
  /**
1589
1833
  * Check that bindings whose names might conflict, don't.
1590
1834
  *
@@ -1599,6 +1843,7 @@ const validateBindingsHaveUniqueNames = (
1599
1843
  durable_objects,
1600
1844
  kv_namespaces,
1601
1845
  r2_buckets,
1846
+ analytics_engine_datasets,
1602
1847
  text_blobs,
1603
1848
  unsafe,
1604
1849
  vars,
@@ -1613,6 +1858,7 @@ const validateBindingsHaveUniqueNames = (
1613
1858
  "Durable Object": getBindingNames(durable_objects),
1614
1859
  "KV Namespace": getBindingNames(kv_namespaces),
1615
1860
  "R2 Bucket": getBindingNames(r2_buckets),
1861
+ "Analytics Engine Dataset": getBindingNames(analytics_engine_datasets),
1616
1862
  "Text Blob": getBindingNames(text_blobs),
1617
1863
  Unsafe: getBindingNames(unsafe),
1618
1864
  "Environment Variable": getBindingNames(vars),
@@ -1721,6 +1967,43 @@ const validateServiceBinding: ValidatorFn = (diagnostics, field, value) => {
1721
1967
  return isValid;
1722
1968
  };
1723
1969
 
1970
+ const validateAnalyticsEngineBinding: ValidatorFn = (
1971
+ diagnostics,
1972
+ field,
1973
+ value
1974
+ ) => {
1975
+ if (typeof value !== "object" || value === null) {
1976
+ diagnostics.errors.push(
1977
+ `"analytics_engine" bindings should be objects, but got ${JSON.stringify(
1978
+ value
1979
+ )}`
1980
+ );
1981
+ return false;
1982
+ }
1983
+ let isValid = true;
1984
+ // Service bindings must have a binding and optional dataset.
1985
+ if (!isRequiredProperty(value, "binding", "string")) {
1986
+ diagnostics.errors.push(
1987
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
1988
+ value
1989
+ )}.`
1990
+ );
1991
+ isValid = false;
1992
+ }
1993
+ if (
1994
+ !isOptionalProperty(value, "dataset", "string") ||
1995
+ (value as { dataset: string }).dataset?.length === 0
1996
+ ) {
1997
+ diagnostics.errors.push(
1998
+ `"${field}" bindings should, optionally, have a string "dataset" field but got ${JSON.stringify(
1999
+ value
2000
+ )}.`
2001
+ );
2002
+ isValid = false;
2003
+ }
2004
+ return isValid;
2005
+ };
2006
+
1724
2007
  const validateWorkerNamespaceBinding: ValidatorFn = (
1725
2008
  diagnostics,
1726
2009
  field,
@@ -1752,3 +2035,117 @@ const validateWorkerNamespaceBinding: ValidatorFn = (
1752
2035
  }
1753
2036
  return isValid;
1754
2037
  };
2038
+
2039
+ function validateQueues(envName: string): ValidatorFn {
2040
+ return (diagnostics, field, value, config) => {
2041
+ const fieldPath =
2042
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
2043
+
2044
+ if (typeof value !== "object" || Array.isArray(value) || value === null) {
2045
+ diagnostics.errors.push(
2046
+ `The field "${fieldPath}" should be an object but got ${JSON.stringify(
2047
+ value
2048
+ )}.`
2049
+ );
2050
+ return false;
2051
+ }
2052
+
2053
+ let isValid = true;
2054
+ if (
2055
+ !validateAdditionalProperties(
2056
+ diagnostics,
2057
+ fieldPath,
2058
+ Object.keys(value),
2059
+ ["consumers", "producers"]
2060
+ )
2061
+ ) {
2062
+ isValid = false;
2063
+ }
2064
+
2065
+ if (hasProperty(value, "consumers")) {
2066
+ const consumers = value.consumers;
2067
+ if (!Array.isArray(consumers)) {
2068
+ diagnostics.errors.push(
2069
+ `The field "${fieldPath}.consumers" should be an array but got ${JSON.stringify(
2070
+ consumers
2071
+ )}.`
2072
+ );
2073
+ isValid = false;
2074
+ }
2075
+
2076
+ for (let i = 0; i < consumers.length; i++) {
2077
+ const consumer = consumers[i];
2078
+ const consumerPath = `${fieldPath}.consumers[${i}]`;
2079
+ if (!validateConsumer(diagnostics, consumerPath, consumer, config)) {
2080
+ isValid = false;
2081
+ }
2082
+ }
2083
+ }
2084
+
2085
+ if (hasProperty(value, "producers")) {
2086
+ if (
2087
+ !validateBindingArray(envName, validateQueueBinding)(
2088
+ diagnostics,
2089
+ `${field}.producers`,
2090
+ value.producers,
2091
+ config
2092
+ )
2093
+ ) {
2094
+ isValid = false;
2095
+ }
2096
+ }
2097
+ return isValid;
2098
+ };
2099
+ }
2100
+
2101
+ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
2102
+ if (typeof value !== "object" || value === null) {
2103
+ diagnostics.errors.push(
2104
+ `"${field}" should be a objects, but got ${JSON.stringify(value)}`
2105
+ );
2106
+ return false;
2107
+ }
2108
+
2109
+ let isValid = true;
2110
+ if (
2111
+ !validateAdditionalProperties(diagnostics, field, Object.keys(value), [
2112
+ "queue",
2113
+ "max_batch_size",
2114
+ "max_batch_timeout",
2115
+ "max_retries",
2116
+ "dead_letter_queue",
2117
+ ])
2118
+ ) {
2119
+ isValid = false;
2120
+ }
2121
+
2122
+ if (!isRequiredProperty(value, "queue", "string")) {
2123
+ diagnostics.errors.push(
2124
+ `"${field}" should have a string "queue" field but got ${JSON.stringify(
2125
+ value
2126
+ )}.`
2127
+ );
2128
+ }
2129
+
2130
+ const options: {
2131
+ key: string;
2132
+ type: "number" | "string";
2133
+ }[] = [
2134
+ { key: "max_batch_size", type: "number" },
2135
+ { key: "max_batch_timeout", type: "number" },
2136
+ { key: "max_retries", type: "number" },
2137
+ { key: "dead_letter_queue", type: "string" },
2138
+ ];
2139
+ for (const optionalOpt of options) {
2140
+ if (!isOptionalProperty(value, optionalOpt.key, optionalOpt.type)) {
2141
+ diagnostics.errors.push(
2142
+ `"${field}" should, optionally, have a ${optionalOpt.type} "${
2143
+ optionalOpt.key
2144
+ }" field but got ${JSON.stringify(value)}.`
2145
+ );
2146
+ isValid = false;
2147
+ }
2148
+ }
2149
+
2150
+ return isValid;
2151
+ };
@@ -1,6 +1,7 @@
1
1
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
2
2
  import * as path from "path";
3
3
  import { findUpSync } from "find-up";
4
+ import { CI } from "./is-ci";
4
5
  import isInteractive from "./is-interactive";
5
6
  import { logger } from "./logger";
6
7
 
@@ -29,9 +30,9 @@ const arrayFormatter = new Intl.ListFormat("en", {
29
30
  });
30
31
 
31
32
  function showCacheMessage(fields: string[], folder: string) {
32
- if (!cacheMessageShown && isInteractive()) {
33
+ if (!cacheMessageShown && isInteractive() && !CI.isCI()) {
33
34
  if (fields.length > 0) {
34
- logger.log(
35
+ logger.debug(
35
36
  `Retrieving cached values for ${arrayFormatter.format(
36
37
  fields
37
38
  )} from ${path.relative(process.cwd(), folder)}`
@@ -3,7 +3,10 @@ import { fetch } from "undici";
3
3
  import { fetchResult } from "./cfetch";
4
4
  import { createWorkerUploadForm } from "./create-worker-upload-form";
5
5
  import { logger } from "./logger";
6
+ import { parseJSON } from "./parse";
7
+ import { getAccessToken } from "./user/access";
6
8
  import type { CfAccount, CfWorkerContext, CfWorkerInit } from "./worker";
9
+ import type { HeadersInit } from "undici";
7
10
 
8
11
  /**
9
12
  * A Preview Session on the edge
@@ -125,9 +128,26 @@ export async function createPreviewSession(
125
128
  undefined,
126
129
  abortSignal
127
130
  );
128
- const { inspector_websocket, prewarm, token } = (await (
129
- await fetch(exchange_url, { signal: abortSignal })
130
- ).json()) as { inspector_websocket: string; token: string; prewarm: string };
131
+
132
+ logger.debug(`-- START EXCHANGE API REQUEST: GET ${exchange_url}`);
133
+ logger.debug("-- END EXCHANGE API REQUEST");
134
+ const exchangeResponse = await fetch(exchange_url, { signal: abortSignal });
135
+ const bodyText = await exchangeResponse.text();
136
+ logger.debug(
137
+ "-- START EXCHANGE API RESPONSE:",
138
+ exchangeResponse.statusText,
139
+ exchangeResponse.status
140
+ );
141
+ logger.debug("HEADERS:", JSON.stringify(exchangeResponse.headers, null, 2));
142
+ logger.debug("RESPONSE:", bodyText);
143
+ logger.debug("-- END EXCHANGE API RESPONSE");
144
+
145
+ const { inspector_websocket, prewarm, token } = parseJSON<{
146
+ inspector_websocket: string;
147
+ token: string;
148
+ prewarm: string;
149
+ }>(bodyText);
150
+
131
151
  const { host } = new URL(inspector_websocket);
132
152
  const query = `cf_workers_preview_token=${token}`;
133
153
 
@@ -233,13 +253,18 @@ export async function createWorkerPreview(
233
253
  session,
234
254
  abortSignal
235
255
  );
256
+ const accessToken = await getAccessToken(token.prewarmUrl.hostname);
257
+
258
+ const headers: HeadersInit = { "cf-workers-preview-token": token.value };
259
+ if (accessToken) {
260
+ headers.cookie = `CF_Authorization=${accessToken}`;
261
+ }
262
+
236
263
  // fire and forget the prewarm call
237
264
  fetch(token.prewarmUrl.href, {
238
265
  method: "POST",
239
266
  signal: abortSignal,
240
- headers: {
241
- "cf-workers-preview-token": token.value,
242
- },
267
+ headers,
243
268
  }).then(
244
269
  (response) => {
245
270
  if (!response.ok) {