create-cloudflare 2.0.8 → 2.0.10

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 (45) hide show
  1. package/README.md +47 -2
  2. package/dist/cli.js +48785 -51772
  3. package/dist/tsconfig.tsbuildinfo +1 -1
  4. package/package.json +7 -3
  5. package/templates/common/js/.editorconfig +13 -0
  6. package/templates/common/js/.prettierrc +2 -1
  7. package/templates/common/js/wrangler.toml +37 -26
  8. package/templates/common/ts/.editorconfig +13 -0
  9. package/templates/common/ts/.prettierrc +2 -1
  10. package/templates/common/ts/wrangler.toml +37 -26
  11. package/templates/hello-world/js/.editorconfig +13 -0
  12. package/templates/{simple → hello-world}/js/.prettierrc +2 -1
  13. package/templates/hello-world/js/wrangler.toml +51 -0
  14. package/templates/hello-world/ts/.editorconfig +13 -0
  15. package/templates/{simple → hello-world}/ts/.prettierrc +2 -1
  16. package/templates/hello-world/ts/wrangler.toml +51 -0
  17. package/templates/queues/js/.editorconfig +13 -0
  18. package/templates/queues/js/.prettierrc +6 -0
  19. package/templates/queues/js/package.json +14 -0
  20. package/templates/queues/js/src/worker.js +38 -0
  21. package/templates/queues/js/wrangler.toml +19 -0
  22. package/templates/queues/ts/.editorconfig +13 -0
  23. package/templates/queues/ts/.prettierrc +6 -0
  24. package/templates/queues/ts/package.json +14 -0
  25. package/templates/queues/ts/src/worker.ts +43 -0
  26. package/templates/queues/ts/tsconfig.json +101 -0
  27. package/templates/queues/ts/wrangler.toml +19 -0
  28. package/templates/scheduled/js/.editorconfig +13 -0
  29. package/templates/scheduled/js/.prettierrc +6 -0
  30. package/templates/scheduled/js/package.json +14 -0
  31. package/templates/scheduled/js/src/worker.js +30 -0
  32. package/templates/scheduled/js/wrangler.toml +9 -0
  33. package/templates/scheduled/ts/.editorconfig +13 -0
  34. package/templates/scheduled/ts/.prettierrc +6 -0
  35. package/templates/scheduled/ts/package.json +14 -0
  36. package/templates/scheduled/ts/src/worker.ts +50 -0
  37. package/templates/scheduled/ts/tsconfig.json +101 -0
  38. package/templates/scheduled/ts/wrangler.toml +9 -0
  39. package/templates/simple/js/wrangler.toml +0 -40
  40. package/templates/simple/ts/wrangler.toml +0 -40
  41. /package/templates/{simple → hello-world}/js/package.json +0 -0
  42. /package/templates/{simple → hello-world}/js/src/worker.js +0 -0
  43. /package/templates/{simple → hello-world}/ts/package.json +0 -0
  44. /package/templates/{simple → hello-world}/ts/src/worker.ts +0 -0
  45. /package/templates/{simple → hello-world}/ts/tsconfig.json +0 -0
