wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
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/README.md +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import fetchMock from "jest-fetch-mock";
|
|
2
2
|
import { Request } from "undici";
|
|
3
3
|
import openInBrowser from "../../open-in-browser";
|
|
4
|
-
import {
|
|
5
|
-
createFetchResult,
|
|
6
|
-
setMockRawResponse,
|
|
7
|
-
setMockResponse,
|
|
8
|
-
} from "./mock-cfetch";
|
|
4
|
+
import { setMockResponse } from "./mock-cfetch";
|
|
9
5
|
import { mockHttpServer } from "./mock-http-server";
|
|
10
6
|
|
|
11
7
|
export function mockGetMemberships(
|
|
@@ -16,12 +12,6 @@ export function mockGetMemberships(
|
|
|
16
12
|
});
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
export function mockGetMembershipsFail() {
|
|
20
|
-
setMockRawResponse("/memberships", () => {
|
|
21
|
-
return createFetchResult([], false);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
15
|
// the response to send when wrangler wants an oauth grant
|
|
26
16
|
let oauthGrantResponse: GrantResponseOptions | "timeout" = {};
|
|
27
17
|
|
|
@@ -42,10 +32,13 @@ export const mockOAuthFlow = () => {
|
|
|
42
32
|
* at the OAuth URL, it will automatically trigger the callback URL on the mock HttpServer that
|
|
43
33
|
* we have created as part of the call to `mockOAuthFlow()`.
|
|
44
34
|
*/
|
|
45
|
-
const mockOAuthServerCallback = (
|
|
35
|
+
const mockOAuthServerCallback = (
|
|
36
|
+
respondWith?: "timeout" | "success" | "failure" | GrantResponseOptions
|
|
37
|
+
) => {
|
|
46
38
|
(
|
|
47
39
|
openInBrowser as jest.MockedFunction<typeof openInBrowser>
|
|
48
40
|
).mockImplementation(async (url: string) => {
|
|
41
|
+
if (respondWith) mockGrantAuthorization({ respondWith });
|
|
49
42
|
// We don't support the grant response timing out.
|
|
50
43
|
if (oauthGrantResponse === "timeout") {
|
|
51
44
|
throw "unimplemented";
|
|
@@ -68,6 +61,7 @@ export const mockOAuthFlow = () => {
|
|
|
68
61
|
});
|
|
69
62
|
};
|
|
70
63
|
|
|
64
|
+
//TODO: this can just handled in `mockOAuthServerCallback`
|
|
71
65
|
const mockGrantAuthorization = ({
|
|
72
66
|
respondWith,
|
|
73
67
|
}: {
|
|
@@ -88,16 +82,19 @@ export const mockOAuthFlow = () => {
|
|
|
88
82
|
}
|
|
89
83
|
};
|
|
90
84
|
|
|
91
|
-
const mockRevokeAuthorization = (
|
|
85
|
+
const mockRevokeAuthorization = ({
|
|
86
|
+
domain = "dash.cloudflare.com",
|
|
87
|
+
}: { domain?: string } = {}) => {
|
|
92
88
|
const outcome = {
|
|
93
89
|
actual: new Request("https://example.org"),
|
|
94
|
-
expected: new Request(
|
|
90
|
+
expected: new Request(`https://${domain}/oauth2/revoke`, {
|
|
95
91
|
method: "POST",
|
|
96
92
|
}),
|
|
97
93
|
};
|
|
98
94
|
|
|
99
95
|
fetchMock.mockIf(outcome.expected.url, async (req) => {
|
|
100
|
-
|
|
96
|
+
// TODO: update Miniflare typings to match full undici Request
|
|
97
|
+
outcome.actual = req as unknown as Request;
|
|
101
98
|
return "";
|
|
102
99
|
});
|
|
103
100
|
|
|
@@ -106,18 +103,21 @@ export const mockOAuthFlow = () => {
|
|
|
106
103
|
|
|
107
104
|
const mockGrantAccessToken = ({
|
|
108
105
|
respondWith,
|
|
106
|
+
domain = "dash.cloudflare.com",
|
|
109
107
|
}: {
|
|
110
108
|
respondWith: MockTokenResponse;
|
|
109
|
+
domain?: string;
|
|
111
110
|
}) => {
|
|
112
111
|
const outcome = {
|
|
113
112
|
actual: new Request("https://example.org"),
|
|
114
|
-
expected: new Request(
|
|
113
|
+
expected: new Request(`https://${domain}/oauth2/token`, {
|
|
115
114
|
method: "POST",
|
|
116
115
|
}),
|
|
117
116
|
};
|
|
118
117
|
|
|
119
118
|
fetchMock.mockOnceIf(outcome.expected.url, async (req) => {
|
|
120
|
-
|
|
119
|
+
// TODO: update Miniflare typings to match full undici Request
|
|
120
|
+
outcome.actual = req as unknown as Request;
|
|
121
121
|
return makeTokenResponse(respondWith);
|
|
122
122
|
});
|
|
123
123
|
|
|
@@ -126,49 +126,70 @@ export const mockOAuthFlow = () => {
|
|
|
126
126
|
|
|
127
127
|
const mockExchangeRefreshTokenForAccessToken = ({
|
|
128
128
|
respondWith,
|
|
129
|
+
domain = "dash.cloudlfare.com",
|
|
129
130
|
}: {
|
|
130
131
|
respondWith: "refreshSuccess" | "refreshError" | "badResponse";
|
|
132
|
+
domain?: string;
|
|
131
133
|
}) => {
|
|
132
|
-
fetchMock.mockOnceIf(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
default:
|
|
165
|
-
return "Not a respondWith option for `mockExchangeRefreshTokenForAccessToken`";
|
|
166
|
-
}
|
|
134
|
+
fetchMock.mockOnceIf(`https://${domain}/oauth2/token`, async () => {
|
|
135
|
+
switch (respondWith) {
|
|
136
|
+
case "refreshSuccess":
|
|
137
|
+
return {
|
|
138
|
+
status: 200,
|
|
139
|
+
body: JSON.stringify({
|
|
140
|
+
access_token: "access_token_success_mock",
|
|
141
|
+
expires_in: 1701,
|
|
142
|
+
refresh_token: "refresh_token_success_mock",
|
|
143
|
+
scope: "scope_success_mock",
|
|
144
|
+
token_type: "bearer",
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
case "refreshError":
|
|
148
|
+
return {
|
|
149
|
+
status: 400,
|
|
150
|
+
body: JSON.stringify({
|
|
151
|
+
error: "invalid_request",
|
|
152
|
+
error_description: "error_description_mock",
|
|
153
|
+
error_hint: "error_hint_mock",
|
|
154
|
+
error_verbose: "error_verbose_mock",
|
|
155
|
+
status_code: 400,
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
case "badResponse":
|
|
159
|
+
return {
|
|
160
|
+
status: 400,
|
|
161
|
+
body: `<html> <body> This shouldn't be sent, but should be handled </body> </html>`,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
default:
|
|
165
|
+
return "Not a respondWith option for `mockExchangeRefreshTokenForAccessToken`";
|
|
167
166
|
}
|
|
168
|
-
);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const mockDomainUsesAccess = ({
|
|
171
|
+
usesAccess,
|
|
172
|
+
domain = "dash.cloudflare.com",
|
|
173
|
+
}: {
|
|
174
|
+
usesAccess: boolean;
|
|
175
|
+
domain?: string;
|
|
176
|
+
}) => {
|
|
177
|
+
// If the domain relies upon Cloudflare Access, then a request to the domain
|
|
178
|
+
// will result in a redirect to the `cloudflareaccess.com` domain.
|
|
179
|
+
fetchMock.mockOnceIf(`https://${domain}/`, async () => {
|
|
180
|
+
if (usesAccess) {
|
|
181
|
+
return {
|
|
182
|
+
status: 302,
|
|
183
|
+
headers: { location: "cloudflareaccess.com" },
|
|
184
|
+
};
|
|
185
|
+
} else {
|
|
186
|
+
return { status: 200 };
|
|
187
|
+
}
|
|
188
|
+
});
|
|
169
189
|
};
|
|
170
190
|
|
|
171
191
|
return {
|
|
192
|
+
mockDomainUsesAccess,
|
|
172
193
|
mockGrantAccessToken,
|
|
173
194
|
mockGrantAuthorization,
|
|
174
195
|
mockOAuthServerCallback,
|
|
@@ -5,22 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
let writeSpy: jest.SpyInstance;
|
|
7
7
|
|
|
8
|
-
function captureLastWriteCall(spy: jest.SpyInstance): Buffer {
|
|
8
|
+
function captureLastWriteCall(spy: jest.SpyInstance): Buffer | undefined {
|
|
9
9
|
const calls = spy.mock.calls;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
|
|
11
|
+
// Loop through and find the buffer in calls
|
|
12
|
+
// (we don't know the index of the buffer in the calls array)
|
|
13
|
+
const buffer = calls
|
|
14
|
+
.map((call) => call[0])
|
|
15
|
+
.find((call) => call instanceof Buffer);
|
|
16
|
+
|
|
16
17
|
if (buffer instanceof Buffer) {
|
|
17
18
|
return buffer;
|
|
18
|
-
} else {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Unexpected non-Buffer passed to \`stdout.write()\`: "${JSON.stringify(
|
|
21
|
-
buffer
|
|
22
|
-
)}"`
|
|
23
|
-
);
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
rest.get("*access-protected.com*", (_, response, cxt) => {
|
|
5
|
+
return response.once(
|
|
6
|
+
cxt.status(302),
|
|
7
|
+
cxt.set("location", "access-protected-com.cloudflareaccess.com")
|
|
8
|
+
);
|
|
9
|
+
}),
|
|
10
|
+
rest.get("*not-access-protected.com*", (_, response, cxt) => {
|
|
11
|
+
return response.once(cxt.status(200), cxt.body("OK"));
|
|
12
|
+
}),
|
|
13
|
+
];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
import type { DeploymentListRes } from "../../../../deployments";
|
|
4
|
+
|
|
5
|
+
export const mswSuccessDeployments = [
|
|
6
|
+
rest.get(
|
|
7
|
+
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
8
|
+
(_, response, context) =>
|
|
9
|
+
response.once(
|
|
10
|
+
context.status(200),
|
|
11
|
+
context.json({
|
|
12
|
+
success: true,
|
|
13
|
+
errors: [],
|
|
14
|
+
messages: [],
|
|
15
|
+
result: {
|
|
16
|
+
latest: {
|
|
17
|
+
id: "Galaxy-Class",
|
|
18
|
+
number: "1701-E",
|
|
19
|
+
metadata: {
|
|
20
|
+
author_id: "Picard-Gamma-6-0-7-3",
|
|
21
|
+
author_email: "Jean-Luc-Picard@federation.org",
|
|
22
|
+
source: "wrangler",
|
|
23
|
+
created_on: "2021-01-01T00:00:00.000000Z",
|
|
24
|
+
modified_on: "2021-01-01T00:00:00.000000Z",
|
|
25
|
+
},
|
|
26
|
+
resources: {
|
|
27
|
+
script: "MOCK-TAG",
|
|
28
|
+
bindings: [],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
items: [
|
|
32
|
+
{
|
|
33
|
+
id: "Galaxy-Class",
|
|
34
|
+
number: "1701-E",
|
|
35
|
+
metadata: {
|
|
36
|
+
author_id: "Picard-Gamma-6-0-7-3",
|
|
37
|
+
author_email: "Jean-Luc-Picard@federation.org",
|
|
38
|
+
source: "wrangler",
|
|
39
|
+
created_on: "2021-01-01T00:00:00.000000Z",
|
|
40
|
+
modified_on: "2021-01-01T00:00:00.000000Z",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "Intrepid-Class",
|
|
45
|
+
number: "NCC-74656",
|
|
46
|
+
metadata: {
|
|
47
|
+
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
|
|
48
|
+
author_email: "Kathryn-Janeway@federation.org",
|
|
49
|
+
source: "wrangler",
|
|
50
|
+
created_on: "2021-02-02T00:00:00.000000Z",
|
|
51
|
+
modified_on: "2021-02-02T00:00:00.000000Z",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
} as DeploymentListRes,
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
),
|
|
59
|
+
];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export const mswSuccessNamespacesHandlers = [
|
|
4
|
+
rest.post(
|
|
5
|
+
"*/accounts/:accountId/workers/dispatch/namespaces",
|
|
6
|
+
(_, response, context) => {
|
|
7
|
+
return response.once(
|
|
8
|
+
context.status(200),
|
|
9
|
+
context.json({
|
|
10
|
+
success: true,
|
|
11
|
+
errors: [],
|
|
12
|
+
messages: [],
|
|
13
|
+
result: {
|
|
14
|
+
namespace_id: "some-namespace-id",
|
|
15
|
+
namespace_name: "namespace-name",
|
|
16
|
+
created_on: "2022-06-29T14:30:08.16152Z",
|
|
17
|
+
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
18
|
+
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
19
|
+
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
rest.delete(
|
|
26
|
+
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
27
|
+
(_, response, context) => {
|
|
28
|
+
return response.once(
|
|
29
|
+
context.status(200),
|
|
30
|
+
context.json({
|
|
31
|
+
success: true,
|
|
32
|
+
errors: [],
|
|
33
|
+
messages: [],
|
|
34
|
+
result: null,
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
),
|
|
39
|
+
rest.put(
|
|
40
|
+
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
41
|
+
(_, response, context) => {
|
|
42
|
+
return response.once(
|
|
43
|
+
context.status(200),
|
|
44
|
+
context.json({
|
|
45
|
+
success: true,
|
|
46
|
+
errors: [],
|
|
47
|
+
messages: [],
|
|
48
|
+
result: {
|
|
49
|
+
namespace_id: "some-namespace-id",
|
|
50
|
+
namespace_name: "namespace-name",
|
|
51
|
+
created_on: "2022-06-29T14:30:08.16152Z",
|
|
52
|
+
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
53
|
+
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
54
|
+
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
rest.get(
|
|
61
|
+
"*/accounts/:accountId/workers/dispatch/namespaces/:namespaceName",
|
|
62
|
+
(_, response, context) => {
|
|
63
|
+
return response.once(
|
|
64
|
+
context.status(200),
|
|
65
|
+
context.json({
|
|
66
|
+
success: true,
|
|
67
|
+
errors: [],
|
|
68
|
+
messages: [],
|
|
69
|
+
result: {
|
|
70
|
+
namespace_id: "some-namespace-id",
|
|
71
|
+
namespace_name: "namespace-name",
|
|
72
|
+
created_on: "2022-06-29T14:30:08.16152Z",
|
|
73
|
+
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
74
|
+
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
75
|
+
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
rest.get(
|
|
82
|
+
"*/accounts/:accountId/workers/dispatch/namespaces",
|
|
83
|
+
(_, response, context) => {
|
|
84
|
+
return response.once(
|
|
85
|
+
context.status(200),
|
|
86
|
+
context.json({
|
|
87
|
+
success: true,
|
|
88
|
+
errors: [],
|
|
89
|
+
messages: [],
|
|
90
|
+
result: [
|
|
91
|
+
{
|
|
92
|
+
namespace_id: "some-namespace-id",
|
|
93
|
+
namespace_name: "namespace-name",
|
|
94
|
+
created_on: "2022-06-29T14:30:08.16152Z",
|
|
95
|
+
created_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
96
|
+
modified_on: "2022-06-29T14:30:08.16152Z",
|
|
97
|
+
modified_by: "1fc1df98cc4420fe00367c3ab68c1639",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export const mswSuccessOauthHandlers = [
|
|
4
|
+
rest.all("*/oauth/callback", (_, response, context) => {
|
|
5
|
+
return response.once(
|
|
6
|
+
context.status(200),
|
|
7
|
+
context.json({
|
|
8
|
+
success: true,
|
|
9
|
+
errors: [],
|
|
10
|
+
messages: [],
|
|
11
|
+
code: "test-oauth-code",
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
}),
|
|
15
|
+
// revoke access token
|
|
16
|
+
rest.post("*/oauth2/revoke", (_, response, context) =>
|
|
17
|
+
response.once(context.status(200), context.text(""))
|
|
18
|
+
),
|
|
19
|
+
// exchange (auth code | refresh token) for access token
|
|
20
|
+
rest.post("*/oauth2/token", (_, response, context) => {
|
|
21
|
+
return response.once(
|
|
22
|
+
context.status(200),
|
|
23
|
+
context.json({
|
|
24
|
+
access_token: "test-access-token",
|
|
25
|
+
expires_in: 100000,
|
|
26
|
+
refresh_token: "test-refresh-token",
|
|
27
|
+
scope: "account:read",
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export const mswSuccessR2handlers = [
|
|
4
|
+
// List endpoint r2Buckets
|
|
5
|
+
rest.get("*/accounts/:accountId/r2/buckets", (_, response, context) =>
|
|
6
|
+
response.once(
|
|
7
|
+
context.status(200),
|
|
8
|
+
context.json({
|
|
9
|
+
success: true,
|
|
10
|
+
errors: [],
|
|
11
|
+
messages: [],
|
|
12
|
+
result: {
|
|
13
|
+
buckets: [
|
|
14
|
+
{ name: "bucket-1", creation_date: "01-01-2001" },
|
|
15
|
+
{ name: "bucket-2", creation_date: "01-01-2001" },
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
),
|
|
21
|
+
rest.post("*/accounts/:accountId/r2/buckets", (_, response, context) =>
|
|
22
|
+
response.once(
|
|
23
|
+
context.status(200),
|
|
24
|
+
context.json({ success: true, errors: [], messages: [], result: {} })
|
|
25
|
+
)
|
|
26
|
+
),
|
|
27
|
+
rest.put(
|
|
28
|
+
"*/accounts/:accountId/r2/buckets/:bucketName",
|
|
29
|
+
(_, response, context) =>
|
|
30
|
+
response.once(
|
|
31
|
+
context.status(200),
|
|
32
|
+
context.json({ success: true, errors: [], messages: [], result: {} })
|
|
33
|
+
)
|
|
34
|
+
),
|
|
35
|
+
rest.delete(
|
|
36
|
+
"*/accounts/:accountId/r2/buckets/:bucketName",
|
|
37
|
+
(_, response, context) =>
|
|
38
|
+
response.once(
|
|
39
|
+
context.status(200),
|
|
40
|
+
context.json({ success: true, errors: [], messages: [], result: null })
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
rest.get(
|
|
44
|
+
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
45
|
+
(_, response, context) => {
|
|
46
|
+
const imageBuffer = Buffer.from("wormhole-img.png");
|
|
47
|
+
return response.once(
|
|
48
|
+
context.set("Content-Length", imageBuffer.byteLength.toString()),
|
|
49
|
+
context.set("Content-Type", "image/png"),
|
|
50
|
+
context.status(200),
|
|
51
|
+
context.body(imageBuffer)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
rest.put(
|
|
56
|
+
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
57
|
+
(_, response, context) =>
|
|
58
|
+
response.once(
|
|
59
|
+
context.status(200),
|
|
60
|
+
context.json({
|
|
61
|
+
success: true,
|
|
62
|
+
errors: [],
|
|
63
|
+
messages: [],
|
|
64
|
+
result: {
|
|
65
|
+
accountId: "some-account-id",
|
|
66
|
+
bucketName: "bucketName-object-test",
|
|
67
|
+
objectName: "wormhole-img.png",
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
)
|
|
71
|
+
),
|
|
72
|
+
rest.delete(
|
|
73
|
+
"*/accounts/:accountId/r2/buckets/:bucketName/objects/:objectName",
|
|
74
|
+
(_, response, context) =>
|
|
75
|
+
response.once(
|
|
76
|
+
context.status(200),
|
|
77
|
+
context.json({ success: true, errors: [], messages: [], result: null })
|
|
78
|
+
)
|
|
79
|
+
),
|
|
80
|
+
];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
import type { WorkerMetadata } from "../../../../create-worker-upload-form";
|
|
3
|
+
|
|
4
|
+
const bindings: Record<string, WorkerMetadata["bindings"]> = {
|
|
5
|
+
"durable-object": [
|
|
6
|
+
{
|
|
7
|
+
type: "durable_object_namespace",
|
|
8
|
+
name: "TestDO",
|
|
9
|
+
class_name: "TestDO",
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
const scripts: Record<string, string> = {
|
|
14
|
+
websocket: `new WebSocket("ws://dummy")`,
|
|
15
|
+
response: `return new Response("ok")`,
|
|
16
|
+
};
|
|
17
|
+
function getBindings(scriptName: string) {
|
|
18
|
+
return scriptName.split("--").flatMap((part) => bindings[part] ?? []);
|
|
19
|
+
}
|
|
20
|
+
function getScript(scriptName: string) {
|
|
21
|
+
return `export default {fetch(request){
|
|
22
|
+
${scriptName
|
|
23
|
+
.split("--")
|
|
24
|
+
.map((part) => scripts[part] ?? "")
|
|
25
|
+
.join(";\n")}
|
|
26
|
+
}}`;
|
|
27
|
+
}
|
|
28
|
+
export default [
|
|
29
|
+
rest.get(
|
|
30
|
+
"*/accounts/:accountId/workers/services/:scriptName/environments/:env/content",
|
|
31
|
+
({ params: { scriptName } }, res, context) => {
|
|
32
|
+
return res(
|
|
33
|
+
context.status(200),
|
|
34
|
+
context.text(getScript(scriptName as string))
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
rest.get(
|
|
39
|
+
"*/accounts/:accountId/workers/scripts/:scriptName",
|
|
40
|
+
({ params: { scriptName } }, res, context) => {
|
|
41
|
+
return res(
|
|
42
|
+
context.status(200),
|
|
43
|
+
context.text(getScript(scriptName as string))
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
rest.get(
|
|
48
|
+
"*/accounts/:accountId/workers/services/:scriptName/environments/:env/bindings",
|
|
49
|
+
({ params: { scriptName } }, res, context) => {
|
|
50
|
+
return res(
|
|
51
|
+
context.status(200),
|
|
52
|
+
context.json({
|
|
53
|
+
success: true,
|
|
54
|
+
errors: [],
|
|
55
|
+
messages: [],
|
|
56
|
+
result: getBindings(scriptName as string),
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
rest.get(
|
|
62
|
+
"*/accounts/:accountId/workers/scripts/:scriptName/bindings",
|
|
63
|
+
({ params: { scriptName } }, res, context) => {
|
|
64
|
+
return res(
|
|
65
|
+
context.status(200),
|
|
66
|
+
context.json({
|
|
67
|
+
success: true,
|
|
68
|
+
errors: [],
|
|
69
|
+
messages: [],
|
|
70
|
+
result: getBindings(scriptName as string),
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export const mswSuccessUserHandlers = [
|
|
4
|
+
rest.get("*/user", (_, response, cxt) => {
|
|
5
|
+
return response.once(
|
|
6
|
+
cxt.status(200),
|
|
7
|
+
cxt.json({
|
|
8
|
+
success: true,
|
|
9
|
+
errors: [],
|
|
10
|
+
messages: [],
|
|
11
|
+
result: {
|
|
12
|
+
id: "7c5dae5552338874e5053f2534d2767a",
|
|
13
|
+
email: "user@example.com",
|
|
14
|
+
first_name: "John",
|
|
15
|
+
last_name: "Appleseed",
|
|
16
|
+
username: "cfuser12345",
|
|
17
|
+
telephone: "+1 123-123-1234",
|
|
18
|
+
country: "US",
|
|
19
|
+
zipcode: "12345",
|
|
20
|
+
created_on: "2014-01-01T05:20:00Z",
|
|
21
|
+
modified_on: "2014-01-01T05:20:00Z",
|
|
22
|
+
two_factor_authentication_enabled: false,
|
|
23
|
+
suspended: false,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
}),
|
|
28
|
+
rest.get("*/accounts", (_, response, cxt) => {
|
|
29
|
+
return response.once(
|
|
30
|
+
cxt.status(200),
|
|
31
|
+
cxt.json({
|
|
32
|
+
success: true,
|
|
33
|
+
errors: [],
|
|
34
|
+
messages: [],
|
|
35
|
+
result: [
|
|
36
|
+
{ name: "Account One", id: "account-1" },
|
|
37
|
+
{ name: "Account Two", id: "account-2" },
|
|
38
|
+
{ name: "Account Three", id: "account-3" },
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}),
|
|
43
|
+
rest.get("*/memberships", (_, response, context) => {
|
|
44
|
+
return response.once(
|
|
45
|
+
context.status(200),
|
|
46
|
+
context.json({
|
|
47
|
+
success: true,
|
|
48
|
+
errors: [],
|
|
49
|
+
messages: [],
|
|
50
|
+
result: [
|
|
51
|
+
{
|
|
52
|
+
id: "membership-id-1",
|
|
53
|
+
account: { id: "account-id-1", name: "My Personal Account" },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "membership-id-2",
|
|
57
|
+
account: { id: "account-id-2", name: "Enterprise Account" },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
}),
|
|
63
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
rest.get("*/zones", ({ url: { searchParams } }, res, context) => {
|
|
5
|
+
return res(
|
|
6
|
+
context.status(200),
|
|
7
|
+
context.json({
|
|
8
|
+
success: true,
|
|
9
|
+
errors: [],
|
|
10
|
+
messages: [],
|
|
11
|
+
result:
|
|
12
|
+
searchParams.get("name") === "exists.com"
|
|
13
|
+
? [
|
|
14
|
+
{
|
|
15
|
+
id: "exists-com",
|
|
16
|
+
},
|
|
17
|
+
]
|
|
18
|
+
: [],
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}),
|
|
22
|
+
];
|