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.
Files changed (239) hide show
  1. package/README.md +16 -2
  2. package/bin/wrangler.js +31 -11
  3. package/miniflare-dist/index.mjs +1340 -330
  4. package/package.json +40 -13
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +238 -0
  7. package/src/__tests__/api-devregistry.test.js +64 -0
  8. package/src/__tests__/api.test.ts +80 -0
  9. package/src/__tests__/configuration.test.ts +683 -470
  10. package/src/__tests__/d1.test.ts +123 -0
  11. package/src/__tests__/delete.test.ts +263 -0
  12. package/src/__tests__/deployments.test.ts +105 -0
  13. package/src/__tests__/dev.test.tsx +453 -70
  14. package/src/__tests__/dialogs.test.tsx +40 -0
  15. package/src/__tests__/generate.test.ts +235 -0
  16. package/src/__tests__/get-host-from-url.test.ts +16 -0
  17. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  18. package/src/__tests__/helpers/mock-cfetch.ts +92 -26
  19. package/src/__tests__/helpers/mock-console.ts +11 -2
  20. package/src/__tests__/helpers/mock-dialogs.ts +1 -1
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  23. package/src/__tests__/helpers/mock-kv.ts +1 -1
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
  25. package/src/__tests__/helpers/mock-process.ts +8 -13
  26. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  27. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  28. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  29. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  30. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  31. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  32. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  33. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  34. package/src/__tests__/helpers/msw/index.ts +21 -0
  35. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  36. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  37. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  38. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  39. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  40. package/src/__tests__/index.test.ts +103 -97
  41. package/src/__tests__/init.test.ts +1484 -382
  42. package/src/__tests__/jest.setup.ts +88 -5
  43. package/src/__tests__/kv.test.ts +655 -540
  44. package/src/__tests__/logout.test.ts +47 -0
  45. package/src/__tests__/metrics.test.ts +95 -45
  46. package/src/__tests__/middleware.scheduled.test.ts +145 -0
  47. package/src/__tests__/middleware.test.ts +750 -0
  48. package/src/__tests__/pages-deployment-tail.test.ts +884 -0
  49. package/src/__tests__/pages.test.ts +1301 -119
  50. package/src/__tests__/paths.test.ts +39 -0
  51. package/src/__tests__/publish.test.ts +2266 -1180
  52. package/src/__tests__/pubsub.test.ts +211 -88
  53. package/src/__tests__/queues.test.ts +522 -0
  54. package/src/__tests__/r2.test.ts +363 -203
  55. package/src/__tests__/secret.test.ts +261 -59
  56. package/src/__tests__/tail.test.ts +352 -151
  57. package/src/__tests__/test-old-node-version.js +3 -3
  58. package/src/__tests__/tsconfig-sanity.ts +12 -0
  59. package/src/__tests__/tsconfig.json +8 -0
  60. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  61. package/src/__tests__/type-generation.test.ts +233 -0
  62. package/src/__tests__/user.test.ts +59 -73
  63. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  64. package/src/__tests__/validate-dev-props.test.ts +56 -0
  65. package/src/__tests__/whoami.test.tsx +114 -66
  66. package/src/__tests__/worker-namespace.test.ts +154 -155
  67. package/src/api/dev.ts +170 -38
  68. package/src/api/index.ts +1 -0
  69. package/src/bundle-reporter.tsx +41 -2
  70. package/src/bundle.ts +668 -81
  71. package/src/cfetch/index.ts +40 -3
  72. package/src/cfetch/internal.ts +144 -32
  73. package/src/cli.ts +4 -3
  74. package/src/config/config.ts +27 -3
  75. package/src/config/environment.ts +131 -7
  76. package/src/config/index.ts +128 -8
  77. package/src/config/validation-helpers.ts +19 -6
  78. package/src/config/validation.ts +411 -14
  79. package/src/config-cache.ts +3 -2
  80. package/src/create-worker-preview.ts +31 -6
  81. package/src/create-worker-upload-form.ts +84 -22
  82. package/src/d1/backups.tsx +223 -0
  83. package/src/d1/constants.ts +2 -0
  84. package/src/d1/create.tsx +63 -0
  85. package/src/d1/delete.tsx +56 -0
  86. package/src/d1/execute.tsx +352 -0
  87. package/src/d1/formatTimeAgo.ts +14 -0
  88. package/src/d1/index.ts +101 -0
  89. package/src/d1/list.tsx +48 -0
  90. package/src/d1/migrations/apply.tsx +196 -0
  91. package/src/d1/migrations/create.tsx +77 -0
  92. package/src/d1/migrations/helpers.ts +147 -0
  93. package/src/d1/migrations/index.tsx +3 -0
  94. package/src/d1/migrations/list.tsx +79 -0
  95. package/src/d1/migrations/options.ts +18 -0
  96. package/src/d1/options.ts +22 -0
  97. package/src/d1/types.tsx +24 -0
  98. package/src/d1/utils.ts +48 -0
  99. package/src/delete.ts +108 -0
  100. package/src/deployments.ts +83 -0
  101. package/src/deprecated/index.ts +145 -0
  102. package/src/dev/dev-vars.ts +11 -8
  103. package/src/dev/dev.tsx +220 -58
  104. package/src/dev/get-local-persistence-path.tsx +31 -0
  105. package/src/dev/local.tsx +740 -181
  106. package/src/dev/remote.tsx +340 -123
  107. package/src/dev/start-server.ts +543 -0
  108. package/src/dev/use-esbuild.ts +61 -7
  109. package/src/dev/validate-dev-props.ts +31 -0
  110. package/src/dev-registry.tsx +201 -0
  111. package/src/dev.tsx +614 -258
  112. package/src/dialogs.tsx +41 -8
  113. package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
  114. package/src/docs/index.ts +97 -0
  115. package/src/entry.ts +3 -2
  116. package/src/environment-variables/factory.ts +88 -0
  117. package/src/environment-variables/misc-variables.ts +30 -0
  118. package/src/generate/index.ts +300 -0
  119. package/src/git-client.ts +100 -7
  120. package/src/index.tsx +249 -1560
  121. package/src/init.ts +626 -150
  122. package/src/inspect.ts +137 -32
  123. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  124. package/src/is-interactive.ts +4 -0
  125. package/src/jest.d.ts +4 -0
  126. package/src/{kv.ts → kv/helpers.ts} +3 -3
  127. package/src/kv/index.ts +596 -0
  128. package/src/logger.ts +27 -8
  129. package/src/metrics/index.ts +1 -0
  130. package/src/metrics/metrics-config.ts +4 -4
  131. package/src/metrics/metrics-dispatcher.ts +1 -0
  132. package/src/metrics/metrics-usage-headers.ts +24 -0
  133. package/src/metrics/send-event.ts +13 -8
  134. package/src/miniflare-cli/assets.ts +172 -465
  135. package/src/miniflare-cli/index.ts +149 -24
  136. package/src/miniflare-cli/tsconfig.json +9 -0
  137. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  138. package/src/miniflare-cli/types.ts +11 -0
  139. package/src/module-collection.ts +12 -3
  140. package/src/pages/build.tsx +108 -42
  141. package/src/pages/constants.ts +11 -0
  142. package/src/pages/deployment-tails.tsx +284 -0
  143. package/src/pages/deployments.tsx +9 -31
  144. package/src/pages/dev.tsx +417 -108
  145. package/src/pages/errors.ts +66 -0
  146. package/src/pages/functions/buildPlugin.ts +86 -84
  147. package/src/pages/functions/buildWorker.ts +121 -106
  148. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  149. package/src/pages/functions/routes-consolidation.ts +73 -0
  150. package/src/pages/functions/routes-transformation.test.ts +282 -0
  151. package/src/pages/functions/routes-transformation.ts +115 -0
  152. package/src/pages/functions/routes-validation.test.ts +403 -0
  153. package/src/pages/functions/routes-validation.ts +202 -0
  154. package/src/pages/functions/tsconfig.json +8 -0
  155. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  156. package/src/pages/functions.tsx +82 -0
  157. package/src/pages/hash.tsx +13 -0
  158. package/src/pages/index.tsx +73 -55
  159. package/src/pages/projects.tsx +9 -3
  160. package/src/pages/prompt-select-project.tsx +31 -0
  161. package/src/pages/publish.tsx +183 -60
  162. package/src/pages/types.ts +1 -0
  163. package/src/pages/upload.tsx +107 -56
  164. package/src/pages/utils.ts +13 -2
  165. package/src/paths.ts +49 -4
  166. package/src/proxy.ts +375 -157
  167. package/src/publish/index.ts +270 -0
  168. package/src/{publish.ts → publish/publish.ts} +431 -188
  169. package/src/pubsub/pubsub-commands.tsx +4 -3
  170. package/src/queues/cli/commands/consumer/add.ts +71 -0
  171. package/src/queues/cli/commands/consumer/index.ts +22 -0
  172. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  173. package/src/queues/cli/commands/create.ts +25 -0
  174. package/src/queues/cli/commands/delete.ts +26 -0
  175. package/src/queues/cli/commands/index.ts +36 -0
  176. package/src/queues/cli/commands/list.ts +25 -0
  177. package/src/queues/client.ts +135 -0
  178. package/src/queues/utils.ts +18 -0
  179. package/src/r2/constants.ts +4 -0
  180. package/src/r2/helpers.ts +131 -0
  181. package/src/r2/index.ts +289 -0
  182. package/src/routes.ts +140 -0
  183. package/src/secret/index.ts +379 -0
  184. package/src/sites.tsx +3 -3
  185. package/src/tail/createTail.ts +379 -0
  186. package/src/tail/filters.ts +4 -6
  187. package/src/tail/index.ts +199 -284
  188. package/src/tail/printing.ts +43 -3
  189. package/src/tsconfig-sanity.ts +16 -0
  190. package/src/type-generation.ts +181 -0
  191. package/src/user/access.ts +68 -0
  192. package/src/user/auth-variables.ts +113 -0
  193. package/src/user/choose-account.tsx +1 -1
  194. package/src/user/index.ts +0 -1
  195. package/src/user/user.tsx +116 -49
  196. package/src/utils/collectKeyValues.ts +14 -0
  197. package/src/whoami.tsx +80 -2
  198. package/src/worker.ts +69 -9
  199. package/src/yargs-types.ts +24 -0
  200. package/src/zones.ts +124 -9
  201. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  202. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  203. package/templates/__tests__/tsconfig.json +8 -0
  204. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  205. package/templates/d1-beta-facade.js +205 -0
  206. package/templates/facade.d.ts +14 -0
  207. package/templates/first-party-worker-module-facade.ts +19 -0
  208. package/templates/format-dev-errors.ts +33 -0
  209. package/templates/init-tests/test-jest-new-worker.js +23 -0
  210. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  211. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  212. package/templates/middleware/common.ts +62 -0
  213. package/templates/middleware/loader-modules.ts +82 -0
  214. package/templates/middleware/loader-sw.ts +233 -0
  215. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  216. package/templates/middleware/middleware-pretty-error.ts +40 -0
  217. package/templates/middleware/middleware-scheduled.ts +15 -0
  218. package/templates/new-worker.js +1 -1
  219. package/templates/pages-dev-pipeline.ts +31 -0
  220. package/templates/pages-dev-util.ts +52 -0
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +21 -5
  223. package/templates/pages-template-worker.ts +37 -9
  224. package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
  225. package/templates/service-bindings-module-facade.js +54 -0
  226. package/templates/service-bindings-sw-facade.js +42 -0
  227. package/templates/tsconfig-sanity.ts +11 -0
  228. package/templates/tsconfig.init.json +106 -0
  229. package/templates/tsconfig.json +5 -102
  230. package/templates/tsconfig.tsbuildinfo +1 -0
  231. package/wrangler-dist/cli.d.ts +621 -42
  232. package/wrangler-dist/cli.js +144441 -102606
  233. package/src/environment-variables.ts +0 -35
  234. package/src/faye-websocket.d.ts +0 -6
  235. package/src/generate.ts +0 -33
  236. package/src/miniflare-cli/enum-keys.ts +0 -17
  237. package/src/preview.ts +0 -31
  238. package/src/r2.ts +0 -50
  239. 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("https://dash.cloudflare.com/oauth2/revoke", {
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
- outcome.actual = req;
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("https://dash.cloudflare.com/oauth2/token", {
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
- outcome.actual = req;
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
- "https://dash.cloudflare.com/oauth2/token",
134
- 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_sucess_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`";
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
- if (calls.length > 1) {
11
- throw new Error(
12
- "Unexpected calls to `stdout.write()`: " + JSON.stringify(calls)
13
- );
14
- }
15
- const buffer = calls[0]?.[0] ?? Buffer.alloc(0);
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
+ ];