@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.
- package/README.md +9 -0
- package/astro.d.mts +19 -2
- package/astro.d.ts +19 -2
- package/astro.js +670 -159
- package/astro.mjs +1 -1
- package/{chunk-DRHEHWMS.mjs → chunk-J3PXPHSB.mjs} +828 -317
- package/cloudflare.d.mts +17 -2
- package/cloudflare.d.ts +17 -2
- package/cloudflare.js +670 -159
- package/cloudflare.mjs +1 -1
- package/docs/agents/examples.mdx +8 -0
- package/docs/agents/features.mdx +374 -0
- package/docs/agents/getting-started.mdx +139 -0
- package/docs/agents/overview.mdx +40 -0
- package/docs/agents/patterns/evaluator-optimizer.mdx +72 -0
- package/docs/agents/patterns/orchestrator-workers.mdx +95 -0
- package/docs/agents/patterns/parallelization.mdx +77 -0
- package/docs/agents/patterns/prompt-chaining.mdx +84 -0
- package/docs/basics/best-practices/at-least-one-step.mdx +57 -0
- package/docs/basics/best-practices/business-logic-in-steps.mdx +52 -0
- package/docs/basics/best-practices/deterministic-code.mdx +132 -0
- package/docs/basics/best-practices/idempotency.mdx +38 -0
- package/docs/basics/best-practices/nested-context-methods.mdx +38 -0
- package/docs/basics/best-practices/overview.mdx +35 -0
- package/docs/basics/best-practices/promise-any.mdx +9 -0
- package/docs/basics/best-practices/return-step-results.mdx +80 -0
- package/docs/basics/best-practices/workflow-limits.mdx +62 -0
- package/docs/basics/client/cancel.mdx +137 -0
- package/docs/basics/client/dlq/callback.mdx +21 -0
- package/docs/basics/client/dlq/delete.mdx +120 -0
- package/docs/basics/client/dlq/list.mdx +96 -0
- package/docs/basics/client/dlq/restart.mdx +164 -0
- package/docs/basics/client/dlq/resume.mdx +167 -0
- package/docs/basics/client/logs.mdx +139 -0
- package/docs/basics/client/notify.mdx +79 -0
- package/docs/basics/client/trigger.mdx +139 -0
- package/docs/basics/client/waiters.mdx +31 -0
- package/docs/basics/client.mdx +40 -0
- package/docs/basics/how.mdx +65 -0
- package/docs/basics/serve/advanced.mdx +435 -0
- package/docs/basics/serve.mdx +142 -0
- package/docs/changelog.mdx +174 -0
- package/docs/examples/allInOne.mdx +377 -0
- package/docs/examples/authWebhook.mdx +567 -0
- package/docs/examples/customRetry.mdx +309 -0
- package/docs/examples/customerOnboarding.mdx +230 -0
- package/docs/examples/dynamicWorkflow.mdx +203 -0
- package/docs/examples/eCommerceOrderFulfillment.mdx +281 -0
- package/docs/examples/imageProcessing.mdx +339 -0
- package/docs/examples/paymentRetry.mdx +438 -0
- package/docs/examples/waitForEvent.mdx +201 -0
- package/docs/features/dlq/callback.mdx +42 -0
- package/docs/features/dlq/delete.mdx +29 -0
- package/docs/features/dlq/restart.mdx +33 -0
- package/docs/features/dlq/resume.mdx +37 -0
- package/docs/features/dlq.mdx +39 -0
- package/docs/features/failure-callback.mdx +102 -0
- package/docs/features/failureFunction/advanced.mdx +36 -0
- package/docs/features/failureFunction/reliability.mdx +33 -0
- package/docs/features/flow-control/monitor.mdx +22 -0
- package/docs/features/flow-control/parallelism.mdx +45 -0
- package/docs/features/flow-control/rate-period.mdx +46 -0
- package/docs/features/flow-control.mdx +164 -0
- package/docs/features/invoke/serveMany.mdx +109 -0
- package/docs/features/invoke.mdx +39 -0
- package/docs/features/notify.mdx +127 -0
- package/docs/features/parallel-steps.mdx +41 -0
- package/docs/features/retries/prevent-retries.mdx +140 -0
- package/docs/features/retries.mdx +93 -0
- package/docs/features/wait-for-event.mdx +104 -0
- package/docs/features/wait.mdx +44 -0
- package/docs/features/webhooks.mdx +116 -0
- package/docs/getstarted.mdx +200 -0
- package/docs/howto/cancel.mdx +50 -0
- package/docs/howto/changes.mdx +33 -0
- package/docs/howto/configure.mdx +42 -0
- package/docs/howto/failures.mdx +185 -0
- package/docs/howto/get-token.mdx +18 -0
- package/docs/howto/local-development/development-server.mdx +130 -0
- package/docs/howto/local-development/local-tunnel.mdx +73 -0
- package/docs/howto/middlewares.mdx +263 -0
- package/docs/howto/migrations.mdx +335 -0
- package/docs/howto/multi-region.mdx +107 -0
- package/docs/howto/parallel-runs.mdx +52 -0
- package/docs/howto/readonly-token.mdx +19 -0
- package/docs/howto/realtime/basic.mdx +315 -0
- package/docs/howto/realtime/human-in-the-loop.mdx +454 -0
- package/docs/howto/redact-fields.mdx +61 -0
- package/docs/howto/retry-now.mdx +41 -0
- package/docs/howto/schedule.mdx +104 -0
- package/docs/howto/security.mdx +143 -0
- package/docs/howto/singleton.mdx +137 -0
- package/docs/howto/start.mdx +69 -0
- package/docs/howto/use-webhooks.mdx +256 -0
- package/docs/integrations/aisdk.mdx +316 -0
- package/docs/integrations/anthropic.mdx +51 -0
- package/docs/integrations/datadog.mdx +69 -0
- package/docs/integrations/openai.mdx +87 -0
- package/docs/integrations/prometheus.mdx +65 -0
- package/docs/integrations/resend.mdx +82 -0
- package/docs/llms-txt.mdx +4 -0
- package/docs/openapi.yaml +2944 -0
- package/docs/pricing.mdx +22 -0
- package/docs/quickstarts/astro.mdx +185 -0
- package/docs/quickstarts/cloudflare-workers.mdx +190 -0
- package/docs/quickstarts/express.mdx +190 -0
- package/docs/quickstarts/fastapi.mdx +282 -0
- package/docs/quickstarts/flask.mdx +282 -0
- package/docs/quickstarts/hono.mdx +221 -0
- package/docs/quickstarts/nextjs-fastapi.mdx +147 -0
- package/docs/quickstarts/nextjs-flask.mdx +147 -0
- package/docs/quickstarts/nuxt.mdx +169 -0
- package/docs/quickstarts/platforms.mdx +78 -0
- package/docs/quickstarts/solidjs.mdx +161 -0
- package/docs/quickstarts/svelte.mdx +170 -0
- package/docs/quickstarts/tanstack-start.mdx +205 -0
- package/docs/quickstarts/vercel-nextjs.mdx +233 -0
- package/docs/roadmap.mdx +8 -0
- package/docs/sdk/workflow-js.mdx +4 -0
- package/docs/sdk/workflow-py.mdx +4 -0
- package/docs/steps/api.mdx +64 -0
- package/docs/steps/call.mdx +183 -0
- package/docs/steps/cancel.mdx +25 -0
- package/docs/steps/createWebhook.mdx +40 -0
- package/docs/steps/invoke.mdx +100 -0
- package/docs/steps/notify.mdx +105 -0
- package/docs/steps/run.mdx +150 -0
- package/docs/steps/sleep.mdx +97 -0
- package/docs/steps/sleepUntil.mdx +88 -0
- package/docs/steps/waitForEvent.mdx +60 -0
- package/docs/steps/waitForWebhook.mdx +78 -0
- package/docs/steps.mdx +108 -0
- package/docs/troubleshooting/general.mdx +331 -0
- package/docs/troubleshooting/vercel.mdx +82 -0
- package/express.d.mts +19 -2
- package/express.d.ts +19 -2
- package/express.js +670 -159
- package/express.mjs +1 -1
- package/h3.d.mts +19 -2
- package/h3.d.ts +19 -2
- package/h3.js +670 -159
- package/h3.mjs +1 -1
- package/hono.d.mts +17 -2
- package/hono.d.ts +17 -2
- package/hono.js +670 -159
- package/hono.mjs +1 -1
- package/index.d.mts +50 -21
- package/index.d.ts +50 -21
- package/index.js +686 -171
- package/index.mjs +17 -13
- package/nextjs.d.mts +40 -2
- package/nextjs.d.ts +40 -2
- package/nextjs.js +670 -159
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +16 -2
- package/react-router.d.ts +16 -2
- package/react-router.js +670 -159
- package/react-router.mjs +1 -1
- package/{serve-many-CG3BFvO3.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
- package/{serve-many-iJF1IUXk.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
- package/solidjs.d.mts +10 -1
- package/solidjs.d.ts +10 -1
- package/solidjs.js +670 -159
- package/solidjs.mjs +1 -1
- package/src/platforms/astro.ts +84 -0
- package/src/platforms/cloudflare.ts +127 -0
- package/src/platforms/express.ts +147 -0
- package/src/platforms/h3.ts +105 -0
- package/src/platforms/hono.ts +103 -0
- package/src/platforms/nextjs.ts +193 -0
- package/src/platforms/react-router.ts +92 -0
- package/src/platforms/solidjs.ts +59 -0
- package/src/platforms/svelte.ts +99 -0
- package/src/platforms/tanstack.ts +96 -0
- package/src/src/client/dlq.ts +387 -0
- package/src/src/client/filter-types.ts +166 -0
- package/src/src/client/index.ts +350 -0
- package/src/src/client/types.ts +501 -0
- package/src/src/client/utils.ts +307 -0
- package/src/src/constants.ts +82 -0
- package/src/src/context/api/anthropic.ts +58 -0
- package/src/src/context/api/base.ts +52 -0
- package/src/src/context/api/index.ts +24 -0
- package/src/src/context/api/openai.ts +125 -0
- package/src/src/context/api/resend.ts +57 -0
- package/src/src/context/auto-executor.ts +707 -0
- package/src/src/context/context.ts +681 -0
- package/src/src/context/index.ts +1 -0
- package/src/src/context/provider.ts +37 -0
- package/src/src/context/steps.ts +965 -0
- package/src/src/error.ts +203 -0
- package/src/src/index.ts +13 -0
- package/src/src/middleware/default-callbacks.ts +20 -0
- package/src/src/middleware/index.ts +2 -0
- package/src/src/middleware/logging.ts +39 -0
- package/src/src/middleware/manager.ts +148 -0
- package/src/src/middleware/middleware.ts +46 -0
- package/src/src/middleware/types.ts +72 -0
- package/src/src/qstash/headers.ts +397 -0
- package/src/src/qstash/step-config.ts +268 -0
- package/src/src/qstash/submit-steps.ts +284 -0
- package/src/src/serve/authorization.ts +118 -0
- package/src/src/serve/index.ts +475 -0
- package/src/src/serve/multi-region/handlers.ts +225 -0
- package/src/src/serve/multi-region/utils.ts +88 -0
- package/src/src/serve/options.ts +241 -0
- package/src/src/serve/serve-many.ts +117 -0
- package/src/src/serve/utils.ts +11 -0
- package/src/src/types.ts +590 -0
- package/src/src/utils.ts +141 -0
- package/src/src/workflow-parser.ts +472 -0
- package/src/src/workflow-requests.ts +575 -0
- package/svelte.d.mts +17 -2
- package/svelte.d.ts +17 -2
- package/svelte.js +670 -159
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +15 -2
- package/tanstack.d.ts +15 -2
- package/tanstack.js +670 -159
- package/tanstack.mjs +1 -1
- package/{types-CekOpKvz.d.ts → types-CrgK5P6p.d.mts} +372 -32
- package/{types-CekOpKvz.d.mts → types-CrgK5P6p.d.ts} +372 -32
package/src/src/types.ts
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import type { FlowControl, Receiver } from "@upstash/qstash";
|
|
2
|
+
import type { Client } from "@upstash/qstash";
|
|
3
|
+
import type { HTTPMethods } from "@upstash/qstash";
|
|
4
|
+
import type { WorkflowContext } from "./context";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { WorkflowNonRetryableError, WorkflowRetryAfterError } from "./error";
|
|
7
|
+
import { WorkflowMiddleware } from "./middleware";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Interface for Client with required methods
|
|
11
|
+
*
|
|
12
|
+
* Neeeded to resolve import issues
|
|
13
|
+
*/
|
|
14
|
+
export type WorkflowClient = {
|
|
15
|
+
batch: InstanceType<typeof Client>["batch"];
|
|
16
|
+
batchJSON: InstanceType<typeof Client>["batchJSON"];
|
|
17
|
+
publishJSON: InstanceType<typeof Client>["publishJSON"];
|
|
18
|
+
publish: InstanceType<typeof Client>["publish"];
|
|
19
|
+
http: InstanceType<typeof Client>["http"];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Interface for Receiver with required methods
|
|
23
|
+
*
|
|
24
|
+
* Neeeded to resolve import issues
|
|
25
|
+
*/
|
|
26
|
+
export type WorkflowReceiver = {
|
|
27
|
+
verify: InstanceType<typeof Receiver>["verify"];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const StepTypes = [
|
|
31
|
+
"Initial",
|
|
32
|
+
"Run",
|
|
33
|
+
"SleepFor",
|
|
34
|
+
"SleepUntil",
|
|
35
|
+
"Call",
|
|
36
|
+
"Wait",
|
|
37
|
+
"Notify",
|
|
38
|
+
"Invoke",
|
|
39
|
+
"CreateWebhook",
|
|
40
|
+
"WaitForWebhook",
|
|
41
|
+
] as const;
|
|
42
|
+
export type StepType = (typeof StepTypes)[number];
|
|
43
|
+
|
|
44
|
+
type ThirdPartyCallFields<TBody = unknown> = {
|
|
45
|
+
/**
|
|
46
|
+
* Third party call URL. Set when context.call is used.
|
|
47
|
+
*/
|
|
48
|
+
callUrl: string;
|
|
49
|
+
/**
|
|
50
|
+
* Third party call method. Set when context.call is used.
|
|
51
|
+
*/
|
|
52
|
+
callMethod: HTTPMethods;
|
|
53
|
+
/**
|
|
54
|
+
* Third party call body. Set when context.call is used.
|
|
55
|
+
*/
|
|
56
|
+
callBody: TBody;
|
|
57
|
+
/**
|
|
58
|
+
* Third party call headers. Set when context.call is used.
|
|
59
|
+
*/
|
|
60
|
+
callHeaders: Record<string, string>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type WaitFields = {
|
|
64
|
+
waitEventId: string;
|
|
65
|
+
timeout: string;
|
|
66
|
+
waitTimeout?: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type NotifyFields = {
|
|
70
|
+
notifyEventId?: string;
|
|
71
|
+
eventData?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type Step<TResult = unknown, TBody = unknown> = {
|
|
75
|
+
/**
|
|
76
|
+
* index of the step
|
|
77
|
+
*/
|
|
78
|
+
stepId: number;
|
|
79
|
+
/**
|
|
80
|
+
* name of the step
|
|
81
|
+
*/
|
|
82
|
+
stepName: string;
|
|
83
|
+
/**
|
|
84
|
+
* type of the step (Initial/Run/SleepFor/SleepUntil/Call)
|
|
85
|
+
*/
|
|
86
|
+
stepType: StepType;
|
|
87
|
+
/**
|
|
88
|
+
* step result. Set if context.run or context.call are used.
|
|
89
|
+
*/
|
|
90
|
+
out?: TResult;
|
|
91
|
+
/**
|
|
92
|
+
* sleep duration in seconds. Set when context.sleep is used.
|
|
93
|
+
*/
|
|
94
|
+
sleepFor?: number | Duration;
|
|
95
|
+
/**
|
|
96
|
+
* unix timestamp (in seconds) to wait until. Set when context.sleepUntil is used.
|
|
97
|
+
*/
|
|
98
|
+
sleepUntil?: number;
|
|
99
|
+
/**
|
|
100
|
+
* number of steps running concurrently if the step is in a parallel run.
|
|
101
|
+
* Set to 1 if step is not parallel.
|
|
102
|
+
*/
|
|
103
|
+
concurrent: number;
|
|
104
|
+
/**
|
|
105
|
+
* target step of a plan step. In other words, the step to assign the
|
|
106
|
+
* result of a plan step.
|
|
107
|
+
*
|
|
108
|
+
* undefined if the step is not a plan step (of a parallel run). Otherwise,
|
|
109
|
+
* set to the target step.
|
|
110
|
+
*/
|
|
111
|
+
targetStep?: number;
|
|
112
|
+
} & (ThirdPartyCallFields<TBody> | { [P in keyof ThirdPartyCallFields]?: never }) &
|
|
113
|
+
(WaitFields | { [P in keyof WaitFields]?: never }) &
|
|
114
|
+
(NotifyFields | { [P in keyof NotifyFields]?: never });
|
|
115
|
+
|
|
116
|
+
export type RawStep = {
|
|
117
|
+
messageId: string;
|
|
118
|
+
body: string; // body is a base64 encoded step or payload
|
|
119
|
+
callType: "step" | "toCallback" | "fromCallback" | "stepConfig";
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type SyncStepFunction<TResult> = () => TResult;
|
|
123
|
+
export type AsyncStepFunction<TResult> = () => Promise<TResult>;
|
|
124
|
+
export type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
|
|
125
|
+
|
|
126
|
+
export type ParallelCallState = "first" | "partial" | "discard" | "last";
|
|
127
|
+
|
|
128
|
+
export type RouteFunction<TInitialPayload, TResult = unknown> = (
|
|
129
|
+
context: WorkflowContext<TInitialPayload>
|
|
130
|
+
) => Promise<TResult>;
|
|
131
|
+
|
|
132
|
+
export type FinishCondition =
|
|
133
|
+
| "success"
|
|
134
|
+
| "duplicate-step"
|
|
135
|
+
| "fromCallback"
|
|
136
|
+
| "auth-fail"
|
|
137
|
+
| "failure-callback-executed"
|
|
138
|
+
| "failure-callback-undefined"
|
|
139
|
+
| "workflow-already-ended"
|
|
140
|
+
| WorkflowNonRetryableError;
|
|
141
|
+
|
|
142
|
+
export type DetailedFinishCondition =
|
|
143
|
+
| {
|
|
144
|
+
condition: Exclude<FinishCondition, WorkflowNonRetryableError | "failure-callback-executed">;
|
|
145
|
+
result?: never;
|
|
146
|
+
}
|
|
147
|
+
| {
|
|
148
|
+
condition: "non-retryable-error";
|
|
149
|
+
result: WorkflowNonRetryableError;
|
|
150
|
+
}
|
|
151
|
+
| {
|
|
152
|
+
condition: "retry-after-error";
|
|
153
|
+
result: WorkflowRetryAfterError;
|
|
154
|
+
}
|
|
155
|
+
| {
|
|
156
|
+
condition: "failure-callback-executed";
|
|
157
|
+
result: string | void;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
type WorkflowContextWithoutMethods<TInitialPayload> = Omit<
|
|
161
|
+
WorkflowContext<TInitialPayload>,
|
|
162
|
+
| "run"
|
|
163
|
+
| "sleepUntil"
|
|
164
|
+
| "sleep"
|
|
165
|
+
| "call"
|
|
166
|
+
| "waitForEvent"
|
|
167
|
+
| "notify"
|
|
168
|
+
| "cancel"
|
|
169
|
+
| "api"
|
|
170
|
+
| "invoke"
|
|
171
|
+
| "createWebhook"
|
|
172
|
+
| "waitForWebhook"
|
|
173
|
+
>;
|
|
174
|
+
|
|
175
|
+
export type QStashClientExtraConfig = Omit<
|
|
176
|
+
NonNullable<ConstructorParameters<typeof Client>[0]>,
|
|
177
|
+
"baseUrl" | "token"
|
|
178
|
+
>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Options of `serve`.
|
|
182
|
+
*
|
|
183
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
|
|
184
|
+
*/
|
|
185
|
+
export type WorkflowServeOptions<TInitialPayload = unknown, TResult = unknown> = {
|
|
186
|
+
/**
|
|
187
|
+
* QStash client or client configuration
|
|
188
|
+
*
|
|
189
|
+
* Can be either:
|
|
190
|
+
* - A WorkflowClient instance
|
|
191
|
+
* - Client configuration options (omitting baseUrl and token, which will be read from env vars)
|
|
192
|
+
*/
|
|
193
|
+
qstashClient?: WorkflowClient | QStashClientExtraConfig;
|
|
194
|
+
/**
|
|
195
|
+
* Url of the endpoint where the workflow is set up.
|
|
196
|
+
*
|
|
197
|
+
* If not set, url will be inferred from the request.
|
|
198
|
+
*/
|
|
199
|
+
url?: string;
|
|
200
|
+
/**
|
|
201
|
+
* Receiver to verify *all* requests by checking if they come from QStash
|
|
202
|
+
*
|
|
203
|
+
* By default, a receiver is created from the env variables
|
|
204
|
+
* QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY if they are set.
|
|
205
|
+
*/
|
|
206
|
+
receiver?: WorkflowReceiver;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Failure function called when QStash retries are exhausted while executing
|
|
210
|
+
* the workflow.
|
|
211
|
+
*
|
|
212
|
+
* @param context workflow context at the moment of error
|
|
213
|
+
* @param failStatus error status
|
|
214
|
+
* @param failResponse error message
|
|
215
|
+
* @returns void
|
|
216
|
+
* @see node_modules/@upstash/workflow/docs/features/failure-callback.mdx
|
|
217
|
+
*/
|
|
218
|
+
failureFunction?: (failureData: {
|
|
219
|
+
context: WorkflowContextWithoutMethods<TInitialPayload>;
|
|
220
|
+
failStatus: number;
|
|
221
|
+
failResponse: string;
|
|
222
|
+
failHeaders: Record<string, string[]>;
|
|
223
|
+
failStack: string;
|
|
224
|
+
}) => Promise<void | string> | void | string;
|
|
225
|
+
/**
|
|
226
|
+
* Base Url of the workflow endpoint
|
|
227
|
+
*
|
|
228
|
+
* Can be used to set if there is a local tunnel or a proxy between
|
|
229
|
+
* QStash and the workflow endpoint.
|
|
230
|
+
*
|
|
231
|
+
* Will be set to the env variable UPSTASH_WORKFLOW_URL if not passed.
|
|
232
|
+
* If the env variable is not set, the url will be infered as usual from
|
|
233
|
+
* the `request.url` or the `url` parameter in `serve` options.
|
|
234
|
+
*
|
|
235
|
+
* @default undefined
|
|
236
|
+
*/
|
|
237
|
+
baseUrl?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Optionally, one can pass an env object mapping environment
|
|
240
|
+
* variables to their keys.
|
|
241
|
+
*
|
|
242
|
+
* Useful in cases like cloudflare with hono.
|
|
243
|
+
*/
|
|
244
|
+
env?: Record<string, string | undefined>;
|
|
245
|
+
/**
|
|
246
|
+
* By default, Workflow SDK sends telemetry about SDK version, framework or runtime.
|
|
247
|
+
*
|
|
248
|
+
* Set `disableTelemetry` to disable this behavior.
|
|
249
|
+
*
|
|
250
|
+
* @default false
|
|
251
|
+
*/
|
|
252
|
+
disableTelemetry?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* List of workflow middlewares to use
|
|
255
|
+
*
|
|
256
|
+
* @see node_modules/@upstash/workflow/docs/howto/middlewares.mdx
|
|
257
|
+
*/
|
|
258
|
+
middlewares?: WorkflowMiddleware<TInitialPayload, TResult>[];
|
|
259
|
+
/**
|
|
260
|
+
* Whether to enable verbose logging for debugging purposes
|
|
261
|
+
*/
|
|
262
|
+
verbose?: boolean;
|
|
263
|
+
} & ExclusiveValidationOptions<TInitialPayload>;
|
|
264
|
+
|
|
265
|
+
type ValidationOptions<TInitialPayload> = {
|
|
266
|
+
schema?: z.ZodType<TInitialPayload>;
|
|
267
|
+
initialPayloadParser?: (initialPayload: string) => TInitialPayload;
|
|
268
|
+
};
|
|
269
|
+
export type ExclusiveValidationOptions<TInitialPayload> =
|
|
270
|
+
| {
|
|
271
|
+
schema?: ValidationOptions<TInitialPayload>["schema"];
|
|
272
|
+
initialPayloadParser?: never;
|
|
273
|
+
}
|
|
274
|
+
| {
|
|
275
|
+
schema?: never;
|
|
276
|
+
initialPayloadParser?: ValidationOptions<TInitialPayload>["initialPayloadParser"];
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
export type Telemetry = {
|
|
280
|
+
/**
|
|
281
|
+
* sdk version
|
|
282
|
+
*/
|
|
283
|
+
sdk: string;
|
|
284
|
+
/**
|
|
285
|
+
* platform (such as nextjs/cloudflare)
|
|
286
|
+
*/
|
|
287
|
+
framework?: string;
|
|
288
|
+
/**
|
|
289
|
+
* node version
|
|
290
|
+
*/
|
|
291
|
+
runtime?: string;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Payload passed as body in failureFunction
|
|
296
|
+
*/
|
|
297
|
+
export type FailureFunctionPayload = {
|
|
298
|
+
/**
|
|
299
|
+
* error name
|
|
300
|
+
*/
|
|
301
|
+
error: string;
|
|
302
|
+
/**
|
|
303
|
+
* error message
|
|
304
|
+
*/
|
|
305
|
+
message: string;
|
|
306
|
+
/**
|
|
307
|
+
* error stack trace if available
|
|
308
|
+
*/
|
|
309
|
+
stack?: string;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Makes all fields except the ones selected required
|
|
314
|
+
*/
|
|
315
|
+
export type RequiredExceptFields<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
|
|
316
|
+
|
|
317
|
+
export type Waiter = {
|
|
318
|
+
url: string;
|
|
319
|
+
deadline: number;
|
|
320
|
+
headers: Record<string, string[]>;
|
|
321
|
+
timeoutUrl?: string;
|
|
322
|
+
timeoutBody?: unknown;
|
|
323
|
+
timeoutHeaders?: Record<string, string[]>;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export type NotifyResponse = {
|
|
327
|
+
waiter: Waiter;
|
|
328
|
+
messageId: string;
|
|
329
|
+
error: string;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export type WaitRequest = {
|
|
333
|
+
url: string;
|
|
334
|
+
step: Step;
|
|
335
|
+
timeout: string;
|
|
336
|
+
timeoutUrl?: string;
|
|
337
|
+
timeoutBody?: string;
|
|
338
|
+
timeoutHeaders?: Record<string, string[]>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export type WaitStepResponse<TEventData = unknown> = {
|
|
342
|
+
/**
|
|
343
|
+
* whether the wait for event step timed out. false if
|
|
344
|
+
* the step is notified
|
|
345
|
+
*/
|
|
346
|
+
timeout: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* body passed in notify request
|
|
349
|
+
*/
|
|
350
|
+
eventData: TEventData;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export type NotifyStepResponse = {
|
|
354
|
+
/**
|
|
355
|
+
* notified event id
|
|
356
|
+
*/
|
|
357
|
+
eventId: string;
|
|
358
|
+
/**
|
|
359
|
+
* event data sent with notify
|
|
360
|
+
*/
|
|
361
|
+
eventData: unknown;
|
|
362
|
+
/**
|
|
363
|
+
* response from notify
|
|
364
|
+
*/
|
|
365
|
+
notifyResponse: NotifyResponse[];
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
export type CallResponse<TResult = unknown> = {
|
|
369
|
+
status: number;
|
|
370
|
+
body: TResult;
|
|
371
|
+
header: Record<string, string[]>;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Valid duration string formats
|
|
376
|
+
* @example "30s" // 30 seconds
|
|
377
|
+
* @example "5m" // 5 minutes
|
|
378
|
+
* @example "2h" // 2 hours
|
|
379
|
+
* @example "1d" // 1 day
|
|
380
|
+
*/
|
|
381
|
+
export type Duration = `${bigint}${"s" | "m" | "h" | "d"}`;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
|
|
385
|
+
*/
|
|
386
|
+
export interface WaitEventOptions {
|
|
387
|
+
/**
|
|
388
|
+
* Duration in seconds to wait for an event before timing out the workflow.
|
|
389
|
+
* @example 300 // 5 minutes in seconds
|
|
390
|
+
* @example "5m" // 5 minutes as duration string
|
|
391
|
+
* @default "7d"
|
|
392
|
+
*/
|
|
393
|
+
timeout?: number | Duration;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Step-level settings which override the workflow run settings
|
|
398
|
+
* passed in `client.trigger` for the execution of a single step.
|
|
399
|
+
*
|
|
400
|
+
* Passed as the third argument of `context.run`:
|
|
401
|
+
*
|
|
402
|
+
* ```ts
|
|
403
|
+
* const result = await context.run(
|
|
404
|
+
* "step",
|
|
405
|
+
* () => { ... },
|
|
406
|
+
* { flowControl: { key: "custom-key", parallelism: 3 }, retries: 5 }
|
|
407
|
+
* );
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* The settings must be applied to the request whose delivery executes
|
|
411
|
+
* the step:
|
|
412
|
+
*
|
|
413
|
+
* - a step running in parallel with others carries its settings on its
|
|
414
|
+
* own plan step, whose delivery is what executes the step. No extra
|
|
415
|
+
* request is made.
|
|
416
|
+
* - otherwise, the SDK can only learn about the step once the workflow
|
|
417
|
+
* function has been replayed, which happens in a delivery that was
|
|
418
|
+
* published before the step was known. So instead of executing the
|
|
419
|
+
* step in that delivery, a hidden request carrying the
|
|
420
|
+
* settings is published and the step executes when QStash delivers it.
|
|
421
|
+
* This costs one extra message and one extra endpoint invocation per
|
|
422
|
+
* step which carries settings. QStash hides the request from the
|
|
423
|
+
* step logs.
|
|
424
|
+
*/
|
|
425
|
+
export type StepSettings = {
|
|
426
|
+
/**
|
|
427
|
+
* Settings for controlling the number of active requests
|
|
428
|
+
* and number of requests per second with the same key
|
|
429
|
+
* while executing this step.
|
|
430
|
+
*
|
|
431
|
+
* Overrides the flow control settings passed when triggering
|
|
432
|
+
* the workflow for this step only.
|
|
433
|
+
*/
|
|
434
|
+
flowControl?: FlowControl;
|
|
435
|
+
/**
|
|
436
|
+
* Number of times QStash will retry the delivery which executes
|
|
437
|
+
* this step.
|
|
438
|
+
*
|
|
439
|
+
* Overrides the retries passed when triggering the workflow for
|
|
440
|
+
* this step only.
|
|
441
|
+
*/
|
|
442
|
+
retries?: number;
|
|
443
|
+
/**
|
|
444
|
+
* Delay between retries of the delivery which executes this step.
|
|
445
|
+
* Leading and trailing whitespace is trimmed. An empty or whitespace-only
|
|
446
|
+
* string leaves the workflow run's retry delay unchanged.
|
|
447
|
+
*/
|
|
448
|
+
retryDelay?: string;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @see node_modules/@upstash/workflow/docs/steps/call.mdx
|
|
453
|
+
*/
|
|
454
|
+
export type CallSettings = {
|
|
455
|
+
url: string;
|
|
456
|
+
method?: HTTPMethods;
|
|
457
|
+
body?: string;
|
|
458
|
+
headers?: Record<string, string>;
|
|
459
|
+
retries?: number;
|
|
460
|
+
retryDelay?: string;
|
|
461
|
+
/**
|
|
462
|
+
* Max time to wait for the endpoint to respond. Pass a duration string such as "10s".
|
|
463
|
+
* A number is sent without a unit and QStash rejects the step ("missing unit in
|
|
464
|
+
* duration"), which stops the run with only a "Tried to append to a cancelled workflow"
|
|
465
|
+
* warning.
|
|
466
|
+
*/
|
|
467
|
+
timeout?: Duration | number;
|
|
468
|
+
flowControl?: FlowControl;
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export type HeaderParams = {
|
|
472
|
+
/**
|
|
473
|
+
* whether the request is a first invocation request.
|
|
474
|
+
*/
|
|
475
|
+
initHeaderValue: "true" | "false";
|
|
476
|
+
/**
|
|
477
|
+
* run id of the workflow
|
|
478
|
+
*/
|
|
479
|
+
workflowRunId: string;
|
|
480
|
+
/**
|
|
481
|
+
* url where the workflow is hosted
|
|
482
|
+
*/
|
|
483
|
+
workflowUrl: string;
|
|
484
|
+
/**
|
|
485
|
+
* user headers which will be forwarded in the request
|
|
486
|
+
*/
|
|
487
|
+
userHeaders?: Headers;
|
|
488
|
+
/**
|
|
489
|
+
* telemetry to include in timeoutHeaders.
|
|
490
|
+
*
|
|
491
|
+
* Only needed/used when the step is a waitForEvent step
|
|
492
|
+
*/
|
|
493
|
+
telemetry?: Telemetry;
|
|
494
|
+
/**
|
|
495
|
+
* invoke count to include in headers
|
|
496
|
+
*/
|
|
497
|
+
invokeCount?: number;
|
|
498
|
+
} & (
|
|
499
|
+
| {
|
|
500
|
+
/**
|
|
501
|
+
* step to generate headers for
|
|
502
|
+
*/
|
|
503
|
+
step: Step;
|
|
504
|
+
/**
|
|
505
|
+
* number of retries in context.call
|
|
506
|
+
*/
|
|
507
|
+
callRetries?: number;
|
|
508
|
+
/**
|
|
509
|
+
* retry delay to include in headers.
|
|
510
|
+
*/
|
|
511
|
+
callRetryDelay?: string;
|
|
512
|
+
/**
|
|
513
|
+
* timeout duration in context.call
|
|
514
|
+
*/
|
|
515
|
+
callTimeout?: number | Duration;
|
|
516
|
+
/**
|
|
517
|
+
* Settings for controlling the number of active requests
|
|
518
|
+
* and number of requests per second with the same key.
|
|
519
|
+
*
|
|
520
|
+
* will be passed in context.call.
|
|
521
|
+
*/
|
|
522
|
+
callFlowControl?: FlowControl;
|
|
523
|
+
}
|
|
524
|
+
| {
|
|
525
|
+
/**
|
|
526
|
+
* step not passed. Either first invocation or simply getting headers for
|
|
527
|
+
* third party callack.
|
|
528
|
+
*/
|
|
529
|
+
step?: never;
|
|
530
|
+
/**
|
|
531
|
+
* number of retries in context.call
|
|
532
|
+
*
|
|
533
|
+
* set to never because this is not a context.call step
|
|
534
|
+
*/
|
|
535
|
+
callRetries?: never;
|
|
536
|
+
/**
|
|
537
|
+
* retry delay to include in headers.
|
|
538
|
+
*
|
|
539
|
+
* set to never because this is not a context.call step
|
|
540
|
+
*/
|
|
541
|
+
callRetryDelay?: never;
|
|
542
|
+
/**
|
|
543
|
+
* timeout duration in context.call
|
|
544
|
+
*
|
|
545
|
+
* set to never because this is not a context.call step
|
|
546
|
+
*/
|
|
547
|
+
callTimeout?: never;
|
|
548
|
+
/**
|
|
549
|
+
* Settings for controlling the number of active requests
|
|
550
|
+
* and number of requests per second with the same key.
|
|
551
|
+
*
|
|
552
|
+
* will be passed in context.call.
|
|
553
|
+
*/
|
|
554
|
+
callFlowControl?: never;
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
export type InvokeWorkflowRequest = {
|
|
559
|
+
workflowUrl: string;
|
|
560
|
+
workflowRunId: string;
|
|
561
|
+
workflowRunCreatedAt: number;
|
|
562
|
+
headers: Record<string, string[]>;
|
|
563
|
+
step: Step;
|
|
564
|
+
body?: string;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
export type LazyInvokeStepParams<TInitiaPayload, TResult> = {
|
|
568
|
+
workflow: InvokableWorkflow<TInitiaPayload, TResult>;
|
|
569
|
+
workflowRunId?: string;
|
|
570
|
+
label?: string | string[];
|
|
571
|
+
} & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay"> &
|
|
572
|
+
(TInitiaPayload extends undefined ? { body?: undefined } : { body: TInitiaPayload });
|
|
573
|
+
|
|
574
|
+
export type InvokeStepResponse<TBody> = {
|
|
575
|
+
body: TBody;
|
|
576
|
+
isCanceled?: boolean;
|
|
577
|
+
isFailed?: boolean;
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
export type InvokableWorkflow<TInitialPayload, TResult> = {
|
|
581
|
+
routeFunction: RouteFunction<TInitialPayload, TResult>;
|
|
582
|
+
options: WorkflowServeOptions<TInitialPayload, TResult>;
|
|
583
|
+
workflowId?: string;
|
|
584
|
+
/**
|
|
585
|
+
* whether the invoked workflow should use JSON content type for initial trigger
|
|
586
|
+
*
|
|
587
|
+
* this is set by platform createWorkflow helpers and is not part of public serve options
|
|
588
|
+
*/
|
|
589
|
+
useJSONContent?: boolean;
|
|
590
|
+
};
|