wrangler 0.0.0-e151223 → 0.0.0-e273e09

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 (152) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +49 -5
  4. package/miniflare-dist/index.mjs +4886 -0
  5. package/package.json +54 -28
  6. package/pages/functions/buildPlugin.ts +105 -0
  7. package/pages/functions/buildWorker.ts +93 -4
  8. package/pages/functions/filepath-routing.test.ts +223 -36
  9. package/pages/functions/filepath-routing.ts +78 -120
  10. package/pages/functions/routes.ts +13 -17
  11. package/pages/functions/template-plugin.ts +147 -0
  12. package/pages/functions/template-worker.ts +24 -17
  13. package/src/__tests__/config-cache.test.ts +36 -0
  14. package/src/__tests__/configuration.test.ts +3487 -0
  15. package/src/__tests__/dev.test.tsx +977 -65
  16. package/src/__tests__/guess-worker-format.test.ts +85 -0
  17. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  18. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  19. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  20. package/src/__tests__/helpers/mock-bin.ts +36 -0
  21. package/src/__tests__/helpers/mock-cfetch.ts +48 -10
  22. package/src/__tests__/helpers/mock-console.ts +39 -8
  23. package/src/__tests__/helpers/mock-dialogs.ts +67 -2
  24. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  25. package/src/__tests__/helpers/mock-istty.ts +27 -0
  26. package/src/__tests__/helpers/mock-kv.ts +9 -16
  27. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  28. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  29. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  30. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  31. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  32. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  33. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  34. package/src/__tests__/https-options.test.ts +130 -0
  35. package/src/__tests__/index.test.ts +160 -309
  36. package/src/__tests__/init.test.ts +1637 -0
  37. package/src/__tests__/jest.setup.ts +49 -6
  38. package/src/__tests__/kv.test.ts +607 -275
  39. package/src/__tests__/logger.test.ts +115 -0
  40. package/src/__tests__/package-manager.test.ts +353 -0
  41. package/src/__tests__/pages.test.ts +754 -0
  42. package/src/__tests__/parse.test.ts +330 -0
  43. package/src/__tests__/publish.test.ts +5472 -939
  44. package/src/__tests__/r2.test.ts +233 -0
  45. package/src/__tests__/route.test.ts +45 -0
  46. package/src/__tests__/secret.test.ts +362 -91
  47. package/src/__tests__/tail.test.ts +690 -0
  48. package/src/__tests__/user.test.ts +131 -0
  49. package/src/__tests__/whoami.test.tsx +60 -7
  50. package/src/abort.d.ts +3 -0
  51. package/src/bundle.ts +197 -0
  52. package/src/cfetch/index.ts +28 -18
  53. package/src/cfetch/internal.ts +99 -29
  54. package/src/cli.ts +6 -2
  55. package/src/config/README.md +107 -0
  56. package/src/config/config.ts +234 -0
  57. package/src/config/diagnostics.ts +80 -0
  58. package/src/config/environment.ts +420 -0
  59. package/src/config/index.ts +225 -0
  60. package/src/config/validation-helpers.ts +584 -0
  61. package/src/config/validation.ts +1548 -0
  62. package/src/config-cache.ts +45 -0
  63. package/src/create-worker-preview.ts +185 -0
  64. package/src/create-worker-upload-form.ts +254 -0
  65. package/src/dev/dev-vars.ts +36 -0
  66. package/src/dev/dev.tsx +401 -0
  67. package/src/dev/local.tsx +326 -0
  68. package/src/dev/remote.tsx +237 -0
  69. package/src/dev/use-esbuild.ts +118 -0
  70. package/src/dialogs.tsx +64 -6
  71. package/src/durable.ts +102 -0
  72. package/src/entry.ts +322 -0
  73. package/src/environment-variables.ts +35 -0
  74. package/src/errors.ts +11 -0
  75. package/src/https-options.ts +123 -0
  76. package/src/index.tsx +1768 -982
  77. package/src/inspect.ts +80 -14
  78. package/src/intl-polyfill.d.ts +139 -0
  79. package/src/{kv.tsx → kv.ts} +199 -67
  80. package/src/logger.ts +66 -0
  81. package/src/miniflare-cli/README.md +30 -0
  82. package/src/miniflare-cli/enum-keys.ts +17 -0
  83. package/src/miniflare-cli/index.ts +41 -0
  84. package/src/miniflare-cli/request-context.ts +40 -0
  85. package/src/module-collection.ts +226 -31
  86. package/src/open-in-browser.ts +19 -0
  87. package/src/package-manager.ts +174 -0
  88. package/src/pages.tsx +1132 -84
  89. package/src/parse.ts +203 -0
  90. package/src/proxy.ts +170 -62
  91. package/src/publish.ts +617 -306
  92. package/src/r2.ts +50 -0
  93. package/src/selfsigned.d.ts +29 -0
  94. package/src/sites.tsx +143 -57
  95. package/src/tail/filters.ts +279 -0
  96. package/src/tail/index.ts +299 -0
  97. package/src/tail/printing.ts +67 -0
  98. package/src/update-check.ts +19 -0
  99. package/src/user.tsx +341 -146
  100. package/src/whoami.tsx +5 -3
  101. package/src/{api/worker.ts → worker.ts} +65 -39
  102. package/src/zones.ts +73 -0
  103. package/templates/gitignore +171 -0
  104. package/templates/new-worker-scheduled.js +17 -0
  105. package/templates/new-worker-scheduled.ts +32 -0
  106. package/templates/new-worker.js +15 -0
  107. package/templates/new-worker.ts +30 -0
  108. package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -5
  109. package/templates/tsconfig.json +105 -0
  110. package/wrangler-dist/cli.js +77223 -75763
  111. package/src/__tests__/helpers/mock-user.ts +0 -27
  112. package/src/__tests__/logout.test.ts +0 -50
  113. package/src/api/form_data.ts +0 -134
  114. package/src/api/preview.ts +0 -128
  115. package/src/config.ts +0 -641
  116. package/src/dev.tsx +0 -834
  117. package/src/npm-installer.ts +0 -20
  118. package/src/tail.tsx +0 -73
  119. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  120. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  121. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  122. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  123. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  124. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  125. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  126. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  127. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  128. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  129. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  130. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  131. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  132. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  133. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  134. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  135. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  136. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  137. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  138. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  139. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  140. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  141. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  142. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  143. package/vendor/wrangler-mime/LICENSE +0 -21
  144. package/vendor/wrangler-mime/Mime.js +0 -97
  145. package/vendor/wrangler-mime/README.md +0 -187
  146. package/vendor/wrangler-mime/cli.js +0 -46
  147. package/vendor/wrangler-mime/index.js +0 -4
  148. package/vendor/wrangler-mime/lite.js +0 -4
  149. package/vendor/wrangler-mime/package.json +0 -52
  150. package/vendor/wrangler-mime/types/other.js +0 -1
  151. package/vendor/wrangler-mime/types/standard.js +0 -1
  152. package/wrangler-dist/cli.js.map +0 -7