@@ -0,0 +1,51 @@
1
+ name = "<TBD>"
2
+ main = "src/worker.ts"
3
+ compatibility_date = "2023-04-21"
4
+
5
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
+ # Note: Use secrets to store sensitive data.
7
+ # Docs: https://developers.cloudflare.com/workers/platform/environment-variables
8
+ # [vars]
9
+ # MY_VARIABLE = "production_value"
10
+
11
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
12
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
13
+ # [[kv_namespaces]]
14
+ # binding = "MY_KV_NAMESPACE"
15
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
16
+
17
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
18
+ # Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
19
+ # [[r2_buckets]]
20
+ # binding = "MY_BUCKET"
21
+ # bucket_name = "my-bucket"
22
+
23
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
24
+ # Docs: https://developers.cloudflare.com/queues/get-started
25
+ # [[queues.producers]]
26
+ # binding = "MY_QUEUE"
27
+ # queue = "my-queue"
28
+
29
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
30
+ # Docs: https://developers.cloudflare.com/queues/get-started
31
+ # [[queues.consumers]]
32
+ # queue = "my-queue"
33
+
34
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
35
+ # Docs: https://developers.cloudflare.com/workers/platform/services
36
+ # [[services]]
37
+ # binding = "MY_SERVICE"
38
+ # service = "/api/*"
39
+
40
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
41
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
42
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
43
+ # [[durable_objects.bindings]]
44
+ # name = "MY_DURABLE_OBJECT"
45
+ # class_name = "MyDurableObject"
46
+
47
+ # Durable Object migrations.
48
+ # Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
49
+ # [[migrations]]
50
+ # tag = "v1"
51
+ # new_classes = ["MyDurableObject"]
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ tab_width = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.yml]
13
+ indent_style = space
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 140,
3
+ "singleQuote": true,
4
+ "semi": true,
5
+ "useTabs": true
6
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler publish",
7
+ "start": "wrangler dev"
8
+ },
9
+ "devDependencies": {
10
+ "@cloudflare/workers-types": "^4.20230419.0",
11
+ "typescript": "^5.0.4",
12
+ "wrangler": "^3.0.0"
13
+ }
14
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers!
3
+ *
4
+ * This is a template for a Queue consumer: a Worker that can consume from a
5
+ * Queue: https://developers.cloudflare.com/queues/get-started/
6
+ *
7
+ * - Run `npm run dev` in your terminal to start a development server
8
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
9
+ * - Run `npm run deploy` to publish your worker
10
+ *
11
+ * Learn more at https://developers.cloudflare.com/workers/
12
+ */
13
+
14
+ export default {
15
+ // Our fetch handler is invoked on a HTTP request: we can send a message to a queue
16
+ // during (or after) a request.
17
+ // https://developers.cloudflare.com/queues/platform/javascript-apis/#producer
18
+ async fetch(req, env, ctx) {
19
+ // To send a message on a queue, we need to create the queue first
20
+ // https://developers.cloudflare.com/queues/get-started/#3-create-a-queue
21
+ await env.MY_QUEUE.send({
22
+ url: req.url,
23
+ method: req.method,
24
+ headers: Object.fromEntries(req.headers),
25
+ });
26
+ return new Response('Sent message to the queue');
27
+ },
28
+ // The queue handler is invoked when a batch of messages is ready to be delivered
29
+ // https://developers.cloudflare.com/queues/platform/javascript-apis/#messagebatch
30
+ async queue(batch, env) {
31
+ // A queue consumer can make requests to other endpoints on the Internet,
32
+ // write to R2 object storage, query a D1 Database, and much more.
33
+ for (let message of batch.messages) {
34
+ // Process each message (we'll just log these)
35
+ console.log(`message ${message.id} processed: ${JSON.stringify(message.body)}`);
36
+ }
37
+ },
38
+ };
@@ -0,0 +1,19 @@
1
+ name = "<TBD>"
2
+ main = "src/worker.js"
3
+ compatibility_date = "2023-05-15"
4
+
5
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
6
+ # Docs: https://developers.cloudflare.com/queues/get-started
7
+ # [[queues.producers]]
8
+ binding = "MY_QUEUE"
9
+ queue = "my-queue"
10
+
11
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
12
+ # Docs: https://developers.cloudflare.com/queues/get-started
13
+ # [[queues.consumers]]
14
+ queue = "my-queue"
15
+ # Optional: Configure batching and retries: https://developers.cloudflare.com/queues/learning/batching-retries/
16
+ # max_batch_size = 10
17
+ # max_batch_timeout = 30
18
+ # max_retries = 10
19
+ # dead_letter_queue = "my-queue-dlq"
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ tab_width = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.yml]
13
+ indent_style = space
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 140,
3
+ "singleQuote": true,
4
+ "semi": true,
5
+ "useTabs": true
6
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler publish",
7
+ "start": "wrangler dev"
8
+ },
9
+ "devDependencies": {
10
+ "@cloudflare/workers-types": "^4.20230419.0",
11
+ "typescript": "^5.0.4",
12
+ "wrangler": "^3.0.0"
13
+ }
14
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers!
3
+ *
4
+ * This is a template for a Queue consumer: a Worker that can consume from a
5
+ * Queue: https://developers.cloudflare.com/queues/get-started/
6
+ *
7
+ * - Run `npm run dev` in your terminal to start a development server
8
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
9
+ * - Run `npm run deploy` to publish your worker
10
+ *
11
+ * Learn more at https://developers.cloudflare.com/workers/
12
+ */
13
+
14
+ export interface Env {
15
+ // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
16
+ MY_QUEUE: Queue;
17
+ }
18
+
19
+ export default {
20
+ // Our fetch handler is invoked on a HTTP request: we can send a message to a queue
21
+ // during (or after) a request.
22
+ // https://developers.cloudflare.com/queues/platform/javascript-apis/#producer
23
+ async fetch(req: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
24
+ // To send a message on a queue, we need to create the queue first
25
+ // https://developers.cloudflare.com/queues/get-started/#3-create-a-queue
26
+ await env.MY_QUEUE.send({
27
+ url: req.url,
28
+ method: req.method,
29
+ headers: Object.fromEntries(req.headers),
30
+ });
31
+ return new Response('Sent message to the queue');
32
+ },
33
+ // The queue handler is invoked when a batch of messages is ready to be delivered
34
+ // https://developers.cloudflare.com/queues/platform/javascript-apis/#messagebatch
35
+ async queue(batch: MessageBatch<Error>, env: Env): Promise<void> {
36
+ // A queue consumer can make requests to other endpoints on the Internet,
37
+ // write to R2 object storage, query a D1 Database, and much more.
38
+ for (let message of batch.messages) {
39
+ // Process each message (we'll just log these)
40
+ console.log(`message ${message.id} processed: ${JSON.stringify(message.body)}`);
41
+ }
42
+ },
43
+ };
@@ -0,0 +1,101 @@
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": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
16
+ "jsx": "react" /* Specify what JSX code is generated. */,
17
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
22
+ // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+
26
+ /* Modules */
27
+ "module": "es2022" /* Specify what module code is generated. */,
28
+ // "rootDir": "./", /* Specify the root folder within your source files. */
29
+ "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
30
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
31
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
+ // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
34
+ "types": ["@cloudflare/workers-types"] /* Specify type package names to be included without being referenced in a source file. */,
35
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
+ "resolveJsonModule": true /* Enable importing .json files */,
37
+ // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
+
39
+ /* JavaScript Support */
40
+ "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
41
+ "checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
42
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
43
+
44
+ /* Emit */
45
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
46
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
47
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
48
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
49
+ // "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. */
50
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
51
+ // "removeComments": true, /* Disable emitting comments. */
52
+ "noEmit": true /* Disable emitting files from a compilation. */,
53
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
54
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
55
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
56
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
57
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
60
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
61
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
62
+ // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
63
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
64
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
65
+ // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
66
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
67
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
68
+
69
+ /* Interop Constraints */
70
+ "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
71
+ "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
72
+ // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
73
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
75
+
76
+ /* Type Checking */
77
+ "strict": true /* Enable all strict type-checking options. */,
78
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
+ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81
+ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83
+ // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
84
+ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86
+ // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
88
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
91
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
93
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
94
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
95
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
96
+
97
+ /* Completeness */
98
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
+ }
101
+ }
@@ -0,0 +1,19 @@
1
+ name = "<TBD>"
2
+ main = "src/worker.ts"
3
+ compatibility_date = "2023-05-15"
4
+
5
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
6
+ # Docs: https://developers.cloudflare.com/queues/get-started
7
+ # [[queues.producers]]
8
+ binding = "MY_QUEUE"
9
+ queue = "my-queue"
10
+
11
+ # Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
12
+ # Docs: https://developers.cloudflare.com/queues/get-started
13
+ # [[queues.consumers]]
14
+ queue = "my-queue"
15
+ # Optional: Configure batching and retries: https://developers.cloudflare.com/queues/learning/batching-retries/
16
+ # max_batch_size = 10
17
+ # max_batch_timeout = 30
18
+ # max_retries = 10
19
+ # dead_letter_queue = "my-queue-dlq"
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ tab_width = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.yml]
13
+ indent_style = space
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 140,
3
+ "singleQuote": true,
4
+ "semi": true,
5
+ "useTabs": true
6
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler publish",
7
+ "start": "wrangler dev"
8
+ },
9
+ "devDependencies": {
10
+ "@cloudflare/workers-types": "^4.20230419.0",
11
+ "typescript": "^5.0.4",
12
+ "wrangler": "^3.0.0"
13
+ }
14
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers!
3
+ *
4
+ * This is a template for a Scheduled Worker: a Worker that can run on a
5
+ * configurable interval:
6
+ * https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
7
+ *
8
+ * - Run `npm run dev` in your terminal to start a development server
9
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
10
+ * - Run `npm run deploy` to publish your worker
11
+ *
12
+ * Learn more at https://developers.cloudflare.com/workers/
13
+ */
14
+
15
+ export default {
16
+ // The scheduled handler is invoked at the interval set in our wrangler.toml's
17
+ // [[triggers]] configuration.
18
+ async scheduled(event, env, ctx) {
19
+ // A Cron Trigger can make requests to other endpoints on the Internet,
20
+ // publish to a Queue, query a D1 Database, and much more.
21
+ //
22
+ // We'll keep it simple and make an API call to a Cloudflare API:
23
+ let resp = await fetch('https://api.cloudflare.com/client/v4/ips');
24
+ let wasSuccessful = resp.ok ? 'success' : 'fail';
25
+
26
+ // You could store this result in KV, write to a D1 Database, or publish to a Queue.
27
+ // In this template, we'll just log the result:
28
+ console.log(`trigger fired at ${event.cron}: ${wasSuccessful}`);
29
+ },
30
+ };
@@ -0,0 +1,9 @@
1
+ name = "<TBD>"
2
+ main = "src/worker.ts"
3
+ compatibility_date = "2023-05-15"
4
+
5
+ # Cron Triggers
6
+ # Docs: https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
7
+ # Configuration: https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
8
+ [triggers]
9
+ crons = ["* * * * *"] # * * * * * = run every minute
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ tab_width = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.yml]
13
+ indent_style = space
@@ -0,0 +1,6 @@
1
+ {
2
+ "printWidth": 140,
3
+ "singleQuote": true,
4
+ "semi": true,
5
+ "useTabs": true
6
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler publish",
7
+ "start": "wrangler dev"
8
+ },
9
+ "devDependencies": {
10
+ "@cloudflare/workers-types": "^4.20230419.0",
11
+ "typescript": "^5.0.4",
12
+ "wrangler": "^3.0.0"
13
+ }
14
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Welcome to Cloudflare Workers!
3
+ *
4
+ * This is a template for a Scheduled Worker: a Worker that can run on a
5
+ * configurable interval:
6
+ * https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
7
+ *
8
+ * - Run `npm run dev` in your terminal to start a development server
9
+ * - Open a browser tab at http://localhost:8787/ to see your worker in action
10
+ * - Run `npm run deploy` to publish your worker
11
+ *
12
+ * Learn more at https://developers.cloudflare.com/workers/
13
+ */
14
+
15
+ export interface Env {
16
+ // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
17
+ // MY_KV_NAMESPACE: KVNamespace;
18
+ //
19
+ // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
20
+ // MY_DURABLE_OBJECT: DurableObjectNamespace;
21
+ //
22
+ // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
23
+ // MY_BUCKET: R2Bucket;
24
+ //
25
+ // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
26
+ // MY_SERVICE: Fetcher;
27
+ //
28
+ // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
29
+ // MY_QUEUE: Queue;
30
+ //
31
+ // Example binding to a D1 Database. Learn more at https://developers.cloudflare.com/workers/platform/bindings/#d1-database-bindings
32
+ // DB: D1Database
33
+ }
34
+
35
+ export default {
36
+ // The scheduled handler is invoked at the interval set in our wrangler.toml's
37
+ // [[triggers]] configuration.
38
+ async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
39
+ // A Cron Trigger can make requests to other endpoints on the Internet,
40
+ // publish to a Queue, query a D1 Database, and much more.
41
+ //
42
+ // We'll keep it simple and make an API call to a Cloudflare API:
43
+ let resp = await fetch('https://api.cloudflare.com/client/v4/ips');
44
+ let wasSuccessful = resp.ok ? 'success' : 'fail';
45
+
46
+ // You could store this result in KV, write to a D1 Database, or publish to a Queue.
47
+ // In this template, we'll just log the result:
48
+ console.log(`trigger fired at ${event.cron}: ${wasSuccessful}`);
49
+ },
50
+ };
@@ -0,0 +1,101 @@
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": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
16
+ "jsx": "react" /* Specify what JSX code is generated. */,
17
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
22
+ // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+
26
+ /* Modules */
27
+ "module": "es2022" /* Specify what module code is generated. */,
28
+ // "rootDir": "./", /* Specify the root folder within your source files. */
29
+ "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
30
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
31
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
+ // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
34
+ "types": ["@cloudflare/workers-types"] /* Specify type package names to be included without being referenced in a source file. */,
35
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
+ "resolveJsonModule": true /* Enable importing .json files */,
37
+ // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
+
39
+ /* JavaScript Support */
40
+ "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
41
+ "checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
42
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
43
+
44
+ /* Emit */
45
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
46
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
47
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
48
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
49
+ // "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. */
50
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
51
+ // "removeComments": true, /* Disable emitting comments. */
52
+ "noEmit": true /* Disable emitting files from a compilation. */,
53
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
54
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
55
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
56
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
57
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
60
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
61
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
62
+ // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
63
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
64
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
65
+ // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
66
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
67
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
68
+
69
+ /* Interop Constraints */
70
+ "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
71
+ "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
72
+ // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
73
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
75
+
76
+ /* Type Checking */
77
+ "strict": true /* Enable all strict type-checking options. */,
78
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
+ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81
+ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83
+ // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
84
+ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86
+ // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
88
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
91
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
93
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
94
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
95
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
96
+
97
+ /* Completeness */
98
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
+ }
101
+ }