wrangler 0.0.0-e1c2f5b9 → 0.0.0-e1d2fd668

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 (292) hide show
  1. package/README.md +17 -15
  2. package/bin/wrangler.js +14 -103
  3. package/config-schema.json +3126 -0
  4. package/package.json +197 -194
  5. package/templates/__tests__/tsconfig.json +1 -1
  6. package/templates/checked-fetch.js +19 -6
  7. package/templates/facade.d.ts +7 -2
  8. package/templates/gitignore +2 -3
  9. package/templates/init-tests/test-vitest-new-worker.js +1 -1
  10. package/templates/init-tests/test-vitest-new-worker.ts +2 -2
  11. package/templates/middleware/common.ts +9 -4
  12. package/templates/middleware/loader-modules.ts +94 -42
  13. package/templates/middleware/loader-sw.ts +6 -10
  14. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  15. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  16. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  17. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  18. package/templates/middleware/middleware-scheduled.ts +15 -1
  19. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  20. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  21. package/templates/modules-watch-stub.js +4 -0
  22. package/templates/new-worker-scheduled.ts +1 -1
  23. package/templates/new-worker.ts +4 -1
  24. package/templates/pages-dev-pipeline.ts +2 -1
  25. package/templates/pages-dev-util.ts +4 -1
  26. package/templates/pages-shim.ts +0 -3
  27. package/templates/pages-template-plugin.ts +32 -13
  28. package/templates/pages-template-worker.ts +12 -3
  29. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  30. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  31. package/templates/tsconfig.init.json +5 -89
  32. package/templates/tsconfig.json +1 -1
  33. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  34. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  35. package/wrangler-dist/ProxyWorker.js +241 -0
  36. package/wrangler-dist/ProxyWorker.js.map +6 -0
  37. package/wrangler-dist/cli.d.ts +26117 -517
  38. package/wrangler-dist/cli.js +173803 -121437
  39. package/wrangler-dist/wasm-sync.wasm +0 -0
  40. package/Cloudflare_CA.pem +0 -18
  41. package/import_meta_url.js +0 -3
  42. package/miniflare-config-stubs/.env.empty +0 -0
  43. package/miniflare-config-stubs/package.empty.json +0 -1
  44. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  45. package/miniflare-dist/index.mjs +0 -6364
  46. package/src/__tests__/access.test.ts +0 -25
  47. package/src/__tests__/api-dev.test.ts +0 -238
  48. package/src/__tests__/api-devregistry.test.js +0 -64
  49. package/src/__tests__/api.test.ts +0 -80
  50. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  51. package/src/__tests__/config-cache.test.ts +0 -42
  52. package/src/__tests__/configuration.test.ts +0 -4163
  53. package/src/__tests__/d1.test.ts +0 -123
  54. package/src/__tests__/delete.test.ts +0 -263
  55. package/src/__tests__/deployments.test.ts +0 -105
  56. package/src/__tests__/dev.test.tsx +0 -1586
  57. package/src/__tests__/dialogs.test.tsx +0 -40
  58. package/src/__tests__/generate.test.ts +0 -235
  59. package/src/__tests__/get-host-from-url.test.ts +0 -16
  60. package/src/__tests__/guess-worker-format.test.ts +0 -85
  61. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  62. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  63. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  64. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  65. package/src/__tests__/helpers/mock-bin.ts +0 -36
  66. package/src/__tests__/helpers/mock-cfetch.ts +0 -277
  67. package/src/__tests__/helpers/mock-console.ts +0 -106
  68. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  69. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  70. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  71. package/src/__tests__/helpers/mock-istty.ts +0 -74
  72. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  73. package/src/__tests__/helpers/mock-kv.ts +0 -33
  74. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -271
  75. package/src/__tests__/helpers/mock-process.ts +0 -34
  76. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  77. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  78. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  79. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -59
  80. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
  81. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  82. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
  83. package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
  84. package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
  85. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -22
  86. package/src/__tests__/helpers/msw/index.ts +0 -21
  87. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  88. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  89. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  90. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  91. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  92. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  93. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  94. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  95. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  96. package/src/__tests__/https-options.test.ts +0 -163
  97. package/src/__tests__/index.test.ts +0 -268
  98. package/src/__tests__/init.test.ts +0 -3094
  99. package/src/__tests__/jest.setup.ts +0 -203
  100. package/src/__tests__/kv.test.ts +0 -1786
  101. package/src/__tests__/logger.test.ts +0 -141
  102. package/src/__tests__/logout.test.ts +0 -47
  103. package/src/__tests__/metrics.test.ts +0 -495
  104. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  105. package/src/__tests__/middleware.test.ts +0 -750
  106. package/src/__tests__/package-manager.test.ts +0 -353
  107. package/src/__tests__/pages-deployment-tail.test.ts +0 -884
  108. package/src/__tests__/pages.test.ts +0 -2443
  109. package/src/__tests__/parse.test.ts +0 -330
  110. package/src/__tests__/paths.test.ts +0 -39
  111. package/src/__tests__/publish.test.ts +0 -7757
  112. package/src/__tests__/pubsub.test.ts +0 -490
  113. package/src/__tests__/queues.test.ts +0 -522
  114. package/src/__tests__/r2.test.ts +0 -393
  115. package/src/__tests__/route.test.ts +0 -45
  116. package/src/__tests__/secret.test.ts +0 -694
  117. package/src/__tests__/tail.test.ts +0 -899
  118. package/src/__tests__/test-old-node-version.js +0 -31
  119. package/src/__tests__/tsconfig-sanity.ts +0 -12
  120. package/src/__tests__/tsconfig.json +0 -8
  121. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  122. package/src/__tests__/type-generation.test.ts +0 -233
  123. package/src/__tests__/user.test.ts +0 -129
  124. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  125. package/src/__tests__/validate-dev-props.test.ts +0 -56
  126. package/src/__tests__/version.test.ts +0 -35
  127. package/src/__tests__/whoami.test.tsx +0 -278
  128. package/src/__tests__/worker-namespace.test.ts +0 -326
  129. package/src/abort.d.ts +0 -3
  130. package/src/api/dev.ts +0 -218
  131. package/src/api/index.ts +0 -2
  132. package/src/bundle-reporter.tsx +0 -68
  133. package/src/bundle.ts +0 -823
  134. package/src/cfetch/index.ts +0 -158
  135. package/src/cfetch/internal.ts +0 -261
  136. package/src/cli.ts +0 -28
  137. package/src/config/README.md +0 -107
  138. package/src/config/config.ts +0 -275
  139. package/src/config/diagnostics.ts +0 -80
  140. package/src/config/environment.ts +0 -577
  141. package/src/config/index.ts +0 -358
  142. package/src/config/validation-helpers.ts +0 -597
  143. package/src/config/validation.ts +0 -2151
  144. package/src/config-cache.ts +0 -85
  145. package/src/create-worker-preview.ts +0 -282
  146. package/src/create-worker-upload-form.ts +0 -325
  147. package/src/d1/backups.tsx +0 -223
  148. package/src/d1/constants.ts +0 -2
  149. package/src/d1/create.tsx +0 -63
  150. package/src/d1/delete.tsx +0 -56
  151. package/src/d1/execute.tsx +0 -352
  152. package/src/d1/formatTimeAgo.ts +0 -14
  153. package/src/d1/index.ts +0 -101
  154. package/src/d1/list.tsx +0 -48
  155. package/src/d1/migrations/apply.tsx +0 -196
  156. package/src/d1/migrations/create.tsx +0 -77
  157. package/src/d1/migrations/helpers.ts +0 -147
  158. package/src/d1/migrations/index.tsx +0 -3
  159. package/src/d1/migrations/list.tsx +0 -79
  160. package/src/d1/migrations/options.ts +0 -18
  161. package/src/d1/options.ts +0 -22
  162. package/src/d1/types.tsx +0 -24
  163. package/src/d1/utils.ts +0 -48
  164. package/src/delete.ts +0 -108
  165. package/src/deployments.ts +0 -83
  166. package/src/deprecated/index.ts +0 -145
  167. package/src/dev/dev-vars.ts +0 -39
  168. package/src/dev/dev.tsx +0 -614
  169. package/src/dev/get-local-persistence-path.tsx +0 -31
  170. package/src/dev/local.tsx +0 -932
  171. package/src/dev/remote.tsx +0 -603
  172. package/src/dev/start-server.ts +0 -543
  173. package/src/dev/use-esbuild.ts +0 -204
  174. package/src/dev/validate-dev-props.ts +0 -31
  175. package/src/dev-registry.tsx +0 -201
  176. package/src/dev.tsx +0 -949
  177. package/src/dialogs.tsx +0 -168
  178. package/src/dispatch-namespace.ts +0 -207
  179. package/src/docs/index.ts +0 -97
  180. package/src/durable.ts +0 -102
  181. package/src/entry.ts +0 -329
  182. package/src/environment-variables/factory.ts +0 -88
  183. package/src/environment-variables/misc-variables.ts +0 -30
  184. package/src/errors.ts +0 -11
  185. package/src/generate/index.ts +0 -300
  186. package/src/git-client.ts +0 -135
  187. package/src/global-wrangler-config-path.ts +0 -26
  188. package/src/https-options.ts +0 -127
  189. package/src/index.tsx +0 -694
  190. package/src/init.ts +0 -1025
  191. package/src/inspect.ts +0 -767
  192. package/src/intl-polyfill.d.ts +0 -139
  193. package/src/is-ci.ts +0 -14
  194. package/src/is-interactive.ts +0 -16
  195. package/src/jest.d.ts +0 -4
  196. package/src/kv/helpers.ts +0 -430
  197. package/src/kv/index.ts +0 -596
  198. package/src/logger.ts +0 -92
  199. package/src/metrics/index.ts +0 -5
  200. package/src/metrics/metrics-config.ts +0 -239
  201. package/src/metrics/metrics-dispatcher.ts +0 -96
  202. package/src/metrics/metrics-usage-headers.ts +0 -24
  203. package/src/metrics/send-event.ts +0 -97
  204. package/src/miniflare-cli/README.md +0 -30
  205. package/src/miniflare-cli/assets.ts +0 -250
  206. package/src/miniflare-cli/index.ts +0 -210
  207. package/src/miniflare-cli/request-context.ts +0 -40
  208. package/src/miniflare-cli/tsconfig.json +0 -9
  209. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  210. package/src/miniflare-cli/types.ts +0 -11
  211. package/src/module-collection.ts +0 -267
  212. package/src/open-in-browser.ts +0 -17
  213. package/src/package-manager.ts +0 -219
  214. package/src/pages/build.tsx +0 -270
  215. package/src/pages/constants.ts +0 -18
  216. package/src/pages/deployment-tails.tsx +0 -284
  217. package/src/pages/deployments.tsx +0 -84
  218. package/src/pages/dev.tsx +0 -710
  219. package/src/pages/errors.ts +0 -66
  220. package/src/pages/functions/buildPlugin.ts +0 -107
  221. package/src/pages/functions/buildWorker.ts +0 -166
  222. package/src/pages/functions/filepath-routing.test.ts +0 -234
  223. package/src/pages/functions/filepath-routing.ts +0 -189
  224. package/src/pages/functions/identifiers.ts +0 -78
  225. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  226. package/src/pages/functions/routes-consolidation.ts +0 -73
  227. package/src/pages/functions/routes-transformation.test.ts +0 -282
  228. package/src/pages/functions/routes-transformation.ts +0 -115
  229. package/src/pages/functions/routes-validation.test.ts +0 -403
  230. package/src/pages/functions/routes-validation.ts +0 -202
  231. package/src/pages/functions/routes.ts +0 -151
  232. package/src/pages/functions/tsconfig.json +0 -8
  233. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  234. package/src/pages/functions.tsx +0 -82
  235. package/src/pages/hash.tsx +0 -13
  236. package/src/pages/index.tsx +0 -102
  237. package/src/pages/projects.tsx +0 -169
  238. package/src/pages/prompt-select-project.tsx +0 -31
  239. package/src/pages/publish.tsx +0 -461
  240. package/src/pages/types.ts +0 -41
  241. package/src/pages/upload.tsx +0 -447
  242. package/src/pages/utils.ts +0 -23
  243. package/src/parse.ts +0 -286
  244. package/src/paths.ts +0 -71
  245. package/src/proxy.ts +0 -694
  246. package/src/publish/index.ts +0 -270
  247. package/src/publish/publish.ts +0 -1036
  248. package/src/pubsub/index.ts +0 -286
  249. package/src/pubsub/pubsub-commands.tsx +0 -624
  250. package/src/queues/cli/commands/consumer/add.ts +0 -71
  251. package/src/queues/cli/commands/consumer/index.ts +0 -22
  252. package/src/queues/cli/commands/consumer/remove.ts +0 -38
  253. package/src/queues/cli/commands/create.ts +0 -25
  254. package/src/queues/cli/commands/delete.ts +0 -26
  255. package/src/queues/cli/commands/index.ts +0 -36
  256. package/src/queues/cli/commands/list.ts +0 -25
  257. package/src/queues/client.ts +0 -135
  258. package/src/queues/utils.ts +0 -18
  259. package/src/r2/constants.ts +0 -4
  260. package/src/r2/helpers.ts +0 -131
  261. package/src/r2/index.ts +0 -289
  262. package/src/routes.ts +0 -140
  263. package/src/secret/index.ts +0 -379
  264. package/src/selfsigned.d.ts +0 -29
  265. package/src/sites.tsx +0 -372
  266. package/src/tail/createTail.ts +0 -379
  267. package/src/tail/filters.ts +0 -277
  268. package/src/tail/index.ts +0 -214
  269. package/src/tail/printing.ts +0 -107
  270. package/src/tsconfig-sanity.ts +0 -16
  271. package/src/type-generation.ts +0 -181
  272. package/src/update-check.ts +0 -19
  273. package/src/user/access.ts +0 -68
  274. package/src/user/auth-variables.ts +0 -113
  275. package/src/user/choose-account.tsx +0 -69
  276. package/src/user/generate-auth-url.ts +0 -33
  277. package/src/user/generate-random-state.ts +0 -16
  278. package/src/user/index.ts +0 -2
  279. package/src/user/user.tsx +0 -1238
  280. package/src/utils/collectKeyValues.ts +0 -14
  281. package/src/whoami.tsx +0 -169
  282. package/src/worker.ts +0 -251
  283. package/src/yargs-types.ts +0 -24
  284. package/src/zones.ts +0 -191
  285. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  286. package/templates/d1-beta-facade.js +0 -205
  287. package/templates/first-party-worker-module-facade.ts +0 -19
  288. package/templates/format-dev-errors.ts +0 -33
  289. package/templates/serve-static-assets.ts +0 -65
  290. package/templates/service-bindings-module-facade.js +0 -54
  291. package/templates/service-bindings-sw-facade.js +0 -42
  292. package/templates/tsconfig.tsbuildinfo +0 -1
