wrangler 0.0.0-ecc8b172 → 0.0.0-ecded1af1

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 (250) hide show
  1. package/README.md +17 -19
  2. package/bin/wrangler.js +24 -93
  3. package/config-schema.json +3115 -0
  4. package/package.json +197 -190
  5. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  6. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  7. package/templates/__tests__/tsconfig.json +8 -0
  8. package/templates/checked-fetch.js +19 -6
  9. package/templates/facade.d.ts +19 -0
  10. package/templates/gitignore +2 -3
  11. package/templates/init-tests/test-jest-new-worker.js +3 -5
  12. package/templates/init-tests/test-vitest-new-worker.js +4 -6
  13. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  14. package/templates/middleware/common.ts +9 -4
  15. package/templates/middleware/loader-modules.ts +94 -44
  16. package/templates/middleware/loader-sw.ts +48 -32
  17. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -1
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.ts +1 -1
  26. package/templates/new-worker.ts +4 -1
  27. package/templates/pages-dev-pipeline.ts +10 -13
  28. package/templates/pages-dev-util.ts +55 -0
  29. package/templates/pages-shim.ts +1 -1
  30. package/templates/pages-template-plugin.ts +37 -14
  31. package/templates/pages-template-worker.ts +33 -7
  32. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  33. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  34. package/templates/tsconfig-sanity.ts +11 -0
  35. package/templates/tsconfig.init.json +22 -0
  36. package/templates/tsconfig.json +5 -102
  37. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  38. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  39. package/wrangler-dist/ProxyWorker.js +241 -0
  40. package/wrangler-dist/ProxyWorker.js.map +6 -0
  41. package/wrangler-dist/cli.d.ts +26095 -471
  42. package/wrangler-dist/cli.js +178062 -122008
  43. package/wrangler-dist/wasm-sync.wasm +0 -0
  44. package/Cloudflare_CA.pem +0 -18
  45. package/import_meta_url.js +0 -3
  46. package/miniflare-config-stubs/.env.empty +0 -0
  47. package/miniflare-config-stubs/package.empty.json +0 -1
  48. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  49. package/miniflare-dist/index.mjs +0 -6310
  50. package/src/__tests__/api-dev.test.ts +0 -209
  51. package/src/__tests__/api-devregistry.test.js +0 -56
  52. package/src/__tests__/api.test.ts +0 -80
  53. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  54. package/src/__tests__/config-cache.test.ts +0 -42
  55. package/src/__tests__/configuration.test.ts +0 -3864
  56. package/src/__tests__/d1.test.ts +0 -70
  57. package/src/__tests__/delete.test.ts +0 -116
  58. package/src/__tests__/dev.test.tsx +0 -1357
  59. package/src/__tests__/dialogs.test.tsx +0 -40
  60. package/src/__tests__/generate.test.ts +0 -235
  61. package/src/__tests__/get-host-from-url.test.ts +0 -16
  62. package/src/__tests__/guess-worker-format.test.ts +0 -85
  63. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  64. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  65. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  66. package/src/__tests__/helpers/mock-bin.ts +0 -36
  67. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  68. package/src/__tests__/helpers/mock-console.ts +0 -106
  69. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  70. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  71. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  72. package/src/__tests__/helpers/mock-istty.ts +0 -74
  73. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  74. package/src/__tests__/helpers/mock-kv.ts +0 -33
  75. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
  76. package/src/__tests__/helpers/mock-process.ts +0 -39
  77. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  78. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  79. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
  80. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
  81. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
  82. package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
  83. package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
  84. package/src/__tests__/helpers/msw/index.ts +0 -15
  85. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  86. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  87. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  88. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  89. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  90. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  91. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  92. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  93. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  94. package/src/__tests__/https-options.test.ts +0 -163
  95. package/src/__tests__/index.test.ts +0 -251
  96. package/src/__tests__/init.test.ts +0 -2816
  97. package/src/__tests__/jest.setup.ts +0 -191
  98. package/src/__tests__/kv.test.ts +0 -1675
  99. package/src/__tests__/logger.test.ts +0 -141
  100. package/src/__tests__/metrics.test.ts +0 -450
  101. package/src/__tests__/middleware.scheduled.test.ts +0 -135
  102. package/src/__tests__/middleware.test.ts +0 -726
  103. package/src/__tests__/package-manager.test.ts +0 -353
  104. package/src/__tests__/pages.test.ts +0 -2111
  105. package/src/__tests__/parse.test.ts +0 -330
  106. package/src/__tests__/paths.test.ts +0 -39
  107. package/src/__tests__/publish.test.ts +0 -7119
  108. package/src/__tests__/pubsub.test.ts +0 -367
  109. package/src/__tests__/r2.test.ts +0 -371
  110. package/src/__tests__/route.test.ts +0 -45
  111. package/src/__tests__/secret.test.ts +0 -644
  112. package/src/__tests__/tail.test.ts +0 -800
  113. package/src/__tests__/test-old-node-version.js +0 -31
  114. package/src/__tests__/user.test.ts +0 -155
  115. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  116. package/src/__tests__/validate-dev-props.test.ts +0 -56
  117. package/src/__tests__/version.test.ts +0 -35
  118. package/src/__tests__/whoami.test.tsx +0 -278
  119. package/src/__tests__/worker-namespace.test.ts +0 -321
  120. package/src/abort.d.ts +0 -3
  121. package/src/api/dev.ts +0 -208
  122. package/src/api/index.ts +0 -2
  123. package/src/bundle-reporter.tsx +0 -29
  124. package/src/bundle.ts +0 -756
  125. package/src/cfetch/index.ts +0 -160
  126. package/src/cfetch/internal.ts +0 -263
  127. package/src/cli.ts +0 -29
  128. package/src/config/README.md +0 -107
  129. package/src/config/config.ts +0 -275
  130. package/src/config/diagnostics.ts +0 -80
  131. package/src/config/environment.ts +0 -505
  132. package/src/config/index.ts +0 -293
  133. package/src/config/validation-helpers.ts +0 -597
  134. package/src/config/validation.ts +0 -1930
  135. package/src/config-cache.ts +0 -85
  136. package/src/create-worker-preview.ts +0 -275
  137. package/src/create-worker-upload-form.ts +0 -301
  138. package/src/d1/backups.tsx +0 -212
  139. package/src/d1/create.tsx +0 -54
  140. package/src/d1/delete.tsx +0 -56
  141. package/src/d1/execute.tsx +0 -294
  142. package/src/d1/formatTimeAgo.ts +0 -14
  143. package/src/d1/index.ts +0 -75
  144. package/src/d1/list.tsx +0 -48
  145. package/src/d1/options.ts +0 -12
  146. package/src/d1/types.tsx +0 -14
  147. package/src/d1/utils.ts +0 -39
  148. package/src/delete.ts +0 -86
  149. package/src/deprecated/index.ts +0 -453
  150. package/src/dev/dev-vars.ts +0 -36
  151. package/src/dev/dev.tsx +0 -575
  152. package/src/dev/get-local-persistence-path.tsx +0 -31
  153. package/src/dev/local.tsx +0 -686
  154. package/src/dev/remote.tsx +0 -601
  155. package/src/dev/start-server.ts +0 -506
  156. package/src/dev/use-esbuild.ts +0 -197
  157. package/src/dev/validate-dev-props.ts +0 -31
  158. package/src/dev-registry.tsx +0 -201
  159. package/src/dev.tsx +0 -865
  160. package/src/dialogs.tsx +0 -163
  161. package/src/dispatch-namespace.ts +0 -206
  162. package/src/durable.ts +0 -102
  163. package/src/entry.ts +0 -329
  164. package/src/environment-variables.ts +0 -50
  165. package/src/errors.ts +0 -11
  166. package/src/git-client.ts +0 -124
  167. package/src/global-wrangler-config-path.ts +0 -26
  168. package/src/https-options.ts +0 -127
  169. package/src/index.tsx +0 -582
  170. package/src/init.ts +0 -970
  171. package/src/inspect.ts +0 -747
  172. package/src/intl-polyfill.d.ts +0 -139
  173. package/src/is-ci.ts +0 -14
  174. package/src/is-interactive.ts +0 -12
  175. package/src/kv/helpers.ts +0 -430
  176. package/src/kv/index.ts +0 -645
  177. package/src/logger.ts +0 -80
  178. package/src/metrics/index.ts +0 -5
  179. package/src/metrics/metrics-config.ts +0 -239
  180. package/src/metrics/metrics-dispatcher.ts +0 -96
  181. package/src/metrics/metrics-usage-headers.ts +0 -24
  182. package/src/metrics/send-event.ts +0 -94
  183. package/src/miniflare-cli/README.md +0 -30
  184. package/src/miniflare-cli/assets.ts +0 -215
  185. package/src/miniflare-cli/index.ts +0 -208
  186. package/src/miniflare-cli/request-context.ts +0 -40
  187. package/src/module-collection.ts +0 -267
  188. package/src/open-in-browser.ts +0 -17
  189. package/src/package-manager.ts +0 -219
  190. package/src/pages/build.tsx +0 -238
  191. package/src/pages/constants.ts +0 -16
  192. package/src/pages/deployments.tsx +0 -106
  193. package/src/pages/dev.tsx +0 -689
  194. package/src/pages/errors.ts +0 -66
  195. package/src/pages/functions/buildPlugin.ts +0 -110
  196. package/src/pages/functions/buildWorker.ts +0 -156
  197. package/src/pages/functions/filepath-routing.test.ts +0 -234
  198. package/src/pages/functions/filepath-routing.ts +0 -189
  199. package/src/pages/functions/identifiers.ts +0 -78
  200. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  201. package/src/pages/functions/routes-consolidation.ts +0 -73
  202. package/src/pages/functions/routes-transformation.test.ts +0 -282
  203. package/src/pages/functions/routes-transformation.ts +0 -115
  204. package/src/pages/functions/routes-validation.test.ts +0 -403
  205. package/src/pages/functions/routes-validation.ts +0 -202
  206. package/src/pages/functions/routes.ts +0 -151
  207. package/src/pages/functions.tsx +0 -82
  208. package/src/pages/hash.tsx +0 -13
  209. package/src/pages/index.tsx +0 -94
  210. package/src/pages/projects.tsx +0 -169
  211. package/src/pages/publish.tsx +0 -436
  212. package/src/pages/types.ts +0 -49
  213. package/src/pages/upload.tsx +0 -398
  214. package/src/pages/utils.ts +0 -12
  215. package/src/parse.ts +0 -286
  216. package/src/paths.ts +0 -71
  217. package/src/proxy.ts +0 -657
  218. package/src/publish/index.ts +0 -267
  219. package/src/publish/publish.ts +0 -913
  220. package/src/pubsub/index.ts +0 -286
  221. package/src/pubsub/pubsub-commands.tsx +0 -623
  222. package/src/r2/helpers.ts +0 -131
  223. package/src/r2/index.ts +0 -277
  224. package/src/routes.ts +0 -140
  225. package/src/secret/index.ts +0 -403
  226. package/src/selfsigned.d.ts +0 -29
  227. package/src/sites.tsx +0 -372
  228. package/src/tail/createTail.ts +0 -315
  229. package/src/tail/filters.ts +0 -277
  230. package/src/tail/index.ts +0 -217
  231. package/src/tail/printing.ts +0 -107
  232. package/src/update-check.ts +0 -19
  233. package/src/user/choose-account.tsx +0 -69
  234. package/src/user/env-vars.ts +0 -46
  235. package/src/user/generate-auth-url.ts +0 -33
  236. package/src/user/generate-random-state.ts +0 -16
  237. package/src/user/index.ts +0 -3
  238. package/src/user/user.tsx +0 -1192
  239. package/src/utils/collectKeyValues.ts +0 -14
  240. package/src/whoami.tsx +0 -169
  241. package/src/worker.ts +0 -234
  242. package/src/yargs-types.ts +0 -7
  243. package/src/zones.ts +0 -165
  244. package/templates/d1-beta-facade.js +0 -174
  245. package/templates/experimental-local-cache-stubs.js +0 -27
  246. package/templates/first-party-worker-module-facade.ts +0 -18
  247. package/templates/format-dev-errors.ts +0 -32
  248. package/templates/serve-static-assets.ts +0 -63
  249. package/templates/service-bindings-module-facade.js +0 -54
  250. package/templates/service-bindings-sw-facade.js +0 -42
