create-cloudflare 0.0.0-9c15b6ea2 → 0.0.0-9c30aecaa

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 (92) hide show
  1. package/dist/cli.js +283 -246
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +8 -8
  4. package/templates/analog/c3.ts +0 -24
  5. package/templates/analog/templates/env.d.ts +1 -1
  6. package/templates/angular/pages/c3.ts +3 -3
  7. package/templates/angular/pages/templates/wrangler.jsonc +5 -0
  8. package/templates/angular/workers/c3.ts +1 -0
  9. package/templates/astro/workers/templates/js/wrangler.jsonc +2 -1
  10. package/templates/astro/workers/templates/ts/wrangler.jsonc +2 -1
  11. package/templates/common/ts/tsconfig.json +0 -3
  12. package/templates/docusaurus/pages/c3.ts +1 -0
  13. package/templates/docusaurus/workers/c3.ts +1 -0
  14. package/templates/gatsby/pages/c3.ts +1 -0
  15. package/templates/gatsby/workers/c3.ts +1 -0
  16. package/templates/hello-world/ts/test/index.spec.ts +0 -1
  17. package/templates/hello-world/ts/test/tsconfig.json +1 -1
  18. package/templates/hello-world/ts/tsconfig.json +0 -2
  19. package/templates/hello-world-assets-only/templates/public/index.html +1 -0
  20. package/templates/hello-world-assets-only/templates/wrangler.jsonc +1 -0
  21. package/templates/hello-world-durable-object/ts/tsconfig.json +0 -2
  22. package/templates/hello-world-durable-object-with-assets/js/public/index.html +1 -0
  23. package/templates/hello-world-durable-object-with-assets/js/wrangler.jsonc +1 -1
  24. package/templates/hello-world-durable-object-with-assets/py/public/index.html +1 -0
  25. package/templates/hello-world-durable-object-with-assets/py/wrangler.jsonc +1 -1
  26. package/templates/hello-world-durable-object-with-assets/ts/public/index.html +1 -0
  27. package/templates/hello-world-durable-object-with-assets/ts/tsconfig.json +0 -2
  28. package/templates/hello-world-durable-object-with-assets/ts/wrangler.jsonc +1 -1
  29. package/templates/hello-world-with-assets/js/public/index.html +1 -0
  30. package/templates/hello-world-with-assets/js/wrangler.jsonc +3 -2
  31. package/templates/hello-world-with-assets/py/public/index.html +1 -0
  32. package/templates/hello-world-with-assets/py/wrangler.jsonc +1 -1
  33. package/templates/hello-world-with-assets/ts/public/index.html +1 -0
  34. package/templates/hello-world-with-assets/ts/test/tsconfig.json +1 -1
  35. package/templates/hello-world-with-assets/ts/tsconfig.json +0 -2
  36. package/templates/hello-world-with-assets/ts/wrangler.jsonc +2 -2
  37. package/templates/hello-world-workflows/c3.ts +20 -0
  38. package/templates/hello-world-workflows/js/package.json +13 -0
  39. package/templates/hello-world-workflows/js/src/index.js +129 -0
  40. package/templates/hello-world-workflows/js/wrangler.jsonc +17 -0
  41. package/templates/hello-world-workflows/ts/package.json +15 -0
  42. package/templates/hello-world-workflows/ts/src/index.ts +111 -0
  43. package/templates/hello-world-workflows/ts/tsconfig.json +40 -0
  44. package/templates/hello-world-workflows/ts/wrangler.jsonc +17 -0
  45. package/templates/hono/pages/c3.ts +4 -1
  46. package/templates/hono/workers/c3.ts +3 -1
  47. package/templates/next/pages/c3.ts +6 -10
  48. package/templates/next/workers/c3.ts +7 -5
  49. package/templates/next/workers/templates/public/_headers +3 -0
  50. package/templates/nuxt/pages/c3.ts +2 -26
  51. package/templates/nuxt/pages/templates/env.d.ts +1 -1
  52. package/templates/nuxt/workers/c3.ts +2 -26
  53. package/templates/nuxt/workers/templates/env.d.ts +1 -1
  54. package/templates/openapi/ts/tsconfig.json +0 -1
  55. package/templates/queues/ts/tsconfig.json +0 -2
  56. package/templates/qwik/pages/c3.ts +1 -0
  57. package/templates/qwik/workers/c3.ts +1 -0
  58. package/templates/qwik/workers/templates/wrangler.jsonc +2 -1
  59. package/templates/react/pages/c3.ts +4 -2
  60. package/templates/react/pages/templates/wrangler.jsonc +5 -0
  61. package/templates/react/workers/ts/tsconfig.worker.json +1 -1
  62. package/templates/react-router/c3.ts +0 -12
  63. package/templates/remix/pages/c3.ts +1 -0
  64. package/templates/remix/pages/templates/worker-configuration.d.ts +1 -1
  65. package/templates/remix/workers/c3.ts +1 -0
  66. package/templates/scheduled/ts/tsconfig.json +0 -2
  67. package/templates/solid/c3.ts +1 -0
  68. package/templates/svelte/pages/c3.ts +3 -3
  69. package/templates/svelte/workers/c3.ts +3 -3
  70. package/templates/vue/pages/c3.ts +5 -3
  71. package/templates/vue/pages/templates/wrangler.jsonc +5 -0
  72. package/templates/vue/workers/ts/tsconfig.worker.json +1 -1
  73. package/templates-experimental/solid/c3.ts +1 -1
  74. package/templates/analog/templates/worker-configuration.d.ts +0 -4
  75. package/templates/astro/workers/templates/ts/worker-configuration.d.ts +0 -4
  76. package/templates/common/ts/worker-configuration.d.ts +0 -4
  77. package/templates/hello-world/ts/worker-configuration.d.ts +0 -8
  78. package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +0 -7
  79. package/templates/hello-world-durable-object-with-assets/ts/worker-configuration.d.ts +0 -8
  80. package/templates/hello-world-with-assets/ts/worker-configuration.d.ts +0 -7
  81. package/templates/hono/pages/templates/worker-configuration.d.ts +0 -4
  82. package/templates/hono/workers/templates/worker-configuration.d.ts +0 -4
  83. package/templates/next/pages/env.d.ts +0 -5
  84. package/templates/next/workers/templates/cloudflare-env.d.ts +0 -5
  85. package/templates/nuxt/pages/templates/worker-configuration.d.ts +0 -4
  86. package/templates/nuxt/workers/templates/worker-configuration.d.ts +0 -4
  87. package/templates/openapi/ts/worker-configuration.d.ts +0 -4
  88. package/templates/queues/ts/worker-configuration.d.ts +0 -5
  89. package/templates/react/workers/ts/worker-configuration.d.ts +0 -5
  90. package/templates/react-router/templates/worker-configuration.d.ts +0 -8
  91. package/templates/scheduled/ts/worker-configuration.d.ts +0 -4
  92. package/templates/vue/workers/ts/worker-configuration.d.ts +0 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-9c15b6ea2",