@@ -1,694 +0,0 @@
1
- import * as fs from "node:fs";
2
- import { writeFileSync } from "node:fs";
3
- import * as TOML from "@iarna/toml";
4
- import { rest } from "msw";
5
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
6
- import { mockConsoleMethods } from "./helpers/mock-console";
7
- import {
8
- mockConfirm,
9
- mockPrompt,
10
- clearConfirmMocks,
11
- clearPromptMocks,
12
- } from "./helpers/mock-dialogs";
13
- import { useMockStdin } from "./helpers/mock-stdin";
14
- import { msw } from "./helpers/msw";
15
- import { runInTempDir } from "./helpers/run-in-tmp";
16
- import { runWrangler } from "./helpers/run-wrangler";
17
-
18
- function createFetchResult(result: unknown, success = true) {
19
- return {
20
- success,
21
- errors: [],
22
- messages: [],
23
- result,
24
- };
25
- }
26
-
27
- export function mockGetMembershipsFail() {
28
- msw.use(
29
- rest.get("*/memberships", (req, res, ctx) => {
30
- return res.once(ctx.json(createFetchResult([], false)));
31
- })
32
- );
33
- }
34
-
35
- export function mockGetMemberships(
36
- accounts: { id: string; account: { id: string; name: string } }[]
37
- ) {
38
- msw.use(
39
- rest.get("*/memberships", (req, res, ctx) => {
40
- return res.once(ctx.json(createFetchResult(accounts)));
41
- })
42
- );
43
- }
44
-
45
- describe("wrangler secret", () => {
46
- const std = mockConsoleMethods();
47
-
48
- runInTempDir();
49
- mockAccountId();
50
- mockApiToken();
51
-
52
- afterEach(() => {
53
- clearConfirmMocks();
54
- clearPromptMocks();
55
- });
56
-
57
- describe("put", () => {
58
- function mockPutRequest(
59
- input: { name: string; text: string },
60
- env?: string,
61
- legacyEnv = false
62
- ) {
63
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
64
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
65
- msw.use(
66
- rest.put(
67
- `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
68
- async (req, res, ctx) => {
69
- expect(req.params.accountId).toEqual("some-account-id");
70
- expect(req.params.scriptName).toEqual(
71
- legacyEnv && env ? `script-name-${env}` : "script-name"
72
- );
73
- if (!legacyEnv) {
74
- expect(req.params.envName).toEqual(env);
75
- }
76
- const { name, text, type } = await req.json();
77
- expect(type).toEqual("secret_text");
78
- expect(name).toEqual(input.name);
79
- expect(text).toEqual(input.text);
80
-
81
- return res.once(ctx.json(createFetchResult({ name, type })));
82
- }
83
- )
84
- );
85
- }
86
-
87
- describe("interactive", () => {
88
- useMockStdin({ isTTY: true });
89
-
90
- it("should trim stdin secret value", async () => {
91
- mockPrompt({
92
- text: "Enter a secret value:",
93
- type: "password",
94
- result: `hunter2
95
- `,
96
- });
97
-
98
- mockPutRequest({ name: `secret-name`, text: `hunter2` });
99
- await runWrangler("secret put secret-name --name script-name");
100
- expect(std.out).toMatchInlineSnapshot(`
101
- "🌀 Creating the secret for the Worker \\"script-name\\"
102
- ✨ Success! Uploaded secret secret-name"
103
- `);
104
- });
105
-
106
- it("should create a secret", async () => {
107
- mockPrompt({
108
- text: "Enter a secret value:",
109
- type: "password",
110
- result: "the-secret",
111
- });
112
-
113
- mockPutRequest({ name: "the-key", text: "the-secret" });
114
- await runWrangler("secret put the-key --name script-name");
115
-
116
- expect(std.out).toMatchInlineSnapshot(`
117
- "🌀 Creating the secret for the Worker \\"script-name\\"
118
- ✨ Success! Uploaded secret the-key"
119
- `);
120
- expect(std.err).toMatchInlineSnapshot(`""`);
121
- });
122
-
123
- it("should create secret:bulk", async () => {
124
- writeFileSync(
125
- "secret.json",
126
- JSON.stringify({
127
- "secret-name-1": "secret_text",
128
- "secret-name-2": "secret_text",
129
- })
130
- );
131
-
132
- // User counter to pass different secrets to the request mock
133
- let counter = 0;
134
- msw.use(
135
- rest.put(
136
- `*/accounts/:accountId/workers/scripts/:scriptName/secrets`,
137
- (req, res, ctx) => {
138
- expect(req.params.accountId).toEqual("some-account-id");
139
- counter++;
140
-
141
- return res(
142
- ctx.json(
143
- createFetchResult({
144
- name: `secret-name-${counter}`,
145
- type: "secret_text",
146
- })
147
- )
148
- );
149
- }
150
- )
151
- );
152
-
153
- await runWrangler("secret:bulk ./secret.json --name script-name");
154
-
155
- expect(std.out).toMatchInlineSnapshot(`
156
- "🌀 Creating the secrets for the Worker \\"script-name\\"
157
- ✨ Successfully created secret for key: secret-name-1
158
- ✨ Successfully created secret for key: secret-name-2
159
-
160
- Finished processing secrets JSON file:
161
- ✨ 2 secrets successfully uploaded"
162
- `);
163
- expect(std.err).toMatchInlineSnapshot(`""`);
164
- });
165
-
166
- it("should handle network failure on secret:bulk", async () => {
167
- writeFileSync(
168
- "secret.json",
169
- JSON.stringify({
170
- "secret-name-1": "secret_text",
171
- "secret-name-2": "secret_text",
172
- })
173
- );
174
-
175
- // User counter to pass different secrets to the request mock
176
- let counter = 0;
177
- msw.use(
178
- rest.put(
179
- `*/accounts/:accountId/workers/scripts/:scriptName/secrets`,
180
- (req, res) => {
181
- expect(req.params.accountId).toEqual("some-account-id");
182
- counter++;
183
-
184
- return res.networkError(`Failed to create secret ${counter}`);
185
- }
186
- )
187
- );
188
-
189
- await runWrangler("secret:bulk ./secret.json --name script-name");
190
-
191
- expect(std.out).toMatchInlineSnapshot(`
192
- "🌀 Creating the secrets for the Worker \\"script-name\\"
193
-
194
- Finished processing secrets JSON file:
195
- ✨ 0 secrets successfully uploaded
196
- 🚨 2 secrets failed to upload"
197
- `);
198
- expect(std.err).toMatchInlineSnapshot(`
199
- "X [ERROR] 🚨 Error uploading secret for key: secret-name-1:
200
-
201
- request to
202
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
203
- failed, reason: Failed to create secret 1
204
-
205
-
206
- X [ERROR] 🚨 Error uploading secret for key: secret-name-2:
207
-
208
- request to
209
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
210
- failed, reason: Failed to create secret 2
211
-
212
- "
213
- `);
214
- });
215
-
216
- it("should count success and network failure on secret:bulk", async () => {
217
- writeFileSync(
218
- "secret.json",
219
- JSON.stringify({
220
- "secret-name-1": "secret_text",
221
- "secret-name-2": "secret_text",
222
- "secret-name-3": "secret_text",
223
- "secret-name-4": "secret_text",
224
- "secret-name-5": "secret_text",
225
- "secret-name-6": "secret_text",
226
- "secret-name-7": "secret_text",
227
- })
228
- );
229
-
230
- // User counter to pass different secrets to the request mock
231
- let counter = 0;
232
- msw.use(
233
- rest.put(
234
- `*/accounts/:accountId/workers/scripts/:scriptName/secrets`,
235
- (req, res, ctx) => {
236
- expect(req.params.accountId).toEqual("some-account-id");
237
- counter++;
238
-
239
- if (counter % 2 === 0) {
240
- return res(
241
- ctx.json(
242
- createFetchResult({
243
- name: `secret-name-${counter}`,
244
- type: "secret_text",
245
- })
246
- )
247
- );
248
- } else {
249
- return res.networkError(`Failed to create secret ${counter}`);
250
- }
251
- }
252
- )
253
- );
254
-
255
- await runWrangler("secret:bulk ./secret.json --name script-name");
256
-
257
- expect(std.out).toMatchInlineSnapshot(`
258
- "🌀 Creating the secrets for the Worker \\"script-name\\"
259
- ✨ Successfully created secret for key: secret-name-2
260
- ✨ Successfully created secret for key: secret-name-4
261
- ✨ Successfully created secret for key: secret-name-6
262
-
263
- Finished processing secrets JSON file:
264
- ✨ 3 secrets successfully uploaded
265
- 🚨 4 secrets failed to upload"
266
- `);
267
- expect(std.err).toMatchInlineSnapshot(`
268
- "X [ERROR] 🚨 Error uploading secret for key: secret-name-1:
269
-
270
- request to
271
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
272
- failed, reason: Failed to create secret 1
273
-
274
-
275
- X [ERROR] 🚨 Error uploading secret for key: secret-name-3:
276
-
277
- request to
278
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
279
- failed, reason: Failed to create secret 3
280
-
281
-
282
- X [ERROR] 🚨 Error uploading secret for key: secret-name-5:
283
-
284
- request to
285
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
286
- failed, reason: Failed to create secret 5
287
-
288
-
289
- X [ERROR] 🚨 Error uploading secret for key: secret-name-7:
290
-
291
- request to
292
- https://api.cloudflare.com/client/v4/accounts/some-account-id/workers/scripts/script-name/secrets
293
- failed, reason: Failed to create secret 7
294
-
295
- "
296
- `);
297
- });
298
-
299
- it("should create a secret: legacy envs", async () => {
300
- mockPrompt({
301
- text: "Enter a secret value:",
302
- type: "password",
303
- result: "the-secret",
304
- });
305
-
306
- mockPutRequest(
307
- { name: "the-key", text: "the-secret" },
308
- "some-env",
309
- true
310
- );
311
- await runWrangler(
312
- "secret put the-key --name script-name --env some-env --legacy-env"
313
- );
314
-
315
- expect(std.out).toMatchInlineSnapshot(`
316
- "🌀 Creating the secret for the Worker \\"script-name-some-env\\"
317
- ✨ Success! Uploaded secret the-key"
318
- `);
319
- expect(std.err).toMatchInlineSnapshot(`""`);
320
- });
321
-
322
- it("should create a secret: service envs", async () => {
323
- mockPrompt({
324
- text: "Enter a secret value:",
325
- type: "password",
326
- result: "the-secret",
327
- });
328
-
329
- mockPutRequest(
330
- { name: "the-key", text: "the-secret" },
331
- "some-env",
332
- false
333
- );
334
- await runWrangler(
335
- "secret put the-key --name script-name --env some-env --legacy-env false"
336
- );
337
-
338
- expect(std.out).toMatchInlineSnapshot(`
339
- "🌀 Creating the secret for the Worker \\"script-name\\" (some-env)
340
- ✨ Success! Uploaded secret the-key"
341
- `);
342
- expect(std.err).toMatchInlineSnapshot(`""`);
343
- });
344
-
345
- it("should error without a script name", async () => {
346
- let error: Error | undefined;
347
- try {
348
- await runWrangler("secret put the-key");
349
- } catch (e) {
350
- error = e as Error;
351
- }
352
- expect(std.out).toMatchInlineSnapshot(`
353
- "
354
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
355
- `);
356
- expect(std.err).toMatchInlineSnapshot(`
357
- "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
358
-
359
- "
360
- `);
361
- expect(error).toMatchInlineSnapshot(
362
- `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
363
- );
364
- });
365
- });
366
-
367
- describe("non-interactive", () => {
368
- const mockStdIn = useMockStdin({ isTTY: false });
369
-
370
- it("should trim stdin secret value, from piped input", async () => {
371
- mockPutRequest({ name: "the-key", text: "the-secret" });
372
- // Pipe the secret in as three chunks to test that we reconstitute it correctly.
373
- mockStdIn.send(
374
- `the`,
375
- `-`,
376
- `secret
377
- ` // whitespace & newline being removed
378
- );
379
- await runWrangler("secret put the-key --name script-name");
380
-
381
- expect(std.out).toMatchInlineSnapshot(`
382
- "🌀 Creating the secret for the Worker \\"script-name\\"
383
- ✨ Success! Uploaded secret the-key"
384
- `);
385
- expect(std.warn).toMatchInlineSnapshot(`""`);
386
- expect(std.err).toMatchInlineSnapshot(`""`);
387
- });
388
-
389
- it("should create a secret, from piped input", async () => {
390
- mockPutRequest({ name: "the-key", text: "the-secret" });
391
- // Pipe the secret in as three chunks to test that we reconstitute it correctly.
392
- mockStdIn.send("the", "-", "secret");
393
- await runWrangler("secret put the-key --name script-name");
394
-
395
- expect(std.out).toMatchInlineSnapshot(`
396
- "🌀 Creating the secret for the Worker \\"script-name\\"
397
- ✨ Success! Uploaded secret the-key"
398
- `);
399
- expect(std.warn).toMatchInlineSnapshot(`""`);
400
- expect(std.err).toMatchInlineSnapshot(`""`);
401
- });
402
-
403
- it("should error if the piped input fails", async () => {
404
- mockPutRequest({ name: "the-key", text: "the-secret" });
405
- mockStdIn.throwError(new Error("Error in stdin stream"));
406
- await expect(
407
- runWrangler("secret put the-key --name script-name")
408
- ).rejects.toThrowErrorMatchingInlineSnapshot(`"Error in stdin stream"`);
409
-
410
- expect(std.out).toMatchInlineSnapshot(`
411
- "
412
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
413
- `);
414
- expect(std.warn).toMatchInlineSnapshot(`""`);
415
- });
416
-
417
- describe("with accountId", () => {
418
- mockAccountId({ accountId: null });
419
-
420
- it("should error if request for memberships fails", async () => {
421
- mockGetMembershipsFail();
422
- await expect(
423
- runWrangler("secret put the-key --name script-name")
424
- ).rejects.toThrowErrorMatchingInlineSnapshot(
425
- `"A request to the Cloudflare API (/memberships) failed."`
426
- );
427
- });
428
-
429
- it("should error if a user has no account", async () => {
430
- mockGetMemberships([]);
431
- await expect(runWrangler("secret put the-key --name script-name"))
432
- .rejects.toThrowErrorMatchingInlineSnapshot(`
433
- "Failed to automatically retrieve account IDs for the logged in user.
434
- In a non-interactive environment, it is mandatory to specify an account ID, either by assigning its value to CLOUDFLARE_ACCOUNT_ID, or as \`account_id\` in your \`wrangler.toml\` file."
435
- `);
436
- });
437
-
438
- it("should use the account from wrangler.toml", async () => {
439
- fs.writeFileSync(
440
- "wrangler.toml",
441
- TOML.stringify({
442
- account_id: "some-account-id",
443
- }),
444
- "utf-8"
445
- );
446
- mockStdIn.send("the-secret");
447
- mockPutRequest({ name: "the-key", text: "the-secret" });
448
- await runWrangler("secret put the-key --name script-name");
449
- expect(std.out).toMatchInlineSnapshot(`
450
- "🌀 Creating the secret for the Worker \\"script-name\\"
451
- ✨ Success! Uploaded secret the-key"
452
- `);
453
- expect(std.warn).toMatchInlineSnapshot(`""`);
454
- expect(std.err).toMatchInlineSnapshot(`""`);
455
- });
456
-
457
- it("should error if a user has multiple accounts, and has not specified an account in wrangler.toml", async () => {
458
- mockGetMemberships([
459
- {
460
- id: "1",
461
- account: { id: "account-id-1", name: "account-name-1" },
462
- },
463
- {
464
- id: "2",
465
- account: { id: "account-id-2", name: "account-name-2" },
466
- },
467
- {
468
- id: "3",
469
- account: { id: "account-id-3", name: "account-name-3" },
470
- },
471
- ]);
472
-
473
- await expect(runWrangler("secret put the-key --name script-name"))
474
- .rejects.toThrowErrorMatchingInlineSnapshot(`
475
- "More than one account available but unable to select one in non-interactive mode.
476
- Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
477
- Available accounts are (\\"<name>\\" - \\"<id>\\"):
478
- \\"account-name-1\\" - \\"account-id-1\\")
479
- \\"account-name-2\\" - \\"account-id-2\\")
480
- \\"account-name-3\\" - \\"account-id-3\\")"
481
- `);
482
- });
483
- });
484
- });
485
- });
486
-
487
- describe("delete", () => {
488
- function mockDeleteRequest(
489
- input: {
490
- scriptName: string;
491
- secretName: string;
492
- },
493
- env?: string,
494
- legacyEnv = false
495
- ) {
496
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
497
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
498
- msw.use(
499
- rest.delete(
500
- `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets/:secretName`,
501
- (req, res, ctx) => {
502
- expect(req.params.accountId).toEqual("some-account-id");
503
- expect(req.params.scriptName).toEqual(
504
- legacyEnv && env ? `script-name-${env}` : "script-name"
505
- );
506
- if (!legacyEnv) {
507
- if (env) {
508
- expect(req.params.secretName).toEqual(input.secretName);
509
- }
510
- }
511
- return res.once(ctx.json(createFetchResult(null)));
512
- }
513
- )
514
- );
515
- }
516
- it("should delete a secret", async () => {
517
- mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
518
- mockConfirm({
519
- text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name?",
520
- result: true,
521
- });
522
- await runWrangler("secret delete the-key --name script-name");
523
- expect(std.out).toMatchInlineSnapshot(`
524
- "🌀 Deleting the secret the-key on the Worker script-name
525
- ✨ Success! Deleted secret the-key"
526
- `);
527
- expect(std.err).toMatchInlineSnapshot(`""`);
528
- });
529
-
530
- it("should delete a secret: legacy envs", async () => {
531
- mockDeleteRequest(
532
- { scriptName: "script-name", secretName: "the-key" },
533
- "some-env",
534
- true
535
- );
536
- mockConfirm({
537
- text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name-some-env?",
538
- result: true,
539
- });
540
- await runWrangler(
541
- "secret delete the-key --name script-name --env some-env --legacy-env"
542
- );
543
- expect(std.out).toMatchInlineSnapshot(`
544
- "🌀 Deleting the secret the-key on the Worker script-name-some-env
545
- ✨ Success! Deleted secret the-key"
546
- `);
547
- expect(std.err).toMatchInlineSnapshot(`""`);
548
- });
549
-
550
- it("should delete a secret: service envs", async () => {
551
- mockDeleteRequest(
552
- { scriptName: "script-name", secretName: "the-key" },
553
- "some-env"
554
- );
555
- mockConfirm({
556
- text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name (some-env)?",
557
- result: true,
558
- });
559
- await runWrangler(
560
- "secret delete the-key --name script-name --env some-env --legacy-env false"
561
- );
562
- expect(std.out).toMatchInlineSnapshot(`
563
- "🌀 Deleting the secret the-key on the Worker script-name (some-env)
564
- ✨ Success! Deleted secret the-key"
565
- `);
566
- expect(std.err).toMatchInlineSnapshot(`""`);
567
- });
568
-
569
- it("should error without a script name", async () => {
570
- let error: Error | undefined;
571
-
572
- try {
573
- await runWrangler("secret delete the-key");
574
- } catch (e) {
575
- error = e as Error;
576
- }
577
- expect(std.out).toMatchInlineSnapshot(`
578
- "
579
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
580
- `);
581
- expect(std.err).toMatchInlineSnapshot(`
582
- "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
583
-
584
- "
585
- `);
586
- expect(error).toMatchInlineSnapshot(
587
- `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
588
- );
589
- });
590
- });
591
-
592
- describe("list", () => {
593
- function mockListRequest(
594
- input: { scriptName: string },
595
- env?: string,
596
- legacyEnv = false
597
- ) {
598
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
599
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
600
- msw.use(
601
- rest.get(
602
- `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
603
- (req, res, ctx) => {
604
- expect(req.params.accountId).toEqual("some-account-id");
605
- expect(req.params.scriptName).toEqual(
606
- legacyEnv && env ? `script-name-${env}` : "script-name"
607
- );
608
- if (!legacyEnv) {
609
- expect(req.params.envName).toEqual(env);
610
- }
611
-
612
- return res.once(
613
- ctx.json(
614
- createFetchResult([
615
- {
616
- name: "the-secret-name",
617
- type: "secret_text",
618
- },
619
- ])
620
- )
621
- );
622
- }
623
- )
624
- );
625
- }
626
-
627
- it("should list secrets", async () => {
628
- mockListRequest({ scriptName: "script-name" });
629
- await runWrangler("secret list --name script-name");
630
- expect(std.out).toMatchInlineSnapshot(`
631
- "[
632
- {
633
- \\"name\\": \\"the-secret-name\\",
634
- \\"type\\": \\"secret_text\\"
635
- }
636
- ]"
637
- `);
638
- expect(std.err).toMatchInlineSnapshot(`""`);
639
- });
640
-
641
- it("should list secrets: legacy envs", async () => {
642
- mockListRequest({ scriptName: "script-name" }, "some-env", true);
643
- await runWrangler(
644
- "secret list --name script-name --env some-env --legacy-env"
645
- );
646
- expect(std.out).toMatchInlineSnapshot(`
647
- "[
648
- {
649
- \\"name\\": \\"the-secret-name\\",
650
- \\"type\\": \\"secret_text\\"
651
- }
652
- ]"
653
- `);
654
- expect(std.err).toMatchInlineSnapshot(`""`);
655
- });
656
-
657
- it("should list secrets: service envs", async () => {
658
- mockListRequest({ scriptName: "script-name" }, "some-env");
659
- await runWrangler(
660
- "secret list --name script-name --env some-env --legacy-env false"
661
- );
662
- expect(std.out).toMatchInlineSnapshot(`
663
- "[
664
- {
665
- \\"name\\": \\"the-secret-name\\",
666
- \\"type\\": \\"secret_text\\"
667
- }
668
- ]"
669
- `);
670
- expect(std.err).toMatchInlineSnapshot(`""`);
671
- });
672
-
673
- it("should error without a script name", async () => {
674
- let error: Error | undefined;
675
- try {
676
- await runWrangler("secret list");
677
- } catch (e) {
678
- error = e as Error;
679
- }
680
- expect(std.out).toMatchInlineSnapshot(`
681
- "
682
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
683
- `);
684
- expect(std.err).toMatchInlineSnapshot(`
685
- "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
686
-
687
- "
688
- `);
689
- expect(error).toMatchInlineSnapshot(
690
- `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
691
- );
692
- });
693
- });
694
- });