wrangler 0.0.0-e61907d → 0.0.0-ece06ea
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 +51 -0
- package/bin/wrangler.js +36 -2
- package/import_meta_url.js +3 -0
- package/package.json +49 -16
- package/src/__tests__/clipboardy-mock.js +4 -0
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/index.test.ts +153 -0
- package/src/__tests__/mock-cfetch.js +46 -0
- package/src/api/form_data.ts +158 -0
- package/src/api/inspect.ts +441 -0
- package/src/api/preview.ts +123 -0
- package/src/api/worker.ts +161 -0
- package/src/cfetch.ts +72 -0
- package/src/cli.ts +10 -0
- package/src/config.ts +124 -0
- package/src/dev.tsx +736 -0
- package/src/dialogs.tsx +85 -0
- package/src/index.tsx +1845 -0
- package/src/kv.tsx +211 -0
- package/src/pages.tsx +344 -0
- package/src/publish.ts +354 -0
- package/src/sites.tsx +115 -0
- package/src/tail.tsx +71 -0
- package/src/user.tsx +1029 -0
- package/src/util/fetch.ts +74 -0
- package/wrangler-dist/{index_node.js → cli.js} +55431 -20739
- package/wrangler-dist/cli.js.map +7 -0
- package/wrangler-dist/index_node.js.map +0 -7
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|