@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,331 @@
1
+ ---
2
+ title: "General"
3
+ sidebarTitle: "General"
4
+ ---
5
+
6
+ ## Running Steps Inside try/catch Blocks
7
+
8
+ When running steps (run, sleep, call, or any other step) inside a try/catch block, you'll encounter the following error:
9
+
10
+ ```
11
+ WorkflowAbort: This is an Upstash Workflow error thrown after
12
+ a step executes. It is expected to be raised. Make sure that
13
+ you await for each step. Also, if you are using try/catch
14
+ blocks, you should not wrap context.run/sleep/sleepUntil/call
15
+ methods with try/catch. Aborting workflow after executing
16
+ step 'some-step'.
17
+ ```
18
+
19
+ The `WorkflowAbort` error is thrown by the Workflow SDK when a step executes successfully. When you run a step inside a try/catch block, you have two primary options:
20
+
21
+ 1. **Re-throw WorkflowAbort**: If you need a try/catch block, re-throw the `WorkflowAbort` error:
22
+
23
+ 2. **Avoid Running Steps in try/catch**: The simplest solution is to not wrap steps in try/catch blocks. If you have a `context.run` inside try/catch, you can try putting the try/catch inside the context.run.
24
+
25
+ <CodeGroup>
26
+
27
+ ```typescript TypeScript {1, 6-7}
28
+ import { WorkflowAbort } from '@upstash/workflow';
29
+
30
+ try {
31
+ await context.run( ... );
32
+ } catch (error) {
33
+ if (error instanceof WorkflowAbort) {
34
+ throw error;
35
+ } else {
36
+ // handle other errors
37
+ }
38
+ }
39
+ ```
40
+
41
+ ``` python Python {1, 6-7}
42
+ from upstash_workflow import WorkflowAbort
43
+
44
+ try:
45
+ await context.run( ... )
46
+ except Exception as e:
47
+ if isinstance(e, WorkflowAbort):
48
+ raise e
49
+ else:
50
+ # handle other errors
51
+
52
+ ```
53
+
54
+ </CodeGroup>
55
+
56
+ ## `context.requestPayload` Becoming Undefined
57
+
58
+ ### Headers Considerations
59
+
60
+ In some frameworks, you may need to pass specific headers for the workflow to access `requestPayload`:
61
+
62
+ - Try passing `Content-type: text/plain` or `Content-type: application/json` headers when starting the workflow.
63
+ - Note that `publishJSON` can only publish `Content-type: application/json`.
64
+
65
+ ### `context.call` Execution
66
+
67
+ [During a workflow run, the endpoint will be called multiple times](/workflow/basics/how). While executing `context.call`, the endpoint is called at least twice, with the SDK attempting to run the route function until the first step for custom authorization.
68
+
69
+ Accessing `context.requestPayload` before any step can result in it becoming undefined:
70
+
71
+ <CodeGroup>
72
+
73
+ ```typescript TypeScript {2-4, 8}
74
+ export const { POST } = serve(async (context) => {
75
+ // Will print undefined while executing context.call
76
+ const payload = context.requestPayload
77
+ console.log(payload)
78
+
79
+ // ... steps or any other code
80
+
81
+ context.call( ... )
82
+ })
83
+ ```
84
+
85
+ ``` python Python {3-5, 9}
86
+ @serve.post("/api/example")
87
+ async def example(context: AsyncWorkflowContext[str]) -> None:
88
+ # Will print None while executing context.call
89
+ payload = context.request_payload
90
+ print(payload)
91
+
92
+ # ... steps or any other code
93
+
94
+ context.call( ... )
95
+
96
+ ```
97
+
98
+ </CodeGroup>
99
+
100
+ This behavior stems from the internal mechanics of `context.call`, and resolving this specific interaction is on our roadmap. Note that if you are passing `context.requestPayload` as a parameter to `context.call`, the payload remains intact. However, during the actual execution of `context.call`, the `context.requestPayload` becomes undefined due to the SDK's internal workflow processing steps.
101
+
102
+ To fix this issue, you can try adding a step which returns the payload:
103
+
104
+ <CodeGroup>
105
+
106
+ ```typescript TypeScript {2-4, 7}
107
+ export const { POST } = serve(async (context) => {
108
+ // Payload will never be undefined
109
+ const payload = await context.run("get payload", () => context.requestPayload)
110
+
111
+ // ... steps or any other code
112
+
113
+ context.call( ... )
114
+ })
115
+ ```
116
+
117
+ ``` python Python {4-8, 12}
118
+ @serve.post("/api/example")
119
+ async def example(context: AsyncWorkflowContext[str]) -> None:
120
+
121
+ async def _get_payload() -> str:
122
+ return context.request_payload
123
+
124
+ # Payload will never be None
125
+ payload = await context.run("get payload", _get_payload)
126
+
127
+ # ... steps or any other code
128
+
129
+ context.call( ... )
130
+
131
+ ```
132
+
133
+ </CodeGroup>
134
+
135
+ You can find an example of this usage in [our documentation on usage with AI SDK](/workflow/integrations/aisdk).
136
+
137
+ ## Verification Failed Scenarios
138
+
139
+ When [QStash signature verification](/workflow/howto/security#built-in-request-verification-recommended) is enabled, you might encounter an error like:
140
+
141
+ ```
142
+ Failed to verify that the Workflow request comes from QStash: some-error
143
+
144
+ If signature is missing, trigger the workflow endpoint by publishing your request to QStash instead of calling it directly.
145
+
146
+ If you want to disable QStash Verification, you should clear env variables QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY
147
+ ```
148
+
149
+ Troubleshooting verification errors:
150
+
151
+ - Ensure you [start the workflow using `client.trigger` or by publishing to QStash](/workflow/howto/start).
152
+ - Verify that `QSTASH_CURRENT_SIGNING_KEY` and `QSTASH_NEXT_SIGNING_KEY` environment variables are correct.
153
+ - Pass [appropriate `Content-type` headers](/workflow/troubleshooting/general#headers-considerations) when starting the workflow.
154
+
155
+ ## Authorization Error Handling
156
+
157
+ Consider this workflow:
158
+
159
+ <CodeGroup>
160
+
161
+ ```typescript TypeScript {2-5}
162
+ export const { POST } = serve(async (context) => {
163
+
164
+ if (someCondition()) => {
165
+ return;
166
+ }
167
+
168
+ // rest of the workflow
169
+ })
170
+ ```
171
+
172
+ ``` python Python {3-4}
173
+ @serve.post("/api/example")
174
+ async def example(context: AsyncWorkflowContext[str]) -> None:
175
+ if some_condition():
176
+ return
177
+
178
+ # rest of the workflow
179
+
180
+ ```
181
+
182
+ </CodeGroup>
183
+
184
+ Returning before running any steps will result in:
185
+ - HTTP status: 400
186
+ - Error message: `Failed to authenticate Workflow request.`
187
+
188
+
189
+ This behavior is a direct result of the [custom authorization mechanism](/workflow/howto/security#custom-authorization-method). The Workflow SDK interprets an early function return without executing any steps as an authentication failure.
190
+
191
+ If the function `someCondition()` is non-deterministic, the recommended approach is to transform this condition into an explicit workflow step. Here's the recommended pattern for handling such non-deterministic conditions:
192
+
193
+ <CodeGroup>
194
+
195
+ ```typescript TypeScript {3-6}
196
+ export const { POST } = serve(async (context) => {
197
+
198
+ const shouldReturn = await context.run("check condition", () => someCondition())
199
+ if (shouldReturn) => {
200
+ return;
201
+ }
202
+
203
+ // rest of the workflow
204
+ })
205
+ ```
206
+
207
+ ``` python Python {4-9}
208
+ @serve.post("/api/example")
209
+ async def example(context: AsyncWorkflowContext[str]) -> None:
210
+
211
+ async def _check_condition() -> bool:
212
+ return some_condition()
213
+
214
+ should_return = await context.run("check condition", _check_condition)
215
+ if should_return:
216
+ return
217
+
218
+ # rest of the workflow
219
+
220
+ ```
221
+
222
+ </CodeGroup>
223
+
224
+ ## Retry Configuration
225
+
226
+ Retry settings can be configured in two locations:
227
+
228
+ 1. [**Workflow Start** (client.trigger)](/workflow/howto/start): For the triggered workflow run
229
+ - Default retries: 3
230
+
231
+ 2. [**Context Call**](/workflow/steps/call): For third party requests
232
+ - Default retries: 0
233
+
234
+ ## Verbose Mode Diagnostics
235
+
236
+ <Note>
237
+ This feature is not yet available in
238
+ [workflow-py](https://github.com/upstash/workflow-py). See our
239
+ [Roadmap](/workflow/roadmap) for feature parity plans and
240
+ [Changelog](/workflow/changelog) for updates.
241
+ </Note>
242
+
243
+ Use [verbose mode](/workflow/basics/serve/advanced#param-verbose) to diagnose workflow issues.
244
+
245
+ The logs in this section should be seen very rarely. If you observe these logs consistently, you can reach out to our support.
246
+
247
+ ### Localhost in URL Warning
248
+
249
+ ```
250
+ Workflow URL contains localhost. This can happen in local development,
251
+ but shouldn't happen in production unless you have a route which contains
252
+ localhost. Received: ...
253
+ ```
254
+
255
+ This error indicates that the workflow URL has localhost. Publish requests will fail and workflow won't be able to run.
256
+
257
+ **Potential Solutions:**
258
+ - Verify [baseUrl](/workflow/basics/serve/advanced#param-base-url)
259
+ - Check UPSTASH_WORKFLOW_URL
260
+ - Explicitly pass the full [url](/workflow/basics/serve/advanced#param-url)
261
+
262
+ ### Deduplication Log
263
+ Since QStash has at least once delivery guarantee, there is a very small chance that a step will run twice. This is why we suggest [idempotancy](/workflow/basics/best-practices/idempotency). When this happens, the duplicate step should print the following log and terminate:
264
+
265
+ ```
266
+ Upstash Workflow: The step 'some-step' with id 'step-index' has run twice during workflow execution. Rest of the workflow will continue running as usual.
267
+ ```
268
+
269
+ ### Network Issue Warnings
270
+
271
+ In rare instances, the workflow endpoint may complete its task successfully but fail to send a proper response. The SDK is designed to detect such occurrences. When this happens, the workflow endpoint will return a `200` status code and log one of the following three warnings:
272
+
273
+ ```
274
+ Workflow run wfr-*** already exists. A new one isn't created.
275
+ tried to append to a cancelled workflow. exiting without publishing.
276
+ Failed to remove workflow run wfr-*** as it doesn't exist.
277
+ ```
278
+
279
+ A similar issue can occur if you have two parallel context.call steps at the end of your workflow. While the workflow will execute successfully, you may see this warnings:
280
+
281
+ ```
282
+ Couldn't fetch workflow run steps. This can happen if the workflow run successfully ends before some callback is executed.
283
+ ```
284
+
285
+ ## HTTPS Protocol Issue
286
+
287
+ The Workflow SDK automatically infers the protocol (HTTP or HTTPS) based on the incoming request object in your application.
288
+
289
+ However, if your app is deployed behind a proxy (e.g., Railway or similar platforms), the proxy may terminate SSL and forward the request to your app using plain HTTP.
290
+ This can cause the SDK to mistakenly infer that the request is using HTTP instead of HTTPS.
291
+
292
+ To fix this, explicitly set the `UPSTASH_WORKFLOW_URL` environment variable to the base URL of your application.
293
+ This disables automatic protocol inference and uses the provided static URL instead.
294
+
295
+ If you’re using Express.js behind a front-facing proxy, an alternative solution is to enable [proxy trust](https://expressjs.com/en/api.html#app.set) so Express correctly identifies the original protocol from the X-Forwarded-Proto header:
296
+
297
+ ```javascript
298
+ app.set("trust proxy", true)
299
+ ```
300
+
301
+ ## Workflow Stuck in First Step
302
+
303
+ Imagine that you trigger your workflow with [client.trigger](/workflow/basics/client/trigger) and the workflow starts (you see the run in the dashboard), but it doesn't proceed beyond the first step.
304
+
305
+ If it appears like the initial step has failed:
306
+ - Expand the step in the dashboard to see detailed logs to check for any error messages or stack traces that can provide insights into what went wrong.
307
+ - Ensure that the workflow endpoint is accessible. You can test by sending a `curl` request to see if the request lands on the endpoint.
308
+ - Ensure that the URL you passed to the `client.trigger` method matches the workflow endpoint URL.
309
+ - Verify that you're using the latest SDK version both in the workflow endpoint definition and in the code that calls `client.trigger`.
310
+
311
+ If it appears like the initial step has completed but the workflow is still stuck:
312
+ - Workflow SDK could be unable to correctly infer the workflow URL due to a proxy or an issue in the request object. To check if this is the issue, try passing the [`baseUrl` parameter to the `serve` method](/workflow/basics/serve/advanced#param-base-url). This will override the automatic URL inference and use the provided base URL instead.
313
+
314
+ ## Non-workflow Destination Error
315
+
316
+ Full error:
317
+
318
+ ```
319
+ detected a non-workflow destination for trigger/invoke.
320
+ make sure you are sending the request to the correct endpoint
321
+ ```
322
+
323
+ This error occurs when you call a non-workflow endpoint with `client.trigger` or via Request Builder on Upstash Console. If you check Upstash Console, you will see that the workflow run has started but failed before running any steps:
324
+
325
+ <img src="/img/workflow/non-workflow-endpoint-log.png" alt="Log for a request to a non-Workflow endpoint" />
326
+
327
+ Another way you can encounter this error is if you are calling a workflow endpoint on an older SDK version (before 0.2.17 in TypeScript and 0.1.4 in Python) from a newer SDK version. If this happens, in the logs, you will see that the first step of the workflow run has completed successfully, but the workflow fails immediately after that with the same error.
328
+
329
+ To fix this error, ensure that:
330
+ - You are calling a valid workflow endpoint.
331
+ - Both the caller and the workflow endpoint are using the latest SDK versions.
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: "Vercel"
3
+ sidebarTitle: "Vercel"
4
+ ---
5
+
6
+ # Common Issues and Solutions
7
+
8
+ ### Preview Deployment Protection
9
+
10
+ **Problem:**
11
+ When Deployment Protection setting is enabled on Vercel, it's not possible to trigger and complete a workflow run on a preview deployment.
12
+
13
+ **Solution:**
14
+ Vercel provides a way to bypass this protection by using a bypass secret. To create one, follow these steps:
15
+
16
+ <Steps>
17
+ <Step title="Settings">Go to **Deployment Protection** section under your Vercel project settings.</Step>
18
+
19
+ <Step title="Find related section">
20
+ Click on **Add Secret** under **Protection Bypass for Automation** section.
21
+ <Frame>
22
+ <img src="/img/workflow/troubleshooting/vercel-deployment-protection.png" alt="Vercel deployment protection settings" />
23
+ </Frame>
24
+ </Step>
25
+
26
+ <Step title="Generate a bypass token">Don't forget to save it and store it as an environment variable (e.g., `VERCEL_AUTOMATION_BYPASS_SECRET`).</Step>
27
+ </Steps>
28
+
29
+ Now that you have a bypass token, you need to pass it as a header in two places to bypass deployment protection.
30
+
31
+ ## Using the Bypass Secret
32
+
33
+ ### Step 1: Configure QStash Client with Headers
34
+
35
+ [Configure the QStash client](/workflow/basics/serve/advanced#param-qstash-client) with the bypass header in your workflow serve options. This ensures that all workflow steps, including `context.invoke` calls, will include the bypass header automatically:
36
+
37
+ ```ts
38
+ import { Client } from '@upstash/qstash'
39
+ import { serve } from '@upstash/workflow/nextjs'
40
+
41
+ export const { POST } = serve<string>(async (context) => {
42
+ // your workflow logic
43
+ }, {
44
+ qstashClient: new Client({
45
+ token: process.env.QSTASH_TOKEN!,
46
+ headers: {
47
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET!
48
+ }
49
+ })
50
+ })
51
+ ```
52
+
53
+ ### Step 2: Pass Header When Triggering
54
+
55
+ When [triggering the workflow](/workflow/howto/start) using `curl` or `client.trigger`, you must also pass the bypass secret as a header:
56
+
57
+ <CodeGroup>
58
+ ```ts client.trigger
59
+ import { Client } from "@upstash/workflow";
60
+
61
+ const client = new Client({ token: "<QSTASH_TOKEN>" })
62
+
63
+ await client.trigger({
64
+ url: "https://vercel-preview.com/workflow",
65
+ headers: {
66
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET!
67
+ },
68
+ body: "Hello world!"
69
+ })
70
+ ```
71
+
72
+ ```bash cURL
73
+ curl -X POST \
74
+ 'https://vercel-preview.com/workflow' \
75
+ -H 'x-vercel-protection-bypass: <PROTECTION_BYPASS_SECRET>' \
76
+ -d 'Hello world!'
77
+ ```
78
+ </CodeGroup>
79
+
80
+ <Warning>
81
+ Note that you should apply both of the steps above. The header must be passed when triggering the workflow AND configured in the QStash client for subsequent workflow steps to work properly.
82
+ </Warning>
package/express.d.mts CHANGED
@@ -1,12 +1,29 @@
1
1
  import * as express_serve_static_core from 'express-serve-static-core';
2
- import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CekOpKvz.mjs';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CrgK5P6p.mjs';
3
3
  import { Router } from 'express';
4
- import { s as serveManyBase } from './serve-many-CG3BFvO3.mjs';
4
+ import { s as serveManyBase } from './serve-many-BKukvLNl.mjs';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
+ import 'neverthrow';
7
8
 
9
+ /**
10
+ * Code outside steps runs again on every request of the run. Anything it branches on or
11
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
12
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
13
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
14
+ * result.
15
+ *
16
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
17
+ * @see node_modules/@upstash/workflow/docs/quickstarts/express.mdx
18
+ */
8
19
  declare function serve<TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>): Router;
20
+ /**
21
+ * @see node_modules/@upstash/workflow/docs/features/invoke.mdx
22
+ */
9
23
  declare const createWorkflow: <TInitialPayload, TResult>(...params: Parameters<typeof serve<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
24
+ /**
25
+ * @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
26
+ */
10
27
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => express_serve_static_core.Router;
11
28
 
12
29
  export { createWorkflow, serve, serveMany };
package/express.d.ts CHANGED
@@ -1,12 +1,29 @@
1
1
  import * as express_serve_static_core from 'express-serve-static-core';
2
- import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CekOpKvz.js';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CrgK5P6p.js';
3
3
  import { Router } from 'express';
4
- import { s as serveManyBase } from './serve-many-iJF1IUXk.js';
4
+ import { s as serveManyBase } from './serve-many-CrLKQpuZ.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
+ import 'neverthrow';
7
8
 
9
+ /**
10
+ * Code outside steps runs again on every request of the run. Anything it branches on or
11
+ * returns early on (Date.now(), database rows, random values) must give the same answer on
12
+ * every request, or later requests fail with "Incompatible step name" or "Failed to
13
+ * authenticate Workflow request". Read such values inside `context.run` and branch on its
14
+ * result.
15
+ *
16
+ * @see node_modules/@upstash/workflow/docs/basics/serve.mdx
17
+ * @see node_modules/@upstash/workflow/docs/quickstarts/express.mdx
18
+ */
8
19
  declare function serve<TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>): Router;
20
+ /**
21
+ * @see node_modules/@upstash/workflow/docs/features/invoke.mdx
22
+ */
9
23
  declare const createWorkflow: <TInitialPayload, TResult>(...params: Parameters<typeof serve<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
24
+ /**
25
+ * @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
26
+ */
10
27
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => express_serve_static_core.Router;
11
28
 
12
29
  export { createWorkflow, serve, serveMany };