3
+ "version": "0.0.0-9c30aecaa",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -30,7 +30,7 @@
30
30
  "@babel/parser": "^7.21.3",
31
31
  "@babel/types": "^7.21.4",
32
32
  "@clack/prompts": "^0.6.3",
33
- "@cloudflare/workers-types": "^4.20250428.0",
33
+ "@cloudflare/workers-types": "^4.20250604.0",
34
34
  "@iarna/toml": "^3.0.0",
35
35
  "@types/command-exists": "^1.2.0",
36
36
  "@types/cross-spawn": "^6.0.2",
@@ -38,7 +38,7 @@
38
38
  "@types/degit": "^2.8.6",
39
39
  "@types/dns2": "^2.0.3",
40
40
  "@types/esprima": "^4.0.3",
41
- "@types/node": "^18.19.75",
41
+ "@types/node": "^20.17.32",
42
42
  "@types/semver": "^7.5.1",
43
43
  "@types/which-pm-runs": "^1.0.0",
44
44
  "@types/yargs": "^17.0.22",
@@ -52,7 +52,7 @@
52
52
  "degit": "^2.8.4",
53
53
  "dns2": "^2.1.0",
54
54
  "dotenv": "^16.0.0",
55
- "esbuild": "0.25.2",
55
+ "esbuild": "0.25.4",
56
56
  "execa": "^7.1.1",
