wrangler 0.0.0-e0d2f35 → 0.0.0-e101451a2

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 (132) hide show
  1. package/README.md +44 -25
  2. package/bin/wrangler.js +88 -31
  3. package/config-schema.json +3354 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +148 -94
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +170 -0
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  21. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  22. package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
  23. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  24. package/templates/middleware/middleware-pretty-error.ts +40 -0
  25. package/templates/middleware/middleware-scheduled.ts +29 -0
  26. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  27. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  28. package/templates/modules-watch-stub.js +4 -0
  29. package/templates/new-worker-scheduled.js +17 -0
  30. package/templates/new-worker-scheduled.ts +32 -0
  31. package/templates/new-worker.js +15 -0
  32. package/templates/new-worker.ts +33 -0
  33. package/templates/no-op-worker.js +10 -0
  34. package/templates/pages-dev-pipeline.ts +33 -0
  35. package/templates/pages-dev-util.ts +55 -0
  36. package/templates/pages-shim.ts +9 -0
  37. package/templates/pages-template-plugin.ts +190 -0
  38. package/templates/pages-template-worker.ts +198 -0
  39. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  40. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  41. package/templates/strip-cf-connecting-ip-header.js +13 -0
  42. package/templates/tsconfig-sanity.ts +11 -0
  43. package/templates/tsconfig.init.json +22 -0
  44. package/templates/tsconfig.json +15 -0
  45. package/templates/tsconfig.tsbuildinfo +1 -0
  46. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  47. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  48. package/wrangler-dist/ProxyWorker.js +241 -0
  49. package/wrangler-dist/ProxyWorker.js.map +6 -0
  50. package/wrangler-dist/cli.d.ts +26860 -0
  51. package/wrangler-dist/cli.js +152497 -118904
  52. package/import_meta_url.js +0 -3
  53. package/miniflare-config-stubs/.env.empty +0 -0
  54. package/miniflare-config-stubs/package.empty.json +0 -1
  55. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  56. package/pages/functions/buildWorker.ts +0 -62
  57. package/pages/functions/filepath-routing.test.ts +0 -39
  58. package/pages/functions/filepath-routing.ts +0 -228
  59. package/pages/functions/identifiers.ts +0 -78
  60. package/pages/functions/routes.ts +0 -158
  61. package/pages/functions/template-worker.ts +0 -136
  62. package/src/__tests__/clipboardy-mock.js +0 -4
  63. package/src/__tests__/dev.test.tsx +0 -71
  64. package/src/__tests__/index.test.ts +0 -424
  65. package/src/__tests__/jest.setup.ts +0 -29
  66. package/src/__tests__/kv.test.ts +0 -1224
  67. package/src/__tests__/logout.test.ts +0 -64
  68. package/src/__tests__/mock-cfetch.ts +0 -173
  69. package/src/__tests__/mock-console.ts +0 -34
  70. package/src/__tests__/mock-dialogs.ts +0 -65
  71. package/src/__tests__/mock-kv.ts +0 -40
  72. package/src/__tests__/mock-user.ts +0 -27
  73. package/src/__tests__/publish.test.ts +0 -1206
  74. package/src/__tests__/run-in-tmp.ts +0 -29
  75. package/src/__tests__/run-wrangler.ts +0 -8
  76. package/src/__tests__/secret.test.ts +0 -206
  77. package/src/__tests__/whoami.test.tsx +0 -101
  78. package/src/api/form_data.ts +0 -135
  79. package/src/api/preview.ts +0 -128
  80. package/src/api/worker.ts +0 -155
  81. package/src/cfetch/index.ts +0 -111
  82. package/src/cfetch/internal.ts +0 -71
  83. package/src/cli.ts +0 -9
  84. package/src/config.ts +0 -641
  85. package/src/dev.tsx +0 -830
  86. package/src/dialogs.tsx +0 -77
  87. package/src/index.tsx +0 -2078
  88. package/src/inspect.ts +0 -595
  89. package/src/kv.tsx +0 -276
  90. package/src/module-collection.ts +0 -63
  91. package/src/pages.tsx +0 -1043
  92. package/src/proxy.ts +0 -370
  93. package/src/publish.ts +0 -410
  94. package/src/sites.tsx +0 -240
  95. package/src/tail.tsx +0 -73
  96. package/src/user.tsx +0 -1019
  97. package/src/whoami.tsx +0 -69
  98. package/static-asset-facade.js +0 -47
  99. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  100. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  101. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  102. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  103. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  104. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  105. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  106. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  107. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  108. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  109. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  110. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  111. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  112. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  113. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  114. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  115. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  116. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  117. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  118. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  119. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  120. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  121. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  122. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  123. package/vendor/wrangler-mime/LICENSE +0 -21
  124. package/vendor/wrangler-mime/Mime.js +0 -97
  125. package/vendor/wrangler-mime/README.md +0 -187
  126. package/vendor/wrangler-mime/cli.js +0 -46
  127. package/vendor/wrangler-mime/index.js +0 -4
  128. package/vendor/wrangler-mime/lite.js +0 -4
  129. package/vendor/wrangler-mime/package.json +0 -52
  130. package/vendor/wrangler-mime/types/other.js +0 -1
  131. package/vendor/wrangler-mime/types/standard.js +0 -1
  132. package/wrangler-dist/cli.js.map +0 -7
