wrangler 0.0.0-e492c10 → 0.0.0-e4abed3e

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 (182) hide show
  1. package/README.md +30 -12
  2. package/bin/wrangler.js +90 -39
  3. package/config-schema.json +3059 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +132 -86
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +2 -3
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +22 -4
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +22 -0
  39. package/templates/tsconfig.json +6 -103
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +26390 -0
  45. package/wrangler-dist/cli.js +201375 -103384
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/miniflare-dist/index.mjs +0 -4886
  52. package/pages/functions/buildPlugin.ts +0 -92
  53. package/pages/functions/buildWorker.ts +0 -138
  54. package/pages/functions/filepath-routing.test.ts +0 -234
  55. package/pages/functions/filepath-routing.ts +0 -189
  56. package/pages/functions/identifiers.ts +0 -78
  57. package/pages/functions/routes.ts +0 -156
  58. package/pages/functions/template-plugin.ts +0 -146
  59. package/pages/functions/template-worker.ts +0 -143
  60. package/src/__tests__/config-cache.test.ts +0 -36
  61. package/src/__tests__/configuration.test.ts +0 -3125
  62. package/src/__tests__/dev.test.tsx +0 -827
  63. package/src/__tests__/guess-worker-format.test.ts +0 -85
  64. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  65. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  66. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  67. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  68. package/src/__tests__/helpers/mock-bin.ts +0 -36
  69. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  70. package/src/__tests__/helpers/mock-console.ts +0 -87
  71. package/src/__tests__/helpers/mock-dialogs.ts +0 -90
  72. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  73. package/src/__tests__/helpers/mock-istty.ts +0 -27
  74. package/src/__tests__/helpers/mock-kv.ts +0 -33
  75. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -255
  76. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  77. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  78. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  79. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  80. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  81. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  82. package/src/__tests__/https-options.test.ts +0 -130
  83. package/src/__tests__/index.test.ts +0 -242
  84. package/src/__tests__/init.test.ts +0 -1516
  85. package/src/__tests__/jest.setup.ts +0 -77
  86. package/src/__tests__/kv.test.ts +0 -1442
  87. package/src/__tests__/logger.test.ts +0 -115
  88. package/src/__tests__/package-manager.test.ts +0 -206
  89. package/src/__tests__/pages.test.ts +0 -327
  90. package/src/__tests__/parse.test.ts +0 -326
  91. package/src/__tests__/publish.test.ts +0 -4948
  92. package/src/__tests__/r2.test.ts +0 -210
  93. package/src/__tests__/route.test.ts +0 -45
  94. package/src/__tests__/secret.test.ts +0 -446
  95. package/src/__tests__/tail.test.ts +0 -690
  96. package/src/__tests__/user.test.ts +0 -131
  97. package/src/__tests__/whoami.test.tsx +0 -105
  98. package/src/bundle.ts +0 -169
  99. package/src/cfetch/index.ts +0 -104
  100. package/src/cfetch/internal.ts +0 -137
  101. package/src/cli.ts +0 -13
  102. package/src/config/README.md +0 -107
  103. package/src/config/config.ts +0 -234
  104. package/src/config/diagnostics.ts +0 -80
  105. package/src/config/environment.ts +0 -394
  106. package/src/config/index.ts +0 -63
  107. package/src/config/validation-helpers.ts +0 -575
  108. package/src/config/validation.ts +0 -1424
  109. package/src/config-cache.ts +0 -45
  110. package/src/create-worker-preview.ts +0 -175
  111. package/src/create-worker-upload-form.ts +0 -240
  112. package/src/dev/dev-vars.ts +0 -36
  113. package/src/dev/dev.tsx +0 -418
  114. package/src/dev/local.tsx +0 -312
  115. package/src/dev/remote.tsx +0 -213
  116. package/src/dev/use-esbuild.ts +0 -118
  117. package/src/dialogs.tsx +0 -87
  118. package/src/entry.ts +0 -267
  119. package/src/environment-variables.ts +0 -35
  120. package/src/errors.ts +0 -11
  121. package/src/https-options.ts +0 -123
  122. package/src/index.tsx +0 -2698
  123. package/src/inspect.ts +0 -623
  124. package/src/intl-polyfill.d.ts +0 -139
  125. package/src/kv.ts +0 -319
  126. package/src/logger.ts +0 -66
  127. package/src/miniflare-cli/README.md +0 -30
  128. package/src/miniflare-cli/enum-keys.ts +0 -17
  129. package/src/miniflare-cli/index.ts +0 -41
  130. package/src/miniflare-cli/request-context.ts +0 -40
  131. package/src/module-collection.ts +0 -258
  132. package/src/open-in-browser.ts +0 -26
  133. package/src/package-manager.ts +0 -127
  134. package/src/pages.tsx +0 -1875
  135. package/src/parse.ts +0 -185
  136. package/src/paths.ts +0 -26
  137. package/src/proxy.ts +0 -449
  138. package/src/publish.ts +0 -469
  139. package/src/r2.ts +0 -50
  140. package/src/selfsigned.d.ts +0 -29
  141. package/src/sites.tsx +0 -293
  142. package/src/tail/filters.ts +0 -279
  143. package/src/tail/index.ts +0 -299
  144. package/src/tail/printing.ts +0 -67
  145. package/src/update-check.ts +0 -19
  146. package/src/user.tsx +0 -1203
  147. package/src/whoami.tsx +0 -70
  148. package/src/worker.ts +0 -172
  149. package/templates/static-asset-facade.js +0 -47
  150. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  151. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  152. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  153. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  154. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  155. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  156. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  157. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  158. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  159. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  160. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  161. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  162. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  163. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  164. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  165. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  166. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  167. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  168. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  169. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  170. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  171. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  172. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  173. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  174. package/vendor/wrangler-mime/LICENSE +0 -21
  175. package/vendor/wrangler-mime/Mime.js +0 -97
  176. package/vendor/wrangler-mime/README.md +0 -187
  177. package/vendor/wrangler-mime/cli.js +0 -46
  178. package/vendor/wrangler-mime/index.js +0 -4
  179. package/vendor/wrangler-mime/lite.js +0 -4
  180. package/vendor/wrangler-mime/package.json +0 -52
  181. package/vendor/wrangler-mime/types/other.js +0 -1
  182. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -1,210 +0,0 @@