57
57
  "glob": "^10.3.3",
58
58
  "haikunator": "^2.1.2",
@@ -70,12 +70,12 @@
70
70
  "wrap-ansi": "^9.0.0",
71
71
  "xdg-app-paths": "^8.3.0",
72
72
  "yargs": "^17.7.2",
73
- "@cloudflare/cli": "1.1.1",
74
- "@cloudflare/vite-plugin": "0.0.0-9c15b6ea2",
75
73
  "@cloudflare/eslint-config-worker": "1.1.0",
74
+ "@cloudflare/cli": "1.1.1",
76
75
  "@cloudflare/mock-npm-registry": "0.0.0",
77
- "@cloudflare/workers-tsconfig": "0.0.0",
78
- "wrangler": "0.0.0-9c15b6ea2"
76
+ "@cloudflare/vite-plugin": "0.0.0-9c30aecaa",
77
+ "wrangler": "0.0.0-9c30aecaa",
78
+ "@cloudflare/workers-tsconfig": "0.0.0"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=18.14.1"
@@ -3,8 +3,6 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { spinner } from "@cloudflare/cli/interactive";
4
4
  import { runFrameworkGenerator } from "frameworks/index";
5
5
  import { loadTemplateSnippets, transformFile } from "helpers/codemod";
6
- import { getLatestTypesEntrypoint } from "helpers/compatDate";
7
- import { readFile, writeFile } from "helpers/files";
8
6
  import { detectPackageManager } from "helpers/packageManagers";
9
7
  import { installPackages } from "helpers/packages";
10
8
  import * as recast from "recast";
@@ -40,28 +38,6 @@ const configure = async (ctx: C3Context) => {
40
38
  }
41
39
 
42
40
  updateViteConfig(ctx);
43
- updateEnvTypes(ctx);
44
- };
45
-
46
- const updateEnvTypes = (ctx: C3Context) => {
47
- const filepath = "env.d.ts";
48
-
49
- const s = spinner();
50
- s.start(`Updating ${filepath}`);
51
-
52
- let file = readFile(filepath);
53
-
54
- let typesEntrypoint = `@cloudflare/workers-types`;
55
- const latestEntrypoint = getLatestTypesEntrypoint(ctx);
56
- if (latestEntrypoint) {
57
- typesEntrypoint += `/${latestEntrypoint}`;
58
- }
59
-
60
- // Replace placeholder with actual types entrypoint
61
- file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
62
- writeFile("env.d.ts", file);
63
-
64
- s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
65
41
  };
66
42
 
