wrangler 0.0.0-e7a0cd5b → 0.0.0-e7c7235fd
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 +31 -45
- package/bin/wrangler.js +24 -93
- package/config-schema.json +3324 -0
- package/package.json +183 -191
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +19 -6
- package/templates/facade.d.ts +19 -0
- package/templates/gitignore +2 -3
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +4 -6
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +9 -4
- package/templates/middleware/loader-modules.ts +94 -44
- package/templates/middleware/loader-sw.ts +48 -32
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
- package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
- package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
- package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
- package/templates/middleware/middleware-scheduled.ts +15 -1
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.ts +1 -1
- package/templates/new-worker.ts +4 -1
- package/templates/pages-dev-pipeline.ts +6 -2
- package/templates/pages-dev-util.ts +4 -1
- package/templates/pages-shim.ts +1 -1
- package/templates/pages-template-plugin.ts +33 -14
- package/templates/pages-template-worker.ts +12 -3
- package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +336 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +5 -103
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +241 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26345 -529
- package/wrangler-dist/cli.js +159104 -150579
- package/Cloudflare_CA.pem +0 -18
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/miniflare-dist/index.mjs +0 -6316
- package/src/__tests__/access.test.ts +0 -25
- package/src/__tests__/api-dev.test.ts +0 -209
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/api.test.ts +0 -80
- package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
- package/src/__tests__/config-cache.test.ts +0 -42
- package/src/__tests__/configuration.test.ts +0 -4028
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/delete.test.ts +0 -230
- package/src/__tests__/deployments.test.ts +0 -95
- package/src/__tests__/dev.test.tsx +0 -1509
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/generate.test.ts +0 -235
- package/src/__tests__/get-host-from-url.test.ts +0 -16
- package/src/__tests__/guess-worker-format.test.ts +0 -85
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/mock-account-id.ts +0 -48
- package/src/__tests__/helpers/mock-bin.ts +0 -36
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/helpers/mock-console.ts +0 -106
- package/src/__tests__/helpers/mock-dialogs.ts +0 -153
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
- package/src/__tests__/helpers/mock-http-server.ts +0 -46
- package/src/__tests__/helpers/mock-istty.ts +0 -74
- package/src/__tests__/helpers/mock-known-routes.ts +0 -7
- package/src/__tests__/helpers/mock-kv.ts +0 -33
- package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
- package/src/__tests__/helpers/mock-process.ts +0 -39
- package/src/__tests__/helpers/mock-stdin.ts +0 -108
- package/src/__tests__/helpers/mock-web-socket.ts +0 -29
- package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
- package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -59
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
- package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
- package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
- package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
- package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
- package/src/__tests__/helpers/msw/handlers/zones.ts +0 -22
- package/src/__tests__/helpers/msw/index.ts +0 -21
- package/src/__tests__/helpers/run-in-tmp.ts +0 -38
- package/src/__tests__/helpers/run-wrangler.ts +0 -16
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
- package/src/__tests__/helpers/write-worker-source.ts +0 -31
- package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
- package/src/__tests__/https-options.test.ts +0 -163
- package/src/__tests__/index.test.ts +0 -262
- package/src/__tests__/init.test.ts +0 -2900
- package/src/__tests__/jest.setup.ts +0 -202
- package/src/__tests__/kv.test.ts +0 -1675
- package/src/__tests__/logger.test.ts +0 -141
- package/src/__tests__/metrics.test.ts +0 -450
- package/src/__tests__/middleware.scheduled.test.ts +0 -135
- package/src/__tests__/middleware.test.ts +0 -726
- package/src/__tests__/package-manager.test.ts +0 -353
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/__tests__/parse.test.ts +0 -330
- package/src/__tests__/paths.test.ts +0 -39
- package/src/__tests__/publish.test.ts +0 -7660
- package/src/__tests__/pubsub.test.ts +0 -370
- package/src/__tests__/queues.test.ts +0 -371
- package/src/__tests__/r2.test.ts +0 -376
- package/src/__tests__/route.test.ts +0 -45
- package/src/__tests__/secret.test.ts +0 -644
- package/src/__tests__/tail.test.ts +0 -800
- package/src/__tests__/test-old-node-version.js +0 -31
- package/src/__tests__/type-generation.test.ts +0 -217
- package/src/__tests__/user.test.ts +0 -155
- package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
- package/src/__tests__/validate-dev-props.test.ts +0 -56
- package/src/__tests__/version.test.ts +0 -35
- package/src/__tests__/whoami.test.tsx +0 -278
- package/src/__tests__/worker-namespace.test.ts +0 -326
- package/src/abort.d.ts +0 -3
- package/src/api/dev.ts +0 -208
- package/src/api/index.ts +0 -2
- package/src/bundle-reporter.tsx +0 -68
- package/src/bundle.ts +0 -785
- package/src/cfetch/index.ts +0 -160
- package/src/cfetch/internal.ts +0 -263
- package/src/cli.ts +0 -28
- package/src/config/README.md +0 -107
- package/src/config/config.ts +0 -275
- package/src/config/diagnostics.ts +0 -80
- package/src/config/environment.ts +0 -563
- package/src/config/index.ts +0 -342
- package/src/config/validation-helpers.ts +0 -597
- package/src/config/validation.ts +0 -2113
- package/src/config-cache.ts +0 -85
- package/src/create-worker-preview.ts +0 -282
- package/src/create-worker-upload-form.ts +0 -321
- package/src/d1/backups.tsx +0 -218
- package/src/d1/create.tsx +0 -54
- package/src/d1/delete.tsx +0 -56
- package/src/d1/execute.tsx +0 -299
- package/src/d1/formatTimeAgo.ts +0 -14
- package/src/d1/index.ts +0 -76
- package/src/d1/list.tsx +0 -48
- package/src/d1/options.ts +0 -12
- package/src/d1/types.tsx +0 -14
- package/src/d1/utils.ts +0 -39
- package/src/delete.ts +0 -108
- package/src/deployments.ts +0 -74
- package/src/deprecated/index.ts +0 -438
- package/src/dev/dev-vars.ts +0 -39
- package/src/dev/dev.tsx +0 -587
- package/src/dev/get-local-persistence-path.tsx +0 -31
- package/src/dev/local.tsx +0 -717
- package/src/dev/remote.tsx +0 -603
- package/src/dev/start-server.ts +0 -513
- package/src/dev/use-esbuild.ts +0 -204
- package/src/dev/validate-dev-props.ts +0 -31
- package/src/dev-registry.tsx +0 -201
- package/src/dev.tsx +0 -869
- package/src/dialogs.tsx +0 -163
- package/src/dispatch-namespace.ts +0 -207
- package/src/durable.ts +0 -102
- package/src/entry.ts +0 -329
- package/src/environment-variables.ts +0 -50
- package/src/errors.ts +0 -11
- package/src/git-client.ts +0 -124
- package/src/global-wrangler-config-path.ts +0 -26
- package/src/https-options.ts +0 -127
- package/src/index.tsx +0 -684
- package/src/init.ts +0 -970
- package/src/inspect.ts +0 -767
- package/src/intl-polyfill.d.ts +0 -139
- package/src/is-ci.ts +0 -14
- package/src/is-interactive.ts +0 -16
- package/src/kv/helpers.ts +0 -430
- package/src/kv/index.ts +0 -596
- package/src/logger.ts +0 -92
- package/src/metrics/index.ts +0 -5
- package/src/metrics/metrics-config.ts +0 -239
- package/src/metrics/metrics-dispatcher.ts +0 -96
- package/src/metrics/metrics-usage-headers.ts +0 -24
- package/src/metrics/send-event.ts +0 -94
- package/src/miniflare-cli/README.md +0 -30
- package/src/miniflare-cli/assets.ts +0 -215
- package/src/miniflare-cli/index.ts +0 -213
- package/src/miniflare-cli/request-context.ts +0 -40
- package/src/module-collection.ts +0 -267
- package/src/open-in-browser.ts +0 -17
- package/src/package-manager.ts +0 -219
- package/src/pages/build.tsx +0 -238
- package/src/pages/constants.ts +0 -18
- package/src/pages/deployments.tsx +0 -106
- package/src/pages/dev.tsx +0 -693
- package/src/pages/errors.ts +0 -66
- package/src/pages/functions/buildPlugin.ts +0 -110
- package/src/pages/functions/buildWorker.ts +0 -156
- package/src/pages/functions/filepath-routing.test.ts +0 -234
- package/src/pages/functions/filepath-routing.ts +0 -189
- package/src/pages/functions/identifiers.ts +0 -78
- package/src/pages/functions/routes-consolidation.test.ts +0 -250
- package/src/pages/functions/routes-consolidation.ts +0 -73
- package/src/pages/functions/routes-transformation.test.ts +0 -282
- package/src/pages/functions/routes-transformation.ts +0 -115
- package/src/pages/functions/routes-validation.test.ts +0 -403
- package/src/pages/functions/routes-validation.ts +0 -202
- package/src/pages/functions/routes.ts +0 -151
- package/src/pages/functions.tsx +0 -82
- package/src/pages/hash.tsx +0 -13
- package/src/pages/index.tsx +0 -94
- package/src/pages/projects.tsx +0 -169
- package/src/pages/publish.tsx +0 -436
- package/src/pages/types.ts +0 -49
- package/src/pages/upload.tsx +0 -425
- package/src/pages/utils.ts +0 -12
- package/src/parse.ts +0 -286
- package/src/paths.ts +0 -71
- package/src/proxy.ts +0 -689
- package/src/publish/index.ts +0 -270
- package/src/publish/publish.ts +0 -1035
- package/src/pubsub/index.ts +0 -286
- package/src/pubsub/pubsub-commands.tsx +0 -624
- package/src/queues/cli/commands/consumer/add.ts +0 -71
- package/src/queues/cli/commands/consumer/index.ts +0 -22
- package/src/queues/cli/commands/consumer/remove.ts +0 -38
- package/src/queues/cli/commands/create.ts +0 -25
- package/src/queues/cli/commands/delete.ts +0 -26
- package/src/queues/cli/commands/index.ts +0 -33
- package/src/queues/cli/commands/list.ts +0 -25
- package/src/queues/client.ts +0 -135
- package/src/r2/helpers.ts +0 -131
- package/src/r2/index.ts +0 -277
- package/src/routes.ts +0 -140
- package/src/secret/index.ts +0 -379
- package/src/selfsigned.d.ts +0 -29
- package/src/sites.tsx +0 -372
- package/src/tail/createTail.ts +0 -315
- package/src/tail/filters.ts +0 -277
- package/src/tail/index.ts +0 -214
- package/src/tail/printing.ts +0 -107
- package/src/type-generation.ts +0 -159
- package/src/update-check.ts +0 -19
- package/src/user/access.ts +0 -69
- package/src/user/choose-account.tsx +0 -69
- package/src/user/env-vars.ts +0 -46
- package/src/user/generate-auth-url.ts +0 -33
- package/src/user/generate-random-state.ts +0 -16
- package/src/user/index.ts +0 -3
- package/src/user/user.tsx +0 -1192
- package/src/utils/collectKeyValues.ts +0 -14
- package/src/whoami.tsx +0 -169
- package/src/worker.ts +0 -242
- package/src/yargs-types.ts +0 -20
- package/src/zones.ts +0 -191
- package/templates/d1-beta-facade.js +0 -174
- package/templates/experimental-local-cache-stubs.js +0 -27
- package/templates/first-party-worker-module-facade.ts +0 -18
- package/templates/format-dev-errors.ts +0 -32
- package/templates/serve-static-assets.ts +0 -63
- package/templates/service-bindings-module-facade.js +0 -54
- 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,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,13 +0,0 @@
|
|
|
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
|
-
];
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { rest } from "msw";
|
|
2
|
-
|
|
3
|
-
import type { DeploymentListRes } from "../../../../deployments";
|
|
4
|
-
|
|
5
|
-
export const mswSuccessDeployments = [
|
|
6
|
-
rest.get(
|
|
7
|
-
"*/accounts/:accountId/workers/versions/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
|
-
];
|