wrangler 0.0.0-e9ab55a → 0.0.0-ea7ee45

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 (197) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +33 -14
  3. package/bin/wrangler.js +123 -25
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4893 -0
  6. package/package.json +156 -125
  7. package/src/__tests__/config-cache.test.ts +36 -0
  8. package/src/__tests__/configuration.test.ts +3829 -0
  9. package/src/__tests__/dev.test.tsx +1155 -63
  10. package/src/__tests__/guess-worker-format.test.ts +85 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/helpers/mock-cfetch.ts +211 -0
  17. package/src/__tests__/helpers/mock-console.ts +97 -0
  18. package/src/__tests__/helpers/mock-dialogs.ts +153 -0
  19. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  20. package/src/__tests__/helpers/mock-istty.ts +74 -0
  21. package/src/__tests__/helpers/mock-kv.ts +33 -0
  22. package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
  23. package/src/__tests__/helpers/mock-process.ts +39 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +108 -0
  25. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +39 -0
  27. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  28. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  29. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  30. package/src/__tests__/https-options.test.ts +130 -0
  31. package/src/__tests__/index.test.ts +259 -284
  32. package/src/__tests__/init.test.ts +1992 -0
  33. package/src/__tests__/jest.setup.ts +95 -10
  34. package/src/__tests__/kv.test.ts +1402 -909
  35. package/src/__tests__/logger.test.ts +141 -0
  36. package/src/__tests__/package-manager.test.ts +353 -0
  37. package/src/__tests__/pages.test.ts +1254 -0
  38. package/src/__tests__/parse.test.ts +330 -0
  39. package/src/__tests__/publish.test.ts +6504 -93
  40. package/src/__tests__/pubsub.test.ts +276 -0
  41. package/src/__tests__/r2.test.ts +233 -0
  42. package/src/__tests__/route.test.ts +45 -0
  43. package/src/__tests__/secret.test.ts +486 -0
  44. package/src/__tests__/tail.test.ts +690 -0
  45. package/src/__tests__/user.test.ts +143 -0
  46. package/src/__tests__/whoami.test.tsx +220 -0
  47. package/src/__tests__/worker-namespace.test.ts +327 -0
  48. package/src/abort.d.ts +3 -0
  49. package/src/api/dev.ts +39 -0
  50. package/src/api/index.ts +1 -0
  51. package/src/bundle-reporter.tsx +29 -0
  52. package/src/bundle.ts +212 -0
  53. package/src/cfetch/index.ts +88 -69
  54. package/src/cfetch/internal.ts +124 -44
  55. package/src/cli.ts +24 -6
  56. package/src/config/README.md +107 -0
  57. package/src/config/config.ts +243 -0
  58. package/src/config/diagnostics.ts +80 -0
  59. package/src/config/environment.ts +430 -0
  60. package/src/config/index.ts +225 -0
  61. package/src/config/validation-helpers.ts +584 -0
  62. package/src/config/validation.ts +1693 -0
  63. package/src/config-cache.ts +44 -0
  64. package/src/create-worker-preview.ts +255 -0
  65. package/src/create-worker-upload-form.ts +254 -0
  66. package/src/dev/dev-vars.ts +36 -0
  67. package/src/dev/dev.tsx +417 -0
  68. package/src/dev/local.tsx +350 -0
  69. package/src/dev/remote.tsx +367 -0
  70. package/src/dev/use-esbuild.ts +150 -0
  71. package/src/dev.tsx +515 -773
  72. package/src/dialogs.tsx +117 -59
  73. package/src/durable.ts +102 -0
  74. package/src/entry.ts +328 -0
  75. package/src/environment-variables.ts +35 -0
  76. package/src/errors.ts +11 -0
  77. package/src/generate.ts +33 -0
  78. package/src/git-client.ts +42 -0
  79. package/src/https-options.ts +123 -0
  80. package/src/index.tsx +1844 -1901
  81. package/src/init.ts +549 -0
  82. package/src/inspect.ts +615 -496
  83. package/src/intl-polyfill.d.ts +139 -0
  84. package/src/kv.ts +408 -0
  85. package/src/logger.ts +73 -0
  86. package/src/miniflare-cli/README.md +30 -0
  87. package/src/miniflare-cli/enum-keys.ts +17 -0
  88. package/src/miniflare-cli/index.ts +52 -0
  89. package/src/miniflare-cli/request-context.ts +40 -0
  90. package/src/module-collection.ts +247 -53
  91. package/src/open-in-browser.ts +17 -0
  92. package/src/package-manager.ts +174 -0
  93. package/src/pages/build.tsx +202 -0
  94. package/src/pages/constants.ts +7 -0
  95. package/src/pages/deployments.tsx +101 -0
  96. package/src/pages/dev.tsx +964 -0
  97. package/src/pages/functions/buildPlugin.ts +105 -0
  98. package/src/pages/functions/buildWorker.ts +151 -0
  99. package/src/pages/functions/filepath-routing.test.ts +234 -0
  100. package/src/pages/functions/filepath-routing.ts +189 -0
  101. package/src/pages/functions/identifiers.ts +78 -0
  102. package/src/pages/functions/routes.ts +151 -0
  103. package/src/pages/index.tsx +84 -0
  104. package/src/pages/projects.tsx +157 -0
  105. package/src/pages/publish.tsx +335 -0
  106. package/src/pages/types.ts +40 -0
  107. package/src/pages/upload.tsx +384 -0
  108. package/src/pages/utils.ts +12 -0
  109. package/src/parse.ts +286 -0
  110. package/src/paths.ts +26 -0
  111. package/src/preview.ts +31 -0
  112. package/src/proxy.ts +428 -254
  113. package/src/publish.ts +750 -366
  114. package/src/pubsub/index.ts +286 -0
  115. package/src/pubsub/pubsub-commands.tsx +594 -0
  116. package/src/r2.ts +50 -0
  117. package/src/selfsigned.d.ts +29 -0
  118. package/src/sites.tsx +357 -103
  119. package/src/tail/filters.ts +279 -0
  120. package/src/tail/index.ts +299 -0
  121. package/src/tail/printing.ts +67 -0
  122. package/src/update-check.ts +19 -0
  123. package/src/user/choose-account.tsx +60 -0
  124. package/src/user/env-vars.ts +46 -0
  125. package/src/user/generate-auth-url.ts +33 -0
  126. package/src/user/generate-random-state.ts +16 -0
  127. package/src/user/index.ts +3 -0
  128. package/src/user/user.tsx +1130 -0
  129. package/src/whoami.tsx +90 -0
  130. package/src/worker-namespace.ts +190 -0
  131. package/src/worker.ts +185 -0
  132. package/src/zones.ts +76 -0
  133. package/templates/checked-fetch.js +17 -0
  134. package/templates/gitignore +171 -0
  135. package/templates/new-worker-scheduled.js +17 -0
  136. package/templates/new-worker-scheduled.ts +32 -0
  137. package/templates/new-worker.js +15 -0
  138. package/templates/new-worker.ts +30 -0
  139. package/templates/no-op-worker.js +10 -0
  140. package/templates/pages-template-plugin.ts +155 -0
  141. package/templates/pages-template-worker.ts +161 -0
  142. package/templates/static-asset-facade.js +43 -0
  143. package/templates/tsconfig.json +105 -0
  144. package/wrangler-dist/cli.js +107117 -103435
  145. package/pages/functions/buildWorker.ts +0 -62
  146. package/pages/functions/filepath-routing.test.ts +0 -39
  147. package/pages/functions/filepath-routing.ts +0 -228
  148. package/pages/functions/identifiers.ts +0 -78
  149. package/pages/functions/routes.ts +0 -158
  150. package/pages/functions/template-worker.ts +0 -136
  151. package/src/__tests__/mock-cfetch.ts +0 -171
  152. package/src/__tests__/mock-dialogs.ts +0 -65
  153. package/src/__tests__/run-in-tmp.ts +0 -19
  154. package/src/__tests__/run-wrangler.ts +0 -32
  155. package/src/api/form_data.ts +0 -131
  156. package/src/api/preview.ts +0 -128
  157. package/src/api/worker.ts +0 -155
  158. package/src/config.ts +0 -646
  159. package/src/kv.tsx +0 -276
  160. package/src/pages.tsx +0 -1040
  161. package/src/tail.tsx +0 -73
  162. package/src/user.tsx +0 -1027
  163. package/static-asset-facade.js +0 -47
  164. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  165. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  166. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  167. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  168. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  169. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  170. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  171. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  172. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  173. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  174. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  175. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  176. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  177. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  178. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  179. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  180. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  181. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  182. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  183. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  184. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  185. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  186. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  187. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  188. package/vendor/wrangler-mime/LICENSE +0 -21
  189. package/vendor/wrangler-mime/Mime.js +0 -97
  190. package/vendor/wrangler-mime/README.md +0 -187
  191. package/vendor/wrangler-mime/cli.js +0 -46
  192. package/vendor/wrangler-mime/index.js +0 -4
  193. package/vendor/wrangler-mime/lite.js +0 -4
  194. package/vendor/wrangler-mime/package.json +0 -52
  195. package/vendor/wrangler-mime/types/other.js +0 -1
  196. package/vendor/wrangler-mime/types/standard.js +0 -1
  197. package/wrangler-dist/cli.js.map +0 -7
