wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
package/src/cfetch/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { URLSearchParams } from "node:url";
|
|
2
|
+
import { logger } from "../logger";
|
|
2
3
|
import { ParseError } from "../parse";
|
|
3
|
-
import { fetchInternal } from "./internal";
|
|
4
|
+
import { fetchInternal, performApiFetch } from "./internal";
|
|
4
5
|
import type { RequestInit } from "undici";
|
|
5
6
|
|
|
6
7
|
// Check out https://api.cloudflare.com/ for API docs.
|
|
7
8
|
|
|
8
|
-
export { getCloudflareAPIBaseURL as getCloudflareApiBaseUrl } from "./internal";
|
|
9
|
-
|
|
10
9
|
export interface FetchError {
|
|
11
10
|
code: number;
|
|
12
11
|
message: string;
|
|
@@ -119,3 +118,41 @@ function renderError(err: FetchError, level = 0): string {
|
|
|
119
118
|
chainedMessages
|
|
120
119
|
);
|
|
121
120
|
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Fetch the raw script content of a Worker
|
|
124
|
+
* Note, this will concatenate the files of multi-module workers
|
|
125
|
+
*/
|
|
126
|
+
export async function fetchScriptContent(
|
|
127
|
+
resource: string,
|
|
128
|
+
init: RequestInit = {},
|
|
129
|
+
queryParams?: URLSearchParams,
|
|
130
|
+
abortSignal?: AbortSignal
|
|
131
|
+
): Promise<string> {
|
|
132
|
+
const response = await performApiFetch(
|
|
133
|
+
resource,
|
|
134
|
+
init,
|
|
135
|
+
queryParams,
|
|
136
|
+
abortSignal
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
logger.debug(
|
|
140
|
+
"-- START CF API RESPONSE:",
|
|
141
|
+
response.statusText,
|
|
142
|
+
response.status
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
logger.debug("HEADERS:", { ...response.headers });
|
|
146
|
+
// logger.debug("RESPONSE:", text);
|
|
147
|
+
logger.debug("-- END CF API RESPONSE");
|
|
148
|
+
const contentType = response.headers.get("content-type");
|
|
149
|
+
|
|
150
|
+
const usesModules = contentType?.startsWith("multipart");
|
|
151
|
+
if (usesModules && contentType) {
|
|
152
|
+
const form = await response.formData();
|
|
153
|
+
const entries = Array.from(form.entries());
|
|
154
|
+
return entries.map((e) => e[1]).join("\n");
|
|
155
|
+
} else {
|
|
156
|
+
return await response.text();
|
|
157
|
+
}
|
|
158
|
+
}
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import { fetch, Headers } from "undici";
|
|
2
|
+
import { fetch, File, Headers } from "undici";
|
|
3
3
|
import { version as wranglerVersion } from "../../package.json";
|
|
4
|
-
import {
|
|
4
|
+
import { getCloudflareApiBaseUrl } from "../environment-variables/misc-variables";
|
|
5
|
+
import { logger } from "../logger";
|
|
5
6
|
import { ParseError, parseJSON } from "../parse";
|
|
6
7
|
import { loginOrRefreshIfRequired, requireApiToken } from "../user";
|
|
7
8
|
import type { ApiCredentials } from "../user";
|
|
8
9
|
import type { URLSearchParams } from "node:url";
|
|
9
|
-
import type { RequestInit, HeadersInit } from "undici";
|
|
10
|
+
import type { RequestInit, HeadersInit, Response } from "undici";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
12
|
+
/*
|
|
13
|
+
* performApiFetch does everything required to make a CF API request,
|
|
14
|
+
* but doesn't parse the response as JSON. For normal V4 API responses,
|
|
15
|
+
* use `fetchInternal`
|
|
16
|
+
* */
|
|
17
|
+
export async function performApiFetch(
|
|
18
|
+
resource: string,
|
|
19
|
+
init: RequestInit = {},
|
|
20
|
+
queryParams?: URLSearchParams,
|
|
21
|
+
abortSignal?: AbortSignal
|
|
22
|
+
) {
|
|
23
|
+
const method = init.method ?? "GET";
|
|
24
|
+
assert(
|
|
25
|
+
resource.startsWith("/"),
|
|
26
|
+
`CF API fetch - resource path must start with a "/" but got "${resource}"`
|
|
27
|
+
);
|
|
28
|
+
await requireLoggedIn();
|
|
29
|
+
const apiToken = requireApiToken();
|
|
30
|
+
const headers = cloneHeaders(init.headers);
|
|
31
|
+
addAuthorizationHeaderIfUnspecified(headers, apiToken);
|
|
32
|
+
addUserAgent(headers);
|
|
33
|
+
|
|
34
|
+
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
35
|
+
logger.debug(
|
|
36
|
+
`-- START CF API REQUEST: ${method} ${getCloudflareApiBaseUrl()}${resource}${queryString}`
|
|
37
|
+
);
|
|
38
|
+
const logHeaders = cloneHeaders(headers);
|
|
39
|
+
delete logHeaders["Authorization"];
|
|
40
|
+
logger.debug("HEADERS:", JSON.stringify(logHeaders, null, 2));
|
|
41
|
+
logger.debug(
|
|
42
|
+
"INIT:",
|
|
43
|
+
JSON.stringify({ ...init, headers: logHeaders }, null, 2)
|
|
44
|
+
);
|
|
45
|
+
logger.debug("-- END CF API REQUEST");
|
|
46
|
+
return await fetch(`${getCloudflareApiBaseUrl()}${resource}${queryString}`, {
|
|
47
|
+
method,
|
|
48
|
+
...init,
|
|
49
|
+
headers,
|
|
50
|
+
signal: abortSignal,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
19
53
|
|
|
20
54
|
/**
|
|
21
55
|
* Make a fetch request to the Cloudflare API.
|
|
@@ -32,28 +66,25 @@ export async function fetchInternal<ResponseType>(
|
|
|
32
66
|
queryParams?: URLSearchParams,
|
|
33
67
|
abortSignal?: AbortSignal
|
|
34
68
|
): Promise<ResponseType> {
|
|
35
|
-
assert(
|
|
36
|
-
resource.startsWith("/"),
|
|
37
|
-
`CF API fetch - resource path must start with a "/" but got "${resource}"`
|
|
38
|
-
);
|
|
39
|
-
await requireLoggedIn();
|
|
40
|
-
const apiToken = requireApiToken();
|
|
41
|
-
const headers = cloneHeaders(init.headers);
|
|
42
|
-
addAuthorizationHeaderIfUnspecified(headers, apiToken);
|
|
43
|
-
addUserAgent(headers);
|
|
44
|
-
|
|
45
|
-
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
46
69
|
const method = init.method ?? "GET";
|
|
47
|
-
const response = await
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
headers,
|
|
53
|
-
signal: abortSignal,
|
|
54
|
-
}
|
|
70
|
+
const response = await performApiFetch(
|
|
71
|
+
resource,
|
|
72
|
+
init,
|
|
73
|
+
queryParams,
|
|
74
|
+
abortSignal
|
|
55
75
|
);
|
|
56
76
|
const jsonText = await response.text();
|
|
77
|
+
logger.debug(
|
|
78
|
+
"-- START CF API RESPONSE:",
|
|
79
|
+
response.statusText,
|
|
80
|
+
response.status
|
|
81
|
+
);
|
|
82
|
+
const logHeaders = cloneHeaders(response.headers);
|
|
83
|
+
delete logHeaders["Authorization"];
|
|
84
|
+
logger.debug("HEADERS:", JSON.stringify(logHeaders, null, 2));
|
|
85
|
+
logger.debug("RESPONSE:", jsonText);
|
|
86
|
+
logger.debug("-- END CF API RESPONSE");
|
|
87
|
+
|
|
57
88
|
try {
|
|
58
89
|
return parseJSON<ResponseType>(jsonText);
|
|
59
90
|
} catch (err) {
|
|
@@ -124,7 +155,6 @@ function addUserAgent(headers: Record<string, string>): void {
|
|
|
124
155
|
* Note: any calls to fetchKVGetValue must call encodeURIComponent on key
|
|
125
156
|
* before passing it
|
|
126
157
|
*/
|
|
127
|
-
|
|
128
158
|
export async function fetchKVGetValue(
|
|
129
159
|
accountId: string,
|
|
130
160
|
namespaceId: string,
|
|
@@ -134,7 +164,7 @@ export async function fetchKVGetValue(
|
|
|
134
164
|
const auth = requireApiToken();
|
|
135
165
|
const headers: Record<string, string> = {};
|
|
136
166
|
addAuthorizationHeaderIfUnspecified(headers, auth);
|
|
137
|
-
const resource = `${
|
|
167
|
+
const resource = `${getCloudflareApiBaseUrl()}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
|
|
138
168
|
const response = await fetch(resource, {
|
|
139
169
|
method: "GET",
|
|
140
170
|
headers,
|
|
@@ -147,3 +177,85 @@ export async function fetchKVGetValue(
|
|
|
147
177
|
);
|
|
148
178
|
}
|
|
149
179
|
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The implementation for fetching a R2 object from Cloudflare API.
|
|
183
|
+
* We have a special implementation to handle the non-standard API response
|
|
184
|
+
* that doesn't return JSON, likely due to the streaming nature.
|
|
185
|
+
*
|
|
186
|
+
* note: The implementation should be called from light wrappers for
|
|
187
|
+
* different methods (GET, PUT)
|
|
188
|
+
*/
|
|
189
|
+
type ResponseWithBody = Response & { body: NonNullable<Response["body"]> };
|
|
190
|
+
export async function fetchR2Objects(
|
|
191
|
+
resource: string,
|
|
192
|
+
bodyInit: RequestInit = {}
|
|
193
|
+
): Promise<ResponseWithBody> {
|
|
194
|
+
await requireLoggedIn();
|
|
195
|
+
const auth = requireApiToken();
|
|
196
|
+
const headers = cloneHeaders(bodyInit.headers);
|
|
197
|
+
addAuthorizationHeaderIfUnspecified(headers, auth);
|
|
198
|
+
addUserAgent(headers);
|
|
199
|
+
|
|
200
|
+
const response = await fetch(`${getCloudflareApiBaseUrl()}${resource}`, {
|
|
201
|
+
...bodyInit,
|
|
202
|
+
headers,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (response.ok && response.body) {
|
|
206
|
+
return response as ResponseWithBody;
|
|
207
|
+
} else {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Failed to fetch ${resource} - ${response.status}: ${response.statusText});`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* This is a wrapper STOPGAP for getting the script which returns a raw text response.
|
|
216
|
+
*/
|
|
217
|
+
export async function fetchDashboardScript(
|
|
218
|
+
resource: string,
|
|
219
|
+
bodyInit: RequestInit = {}
|
|
220
|
+
): Promise<string> {
|
|
221
|
+
await requireLoggedIn();
|
|
222
|
+
const auth = requireApiToken();
|
|
223
|
+
const headers = cloneHeaders(bodyInit.headers);
|
|
224
|
+
addAuthorizationHeaderIfUnspecified(headers, auth);
|
|
225
|
+
addUserAgent(headers);
|
|
226
|
+
|
|
227
|
+
const response = await fetch(`${getCloudflareApiBaseUrl()}${resource}`, {
|
|
228
|
+
...bodyInit,
|
|
229
|
+
headers,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (!response.ok || !response.body) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
`Failed to fetch ${resource} - ${response.status}: ${response.statusText});`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const usesModules = response.headers
|
|
239
|
+
.get("content-type")
|
|
240
|
+
?.startsWith("multipart");
|
|
241
|
+
|
|
242
|
+
if (usesModules) {
|
|
243
|
+
// Response from edge contains generic "name = worker.js" for dashboard created scripts
|
|
244
|
+
const form = await response.formData();
|
|
245
|
+
const entries = Array.from(form.entries());
|
|
246
|
+
if (entries.length > 1)
|
|
247
|
+
throw new RangeError("Expected only one entry in multipart response");
|
|
248
|
+
const [_, file] = entries[0];
|
|
249
|
+
|
|
250
|
+
if (file instanceof File) {
|
|
251
|
+
return await file.text();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return file ?? "";
|
|
255
|
+
|
|
256
|
+
// Follow up on issue in Undici about multipart/form-data support & replace the workaround: https://github.com/nodejs/undici/issues/974
|
|
257
|
+
// This should be using a builtin formData() parser pattern.
|
|
258
|
+
} else {
|
|
259
|
+
return response.text();
|
|
260
|
+
}
|
|
261
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import "dotenv/config"; // Grab locally specified env params from a `.env` file.
|
|
2
1
|
import process from "process";
|
|
3
2
|
import { hideBin } from "yargs/helpers";
|
|
4
3
|
import { unstable_dev } from "./api";
|
|
5
4
|
import { FatalError } from "./errors";
|
|
6
5
|
import { main } from ".";
|
|
7
6
|
|
|
7
|
+
import type { UnstableDevWorker, UnstableDevOptions } from "./api";
|
|
8
8
|
/**
|
|
9
9
|
* The main entrypoint for the CLI.
|
|
10
10
|
* main only gets called when the script is run directly, not when it's imported as a module.
|
|
11
11
|
*/
|
|
12
|
-
if (typeof jest === "undefined" && require.main) {
|
|
12
|
+
if (typeof jest === "undefined" && require.main === module) {
|
|
13
13
|
main(hideBin(process.argv)).catch((e) => {
|
|
14
14
|
// The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
|
|
15
15
|
// Here we just want to ensure that the process exits with a non-zero code.
|
|
@@ -24,4 +24,5 @@ if (typeof jest === "undefined" && require.main) {
|
|
|
24
24
|
* It makes it possible to import wrangler from 'wrangler',
|
|
25
25
|
* and call wrangler.unstable_dev().
|
|
26
26
|
*/
|
|
27
|
-
export
|
|
27
|
+
export { unstable_dev };
|
|
28
|
+
export type { UnstableDevWorker, UnstableDevOptions };
|
package/src/config/config.ts
CHANGED
|
@@ -127,8 +127,13 @@ export interface ConfigFields<Dev extends RawDevConfig> {
|
|
|
127
127
|
* This can either be a string, or an object with additional config fields.
|
|
128
128
|
*/
|
|
129
129
|
assets:
|
|
130
|
-
|
|
|
131
|
-
|
|
130
|
+
| {
|
|
131
|
+
bucket: string;
|
|
132
|
+
include: string[];
|
|
133
|
+
exclude: string[];
|
|
134
|
+
browser_TTL: number | undefined;
|
|
135
|
+
serve_single_page_app: boolean;
|
|
136
|
+
}
|
|
132
137
|
| undefined;
|
|
133
138
|
|
|
134
139
|
/**
|
|
@@ -163,13 +168,25 @@ export interface ConfigFields<Dev extends RawDevConfig> {
|
|
|
163
168
|
[key: string]: string;
|
|
164
169
|
}
|
|
165
170
|
| undefined;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* By default, wrangler.toml is the source of truth for your environment configuration, like a terraform file.
|
|
174
|
+
*
|
|
175
|
+
* If you change your vars in the dashboard, wrangler *will* override/delete them on its next publish.
|
|
176
|
+
*
|
|
177
|
+
* If you want to keep your dashboard vars when wrangler deploys, set this field to true.
|
|
178
|
+
*
|
|
179
|
+
* @default false
|
|
180
|
+
* @nonInheritable
|
|
181
|
+
*/
|
|
182
|
+
keep_vars?: boolean;
|
|
166
183
|
}
|
|
167
184
|
|
|
168
185
|
export interface DevConfig {
|
|
169
186
|
/**
|
|
170
187
|
* IP address for the local dev server to listen on,
|
|
171
188
|
*
|
|
172
|
-
* @default `
|
|
189
|
+
* @default `0.0.0.0`
|
|
173
190
|
*/
|
|
174
191
|
ip: string;
|
|
175
192
|
|
|
@@ -180,6 +197,13 @@ export interface DevConfig {
|
|
|
180
197
|
*/
|
|
181
198
|
port: number | undefined;
|
|
182
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Port for the local dev server's inspector to listen on
|
|
202
|
+
*
|
|
203
|
+
* @default `9229`
|
|
204
|
+
*/
|
|
205
|
+
inspector_port: number | undefined;
|
|
206
|
+
|
|
183
207
|
/**
|
|
184
208
|
* Protocol that local wrangler dev server listens to requests on.
|
|
185
209
|
*
|
|
@@ -210,13 +210,18 @@ interface EnvironmentInheritable {
|
|
|
210
210
|
* @default `[]`
|
|
211
211
|
* @nonInheritable
|
|
212
212
|
*/
|
|
213
|
-
|
|
213
|
+
dispatch_namespaces: {
|
|
214
214
|
/** The binding name used to refer to the bound service. */
|
|
215
215
|
binding: string;
|
|
216
216
|
/** The namespace to bind to. */
|
|
217
217
|
namespace: string;
|
|
218
218
|
}[];
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Designates this worker as an internal-only "first-party" worker.
|
|
222
|
+
*/
|
|
223
|
+
first_party_worker: boolean | undefined;
|
|
224
|
+
|
|
220
225
|
/**
|
|
221
226
|
* TODO: remove this as it has been deprecated.
|
|
222
227
|
*
|
|
@@ -224,6 +229,36 @@ interface EnvironmentInheritable {
|
|
|
224
229
|
* So we need to include it in this type so it is available.
|
|
225
230
|
*/
|
|
226
231
|
zone_id?: string;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Specify a compiled capnp schema to use
|
|
235
|
+
* Then add a binding per field in the top level message that you will send to logfwdr
|
|
236
|
+
*
|
|
237
|
+
* @default `{schema:undefined,bindings:[]}`
|
|
238
|
+
* @inheritable
|
|
239
|
+
*/
|
|
240
|
+
logfwdr: {
|
|
241
|
+
/** capnp schema filename */
|
|
242
|
+
schema: string | undefined;
|
|
243
|
+
bindings: {
|
|
244
|
+
/** The binding name used to refer to logfwdr */
|
|
245
|
+
name: string;
|
|
246
|
+
/** The destination for this logged message */
|
|
247
|
+
destination: string;
|
|
248
|
+
}[];
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Send Trace Events from this worker to Workers Logpush.
|
|
253
|
+
*
|
|
254
|
+
* This will not configure a corresponding Logpush job automatically.
|
|
255
|
+
*
|
|
256
|
+
* For more information about Workers Logpush, see:
|
|
257
|
+
* https://blog.cloudflare.com/logpush-for-workers/
|
|
258
|
+
*
|
|
259
|
+
* @inheritable
|
|
260
|
+
*/
|
|
261
|
+
logpush: boolean | undefined;
|
|
227
262
|
}
|
|
228
263
|
|
|
229
264
|
/**
|
|
@@ -302,6 +337,44 @@ interface EnvironmentNonInheritable {
|
|
|
302
337
|
preview_id?: string;
|
|
303
338
|
}[];
|
|
304
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Specifies Queues that are bound to this Worker environment.
|
|
342
|
+
*
|
|
343
|
+
* NOTE: This field is not automatically inherited from the top level environment,
|
|
344
|
+
* and so must be specified in every named environment.
|
|
345
|
+
*
|
|
346
|
+
* @default `{}`
|
|
347
|
+
* @nonInheritable
|
|
348
|
+
*/
|
|
349
|
+
queues: {
|
|
350
|
+
/** Producer bindings */
|
|
351
|
+
producers?: {
|
|
352
|
+
/** The binding name used to refer to the Queue in the worker. */
|
|
353
|
+
binding: string;
|
|
354
|
+
|
|
355
|
+
/** The name of this Queue. */
|
|
356
|
+
queue: string;
|
|
357
|
+
}[];
|
|
358
|
+
|
|
359
|
+
/** Consumer configuration */
|
|
360
|
+
consumers?: {
|
|
361
|
+
/** The name of the queue from which this script should consume. */
|
|
362
|
+
queue: string;
|
|
363
|
+
|
|
364
|
+
/** The maximum number of messages per batch */
|
|
365
|
+
max_batch_size?: number;
|
|
366
|
+
|
|
367
|
+
/** The maximum number of seconds to wait to fill a batch with messages. */
|
|
368
|
+
max_batch_timeout?: number;
|
|
369
|
+
|
|
370
|
+
/** The maximum number of retries for each message. */
|
|
371
|
+
max_retries?: number;
|
|
372
|
+
|
|
373
|
+
/** The queue to send messages that failed to be consumed. */
|
|
374
|
+
dead_letter_queue?: string;
|
|
375
|
+
}[];
|
|
376
|
+
};
|
|
377
|
+
|
|
305
378
|
/**
|
|
306
379
|
* Specifies R2 buckets that are bound to this Worker environment.
|
|
307
380
|
*
|
|
@@ -320,6 +393,32 @@ interface EnvironmentNonInheritable {
|
|
|
320
393
|
preview_bucket_name?: string;
|
|
321
394
|
}[];
|
|
322
395
|
|
|
396
|
+
/**
|
|
397
|
+
* Specifies D1 databases that are bound to this Worker environment.
|
|
398
|
+
*
|
|
399
|
+
* NOTE: This field is not automatically inherited from the top level environment,
|
|
400
|
+
* and so must be specified in every named environment.
|
|
401
|
+
*
|
|
402
|
+
* @default `[]`
|
|
403
|
+
* @nonInheritable
|
|
404
|
+
*/
|
|
405
|
+
d1_databases: {
|
|
406
|
+
/** The binding name used to refer to the D1 database in the worker. */
|
|
407
|
+
binding: string;
|
|
408
|
+
/** The name of this D1 database. */
|
|
409
|
+
database_name: string;
|
|
410
|
+
/** The UUID of this D1 database (not required). */
|
|
411
|
+
database_id: string;
|
|
412
|
+
/** The UUID of this D1 database for Wrangler Dev (if specified). */
|
|
413
|
+
preview_database_id?: string;
|
|
414
|
+
/** The name of the migrations table for this D1 database (defaults to 'd1_migrations'). */
|
|
415
|
+
migrations_table?: string;
|
|
416
|
+
/** The path to the directory of migrations for this D1 database (defaults to './migrations'). */
|
|
417
|
+
migrations_dir?: string;
|
|
418
|
+
/** Internal use only. */
|
|
419
|
+
database_internal_env?: string;
|
|
420
|
+
}[];
|
|
421
|
+
|
|
323
422
|
/**
|
|
324
423
|
* Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
|
|
325
424
|
*
|
|
@@ -329,13 +428,31 @@ interface EnvironmentNonInheritable {
|
|
|
329
428
|
* @default `[]`
|
|
330
429
|
* @nonInheritable
|
|
331
430
|
*/
|
|
332
|
-
services:
|
|
333
|
-
|
|
431
|
+
services:
|
|
432
|
+
| {
|
|
433
|
+
/** The binding name used to refer to the bound service. */
|
|
434
|
+
binding: string;
|
|
435
|
+
/** The name of the service. */
|
|
436
|
+
service: string;
|
|
437
|
+
/** The environment of the service (e.g. production, staging, etc). */
|
|
438
|
+
environment?: string;
|
|
439
|
+
}[]
|
|
440
|
+
| undefined;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Specifies analytics engine datasets that are bound to this Worker environment.
|
|
444
|
+
*
|
|
445
|
+
* NOTE: This field is not automatically inherited from the top level environment,
|
|
446
|
+
* and so must be specified in every named environment.
|
|
447
|
+
*
|
|
448
|
+
* @default `[]`
|
|
449
|
+
* @nonInheritable
|
|
450
|
+
*/
|
|
451
|
+
analytics_engine_datasets: {
|
|
452
|
+
/** The binding name used to refer to the dataset in the worker. */
|
|
334
453
|
binding: string;
|
|
335
|
-
/** The name of
|
|
336
|
-
|
|
337
|
-
/** The environment of the service (e.g. production, staging, etc). */
|
|
338
|
-
environment?: string;
|
|
454
|
+
/** The name of this dataset to write to. */
|
|
455
|
+
dataset?: string;
|
|
339
456
|
}[];
|
|
340
457
|
|
|
341
458
|
/**
|
|
@@ -375,6 +492,13 @@ interface EnvironmentDeprecated {
|
|
|
375
492
|
*/
|
|
376
493
|
zone_id?: string;
|
|
377
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Legacy way of defining KVNamespaces that is no longer supported.
|
|
497
|
+
*
|
|
498
|
+
* @deprecated DO NOT USE. This was a legacy bug from wrangler 1, that we do not want to support.
|
|
499
|
+
*/
|
|
500
|
+
"kv-namespaces"?: string;
|
|
501
|
+
|
|
378
502
|
/**
|
|
379
503
|
* A list of services that your worker should be bound to.
|
|
380
504
|
*
|