wrangler 0.0.0-e0d2f35 → 0.0.0-e1b8ac4

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 (160) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +48 -4
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4886 -0
  6. package/package.json +58 -31
  7. package/pages/functions/buildPlugin.ts +105 -0
  8. package/pages/functions/buildWorker.ts +93 -4
  9. package/pages/functions/filepath-routing.test.ts +223 -28
  10. package/pages/functions/filepath-routing.ts +92 -131
  11. package/pages/functions/routes.ts +16 -18
  12. package/pages/functions/template-plugin.ts +147 -0
  13. package/pages/functions/template-worker.ts +24 -17
  14. package/src/__tests__/config-cache.test.ts +36 -0
  15. package/src/__tests__/configuration.test.ts +3548 -0
  16. package/src/__tests__/dev.test.tsx +1049 -65
  17. package/src/__tests__/guess-worker-format.test.ts +85 -0
  18. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  19. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  20. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  21. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  22. package/src/__tests__/helpers/mock-bin.ts +36 -0
  23. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +50 -12
  24. package/src/__tests__/helpers/mock-console.ts +87 -0
  25. package/src/__tests__/helpers/mock-dialogs.ts +153 -0
  26. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  27. package/src/__tests__/helpers/mock-istty.ts +27 -0
  28. package/src/__tests__/{mock-kv.ts → helpers/mock-kv.ts} +9 -16
  29. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  30. package/src/__tests__/helpers/mock-process.ts +24 -0
  31. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  32. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  33. package/src/__tests__/{run-in-tmp.ts → helpers/run-in-tmp.ts} +11 -1
  34. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  35. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  36. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  37. package/src/__tests__/https-options.test.ts +130 -0
  38. package/src/__tests__/index.test.ts +171 -338
  39. package/src/__tests__/init.test.ts +1992 -0
  40. package/src/__tests__/jest.setup.ts +86 -8
  41. package/src/__tests__/kv.test.ts +745 -449
  42. package/src/__tests__/logger.test.ts +141 -0
  43. package/src/__tests__/package-manager.test.ts +353 -0
  44. package/src/__tests__/pages.test.ts +754 -0
  45. package/src/__tests__/parse.test.ts +330 -0
  46. package/src/__tests__/publish.test.ts +5631 -903
  47. package/src/__tests__/r2.test.ts +233 -0
  48. package/src/__tests__/route.test.ts +45 -0
  49. package/src/__tests__/secret.test.ts +370 -95
  50. package/src/__tests__/tail.test.ts +690 -0
  51. package/src/__tests__/user.test.ts +132 -0
  52. package/src/__tests__/whoami.test.tsx +58 -20
  53. package/src/abort.d.ts +3 -0
  54. package/src/bundle.ts +204 -0
  55. package/src/cfetch/index.ts +30 -20
  56. package/src/cfetch/internal.ts +101 -30
  57. package/src/cli.ts +6 -2
  58. package/src/config/README.md +107 -0
  59. package/src/config/config.ts +243 -0
  60. package/src/config/diagnostics.ts +80 -0
  61. package/src/config/environment.ts +420 -0
  62. package/src/config/index.ts +225 -0
  63. package/src/config/validation-helpers.ts +584 -0
  64. package/src/config/validation.ts +1580 -0
  65. package/src/config-cache.ts +45 -0
  66. package/src/create-worker-preview.ts +185 -0
  67. package/src/create-worker-upload-form.ts +254 -0
  68. package/src/dev/dev-vars.ts +36 -0
  69. package/src/dev/dev.tsx +399 -0
  70. package/src/dev/local.tsx +321 -0
  71. package/src/dev/remote.tsx +242 -0
  72. package/src/dev/use-esbuild.ts +112 -0
  73. package/src/dialogs.tsx +66 -8
  74. package/src/durable.ts +102 -0
  75. package/src/entry.ts +322 -0
  76. package/src/environment-variables.ts +35 -0
  77. package/src/errors.ts +11 -0
  78. package/src/generate-auth-url.ts +33 -0
  79. package/src/generate-random-state.ts +16 -0
  80. package/src/https-options.ts +123 -0
  81. package/src/index.tsx +1848 -1019
  82. package/src/inspect.ts +87 -20
  83. package/src/intl-polyfill.d.ts +139 -0
  84. package/src/{kv.tsx → kv.ts} +199 -67
  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 +41 -0
  89. package/src/miniflare-cli/request-context.ts +40 -0
  90. package/src/module-collection.ts +229 -34
  91. package/src/open-in-browser.ts +17 -0
  92. package/src/package-manager.ts +174 -0
  93. package/src/pages.tsx +1145 -95
  94. package/src/parse.ts +222 -0
  95. package/src/paths.ts +26 -0
  96. package/src/proxy.ts +180 -74
  97. package/src/publish.ts +626 -310
  98. package/src/r2.ts +50 -0
  99. package/src/selfsigned.d.ts +29 -0
  100. package/src/sites.tsx +187 -59
  101. package/src/tail/filters.ts +279 -0
  102. package/src/tail/index.ts +299 -0
  103. package/src/tail/printing.ts +67 -0
  104. package/src/update-check.ts +19 -0
  105. package/src/user.tsx +359 -176
  106. package/src/whoami.tsx +5 -3
  107. package/src/{api/worker.ts → worker.ts} +66 -40
  108. package/src/zones.ts +73 -0
  109. package/templates/gitignore +171 -0
  110. package/templates/new-worker-scheduled.js +17 -0
  111. package/templates/new-worker-scheduled.ts +32 -0
  112. package/templates/new-worker.js +15 -0
  113. package/templates/new-worker.ts +30 -0
  114. package/{static-asset-facade.js → templates/static-asset-facade.js} +3 -7
  115. package/templates/tsconfig.json +105 -0
  116. package/wrangler-dist/cli.js +112889 -110835
  117. package/src/__tests__/logout.test.ts +0 -64
  118. package/src/__tests__/mock-console.ts +0 -34
  119. package/src/__tests__/mock-dialogs.ts +0 -65
  120. package/src/__tests__/mock-user.ts +0 -27
  121. package/src/__tests__/run-wrangler.ts +0 -8
  122. package/src/api/form_data.ts +0 -135
  123. package/src/api/preview.ts +0 -128
  124. package/src/config.ts +0 -641
  125. package/src/dev.tsx +0 -830
  126. package/src/tail.tsx +0 -73
  127. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  128. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  129. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  130. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  131. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  132. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  133. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  134. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  135. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  136. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  137. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  138. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  139. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  140. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  141. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  142. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  143. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  144. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  145. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  146. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  147. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  148. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  149. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  150. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  151. package/vendor/wrangler-mime/LICENSE +0 -21
  152. package/vendor/wrangler-mime/Mime.js +0 -97
  153. package/vendor/wrangler-mime/README.md +0 -187
  154. package/vendor/wrangler-mime/cli.js +0 -46
  155. package/vendor/wrangler-mime/index.js +0 -4
  156. package/vendor/wrangler-mime/lite.js +0 -4
  157. package/vendor/wrangler-mime/package.json +0 -52
  158. package/vendor/wrangler-mime/types/other.js +0 -1
  159. package/vendor/wrangler-mime/types/standard.js +0 -1
  160. package/wrangler-dist/cli.js.map +0 -7
