@upstash/workflow 1.4.0 → 1.5.0

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 (223) hide show
  1. package/README.md +9 -0
  2. package/astro.d.mts +19 -2
  3. package/astro.d.ts +19 -2
  4. package/astro.js +670 -159
  5. package/astro.mjs +1 -1
  6. package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
  7. package/cloudflare.d.mts +17 -2
  8. package/cloudflare.d.ts +17 -2
  9. package/cloudflare.js +670 -159
  10. package/cloudflare.mjs +1 -1
  11. package/docs/agents/examples.mdx +8 -0
  12. package/docs/agents/features.mdx +374 -0
  13. package/docs/agents/getting-started.mdx +139 -0
  14. package/docs/agents/overview.mdx +40 -0
  15. package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
  16. package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
  17. package/docs/agents/patterns/parallelization.mdx +77 -0
  18. package/docs/agents/patterns/prompt-chaining.mdx +84 -0
  19. package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
  20. package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
  21. package/docs/basics/best-practices/deterministic-code.mdx +132 -0
  22. package/docs/basics/best-practices/idempotency.mdx +38 -0
  23. package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
  24. package/docs/basics/best-practices/overview.mdx +35 -0
  25. package/docs/basics/best-practices/promise-any.mdx +9 -0
  26. package/docs/basics/best-practices/return-step-results.mdx +80 -0
  27. package/docs/basics/best-practices/workflow-limits.mdx +62 -0
  28. package/docs/basics/client/cancel.mdx +137 -0
  29. package/docs/basics/client/dlq/callback.mdx +21 -0
  30. package/docs/basics/client/dlq/delete.mdx +120 -0
  31. package/docs/basics/client/dlq/list.mdx +96 -0
  32. package/docs/basics/client/dlq/restart.mdx +164 -0
  33. package/docs/basics/client/dlq/resume.mdx +167 -0
  34. package/docs/basics/client/logs.mdx +139 -0
  35. package/docs/basics/client/notify.mdx +79 -0
  36. package/docs/basics/client/trigger.mdx +139 -0
  37. package/docs/basics/client/waiters.mdx +31 -0
  38. package/docs/basics/client.mdx +40 -0
  39. package/docs/basics/how.mdx +65 -0
  40. package/docs/basics/serve/advanced.mdx +435 -0
  41. package/docs/basics/serve.mdx +142 -0
  42. package/docs/changelog.mdx +174 -0
  43. package/docs/examples/allInOne.mdx +377 -0
  44. package/docs/examples/authWebhook.mdx +567 -0
  45. package/docs/examples/customRetry.mdx +309 -0
  46. package/docs/examples/customerOnboarding.mdx +230 -0
  47. package/docs/examples/dynamicWorkflow.mdx +203 -0
  48. package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
  49. package/docs/examples/imageProcessing.mdx +339 -0
  50. package/docs/examples/paymentRetry.mdx +438 -0
  51. package/docs/examples/waitForEvent.mdx +201 -0
  52. package/docs/features/dlq/callback.mdx +42 -0
  53. package/docs/features/dlq/delete.mdx +29 -0
  54. package/docs/features/dlq/restart.mdx +33 -0
  55. package/docs/features/dlq/resume.mdx +37 -0
  56. package/docs/features/dlq.mdx +39 -0
  57. package/docs/features/failure-callback.mdx +102 -0
  58. package/docs/features/failureFunction/advanced.mdx +36 -0
  59. package/docs/features/failureFunction/reliability.mdx +33 -0
  60. package/docs/features/flow-control/monitor.mdx +22 -0
  61. package/docs/features/flow-control/parallelism.mdx +45 -0
  62. package/docs/features/flow-control/rate-period.mdx +46 -0
  63. package/docs/features/flow-control.mdx +164 -0
  64. package/docs/features/invoke/serveMany.mdx +109 -0
  65. package/docs/features/invoke.mdx +39 -0
  66. package/docs/features/notify.mdx +127 -0
  67. package/docs/features/parallel-steps.mdx +41 -0
  68. package/docs/features/retries/prevent-retries.mdx +140 -0
  69. package/docs/features/retries.mdx +93 -0
  70. package/docs/features/wait-for-event.mdx +104 -0
  71. package/docs/features/wait.mdx +44 -0
  72. package/docs/features/webhooks.mdx +116 -0
  73. package/docs/getstarted.mdx +200 -0
  74. package/docs/howto/cancel.mdx +50 -0
  75. package/docs/howto/changes.mdx +33 -0
  76. package/docs/howto/configure.mdx +42 -0
  77. package/docs/howto/failures.mdx +185 -0
  78. package/docs/howto/get-token.mdx +18 -0
  79. package/docs/howto/local-development/development-server.mdx +130 -0
  80. package/docs/howto/local-development/local-tunnel.mdx +73 -0
  81. package/docs/howto/middlewares.mdx +263 -0
  82. package/docs/howto/migrations.mdx +335 -0
  83. package/docs/howto/multi-region.mdx +107 -0
  84. package/docs/howto/parallel-runs.mdx +52 -0
  85. package/docs/howto/readonly-token.mdx +19 -0
  86. package/docs/howto/realtime/basic.mdx +315 -0
  87. package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
  88. package/docs/howto/redact-fields.mdx +61 -0
  89. package/docs/howto/retry-now.mdx +41 -0
  90. package/docs/howto/schedule.mdx +104 -0
  91. package/docs/howto/security.mdx +143 -0
  92. package/docs/howto/singleton.mdx +137 -0
  93. package/docs/howto/start.mdx +69 -0
  94. package/docs/howto/use-webhooks.mdx +256 -0
  95. package/docs/integrations/aisdk.mdx +316 -0
  96. package/docs/integrations/anthropic.mdx +51 -0
  97. package/docs/integrations/datadog.mdx +69 -0
  98. package/docs/integrations/openai.mdx +87 -0
  99. package/docs/integrations/prometheus.mdx +65 -0
  100. package/docs/integrations/resend.mdx +82 -0
  101. package/docs/llms-txt.mdx +4 -0
  102. package/docs/openapi.yaml +2944 -0
  103. package/docs/pricing.mdx +22 -0
  104. package/docs/quickstarts/astro.mdx +185 -0
  105. package/docs/quickstarts/cloudflare-workers.mdx +190 -0
  106. package/docs/quickstarts/express.mdx +190 -0
  107. package/docs/quickstarts/fastapi.mdx +282 -0
  108. package/docs/quickstarts/flask.mdx +282 -0
  109. package/docs/quickstarts/hono.mdx +221 -0
  110. package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
  111. package/docs/quickstarts/nextjs-flask.mdx +147 -0
  112. package/docs/quickstarts/nuxt.mdx +169 -0
  113. package/docs/quickstarts/platforms.mdx +78 -0
  114. package/docs/quickstarts/solidjs.mdx +161 -0
  115. package/docs/quickstarts/svelte.mdx +170 -0
  116. package/docs/quickstarts/tanstack-start.mdx +205 -0
  117. package/docs/quickstarts/vercel-nextjs.mdx +233 -0
  118. package/docs/roadmap.mdx +8 -0
  119. package/docs/sdk/workflow-js.mdx +4 -0
  120. package/docs/sdk/workflow-py.mdx +4 -0
  121. package/docs/steps/api.mdx +64 -0
  122. package/docs/steps/call.mdx +183 -0
  123. package/docs/steps/cancel.mdx +25 -0
  124. package/docs/steps/createWebhook.mdx +40 -0
  125. package/docs/steps/invoke.mdx +100 -0
  126. package/docs/steps/notify.mdx +105 -0
  127. package/docs/steps/run.mdx +150 -0
  128. package/docs/steps/sleep.mdx +97 -0
  129. package/docs/steps/sleepUntil.mdx +88 -0
  130. package/docs/steps/waitForEvent.mdx +60 -0
  131. package/docs/steps/waitForWebhook.mdx +78 -0
  132. package/docs/steps.mdx +108 -0
  133. package/docs/troubleshooting/general.mdx +331 -0
  134. package/docs/troubleshooting/vercel.mdx +82 -0
  135. package/express.d.mts +19 -2
  136. package/express.d.ts +19 -2
  137. package/express.js +670 -159
  138. package/express.mjs +1 -1
  139. package/h3.d.mts +19 -2
  140. package/h3.d.ts +19 -2
  141. package/h3.js +670 -159
  142. package/h3.mjs +1 -1
  143. package/hono.d.mts +17 -2
  144. package/hono.d.ts +17 -2
  145. package/hono.js +670 -159
  146. package/hono.mjs +1 -1
  147. package/index.d.mts +50 -21
  148. package/index.d.ts +50 -21
  149. package/index.js +686 -171
  150. package/index.mjs +17 -13
  151. package/nextjs.d.mts +40 -2
  152. package/nextjs.d.ts +40 -2
  153. package/nextjs.js +670 -159
  154. package/nextjs.mjs +1 -1
  155. package/package.json +1 -1
  156. package/react-router.d.mts +16 -2
  157. package/react-router.d.ts +16 -2
  158. package/react-router.js +670 -159
  159. package/react-router.mjs +1 -1
  160. package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
  161. package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
  162. package/solidjs.d.mts +10 -1
  163. package/solidjs.d.ts +10 -1
  164. package/solidjs.js +670 -159
  165. package/solidjs.mjs +1 -1
  166. package/src/platforms/astro.ts +84 -0
  167. package/src/platforms/cloudflare.ts +127 -0
  168. package/src/platforms/express.ts +147 -0
  169. package/src/platforms/h3.ts +105 -0
  170. package/src/platforms/hono.ts +103 -0
  171. package/src/platforms/nextjs.ts +193 -0
  172. package/src/platforms/react-router.ts +92 -0
  173. package/src/platforms/solidjs.ts +59 -0
  174. package/src/platforms/svelte.ts +99 -0
  175. package/src/platforms/tanstack.ts +96 -0
  176. package/src/src/client/dlq.ts +387 -0
  177. package/src/src/client/filter-types.ts +166 -0
  178. package/src/src/client/index.ts +350 -0
  179. package/src/src/client/types.ts +501 -0
  180. package/src/src/client/utils.ts +307 -0
  181. package/src/src/constants.ts +82 -0
  182. package/src/src/context/api/anthropic.ts +58 -0
  183. package/src/src/context/api/base.ts +52 -0
  184. package/src/src/context/api/index.ts +24 -0
  185. package/src/src/context/api/openai.ts +125 -0
  186. package/src/src/context/api/resend.ts +57 -0
  187. package/src/src/context/auto-executor.ts +707 -0
  188. package/src/src/context/context.ts +681 -0
  189. package/src/src/context/index.ts +1 -0
  190. package/src/src/context/provider.ts +37 -0
  191. package/src/src/context/steps.ts +965 -0
  192. package/src/src/error.ts +203 -0
  193. package/src/src/index.ts +13 -0
  194. package/src/src/middleware/default-callbacks.ts +20 -0
  195. package/src/src/middleware/index.ts +2 -0
  196. package/src/src/middleware/logging.ts +39 -0
  197. package/src/src/middleware/manager.ts +148 -0
  198. package/src/src/middleware/middleware.ts +46 -0
  199. package/src/src/middleware/types.ts +72 -0
  200. package/src/src/qstash/headers.ts +397 -0
  201. package/src/src/qstash/step-config.ts +268 -0
  202. package/src/src/qstash/submit-steps.ts +284 -0
  203. package/src/src/serve/authorization.ts +118 -0
  204. package/src/src/serve/index.ts +475 -0
  205. package/src/src/serve/multi-region/handlers.ts +225 -0
  206. package/src/src/serve/multi-region/utils.ts +88 -0
  207. package/src/src/serve/options.ts +241 -0
  208. package/src/src/serve/serve-many.ts +117 -0
  209. package/src/src/serve/utils.ts +11 -0
  210. package/src/src/types.ts +590 -0
  211. package/src/src/utils.ts +141 -0
  212. package/src/src/workflow-parser.ts +472 -0
  213. package/src/src/workflow-requests.ts +575 -0
  214. package/svelte.d.mts +17 -2
  215. package/svelte.d.ts +17 -2
  216. package/svelte.js +670 -159
  217. package/svelte.mjs +1 -1
  218. package/tanstack.d.mts +15 -2
  219. package/tanstack.d.ts +15 -2
  220. package/tanstack.js +670 -159
  221. package/tanstack.mjs +1 -1
  222. package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
  223. package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