1
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
3
- import { mockConsoleMethods } from "./helpers/mock-console";
4
- import { runInTempDir } from "./helpers/run-in-tmp";
5
- import { runWrangler } from "./helpers/run-wrangler";
6
- import type { R2BucketInfo } from "../r2";
7
-
8
- describe("wrangler", () => {
9
- mockAccountId();
10
- mockApiToken();
11
- runInTempDir();
12
- const std = mockConsoleMethods();
13
-
14
- afterEach(() => {
15
- unsetAllMocks();
16
- });
17
-
18
- describe("r2", () => {
19
- describe("bucket", () => {
20
- describe("list", () => {
21
- function mockListRequest(buckets: R2BucketInfo[]) {
22
- const requests = { count: 0 };
23
- setMockResponse(
24
- "/accounts/:accountId/r2/buckets",
25
- ([_url, accountId], init) => {
26
- requests.count++;
27
- expect(accountId).toEqual("some-account-id");
28
- expect(init).toEqual({});
29
- return { buckets };
30
- }
31
- );
32
- return requests;
33
- }
34
-
35
- it("should list buckets", async () => {
36
- const expectedBuckets: R2BucketInfo[] = [
37
- { name: "bucket-1", creation_date: "01-01-2001" },
38
- { name: "bucket-2", creation_date: "01-01-2001" },
39
- ];
40
- mockListRequest(expectedBuckets);
41
- await runWrangler("r2 bucket list");
42
-
43
- expect(std.err).toMatchInlineSnapshot(`""`);
44
- const buckets = JSON.parse(std.out);
45
- expect(buckets).toEqual(expectedBuckets);
46
- });
47
- });
48
-
49
- describe("create", () => {
50
- function mockCreateRequest(expectedBucketName: string) {
51
- const requests = { count: 0 };
52
- setMockResponse(
53
- "/accounts/:accountId/r2/buckets/:bucketName",
54
- "PUT",
55
- ([_url, accountId, bucketName]) => {
56
- expect(accountId).toEqual("some-account-id");
57
- expect(bucketName).toEqual(expectedBucketName);
58
- requests.count += 1;
59
- }
60
- );
61
- return requests;
62
- }
63
-
64
- it("should error if no bucket name is given", async () => {
65
- await expect(
66
- runWrangler("r2 bucket create")
67
- ).rejects.toThrowErrorMatchingInlineSnapshot(
68
- `"Not enough non-option arguments: got 0, need at least 1"`
69
- );
70
- expect(std.out).toMatchInlineSnapshot(`
71
- "
72
- "
73
- `);
74
- expect(std.err).toMatchInlineSnapshot(`
75
- "wrangler r2 bucket create <name>
76
-
77
- Create a new R2 bucket
78
-
79
- Positionals:
80
- name The name of the new bucket [string] [required]
81
-
82
- Flags:
83
- -c, --config Path to .toml configuration file [string]
84
- -h, --help Show help [boolean]
85
- -v, --version Show version number [boolean]
86
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
87
-
88
- "
89
- `);
90
- });
91
-
92
- it("should error if the bucket to create contains spaces", async () => {
93
- await expect(
94
- runWrangler("r2 bucket create abc def ghi")
95
- ).rejects.toThrowErrorMatchingInlineSnapshot(
96
- `"Unknown arguments: def, ghi"`
97
- );
98
- expect(std.out).toMatchInlineSnapshot(`
99
- "
100
- "
101
- `);
102
- expect(std.err).toMatchInlineSnapshot(`
103
- "wrangler r2 bucket create <name>
104
-
105
- Create a new R2 bucket
106
-
107
- Positionals:
108
- name The name of the new bucket [string] [required]
109
-
110
- Flags:
111
- -c, --config Path to .toml configuration file [string]
112
- -h, --help Show help [boolean]
113
- -v, --version Show version number [boolean]
114
- X [ERROR] Unknown arguments: def, ghi
115
-
116
- "
117
- `);
118
- });
119
-
120
- it("should create a bucket", async () => {
121
- const requests = mockCreateRequest("testBucket");
122
- await runWrangler("r2 bucket create testBucket");
123
- expect(std.out).toMatchInlineSnapshot(`
124
- "Creating bucket testBucket.
125
- Created bucket testBucket."
126
- `);
127
- expect(requests.count).toEqual(1);
128
- });
129
- });
130
-
131
- describe("delete", () => {
132
- function mockDeleteRequest(expectedBucketName: string) {
133
- const requests = { count: 0 };
134
- setMockResponse(
135
- "/accounts/:accountId/r2/buckets/:bucketName",
136
- "DELETE",
137
- ([_url, accountId, bucketName]) => {
138
- expect(accountId).toEqual("some-account-id");
139
- expect(bucketName).toEqual(expectedBucketName);
140
- requests.count += 1;
141
- }
142
- );
143
- return requests;
144
- }
145
-
146
- it("should error if no bucket name is given", async () => {
147
- await expect(
148
- runWrangler("r2 bucket delete")
149
- ).rejects.toThrowErrorMatchingInlineSnapshot(
150
- `"Not enough non-option arguments: got 0, need at least 1"`
151
- );
152
- expect(std.out).toMatchInlineSnapshot(`
153
- "
154
- "
155
- `);
156
- expect(std.err).toMatchInlineSnapshot(`
157
- "wrangler r2 bucket delete <name>
158
-
159
- Delete an R2 bucket
160
-
161
- Positionals:
162
- name The name of the bucket to delete [string] [required]
163
-
164
- Flags:
165
- -c, --config Path to .toml configuration file [string]
166
- -h, --help Show help [boolean]
167
- -v, --version Show version number [boolean]
168
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
169
-
170
- "
171
- `);
172
- });
173
-
174
- it("should error if the bucket name to delete contains spaces", async () => {
175
- await expect(
176
- runWrangler("r2 bucket delete abc def ghi")
177
- ).rejects.toThrowErrorMatchingInlineSnapshot(
178
- `"Unknown arguments: def, ghi"`
179
- );
180
- expect(std.out).toMatchInlineSnapshot(`
181
- "
182
- "
183
- `);
184
- expect(std.err).toMatchInlineSnapshot(`
185
- "wrangler r2 bucket delete <name>
186
-
187
- Delete an R2 bucket
188
-
189
- Positionals:
190
- name The name of the bucket to delete [string] [required]
191
-
192
- Flags:
193
- -c, --config Path to .toml configuration file [string]
194
- -h, --help Show help [boolean]
195
- -v, --version Show version number [boolean]
196
- X [ERROR] Unknown arguments: def, ghi
197
-
198
- "
199
- `);
200
- });
201
-
202
- it("should delete a bucket specified by name", async () => {
203
- const requests = mockDeleteRequest("some-bucket");
204
- await runWrangler(`r2 bucket delete some-bucket`);
205
- expect(requests.count).toEqual(1);
206
- });
207
- });
208
- });
209
- });
210
- });
@@ -1,45 +0,0 @@
1
- import { mockConsoleMethods } from "./helpers/mock-console";
2
- import { runInTempDir } from "./helpers/run-in-tmp";
3
- import { runWrangler } from "./helpers/run-wrangler";
4
-
5
- describe("wrangler route", () => {
6
- mockConsoleMethods();
7
- runInTempDir();
8
-
9
- it("shows a deprecation notice when `wrangler route` is run", async () => {
10
- await expect(runWrangler("route")).rejects
11
- .toThrowErrorMatchingInlineSnapshot(`
12
- "Deprecation:
13
- \`wrangler route\` has been deprecated.
14
- Please use wrangler.toml and/or \`wrangler publish --routes\` to modify routes"
15
- `);
16
- });
17
-
18
- it("shows a deprecation notice when `wrangler route delete` is run", async () => {
19
- await expect(runWrangler("route delete")).rejects
20
- .toThrowErrorMatchingInlineSnapshot(`
21
- "Deprecation:
22
- \`wrangler route delete\` has been deprecated.
23
- Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
24
- `);
25
- });
26
-
27
- it("shows a deprecation notice when `wrangler route delete <id>` is run", async () => {
28
- await expect(runWrangler("route delete some-zone-id")).rejects
29
- .toThrowErrorMatchingInlineSnapshot(`
30
- "Deprecation:
31
- \`wrangler route delete\` has been deprecated.
32
- Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
33
- `);
34
- });
35
-
36
- it("shows a deprecation notice when `wrangler route list` is run", async () => {
37
- await expect(runWrangler("route list")).rejects
38
- .toThrowErrorMatchingInlineSnapshot(`
39
- "Deprecation:
40
- \`wrangler route list\` has been deprecated.
41
- Refer to wrangler.toml for a list of routes the worker will be deployed to upon publishing.
42
- Refer to the Cloudflare Dashboard to see the routes this worker is currently running on."
43
- `);
44
- });
45
- });
@@ -1,446 +0,0 @@
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";
16
-
17
- describe("wrangler secret", () => {
18
- const std = mockConsoleMethods();
19
- const { mockGetMemberships } = mockOAuthFlow();
20
-
21
- runInTempDir();
22
- mockAccountId();
23
- mockApiToken();
24
-
25
- afterEach(() => {
26
- unsetAllMocks();
27
- clearConfirmMocks();
28
- clearPromptMocks();
29
- });
30
-
31
- describe("put", () => {
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" : "";
39
- setMockResponse(
40
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
41
- "PUT",
42
- ([_url, accountId, scriptName, envName], { body }) => {
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
- }
50
- const { name, text, type } = JSON.parse(body as string);
51
- expect(type).toEqual("secret_text");
52
- expect(name).toEqual(input.name);
53
- expect(text).toEqual(input.text);
54
-
55
- return { name, type };
56
- }
57
- );
58
- }
59
-
60
- describe("interactive", () => {
61
- useMockStdin({ isTTY: true });
62
-
63
- it("should create a secret", async () => {
64
- mockPrompt({
65
- text: "Enter a secret value:",
66
- type: "password",
67
- result: "the-secret",
68
- });
69
-
70
- mockPutRequest({ name: "the-key", text: "the-secret" });
71
- await runWrangler("secret put the-key --name script-name");
72
-
73
- expect(std.out).toMatchInlineSnapshot(`
74
- "🌀 Creating the secret for script script-name
75
- ✨ Success! Uploaded secret the-key"
76
- `);
77
- expect(std.err).toMatchInlineSnapshot(`""`);
78
- });
79
-
80
- it("should create a secret: legacy envs", async () => {
81
- mockPrompt({
82
- text: "Enter a secret value:",
83
- type: "password",
84
- result: "the-secret",
85
- });
86
-
87
- mockPutRequest(
88
- { name: "the-key", text: "the-secret" },
89
- "some-env",
90
- true
91
- );
92
- await runWrangler(
93
- "secret put the-key --name script-name --env some-env --legacy-env"
94
- );
95
-
96
- expect(std.out).toMatchInlineSnapshot(`
97
- "🌀 Creating the secret for script script-name-some-env
98
- ✨ Success! Uploaded secret the-key"
99
- `);
100
- expect(std.err).toMatchInlineSnapshot(`""`);
101
- });
102
-
103
- it("should create a secret: service envs", async () => {
104
- mockPrompt({
105
- text: "Enter a secret value:",
106
- type: "password",
107
- result: "the-secret",
108
- });
109
-
110
- mockPutRequest(
111
- { name: "the-key", text: "the-secret" },
112
- "some-env",
113
- false
114
- );
115
- await runWrangler(
116
- "secret put the-key --name script-name --env some-env --legacy-env false"
117
- );
118
-
119
- expect(std.out).toMatchInlineSnapshot(`
120
- "🌀 Creating the secret for script script-name (some-env)
121
- ✨ Success! Uploaded secret the-key"
122
- `);
123
- expect(std.err).toMatchInlineSnapshot(`""`);
124
- });
125
-
126
- it("should error without a script name", async () => {
127
- let error: Error | undefined;
128
- try {
129
- await runWrangler("secret put the-key");
130
- } catch (e) {
131
- error = e as Error;
132
- }
133
- expect(std.out).toMatchInlineSnapshot(`
134
- "
135
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
136
- `);
137
- expect(std.err).toMatchInlineSnapshot(`
138
- "X [ERROR] Missing script name
139
-
140
- "
141
- `);
142
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
143
- });
144
- });
145
-
146
- describe("non-interactive", () => {
147
- const mockStdIn = useMockStdin({ isTTY: false });
148
-
149
- it("should create a secret, from piped input", async () => {
150
- mockPutRequest({ name: "the-key", text: "the-secret" });
151
- // Pipe the secret in as three chunks to test that we reconstitute it correctly.
152
- mockStdIn.send("the", "-", "secret");
153
- await runWrangler("secret put the-key --name script-name");
154
-
155
- expect(std.out).toMatchInlineSnapshot(`
156
- "🌀 Creating the secret for script script-name
157
- ✨ Success! Uploaded secret the-key"
158
- `);
159
- expect(std.warn).toMatchInlineSnapshot(`""`);
160
- expect(std.err).toMatchInlineSnapshot(`""`);
161
- });
162
-
163
- it("should error if the piped input fails", async () => {
164
- mockPutRequest({ name: "the-key", text: "the-secret" });
165
- mockStdIn.throwError(new Error("Error in stdin stream"));
166
- await expect(
167
- runWrangler("secret put the-key --name script-name")
168
- ).rejects.toThrowErrorMatchingInlineSnapshot(`"Error in stdin stream"`);
169
-
170
- expect(std.out).toMatchInlineSnapshot(`
171
- "
172
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
173
- `);
174
- expect(std.warn).toMatchInlineSnapshot(`""`);
175
- });
176
-
177
- describe("with accountId", () => {
178
- mockAccountId({ accountId: null });
179
-
180
- it("should error if a user has no account", async () => {
181
- mockGetMemberships({
182
- success: false,
183
- result: [],
184
- });
185
- await expect(
186
- runWrangler("secret put the-key --name script-name")
187
- ).rejects.toThrowErrorMatchingInlineSnapshot(
188
- `"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."`
189
- );
190
- });
191
-
192
- it("should use the account from wrangler.toml", async () => {
193
- fs.writeFileSync(
194
- "wrangler.toml",
195
- TOML.stringify({
196
- account_id: "some-account-id",
197
- }),
198
- "utf-8"
199
- );
200
- mockStdIn.send("the-secret");
201
- mockPutRequest({ name: "the-key", text: "the-secret" });
202
- await runWrangler("secret put the-key --name script-name");
203
- expect(std.out).toMatchInlineSnapshot(`
204
- "🌀 Creating the secret for script script-name
205
- ✨ Success! Uploaded secret the-key"
206
- `);
207
- expect(std.warn).toMatchInlineSnapshot(`""`);
208
- expect(std.err).toMatchInlineSnapshot(`""`);
209
- });
210
-
211
- it("should error if a user has multiple accounts, and has not specified an account in wrangler.toml", async () => {
212
- mockGetMemberships({
213
- success: true,
214
- result: [
215
- {
216
- id: "1",
217
- account: { id: "account-id-1", name: "account-name-1" },
218
- },
219
- {
220
- id: "2",
221
- account: { id: "account-id-2", name: "account-name-2" },
222
- },
223
- {
224
- id: "3",
225
- account: { id: "account-id-3", name: "account-name-3" },
226
- },
227
- ],
228
- });
229
-
230
- await expect(runWrangler("secret put the-key --name script-name"))
231
- .rejects.toThrowErrorMatchingInlineSnapshot(`
232
- "More than one account available but unable to select one in non-interactive mode.
233
- Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
234
- Available accounts are (\\"<name>\\" - \\"<id>\\"):
235
- \\"account-name-1\\" - \\"account-id-1\\")
236
- \\"account-name-2\\" - \\"account-id-2\\")
237
- \\"account-name-3\\" - \\"account-id-3\\")"
238
- `);
239
- });
240
- });
241
- });
242
- });
243
-
244
- describe("delete", () => {
245
- function mockDeleteRequest(
246
- input: {
247
- scriptName: string;
248
- secretName: string;
249
- },
250
- env?: string,
251
- legacyEnv = false
252
- ) {
253
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
254
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
255
- setMockResponse(
256
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets/:secretName`,
257
- "DELETE",
258
- ([_url, accountId, scriptName, envOrSecretName, secretName]) => {
259
- expect(accountId).toEqual("some-account-id");
260
- expect(scriptName).toEqual(
261
- legacyEnv && env ? `script-name-${env}` : "script-name"
262
- );
263
- if (!legacyEnv) {
264
- if (env) {
265
- expect(envOrSecretName).toEqual(env);
266
- expect(secretName).toEqual(input.secretName);
267
- } else {
268
- expect(envOrSecretName).toEqual(input.secretName);
269
- }
270
- } else {
271
- expect(envOrSecretName).toEqual(input.secretName);
272
- }
273
- return null;
274
- }
275
- );
276
- }
277
- it("should delete a secret", async () => {
278
- mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
279
- mockConfirm({
280
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
281
- result: true,
282
- });
283
- await runWrangler("secret delete the-key --name script-name");
284
- expect(std.out).toMatchInlineSnapshot(`
285
- "🌀 Deleting the secret the-key on script script-name
286
- ✨ Success! Deleted secret the-key"
287
- `);
288
- expect(std.err).toMatchInlineSnapshot(`""`);
289
- });
290
-
291
- it("should delete a secret: legacy envs", async () => {
292
- mockDeleteRequest(
293
- { scriptName: "script-name", secretName: "the-key" },
294
- "some-env",
295
- true
296
- );
297
- mockConfirm({
298
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name-some-env?",
299
- result: true,
300
- });
301
- await runWrangler(
302
- "secret delete the-key --name script-name --env some-env --legacy-env"
303
- );
304
- expect(std.out).toMatchInlineSnapshot(`
305
- "🌀 Deleting the secret the-key on script script-name-some-env
306
- ✨ Success! Deleted secret the-key"
307
- `);
308
- expect(std.err).toMatchInlineSnapshot(`""`);
309
- });
310
-
311
- it("should delete a secret: service envs", async () => {
312
- mockDeleteRequest(
313
- { scriptName: "script-name", secretName: "the-key" },
314
- "some-env"
315
- );
316
- mockConfirm({
317
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name (some-env)?",
318
- result: true,
319
- });
320
- await runWrangler(
321
- "secret delete the-key --name script-name --env some-env --legacy-env false"
322
- );
323
- expect(std.out).toMatchInlineSnapshot(`
324
- "🌀 Deleting the secret the-key on script script-name (some-env)
325
- ✨ Success! Deleted secret the-key"
326
- `);
327
- expect(std.err).toMatchInlineSnapshot(`""`);
328
- });
329
-
330
- it("should error without a script name", async () => {
331
- let error: Error | undefined;
332
-
333
- try {
334
- await runWrangler("secret delete the-key");
335
- } catch (e) {
336
- error = e as Error;
337
- }
338
- expect(std.out).toMatchInlineSnapshot(`
339
- "
340
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
341
- `);
342
- expect(std.err).toMatchInlineSnapshot(`
343
- "X [ERROR] Missing script name
344
-
345
- "
346
- `);
347
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
348
- });
349
- });
350
-
351
- describe("list", () => {
352
- function mockListRequest(
353
- input: { scriptName: string },
354
- env?: string,
355
- legacyEnv = false
356
- ) {
357
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
358
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
359
- setMockResponse(
360
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
361
- "GET",
362
- ([_url, accountId, scriptName, envName]) => {
363
- expect(accountId).toEqual("some-account-id");
364
- expect(scriptName).toEqual(
365
- legacyEnv && env ? `script-name-${env}` : "script-name"
366
- );
367
- if (!legacyEnv) {
368
- expect(envName).toEqual(env);
369
- }
370
-
371
- return [
372
- {
373
- name: "the-secret-name",
374
- type: "secret_text",
375
- },
376
- ];
377
- }
378
- );
379
- }
380
-
381
- it("should list secrets", async () => {
382
- mockListRequest({ scriptName: "script-name" });
383
- await runWrangler("secret list --name script-name");
384
- expect(std.out).toMatchInlineSnapshot(`
385
- "[
386
- {
387
- \\"name\\": \\"the-secret-name\\",
388
- \\"type\\": \\"secret_text\\"
389
- }
390
- ]"
391
- `);
392
- expect(std.err).toMatchInlineSnapshot(`""`);
393
- });
394
-
395
- it("should list secrets: legacy envs", async () => {
396
- mockListRequest({ scriptName: "script-name" }, "some-env", true);
397
- await runWrangler(
398
- "secret list --name script-name --env some-env --legacy-env"
399
- );
400
- expect(std.out).toMatchInlineSnapshot(`
401
- "[
402
- {
403
- \\"name\\": \\"the-secret-name\\",
404
- \\"type\\": \\"secret_text\\"
405
- }
406
- ]"
407
- `);
408
- expect(std.err).toMatchInlineSnapshot(`""`);
409
- });
410
-
411
- it("should list secrets: service envs", async () => {
412
- mockListRequest({ scriptName: "script-name" }, "some-env");
413
- await runWrangler(
414
- "secret list --name script-name --env some-env --legacy-env false"
415
- );
416
- expect(std.out).toMatchInlineSnapshot(`
417
- "[
418
- {
419
- \\"name\\": \\"the-secret-name\\",
420
- \\"type\\": \\"secret_text\\"
421
- }
422
- ]"
423
- `);
424
- expect(std.err).toMatchInlineSnapshot(`""`);
425
- });
426
-
427
- it("should error without a script name", async () => {
428
- let error: Error | undefined;
429
- try {
430
- await runWrangler("secret list");
431
- } catch (e) {
432
- error = e as Error;
433
- }
434
- expect(std.out).toMatchInlineSnapshot(`
435
- "
436
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
437
- `);
438
- expect(std.err).toMatchInlineSnapshot(`
439
- "X [ERROR] Missing script name
440
-
441
- "
442
- `);
443
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
444
- });
445
- });
446
- });