wrangler 0.0.0-e98613f8 → 0.0.0-e9a45766c

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 (244) hide show
  1. package/README.md +10 -4
  2. package/bin/wrangler.js +10 -2
  3. package/miniflare-dist/index.mjs +257 -132
  4. package/package.json +26 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +575 -39
  9. package/src/__tests__/constellation.test.ts +371 -0
  10. package/src/__tests__/d1/d1.test.ts +82 -0
  11. package/src/__tests__/d1/execute.test.ts +66 -0
  12. package/src/__tests__/d1/migrate.test.ts +257 -0
  13. package/src/__tests__/d1/splitter.test.ts +255 -0
  14. package/src/__tests__/delete.test.ts +11 -2
  15. package/src/__tests__/deployments.test.ts +330 -52
  16. package/src/__tests__/dev.test.tsx +146 -82
  17. package/src/__tests__/generate.test.ts +10 -8
  18. package/src/__tests__/guess-worker-format.test.ts +35 -0
  19. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  20. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  21. package/src/__tests__/helpers/mock-console.ts +6 -0
  22. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  23. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  24. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  25. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  26. package/src/__tests__/helpers/mock-kv.ts +29 -16
  27. package/src/__tests__/helpers/mock-oauth-flow.ts +99 -92
  28. package/src/__tests__/helpers/mock-process.ts +8 -13
  29. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  30. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  31. package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
  32. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +92 -74
  42. package/src/__tests__/init.test.ts +909 -628
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +1 -1
  47. package/src/__tests__/metrics.test.ts +93 -50
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +589 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +528 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +239 -102
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +2218 -1002
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +42 -32
  63. package/src/__tests__/r2.test.ts +37 -56
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +113 -23
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +8 -0
  72. package/src/__tests__/user.test.ts +7 -18
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +172 -61
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +77 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +371 -0
  81. package/src/bundle.ts +139 -33
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +80 -16
  87. package/src/config/index.ts +99 -30
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +275 -9
  90. package/src/constellation/createProject.tsx +51 -0
  91. package/src/constellation/deleteProject.ts +51 -0
  92. package/src/constellation/deleteProjectModel.ts +68 -0
  93. package/src/constellation/index.ts +75 -0
  94. package/src/constellation/listCatalog.tsx +35 -0
  95. package/src/constellation/listModel.tsx +41 -0
  96. package/src/constellation/listProject.tsx +28 -0
  97. package/src/constellation/listRuntime.tsx +28 -0
  98. package/src/constellation/options.ts +17 -0
  99. package/src/constellation/types.ts +17 -0
  100. package/src/constellation/uploadModel.tsx +64 -0
  101. package/src/constellation/utils.ts +90 -0
  102. package/src/create-worker-preview.ts +19 -8
  103. package/src/create-worker-upload-form.ts +52 -5
  104. package/src/d1/backups.tsx +40 -44
  105. package/src/d1/create.tsx +50 -43
  106. package/src/d1/{delete.tsx → delete.ts} +8 -11
  107. package/src/d1/execute.tsx +171 -166
  108. package/src/d1/index.ts +5 -6
  109. package/src/d1/list.tsx +27 -13
  110. package/src/d1/migrations/apply.tsx +92 -64
  111. package/src/d1/migrations/create.tsx +31 -29
  112. package/src/d1/migrations/helpers.ts +66 -44
  113. package/src/d1/migrations/list.tsx +47 -31
  114. package/src/d1/migrations/options.ts +7 -2
  115. package/src/d1/options.ts +3 -3
  116. package/src/d1/splitter.ts +161 -0
  117. package/src/d1/{types.tsx → types.ts} +1 -0
  118. package/src/d1/utils.ts +2 -1
  119. package/src/delete.ts +8 -16
  120. package/src/deployments.ts +333 -42
  121. package/src/deprecated/index.ts +8 -302
  122. package/src/dev/dev.tsx +13 -22
  123. package/src/dev/local.tsx +131 -69
  124. package/src/dev/remote.tsx +35 -3
  125. package/src/dev/start-server.ts +83 -77
  126. package/src/dev/use-esbuild.ts +63 -52
  127. package/src/dev/validate-dev-props.ts +9 -0
  128. package/src/{dev-registry.tsx → dev-registry.ts} +9 -8
  129. package/src/dev.tsx +131 -110
  130. package/src/dialogs.ts +136 -0
  131. package/src/dispatch-namespace.ts +21 -17
  132. package/src/docs/helpers.ts +50 -0
  133. package/src/docs/index.ts +54 -0
  134. package/src/entry.ts +26 -11
  135. package/src/environment-variables/factory.ts +89 -0
  136. package/src/environment-variables/misc-variables.ts +30 -0
  137. package/src/generate/index.ts +298 -0
  138. package/src/{index.tsx → index.ts} +137 -56
  139. package/src/init.ts +254 -187
  140. package/src/inspect.ts +170 -9
  141. package/src/jest.d.ts +4 -0
  142. package/src/kv/helpers.ts +7 -4
  143. package/src/kv/index.ts +15 -17
  144. package/src/logger.ts +36 -5
  145. package/src/metrics/metrics-config.ts +1 -1
  146. package/src/metrics/send-event.ts +4 -1
  147. package/src/miniflare-cli/assets.ts +66 -31
  148. package/src/miniflare-cli/index.ts +5 -8
  149. package/src/miniflare-cli/tsconfig.json +9 -0
  150. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  151. package/src/miniflare-cli/types.ts +11 -0
  152. package/src/module-collection.ts +92 -26
  153. package/src/mtls-certificate/cli.ts +155 -0
  154. package/src/pages/build.ts +423 -0
  155. package/src/pages/buildFunctions.ts +140 -0
  156. package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +7 -10
  157. package/src/pages/deployments.tsx +9 -9
  158. package/src/pages/{dev.tsx → dev.ts} +167 -139
  159. package/src/pages/errors.ts +1 -0
  160. package/src/pages/functions/buildPlugin.ts +61 -54
  161. package/src/pages/functions/buildWorker.ts +217 -33
  162. package/src/pages/functions/tsconfig.json +8 -0
  163. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  164. package/src/pages/{functions.tsx → functions.ts} +8 -4
  165. package/src/pages/{index.tsx → index.ts} +3 -3
  166. package/src/pages/projects.tsx +12 -22
  167. package/src/pages/publish.tsx +43 -227
  168. package/src/pages/types.ts +5 -0
  169. package/src/pages/upload.tsx +57 -14
  170. package/src/pages/utils.ts +1 -1
  171. package/src/parse.ts +23 -1
  172. package/src/paths.ts +1 -1
  173. package/src/publish/index.ts +20 -16
  174. package/src/publish/publish.ts +76 -46
  175. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  176. package/src/queues/cli/commands/consumer/add.ts +24 -24
  177. package/src/queues/cli/commands/consumer/index.ts +3 -6
  178. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  179. package/src/queues/cli/commands/create.ts +8 -8
  180. package/src/queues/cli/commands/delete.ts +8 -8
  181. package/src/queues/cli/commands/index.ts +3 -4
  182. package/src/queues/cli/commands/list.ts +8 -8
  183. package/src/queues/client.ts +1 -0
  184. package/src/r2/helpers.ts +1 -0
  185. package/src/r2/index.ts +28 -28
  186. package/src/secret/index.ts +15 -16
  187. package/src/{sites.tsx → sites.ts} +165 -53
  188. package/src/tail/createTail.ts +37 -1
  189. package/src/tail/filters.ts +1 -1
  190. package/src/tail/index.ts +8 -11
  191. package/src/tail/printing.ts +25 -0
  192. package/src/traverse-module-graph.ts +54 -0
  193. package/src/tsconfig-sanity.ts +16 -0
  194. package/src/type-generation.ts +11 -3
  195. package/src/user/access.ts +0 -1
  196. package/src/user/auth-variables.ts +113 -0
  197. package/src/user/choose-account.tsx +1 -31
  198. package/src/user/index.ts +0 -1
  199. package/src/user/{user.tsx → user.ts} +114 -77
  200. package/src/utils/render.ts +93 -0
  201. package/src/{whoami.tsx → whoami.ts} +37 -71
  202. package/src/worker.ts +35 -1
  203. package/src/yargs-types.ts +18 -5
  204. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  205. package/templates/__tests__/tsconfig.json +8 -0
  206. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  207. package/templates/checked-fetch.js +9 -3
  208. package/templates/d1-beta-facade.js +42 -3
  209. package/templates/facade.d.ts +14 -0
  210. package/templates/first-party-worker-module-facade.ts +4 -3
  211. package/templates/format-dev-errors.ts +8 -6
  212. package/templates/gitignore +1 -0
  213. package/templates/init-tests/test-jest-new-worker.js +3 -5
  214. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  215. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  216. package/templates/middleware/loader-modules.ts +2 -2
  217. package/templates/middleware/loader-sw.ts +6 -0
  218. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  219. package/templates/new-worker.ts +3 -0
  220. package/templates/pages-dev-pipeline.ts +4 -1
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +19 -10
  223. package/templates/serve-static-assets.ts +17 -14
  224. package/templates/service-bindings-module-facade.js +1 -0
  225. package/templates/tsconfig-sanity.ts +11 -0
  226. package/templates/tsconfig.init.json +105 -0
  227. package/templates/tsconfig.json +5 -103
  228. package/templates/tsconfig.tsbuildinfo +1 -0
  229. package/wrangler-dist/cli.d.ts +871 -73
  230. package/wrangler-dist/cli.js +80512 -90686
  231. package/wrangler-dist/wasm-sync.wasm +0 -0
  232. package/src/__tests__/api-devregistry.test.js +0 -56
  233. package/src/__tests__/d1.test.ts +0 -80
  234. package/src/__tests__/dialogs.test.tsx +0 -40
  235. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  236. package/src/__tests__/pages.test.ts +0 -2442
  237. package/src/dialogs.tsx +0 -168
  238. package/src/environment-variables.ts +0 -50
  239. package/src/pages/build.tsx +0 -270
  240. package/src/user/env-vars.ts +0 -46
  241. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  242. /package/src/d1/migrations/{index.tsx → index.ts} +0 -0
  243. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  244. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -358,6 +358,26 @@ function normalizeAndValidateMainField(
358
358
  }