package/src/kv.tsx DELETED
@@ -1,276 +0,0 @@
1
- import { URLSearchParams } from "node:url";
2
- import type { Config } from "./config";
3
- import { fetchListResult, fetchResult } from "./cfetch";
4
-
5
- type KvArgs = {
6
- binding?: string;
7
- "namespace-id"?: string;
8
- env?: string;
9
- preview?: boolean;
10
- config?: Config;
11
- };
12
-
13
- /**
14
- * Create a new namespace under the given `accountId` with the given `title`.
15
- *
16
- * @returns the generated id of the created namespace.
17
- */
18
- export async function createNamespace(
19
- accountId: string,
20
- title: string
21
- ): Promise<string> {
22
- const response = await fetchResult<{ id: string }>(
23
- `/accounts/${accountId}/storage/kv/namespaces`,
24
- {
25
- method: "POST",
26
- headers: {
27
- "Content-Type": "application/json",
28
- },
29
- body: JSON.stringify({
30
- title,
31
- }),
32
- }
33
- );
34
-
35
- return response.id;
36
- }
37
-
38
- /**
39
- * The information about a namespace that is returned from `listNamespaces()`.
40
- */
41
- export interface KVNamespaceInfo {
42
- id: string;
43
- title: string;
44
- supports_url_encoding?: boolean;
45
- }
46
-
47
- /**
48
- * Fetch a list of all the namespaces under the given `accountId`.
49
- */
50
- export async function listNamespaces(
51
- accountId: string
52
- ): Promise<KVNamespaceInfo[]> {
53
- const pageSize = 100;
54
- let page = 1;
55
- const results: KVNamespaceInfo[] = [];
56
- while (results.length % pageSize === 0) {
57
- const json = await fetchResult<KVNamespaceInfo[]>(
58
- `/accounts/${accountId}/storage/kv/namespaces`,
59
- {},
60
- new URLSearchParams({
61
- per_page: pageSize.toString(),
62
- order: "title",
63
- direction: "asc",
64
- page: page.toString(),
65
- })
66
- );
67
- page++;
68
- results.push(...json);
69
- if (json.length < pageSize) {
70
- break;
71
- }
72
- }
73
- return results;
74
- }
75
-
76
- export interface NamespaceKeyInfo {
77
- name: string;
78
- expiration?: number;
79
- metadata?: { [key: string]: unknown };
80
- }
81
-
82
- export async function listNamespaceKeys(
83
- accountId: string,
84
- namespaceId: string,
85
- prefix = ""
86
- ) {
87
- return await fetchListResult<NamespaceKeyInfo>(
88
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`,
89
- {},
90
- new URLSearchParams({ prefix })
91
- );
92
- }
93
-
94
- export async function putKeyValue(
95
- accountId: string,
96
- namespaceId: string,
97
- key: string,
98
- value: string,
99
- args?: { expiration?: number; expiration_ttl?: number }
100
- ) {
101
- let searchParams: URLSearchParams | undefined;
102
- if (args) {
103
- searchParams = new URLSearchParams();
104
- if (args.expiration) {
105
- searchParams.set("expiration", `${args.expiration}`);
106
- }
107
- if (args.expiration_ttl) {
108
- searchParams.set("expiration_ttl", `${args.expiration_ttl}`);
109
- }
110
- }
111
- return await fetchResult(
112
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
113
- { method: "PUT", body: value },
114
- searchParams
115
- );
116
- }
117
-
118
- export async function putBulkKeyValue(
119
- accountId: string,
120
- namespaceId: string,
121
- keyvalueStr: string
122
- ) {
123
- return await fetchResult(
124
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
125
- {
126
- method: "PUT",
127
- body: keyvalueStr,
128
- headers: { "Content-Type": "application/json" },
129
- }
130
- );
131
- }
132
-
133
- export async function deleteBulkKeyValue(
134
- accountId: string,
135
- namespaceId: string,
136
- keyStr: string
137
- ) {
138
- return await fetchResult(
139
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
140
- {
141
- method: "DELETE",
142
- body: keyStr,
143
- headers: { "Content-Type": "application/json" },
144
- }
145
- );
146
- }
147
-
148
- export function getNamespaceId({
149
- preview,
150
- binding,
151
- config,
152
- "namespace-id": namespaceId,
153
- env,
154
- }: KvArgs): string {
155
- // nice
156
- if (namespaceId) {
157
- return namespaceId;
158
- }
159
-
160
- // begin pre-flight checks
161
-
162
- // `--binding` is only valid if there's a wrangler configuration file.
163
- if (binding && !config) {
164
- throw new Error("--binding specified, but no config file was found.");
165
- }
166
-
167
- // there's no config. abort here
168
- if (!config) {
169
- throw new Error(
170
- "Failed to find a config file.\n" +
171
- "Either use --namespace-id to upload directly or create a configuration file with a binding."
172
- );
173
- }
174
-
175
- // they want to use an environment, actually
176
- if (env) {
177
- if (!config.env || !config.env[env]) {
178
- throw new Error(
179
- `Failed to find environment "${env}" in configuration file!`
180
- );
181
- }
182
-
183
- // TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
184
- return getNamespaceId({
185
- binding,
186
- "namespace-id": namespaceId,
187
- env: undefined,
188
- preview,
189
- config: {
190
- env: undefined,
191
- build: undefined,
192
- name: undefined,
193
- account_id: undefined,
194
- ...config.env[env],
195
- },
196
- });
197
- }
198
-
199
- // there's no KV namespaces
200
- if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
201
- throw new Error(
202
- "No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
203
- );
204
- }
205
-
206
- const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
207
-
208
- // we couldn't find a namespace with that binding
209
- if (!namespace) {
210
- throw new Error(
211
- `A namespace with binding name "${binding}" was not found in the configured "kv_namespaces".`
212
- );
213
- }
214
-
215
- // end pre-flight checks
216
-
217
- // we're in preview mode, `--preview true` or `--preview` was passed
218
- if (preview && namespace.preview_id) {
219
- namespaceId = namespace.preview_id;
220
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
221
- return namespaceId;
222
- } else if (preview) {
223
- throw new Error(
224
- `No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
225
- );
226
- }
227
-
228
- // either `--preview false`, or preview wasn't passed
229
- // TODO: should we care? or should we just treat false and undefined the same
230
- const previewIsDefined = typeof preview !== "undefined";
231
-
232
- // --preview false was passed
233
- if (previewIsDefined && namespace.id) {
234
- namespaceId = namespace.id;
235
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
236
- return namespaceId;
237
- } else if (previewIsDefined) {
238
- throw new Error(
239
- `No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
240
- );
241
- }
242
-
243
- // `--preview` wasn't passed
244
- const bindingHasOnlyOneId =
245
- (namespace.id && !namespace.preview_id) ||
246
- (!namespace.id && namespace.preview_id);
247
- if (bindingHasOnlyOneId) {
248
- namespaceId = namespace.id || namespace.preview_id;
249
- } else {
250
- throw new Error(
251
- `${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
252
- );
253
- }
254
-
255
- // shouldn't happen. we should be able to prove this with strong typing.
256
- // TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
257
- if (!namespaceId) {
258
- throw Error(
259
- "Something went wrong trying to determine which namespace to upload to.\n" +
260
- "Please create a github issue with the command you just ran along with your wrangler configuration."
261
- );
262
- }
263
-
264
- return namespaceId;
265
- }
266
-
267
- /**
268
- * KV namespace binding names must be valid JS identifiers.
269
- */
270
- export function isValidNamespaceBinding(
271
- binding: string | undefined
272
- ): binding is string {
273
- return (
274
- typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding)
275
- );
276
- }