@@ -0,0 +1,221 @@
1
+ ---
2
+ title: Upstash Workflow with Hono
3
+ sidebarTitle: Hono
4
+ ---
5
+
6
+ <Card title="GitHub Repository" icon="github" href="https://github.com/upstash/workflow-js/tree/main/examples/hono" horizontal>
7
+ You can find the project source code on GitHub.
8
+ </Card>
9
+ <Card title="Deploy With Cloudflare Workers" icon="cloudflare" href="https://deploy.workers.cloudflare.com/?url=https://github.com/upstash/qstash-workflow-example-cloudflare-workers-hono" horizontal>
10
+ Deploy the project to Cloudflare Workers with a single click.
11
+ </Card>
12
+ This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Hono. You can also explore our [Hono example](https://github.com/upstash/workflow-js/tree/main/examples/hono) for a detailed, end-to-end example and best practices.
13
+
14
+ ## Prerequisites
15
+
16
+ 1. An Upstash QStash API key.
17
+ 2. Node.js and npm (another package manager) installed.
18
+
19
+ If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
20
+
21
+ ## Step 1: Installation
22
+
23
+ First, install the Workflow SDK in your Hono project:
24
+
25
+ <Tabs>
26
+ <Tab title="npm">
27
+ ```bash
28
+ npm install @upstash/workflow
29
+ ```
30
+ </Tab>
31
+ <Tab title="pnpm">
32
+ ```bash
33
+ pnpm install @upstash/workflow
34
+ ```
35
+ </Tab>
36
+ <Tab title="bun">
37
+ ```bash
38
+ bun add @upstash/workflow
39
+ ```
40
+ </Tab>
41
+ </Tabs>
42
+
43
+
44
+ ## Step 2: Configure Environment Variables
45
+
46
+ Create a `.dev.vars` file in your project root and add your QStash token. This key is used to authenticate your application with the QStash service.
47
+
48
+ ```bash Terminal
49
+ touch .dev.vars
50
+ ```
51
+
52
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app's URL. However, for local development, you have two main options: [use a local QStash server or set up a local tunnel](/workflow/howto/local-development/development-server).
53
+
54
+ ### Option 1: Local QStash Server
55
+
56
+ To start the local QStash server, run:
57
+
58
+ ```bash
59
+ npx @upstash/qstash-cli dev
60
+ ```
61
+
62
+ Once the command runs successfully, you’ll see `QSTASH_URL` and `QSTASH_TOKEN` values in the console. Add these values to your `.dev.vars` file:
63
+
64
+ ```txt .dev.vars
65
+ QSTASH_URL="http://127.0.0.1:8080"
66
+ QSTASH_TOKEN="<QSTASH_TOKEN>"
67
+ ```
68
+
69
+ This approach allows you to test workflows locally without affecting your billing. However, runs won't be logged in the Upstash Console.
70
+
71
+ ### Option 2: Local Tunnel
72
+
73
+ Alternatively, you can set up a local tunnel. For this option:
74
+
75
+ 1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
76
+ 2. Update your `.dev.vars` file with the following:
77
+
78
+ ```txt .dev.vars
79
+ QSTASH_TOKEN="***"
80
+ UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
81
+ ```
82
+
83
+ - Replace `***` with your actual QStash token.
84
+ - Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
85
+
86
+ Here’s where you can find your QStash token:
87
+
88
+ <Frame>
89
+ <img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
90
+ </Frame>
91
+
92
+ Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
93
+
94
+ ## Step 3: Create a Workflow Endpoint
95
+
96
+ A workflow endpoint allows you to define a set of steps that, together, make up a workflow. Each step contains a piece of business logic that is automatically retried on failure, with easy monitoring via our visual workflow dashboard.
97
+
98
+ To define a workflow endpoint with Hono, navigate into your entrypoint file (usually `src/index.ts`) and add the following code:
99
+
100
+ <Tabs>
101
+
102
+ <Tab title="Minimal example">
103
+ ```typescript src/index.ts
104
+ import { Hono } from "hono"
105
+ import { serve } from "@upstash/workflow/hono"
106
+
107
+ const app = new Hono()
108
+
109
+ app.post("/workflow",
110
+ serve(async (context) => {
111
+ await context.run("initial-step", () => {
112
+ console.log("initial step ran")
113
+ })
114
+
115
+ await context.run("second-step", () => {
116
+ console.log("second step ran")
117
+ })
118
+ })
119
+ )
120
+
121
+ export default app
122
+ ```
123
+ </Tab>
124
+
125
+
126
+ <Tab title="With Hono context">
127
+ ```typescript src/index.ts
128
+ import { Hono } from "hono"
129
+ import { serve, WorkflowBindings } from "@upstash/workflow/hono"
130
+ import { env } from "hono/adapter"
131
+
132
+ interface Bindings extends WorkflowBindings {
133
+ ENVIRONMENT: "development" | "production"
134
+ }
135
+
136
+ const app = new Hono<{ Bindings: Bindings }>()
137
+
138
+ app.post("/workflow", (c) => {
139
+ // 👇 access Honos native context, i.e. getting an env variable
140
+ const { ENVIRONMENT } = env(c)
141
+
142
+ // 👇 `unknown` represents your initial payload data type
143
+ const handler = serve<unknown, Bindings>(
144
+ async (context) => { ... }
145
+ )
146
+
147
+ return await handler(c)
148
+ })
149
+
150
+ export default app
151
+ ```
152
+ </Tab>
153
+ </Tabs>
154
+
155
+ ## Step 4: Run the Workflow Endpoint
156
+
157
+ To start your Hono app locally, run the following command:
158
+
159
+ ```bash Terminal
160
+ npm run dev
161
+ ```
162
+
163
+ Executing this command prints a local URL to your workflow endpoint. By default, this URL is `http://localhost:8787`.
164
+
165
+ You can verify your correct environment variable setup by checking the wrangler output, which should now have access to your `QSTASH_TOKEN` binding and log your local URL:
166
+
167
+ <Frame>
168
+ <img src="/img/qstash-workflow/wrangler.png" alt="Local Cloudflare Worker started with Wrangler" />
169
+ </Frame>
170
+
171
+ Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
172
+
173
+ ```bash Terminal
174
+ curl -X POST https://localhost:8787/workflow
175
+
176
+ # result: {"workflowRunId":"wfr_xxxxxx"}
177
+ ```
178
+
179
+ See the [documentation on starting a workflow](/workflow/howto/start) for other ways you can start your workflow.
180
+
181
+ <Frame>
182
+ <img src="/img/qstash-workflow/hono_local_request.png" alt="Local workflow request" />
183
+ </Frame>
184
+
185
+ If you didn't set up local QStash development server, you can use this ID to track the workflow run and see its status in your QStash workflow dashboard. All steps are listed with their statuses, headers, and body for a detailed overview of your workflow from start to finish. Click on a step to see its detailed logs.
186
+
187
+ <Frame>
188
+ <img src="/img/qstash-workflow/dashboard.png" alt="Workflow run in the Upstash Console" />
189
+ </Frame>
190
+
191
+ ## Step 5: Deploying to Production
192
+
193
+ When deploying your Hono app with Upstash Workflow to production, there are a few key points to keep in mind:
194
+
195
+ 1. **Environment Variables**: Make sure that all necessary environment variables from your `.dev.vars` file are set in your Cloudflare Worker project settings. For example, your `QSTASH_TOKEN`, and any other configuration variables your workflow might need.
196
+
197
+ 2. **Remove Local Development Settings**: In your production code, you can remove or conditionally exclude any local development settings. For example, if you used [local tunnel for local development](/workflow/howto/local-development/local-tunnel)
198
+
199
+ 3. **Deployment**: Deploy your Hono app to production as you normally would, for example using the Cloudflare CLI:
200
+
201
+ ```bash Terminal
202
+ wrangler deploy
203
+ ```
204
+
205
+ 4. **Verify Workflow Endpoint**: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
206
+
207
+ ```bash Terminal
208
+ curl -X POST https://<YOUR-PRODUCTION-URL>/workflow
209
+ ```
210
+
211
+ 5. **Monitor in QStash Dashboard**: Use the QStash dashboard to monitor your production workflows. You can track workflow runs, view step statuses, and access detailed logs.
212
+
213
+ 6. **Set Up Alerts**: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
214
+
215
+ ## Next Steps
216
+
217
+ 1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
218
+
219
+ 2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/hono) for a detailed, end-to-end example and best practices.
220
+
221
+ 3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
@@ -0,0 +1,147 @@
1
+ ---
2
+ title: Upstash Workflow with Next.js and FastAPI
3
+ sidebarTitle: Next.js & FastAPI
4
+ ---
5
+
6
+ <Card title="GitHub Repository" icon="github" href="https://github.com/upstash/workflow-py/tree/master/examples/nextjs-fastapi" horizontal>
7
+ You can find the project source code on GitHub.
8
+ </Card>
9
+
10
+ This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Next.js & FastAPI. You can also explore [the source code](https://github.com/upstash/workflow-py/tree/master/examples/nextjs-fastapi) for a detailed, end-to-end example and best practices.
11
+
12
+ ## Prerequisites
13
+
14
+ 1. An Upstash QStash API key.
15
+ 2. Node.js and npm (or another package manager) installed.
16
+ 3. Python and pip installed.
17
+
18
+ If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
19
+
20
+ ## Step 1: Setup
21
+
22
+ Clone the [Next.js & FastAPI example](https://github.com/upstash/workflow-py/tree/master/examples/nextjs-fastapi):
23
+
24
+ ```bash
25
+ git clone https://github.com/upstash/workflow-py.git
26
+ cd workflow-py/examples/nextjs-fastapi
27
+ ```
28
+
29
+ ## Step 2: Installation
30
+
31
+ Create a virtual environment and activate it:
32
+
33
+ ```bash Terminal
34
+ python -m venv venv
35
+ source venv/bin/activate
36
+ ```
37
+
38
+ Install the dependencies:
39
+
40
+ ```bash
41
+ npm install
42
+ ```
43
+
44
+ ## Step 3: Configure Environment Variables
45
+
46
+ Create a `.env` file in your project root and add your QStash token. This token is used to authenticate your application with the QStash service.
47
+
48
+ ```bash Terminal
49
+ touch .env
50
+ ```
51
+
52
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app's URL. However, for local development, you have two main options: [use a local QStash server or set up a local tunnel](/workflow/howto/local-development/development-server).
53
+
54
+ ### Option 1: Local QStash Server
55
+
56
+ To start the local QStash server, run:
57
+
58
+ ```bash
59
+ npx @upstash/qstash-cli dev
60
+ ```
61
+
62
+ Once the command runs successfully, you’ll see `QSTASH_URL` and `QSTASH_TOKEN` values in the console. Add these values to your `.env` file:
63
+
64
+ ```bash .env
65
+ export QSTASH_URL="http://127.0.0.1:8080"
66
+ export QSTASH_TOKEN="<QSTASH_TOKEN>"
67
+ ```
68
+
69
+ This approach allows you to test workflows locally without affecting your billing. However, runs won't be logged in the Upstash Console.
70
+
71
+ ### Option 2: Local Tunnel
72
+
73
+ Alternatively, you can set up a local tunnel. For this option:
74
+
75
+ 1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
76
+ 2. Update your `.env` file with the following:
77
+
78
+ ```bash .env
79
+ export QSTASH_TOKEN="***"
80
+ export UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
81
+ ```
82
+
83
+ - Replace `***` with your actual QStash token.
84
+ - Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
85
+
86
+ Here’s where you can find your QStash token:
87
+
88
+ <Frame>
89
+ <img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
90
+ </Frame>
91
+
92
+ Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
93
+
94
+ ## Step 4: Start the Development Server
95
+
96
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), and QStash needs a publicly accessible URL to run your workflows. Here's how to [set up your workflow endpoint for local development](/workflow/howto/local-development/development-server).
97
+
98
+ In a nutshell, in local development, you can either use the QStash development server or use a local tunnel to make your workflow endpoint publicly accessible.
99
+
100
+ Don't forget to source your environment file to set your environment variables:
101
+
102
+ ```bash Terminal
103
+ source .env
104
+ ```
105
+
106
+ After defining the endpoint, you can trigger your workflow by starting your app:
107
+
108
+ ```bash Terminal
109
+ npm run dev
110
+ ```
111
+
112
+ Navigate to [http://localhost:3000](http://localhost:3000) to see your Next.js app in action.
113
+ FastAPI will be running on [http://localhost:8000](http://localhost:8000).
114
+
115
+ <Frame>
116
+ <img src="/img/workflow/quickstarts/nextjs-fastapi/workflow-nextjs-fastapi.png" alt="Next.js frontend and Python Workflow API architecture" />
117
+ </Frame>
118
+
119
+ ## Step 5: Deploying the Project at Vercel
120
+
121
+ To deploy the project at vercel and try the endpoints, you should start with setting up the project by running:
122
+
123
+ ```bash Terminal
124
+ vercel
125
+ ```
126
+
127
+ Next, you should go to vercel.com, find your project and add `QSTASH_TOKEN`, to the project as environment variables. You can find these env variables from the [Upstash Console](https://console.upstash.com/qstash). To learn more about other env variables and their use in the context of Upstash Workflow, you can read [the Secure your Endpoint in our documentation](/workflow/howto/security#built-in-request-verification-recommended).
128
+
129
+ Once you add the env variables, you can deploy the project with:
130
+
131
+ ```bash Terminal
132
+ vercel --prod
133
+ ```
134
+
135
+ Note that the project won't work in preview. It should be deployed to production like above. This is because preview requires authentication.
136
+
137
+ Once you have the app deployed, you can go to the deployment and call the endpoints using the form on the page.
138
+
139
+ You can observe the logs at [Upstash console under the Worfklow tab](https://console.upstash.com/qstash?tab=workflow) or vercel.com to see your workflow operate.
140
+
141
+ ## Next Steps
142
+
143
+ 1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
144
+
145
+ 2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/nextjs-fastapi for a detailed, end-to-end example and best practices.
146
+
147
+ 3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
@@ -0,0 +1,147 @@
1
+ ---
2
+ title: Upstash Workflow with Next.js and Flask
3
+ sidebarTitle: Next.js & Flask
4
+ ---
5
+
6
+ <Card title="GitHub Repository" icon="github" href="https://github.com/upstash/workflow-py/tree/master/examples/nextjs-flask" horizontal>
7
+ You can find the project source code on GitHub.
8
+ </Card>
9
+
10
+ This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Next.js & Flask. You can also explore [the source code](https://github.com/upstash/workflow-py/tree/master/examples/nextjs-flask) for a detailed, end-to-end example and best practices.
11
+
12
+ ## Prerequisites
13
+
14
+ 1. An Upstash QStash API key.
15
+ 2. Node.js and npm (or another package manager) installed.
16
+ 3. Python and pip installed.
17
+
18
+ If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
19
+
20
+ ## Step 1: Setup
21
+
22
+ Clone the [Next.js & Flask example](https://github.com/upstash/workflow-py/tree/master/examples/nextjs-flask):
23
+
24
+ ```bash
25
+ git clone https://github.com/upstash/workflow-py.git
26
+ cd workflow-py/examples/nextjs-flask
27
+ ```
28
+
29
+ ## Step 2: Installation
30
+
31
+ Create a virtual environment and activate it:
32
+
33
+ ```bash Terminal
34
+ python -m venv venv
35
+ source venv/bin/activate
36
+ ```
37
+
38
+ Install the dependencies:
39
+
40
+ ```bash
41
+ npm install
42
+ ```
43
+
44
+ ## Step 3: Configure Environment Variables
45
+
46
+ Create a `.env` file in your project root and add your QStash token. This token is used to authenticate your application with the QStash service.
47
+
48
+ ```bash Terminal
49
+ touch .env
50
+ ```
51
+
52
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app's URL. However, for local development, you have two main options: [use a local QStash server or set up a local tunnel](/workflow/howto/local-development/development-server).
53
+
54
+ ### Option 1: Local QStash Server
55
+
56
+ To start the local QStash server, run:
57
+
58
+ ```bash
59
+ npx @upstash/qstash-cli dev
60
+ ```
61
+
62
+ Once the command runs successfully, you’ll see `QSTASH_URL` and `QSTASH_TOKEN` values in the console. Add these values to your `.env` file:
63
+
64
+ ```bash .env
65
+ export QSTASH_URL="http://127.0.0.1:8080"
66
+ export QSTASH_TOKEN="<QSTASH_TOKEN>"
67
+ ```
68
+
69
+ This approach allows you to test workflows locally without affecting your billing. However, runs won't be logged in the Upstash Console.
70
+
71
+ ### Option 2: Local Tunnel
72
+
73
+ Alternatively, you can set up a local tunnel. For this option:
74
+
75
+ 1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
76
+ 2. Update your `.env` file with the following:
77
+
78
+ ```bash .env
79
+ export QSTASH_TOKEN="***"
80
+ export UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
81
+ ```
82
+
83
+ - Replace `***` with your actual QStash token.
84
+ - Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
85
+
86
+ Here’s where you can find your QStash token:
87
+
88
+ <Frame>
89
+ <img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
90
+ </Frame>
91
+
92
+ Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
93
+
94
+ ## Step 4: Start the Development Server
95
+
96
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), and QStash needs a publicly accessible URL to run your workflows. Here's how to [set up your workflow endpoint for local development](/workflow/howto/local-development/development-server).
97
+
98
+ In a nutshell, in local development, you can either use the QStash development server or use a local tunnel to make your workflow endpoint publicly accessible.
99
+
100
+ Don't forget to source your environment file to set your environment variables:
101
+
102
+ ```bash Terminal
103
+ source .env
104
+ ```
105
+
106
+ After defining the endpoint, you can trigger your workflow by starting your app:
107
+
108
+ ```bash
109
+ npm run dev
110
+ ```
111
+
112
+ Navigate to [http://localhost:3000](http://localhost:3000) to see your Next.js app in action.
113
+ Flask will be running on [http://localhost:8000](http://localhost:8000).
114
+
115
+ <Frame>
116
+ <img src="/img/workflow/quickstarts/nextjs-fastapi/workflow-nextjs-fastapi.png" alt="Next.js frontend and Python Workflow API architecture" />
117
+ </Frame>
118
+
119
+ ## Step 5: Deploying the Project at Vercel
120
+
121
+ To deploy the project at vercel and try the endpoints, you should start with setting up the project by running:
122
+
123
+ ```bash Terminal
124
+ vercel
125
+ ```
126
+
127
+ Next, you should go to vercel.com, find your project and add `QSTASH_TOKEN`, to the project as environment variables. You can find these env variables from the [Upstash Console](https://console.upstash.com/qstash). To learn more about other env variables and their use in the context of Upstash Workflow, you can read [the Secure your Endpoint in our documentation](/workflow/howto/security#built-in-request-verification-recommended).
128
+
129
+ Once you add the env variables, you can deploy the project with:
130
+
131
+ ```bash Terminal
132
+ vercel --prod
133
+ ```
134
+
135
+ Note that the project won't work in preview. It should be deployed to production like above. This is because preview requires authentication.
136
+
137
+ Once you have the app deployed, you can go to the deployment and call the endpoints using the form on the page.
138
+
139
+ You can observe the logs at [Upstash console under the Worfklow tab](https://console.upstash.com/qstash?tab=workflow) or vercel.com to see your workflow operate.
140
+
141
+ ## Next Steps
142
+
143
+ 1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
144
+
145
+ 2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/nextjs-flask) for a detailed, end-to-end example and best practices.
146
+
147
+ 3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).
@@ -0,0 +1,169 @@
1
+ ---
2
+ title: Upstash Workflow with Nuxt
3
+ sidebarTitle: Nuxt
4
+ ---
5
+
6
+ <Card title="GitHub Repository" icon="github" href="https://github.com/upstash/workflow-js/tree/main/examples/nuxt" horizontal>
7
+ You can find the project source code on GitHub.
8
+ </Card>
9
+ <Card title="Deploy With Vercel" icon="triangle" iconType="sharp-solid" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fupstash%2Fworkflow-js%2Ftree%2Fmain%2Fworkflow%2Fnuxt&env=QSTASH_TOKEN&envDescription=You%20can%20access%20this%20variable%20from%20Upstash%20Console%2C%20under%20QStash%20page.%20&project-name=workflow-nuxt&repository-name=workflow-nuxt&demo-title=Upstash%20Workflow%20Example&demo-description=A%20Nuxt%20application%20utilizing%20Upstash%20Workflow" horizontal>
10
+ Deploy the project to Vercel with a single click.
11
+ </Card>
12
+
13
+ This guide provides detailed, step-by-step instructions on how to use and deploy Upstash Workflow with Nuxt.js. You can also explore our [Nuxt example](https://github.com/upstash/workflow-js/tree/main/examples/nuxt) for a detailed, end-to-end example and best practices.
14
+
15
+ ## Prerequisites
16
+
17
+ 1. An Upstash QStash API key.
18
+ 2. Node.js and npm (another package manager) installed.
19
+
20
+ If you haven't obtained your QStash API key yet, you can do so by [signing up](https://console.upstash.com/auth/sign-in) for an Upstash account and navigating to your QStash dashboard.
21
+
22
+ ## Step 1: Installation
23
+
24
+ First, install the Workflow SDK in your Nuxt project:
25
+
26
+ <Tabs>
27
+ <Tab title="npm">
28
+ ```bash
29
+ npm install @upstash/workflow
30
+ ```
31
+ </Tab>
32
+ <Tab title="pnpm">
33
+ ```bash
34
+ pnpm install @upstash/workflow
35
+ ```
36
+ </Tab>
37
+ <Tab title="bun">
38
+ ```bash
39
+ bun add @upstash/workflow
40
+ ```
41
+ </Tab>
42
+ </Tabs>
43
+
44
+
45
+ ## Step 2: Configure Environment Variables
46
+
47
+ Create a `.env.local` file in your project root and add your QStash token. This token is used to authenticate your application with the QStash service.
48
+
49
+ ```bash Terminal
50
+ touch .env.local
51
+ ```
52
+
53
+ Upstash Workflow is powered by [QStash](/qstash/overall/getstarted), which requires access to your endpoint to execute workflows. When your app is deployed, QStash will use the app's URL. However, for local development, you have two main options: [use a local QStash server or set up a local tunnel](/workflow/howto/local-development/development-server).
54
+
55
+ ### Option 1: Development Server
56
+
57
+ Since you are using `@upstash/workflow`, you can set `QSTASH_DEV=true` in your `.env.local` file. The SDK then downloads and connects to the local QStash development server automatically — no tokens or signing keys to copy over:
58
+
59
+ ```txt .env.local
60
+ QSTASH_DEV=true
61
+ ```
62
+
63
+ Both the workflow client and the `serve()` endpoint pick up the dev server automatically, including signature verification. This lets you test workflows locally without affecting your billing.
64
+
65
+ For ports, the `registerQStashDev()` helper, and other details, see the [Development Server guide](/workflow/howto/local-development/development-server).
66
+
67
+ ### Option 2: Local Tunnel
68
+
69
+ Alternatively, you can set up a local tunnel. For this option:
70
+
71
+ 1. Copy the `QSTASH_TOKEN` from the Upstash Console (see [Get your QStash Token](/workflow/howto/get-token)).
72
+ 2. Update your `.env.local` file with the following:
73
+
74
+ ```txt
75
+ QSTASH_TOKEN="***"
76
+ UPSTASH_WORKFLOW_URL="<UPSTASH_WORKFLOW_URL>"
77
+ ```
78
+
79
+ - Replace `***` with your actual QStash token.
80
+ - Set `UPSTASH_WORKFLOW_URL` to the public URL provided by your local tunnel.
81
+
82
+ Here’s where you can find your QStash token:
83
+
84
+ <Frame>
85
+ <img src="/img/qstash-workflow/console-quickstart-env.jpg" alt="QStash environment variables in the Upstash Console" />
86
+ </Frame>
87
+
88
+ Using a local tunnel connects your endpoint to the production QStash, enabling you to view workflow logs in the Upstash Console.
89
+
90
+ ## Step 3: Create a Workflow Endpoint
91
+
92
+ A workflow endpoint allows you to define a set of steps that, together, make up a workflow. Each step contains a piece of business logic that is automatically retried on failure, with easy monitoring via our visual workflow dashboard.
93
+
94
+ To define a workflow endpoint in a Nuxt.js project, navigate into the Nuxt.js `server/api` directory and create a new file, for example called `workflow.ts`. This file will contain your workflow:
95
+
96
+ ```typescript server/api/workflow.ts
97
+ import { serve } from "@upstash/workflow/h3"
98
+
99
+ const { handler } = serve(
100
+ async (context) => {
101
+ await context.run("initial-step", () => {
102
+ console.log("initial step ran")
103
+ })
104
+
105
+ await context.run("second-step", () => {
106
+ console.log("second step ran")
107
+ })
108
+ },
109
+ )
110
+
111
+ export default handler;
112
+ ```
113
+
114
+ ## Step 4: Run the Workflow Endpoint
115
+
116
+ After defining the endpoint, you can trigger your workflow by starting your app:
117
+
118
+ ```bash Terminal
119
+ npm run dev
120
+ ````
121
+
122
+ Then, make a POST request to your workflow endpoint. For each workflow run, a unique workflow run ID is returned:
123
+
124
+ ```bash Terminal
125
+ curl -X POST https://localhost:3000/api/workflow
126
+
127
+ # result: {"workflowRunId":"wfr_xxxxxx"}
128
+ ```
129
+
130
+ See the [documentation on starting a workflow](/workflow/howto/start) for other ways you can start your workflow.
131
+
132
+ <Frame>
133
+ {/* also works for nuxt */}
134
+ <img src="/img/qstash-workflow/nextjs_local_request.png" alt="Local workflow request" />
135
+ </Frame>
136
+
137
+ If you are using a local tunnel, you can use this ID to track the workflow run and see its status in your QStash workflow dashboard. All steps are listed with their statuses, headers, and body for a detailed overview of your workflow from start to finish. Click on a step to see its detailed logs.
138
+
139
+ <Frame>
140
+ <img src="/img/qstash-workflow/dashboard.png" alt="Workflow run in the Upstash Console" />
141
+ </Frame>
142
+
143
+ ## Step 5: Deploying to Production
144
+
145
+ When deploying your Nuxt.js application with Upstash Workflow to production, there are a few key points to keep in mind:
146
+
147
+ 1. **Environment Variables**: Make sure that all necessary environment variables are set in your platforms project settings. For example, your `QSTASH_TOKEN` and any other configuration variables your workflow might need.
148
+
149
+ 2. **Remove Local Development Settings**: In your production code, you can remove or conditionally exclude any local development settings. For example, if you used [local tunnel for local development](/workflow/howto/local-development/local-tunnel)
150
+
151
+ 3. **Deployment**: Deploy your Nuxt application to Vercel, Cloudflare Pages or other platforms as you normally would. These platforms will automatically detect and build your Nuxt application.
152
+
153
+ 4. **Verify Workflow Endpoint**: After deployment, verify that your workflow endpoint is accessible by making a POST request to your production URL:
154
+
155
+ ```bash Terminal
156
+ curl -X POST https://<YOUR-PRODUCTION-URL>/api/workflow
157
+ ```
158
+
159
+ 5. **Monitor in QStash Dashboard**: Use the QStash dashboard to monitor your production workflows. You can track workflow runs, view step statuses, and access detailed logs.
160
+
161
+ 6. **Set Up Alerts**: Consider setting up alerts in Sentry or other monitoring tools to be notified of any workflow failures in production.
162
+
163
+ ## Next Steps
164
+
165
+ 1. Learn how to protect your workflow endpoint from unauthorized access by [securing your workflow endpoint](/workflow/howto/security).
166
+
167
+ 2. Explore [the source code](https://github.com/upstash/workflow-js/tree/main/examples/nuxt) for a detailed, end-to-end example and best practices.
168
+
169
+ 3. For setting up and testing your workflows in a local environment, check out our [local development guide](/workflow/howto/local-development/development-server).