@@ -1,74 +0,0 @@
1
- const ORIGINAL_STDOUT = process.stdout;
2
- const ORIGINAL_STDIN = process.stdin;
3
-
4
- /**
5
- * Mock `process.stdout.isTTY`
6
- */
7
- export function useMockIsTTY() {
8
- /**
9
- * Explicitly set `process.stdout.isTTY` to a given value (or to a getter function).
10
- */
11
- const setIsTTY = (
12
- isTTY:
13
- | boolean
14
- | { stdin: boolean | (() => boolean); stdout: boolean | (() => boolean) }
15
- ) => {
16
- mockStdStream("stdout", ORIGINAL_STDOUT, isTTY);
17
- mockStdStream("stdin", ORIGINAL_STDIN, isTTY);
18
- };
19
-
20
- beforeEach(() => {
21
- Object.defineProperty(process, "stdout", { value: ORIGINAL_STDOUT });
22
- Object.defineProperty(process, "stdin", { value: ORIGINAL_STDIN });
23
- });
24
-
25
- afterEach(() => {
26
- Object.defineProperty(process, "stdout", { value: ORIGINAL_STDOUT });
27
- Object.defineProperty(process, "stdin", { value: ORIGINAL_STDIN });
28
- });
29
-
30
- return { setIsTTY };
31
- }
32
-
33
- /**
34
- * Create a mock version of the specified stream which overrides `isTTY`
35
- * with the given mock responses.
36
- *
37
- * @param streamName the property name on `process` for the stream to be mocked.
38
- * @param originalStream the original stream object from the `process` object to be overridden.
39
- * @param isTTY the mock behaviour for the `isTTY` property:
40
- * - boolean or `{ [streamName]: boolean } - use this value for isTTY;
41
- * - { [streamName]: () => boolean } - use this function as a getter for isTTY.
42
- */
43
- function mockStdStream<T extends object>(
44
- streamName: "stdout" | "stdin",
45
- originalStream: T,
46
- isTTY:
47
- | boolean
48
- | { stdin: boolean | (() => boolean); stdout: boolean | (() => boolean) }
49
- ) {
50
- Object.defineProperty(process, streamName, {
51
- value: createStdProxy(
52
- originalStream,
53
- typeof isTTY === "boolean" ? isTTY : isTTY[streamName]
54
- ),
55
- });
56
- }
57
-
58
- /**
59
- * Create a proxy wrapper around the given `stream` object that overrides the `isTTY` property.
60
- */
61
- function createStdProxy<T extends object>(
62
- stream: T,
63
- isTTY: boolean | (() => boolean)
64
- ): T {
65
- return new Proxy(stream, {
66
- get(target, prop) {
67
- return prop === "isTTY"
68
- ? typeof isTTY === "boolean"
69
- ? isTTY
70
- : isTTY()
71
- : target[prop as keyof typeof target];
72
- },
73
- });
74
- }
@@ -1,7 +0,0 @@
1
- import { setMockResponse } from "./mock-cfetch";
2
-
3
- export function mockCollectKnownRoutesRequest(
4
- routes: { pattern: string; script: string }[]
5
- ) {
6
- setMockResponse(`/zones/:zoneId/workers/routes`, "GET", () => routes);
7
- }
@@ -1,33 +0,0 @@
1
- import { createFetchResult, setMockRawResponse } from "./mock-cfetch";
2
- import type { NamespaceKeyInfo } from "../../kv/helpers";
3
-
4
- export function mockKeyListRequest(
5
- expectedNamespaceId: string,
6
- expectedKeys: NamespaceKeyInfo[],
7
- keysPerRequest = 1000,
8
- blankCursorValue: "" | undefined | null = undefined
9
- ) {
10
- const requests = { count: 0 };
11
- // See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
12
-
13
- setMockRawResponse(
14
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
15
- "GET",
16
- ([_url, accountId, namespaceId], _init, query) => {
17
- requests.count++;
18
- expect(accountId).toEqual("some-account-id");
19
- expect(namespaceId).toEqual(expectedNamespaceId);
20
- if (expectedKeys.length <= keysPerRequest) {
21
- return createFetchResult(expectedKeys);
22
- } else {
23
- const start = parseInt(query.get("cursor") ?? "0") || 0;
24
- const end = start + keysPerRequest;
25
- const cursor = end < expectedKeys.length ? end : blankCursorValue;
26
- return createFetchResult(expectedKeys.slice(start, end), true, [], [], {
27
- cursor,
28
- });
29
- }
30
- }
31
- );
32
- return requests;
33
- }
@@ -1,252 +0,0 @@
1
- import fetchMock from "jest-fetch-mock";
2
- import { Request } from "undici";
3
- import openInBrowser from "../../open-in-browser";
4
- import {
5
- createFetchResult,
6
- setMockRawResponse,
7
- setMockResponse,
8
- } from "./mock-cfetch";
9
- import { mockHttpServer } from "./mock-http-server";
10
-
11
- export function mockGetMemberships(
12
- accounts: { id: string; account: { id: string; name: string } }[]
13
- ) {
14
- setMockResponse("/memberships", "GET", () => {
15
- return accounts;
16
- });
17
- }
18
-
19
- export function mockGetMembershipsFail() {
20
- setMockRawResponse("/memberships", () => {
21
- return createFetchResult([], false);
22
- });
23
- }
24
-
25
- // the response to send when wrangler wants an oauth grant
26
- let oauthGrantResponse: GrantResponseOptions | "timeout" = {};
27
-
28
- /**
29
- * Functions to help with mocking various parts of the OAuth Flow
30
- */
31
- export const mockOAuthFlow = () => {
32
- const fetchHttp = mockHttpServer();
33
-
34
- afterEach(() => {
35
- fetchMock.resetMocks();
36
- });
37
-
38
- /**
39
- * Mock out the callback from a browser to our HttpServer.
40
- *
41
- * This function will override `openInBrowser()` so that instead of opening a browser window
42
- * at the OAuth URL, it will automatically trigger the callback URL on the mock HttpServer that
43
- * we have created as part of the call to `mockOAuthFlow()`.
44
- */
45
- const mockOAuthServerCallback = () => {
46
- (
47
- openInBrowser as jest.MockedFunction<typeof openInBrowser>
48
- ).mockImplementation(async (url: string) => {
49
- // We don't support the grant response timing out.
50
- if (oauthGrantResponse === "timeout") {
51
- throw "unimplemented";
52
- }
53
-
54
- // Create a fake callback request that would be created by the OAuth server
55
- const { searchParams } = new URL(url);
56
- const queryParams = toQueryParams(oauthGrantResponse, searchParams);
57
- const request = new Request(
58
- `${searchParams.get("redirect_uri")}?${queryParams}`
59
- );
60
-
61
- // Trigger the mock HttpServer to handle this fake request to continue the OAuth flow.
62
- fetchHttp(request).catch((e) => {
63
- throw new Error(
64
- "Failed to send OAuth Grant to wrangler, maybe the server was closed?",
65
- e as Error
66
- );
67
- });
68
- });
69
- };
70
-
71
- const mockGrantAuthorization = ({
72
- respondWith,
73
- }: {
74
- respondWith: "timeout" | "success" | "failure" | GrantResponseOptions;
75
- }) => {
76
- if (respondWith === "failure") {
77
- oauthGrantResponse = {
78
- error: "access_denied",
79
- };
80
- } else if (respondWith === "success") {
81
- oauthGrantResponse = {
82
- code: "test-oauth-code",
83
- };
84
- } else if (respondWith === "timeout") {
85
- oauthGrantResponse = "timeout";
86
- } else {
87
- oauthGrantResponse = respondWith;
88
- }
89
- };
90
-
91
- const mockRevokeAuthorization = () => {
92
- const outcome = {
93
- actual: new Request("https://example.org"),
94
- expected: new Request("https://dash.cloudflare.com/oauth2/revoke", {
95
- method: "POST",
96
- }),
97
- };
98
-
99
- fetchMock.mockIf(outcome.expected.url, async (req) => {
100
- // TODO: update Miniflare typings to match full undici Request
101
- outcome.actual = req as unknown as Request;
102
- return "";
103
- });
104
-
105
- return outcome;
106
- };
107
-
108
- const mockGrantAccessToken = ({
109
- respondWith,
110
- }: {
111
- respondWith: MockTokenResponse;
112
- }) => {
113
- const outcome = {
114
- actual: new Request("https://example.org"),
115
- expected: new Request("https://dash.cloudflare.com/oauth2/token", {
116
- method: "POST",
117
- }),
118
- };
119
-
120
- fetchMock.mockOnceIf(outcome.expected.url, async (req) => {
121
- // TODO: update Miniflare typings to match full undici Request
122
- outcome.actual = req as unknown as Request;
123
- return makeTokenResponse(respondWith);
124
- });
125
-
126
- return outcome;
127
- };
128
-
129
- const mockExchangeRefreshTokenForAccessToken = ({
130
- respondWith,
131
- }: {
132
- respondWith: "refreshSuccess" | "refreshError" | "badResponse";
133
- }) => {
134
- fetchMock.mockOnceIf(
135
- "https://dash.cloudflare.com/oauth2/token",
136
- async () => {
137
- switch (respondWith) {
138
- case "refreshSuccess":
139
- return {
140
- status: 200,
141
- body: JSON.stringify({
142
- access_token: "access_token_success_mock",
143
- expires_in: 1701,
144
- refresh_token: "refresh_token_sucess_mock",
145
- scope: "scope_success_mock",
146
- token_type: "bearer",
147
- }),
148
- };
149
- case "refreshError":
150
- return {
151
- status: 400,
152
- body: JSON.stringify({
153
- error: "invalid_request",
154
- error_description: "error_description_mock",
155
- error_hint: "error_hint_mock",
156
- error_verbose: "error_verbose_mock",
157
- status_code: 400,
158
- }),
159
- };
160
- case "badResponse":
161
- return {
162
- status: 400,
163
- body: `<html> <body> This shouldn't be sent, but should be handled </body> </html>`,
164
- };
165
-
166
- default:
167
- return "Not a respondWith option for `mockExchangeRefreshTokenForAccessToken`";
168
- }
169
- }
170
- );
171
- };
172
-
173
- return {
174
- mockGrantAccessToken,
175
- mockGrantAuthorization,
176
- mockOAuthServerCallback,
177
- mockRevokeAuthorization,
178
- mockExchangeRefreshTokenForAccessToken,
179
- };
180
- };
181
-
182
- type GrantResponseOptions = {
183
- code?: string;
184
- error?: ErrorType | ErrorType[];
185
- };
186
-
187
- const toQueryParams = (
188
- { code, error }: GrantResponseOptions,
189
- wranglerRequestParams: URLSearchParams
190
- ): string => {
191
- const queryParams = [];
192
- if (code) {
193
- queryParams.push(`code=${code}`);
194
- }
195
- if (error) {
196
- const stringifiedErr = Array.isArray(error) ? error.join(",") : error;
197
- queryParams.push(`error=${stringifiedErr}`);
198
- }
199
-
200
- queryParams.push(`state=${wranglerRequestParams.get("state")}`);
201
-
202
- return queryParams.join("&");
203
- };
204
-
205
- type ErrorType =
206
- | "invalid_request"
207
- | "invalid_grant"
208
- | "unauthorized_client"
209
- | "access_denied"
210
- | "unsupported_response_type"
211
- | "invalid_scope"
212
- | "server_error"
213
- | "temporarily_unavailable"
214
- | "invalid_client"
215
- | "unsupported_grant_type"
216
- | "invalid_json"
217
- | "invalid_token"
218
- | "test-token-grant-error";
219
-
220
- type MockTokenResponse =
221
- | "ok"
222
- | "error"
223
- | {
224
- access_token: string;
225
- expires_in: number;
226
- refresh_token: string;
227
- scope: string;
228
- }
229
- | {
230
- error: ErrorType;
231
- };
232
-
233
- const makeTokenResponse = (partialResponse: MockTokenResponse): string => {
234
- let fullResponse: MockTokenResponse;
235
-
236
- if (partialResponse === "ok") {
237
- fullResponse = {
238
- access_token: "test-access-token",
239
- expires_in: 100000,
240
- refresh_token: "test-refresh-token",
241
- scope: "account:read",
242
- };
243
- } else if (partialResponse === "error") {
244
- fullResponse = {
245
- error: "test-token-grant-error",
246
- };
247
- } else {
248
- fullResponse = partialResponse;
249
- }
250
-
251
- return JSON.stringify(fullResponse);
252
- };
@@ -1,39 +0,0 @@
1
- /**
2
- * We use this module to mock process methods (write only for now),
3
- * and optionally assert on the values they're called with in our tests.
4
- */
5
-
6
- let writeSpy: jest.SpyInstance;
7
-
8
- function captureLastWriteCall(spy: jest.SpyInstance): Buffer {
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);
16
- if (buffer instanceof Buffer) {
17
- return buffer;
18
- } else {
19
- throw new Error(
20
- `Unexpected non-Buffer passed to \`stdout.write()\`: "${JSON.stringify(
21
- buffer
22
- )}"`
23
- );
24
- }
25
- }
26
-
27
- export function mockProcess() {
28
- beforeEach(() => {
29
- writeSpy = jest.spyOn(process.stdout, "write").mockImplementation();
30
- });
31
- afterEach(() => {
32
- writeSpy.mockRestore();
33
- });
34
- return {
35
- get write() {
36
- return captureLastWriteCall(writeSpy);
37
- },
38
- };
39
- }
@@ -1,108 +0,0 @@
1
- const ORIGINAL_STDIN = process.stdin;
2
-
3
- /**
4
- * Mock process.stdin so that we can pipe in text for non-interactive mode tests.
5
- */
6
- export function useMockStdin({ isTTY }: { isTTY: boolean }) {
7
- const mockStdin = new MockStdIn(isTTY);
8
-
9
- beforeEach(() => {
10
- mockStdin.reset();
11
- Object.defineProperty(process, "stdin", {
12
- value: mockStdin,
13
- configurable: true,
14
- writable: false,
15
- });
16
- });
17
-
18
- afterEach(() => {
19
- Object.defineProperty(process, "stdin", {
20
- value: ORIGINAL_STDIN,
21
- configurable: true,
22
- writable: false,
23
- });
24
- });
25
-
26
- return mockStdin;
27
- }
28
-
29
- const failCallback: (value: unknown) => void = () => {
30
- throw new Error(
31
- "TEST FAILURE: stdin callback called before being initialized."
32
- );
33
- };
34
-
35
- /**
36
- * A mock version of `process.std`, which can be used to simulate piping data
37
- * into the wrangler process in non-interactive mode.
38
- */
39
- class MockStdIn {
40
- private endCallback = failCallback;
41
- private errorCallback = failCallback;
42
- private chunks: string[] = [];
43
- private error: Error | undefined;
44
-
45
- /**
46
- * Set this to true if you want the stdin stream to error.
47
- */
48
- throwError(error: Error) {
49
- this.error = error;
50
- }
51
-
52
- /**
53
- * Call this to clean out the chunks that are queued for sending.
54
- */
55
- reset() {
56
- this.chunks.length = 0;
57
- this.error = undefined;
58
- }
59
-
60
- /**
61
- * Queue up some chunks to be sent.
62
- */
63
- send(...chunks: string[]) {
64
- this.chunks.push(...chunks);
65
- }
66
-
67
- constructor(
68
- /**
69
- * Used by wrangler to check whether stdin is interactive.
70
- */
71
- readonly isTTY: boolean
72
- ) {}
73
-
74
- /**
75
- * Used by wrangler to add event listeners.
76
- */
77
- on(eventName: string, callback: () => void) {
78
- switch (eventName) {
79
- case "readable":
80
- setImmediate(callback);
81
- break;
82
- case "end":
83
- this.endCallback = callback;
84
- break;
85
- case "error":
86
- this.errorCallback = callback;
87
- break;
88
- }
89
- }
90
-
91
- /**
92
- * Used by wrangler to get the next chunk of data in the stream.
93
- */
94
- read() {
95
- if (this.error) {
96
- setImmediate(() => this.errorCallback(this.error));
97
- }
98
- if (this.chunks.length === 0) {
99
- setImmediate(this.endCallback);
100
- }
101
- return this.chunks.shift() ?? null;
102
- }
103
-
104
- /**
105
- * Used by Ink.js to set the encoding of the stdout.
106
- */
107
- setEncoding() {}
108
- }
@@ -1,29 +0,0 @@
1
- import { WebSocket } from "mock-socket";
2
-
3
- /**
4
- * A version of the mock WebSocket that supports the methods that we use.
5
- */
6
- export class MockWebSocket extends WebSocket {
7
- on(event: string | symbol, listener: (...args: unknown[]) => void): this {
8
- switch (event) {
9
- case "message":
10
- this.onmessage = ({ data }) => {
11
- listener(data);
12
- };
13
- break;
14
- case "open":
15
- this.onopen = listener;
16
- break;
17
- case "close":
18
- this.onclose = listener;
19
- break;
20
- default:
21
- throw new Error("Unknown event type: " + event.toString());
22
- }
23
- return this;
24
- }
25
-
26
- terminate() {
27
- this.close();
28
- }
29
- }
@@ -1,104 +0,0 @@
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
- ];
@@ -1,36 +0,0 @@
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(
17
- "https://dash.cloudflare.com/oauth2/revoke",
18
- (_, response, context) =>
19
- response.once(context.status(200), context.text(""))
20
- ),
21
- // exchange (auth code | refresh token) for access token
22
- rest.post(
23
- "https://dash.cloudflare.com/oauth2/token",
24
- (_, response, context) => {
25
- return response.once(
26
- context.status(200),
27
- context.json({
28
- access_token: "test-access-token",
29
- expires_in: 100000,
30
- refresh_token: "test-refresh-token",
31
- scope: "account:read",
32
- })
33
- );
34
- }
35
- ),
36
- ];