wrangler 0.0.0-ece06ea → 0.0.0-eebdb6c
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/package.json +22 -15
- package/pages/functions/buildWorker.ts +57 -0
- package/pages/functions/filepath-routing.test.ts +32 -0
- package/pages/functions/filepath-routing.ts +225 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +158 -0
- package/pages/functions/template-worker.ts +135 -0
- package/src/__tests__/index.test.ts +254 -120
- package/src/__tests__/jest.setup.ts +22 -0
- package/src/__tests__/kv.test.ts +1098 -0
- package/src/__tests__/mock-cfetch.ts +171 -0
- package/src/__tests__/mock-dialogs.ts +65 -0
- package/src/__tests__/run-in-tmp.ts +19 -0
- package/src/__tests__/run-wrangler.ts +32 -0
- package/src/api/form_data.ts +70 -97
- package/src/api/inspect.ts +0 -11
- package/src/api/preview.ts +29 -24
- package/src/api/worker.ts +34 -40
- package/src/cfetch/index.ts +103 -0
- package/src/cfetch/internal.ts +69 -0
- package/src/cli.ts +6 -7
- package/src/config.ts +14 -7
- package/src/dev.tsx +274 -131
- package/src/dialogs.tsx +4 -12
- package/src/index.tsx +304 -245
- package/src/kv.tsx +101 -45
- package/src/module-collection.ts +64 -0
- package/src/pages.tsx +681 -104
- package/src/proxy.ts +103 -0
- package/src/publish.ts +54 -58
- package/src/sites.tsx +5 -6
- package/src/tail.tsx +5 -3
- package/src/user.tsx +9 -16
- package/wrangler-dist/cli.js +36633 -49770
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/cfetch.ts +0 -72
- package/src/util/fetch.ts +0 -74
|
File without changes
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// This file mocks ../cfetch.ts
|
|
2
|
-
// so we can insert whatever responses we want from it
|
|
3
|
-
|
|
4
|
-
const pathToRegexp = require("path-to-regexp");
|
|
5
|
-
// TODO: add jsdoc style types here
|
|
6
|
-
|
|
7
|
-
// type MockHandler = (resource: string, init?: RequestInit) => any; // TODO: use a generic here
|
|
8
|
-
|
|
9
|
-
let mocks = [];
|
|
10
|
-
|
|
11
|
-
function mockCfetch(resource, init) {
|
|
12
|
-
for (const { regexp, handler } of mocks) {
|
|
13
|
-
if (regexp.test(resource)) {
|
|
14
|
-
return handler(resource, init); // should we have some kind of fallthrough system? we'll see.
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`no mocks found for ${resource}`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function setMock(resource, handler) {
|
|
21
|
-
const mock = {
|
|
22
|
-
resource,
|
|
23
|
-
handler,
|
|
24
|
-
regexp: pathToRegexp(resource),
|
|
25
|
-
};
|
|
26
|
-
mocks.push(mock);
|
|
27
|
-
return () => {
|
|
28
|
-
mocks = mocks.filter((x) => x !== mock);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function unsetAllMocks() {
|
|
33
|
-
mocks = [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const CF_API_BASE_URL =
|
|
37
|
-
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
|
38
|
-
|
|
39
|
-
Object.assign(module.exports, {
|
|
40
|
-
__esModule: true,
|
|
41
|
-
default: mockCfetch,
|
|
42
|
-
mockCfetch,
|
|
43
|
-
setMock,
|
|
44
|
-
unsetAllMocks,
|
|
45
|
-
CF_API_BASE_URL,
|
|
46
|
-
});
|
package/src/cfetch.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
import type { RequestInit } from "node-fetch";
|
|
3
|
-
import { getAPIToken } from "./user";
|
|
4
|
-
import { loginOrRefreshIfRequired } from "./user";
|
|
5
|
-
|
|
6
|
-
export const CF_API_BASE_URL =
|
|
7
|
-
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
|
8
|
-
|
|
9
|
-
export default async function fetchWithAuthAndLoginIfRequired<ResponseType>(
|
|
10
|
-
resource: string,
|
|
11
|
-
init: RequestInit = {}
|
|
12
|
-
): Promise<ResponseType> {
|
|
13
|
-
const loggedIn = await loginOrRefreshIfRequired();
|
|
14
|
-
if (!loggedIn) {
|
|
15
|
-
throw new Error("Not logged in");
|
|
16
|
-
}
|
|
17
|
-
const apiToken = getAPIToken();
|
|
18
|
-
if (!apiToken) {
|
|
19
|
-
throw new Error("No API token found");
|
|
20
|
-
}
|
|
21
|
-
// @ts-expect-error Authorization isn't non HeadersInit, annoyingly
|
|
22
|
-
if (init.headers?.Authorization) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"fetchWithAuthAndLoginIfRequired will not add an authorisation header a request that already specifies it"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
// should I bother with response code?
|
|
28
|
-
// maybe I can just throw the json error?
|
|
29
|
-
|
|
30
|
-
const response = await fetch(`${CF_API_BASE_URL}${resource}`, {
|
|
31
|
-
method: "GET",
|
|
32
|
-
...init,
|
|
33
|
-
headers: {
|
|
34
|
-
...(init.headers || {}),
|
|
35
|
-
Authorization: `Bearer ${apiToken}`,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
const text = await response.text();
|
|
39
|
-
let json;
|
|
40
|
-
try {
|
|
41
|
-
json = JSON.parse(text);
|
|
42
|
-
} catch (parseError) {
|
|
43
|
-
// hate this edge case
|
|
44
|
-
// the only api call I know that doesn't return json is kv:key get <key>
|
|
45
|
-
|
|
46
|
-
// maybe it's a plain response
|
|
47
|
-
if (response.ok) {
|
|
48
|
-
// @ts-expect-error bleh
|
|
49
|
-
return text;
|
|
50
|
-
} else {
|
|
51
|
-
// UGH.
|
|
52
|
-
throw new Error(`${response.status}: ${response.statusText}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (json.success) {
|
|
57
|
-
return json.result;
|
|
58
|
-
} else {
|
|
59
|
-
const errorDesc = json.errors?.[0];
|
|
60
|
-
if (errorDesc) {
|
|
61
|
-
// TODO: map .message to real human readable strings
|
|
62
|
-
const error = new Error(`${errorDesc.code}: ${errorDesc.message}`);
|
|
63
|
-
// @ts-expect-error hacksss
|
|
64
|
-
error.code = errorDesc.code;
|
|
65
|
-
throw error;
|
|
66
|
-
} else {
|
|
67
|
-
// This should almost never happen.
|
|
68
|
-
// ... which means it'll probably happen, lol.
|
|
69
|
-
throw new Error(`${response.status}: ${response.statusText}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/util/fetch.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import fetch, { Headers } from "node-fetch";
|
|
2
|
-
import type { Response, HeadersInit, RequestInit } from "node-fetch";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A `fetch()` function.
|
|
6
|
-
*
|
|
7
|
-
* @link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
8
|
-
*/
|
|
9
|
-
export type Fetch = (input: string, init?: RequestInit) => Promise<Response>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Default options for creating a `fetch()` function.
|
|
13
|
-
*/
|
|
14
|
-
export interface FetchInit {
|
|
15
|
-
/**
|
|
16
|
-
* The host.
|
|
17
|
-
*/
|
|
18
|
-
host?: string;
|
|
19
|
-
/**
|
|
20
|
-
* The user agent.
|
|
21
|
-
*/
|
|
22
|
-
userAgent?: string;
|
|
23
|
-
/**
|
|
24
|
-
* The header map.
|
|
25
|
-
*/
|
|
26
|
-
headers?: HeadersInit;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Creates a custom `fetch()` function.
|
|
31
|
-
*/
|
|
32
|
-
export function fetchIt(init: FetchInit = {}): Fetch {
|
|
33
|
-
const { host, headers: headersInit, userAgent } = init;
|
|
34
|
-
|
|
35
|
-
return async (input: string, init: RequestInit = {}) => {
|
|
36
|
-
if (input.startsWith("/")) {
|
|
37
|
-
input = `https://${host}${input}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const headers = new Headers(headersInit);
|
|
41
|
-
if (userAgent) {
|
|
42
|
-
headers.set("User-Agent", userAgent);
|
|
43
|
-
}
|
|
44
|
-
for (const [name, value] of new Headers(init.headers).entries()) {
|
|
45
|
-
headers.set(name, value);
|
|
46
|
-
}
|
|
47
|
-
init.headers = headers;
|
|
48
|
-
|
|
49
|
-
return fetch(input, init);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* A `fetch()` function that outputs a JSON response.
|
|
55
|
-
*/
|
|
56
|
-
export type FetchJson = <T>(input: string, init?: RequestInit) => Promise<T>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a custom `fetch()` function for JSON responses.
|
|
60
|
-
*/
|
|
61
|
-
export function fetchJson(init?: FetchInit): FetchJson {
|
|
62
|
-
const fetch = fetchIt(init);
|
|
63
|
-
|
|
64
|
-
return async (input: string, init: RequestInit = {}) => {
|
|
65
|
-
const response = await fetch(input, init);
|
|
66
|
-
const text = await response.text();
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
return JSON.parse(text);
|
|
70
|
-
} catch (cause) {
|
|
71
|
-
throw new Error("Expected a JSON response, but instead got: " + text);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|