wrangler 0.0.2 → 0.0.6

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 (69) hide show
  1. package/README.md +51 -55
  2. package/bin/wrangler.js +36 -0
  3. package/import_meta_url.js +3 -0
  4. package/miniflare-config-stubs/.env.empty +0 -0
  5. package/miniflare-config-stubs/package.empty.json +1 -0
  6. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  7. package/package.json +111 -9
  8. package/src/__tests__/clipboardy-mock.js +4 -0
  9. package/src/__tests__/index.test.ts +391 -0
  10. package/src/__tests__/jest.setup.ts +17 -0
  11. package/src/__tests__/mock-cfetch.js +42 -0
  12. package/src/__tests__/mock-dialogs.ts +65 -0
  13. package/src/api/form_data.ts +141 -0
  14. package/src/api/inspect.ts +430 -0
  15. package/src/api/preview.ts +128 -0
  16. package/src/api/worker.ts +161 -0
  17. package/src/cfetch.ts +72 -0
  18. package/src/cli.ts +10 -0
  19. package/src/config.ts +122 -0
  20. package/src/dev.tsx +867 -0
  21. package/src/dialogs.tsx +77 -0
  22. package/src/index.tsx +1875 -0
  23. package/src/kv.tsx +211 -0
  24. package/src/module-collection.ts +64 -0
  25. package/src/pages.tsx +818 -0
  26. package/src/proxy.ts +104 -0
  27. package/src/publish.ts +358 -0
  28. package/src/sites.tsx +115 -0
  29. package/src/tail.tsx +71 -0
  30. package/src/user.tsx +1029 -0
  31. package/static-asset-facade.js +47 -0
  32. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +332 -0
  33. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +176 -0
  34. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +25 -0
  35. package/vendor/@cloudflare/kv-asset-handler/README.md +245 -0
  36. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +32 -0
  37. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +354 -0
  38. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +13 -0
  39. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +148 -0
  40. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +1 -0
  41. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +436 -0
  42. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +1 -0
  43. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +40 -0
  44. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +1 -0
  45. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +42 -0
  46. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +26 -0
  47. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +31 -0
  48. package/vendor/@cloudflare/kv-asset-handler/package.json +52 -0
  49. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +296 -0
  50. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +136 -0
  51. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +464 -0
  52. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +33 -0
  53. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +42 -0
  54. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +39 -0
  55. package/vendor/wrangler-mime/CHANGELOG.md +289 -0
  56. package/vendor/wrangler-mime/LICENSE +21 -0
  57. package/vendor/wrangler-mime/Mime.js +97 -0
  58. package/vendor/wrangler-mime/README.md +187 -0
  59. package/vendor/wrangler-mime/cli.js +46 -0
  60. package/vendor/wrangler-mime/index.js +4 -0
  61. package/vendor/wrangler-mime/lite.js +4 -0
  62. package/vendor/wrangler-mime/package.json +52 -0
  63. package/vendor/wrangler-mime/types/other.js +1 -0
  64. package/vendor/wrangler-mime/types/standard.js +1 -0
  65. package/wrangler-dist/cli.js +125758 -0
  66. package/wrangler-dist/cli.js.map +7 -0
  67. package/.npmignore +0 -15
  68. package/index.js +0 -250
  69. package/tests/is.spec.js +0 -1155
