@upstash/workflow 0.3.0-rc → 0.3.0-rc1
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/astro.d.mts +3 -3
- package/astro.d.ts +3 -3
- package/astro.js +1048 -676
- package/astro.mjs +1 -1
- package/{chunk-AGYYZKP7.mjs → chunk-2Z32SOYM.mjs} +1047 -674
- package/cloudflare.d.mts +3 -3
- package/cloudflare.d.ts +3 -3
- package/cloudflare.js +1048 -676
- package/cloudflare.mjs +1 -1
- package/express.d.mts +3 -3
- package/express.d.ts +3 -3
- package/express.js +1058 -681
- package/express.mjs +11 -6
- package/h3.d.mts +3 -3
- package/h3.d.ts +3 -3
- package/h3.js +1053 -677
- package/h3.mjs +6 -2
- package/hono.d.mts +3 -3
- package/hono.d.ts +3 -3
- package/hono.js +1048 -676
- package/hono.mjs +1 -1
- package/index.d.mts +98 -64
- package/index.d.ts +98 -64
- package/index.js +1079 -697
- package/index.mjs +30 -20
- package/nextjs.d.mts +4 -4
- package/nextjs.d.ts +4 -4
- package/nextjs.js +1049 -677
- package/nextjs.mjs +2 -2
- package/package.json +1 -1
- package/{serve-many-DVtHRxeg.d.ts → serve-many-DhB8-zPD.d.mts} +2 -2
- package/{serve-many-DEwKPF6H.d.mts → serve-many-qnfynN1x.d.ts} +2 -2
- package/solidjs.d.mts +2 -2
- package/solidjs.d.ts +2 -2
- package/solidjs.js +1053 -677
- package/solidjs.mjs +6 -2
- package/svelte.d.mts +5 -6
- package/svelte.d.ts +5 -6
- package/svelte.js +1061 -682
- package/svelte.mjs +14 -7
- package/tanstack.d.mts +3 -3
- package/tanstack.d.ts +3 -3
- package/tanstack.js +1048 -676
- package/tanstack.mjs +1 -1
- package/{types-DESkn7K9.d.ts → types-pEje3VEB.d.mts} +212 -239
- package/{types-DESkn7K9.d.mts → types-pEje3VEB.d.ts} +212 -239
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QstashError, PublishRequest,
|
|
1
|
+
import { QstashError, PublishRequest, HTTPMethods as HTTPMethods$1, FlowControl, Client, Receiver } from '@upstash/qstash';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,23 +8,17 @@ declare class WorkflowError extends QstashError {
|
|
|
8
8
|
constructor(message: string);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Base error for workflow abort scenarios
|
|
12
|
+
* Raised when a workflow step executes successfully.
|
|
13
13
|
*/
|
|
14
14
|
declare class WorkflowAbort extends Error {
|
|
15
|
-
stepInfo?: Step;
|
|
16
15
|
stepName: string;
|
|
16
|
+
stepInfo?: Step;
|
|
17
17
|
/**
|
|
18
|
-
* whether workflow is to be canceled on abort
|
|
19
|
-
*/
|
|
20
|
-
cancelWorkflow: boolean;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
18
|
* @param stepName name of the aborting step
|
|
24
19
|
* @param stepInfo step information
|
|
25
|
-
* @param cancelWorkflow
|
|
26
20
|
*/
|
|
27
|
-
constructor(stepName: string, stepInfo?: Step
|
|
21
|
+
constructor(stepName: string, stepInfo?: Step);
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Raised when the workflow is failed due to a non-retryable error
|
|
@@ -38,35 +32,134 @@ declare class WorkflowNonRetryableError extends WorkflowAbort {
|
|
|
38
32
|
declare class WorkflowRetryAfterError extends WorkflowAbort {
|
|
39
33
|
retryAfter: number | Duration;
|
|
40
34
|
/**
|
|
41
|
-
* @param retryAfter time in seconds after which the workflow should be retried
|
|
42
35
|
* @param message error message to be displayed
|
|
36
|
+
* @param retryAfter time in seconds after which the workflow should be retried
|
|
43
37
|
*/
|
|
44
38
|
constructor(message: string, retryAfter: number | Duration);
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
type
|
|
49
|
-
type
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
type LifeCycleEvent = "beforeExecution" | "afterExecution" | "runStarted" | "runCompleted";
|
|
42
|
+
type DebugEvent = "onError" | "onWarning" | "onInfo";
|
|
43
|
+
type LifeCycleEventParameters<TResult> = {
|
|
44
|
+
beforeExecution: {
|
|
45
|
+
stepName: string;
|
|
46
|
+
};
|
|
47
|
+
afterExecution: {
|
|
48
|
+
stepName: string;
|
|
49
|
+
result: unknown;
|
|
50
|
+
};
|
|
51
|
+
runStarted: {};
|
|
52
|
+
runCompleted: {
|
|
53
|
+
result: TResult;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
type DebugEventParameters = {
|
|
57
|
+
onError: {
|
|
58
|
+
error: Error;
|
|
59
|
+
};
|
|
60
|
+
onWarning: {
|
|
61
|
+
warning: string;
|
|
62
|
+
};
|
|
63
|
+
onInfo: {
|
|
64
|
+
info: string;
|
|
65
|
+
};
|
|
55
66
|
};
|
|
56
|
-
type
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
type MiddlewareCallbacks<TInitialPayload, TResult> = Partial<{
|
|
68
|
+
[K in LifeCycleEvent]: (params: LifeCycleEventParameters<TResult>[K] & {
|
|
69
|
+
context: WorkflowContext<TInitialPayload>;
|
|
70
|
+
}) => Promise<void> | void;
|
|
71
|
+
} & {
|
|
72
|
+
[K in DebugEvent]: (params: DebugEventParameters[K] & {
|
|
73
|
+
workflowRunId?: string;
|
|
74
|
+
}) => Promise<void> | void;
|
|
75
|
+
}>;
|
|
76
|
+
type MiddlewareInitCallbacks<TInitialPayload, TResult> = () => Promise<MiddlewareCallbacks<TInitialPayload, TResult>> | MiddlewareCallbacks<TInitialPayload, TResult>;
|
|
77
|
+
type MiddlewareCallbackConfig<TInitialPayload, TResult> = {
|
|
78
|
+
init: MiddlewareInitCallbacks<TInitialPayload, TResult>;
|
|
79
|
+
} | {
|
|
80
|
+
callbacks: MiddlewareCallbacks<TInitialPayload, TResult>;
|
|
59
81
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
type MiddlewareParameters<TInitialPayload, TResult> = {
|
|
83
|
+
name: string;
|
|
84
|
+
} & MiddlewareCallbackConfig<TInitialPayload, TResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Type for the dispatch debug method that can be passed to helper functions
|
|
87
|
+
* without needing to pass generics everywhere
|
|
88
|
+
*/
|
|
89
|
+
type DispatchDebug = <K extends DebugEvent>(event: K, params: DebugEventParameters[K]) => Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Type for the dispatch lifecycle method
|
|
92
|
+
*/
|
|
93
|
+
type DispatchLifecycle<TResult = unknown> = <K extends LifeCycleEvent>(event: K, params: LifeCycleEventParameters<TResult>[K]) => Promise<void>;
|
|
94
|
+
|
|
95
|
+
declare class WorkflowMiddleware<TInitialPayload = unknown, TResult = unknown> {
|
|
96
|
+
readonly name: string;
|
|
97
|
+
private initCallbacks?;
|
|
98
|
+
/**
|
|
99
|
+
* Callback functions
|
|
100
|
+
*
|
|
101
|
+
* Initially set to undefined, will be populated after init is called
|
|
102
|
+
*/
|
|
103
|
+
private middlewareCallbacks?;
|
|
104
|
+
constructor(parameters: MiddlewareParameters<TInitialPayload, TResult>);
|
|
105
|
+
ensureInit(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Gets a callback function by name.
|
|
108
|
+
*
|
|
109
|
+
* @param callback name of the callback to retrieve
|
|
110
|
+
*/
|
|
111
|
+
getCallback<K extends keyof MiddlewareCallbacks<TInitialPayload, TResult>>(callback: K): MiddlewareCallbacks<TInitialPayload, TResult>[K] | undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* MiddlewareManager - Simplified middleware dispatcher
|
|
116
|
+
*
|
|
117
|
+
* This class manages middleware execution without requiring generics everywhere.
|
|
118
|
+
* Once created, you can export dispatch methods that handle both lifecycle and debug events.
|
|
119
|
+
*/
|
|
120
|
+
declare class MiddlewareManager<TInitialPayload = any, TResult = any> {
|
|
121
|
+
private middlewares;
|
|
122
|
+
private workflowRunId;
|
|
123
|
+
private context;
|
|
124
|
+
/**
|
|
125
|
+
* @param middlewares list of workflow middlewares
|
|
126
|
+
*/
|
|
127
|
+
constructor(middlewares?: WorkflowMiddleware<TInitialPayload, TResult>[]);
|
|
128
|
+
/**
|
|
129
|
+
* Assign workflow run ID - will be passed to debug events
|
|
130
|
+
*
|
|
131
|
+
* @param workflowRunId workflow run id to assign
|
|
132
|
+
*/
|
|
133
|
+
assignWorkflowRunId(workflowRunId: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Assign context - required for lifecycle events
|
|
136
|
+
*
|
|
137
|
+
* also assigns workflowRunId from context
|
|
138
|
+
*
|
|
139
|
+
* @param context workflow context to assign
|
|
140
|
+
*/
|
|
141
|
+
assignContext(context: WorkflowContext<TInitialPayload>): void;
|
|
142
|
+
/**
|
|
143
|
+
* Internal method to execute middlewares with common error handling logic
|
|
144
|
+
*
|
|
145
|
+
* @param event event name to dispatch
|
|
146
|
+
* @param params event parameters
|
|
147
|
+
*/
|
|
148
|
+
private executeMiddlewares;
|
|
149
|
+
/**
|
|
150
|
+
* Dispatch a debug event (onError, onWarning, onInfo)
|
|
151
|
+
*
|
|
152
|
+
* @param event debug event name
|
|
153
|
+
* @param params event parameters
|
|
154
|
+
*/
|
|
155
|
+
dispatchDebug<K extends DebugEvent>(event: K, params: DebugEventParameters[K]): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Dispatch a lifecycle event (beforeExecution, afterExecution, runStarted, runCompleted)
|
|
158
|
+
*
|
|
159
|
+
* @param event lifecycle event name
|
|
160
|
+
* @param params event parameters
|
|
161
|
+
*/
|
|
162
|
+
dispatchLifecycle<K extends LifeCycleEvent>(event: K, params: LifeCycleEventParameters<TResult>[K]): Promise<void>;
|
|
70
163
|
}
|
|
71
164
|
|
|
72
165
|
type HeadersResponse = {
|
|
@@ -94,7 +187,8 @@ declare abstract class BaseLazyStep<TResult = unknown> {
|
|
|
94
187
|
readonly stepName: string;
|
|
95
188
|
abstract readonly stepType: StepType;
|
|
96
189
|
protected abstract readonly allowUndefinedOut: boolean;
|
|
97
|
-
|
|
190
|
+
protected readonly context: WorkflowContext;
|
|
191
|
+
constructor(context: WorkflowContext, stepName: string);
|
|
98
192
|
/**
|
|
99
193
|
* plan step to submit when step will run parallel with other
|
|
100
194
|
* steps (parallel call state `first`)
|
|
@@ -117,11 +211,12 @@ declare abstract class BaseLazyStep<TResult = unknown> {
|
|
|
117
211
|
*
|
|
118
212
|
* will be called when returning the steps to the context from auto executor
|
|
119
213
|
*
|
|
120
|
-
* @param
|
|
214
|
+
* @param step step
|
|
121
215
|
* @returns parsed out field
|
|
122
216
|
*/
|
|
123
|
-
parseOut(
|
|
124
|
-
protected safeParseOut(out: string): TResult;
|
|
217
|
+
parseOut(step: Step): TResult;
|
|
218
|
+
protected safeParseOut(out: string, step: Step): TResult;
|
|
219
|
+
protected handleUndefinedOut(step: Step): TResult;
|
|
125
220
|
protected static tryParsing(stepOut: unknown): any;
|
|
126
221
|
getBody({ step }: GetBodyParams): string;
|
|
127
222
|
getHeaders({ context, telemetry, invokeCount, step }: GetHeaderParams): HeadersResponse;
|
|
@@ -129,21 +224,41 @@ declare abstract class BaseLazyStep<TResult = unknown> {
|
|
|
129
224
|
messageId: string;
|
|
130
225
|
}[]>;
|
|
131
226
|
}
|
|
227
|
+
type Webhook = {
|
|
228
|
+
webhookUrl: string;
|
|
229
|
+
eventId: string;
|
|
230
|
+
};
|
|
231
|
+
type WaitForWebhookResponse = {
|
|
232
|
+
timeout: false;
|
|
233
|
+
request: Request;
|
|
234
|
+
} | {
|
|
235
|
+
timeout: true;
|
|
236
|
+
request: undefined;
|
|
237
|
+
};
|
|
132
238
|
|
|
133
239
|
declare class AutoExecutor {
|
|
134
240
|
private context;
|
|
135
241
|
private promises;
|
|
136
242
|
private activeLazyStepList?;
|
|
137
|
-
private debug?;
|
|
138
243
|
private readonly nonPlanStepCount;
|
|
139
244
|
private readonly steps;
|
|
140
245
|
private indexInCurrentList;
|
|
141
|
-
private invokeCount;
|
|
142
|
-
private telemetry?;
|
|
246
|
+
private readonly invokeCount;
|
|
247
|
+
private readonly telemetry?;
|
|
248
|
+
private readonly dispatchDebug;
|
|
249
|
+
private readonly dispatchLifecycle;
|
|
143
250
|
stepCount: number;
|
|
144
251
|
planStepCount: number;
|
|
145
252
|
protected executingStep: string | false;
|
|
146
|
-
|
|
253
|
+
/**
|
|
254
|
+
* @param context workflow context
|
|
255
|
+
* @param steps list of steps
|
|
256
|
+
* @param dispatchDebug debug event dispatcher
|
|
257
|
+
* @param dispatchLifecycle lifecycle event dispatcher
|
|
258
|
+
* @param telemetry optional telemetry information
|
|
259
|
+
* @param invokeCount optional invoke count
|
|
260
|
+
*/
|
|
261
|
+
constructor(context: WorkflowContext, steps: Step[], dispatchDebug: DispatchDebug, dispatchLifecycle: DispatchLifecycle, telemetry?: Telemetry, invokeCount?: number);
|
|
147
262
|
/**
|
|
148
263
|
* Adds the step function to the list of step functions to run in
|
|
149
264
|
* parallel. After adding the function, defers the execution, so
|
|
@@ -178,7 +293,7 @@ declare class AutoExecutor {
|
|
|
178
293
|
/**
|
|
179
294
|
* Executes a step:
|
|
180
295
|
* - If the step result is available in the steps, returns the result
|
|
181
|
-
* - If the result is not
|
|
296
|
+
* - If the result is not available, runs the function
|
|
182
297
|
* - Sends the result to QStash
|
|
183
298
|
*
|
|
184
299
|
* @param lazyStep lazy step to execute
|
|
@@ -188,8 +303,7 @@ declare class AutoExecutor {
|
|
|
188
303
|
/**
|
|
189
304
|
* Runs steps in parallel.
|
|
190
305
|
*
|
|
191
|
-
* @param
|
|
192
|
-
* @param stepFunctions list of async functions to run in parallel
|
|
306
|
+
* @param parallelSteps list of lazy steps to run in parallel
|
|
193
307
|
* @returns results of the functions run in parallel
|
|
194
308
|
*/
|
|
195
309
|
protected runParallel<TResults extends unknown[]>(parallelSteps: {
|
|
@@ -275,22 +389,27 @@ type LLMOwner = "upstash" | "openai" | "anthropic" | "custom";
|
|
|
275
389
|
* copies and updates the request by removing the api field and adding url & headers.
|
|
276
390
|
*
|
|
277
391
|
* @param api api field of PublishRequest
|
|
278
|
-
* @returns updated request
|
|
392
|
+
* @returns updated request with provider info
|
|
279
393
|
*/
|
|
280
394
|
declare const getProviderInfo: (api: Required<PublishRequest>["api"]) => ProviderInfo;
|
|
281
395
|
|
|
282
|
-
type ApiCallSettings<TBody = unknown, TFields extends object = object> = Omit<CallSettings
|
|
396
|
+
type ApiCallSettings<TBody = unknown, TFields extends object = object> = Omit<CallSettings, "url" | "body"> & {
|
|
397
|
+
body: TBody;
|
|
398
|
+
} & TFields;
|
|
283
399
|
declare abstract class BaseWorkflowApi {
|
|
284
400
|
protected context: WorkflowContext;
|
|
401
|
+
/**
|
|
402
|
+
* @param context workflow context
|
|
403
|
+
*/
|
|
285
404
|
constructor({ context }: {
|
|
286
405
|
context: WorkflowContext;
|
|
287
406
|
});
|
|
288
407
|
/**
|
|
289
408
|
* context.call which uses a QStash API
|
|
290
409
|
*
|
|
291
|
-
* @param stepName
|
|
292
|
-
* @param settings
|
|
293
|
-
* @returns
|
|
410
|
+
* @param stepName name of the step
|
|
411
|
+
* @param settings call settings including api configuration
|
|
412
|
+
* @returns call response
|
|
294
413
|
*/
|
|
295
414
|
protected callApi<TResult = unknown, TBody = unknown>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
296
415
|
api: Parameters<typeof getProviderInfo>[0];
|
|
@@ -506,25 +625,6 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
506
625
|
* ```
|
|
507
626
|
*/
|
|
508
627
|
readonly url: string;
|
|
509
|
-
/**
|
|
510
|
-
* URL to call in case of workflow failure with QStash failure callback
|
|
511
|
-
*
|
|
512
|
-
* https://upstash.com/docs/qstash/features/callbacks#what-is-a-failure-callback
|
|
513
|
-
*
|
|
514
|
-
* Can be overwritten by passing a `failureUrl` parameter in `serve`:
|
|
515
|
-
*
|
|
516
|
-
* ```ts
|
|
517
|
-
* export const POST = serve(
|
|
518
|
-
* async (context) => {
|
|
519
|
-
* ...
|
|
520
|
-
* },
|
|
521
|
-
* {
|
|
522
|
-
* failureUrl: "new-url-value"
|
|
523
|
-
* }
|
|
524
|
-
* )
|
|
525
|
-
* ```
|
|
526
|
-
*/
|
|
527
|
-
readonly failureUrl?: string;
|
|
528
628
|
/**
|
|
529
629
|
* Payload of the request which started the workflow.
|
|
530
630
|
*
|
|
@@ -580,46 +680,6 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
580
680
|
* Default value is set to `process.env`.
|
|
581
681
|
*/
|
|
582
682
|
readonly env: Record<string, string | undefined>;
|
|
583
|
-
/**
|
|
584
|
-
* Number of retries
|
|
585
|
-
*/
|
|
586
|
-
readonly retries: number;
|
|
587
|
-
/**
|
|
588
|
-
* Delay between retries.
|
|
589
|
-
*
|
|
590
|
-
* By default, the `retryDelay` is exponential backoff.
|
|
591
|
-
* More details can be found in: https://upstash.com/docs/qstash/features/retry.
|
|
592
|
-
*
|
|
593
|
-
* The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
|
|
594
|
-
*
|
|
595
|
-
* You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
|
|
596
|
-
* The special variable `retried` represents the current retry attempt count (starting from 0).
|
|
597
|
-
*
|
|
598
|
-
* Supported functions:
|
|
599
|
-
* - `pow`
|
|
600
|
-
* - `sqrt`
|
|
601
|
-
* - `abs`
|
|
602
|
-
* - `exp`
|
|
603
|
-
* - `floor`
|
|
604
|
-
* - `ceil`
|
|
605
|
-
* - `round`
|
|
606
|
-
* - `min`
|
|
607
|
-
* - `max`
|
|
608
|
-
*
|
|
609
|
-
* Examples of valid `retryDelay` values:
|
|
610
|
-
* ```ts
|
|
611
|
-
* 1000 // 1 second
|
|
612
|
-
* 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
|
|
613
|
-
* pow(2, retried) // 2 to the power of the current retry attempt
|
|
614
|
-
* max(10, pow(2, retried)) // The greater of 10 or 2^retried
|
|
615
|
-
* ```
|
|
616
|
-
*/
|
|
617
|
-
readonly retryDelay?: string;
|
|
618
|
-
/**
|
|
619
|
-
* Settings for controlling the number of active requests
|
|
620
|
-
* and number of requests per second with the same key.
|
|
621
|
-
*/
|
|
622
|
-
readonly flowControl?: FlowControl;
|
|
623
683
|
/**
|
|
624
684
|
* Label to apply to the workflow run.
|
|
625
685
|
*
|
|
@@ -636,22 +696,18 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
636
696
|
* ```
|
|
637
697
|
*/
|
|
638
698
|
readonly label?: string;
|
|
639
|
-
constructor({ qstashClient, workflowRunId, headers, steps, url,
|
|
699
|
+
constructor({ qstashClient, workflowRunId, headers, steps, url, initialPayload, env, telemetry, invokeCount, label, middlewareManager, }: {
|
|
640
700
|
qstashClient: WorkflowClient;
|
|
641
701
|
workflowRunId: string;
|
|
642
702
|
headers: Headers;
|
|
643
703
|
steps: Step[];
|
|
644
704
|
url: string;
|
|
645
|
-
failureUrl?: string;
|
|
646
|
-
debug?: WorkflowLogger;
|
|
647
705
|
initialPayload: TInitialPayload;
|
|
648
706
|
env?: Record<string, string | undefined>;
|
|
649
|
-
retries?: number;
|
|
650
|
-
retryDelay?: string;
|
|
651
707
|
telemetry?: Telemetry;
|
|
652
708
|
invokeCount?: number;
|
|
653
|
-
flowControl?: FlowControl;
|
|
654
709
|
label?: string;
|
|
710
|
+
middlewareManager?: MiddlewareManager<TInitialPayload>;
|
|
655
711
|
});
|
|
656
712
|
/**
|
|
657
713
|
* Executes a workflow step
|
|
@@ -739,7 +795,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
739
795
|
* header: Record<string, string[]>
|
|
740
796
|
* }
|
|
741
797
|
*/
|
|
742
|
-
call<TResult = unknown
|
|
798
|
+
call<TResult = unknown>(stepName: string, settings: CallSettings): Promise<CallResponse<TResult>>;
|
|
743
799
|
call<TResult extends {
|
|
744
800
|
workflowRunId: string;
|
|
745
801
|
} = {
|
|
@@ -803,10 +859,12 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
803
859
|
*/
|
|
804
860
|
notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
|
|
805
861
|
invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
|
|
862
|
+
createWebhook(stepName: string): Promise<Webhook>;
|
|
863
|
+
waitForWebhook(stepName: string, webhook: Webhook, timeout: Duration): Promise<WaitForWebhookResponse>;
|
|
806
864
|
/**
|
|
807
865
|
* Cancel the current workflow run
|
|
808
866
|
*
|
|
809
|
-
* Will throw
|
|
867
|
+
* Will throw WorkflowCancelAbort to stop workflow execution.
|
|
810
868
|
* Shouldn't be inside try/catch.
|
|
811
869
|
*/
|
|
812
870
|
cancel(): Promise<void>;
|
|
@@ -838,7 +896,7 @@ type WorkflowClient = {
|
|
|
838
896
|
type WorkflowReceiver = {
|
|
839
897
|
verify: InstanceType<typeof Receiver>["verify"];
|
|
840
898
|
};
|
|
841
|
-
declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke"];
|
|
899
|
+
declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke", "CreateWebhook", "WaitForWebhook"];
|
|
842
900
|
type StepType = (typeof StepTypes)[number];
|
|
843
901
|
type ThirdPartyCallFields<TBody = unknown> = {
|
|
844
902
|
/**
|
|
@@ -922,9 +980,9 @@ type AsyncStepFunction<TResult> = () => Promise<TResult>;
|
|
|
922
980
|
type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
|
|
923
981
|
type ParallelCallState = "first" | "partial" | "discard" | "last";
|
|
924
982
|
type RouteFunction<TInitialPayload, TResult = unknown> = (context: WorkflowContext<TInitialPayload>) => Promise<TResult>;
|
|
925
|
-
type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended" | WorkflowNonRetryableError;
|
|
983
|
+
type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback-executed" | "failure-callback-undefined" | "workflow-already-ended" | WorkflowNonRetryableError;
|
|
926
984
|
type DetailedFinishCondition = {
|
|
927
|
-
condition: Exclude<FinishCondition, WorkflowNonRetryableError | "failure-callback">;
|
|
985
|
+
condition: Exclude<FinishCondition, WorkflowNonRetryableError | "failure-callback-executed">;
|
|
928
986
|
result?: never;
|
|
929
987
|
} | {
|
|
930
988
|
condition: "non-retryable-error";
|
|
@@ -933,35 +991,26 @@ type DetailedFinishCondition = {
|
|
|
933
991
|
condition: "retry-after-error";
|
|
934
992
|
result: WorkflowRetryAfterError;
|
|
935
993
|
} | {
|
|
936
|
-
condition: "failure-callback";
|
|
994
|
+
condition: "failure-callback-executed";
|
|
937
995
|
result: string | void;
|
|
938
996
|
};
|
|
939
|
-
type
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
*/
|
|
943
|
-
qstashClient?: WorkflowClient;
|
|
997
|
+
type WorkflowContextWithoutMethods<TInitialPayload> = Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke" | "createWebhook" | "waitForWebhook">;
|
|
998
|
+
type QStashClientExtraConfig = Omit<NonNullable<ConstructorParameters<typeof Client>[0]>, "baseUrl" | "token">;
|
|
999
|
+
type WorkflowServeOptions<TInitialPayload = unknown, TResult = unknown> = {
|
|
944
1000
|
/**
|
|
945
|
-
*
|
|
1001
|
+
* QStash client or client configuration
|
|
946
1002
|
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
1003
|
+
* Can be either:
|
|
1004
|
+
* - A WorkflowClient instance
|
|
1005
|
+
* - Client configuration options (omitting baseUrl and token, which will be read from env vars)
|
|
949
1006
|
*/
|
|
950
|
-
|
|
1007
|
+
qstashClient?: WorkflowClient | QStashClientExtraConfig;
|
|
951
1008
|
/**
|
|
952
1009
|
* Url of the endpoint where the workflow is set up.
|
|
953
1010
|
*
|
|
954
1011
|
* If not set, url will be inferred from the request.
|
|
955
1012
|
*/
|
|
956
1013
|
url?: string;
|
|
957
|
-
/**
|
|
958
|
-
* Verbose mode
|
|
959
|
-
*
|
|
960
|
-
* Disabled if not set. If set to true, a logger is created automatically.
|
|
961
|
-
*
|
|
962
|
-
* Alternatively, a WorkflowLogger can be passed.
|
|
963
|
-
*/
|
|
964
|
-
verbose?: WorkflowLogger | true;
|
|
965
1014
|
/**
|
|
966
1015
|
* Receiver to verify *all* requests by checking if they come from QStash
|
|
967
1016
|
*
|
|
@@ -969,21 +1018,9 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
969
1018
|
* QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY if they are set.
|
|
970
1019
|
*/
|
|
971
1020
|
receiver?: WorkflowReceiver;
|
|
972
|
-
/**
|
|
973
|
-
* Url to call if QStash retries are exhausted while executing the workflow
|
|
974
|
-
*/
|
|
975
|
-
failureUrl?: string;
|
|
976
|
-
/**
|
|
977
|
-
* Error handler called when an error occurs in the workflow. This is
|
|
978
|
-
* different from `failureFunction` in that it is called when an error
|
|
979
|
-
* occurs in the workflow, while `failureFunction` is called when QStash
|
|
980
|
-
* retries are exhausted.
|
|
981
|
-
*/
|
|
982
|
-
onError?: (error: Error) => void;
|
|
983
1021
|
/**
|
|
984
1022
|
* Failure function called when QStash retries are exhausted while executing
|
|
985
|
-
* the workflow.
|
|
986
|
-
* endpoint if passed.
|
|
1023
|
+
* the workflow.
|
|
987
1024
|
*
|
|
988
1025
|
* @param context workflow context at the moment of error
|
|
989
1026
|
* @param failStatus error status
|
|
@@ -991,7 +1028,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
991
1028
|
* @returns void
|
|
992
1029
|
*/
|
|
993
1030
|
failureFunction?: (failureData: {
|
|
994
|
-
context:
|
|
1031
|
+
context: WorkflowContextWithoutMethods<TInitialPayload>;
|
|
995
1032
|
failStatus: number;
|
|
996
1033
|
failResponse: string;
|
|
997
1034
|
failHeaders: Record<string, string[]>;
|
|
@@ -1017,50 +1054,6 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
1017
1054
|
* Useful in cases like cloudflare with hono.
|
|
1018
1055
|
*/
|
|
1019
1056
|
env?: Record<string, string | undefined>;
|
|
1020
|
-
/**
|
|
1021
|
-
* Number of retries to use in workflow requests
|
|
1022
|
-
*
|
|
1023
|
-
* @default 3
|
|
1024
|
-
*/
|
|
1025
|
-
retries?: number;
|
|
1026
|
-
/**
|
|
1027
|
-
* Delay between retries.
|
|
1028
|
-
*
|
|
1029
|
-
* By default, the `retryDelay` is exponential backoff.
|
|
1030
|
-
* More details can be found in: https://upstash.com/docs/qstash/features/retry.
|
|
1031
|
-
*
|
|
1032
|
-
* The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
|
|
1033
|
-
*
|
|
1034
|
-
* You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
|
|
1035
|
-
* The special variable `retried` represents the current retry attempt count (starting from 0).
|
|
1036
|
-
*
|
|
1037
|
-
* Supported functions:
|
|
1038
|
-
* - `pow`
|
|
1039
|
-
* - `sqrt`
|
|
1040
|
-
* - `abs`
|
|
1041
|
-
* - `exp`
|
|
1042
|
-
* - `floor`
|
|
1043
|
-
* - `ceil`
|
|
1044
|
-
* - `round`
|
|
1045
|
-
* - `min`
|
|
1046
|
-
* - `max`
|
|
1047
|
-
*
|
|
1048
|
-
* Examples of valid `retryDelay` values:
|
|
1049
|
-
* ```ts
|
|
1050
|
-
* 1000 // 1 second
|
|
1051
|
-
* 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
|
|
1052
|
-
* pow(2, retried) // 2 to the power of the current retry attempt
|
|
1053
|
-
* max(10, pow(2, retried)) // The greater of 10 or 2^retried
|
|
1054
|
-
* ```
|
|
1055
|
-
*/
|
|
1056
|
-
retryDelay?: string;
|
|
1057
|
-
/**
|
|
1058
|
-
* Whether the framework should use `content-type: application/json`
|
|
1059
|
-
* in `triggerFirstInvocation`.
|
|
1060
|
-
*
|
|
1061
|
-
* Not part of the public API. Only available in serveBase, which is not exported.
|
|
1062
|
-
*/
|
|
1063
|
-
useJSONContent?: boolean;
|
|
1064
1057
|
/**
|
|
1065
1058
|
* By default, Workflow SDK sends telemetry about SDK version, framework or runtime.
|
|
1066
1059
|
*
|
|
@@ -1070,11 +1063,14 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
1070
1063
|
*/
|
|
1071
1064
|
disableTelemetry?: boolean;
|
|
1072
1065
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
* and number of requests per second with the same key.
|
|
1066
|
+
* List of workflow middlewares to use
|
|
1075
1067
|
*/
|
|
1076
|
-
|
|
1077
|
-
|
|
1068
|
+
middlewares?: WorkflowMiddleware<TInitialPayload, TResult>[];
|
|
1069
|
+
/**
|
|
1070
|
+
* Whether to enable verbose logging for debugging purposes
|
|
1071
|
+
*/
|
|
1072
|
+
verbose?: boolean;
|
|
1073
|
+
} & ExclusiveValidationOptions<TInitialPayload>;
|
|
1078
1074
|
type ValidationOptions<TInitialPayload> = {
|
|
1079
1075
|
schema?: z.ZodType<TInitialPayload>;
|
|
1080
1076
|
initialPayloadParser?: (initialPayload: string) => TInitialPayload;
|
|
@@ -1100,7 +1096,6 @@ type Telemetry = {
|
|
|
1100
1096
|
*/
|
|
1101
1097
|
runtime?: string;
|
|
1102
1098
|
};
|
|
1103
|
-
type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent" | "schema" | "initialPayloadParser"> & ExclusiveValidationOptions<TInitialPayload>;
|
|
1104
1099
|
/**
|
|
1105
1100
|
* Payload passed as body in failureFunction
|
|
1106
1101
|
*/
|
|
@@ -1190,29 +1185,15 @@ interface WaitEventOptions {
|
|
|
1190
1185
|
*/
|
|
1191
1186
|
timeout?: number | Duration;
|
|
1192
1187
|
}
|
|
1193
|
-
type
|
|
1194
|
-
type CallSettings<TBody = unknown> = {
|
|
1188
|
+
type CallSettings = {
|
|
1195
1189
|
url: string;
|
|
1196
1190
|
method?: HTTPMethods$1;
|
|
1197
|
-
|
|
1198
|
-
* Request body.
|
|
1199
|
-
*
|
|
1200
|
-
* By default, the body is stringified with `JSON.stringify`. If you want
|
|
1201
|
-
* to send a string body without stringifying it, you need to set
|
|
1202
|
-
* `stringifyBody` to false.
|
|
1203
|
-
*/
|
|
1204
|
-
body?: TBody;
|
|
1191
|
+
body?: string;
|
|
1205
1192
|
headers?: Record<string, string>;
|
|
1206
1193
|
retries?: number;
|
|
1207
1194
|
retryDelay?: string;
|
|
1208
1195
|
timeout?: Duration | number;
|
|
1209
1196
|
flowControl?: FlowControl;
|
|
1210
|
-
/**
|
|
1211
|
-
* Whether the body field should be stringified when making the request.
|
|
1212
|
-
*
|
|
1213
|
-
* @default true
|
|
1214
|
-
*/
|
|
1215
|
-
stringifyBody?: StringifyBody<TBody>;
|
|
1216
1197
|
};
|
|
1217
1198
|
type HeaderParams = {
|
|
1218
1199
|
/**
|
|
@@ -1231,18 +1212,6 @@ type HeaderParams = {
|
|
|
1231
1212
|
* user headers which will be forwarded in the request
|
|
1232
1213
|
*/
|
|
1233
1214
|
userHeaders?: Headers;
|
|
1234
|
-
/**
|
|
1235
|
-
* failure url to call incase of failure
|
|
1236
|
-
*/
|
|
1237
|
-
failureUrl?: WorkflowServeOptions["failureUrl"];
|
|
1238
|
-
/**
|
|
1239
|
-
* retry setting of requests except context.call
|
|
1240
|
-
*/
|
|
1241
|
-
retries?: number;
|
|
1242
|
-
/**
|
|
1243
|
-
* retry delay to include in headers.
|
|
1244
|
-
*/
|
|
1245
|
-
retryDelay?: string;
|
|
1246
1215
|
/**
|
|
1247
1216
|
* telemetry to include in timeoutHeaders.
|
|
1248
1217
|
*
|
|
@@ -1253,11 +1222,6 @@ type HeaderParams = {
|
|
|
1253
1222
|
* invoke count to include in headers
|
|
1254
1223
|
*/
|
|
1255
1224
|
invokeCount?: number;
|
|
1256
|
-
/**
|
|
1257
|
-
* Settings for controlling the number of active requests
|
|
1258
|
-
* and number of requests per second with the same key.
|
|
1259
|
-
*/
|
|
1260
|
-
flowControl?: FlowControl;
|
|
1261
1225
|
} & ({
|
|
1262
1226
|
/**
|
|
1263
1227
|
* step to generate headers for
|
|
@@ -1319,13 +1283,16 @@ type InvokeWorkflowRequest = {
|
|
|
1319
1283
|
workflowRunId: string;
|
|
1320
1284
|
headers: Record<string, string[]>;
|
|
1321
1285
|
step: Step;
|
|
1322
|
-
body
|
|
1286
|
+
body?: string;
|
|
1323
1287
|
};
|
|
1324
1288
|
type LazyInvokeStepParams<TInitiaPayload, TResult> = {
|
|
1325
|
-
workflow:
|
|
1326
|
-
body: TInitiaPayload;
|
|
1289
|
+
workflow: InvokableWorkflow<TInitiaPayload, TResult>;
|
|
1327
1290
|
workflowRunId?: string;
|
|
1328
|
-
} & Pick<CallSettings
|
|
1291
|
+
} & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay"> & (TInitiaPayload extends undefined ? {
|
|
1292
|
+
body?: undefined;
|
|
1293
|
+
} : {
|
|
1294
|
+
body: TInitiaPayload;
|
|
1295
|
+
});
|
|
1329
1296
|
type InvokeStepResponse<TBody> = {
|
|
1330
1297
|
body: TBody;
|
|
1331
1298
|
isCanceled?: boolean;
|
|
@@ -1333,8 +1300,14 @@ type InvokeStepResponse<TBody> = {
|
|
|
1333
1300
|
};
|
|
1334
1301
|
type InvokableWorkflow<TInitialPayload, TResult> = {
|
|
1335
1302
|
routeFunction: RouteFunction<TInitialPayload, TResult>;
|
|
1336
|
-
options: WorkflowServeOptions<
|
|
1303
|
+
options: WorkflowServeOptions<TInitialPayload, TResult>;
|
|
1337
1304
|
workflowId?: string;
|
|
1305
|
+
/**
|
|
1306
|
+
* whether the invoked workflow should use JSON content type for initial trigger
|
|
1307
|
+
*
|
|
1308
|
+
* this is set by platform createWorkflow helpers and is not part of public serve options
|
|
1309
|
+
*/
|
|
1310
|
+
useJSONContent?: boolean;
|
|
1338
1311
|
};
|
|
1339
1312
|
|
|
1340
|
-
export { type AsyncStepFunction as A, type
|
|
1313
|
+
export { type AsyncStepFunction as A, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type QStashClientExtraConfig as Q, type RawStep as R, type StepType as S, type Telemetry as T, WorkflowMiddleware as W, type WorkflowClient as a, type WorkflowReceiver as b, type RouteFunction as c, type WorkflowServeOptions as d, type Waiter as e, WorkflowError as f, WorkflowAbort as g, WorkflowNonRetryableError as h, WorkflowRetryAfterError as i, WorkflowContext as j, StepTypes as k, type Step as l, type SyncStepFunction as m, type StepFunction as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type Duration as t, type WaitEventOptions as u, type CallSettings as v, type InvokeStepResponse as w, type InvokableWorkflow as x };
|