package/src/whoami.tsx CHANGED
@@ -2,10 +2,11 @@ import { Text, render } from "ink";
2
2
  import Table from "ink-table";
3
3
  import React from "react";
4
4
  import { fetchListResult, fetchResult } from "./cfetch";
5
- import { getAPIToken } from "./user";
5
+ import { logger } from "./logger";
6
+ import { getAPIToken, getCloudflareAPITokenFromEnv } from "./user";
6
7
 
7
8
  export async function whoami() {
8
- console.log("Getting User settings...");
9
+ logger.log("Getting User settings...");
9
10
  const user = await getUserInfo();
10
11
  render(<WhoAmI user={user}></WhoAmI>);
11
12
  }
@@ -47,10 +48,11 @@ export interface UserInfo {
47
48
 
48
49
  export async function getUserInfo(): Promise<UserInfo | undefined> {
49
50
  const apiToken = getAPIToken();
51
+ const apiTokenFromEnv = getCloudflareAPITokenFromEnv();
50
52
  return apiToken
51
53
  ? {
52
54
  apiToken,
53
- authType: "OAuth",
55
+ authType: apiTokenFromEnv ? "API" : "OAuth",
54
56
  email: await getEmail(),
55
57
  accounts: await getAccounts(),
56
58
  }
@@ -1,7 +1,3 @@
1
- import { fetch } from "undici";
2
- import { previewToken } from "./preview";
3
- import type { CfPreviewToken } from "./preview";
4
-
5
1
  /**
6
2
  * A Cloudflare account.
7
3
  */
@@ -16,12 +12,13 @@ export interface CfAccount {
16
12
  * An account ID.
17
13
  */
18
14
  accountId: string;
19
- /**
20
- * A zone ID, only required if not using `workers.dev`.
21
- */
22
- zoneId?: string;
23
15
  }
24
16
 
17
+ /**
18
+ * The type of Worker
19
+ */
20
+ export type CfScriptFormat = "modules" | "service-worker";
21
+
25
22
  /**
26
23
  * A module type.
27
24
  */
@@ -66,7 +63,7 @@ export interface CfModule {
66
63
  * A map of variable names to values.
67
64
  */
68
65
  interface CfVars {
69
- [key: string]: string;
66
+ [key: string]: unknown;
70
67
  }
71
68
 
72
69
  /**
@@ -77,6 +74,30 @@ interface CfKvNamespace {
77
74
  id: string;
78
75
  }
79
76
 
77
+ /**
78
+ * A binding to a wasm module (in service-worker format)
79
+ */
80
+
81
+ interface CfWasmModuleBindings {
82
+ [key: string]: string;
83
+ }
84
+
85
+ /**
86
+ * A binding to a text blob (in service-worker format)
87
+ */
88
+
89
+ interface CfTextBlobBindings {
90
+ [key: string]: string;
91
+ }
92
+
93
+ /**
94
+ * A binding to a data blob (in service-worker format)
95
+ */
96
+
97
+ interface CfDataBlobBindings {
98
+ [key: string]: string;
99
+ }
100
+
80
101
  /**
81
102
  * A Durable Object.
82
103
  */
@@ -84,15 +105,23 @@ interface CfDurableObject {
84
105
  name: string;
85
106
  class_name: string;
86
107
  script_name?: string;
108
+ environment?: string;
109
+ }
110
+
111
+ interface CfR2Bucket {
112
+ binding: string;
113
+ bucket_name: string;
87
114
  }
88
115
 
89
- /**
90
- * A Service.
91
- */
92
116
  interface CfService {
93
- name: string;
117
+ binding: string;
94
118
  service: string;
95
- environment: string;
119
+ environment?: string;
120
+ }
121
+
122
+ interface CfUnsafeBinding {
123
+ name: string;
124
+ type: string;
96
125
  }
97
126
 
98
127
  export interface CfDurableObjectMigrations {
@@ -100,7 +129,10 @@ export interface CfDurableObjectMigrations {
100
129
  new_tag: string;
101
130
  steps: {
102
131
  new_classes?: string[];
103
- renamed_classes?: string[];
132
+ renamed_classes?: {
133
+ from: string;
134
+ to: string;
135
+ }[];
104
136
  deleted_classes?: string[];
105
137
  }[];
106
138
  }
@@ -120,36 +152,30 @@ export interface CfWorkerInit {
120
152
  /**
121
153
  * The list of additional modules.
122
154
  */
123
- modules: undefined | CfModule[];
155
+ modules: CfModule[] | undefined;
124
156
  /**
125
157
  * All the bindings
126
158
  */
127
159
  bindings: {
128
- kv_namespaces?: CfKvNamespace[];
129
- durable_objects?: { bindings: CfDurableObject[] };
130
- vars?: CfVars;
131
- services?: CfService[];
160
+ vars: CfVars | undefined;
161
+ kv_namespaces: CfKvNamespace[] | undefined;
162
+ wasm_modules: CfWasmModuleBindings | undefined;
163
+ text_blobs: CfTextBlobBindings | undefined;
164
+ data_blobs: CfDataBlobBindings | undefined;
165
+ durable_objects: { bindings: CfDurableObject[] } | undefined;
166
+ r2_buckets: CfR2Bucket[] | undefined;
167
+ services: CfService[] | undefined;
168
+ unsafe: CfUnsafeBinding[] | undefined;
132
169
  };
133
- migrations: undefined | CfDurableObjectMigrations;
170
+ migrations: CfDurableObjectMigrations | undefined;
134
171
  compatibility_date: string | undefined;
135
- compatibility_flags: undefined | string[];
136
- usage_model: undefined | "bundled" | "unbound";
172
+ compatibility_flags: string[] | undefined;
173
+ usage_model: "bundled" | "unbound" | undefined;
137
174
  }
138
175
 
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;
176
+ export interface CfWorkerContext {
177
+ env: string | undefined;
178
+ legacyEnv: boolean | undefined;
179
+ zone: string | undefined;
180
+ host: string | undefined;
155
181
  }
package/src/zones.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { fetchListResult } from "./cfetch";
2
+ import type { Route } from "./config/environment";
3
+
4
+ /**
5
+ * An object holding information about a zone for publishing.
6
+ */
7
+ export interface Zone {
8
+ id: string;
9
+ host: string;
10
+ }
11
+
12
+ /**
13
+ * Try to compute the a zone ID and host name for one or more routes.
14
+ *
15
+ * When we're given a route, we do 2 things:
16
+ * - We try to extract a host from it
17
+ * - We try to get a zone id from the host
18
+ */
19
+ export async function getZoneForRoute(route: Route): Promise<Zone | undefined> {
20
+ const host =
21
+ typeof route === "string"
22
+ ? getHostFromUrl(route)
23
+ : typeof route === "object"
24
+ ? "zone_name" in route
25
+ ? getHostFromUrl(route.zone_name)
26
+ : getHostFromUrl(route.pattern)
27
+ : undefined;
28
+ const id =
29
+ typeof route === "object" && "zone_id" in route
30
+ ? route.zone_id
31
+ : host
32
+ ? await getZoneIdFromHost(host)
33
+ : undefined;
34
+ return id && host ? { id, host } : undefined;
35
+ }
36
+
37
+ /**
38
+ * Given something that resembles a URL, try to extract a host from it.
39
+ */
40
+ function getHostFromUrl(urlLike: string): string | undefined {
41
+ // strip leading * / *.
42
+ urlLike = urlLike.replace(/^\*(\.)?/g, "");
43
+
44
+ if (!(urlLike.startsWith("http://") || urlLike.startsWith("https://"))) {
45
+ urlLike = "http://" + urlLike;
46
+ }
47
+ return new URL(urlLike).host;
48
+ }
49
+
50
+ /**
51
+ * Given something that resembles a host, try to infer a zone id from it.
52
+ *
53
+ * It's hard to get a 'valid' domain from a string, so we don't even try to validate TLDs, etc.
54
+ * For each domain-like part of the host (e.g. w.x.y.z) try to get a zone id for it by
55
+ * lopping off subdomains until we get a hit from the API.
56
+ */
57
+ export async function getZoneIdFromHost(host: string): Promise<string> {
58
+ const hostPieces = host.split(".");
59
+
60
+ while (hostPieces.length > 1) {
61
+ const zones = await fetchListResult<{ id: string }>(
62
+ `/zones`,
63
+ {},
64
+ new URLSearchParams({ name: hostPieces.join(".") })
65
+ );
66
+ if (zones.length > 0) {
67
+ return zones[0].id;
68
+ }
69
+ hostPieces.shift();
70
+ }
71
+
72
+ throw new Error(`Could not find zone for ${host}`);
73
+ }
@@ -0,0 +1,171 @@
1
+ # Logs
2
+
3
+ logs
4
+ _.log
5
+ npm-debug.log_
6
+ yarn-debug.log*
7
+ yarn-error.log*
8
+ lerna-debug.log*
9
+ .pnpm-debug.log*
10
+
11
+ # Diagnostic reports (https://nodejs.org/api/report.html)
12
+
13
+ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
14
+
15
+ # Runtime data
16
+
17
+ pids
18
+ _.pid
19
+ _.seed
20
+ \*.pid.lock
21
+
22
+ # Directory for instrumented libs generated by jscoverage/JSCover
23
+
24
+ lib-cov
25
+
26
+ # Coverage directory used by tools like istanbul
27
+
28
+ coverage
29
+ \*.lcov
30
+
31
+ # nyc test coverage
32
+
33
+ .nyc_output
34
+
35
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36
+
37
+ .grunt
38
+
39
+ # Bower dependency directory (https://bower.io/)
40
+
41
+ bower_components
42
+
43
+ # node-waf configuration
44
+
45
+ .lock-wscript
46
+
47
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
48
+
49
+ build/Release
50
+
51
+ # Dependency directories
52
+
53
+ node_modules/
54
+ jspm_packages/
55
+
56
+ # Snowpack dependency directory (https://snowpack.dev/)
57
+
58
+ web_modules/
59
+
60
+ # TypeScript cache
61
+
62
+ \*.tsbuildinfo
63
+
64
+ # Optional npm cache directory
65
+
66
+ .npm
67
+
68
+ # Optional eslint cache
69
+
70
+ .eslintcache
71
+
72
+ # Optional stylelint cache
73
+
74
+ .stylelintcache
75
+
76
+ # Microbundle cache
77
+
78
+ .rpt2_cache/
79
+ .rts2_cache_cjs/
80
+ .rts2_cache_es/
81
+ .rts2_cache_umd/
82
+
83
+ # Optional REPL history
84
+
85
+ .node_repl_history
86
+
87
+ # Output of 'npm pack'
88
+
89
+ \*.tgz
90
+
91
+ # Yarn Integrity file
92
+
93
+ .yarn-integrity
94
+
95
+ # dotenv environment variable files
96
+
97
+ .env
98
+ .env.development.local
99
+ .env.test.local
100
+ .env.production.local
101
+ .env.local
102
+
103
+ # parcel-bundler cache (https://parceljs.org/)
104
+
105
+ .cache
106
+ .parcel-cache
107
+
108
+ # Next.js build output
109
+
110
+ .next
111
+ out
112
+
113
+ # Nuxt.js build / generate output
114
+
115
+ .nuxt
116
+ dist
117
+
118
+ # Gatsby files
119
+
120
+ .cache/
121
+
122
+ # Comment in the public line in if your project uses Gatsby and not Next.js
123
+
124
+ # https://nextjs.org/blog/next-9-1#public-directory-support
125
+
126
+ # public
127
+
128
+ # vuepress build output
129
+
130
+ .vuepress/dist
131
+
132
+ # vuepress v2.x temp and cache directory
133
+
134
+ .temp
135
+ .cache
136
+
137
+ # Docusaurus cache and generated files
138
+
139
+ .docusaurus
140
+
141
+ # Serverless directories
142
+
143
+ .serverless/
144
+
145
+ # FuseBox cache
146
+
147
+ .fusebox/
148
+
149
+ # DynamoDB Local files
150
+
151
+ .dynamodb/
152
+
153
+ # TernJS port file
154
+
155
+ .tern-port
156
+
157
+ # Stores VSCode versions used for testing VSCode extensions
158
+
159
+ .vscode-test
160
+
161
+ # yarn v2
162
+
163
+ .yarn/cache
164
+ .yarn/unplugged
165
+ .yarn/build-state.yml
166
+ .yarn/install-state.gz
167
+ .pnp.\*
168
+
169
+ # wrangler project
170
+
171
+ .dev.vars
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers! This is your first scheduled worker.
3
+ *
4
+ * - Run `wrangler dev --local` in your terminal to start a development server
5
+ * - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
6
+ * - Go back to the console to see what your worker has logged
7
+ * - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
8
+ * - Run `wrangler publish --name my-worker` to publish your worker
9
+ *
10
+ * Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
11
+ */
12
+
13
+ export default {
14
+ async scheduled(controller, env, ctx) {
15
+ console.log(`Hello World!`);
16
+ },
17
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers! This is your first scheduled worker.
3
+ *
4
+ * - Run `wrangler dev --local` in your terminal to start a development server
5
+ * - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
6
+ * - Go back to the console to see what your worker has logged
7
+ * - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
8
+ * - Run `wrangler publish --name my-worker` to publish your worker
9
+ *
10
+ * Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
11
+ */
12
+
13
+ export interface Env {
14
+ // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
15
+ // MY_KV_NAMESPACE: KVNamespace;
16
+ //
17
+ // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
18
+ // MY_DURABLE_OBJECT: DurableObjectNamespace;
19
+ //
20
+ // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
21
+ // MY_BUCKET: R2Bucket;
22
+ }
23
+
24
+ export default {
25
+ async scheduled(
26
+ controller: ScheduledController,
27
+ env: Env,
28
+ ctx: ExecutionContext
29
+ ): Promise<void> {
30
+ console.log(`Hello World!`);
31
+ },
32
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers! This is your first worker.
3
+ *
4
+ * - Run `npx wrangler dev src/index.js` in your terminal to start a development server
5
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
6
+ * - Run `npx wrangler publish src/index.js --name my-worker` to publish your worker
7
+ *
8
+ * Learn more at https://developers.cloudflare.com/workers/
9
+ */
10
+
11
+ export default {
12
+ async fetch(request) {
13
+ return new Response("Hello World!");
14
+ },
15
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers! This is your first worker.
3
+ *
4
+ * - Run `wrangler dev src/index.ts` in your terminal to start a development server
5
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
6
+ * - Run `wrangler publish src/index.ts --name my-worker` to publish your worker
7
+ *
8
+ * Learn more at https://developers.cloudflare.com/workers/
9
+ */
10
+
11
+ export interface Env {
12
+ // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
13
+ // MY_KV_NAMESPACE: KVNamespace;
14
+ //
15
+ // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
16
+ // MY_DURABLE_OBJECT: DurableObjectNamespace;
17
+ //
18
+ // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
19
+ // MY_BUCKET: R2Bucket;
20
+ }
21
+
22
+ export default {
23
+ async fetch(
24
+ request: Request,
25
+ env: Env,
26
+ ctx: ExecutionContext
27
+ ): Promise<Response> {
28
+ return new Response("Hello World!");
29
+ },
30
+ };
@@ -4,10 +4,6 @@ import { getAssetFromKV } from "@cloudflare/kv-asset-handler";
4
4
  import manifest from "__STATIC_CONTENT_MANIFEST";
5
5
  const ASSET_MANIFEST = JSON.parse(manifest);
6
6
 
7
- // TODO: remove this
8
- globalThis.__STATIC_CONTENT = undefined;
9
- globalThis.__STATIC_CONTENT_MANIFEST = undefined;
10
-
11
7
  export default {
12
8
  async fetch(request, env, ctx) {
13
9
  let options = {
@@ -41,7 +37,7 @@ export default {
41
37
  // if an error is thrown then serve from actual worker
42
38
  return worker.fetch(request);
43
39
  // TODO: throw here if worker is not available
44
- // (which implies it may be a service worker)
40
+ // (which implies it may be a service-worker)
45
41
  }
46
42
  },
47
43
  };
@@ -0,0 +1,105 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
+ "lib": [
16
+ "es2021"
17
+ ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
18
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
19
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
20
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
21
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
22
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
23
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
24
+ // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
25
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
26
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
27
+
28
+ /* Modules */
29
+ "module": "es2022" /* Specify what module code is generated. */,
30
+ // "rootDir": "./", /* Specify the root folder within your source files. */
31
+ "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
32
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35
+ // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
36
+ "types": [
37
+ "@cloudflare/workers-types"
38
+ ] /* Specify type package names to be included without being referenced in a source file. */,
39
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
40
+ "resolveJsonModule": true /* Enable importing .json files */,
41
+ // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
42
+
43
+ /* JavaScript Support */
44
+ "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
45
+ "checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
46
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
47
+
48
+ /* Emit */
49
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
50
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
51
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
52
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
53
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
54
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
55
+ // "removeComments": true, /* Disable emitting comments. */
56
+ "noEmit": true /* Disable emitting files from a compilation. */,
57
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
58
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
59
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
60
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
61
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
62
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
63
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
64
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
65
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
66
+ // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
67
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
68
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
69
+ // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
70
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
71
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
72
+
73
+ /* Interop Constraints */
74
+ "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
75
+ "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
76
+ // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
77
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
78
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
79
+
80
+ /* Type Checking */
81
+ "strict": true /* Enable all strict type-checking options. */,
82
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
83
+ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
84
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
85
+ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
86
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
87
+ // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
88
+ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
89
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
90
+ // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
91
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
92
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
93
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
94
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
95
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
96
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
97
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
98
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
99
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
100
+
101
+ /* Completeness */
102
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
103
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
104
+ }
105
+ }