359
359
  }
360
360
 
361
+ /**
362
+ * Validate the `base_dir` field and return the normalized values.
363
+ */
364
+ function normalizeAndValidateBaseDirField(
365
+ configPath: string | undefined,
366
+ rawDir: string | undefined
367
+ ): string | undefined {
368
+ const configDir = path.dirname(configPath ?? "wrangler.toml");
369
+ if (rawDir !== undefined) {
370
+ if (typeof rawDir === "string") {
371
+ const directory = path.resolve(configDir);
372
+ return path.resolve(directory, rawDir);
373
+ } else {
374
+ return rawDir;
375
+ }
376
+ } else {
377
+ return;
378
+ }
379
+ }
380
+
361
381
  /**
362
382
  * Validate the `dev` configuration and return the normalized values.
363
383
  */
@@ -741,7 +761,7 @@ function isValidRouteValue(item: unknown): boolean {
741
761
 
742
762
  /**
743
763
  * If account_id has been passed as an empty string, normalise it to undefined.
744
- * This is to workaround older wrangler1-era templates that have account_id = '',
764
+ * This is to workaround older Wrangler v1-era templates that have account_id = '',
745
765
  * which isn't a valid value anyway
746
766
  */
747
767
  function mutateEmptyStringAccountIDValue(
@@ -760,7 +780,7 @@ function mutateEmptyStringAccountIDValue(
760
780
 
761
781
  /**
762
782
  * Normalize empty string to `undefined` by mutating rawEnv.route value.
763
- * As part of backward compatibility with Wrangler1 converting empty string to `undefined`
783
+ * As part of backward compatibility with Wrangler v1 converting empty string to `undefined`
764
784
  */
765
785
  function mutateEmptyStringRouteValue(
766
786
  diagnostics: Diagnostics,
@@ -853,6 +873,32 @@ function validateRoutes(
853
873
  );
854
874
  }
855
875
 
876
+ function normalizeAndValidatePlacement(
877
+ diagnostics: Diagnostics,
878
+ topLevelEnv: Environment | undefined,
879
+ rawEnv: RawEnvironment
880
+ ): Config["placement"] {
881
+ if (rawEnv.placement) {
882
+ validateRequiredProperty(
883
+ diagnostics,
884
+ "placement",
885
+ "mode",
886
+ rawEnv.placement.mode,
887
+ "string",
888
+ ["off", "smart"]
889
+ );
890
+ }
891
+
892
+ return inheritable(
893
+ diagnostics,
894
+ topLevelEnv,
895
+ rawEnv,
896
+ "placement",
897
+ () => true,
898
+ undefined
899
+ );
900
+ }
901
+
856
902
  /**
857
903
  * Validate top-level environment configuration and return the normalized values.
858
904
  */
@@ -909,7 +955,6 @@ function normalizeAndValidateEnvironment(
909
955
 
910
956
  experimental(diagnostics, rawEnv, "unsafe");
911
957
  experimental(diagnostics, rawEnv, "services");
912
- experimental(diagnostics, rawEnv, "dispatch_namespaces");
913
958
 
914
959
  const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
915
960
 
@@ -1012,6 +1057,17 @@ function normalizeAndValidateEnvironment(
1012
1057
  ),
1013
1058
  deprecatedUpload
1014
1059
  ),
1060
+ base_dir: normalizeAndValidateBaseDirField(
1061
+ configPath,
1062
+ inheritable(
1063
+ diagnostics,
1064
+ topLevelEnv,
1065
+ rawEnv,
1066
+ "base_dir",
1067
+ isString,
1068
+ undefined
1069
+ )
1070
+ ),
1015
1071
  route,
1016
1072
  routes,
1017
1073
  triggers: inheritable(
@@ -1030,6 +1086,7 @@ function normalizeAndValidateEnvironment(
1030
1086
  isOneOf("bundled", "unbound"),
1031
1087
  undefined
1032
1088
  ),
1089
+ placement: normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv),
1033
1090
  build,
1034
1091
  workers_dev,
1035
1092
  // Not inherited fields
@@ -1075,6 +1132,16 @@ function normalizeAndValidateEnvironment(
1075
1132
  validateBindingArray(envName, validateKVBinding),
1076
1133
  []
1077
1134
  ),
1135
+ send_email: notInheritable(
1136
+ diagnostics,
1137
+ topLevelEnv,
1138
+ rawConfig,
1139
+ rawEnv,
1140
+ envName,
1141
+ "send_email",
1142
+ validateBindingArray(envName, validateSendEmailBinding),
1143
+ []
1144
+ ),
1078
1145
  queues: notInheritable(
1079
1146
  diagnostics,
1080
1147
  topLevelEnv,
@@ -1115,6 +1182,16 @@ function normalizeAndValidateEnvironment(
1115
1182
  validateBindingArray(envName, validateServiceBinding),
1116
1183
  []
1117
1184
  ),
1185
+ analytics_engine_datasets: notInheritable(
1186
+ diagnostics,
1187
+ topLevelEnv,
1188
+ rawConfig,
1189
+ rawEnv,
1190
+ envName,
1191
+ "analytics_engine_datasets",
1192
+ validateBindingArray(envName, validateAnalyticsEngineBinding),
1193
+ []
1194
+ ),
1118
1195
  dispatch_namespaces: notInheritable(
1119
1196
  diagnostics,
1120
1197
  topLevelEnv,
@@ -1125,6 +1202,16 @@ function normalizeAndValidateEnvironment(
1125
1202
  validateBindingArray(envName, validateWorkerNamespaceBinding),
1126
1203
  []
1127
1204
  ),
1205
+ mtls_certificates: notInheritable(
1206
+ diagnostics,
1207
+ topLevelEnv,
1208
+ rawConfig,
1209
+ rawEnv,
1210
+ envName,
1211
+ "mtls_certificates",
1212
+ validateBindingArray(envName, validateMTlsCertificateBinding),
1213
+ []
1214
+ ),
1128
1215
  logfwdr: inheritable(
1129
1216
  diagnostics,
1130
1217
  topLevelEnv,
@@ -1143,10 +1230,8 @@ function normalizeAndValidateEnvironment(
1143
1230
  rawEnv,
1144
1231
  envName,
1145
1232
  "unsafe",
1146
- validateBindingsProperty(envName, validateUnsafeBinding),
1147
- {
1148
- bindings: [],
1149
- }
1233
+ validateUnsafeSettings(envName),
1234
+ {}
1150
1235
  ),
1151
1236
  zone_id: rawEnv.zone_id,
1152
1237
  no_bundle: inheritable(
@@ -1476,6 +1561,62 @@ const validateBindingsProperty =
1476
1561
  return isValid;
1477
1562
  };
1478
1563
 
1564
+ const validateUnsafeSettings =
1565
+ (envName: string): ValidatorFn =>
1566
+ (diagnostics, field, value, config) => {
1567
+ const fieldPath =
1568
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
1569
+
1570
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1571
+ diagnostics.errors.push(
1572
+ `The field "${fieldPath}" should be an object but got ${JSON.stringify(
1573
+ value
1574
+ )}.`
1575
+ );
1576
+ return false;
1577
+ }
1578
+
1579
+ // At least one of bindings and metadata must exist
1580
+ if (!hasProperty(value, "bindings") && !hasProperty(value, "metadata")) {
1581
+ diagnostics.errors.push(
1582
+ `The field "${fieldPath}" should contain at least one of "bindings" or "metadata" properties but got ${JSON.stringify(
1583
+ value
1584
+ )}.`
1585
+ );
1586
+ return false;
1587
+ }
1588
+
1589
+ // unsafe.bindings
1590
+ if (hasProperty(value, "bindings") && value.bindings !== undefined) {
1591
+ const validateBindingsFn = validateBindingsProperty(
1592
+ envName,
1593
+ validateUnsafeBinding
1594
+ );
1595
+ const valid = validateBindingsFn(diagnostics, field, value, config);
1596
+ if (!valid) {
1597
+ return false;
1598
+ }
1599
+ }
1600
+
1601
+ // unsafe.metadata
1602
+ if (
1603
+ hasProperty(value, "metadata") &&
1604
+ value.metadata !== undefined &&
1605
+ (typeof value.metadata !== "object" ||
1606
+ value.metadata === null ||
1607
+ Array.isArray(value.metadata))
1608
+ ) {
1609
+ diagnostics.errors.push(
1610
+ `The field "${fieldPath}.metadata" should be an object but got ${JSON.stringify(
1611
+ value.metadata
1612
+ )}.`
1613
+ );
1614
+ return false;
1615
+ }
1616
+
1617
+ return true;
1618
+ };
1619
+
1479
1620
  /**
1480
1621
  * Check that the given field is a valid "durable_object" binding object.
1481
1622
  */
@@ -1581,6 +1722,7 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
1581
1722
  "r2_bucket",
1582
1723
  "service",
1583
1724
  "logfwdr",
1725
+ "mtls_certificate",
1584
1726
  ];
1585
1727
 
1586
1728
  if (safeBindings.includes(value.type)) {
@@ -1691,6 +1833,53 @@ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
1691
1833
  return isValid;
1692
1834
  };
1693
1835
 
1836
+ const validateSendEmailBinding: ValidatorFn = (diagnostics, field, value) => {
1837
+ if (typeof value !== "object" || value === null) {
1838
+ diagnostics.errors.push(
1839
+ `"send_email" bindings should be objects, but got ${JSON.stringify(
1840
+ value
1841
+ )}`
1842
+ );
1843
+ return false;
1844
+ }
1845
+ let isValid = true;
1846
+ // send email bindings must have a name.
1847
+ if (!isRequiredProperty(value, "name", "string")) {
1848
+ diagnostics.errors.push(
1849
+ `"${field}" bindings should have a string "name" field but got ${JSON.stringify(
1850
+ value
1851
+ )}.`
1852
+ );
1853
+ isValid = false;
1854
+ }
1855
+ if (!isOptionalProperty(value, "destination_address", "string")) {
1856
+ diagnostics.errors.push(
1857
+ `"${field}" bindings should, optionally, have a string "destination_address" field but got ${JSON.stringify(
1858
+ value
1859
+ )}.`
1860
+ );
1861
+ isValid = false;
1862
+ }
1863
+ if (!isOptionalProperty(value, "allowed_destination_addresses", "object")) {
1864
+ diagnostics.errors.push(
1865
+ `"${field}" bindings should, optionally, have a []string "allowed_destination_addresses" field but got ${JSON.stringify(
1866
+ value
1867
+ )}.`
1868
+ );
1869
+ isValid = false;
1870
+ }
1871
+ if (
1872
+ "destination_address" in value &&
1873
+ "allowed_destination_addresses" in value
1874
+ ) {
1875
+ diagnostics.errors.push(
1876
+ `"${field}" bindings should have either a "destination_address" or "allowed_destination_addresses" field, but not both.`
1877
+ );
1878
+ isValid = false;
1879
+ }
1880
+ return isValid;
1881
+ };
1882
+
1694
1883
  const validateQueueBinding: ValidatorFn = (diagnostics, field, value) => {
1695
1884
  if (typeof value !== "object" || value === null) {
1696
1885
  diagnostics.errors.push(
@@ -1814,7 +2003,7 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
1814
2003
  }
1815
2004
  if (isValid && !process.env.NO_D1_WARNING) {
1816
2005
  diagnostics.warnings.push(
1817
- `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`
2006
+ "D1 Bindings are currently in alpha to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_D1_WARNING=true to hide this message\n\nFor example: `export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>`"
1818
2007
  );
1819
2008
  }
1820
2009
  return isValid;
@@ -1834,6 +2023,7 @@ const validateBindingsHaveUniqueNames = (
1834
2023
  durable_objects,
1835
2024
  kv_namespaces,
1836
2025
  r2_buckets,
2026
+ analytics_engine_datasets,
1837
2027
  text_blobs,
1838
2028
  unsafe,
1839
2029
  vars,
@@ -1848,6 +2038,7 @@ const validateBindingsHaveUniqueNames = (
1848
2038
  "Durable Object": getBindingNames(durable_objects),
1849
2039
  "KV Namespace": getBindingNames(kv_namespaces),
1850
2040
  "R2 Bucket": getBindingNames(r2_buckets),
2041
+ "Analytics Engine Dataset": getBindingNames(analytics_engine_datasets),
1851
2042
  "Text Blob": getBindingNames(text_blobs),
1852
2043
  Unsafe: getBindingNames(unsafe),
1853
2044
  "Environment Variable": getBindingNames(vars),
@@ -1956,6 +2147,43 @@ const validateServiceBinding: ValidatorFn = (diagnostics, field, value) => {
1956
2147
  return isValid;
1957
2148
  };
1958
2149
 
2150
+ const validateAnalyticsEngineBinding: ValidatorFn = (
2151
+ diagnostics,
2152
+ field,
2153
+ value
2154
+ ) => {
2155
+ if (typeof value !== "object" || value === null) {
2156
+ diagnostics.errors.push(
2157
+ `"analytics_engine" bindings should be objects, but got ${JSON.stringify(
2158
+ value
2159
+ )}`
2160
+ );
2161
+ return false;
2162
+ }
2163
+ let isValid = true;
2164
+ // Service bindings must have a binding and optional dataset.
2165
+ if (!isRequiredProperty(value, "binding", "string")) {
2166
+ diagnostics.errors.push(
2167
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
2168
+ value
2169
+ )}.`
2170
+ );
2171
+ isValid = false;
2172
+ }
2173
+ if (
2174
+ !isOptionalProperty(value, "dataset", "string") ||
2175
+ (value as { dataset: string }).dataset?.length === 0
2176
+ ) {
2177
+ diagnostics.errors.push(
2178
+ `"${field}" bindings should, optionally, have a string "dataset" field but got ${JSON.stringify(
2179
+ value
2180
+ )}.`
2181
+ );
2182
+ isValid = false;
2183
+ }
2184
+ return isValid;
2185
+ };
2186
+
1959
2187
  const validateWorkerNamespaceBinding: ValidatorFn = (
1960
2188
  diagnostics,
1961
2189
  field,
@@ -1988,6 +2216,42 @@ const validateWorkerNamespaceBinding: ValidatorFn = (
1988
2216
  return isValid;
1989
2217
  };
1990
2218
 
2219
+ const validateMTlsCertificateBinding: ValidatorFn = (
2220
+ diagnostics,
2221
+ field,
2222
+ value
2223
+ ) => {
2224
+ if (typeof value !== "object" || value === null) {
2225
+ diagnostics.errors.push(
2226
+ `"mtls_certificates" bindings should be objects, but got ${JSON.stringify(
2227
+ value
2228
+ )}`
2229
+ );
2230
+ return false;
2231
+ }
2232
+ let isValid = true;
2233
+ if (!isRequiredProperty(value, "binding", "string")) {
2234
+ diagnostics.errors.push(
2235
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
2236
+ value
2237
+ )}.`
2238
+ );
2239
+ isValid = false;
2240
+ }
2241
+ if (
2242
+ !isRequiredProperty(value, "certificate_id", "string") ||
2243
+ (value as { certificate_id: string }).certificate_id.length === 0
2244
+ ) {
2245
+ diagnostics.errors.push(
2246
+ `"${field}" bindings should have a string "certificate_id" field but got ${JSON.stringify(
2247
+ value
2248
+ )}.`
2249
+ );
2250
+ isValid = false;
2251
+ }
2252
+ return isValid;
2253
+ };
2254
+
1991
2255
  function validateQueues(envName: string): ValidatorFn {
1992
2256
  return (diagnostics, field, value, config) => {
1993
2257
  const fieldPath =
@@ -2066,6 +2330,7 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
2066
2330
  "max_batch_timeout",
2067
2331
  "max_retries",
2068
2332
  "dead_letter_queue",
2333
+ "max_concurrency",
2069
2334
  ])
2070
2335
  ) {
2071
2336
  isValid = false;
@@ -2081,12 +2346,13 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
2081
2346
 
2082
2347
  const options: {
2083
2348
  key: string;
2084
- type: "number" | "string";
2349
+ type: "number" | "string" | "boolean";
2085
2350
  }[] = [
2086
2351
  { key: "max_batch_size", type: "number" },
2087
2352
  { key: "max_batch_timeout", type: "number" },
2088
2353
  { key: "max_retries", type: "number" },
2089
2354
  { key: "dead_letter_queue", type: "string" },
2355
+ { key: "max_concurrency", type: "number" },
2090
2356
  ];
2091
2357
  for (const optionalOpt of options) {
2092
2358
  if (!isOptionalProperty(value, optionalOpt.key, optionalOpt.type)) {
@@ -0,0 +1,51 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { logger } from "../logger";
4
+ import { requireAuth } from "../user";
5
+ import { takeName } from "./options";
6
+ import { constellationBetaWarning } from "./utils";
7
+ import type {
8
+ CommonYargsArgv,
9
+ StrictYargsOptionsToInterface,
10
+ } from "../yargs-types";
11
+ import type { Project } from "./types";
12
+
13
+ export function options(yargs: CommonYargsArgv) {
14
+ return takeName(yargs)
15
+ .positional("runtime", {
16
+ describe: "The name of the runtime to use",
17
+ type: "string",
18
+ demandOption: true,
19
+ })
20
+ .epilogue(constellationBetaWarning);
21
+ }
22
+
23
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
24
+ export const handler = withConfig<HandlerOptions>(
25
+ async ({ name, runtime, config }): Promise<void> => {
26
+ const accountId = await requireAuth(config);
27
+
28
+ logger.log(constellationBetaWarning);
29
+
30
+ let proj: Project;
31
+ try {
32
+ proj = await fetchResult(`/accounts/${accountId}/constellation/project`, {
33
+ method: "POST",
34
+ headers: {
35
+ "Content-Type": "application/json",
36
+ },
37
+ body: JSON.stringify({
38
+ name,
39
+ runtime,
40
+ }),
41
+ });
42
+ } catch (e) {
43
+ if ((e as { code: number }).code === 7409) {
44
+ throw new Error("A project with that name already exists");
45
+ }
46
+ throw e;
47
+ }
48
+
49
+ logger.log(`✅ Successfully created Project "${proj.name}"!`);
50
+ }
51
+ );
@@ -0,0 +1,51 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { logger } from "../logger";
5
+ import { requireAuth } from "../user";
6
+ import { takeName } from "./options";
7
+ import { constellationBetaWarning, getProjectByName } from "./utils";
8
+ import type {
9
+ CommonYargsArgv,
10
+ StrictYargsOptionsToInterface,
11
+ } from "../yargs-types";
12
+
13
+ export function options(yargs: CommonYargsArgv) {
14
+ return takeName(yargs)
15
+ .option("force", {
16
+ describe: "Skip confirmation",
17
+ type: "boolean",
18
+ alias: "f",
19
+ default: false,
20
+ })
21
+ .epilogue(constellationBetaWarning);
22
+ }
23
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
24
+ export const handler = withConfig<HandlerOptions>(
25
+ async ({ name, force, config }): Promise<void> => {
26
+ const accountId = await requireAuth(config);
27
+ logger.log(constellationBetaWarning);
28
+
29
+ const proj = await getProjectByName(config, accountId, name);
30
+
31
+ logger.log(`About to delete Project '${name}' (${proj.id}).`);
32
+ if (!force) {
33
+ const response = await confirm(`Ok to proceed?`);
34
+ if (!response) {
35
+ logger.log(`Not deleting.`);
36
+ return;
37
+ }
38
+
39
+ logger.log("Deleting...");
40
+ }
41
+
42
+ await fetchResult(
43
+ `/accounts/${accountId}/constellation/project/${proj.id}`,
44
+ {
45
+ method: "DELETE",
46
+ }
47
+ );
48
+
49
+ logger.log(`Deleted '${name}' successfully.`);
50
+ }
51
+ );
@@ -0,0 +1,68 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { logger } from "../logger";
5
+ import { requireAuth } from "../user";
6
+ import { takeName } from "./options";
7
+ import {
8
+ constellationBetaWarning,
9
+ getProjectByName,
10
+ getProjectModelByName,
11
+ } from "./utils";
12
+ import type {
13
+ CommonYargsArgv,
14
+ StrictYargsOptionsToInterface,
15
+ } from "../yargs-types";
16
+ import type { Project, Model } from "./types";
17
+
18
+ export function options(yargs: CommonYargsArgv) {
19
+ return takeName(yargs)
20
+ .positional("modelName", {
21
+ describe: "The name of the uploaded model",
22
+ type: "string",
23
+ demandOption: true,
24
+ })
25
+ .option("force", {
26
+ describe: "Skip confirmation",
27
+ type: "boolean",
28
+ alias: "f",
29
+ default: false,
30
+ })
31
+ .epilogue(constellationBetaWarning);
32
+ }
33
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
34
+ export const handler = withConfig<HandlerOptions>(
35
+ async ({ name, modelName, force, config }): Promise<void> => {
36
+ const accountId = await requireAuth(config);
37
+ logger.log(constellationBetaWarning);
38
+
39
+ const proj: Project = await getProjectByName(config, accountId, name);
40
+
41
+ const model: Model = await getProjectModelByName(
42
+ config,
43
+ accountId,
44
+ proj,
45
+ modelName
46
+ );
47
+
48
+ logger.log(`About to delete Model '${modelName}' (${model.id}).`);
49
+ if (!force) {
50
+ const response = await confirm(`Ok to proceed?`);
51
+ if (!response) {
52
+ logger.log(`Not deleting.`);
53
+ return;
54
+ }
55
+
56
+ logger.log("Deleting...");
57
+ }
58
+
59
+ await fetchResult(
60
+ `/accounts/${accountId}/constellation/project/${proj.id}/model/${model.id}`,
61
+ {
62
+ method: "DELETE",
63
+ }
64
+ );
65
+
66
+ logger.log(`Deleted '${modelName}' successfully.`);
67
+ }
68
+ );
@@ -0,0 +1,75 @@
1
+ import * as CreateProject from "./createProject";
2
+ import * as DeleteProject from "./deleteProject";
3
+ import * as DeleteProjectModel from "./deleteProjectModel";
4
+ import * as ListCatalog from "./listCatalog";
5
+ import * as ListModel from "./listModel";
6
+ import * as ListProject from "./listProject";
7
+ import * as ListRuntime from "./listRuntime";
8
+ import * as UploadModel from "./uploadModel";
9
+ import type { CommonYargsArgv } from "../yargs-types";
10
+
11
+ export function constellation(yargs: CommonYargsArgv) {
12
+ return yargs
13
+ .command("project", "Manage your projects", (constProjYargs) => {
14
+ return constProjYargs
15
+ .command(
16
+ "list",
17
+ "List your projects",
18
+ ListProject.options,
19
+ ListProject.handler
20
+ )
21
+ .command(
22
+ "create <name> <runtime>",
23
+ "Create project",
24
+ CreateProject.options,
25
+ CreateProject.handler
26
+ )
27
+ .command(
28
+ "delete <name>",
29
+ "Delete project",
30
+ DeleteProject.options,
31
+ DeleteProject.handler
32
+ );
33
+ })
34
+ .command("model", "Manage your models", (constModelYargs) => {
35
+ return constModelYargs
36
+ .command(
37
+ "upload <name> <modelName> <modelFile>",
38
+ "Upload a model for an existing project",
39
+ UploadModel.options,
40
+ UploadModel.handler
41
+ )
42
+ .command(
43
+ "list <name>",
44
+ "List models of a project",
45
+ ListModel.options,
46
+ ListModel.handler
47
+ )
48
+ .command(
49
+ "delete <name> <modelName>",
50
+ "Delete a model of a project",
51
+ DeleteProjectModel.options,
52
+ DeleteProjectModel.handler
53
+ );
54
+ })
55
+ .command(
56
+ "catalog",
57
+ "Check the curated model catalog",
58
+ (constCatalogYargs) => {
59
+ return constCatalogYargs.command(
60
+ "list",
61
+ "List catalog models",
62
+ ListCatalog.options,
63
+ ListCatalog.handler
64
+ );
65
+ }
66
+ )
67
+ .command("runtime", "Check the suported runtimes", (constRuntimeYargs) => {
68
+ return constRuntimeYargs.command(
69
+ "list",
70
+ "List suported runtimes",
71
+ ListRuntime.options,
72
+ ListRuntime.handler
73
+ );
74
+ });
75
+ }
@@ -0,0 +1,35 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listCatalogEntries } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const entries = await listCatalogEntries(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(entries, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(
26
+ entries.map((entry) => ({
27
+ project_id: entry.project.id,
28
+ project_name: entry.project.name,
29
+ project_runtime: entry.project.runtime,
30
+ models: entry.models.map((model) => model.name).join(","),
31
+ }))
32
+ );
33
+ }
34
+ }
35
+ );