wrangler 0.0.0-e29a241 → 0.0.0-e2a6fa40

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