@@ -1,23 +1,52 @@
1
- import { setMockResponse, unsetAllMocks } from "./mock-cfetch";
2
- import { runWrangler } from "./run-wrangler";
3
- import { runInTempDir } from "./run-in-tmp";
4
- import { mockConfirm, mockPrompt } from "./mock-dialogs";
5
- import { mockConsoleMethods } from "./mock-console";
1
+ import * as fs from "node:fs";
2
+ import * as TOML from "@iarna/toml";
3
+ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
4
+ import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
5
+ import { mockConsoleMethods } from "./helpers/mock-console";
6
+ import {
7
+ mockConfirm,
8
+ mockPrompt,
9
+ clearConfirmMocks,
10
+ clearPromptMocks,
11
+ } from "./helpers/mock-dialogs";
12
+ import { mockOAuthFlow } from "./helpers/mock-oauth-flow";
13
+ import { useMockStdin } from "./helpers/mock-stdin";
14
+ import { runInTempDir } from "./helpers/run-in-tmp";
15
+ import { runWrangler } from "./helpers/run-wrangler";
6
16
 
7
17
  describe("wrangler secret", () => {
8
18
  const std = mockConsoleMethods();
19
+ const { mockGetMemberships } = mockOAuthFlow();
20
+
9
21
  runInTempDir();
22
+ mockAccountId();
23
+ mockApiToken();
24
+
10
25
  afterEach(() => {
11
26
  unsetAllMocks();
27
+ clearConfirmMocks();
28
+ clearPromptMocks();
12
29
  });
13
30
 
14
31
  describe("put", () => {
15
- function mockPutRequest(input: { name: string; text: string }) {
32
+ function mockPutRequest(
33
+ input: { name: string; text: string },
34
+ env?: string,
35
+ legacyEnv = false
36
+ ) {
37
+ const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
38
+ const environment = env && !legacyEnv ? "/environments/:envName" : "";
16
39
  setMockResponse(
17
- "/accounts/:accountId/workers/scripts/:scriptName/secrets",
40
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
18
41
  "PUT",
19
- ([_url, accountId], { body }) => {
42
+ ([_url, accountId, scriptName, envName], { body }) => {
20
43
  expect(accountId).toEqual("some-account-id");
44
+ expect(scriptName).toEqual(
45
+ legacyEnv && env ? `script-name-${env}` : "script-name"
46
+ );
47
+ if (!legacyEnv) {
48
+ expect(envName).toEqual(env);
49
+ }
21
50
  const { name, text, type } = JSON.parse(body as string);
22
51
  expect(type).toEqual("secret_text");
23
52
  expect(name).toEqual(input.name);
@@ -28,70 +57,254 @@ describe("wrangler secret", () => {
28
57
  );
29
58
  }
30
59
 
31
- it("should create a secret", async () => {
32
- mockPrompt({
33
- text: "Enter a secret value:",
34
- type: "password",
35
- result: "the-secret",
60
+ describe("interactive", () => {
61
+ useMockStdin({ isTTY: true });
62
+
63
+ it("should trim stdin secret value", async () => {
64
+ mockPrompt({
65
+ text: "Enter a secret value:",
66
+ type: "password",
67
+ result: `hunter2
68
+ `,
69
+ });
70
+
71
+ mockPutRequest({ name: `secret-name`, text: `hunter2` });
72
+ await runWrangler("secret put secret-name --name script-name");
73
+ expect(std.out).toMatchInlineSnapshot(`
74
+ "🌀 Creating the secret for script script-name
75
+ ✨ Success! Uploaded secret secret-name"
76
+ `);
36
77
  });
37
78
 
38
- mockPutRequest({ name: "the-secret-name", text: "the-secret" });
39
- await runWrangler("secret put the-key --name script-name");
79
+ it("should create a secret", async () => {
80
+ mockPrompt({
81
+ text: "Enter a secret value:",
82
+ type: "password",
83
+ result: "the-secret",
84
+ });
40
85
 
41
- expect(std.out).toMatchInlineSnapshot(`
42
- "🌀 Creating the secret for script script-name
43
- ✨ Success! Uploaded secret the-key"
44
- `);
45
- expect(std.err).toMatchInlineSnapshot(`""`);
46
- });
86
+ mockPutRequest({ name: "the-key", text: "the-secret" });
87
+ await runWrangler("secret put the-key --name script-name");
47
88
 
48
- it("should error without a script name", async () => {
49
- let error: Error | undefined;
50
- try {
51
- await runWrangler("secret put the-key");
52
- } catch (e) {
53
- error = e;
54
- }
55
- expect(std.out).toMatchInlineSnapshot(`""`);
56
- expect(std.err).toMatchInlineSnapshot(`
57
- "Missing script name
89
+ expect(std.out).toMatchInlineSnapshot(`
90
+ "🌀 Creating the secret for script script-name
91
+ ✨ Success! Uploaded secret the-key"
92
+ `);
93
+ expect(std.err).toMatchInlineSnapshot(`""`);
94
+ });
58
95
 
59
- %s
60
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
61
- `);
62
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
96
+ it("should create a secret: legacy envs", async () => {
97
+ mockPrompt({
98
+ text: "Enter a secret value:",
99
+ type: "password",
100
+ result: "the-secret",
101
+ });
102
+
103
+ mockPutRequest(
104
+ { name: "the-key", text: "the-secret" },
105
+ "some-env",
106
+ true
107
+ );
108
+ await runWrangler(
109
+ "secret put the-key --name script-name --env some-env --legacy-env"
110
+ );
111
+
112
+ expect(std.out).toMatchInlineSnapshot(`
113
+ "🌀 Creating the secret for script script-name-some-env
114
+ ✨ Success! Uploaded secret the-key"
115
+ `);
116
+ expect(std.err).toMatchInlineSnapshot(`""`);
117
+ });
118
+
119
+ it("should create a secret: service envs", async () => {
120
+ mockPrompt({
121
+ text: "Enter a secret value:",
122
+ type: "password",
123
+ result: "the-secret",
124
+ });
125
+
126
+ mockPutRequest(
127
+ { name: "the-key", text: "the-secret" },
128
+ "some-env",
129
+ false
130
+ );
131
+ await runWrangler(
132
+ "secret put the-key --name script-name --env some-env --legacy-env false"
133
+ );
134
+
135
+ expect(std.out).toMatchInlineSnapshot(`
136
+ "🌀 Creating the secret for script script-name (some-env)
137
+ ✨ Success! Uploaded secret the-key"
138
+ `);
139
+ expect(std.err).toMatchInlineSnapshot(`""`);
140
+ });
141
+
142
+ it("should error without a script name", async () => {
143
+ let error: Error | undefined;
144
+ try {
145
+ await runWrangler("secret put the-key");
146
+ } catch (e) {
147
+ error = e as Error;
148
+ }
149
+ expect(std.out).toMatchInlineSnapshot(`
150
+ "
151
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
152
+ `);
153
+ expect(std.err).toMatchInlineSnapshot(`
154
+ "X [ERROR] Missing script name
155
+
156
+ "
157
+ `);
158
+ expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
159
+ });
63
160
  });
64
161
 
65
- it("warns about being a no-op in local mode", async () => {
66
- mockPrompt({
67
- text: "Enter a secret value:",
68
- type: "password",
69
- result: "the-secret",
162
+ describe("non-interactive", () => {
163
+ const mockStdIn = useMockStdin({ isTTY: false });
164
+
165
+ it("should trim stdin secret value, from piped input", async () => {
166
+ mockPutRequest({ name: "the-key", text: "the-secret" });
167
+ // Pipe the secret in as three chunks to test that we reconstitute it correctly.
168
+ mockStdIn.send(
169
+ `the`,
170
+ `-`,
171
+ `secret
172
+ ` // whitespace & newline being removed
173
+ );
174
+ await runWrangler("secret put the-key --name script-name");
175
+
176
+ expect(std.out).toMatchInlineSnapshot(`
177
+ "🌀 Creating the secret for script script-name
178
+ ✨ Success! Uploaded secret the-key"
179
+ `);
180
+ expect(std.warn).toMatchInlineSnapshot(`""`);
181
+ expect(std.err).toMatchInlineSnapshot(`""`);
70
182
  });
71
183
 
72
- mockPutRequest({ name: "the-secret-name", text: "the-secret" });
73
- await runWrangler("secret put the-key --name script-name --local");
74
- expect(std.out).toMatchInlineSnapshot(`""`);
75
- expect(std.err).toMatchInlineSnapshot(`""`);
76
- expect(std.warn).toMatchInlineSnapshot(
77
- `"\`wrangler secret put\` is a no-op in --local mode"`
78
- );
184
+ it("should create a secret, from piped input", async () => {
185
+ mockPutRequest({ name: "the-key", text: "the-secret" });
186
+ // Pipe the secret in as three chunks to test that we reconstitute it correctly.
187
+ mockStdIn.send("the", "-", "secret");
188
+ await runWrangler("secret put the-key --name script-name");
189
+
190
+ expect(std.out).toMatchInlineSnapshot(`
191
+ "🌀 Creating the secret for script script-name
192
+ ✨ Success! Uploaded secret the-key"
193
+ `);
194
+ expect(std.warn).toMatchInlineSnapshot(`""`);
195
+ expect(std.err).toMatchInlineSnapshot(`""`);
196
+ });
197
+
198
+ it("should error if the piped input fails", async () => {
199
+ mockPutRequest({ name: "the-key", text: "the-secret" });
200
+ mockStdIn.throwError(new Error("Error in stdin stream"));
201
+ await expect(
202
+ runWrangler("secret put the-key --name script-name")
203
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`"Error in stdin stream"`);
204
+
205
+ expect(std.out).toMatchInlineSnapshot(`
206
+ "
207
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
208
+ `);
209
+ expect(std.warn).toMatchInlineSnapshot(`""`);
210
+ });
211
+
212
+ describe("with accountId", () => {
213
+ mockAccountId({ accountId: null });
214
+
215
+ it("should error if a user has no account", async () => {
216
+ mockGetMemberships({
217
+ success: false,
218
+ result: [],
219
+ });
220
+ await expect(
221
+ runWrangler("secret put the-key --name script-name")
222
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
223
+ `"Failed to automatically retrieve account IDs for the logged in user. 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."`
224
+ );
225
+ });
226
+
227
+ it("should use the account from wrangler.toml", async () => {
228
+ fs.writeFileSync(
229
+ "wrangler.toml",
230
+ TOML.stringify({
231
+ account_id: "some-account-id",
232
+ }),
233
+ "utf-8"
234
+ );
235
+ mockStdIn.send("the-secret");
236
+ mockPutRequest({ name: "the-key", text: "the-secret" });
237
+ await runWrangler("secret put the-key --name script-name");
238
+ expect(std.out).toMatchInlineSnapshot(`
239
+ "🌀 Creating the secret for script script-name
240
+ ✨ Success! Uploaded secret the-key"
241
+ `);
242
+ expect(std.warn).toMatchInlineSnapshot(`""`);
243
+ expect(std.err).toMatchInlineSnapshot(`""`);
244
+ });
245
+
246
+ it("should error if a user has multiple accounts, and has not specified an account in wrangler.toml", async () => {
247
+ mockGetMemberships({
248
+ success: true,
249
+ result: [
250
+ {
251
+ id: "1",
252
+ account: { id: "account-id-1", name: "account-name-1" },
253
+ },
254
+ {
255
+ id: "2",
256
+ account: { id: "account-id-2", name: "account-name-2" },
257
+ },
258
+ {
259
+ id: "3",
260
+ account: { id: "account-id-3", name: "account-name-3" },
261
+ },
262
+ ],
263
+ });
264
+
265
+ await expect(runWrangler("secret put the-key --name script-name"))
266
+ .rejects.toThrowErrorMatchingInlineSnapshot(`
267
+ "More than one account available but unable to select one in non-interactive mode.
268
+ Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
269
+ Available accounts are (\\"<name>\\" - \\"<id>\\"):
270
+ \\"account-name-1\\" - \\"account-id-1\\")
271
+ \\"account-name-2\\" - \\"account-id-2\\")
272
+ \\"account-name-3\\" - \\"account-id-3\\")"
273
+ `);
274
+ });
275
+ });
79
276
  });
80
277
  });
81
278
 
82
279
  describe("delete", () => {
83
- function mockDeleteRequest(input: {
84
- scriptName: string;
85
- secretName: string;
86
- }) {
280
+ function mockDeleteRequest(
281
+ input: {
282
+ scriptName: string;
283
+ secretName: string;
284
+ },
285
+ env?: string,
286
+ legacyEnv = false
287
+ ) {
288
+ const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
289
+ const environment = env && !legacyEnv ? "/environments/:envName" : "";
87
290
  setMockResponse(
88
- "/accounts/:accountId/workers/scripts/:scriptName/secrets/:secretName",
291
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets/:secretName`,
89
292
  "DELETE",
90
- ([_url, accountId, scriptName, secretName]) => {
293
+ ([_url, accountId, scriptName, envOrSecretName, secretName]) => {
91
294
  expect(accountId).toEqual("some-account-id");
92
- expect(scriptName).toEqual(input.scriptName);
93
- expect(secretName).toEqual(input.secretName);
94
-
295
+ expect(scriptName).toEqual(
296
+ legacyEnv && env ? `script-name-${env}` : "script-name"
297
+ );
298
+ if (!legacyEnv) {
299
+ if (env) {
300
+ expect(envOrSecretName).toEqual(env);
301
+ expect(secretName).toEqual(input.secretName);
302
+ } else {
303
+ expect(envOrSecretName).toEqual(input.secretName);
304
+ }
305
+ } else {
306
+ expect(envOrSecretName).toEqual(input.secretName);
307
+ }
95
308
  return null;
96
309
  }
97
310
  );
@@ -104,7 +317,46 @@ describe("wrangler secret", () => {
104
317
  });
105
318
  await runWrangler("secret delete the-key --name script-name");
106
319
  expect(std.out).toMatchInlineSnapshot(`
107
- "🌀 Deleting the secret the-key on script script-name.
320
+ "🌀 Deleting the secret the-key on script script-name
321
+ ✨ Success! Deleted secret the-key"
322
+ `);
323
+ expect(std.err).toMatchInlineSnapshot(`""`);
324
+ });
325
+
326
+ it("should delete a secret: legacy envs", async () => {
327
+ mockDeleteRequest(
328
+ { scriptName: "script-name", secretName: "the-key" },
329
+ "some-env",
330
+ true
331
+ );
332
+ mockConfirm({
333
+ text: "Are you sure you want to permanently delete the variable the-key on the script script-name-some-env?",
334
+ result: true,
335
+ });
336
+ await runWrangler(
337
+ "secret delete the-key --name script-name --env some-env --legacy-env"
338
+ );
339
+ expect(std.out).toMatchInlineSnapshot(`
340
+ "🌀 Deleting the secret the-key on script script-name-some-env
341
+ ✨ Success! Deleted secret the-key"
342
+ `);
343
+ expect(std.err).toMatchInlineSnapshot(`""`);
344
+ });
345
+
346
+ it("should delete a secret: service envs", async () => {
347
+ mockDeleteRequest(
348
+ { scriptName: "script-name", secretName: "the-key" },
349
+ "some-env"
350
+ );
351
+ mockConfirm({
352
+ text: "Are you sure you want to permanently delete the variable the-key on the script script-name (some-env)?",
353
+ result: true,
354
+ });
355
+ await runWrangler(
356
+ "secret delete the-key --name script-name --env some-env --legacy-env false"
357
+ );
358
+ expect(std.out).toMatchInlineSnapshot(`
359
+ "🌀 Deleting the secret the-key on script script-name (some-env)
108
360
  ✨ Success! Deleted secret the-key"
109
361
  `);
110
362
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -116,42 +368,40 @@ describe("wrangler secret", () => {
116
368
  try {
117
369
  await runWrangler("secret delete the-key");
118
370
  } catch (e) {
119
- error = e;
371
+ error = e as Error;
120
372
  }
121
- expect(std.out).toMatchInlineSnapshot(`""`);
373
+ expect(std.out).toMatchInlineSnapshot(`
374
+ "
375
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
376
+ `);
122
377
  expect(std.err).toMatchInlineSnapshot(`
123
- "Missing script name
378
+ "X [ERROR] Missing script name
124
379
 
125
- %s
126
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
380
+ "
127
381
  `);
128
382
  expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
129
383
  });
130
-
131
- it("warns about being a no-op in local mode", async () => {
132
- mockConfirm({
133
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
134
- result: true,
135
- });
136
- await runWrangler("secret delete the-key --name script-name --local");
137
- expect(std.out).toMatchInlineSnapshot(
138
- `"🌀 Deleting the secret the-key on script script-name."`
139
- );
140
- expect(std.err).toMatchInlineSnapshot(`""`);
141
- expect(std.warn).toMatchInlineSnapshot(
142
- `"\`wrangler secret delete\` is a no-op in --local mode"`
143
- );
144
- });
145
384
  });
146
385
 
147
386
  describe("list", () => {
148
- function mockListRequest(input: { scriptName: string }) {
387
+ function mockListRequest(
388
+ input: { scriptName: string },
389
+ env?: string,
390
+ legacyEnv = false
391
+ ) {
392
+ const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
393
+ const environment = env && !legacyEnv ? "/environments/:envName" : "";
149
394
  setMockResponse(
150
- "/accounts/:accountId/workers/scripts/:scriptName/secrets",
395
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
151
396
  "GET",
152
- ([_url, accountId, scriptName]) => {
397
+ ([_url, accountId, scriptName, envName]) => {
153
398
  expect(accountId).toEqual("some-account-id");
154
- expect(scriptName).toEqual(input.scriptName);
399
+ expect(scriptName).toEqual(
400
+ legacyEnv && env ? `script-name-${env}` : "script-name"
401
+ );
402
+ if (!legacyEnv) {
403
+ expect(envName).toEqual(env);
404
+ }
155
405
 
156
406
  return [
157
407
  {
@@ -177,30 +427,55 @@ describe("wrangler secret", () => {
177
427
  expect(std.err).toMatchInlineSnapshot(`""`);
178
428
  });
179
429
 
430
+ it("should list secrets: legacy envs", async () => {
431
+ mockListRequest({ scriptName: "script-name" }, "some-env", true);
432
+ await runWrangler(
433
+ "secret list --name script-name --env some-env --legacy-env"
434
+ );
435
+ expect(std.out).toMatchInlineSnapshot(`
436
+ "[
437
+ {
438
+ \\"name\\": \\"the-secret-name\\",
439
+ \\"type\\": \\"secret_text\\"
440
+ }
441
+ ]"
442
+ `);
443
+ expect(std.err).toMatchInlineSnapshot(`""`);
444
+ });
445
+
446
+ it("should list secrets: service envs", async () => {
447
+ mockListRequest({ scriptName: "script-name" }, "some-env");
448
+ await runWrangler(
449
+ "secret list --name script-name --env some-env --legacy-env false"
450
+ );
451
+ expect(std.out).toMatchInlineSnapshot(`
452
+ "[
453
+ {
454
+ \\"name\\": \\"the-secret-name\\",
455
+ \\"type\\": \\"secret_text\\"
456
+ }
457
+ ]"
458
+ `);
459
+ expect(std.err).toMatchInlineSnapshot(`""`);
460
+ });
461
+
180
462
  it("should error without a script name", async () => {
181
463
  let error: Error | undefined;
182
464
  try {
183
465
  await runWrangler("secret list");
184
466
  } catch (e) {
185
- error = e;
467
+ error = e as Error;
186
468
  }
187
- expect(std.out).toMatchInlineSnapshot(`""`);
469
+ expect(std.out).toMatchInlineSnapshot(`
470
+ "
471
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
472
+ `);
188
473
  expect(std.err).toMatchInlineSnapshot(`
189
- "Missing script name
474
+ "X [ERROR] Missing script name
190
475
 
191
- %s
192
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
476
+ "
193
477
  `);
194
478
  expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
195
479
  });
196
-
197
- it("warns about being a no-op in local mode", async () => {
198
- await runWrangler("secret list --name script-name --local");
199
- expect(std.out).toMatchInlineSnapshot(`""`);
200
- expect(std.err).toMatchInlineSnapshot(`""`);
201
- expect(std.warn).toMatchInlineSnapshot(
202
- `"\`wrangler secret list\` is a no-op in --local mode"`
203
- );
204
- });
205
480
  });
206
481
  });