package/src/api/worker.ts DELETED
@@ -1,155 +0,0 @@
1
- import type { CfPreviewToken } from "./preview";
2
- import { previewToken } from "./preview";
3
- import fetch from "node-fetch";
4
-
5
- /**
6
- * A Cloudflare account.
7
- */
8
- export interface CfAccount {
9
- /**
10
- * An API token.
11
- *
12
- * @link https://api.cloudflare.com/#user-api-tokens-properties
13
- */
14
- apiToken: string;
15
- /**
16
- * An account ID.
17
- */
18
- accountId: string;
19
- /**
20
- * A zone ID, only required if not using `workers.dev`.
21
- */
22
- zoneId?: string;
23
- }
24
-
25
- /**
26
- * A module type.
27
- */
28
- export type CfModuleType =
29
- | "esm"
30
- | "commonjs"
31
- | "compiled-wasm"
32
- | "text"
33
- | "buffer";
34
-
35
- /**
36
- * An imported module.
37
- */
38
- export interface CfModule {
39
- /**
40
- * The module name.
41
- *
42
- * @example
43
- * './src/index.js'
44
- */
45
- name: string;
46
- /**
47
- * The module content, usually JavaScript or WASM code.
48
- *
49
- * @example
50
- * export default {
51
- * async fetch(request) {
52
- * return new Response('Ok')
53
- * }
54
- * }
55
- */
56
- content: string | BufferSource;
57
- /**
58
- * The module type.
59
- *
60
- * If absent, will default to the main module's type.
61
- */
62
- type?: CfModuleType;
63
- }
64
-
65
- /**
66
- * A map of variable names to values.
67
- */
68
- interface CfVars {
69
- [key: string]: string;
70
- }
71
-
72
- /**
73
- * A KV namespace.
74
- */
75
- interface CfKvNamespace {
76
- binding: string;
77
- id: string;
78
- }
79
-
80
- /**
81
- * A Durable Object.
82
- */
83
- interface CfDurableObject {
84
- name: string;
85
- class_name: string;
86
- script_name?: string;
87
- }
88
-
89
- /**
90
- * A Service.
91
- */
92
- interface CfService {
93
- name: string;
94
- service: string;
95
- environment: string;
96
- }
97
-
98
- export interface CfDurableObjectMigrations {
99
- old_tag?: string;
100
- new_tag: string;
101
- steps: {
102
- new_classes?: string[];
103
- renamed_classes?: string[];
104
- deleted_classes?: string[];
105
- }[];
106
- }
107
-
108
- /**
109
- * Options for creating a `CfWorker`.
110
- */
111
- export interface CfWorkerInit {
112
- /**
113
- * The name of the worker.
114
- */
115
- name: string | undefined;
116
- /**
117
- * The entrypoint module.
118
- */
119
- main: CfModule;
120
- /**
121
- * The list of additional modules.
122
- */
123
- modules: undefined | CfModule[];
124
- /**
125
- * All the bindings
126
- */
127
- bindings: {
128
- kv_namespaces?: CfKvNamespace[];
129
- durable_objects?: { bindings: CfDurableObject[] };
130
- vars?: CfVars;
131
- services?: CfService[];
132
- };
133
- migrations: undefined | CfDurableObjectMigrations;
134
- compatibility_date: string | undefined;
135
- compatibility_flags: undefined | string[];
136
- usage_model: undefined | "bundled" | "unbound";
137
- }
138
-
139
- /**
140
- * A stub to create a Cloudflare Worker preview.
141
- *
142
- * @example
143
- * const {value, host} = await createWorker(init, acct);
144
- */
145
- export async function createWorker(
146
- init: CfWorkerInit,
147
- account: CfAccount
148
- ): Promise<CfPreviewToken> {
149
- const token = await previewToken(account, init);
150
- const response = await fetch(token.prewarmUrl.href, { method: "POST" });
151
- if (!response.ok) {
152
- // console.error("worker failed to prewarm: ", response.statusText);
153
- }
154
- return token;
155
- }
@@ -1,111 +0,0 @@
1
- import type { RequestInit } from "node-fetch";
2
- import { URLSearchParams } from "url";
3
- import { fetchInternal } from "./internal";
4
-
5
- // Check out https://api.cloudflare.com/ for API docs.
6
-
7
- export { CF_API_BASE_URL } from "./internal";
8
-
9
- export interface FetchError {
10
- code: number;
11
- message: string;
12
- }
13
- export interface FetchResult<ResponseType = unknown> {
14
- success: boolean;
15
- result: ResponseType;
16
- errors: FetchError[];
17
- messages: string[];
18
- result_info?: unknown;
19
- }
20
-
21
- /**
22
- * Make a fetch request for a raw JSON value.
23
- */
24
- export async function fetchRaw<ResponseType>(
25
- resource: string,
26
- init: RequestInit = {},
27
- queryParams?: URLSearchParams
28
- ): Promise<ResponseType> {
29
- return fetchInternal<ResponseType>(resource, init, queryParams);
30
- }
31
-
32
- /**
33
- * Make a fetch request, and extract the `result` from the JSON response.
34
- */
35
- export async function fetchResult<ResponseType>(
36
- resource: string,
37
- init: RequestInit = {},
38
- queryParams?: URLSearchParams
39
- ): Promise<ResponseType> {
40
- const json = await fetchInternal<FetchResult<ResponseType>>(
41
- resource,
42
- init,
43
- queryParams
44
- );
45
- if (json.success) {
46
- return json.result;
47
- } else {
48
- throwFetchError(resource, json);
49
- }
50
- }
51
-
52
- /**
53
- * Make a fetch request for a list of values,
54
- * extracting the `result` from the JSON response,
55
- * and repeating the request if the results are paginated.
56
- */
57
- export async function fetchListResult<ResponseType>(
58
- resource: string,
59
- init: RequestInit = {},
60
- queryParams?: URLSearchParams
61
- ): Promise<ResponseType[]> {
62
- const results: ResponseType[] = [];
63
- let getMoreResults = true;
64
- let cursor: string | undefined;
65
- while (getMoreResults) {
66
- if (cursor) {
67
- queryParams = new URLSearchParams(queryParams);
68
- queryParams.set("cursor", cursor);
69
- }
70
- const json = await fetchInternal<FetchResult<ResponseType[]>>(
71
- resource,
72
- init,
73
- queryParams
74
- );
75
- if (json.success) {
76
- results.push(...json.result);
77
- if (hasCursor(json.result_info)) {
78
- cursor = json.result_info?.cursor;
79
- } else {
80
- getMoreResults = false;
81
- }
82
- } else {
83
- throwFetchError(resource, json);
84
- }
85
- }
86
- return results;
87
- }
88
-
89
- function throwFetchError(
90
- resource: string,
91
- response: FetchResult<unknown>
92
- ): never {
93
- response.messages.forEach((message) => console.warn(message));
94
- const errors = response.errors
95
- .map((error) => `${error.code}: ${error.message}`)
96
- .join("\n");
97
- const error = new Error(`Failed to fetch ${resource} - \n${errors}`);
98
- // add the first error code directly to this error
99
- // so consumers can use it for specific behaviour
100
- const code = response.errors[0]?.code;
101
- if (code) {
102
- //@ts-expect-error non-standard property on Error
103
- error.code = code;
104
- }
105
- throw error;
106
- }
107
-
108
- function hasCursor(result_info: unknown): result_info is { cursor: string } {
109
- const cursor = (result_info as { cursor: string } | undefined)?.cursor;
110
- return cursor !== undefined && cursor !== null && cursor !== "";
111
- }
@@ -1,71 +0,0 @@
1
- import fetch from "node-fetch";
2
- import type { RequestInit, HeadersInit } from "node-fetch";
3
- import { getAPIToken, loginOrRefreshIfRequired } from "../user";
4
-
5
- export const CF_API_BASE_URL =
6
- process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
7
-
8
- /**
9
- * Make a fetch request to the Cloudflare API.
10
- *
11
- * This function handles acquiring the API token and logging the caller in, as necessary.
12
- *
13
- * Check out https://api.cloudflare.com/ for API docs.
14
- *
15
- * This function should not be used directly, instead use the functions in `cfetch/index.ts`.
16
- */
17
- export async function fetchInternal<ResponseType>(
18
- resource: string,
19
- init: RequestInit = {},
20
- queryParams?: URLSearchParams
21
- ): Promise<ResponseType> {
22
- await requireLoggedIn();
23
- const apiToken = requireApiToken();
24
- const headers = cloneHeaders(init.headers);
25
- addAuthorizationHeader(headers, apiToken);
26
-
27
- const queryString = queryParams ? `?${queryParams.toString()}` : "";
28
- const response = await fetch(`${CF_API_BASE_URL}${resource}${queryString}`, {
29
- method: "GET",
30
- ...init,
31
- headers,
32
- });
33
-
34
- const jsonText = await response.text();
35
- try {
36
- const json = JSON.parse(jsonText);
37
- return json as ResponseType;
38
- } catch (e) {
39
- throw new Error(
40
- `Failed to fetch ${resource} - ${response.status}: ${response.statusText}\nInvalid JSON response:\n${jsonText}`
41
- );
42
- }
43
- }
44
-
45
- function cloneHeaders(headers: HeadersInit | undefined): HeadersInit {
46
- return { ...headers };
47
- }
48
-
49
- async function requireLoggedIn(): Promise<void> {
50
- const loggedIn = await loginOrRefreshIfRequired();
51
- if (!loggedIn) {
52
- throw new Error("Not logged in.");
53
- }
54
- }
55
-
56
- function requireApiToken(): string {
57
- const apiToken = getAPIToken();
58
- if (!apiToken) {
59
- throw new Error("No API token found.");
60
- }
61
- return apiToken;
62
- }
63
-
64
- function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
65
- if (headers["Authorization"]) {
66
- throw new Error(
67
- "The request already specifies an authorisation header - cannot add a new one."
68
- );
69
- }
70
- headers["Authorization"] = `Bearer ${apiToken}`;
71
- }
package/src/cli.ts DELETED
@@ -1,9 +0,0 @@
1
- import { hideBin } from "yargs/helpers";
2
- import { main } from ".";
3
-
4
- main(hideBin(process.argv)).catch(() => {
5
- // The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
6
- // Here we just want to ensure that the process exits with a non-zero code.
7
- // We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
8
- process.exit(1);
9
- });