67
43
  const updateViteConfig = (ctx: C3Context) => {
@@ -1,4 +1,4 @@
1
- /// <reference types="WORKERS_TYPES_ENTRYPOINT" />
1
+ /// <reference types="./worker-configuration.d.ts" />
2
2
 
3
3
  declare module "h3" {
4
4
  interface H3EventContext {
@@ -3,7 +3,6 @@ import { logRaw } from "@cloudflare/cli";
3
3
  import { brandColor, dim } from "@cloudflare/cli/colors";
4
4
  import { spinner } from "@cloudflare/cli/interactive";
5
5
  import { runFrameworkGenerator } from "frameworks/index";
6
- import { compatDateFlag } from "helpers/compatDate";
7
6
  import { readFile, readJSON, writeFile } from "helpers/files";
8
7
  import { detectPackageManager } from "helpers/packageManagers";
9
8
  import { installPackages } from "helpers/packages";
@@ -107,10 +106,11 @@ const config: TemplateConfig = {
107
106
  configure,
108
107
  transformPackageJson: async () => ({
109
108
  scripts: {
110
- start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()}`,
109
+ start: `${npm} run build && wrangler pages dev`,
111
110
  build: `ng build && ${npm} run process`,
112
111
  process: "node ./tools/copy-files.mjs",
113
- deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
112
+ deploy: `${npm} run build && wrangler pages deploy`,
113
+ "cf-typegen": `wrangler types`,
114
114
  },
115
115
  }),
116
116
  };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "compatibility_date": "<TBD>",
4
+ "pages_build_output_dir": "./dist/cloudflare"
5
+ }
@@ -106,6 +106,7 @@ const config: TemplateConfig = {
106
106
  start: `${npm} run build && wrangler dev`,
107
107
  build: `ng build`,
108
108
  deploy: `${npm} run build && wrangler deploy`,
109
+ "cf-typegen": `wrangler types`,
109
110
  },
110
111
  }),
111
112
  };
@@ -3,7 +3,8 @@
3
3
  "main": "./dist/_worker.js/index.js",
4
4
  "compatibility_date": "<TBD>",
5
5
  "compatibility_flags": [
6
- "nodejs_compat"
6
+ "nodejs_compat",
7
+ "global_fetch_strictly_public"
7
8
  ],
8
9
  "assets": {
9
10
  "binding": "ASSETS",
@@ -3,7 +3,8 @@
3
3
  "main": "./dist/_worker.js/index.js",
4
4
  "compatibility_date": "<TBD>",
5
5
  "compatibility_flags": [
6
- "nodejs_compat"
6
+ "nodejs_compat",
7
+ "global_fetch_strictly_public"
7
8
  ],
8
9
  "assets": {
9
10
  "binding": "ASSETS",
@@ -16,9 +16,6 @@
16
16
  /* Enable importing .json files */
17
17
  "resolveJsonModule": true,
18
18
 
19
- /* Specify type package names to be included without being referenced in a source file. */
20
- "types": ["@cloudflare/workers-types"],
21
-
22
19
  /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
23
20
  "allowJs": true,
24
21
  /* Enable error reporting in type-checked JavaScript files. */
@@ -27,5 +27,6 @@ const config: TemplateConfig = {
27
27
  devScript: "preview",
28
28
  deployScript: "deploy",
29
29
  previewScript: "preview",
30
+ workersTypes: "none",
30
31
  };
31
32
  export default config;
@@ -29,5 +29,6 @@ const config: TemplateConfig = {
29
29
  devScript: "start",
30
30
  deployScript: "deploy",
31
31
  previewScript: "preview",
32
+ workersTypes: "none",
32
33
  };
33
34
  export default config;
@@ -47,5 +47,6 @@ const config: TemplateConfig = {
47
47
  devScript: "develop",
48
48
  deployScript: "deploy",
49
49
  previewScript: "preview",
50
+ workersTypes: "none",
50
51
  };
51
52
  export default config;
@@ -49,5 +49,6 @@ const config: TemplateConfig = {
49
49
  devScript: "develop",
50
50
  deployScript: "deploy",
51
51
  previewScript: "preview",
52
+ workersTypes: "none",
52
53
  };
53
54
  export default config;
@@ -1,4 +1,3 @@
1
- // test/index.spec.ts
2
1
  import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
3
2
  import { describe, it, expect } from 'vitest';
4
3
  import worker from '../src/index';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
- "types": ["@cloudflare/workers-types/experimental", "@cloudflare/vitest-pool-workers"]
4
+ "types": ["@cloudflare/vitest-pool-workers"]
5
5
  },
6
6
  "include": ["./**/*.ts", "../worker-configuration.d.ts"],
7
7
  "exclude": []
@@ -13,8 +13,6 @@
13
13
  "module": "es2022",
14
14
  /* Specify how TypeScript looks up a file from a given module specifier. */
15
15
  "moduleResolution": "Bundler",
16
- /* Specify type package names to be included without being referenced in a source file. */
17
- "types": ["@cloudflare/workers-types"],
18
16
  /* Enable importing .json files */
19
17
  "resolveJsonModule": true,
20
18
 
@@ -7,5 +7,6 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading">Hello, World!</h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  </body>
11
12
  </html>
@@ -2,6 +2,7 @@
2
2
  "name": "<TBD>",
3
3
  "compatibility_date": "<TBD>",
4
4
  "assets": {
5
+ // The path to the directory containing the `index.html` file to be served at `/`
5
6
  "directory": "./public"
6
7
  },
7
8
  "observability": {
@@ -13,8 +13,6 @@
13
13
  "module": "es2022",
14
14
  /* Specify how TypeScript looks up a file from a given module specifier. */
15
15
  "moduleResolution": "node",
16
- /* Specify type package names to be included without being referenced in a source file. */
17
- "types": ["@cloudflare/workers-types"],
18
16
  /* Enable importing .json files */
19
17
  "resolveJsonModule": true,
20
18
 
@@ -4,6 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Hello, World!</title>
7
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
7
8
  </head>
8
9
  <body>
9
10
  <h1 id="heading"></h1>
@@ -3,7 +3,7 @@
3
3
  "main": "src/index.js",
4
4
  "compatibility_date": "<TBD>",
5
5
  "assets": {
6
- "binding": "ASSETS",
6
+ // The path to the directory containing the `index.html` file to be served at `/`
7
7
  "directory": "./public"
8
8
  },
9
9
  "durable_objects": {
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading"></h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  <script>
11
12
  fetch('/message')
12
13
  .then((resp) => resp.text())
@@ -6,7 +6,7 @@
6
6
  "python_workers"
7
7
  ],
8
8
  "assets": {
9
- "binding": "ASSETS",
9
+ // The path to the directory containing the `index.html` file to be served at `/`
10
10
  "directory": "./public"
11
11
  },
12
12
  "migrations": [
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading"></h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  <script>
11
12
  fetch('/message')
12
13
  .then((resp) => resp.text())
@@ -13,8 +13,6 @@
13
13
  "module": "es2022",
14
14
  /* Specify how TypeScript looks up a file from a given module specifier. */
15
15
  "moduleResolution": "node",
16
- /* Specify type package names to be included without being referenced in a source file. */
17
- "types": ["@cloudflare/workers-types"],
18
16
  /* Enable importing .json files */
19
17
  "resolveJsonModule": true,
20
18
 
@@ -11,7 +11,7 @@
11
11
  }
12
12
  ],
13
13
  "assets": {
14
- "binding": "ASSETS",
14
+ // The path to the directory containing the `index.html` file to be served at `/`
15
15
  "directory": "./public"
16
16
  },
17
17
  "durable_objects": {
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading"></h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  <button id="button" type="button">Fetch a random UUID</button>
11
12
  <output id="random" for="button"></output>
12
13
  <script>
@@ -3,10 +3,11 @@
3
3
  "main": "src/index.js",
4
4
  "compatibility_date": "<TBD>",
5
5
  "compatibility_flags": [
6
- "nodejs_compat"
6
+ "nodejs_compat",
7
+ "global_fetch_strictly_public"
7
8
  ],
8
9
  "assets": {
9
- "binding": "ASSETS",
10
+ // The path to the directory containing the `index.html` file to be served at `/`
10
11
  "directory": "./public"
11
12
  },
12
13
  "observability": {
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading"></h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  <button id="button" type="button">Fetch a random UUID</button>
11
12
  <output id="random" for="button"></output>
12
13
  <script>
@@ -6,7 +6,7 @@
6
6
  "python_workers"
7
7
  ],
8
8
  "assets": {
9
- "binding": "ASSETS",
9
+ // The path to the directory containing the `index.html` file to be served at `/`
10
10
  "directory": "./public"
11
11
  },
12
12
  "observability": {
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <h1 id="heading"></h1>
10
+ <p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
10
11
  <button id="button" type="button">Fetch a random UUID</button>
11
12
  <output id="random" for="button"></output>
12
13
  <script>
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
- "types": ["@cloudflare/workers-types/experimental", "@cloudflare/vitest-pool-workers"]
4
+ "types": ["@cloudflare/vitest-pool-workers"]
5
5
  },
6
6
  "include": ["./**/*.ts", "../worker-configuration.d.ts"],
7
7
  "exclude": []
@@ -13,8 +13,6 @@
13
13
  "module": "es2022",
14
14
  /* Specify how TypeScript looks up a file from a given module specifier. */
15
15
  "moduleResolution": "Bundler",
16
- /* Specify type package names to be included without being referenced in a source file. */
17
- "types": ["@cloudflare/workers-types"],
18
16
  /* Enable importing .json files */
19
17
  "resolveJsonModule": true,
20
18
 
@@ -3,10 +3,10 @@
3
3
  "main": "src/index.ts",
4
4
  "compatibility_date": "<TBD>",
5
5
  "compatibility_flags": [
6
- "nodejs_compat"
6
+ "global_fetch_strictly_public"
7
7
  ],
8
8
  "assets": {
9
- "binding": "ASSETS",
9
+ // The path to the directory containing the `index.html` file to be served at `/`
10
10
  "directory": "./public"
11
11
  },
12
12
  "observability": {
@@ -0,0 +1,20 @@
1
+ import type { TemplateConfig } from "../../src/templates";
2
+
3
+ export default {
4
+ configVersion: 1,
5
+ id: "hello-world-workflows",
6
+ displayName: "Workflow",
7
+ description:
8
+ "For multi-step applications that automatically retry, persist state, and run for minutes, hours, days or weeks",
9
+ platform: "workers",
10
+ copyFiles: {
11
+ variants: {
12
+ js: {
13
+ path: "./js",
14
+ },
15
+ ts: {
16
+ path: "./ts",
17
+ },
18
+ },
19
+ },
20
+ } satisfies TemplateConfig;
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler deploy",
7
+ "start": "wrangler dev",
8
+ "dev": "wrangler dev"
9
+ },
10
+ "devDependencies": {
11
+ "wrangler": "^4.6.0"
12
+ }
13
+ }
@@ -0,0 +1,129 @@
1
+ import { WorkflowEntrypoint } from "cloudflare:workers";
2
+
3
+ /**
4
+ * Welcome to Cloudflare Workers! This is your first Workflows application.
5
+ *
6
+ * - Run `npm run dev` in your terminal to start a development server
7
+ * - Open a browser tab at http://localhost:8787/ to see your Workflow in action
8
+ * - Run `npm run deploy` to publish your application
9
+ *
10
+ * Learn more at https://developers.cloudflare.com/workflows
11
+ */
12
+
13
+ /**
14
+ * @typedef {Object} Env
15
+ * @property {Workflow} MY_WORKFLOW
16
+ */
17
+
18
+ /**
19
+ * @typedef {Object} Params
20
+ * @property {string} email
21
+ * @property {Record<string, string>} metadata
22
+ */
23
+
24
+ export class MyWorkflow extends WorkflowEntrypoint {
25
+ /**
26
+ * @param {Env} env
27
+ */
28
+ constructor(env) {
29
+ this.env = env;
30
+ }
31
+
32
+ /**
33
+ * @param {WorkflowEvent<Params>} event
34
+ * @param {WorkflowStep} step
35
+ */
36
+ async run(event, step) {
37
+ // Can access bindings on `this.env`
38
+ // Can access params on `event.payload`
39
+
40
+ const files = await step.do("my first step", async () => {
41
+ // Fetch a list of files from $SOME_SERVICE
42
+ return {
43
+ inputParams: event,
44
+ files: [
45
+ "doc_7392_rev3.pdf",
46
+ "report_x29_final.pdf",
47
+ "memo_2024_05_12.pdf",
48
+ "file_089_update.pdf",
49
+ "proj_alpha_v2.pdf",
50
+ "data_analysis_q2.pdf",
51
+ "notes_meeting_52.pdf",
52
+ "summary_fy24_draft.pdf",
53
+ ],
54
+ };
55
+ });
56
+
57
+ // You can optionally have a Workflow wait for additional data,
58
+ // human approval or an external webhook or HTTP request before progressing.
59
+ // You can submit data via HTTP POST to /accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/events/{eventName}
60
+ const waitForApproval = await step.waitForEvent("request-approval", {
61
+ type: "approval", // define an optional key to switch on
62
+ timeout: "1 minute", // keep it short for the example!
63
+ });
64
+
65
+ const apiResponse = await step.do("some other step", async () => {
66
+ let resp = await fetch("https://api.cloudflare.com/client/v4/ips");
67
+ return await resp.json();
68
+ });
69
+
70
+ await step.sleep("wait on something", "1 minute");
71
+
72
+ await step.do(
73
+ "make a call to write that could maybe, just might, fail",
74
+ // Define a retry strategy
75
+ /** @type {Object} */ ({
76
+ retries: {
77
+ limit: 5,
78
+ delay: "5 second",
79
+ backoff: "exponential",
80
+ },
81
+ timeout: "15 minutes",
82
+ }),
83
+ async () => {
84
+ // Do stuff here, with access to the state from our previous steps
85
+ if (Math.random() > 0.5) {
86
+ throw new Error("API call to $STORAGE_SYSTEM failed");
87
+ }
88
+ },
89
+ );
90
+ }
91
+ }
92
+
93
+ export default {
94
+ /**
95
+ * @param {Request} req
96
+ * @param {Env} env
97
+ * @returns {Promise<Response>}
98
+ */
99
+ async fetch(req, env) {
100
+ let url = new URL(req.url);
101
+
102
+ if (url.pathname.startsWith("/favicon")) {
103
+ return Response.json({}, { status: 404 });
104
+ }
105
+
106
+ // Get the status of an existing instance, if provided
107
+ // GET /?instanceId=<id here>
108
+ let id = url.searchParams.get("instanceId");
109
+ if (id) {
110
+ let instance = await env.MY_WORKFLOW.get(id);
111
+ return Response.json({
112
+ status: await instance.status(),
113
+ });
114
+ }
115
+
116
+ // Spawn a new instance and return the ID and status
117
+ let instance = await env.MY_WORKFLOW.create();
118
+ // You can also set the ID to match an ID in your own system
119
+ // and pass an optional payload to the Workflow
120
+ // let instance = await env.MY_WORKFLOW.create({
121
+ // id: 'id-from-your-system',
122
+ // params: { payload: 'to send' },
123
+ // });
124
+ return Response.json({
125
+ id: instance.id,
126
+ details: await instance.status(),
127
+ });
128
+ },
129
+ };
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "main": "src/index.js",
4
+ "compatibility_date": "<TBD>",
5
+
6
+ "observability": {
7
+ "enabled": true,
8
+ "head_sampling_rate": 1,
9
+ },
10
+ "workflows": [
11
+ {
12
+ "name": "<TBD>",
13
+ "binding": "MY_WORKFLOW",
14
+ "class_name": "MyWorkflow",
15
+ },
16
+ ],
17
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "<TBD>",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler deploy",
7
+ "start": "wrangler dev",
8
+ "dev": "wrangler dev",
9
+ "cf-typegen": "wrangler types"
10
+ },
11
+ "devDependencies": {
12
+ "typescript": "^5.0.4",
13
+ "wrangler": "^4.6.0"
14
+ }
15
+ }