wrangler 0.0.0-e2a26a0 → 0.0.0-e322475
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.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +54 -27
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +223 -36
- package/pages/functions/filepath-routing.ts +78 -120
- package/pages/functions/routes.ts +13 -17
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +24 -17
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +3548 -0
- package/src/__tests__/dev.test.tsx +1049 -65
- package/src/__tests__/guess-worker-format.test.ts +85 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -8
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +12 -8
- package/src/__tests__/helpers/mock-console.ts +49 -8
- package/src/__tests__/helpers/mock-dialogs.ts +99 -11
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-process.ts +24 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +150 -435
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +75 -5
- package/src/__tests__/kv.test.ts +634 -253
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/package-manager.test.ts +156 -9
- package/src/__tests__/pages.test.ts +754 -0
- package/src/__tests__/parse.test.ts +330 -0
- package/src/__tests__/publish.test.ts +5895 -961
- package/src/__tests__/r2.test.ts +233 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +362 -91
- package/src/__tests__/tail.test.ts +690 -0
- package/src/__tests__/user.test.ts +132 -0
- package/src/__tests__/whoami.test.tsx +60 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +204 -0
- package/src/cfetch/index.ts +27 -8
- package/src/cfetch/internal.ts +75 -34
- package/src/cli.ts +6 -2
- package/src/config/README.md +107 -0
- package/src/config/config.ts +243 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +420 -0
- package/src/config/index.ts +225 -0
- package/src/config/validation-helpers.ts +584 -0
- package/src/config/validation.ts +1580 -0
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +185 -0
- package/src/create-worker-upload-form.ts +254 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +399 -0
- package/src/dev/local.tsx +321 -0
- package/src/dev/remote.tsx +249 -0
- package/src/dev/use-esbuild.ts +112 -0
- package/src/dialogs.tsx +64 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +328 -0
- package/src/environment-variables.ts +35 -0
- package/src/errors.ts +11 -0
- package/src/generate-auth-url.ts +33 -0
- package/src/generate-random-state.ts +16 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1804 -1009
- package/src/inspect.ts +80 -14
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +193 -69
- package/src/logger.ts +73 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +226 -31
- package/src/open-in-browser.ts +17 -0
- package/src/package-manager.ts +79 -25
- package/src/pages.tsx +1131 -84
- package/src/parse.ts +222 -0
- package/src/proxy.ts +176 -70
- package/src/publish.ts +637 -308
- package/src/r2.ts +50 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +185 -57
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +67 -0
- package/src/update-check.ts +19 -0
- package/src/user.tsx +349 -166
- package/src/whoami.tsx +5 -3
- package/src/{api/worker.ts → worker.ts} +65 -39
- package/src/zones.ts +73 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +17 -2
- package/templates/no-op-worker.js +10 -0
- package/templates/static-asset-facade.js +3 -7
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +77463 -75999
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/api/form_data.ts +0 -134
- package/src/api/preview.ts +0 -128
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/tail.tsx +0 -73
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,27 +1,52 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as TOML from "@iarna/toml";
|
|
1
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
2
4
|
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
3
5
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
4
|
-
import {
|
|
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";
|
|
5
14
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
6
15
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
7
16
|
|
|
8
17
|
describe("wrangler secret", () => {
|
|
9
18
|
const std = mockConsoleMethods();
|
|
19
|
+
const { mockGetMemberships } = mockOAuthFlow();
|
|
20
|
+
|
|
10
21
|
runInTempDir();
|
|
11
22
|
mockAccountId();
|
|
12
23
|
mockApiToken();
|
|
13
24
|
|
|
14
25
|
afterEach(() => {
|
|
15
26
|
unsetAllMocks();
|
|
27
|
+
clearConfirmMocks();
|
|
28
|
+
clearPromptMocks();
|
|
16
29
|
});
|
|
17
30
|
|
|
18
31
|
describe("put", () => {
|
|
19
|
-
function mockPutRequest(
|
|
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" : "";
|
|
20
39
|
setMockResponse(
|
|
21
|
-
|
|
40
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
|
|
22
41
|
"PUT",
|
|
23
|
-
([_url, accountId], { body }) => {
|
|
42
|
+
([_url, accountId, scriptName, envName], { body }) => {
|
|
24
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
|
+
}
|
|
25
50
|
const { name, text, type } = JSON.parse(body as string);
|
|
26
51
|
expect(type).toEqual("secret_text");
|
|
27
52
|
expect(name).toEqual(input.name);
|
|
@@ -32,70 +57,254 @@ describe("wrangler secret", () => {
|
|
|
32
57
|
);
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
+
`);
|
|
40
77
|
});
|
|
41
78
|
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
it("should create a secret", async () => {
|
|
80
|
+
mockPrompt({
|
|
81
|
+
text: "Enter a secret value:",
|
|
82
|
+
type: "password",
|
|
83
|
+
result: "the-secret",
|
|
84
|
+
});
|
|
44
85
|
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
✨ Success! Uploaded secret the-key"
|
|
48
|
-
`);
|
|
49
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
50
|
-
});
|
|
86
|
+
mockPutRequest({ name: "the-key", text: "the-secret" });
|
|
87
|
+
await runWrangler("secret put the-key --name script-name");
|
|
51
88
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
60
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
61
|
-
"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
|
+
});
|
|
62
95
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
152
|
+
`);
|
|
153
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
154
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
155
|
+
|
|
156
|
+
"
|
|
157
|
+
`);
|
|
158
|
+
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
159
|
+
});
|
|
67
160
|
});
|
|
68
161
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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(`""`);
|
|
74
182
|
});
|
|
75
183
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
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
|
+
});
|
|
83
276
|
});
|
|
84
277
|
});
|
|
85
278
|
|
|
86
279
|
describe("delete", () => {
|
|
87
|
-
function mockDeleteRequest(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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" : "";
|
|
91
290
|
setMockResponse(
|
|
92
|
-
|
|
291
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets/:secretName`,
|
|
93
292
|
"DELETE",
|
|
94
|
-
([_url, accountId, scriptName, secretName]) => {
|
|
293
|
+
([_url, accountId, scriptName, envOrSecretName, secretName]) => {
|
|
95
294
|
expect(accountId).toEqual("some-account-id");
|
|
96
|
-
expect(scriptName).toEqual(
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
}
|
|
99
308
|
return null;
|
|
100
309
|
}
|
|
101
310
|
);
|
|
@@ -108,7 +317,46 @@ describe("wrangler secret", () => {
|
|
|
108
317
|
});
|
|
109
318
|
await runWrangler("secret delete the-key --name script-name");
|
|
110
319
|
expect(std.out).toMatchInlineSnapshot(`
|
|
111
|
-
"🌀 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)
|
|
112
360
|
✨ Success! Deleted secret the-key"
|
|
113
361
|
`);
|
|
114
362
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -120,42 +368,40 @@ describe("wrangler secret", () => {
|
|
|
120
368
|
try {
|
|
121
369
|
await runWrangler("secret delete the-key");
|
|
122
370
|
} catch (e) {
|
|
123
|
-
error = e;
|
|
371
|
+
error = e as Error;
|
|
124
372
|
}
|
|
125
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
373
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
374
|
+
"
|
|
375
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
376
|
+
`);
|
|
126
377
|
expect(std.err).toMatchInlineSnapshot(`
|
|
127
|
-
"
|
|
378
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
128
379
|
|
|
129
|
-
|
|
130
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
380
|
+
"
|
|
131
381
|
`);
|
|
132
382
|
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
133
383
|
});
|
|
134
|
-
|
|
135
|
-
it("warns about being a no-op in local mode", async () => {
|
|
136
|
-
mockConfirm({
|
|
137
|
-
text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
|
|
138
|
-
result: true,
|
|
139
|
-
});
|
|
140
|
-
await runWrangler("secret delete the-key --name script-name --local");
|
|
141
|
-
expect(std.out).toMatchInlineSnapshot(
|
|
142
|
-
`"🌀 Deleting the secret the-key on script script-name."`
|
|
143
|
-
);
|
|
144
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
145
|
-
expect(std.warn).toMatchInlineSnapshot(
|
|
146
|
-
`"\`wrangler secret delete\` is a no-op in --local mode"`
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
384
|
});
|
|
150
385
|
|
|
151
386
|
describe("list", () => {
|
|
152
|
-
function mockListRequest(
|
|
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" : "";
|
|
153
394
|
setMockResponse(
|
|
154
|
-
|
|
395
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
|
|
155
396
|
"GET",
|
|
156
|
-
([_url, accountId, scriptName]) => {
|
|
397
|
+
([_url, accountId, scriptName, envName]) => {
|
|
157
398
|
expect(accountId).toEqual("some-account-id");
|
|
158
|
-
expect(scriptName).toEqual(
|
|
399
|
+
expect(scriptName).toEqual(
|
|
400
|
+
legacyEnv && env ? `script-name-${env}` : "script-name"
|
|
401
|
+
);
|
|
402
|
+
if (!legacyEnv) {
|
|
403
|
+
expect(envName).toEqual(env);
|
|
404
|
+
}
|
|
159
405
|
|
|
160
406
|
return [
|
|
161
407
|
{
|
|
@@ -181,30 +427,55 @@ describe("wrangler secret", () => {
|
|
|
181
427
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
182
428
|
});
|
|
183
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
|
+
|
|
184
462
|
it("should error without a script name", async () => {
|
|
185
463
|
let error: Error | undefined;
|
|
186
464
|
try {
|
|
187
465
|
await runWrangler("secret list");
|
|
188
466
|
} catch (e) {
|
|
189
|
-
error = e;
|
|
467
|
+
error = e as Error;
|
|
190
468
|
}
|
|
191
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
469
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
470
|
+
"
|
|
471
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
472
|
+
`);
|
|
192
473
|
expect(std.err).toMatchInlineSnapshot(`
|
|
193
|
-
"
|
|
474
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing script name[0m
|
|
194
475
|
|
|
195
|
-
|
|
196
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
476
|
+
"
|
|
197
477
|
`);
|
|
198
478
|
expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
|
|
199
479
|
});
|
|
200
|
-
|
|
201
|
-
it("warns about being a no-op in local mode", async () => {
|
|
202
|
-
await runWrangler("secret list --name script-name --local");
|
|
203
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
204
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
205
|
-
expect(std.warn).toMatchInlineSnapshot(
|
|
206
|
-
`"\`wrangler secret list\` is a no-op in --local mode"`
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
480
|
});
|
|
210
481
|
});
|