package/src/cfetch.ts ADDED
@@ -0,0 +1,72 @@
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/cli.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { main } from ".";
2
+
3
+ main(process.argv.slice(2)).catch((cause) => {
4
+ const { name, message } = cause;
5
+ if (name === "CloudflareError") {
6
+ console.error("\x1b[31m", message);
7
+ return;
8
+ }
9
+ throw cause;
10
+ });
package/src/config.ts ADDED
@@ -0,0 +1,122 @@
1
+ // we're going to manually write both the type definition AND
2
+ // the validator for the config, so that we can give better error messages
3
+
4
+ type DOMigration = {
5
+ tag: string;
6
+ new_classes?: string[];
7
+ renamed_classes?: string[];
8
+ deleted_classes?: string[];
9
+ };
10
+
11
+ type Project = "webpack" | "javascript" | "rust";
12
+
13
+ type Site = {
14
+ // inherited
15
+ bucket: string;
16
+ "entry-point": string;
17
+ include?: string[];
18
+ exclude?: string[];
19
+ };
20
+
21
+ type Dev = {
22
+ ip?: string;
23
+ port?: number;
24
+ local_protocol?: string;
25
+ upstream_protocol?: string;
26
+ };
27
+
28
+ type Vars = { [key: string]: string };
29
+
30
+ type Cron = string; // TODO: we should be able to parse a cron pattern with ts
31
+
32
+ type KVNamespace = {
33
+ binding?: string;
34
+ preview_id: string;
35
+ id: string;
36
+ };
37
+
38
+ type DurableObject = {
39
+ name: string;
40
+ class_name: string;
41
+ script_name?: string;
42
+ };
43
+
44
+ type Build = {
45
+ command?: string;
46
+ cwd?: string;
47
+ watch_dir?: string;
48
+ } & (
49
+ | {
50
+ upload?: {
51
+ format: "service-worker";
52
+ main: string;
53
+ };
54
+ }
55
+ | {
56
+ upload?: {
57
+ format: "modules";
58
+ dir?: string;
59
+ main?: string;
60
+ rules?: {
61
+ type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm";
62
+ globs: string[]; // can we use typescript for these patterns?
63
+ fallthrough?: boolean;
64
+ };
65
+ };
66
+ }
67
+ );
68
+
69
+ type UsageModel = "bundled" | "unbound";
70
+
71
+ type Env = {
72
+ name?: string; // inherited
73
+ account_id?: string; // inherited
74
+ workers_dev?: boolean; // inherited
75
+ compatibility_date?: string; // inherited
76
+ compatibility_flags?: string[]; // inherited
77
+ zone_id?: string; // inherited
78
+ routes?: string[]; // inherited
79
+ route?: string; // inherited
80
+ webpack_config?: string; // inherited
81
+ site?: Site;
82
+ jsx_factory?: string; // inherited
83
+ jsx_fragment?: string; // inherited
84
+ // we should use typescript to parse cron patterns
85
+ triggers?: { crons: Cron[] }; // inherited
86
+ vars?: Vars;
87
+ durable_objects?: { bindings: DurableObject[] };
88
+ kv_namespaces?: KVNamespace[];
89
+ usage_model?: UsageModel; // inherited
90
+ };
91
+
92
+ export type Config = {
93
+ name?: string; // inherited
94
+ account_id?: string; // inherited
95
+ // @deprecated Don't use this
96
+ type?: Project; // top level
97
+ compatibility_date?: string; // inherited
98
+ compatibility_flags?: string[]; // inherited
99
+ // -- there's some mutually exclusive logic for this next block,
100
+ // but I didn't bother for now
101
+ workers_dev?: boolean; // inherited
102
+ zone_id?: string; // inherited
103
+ routes?: string[]; // inherited
104
+ route?: string; // inherited
105
+ // -- end mutually exclusive stuff
106
+ // @deprecated Don't use this
107
+ webpack_config?: string; // inherited
108
+ jsx_factory?: string; // inherited
109
+ jsx_fragment?: string; // inherited
110
+ vars?: Vars;
111
+ migrations?: DOMigration[];
112
+ durable_objects?: { bindings: DurableObject[] };
113
+ kv_namespaces?: KVNamespace[];
114
+ site?: Site; // inherited
115
+ // we should use typescript to parse cron patterns
116
+ triggers?: { crons: Cron[] }; // inherited
117
+ dev?: Dev;
118
+ usage_model?: UsageModel; // inherited
119
+ // top level
120
+ build?: Build;
121
+ env?: { [envName: string]: void | Env };
122
+ };