@upstash/workflow 0.2.15 → 0.2.17

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types-Dd-3bPoU.mjs';
2
- export { A as AsyncStepFunction, C as CallResponse, u as CallSettings, D as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, w as InvokableWorkflow, v as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, x as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, t as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, z as WorkflowLogger, y as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types-Dd-3bPoU.mjs';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types--R_3XZXz.mjs';
2
+ export { A as AsyncStepFunction, C as CallResponse, v as CallSettings, D as DetailedFinishCondition, t as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, x as InvokableWorkflow, w as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, y as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, u as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, B as WorkflowLogger, z as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types--R_3XZXz.mjs';
3
3
  import { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1 } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
@@ -64,6 +64,10 @@ type BaseStepLog = {
64
64
  * number of retries for the step
65
65
  */
66
66
  retries: number;
67
+ /**
68
+ * retry delay parameter for the step if it was set
69
+ */
70
+ retryDelay?: string;
67
71
  /**
68
72
  * number of parallel steps
69
73
  *
@@ -163,6 +167,25 @@ type StepLog = BaseStepLog & AsOptional<CallUrlGroup> & AsOptional<CallResponseS
163
167
  }> & AsOptional<{
164
168
  sleepUntil: number;
165
169
  }> & AsOptional<WaitEventGroup>;
170
+ type StepError = {
171
+ /**
172
+ * error message associated with the request
173
+ *
174
+ * example:
175
+ * ```
176
+ * detected a non-workflow destination for trigger/invoke.
177
+ * make sure you are sending the request to the correct endpoint
178
+ * ```
179
+ */
180
+ error: string;
181
+ /**
182
+ * response body returned in the request which resulted in an error
183
+ */
184
+ body: string;
185
+ headers: Record<string, string[]>;
186
+ status: number;
187
+ time: number;
188
+ };
166
189
  type StepLogGroup = {
167
190
  /**
168
191
  * Log which belongs to a single step
@@ -192,15 +215,14 @@ type StepLogGroup = {
192
215
  * retries
193
216
  */
194
217
  retries: number;
218
+ /**
219
+ * retry delay parameter for the step if it was set
220
+ */
221
+ retryDelay?: string;
195
222
  /**
196
223
  * errors which occured in the step
197
224
  */
198
- errors?: {
199
- error: string;
200
- headers: Record<string, string[]>;
201
- status: number;
202
- time: number;
203
- }[];
225
+ errors?: StepError[];
204
226
  }[];
205
227
  /**
206
228
  * Log which belongs to the next step
@@ -236,6 +258,22 @@ type FailureFunctionLog = {
236
258
  * @deprecated use dlqId field of the workflow run itself
237
259
  */
238
260
  dlqId: string;
261
+ /**
262
+ * Errors received while running failure function
263
+ */
264
+ errors?: StepError[];
265
+ /**
266
+ * String body returned from the failure function
267
+ */
268
+ responseBody?: string;
269
+ /**
270
+ * Headers received from the failure function
271
+ */
272
+ responseHeaders?: Record<string, string[]>;
273
+ /**
274
+ * Status code of the response from the failure function
275
+ */
276
+ responseStatus?: number;
239
277
  };
240
278
  type WorkflowRunLog = {
241
279
  /**
@@ -334,6 +372,37 @@ type TriggerOptions = {
334
372
  * @default 3
335
373
  */
336
374
  retries?: number;
375
+ /**
376
+ * Delay between retries.
377
+ *
378
+ * By default, the `retryDelay` is exponential backoff.
379
+ * More details can be found in: https://upstash.com/docs/qstash/features/retry.
380
+ *
381
+ * The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
382
+ *
383
+ * You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
384
+ * The special variable `retried` represents the current retry attempt count (starting from 0).
385
+ *
386
+ * Supported functions:
387
+ * - `pow`
388
+ * - `sqrt`
389
+ * - `abs`
390
+ * - `exp`
391
+ * - `floor`
392
+ * - `ceil`
393
+ * - `round`
394
+ * - `min`
395
+ * - `max`
396
+ *
397
+ * Examples of valid `retryDelay` values:
398
+ * ```ts
399
+ * 1000 // 1 second
400
+ * 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
401
+ * pow(2, retried) // 2 to the power of the current retry attempt
402
+ * max(10, pow(2, retried)) // The greater of 10 or 2^retried
403
+ * ```
404
+ */
405
+ retryDelay?: string;
337
406
  /**
338
407
  * Flow control to use for the workflow run.
339
408
  * If not provided, no flow control will be used.
@@ -383,9 +452,22 @@ type DLQResumeRestartResponse = {
383
452
  };
384
453
 
385
454
  type QStashDLQFilterOptions = NonNullable<Required<Parameters<Client$1["dlq"]["listMessages"]>[0]>>["filter"];
386
- type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus">;
455
+ type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus"> & {
456
+ workflowRunId?: string;
457
+ workflowCreatedAt?: string;
458
+ failureFunctionState?: FailureCallbackInfo["state"];
459
+ };
460
+ type FailureCallbackInfo = {
461
+ state?: "CALLBACK_FAIL" | "CALLBACK_SUCCESS" | "CALLBACK_INPROGRESS";
462
+ responseStatus?: number;
463
+ responseBody?: string;
464
+ responseHeaders?: Record<string, string[]>;
465
+ };
387
466
  type DLQMessage = {
388
467
  messageId: string;
468
+ /**
469
+ * URL of the workflow
470
+ */
389
471
  url: string;
390
472
  method: string;
391
473
  header: Record<string, string[]>;
@@ -401,8 +483,16 @@ type DLQMessage = {
401
483
  responseHeader: Record<string, string[]>;
402
484
  responseBody: string;
403
485
  dlqId: string;
486
+ /**
487
+ * URL of the failure callback
488
+ */
489
+ failureCallback?: string;
490
+ /**
491
+ * status of the failure callback
492
+ */
493
+ failureCallbackInfo?: FailureCallbackInfo;
404
494
  };
405
- type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId">;
495
+ type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId" | "failureCallback" | "failureCallbackInfo">;
406
496
  declare class DLQ {
407
497
  private client;
408
498
  constructor(client: Client$1);
@@ -515,6 +605,16 @@ declare class DLQ {
515
605
  */
516
606
  restart(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
517
607
  restart(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
608
+ /**
609
+ * Retry the failure callback of a workflow run whose failureUrl/failureFunction
610
+ * request has failed.
611
+ *
612
+ * @param dlqId - The ID of the DLQ message to retry.
613
+ * @returns
614
+ */
615
+ retryFailureFunction({ dlqId }: Pick<DLQResumeRestartOptions<string>, "dlqId">): Promise<DLQResumeRestartResponse & {
616
+ error?: string;
617
+ }>;
518
618
  private static handleDLQOptions;
519
619
  private static getDlqIdQueryParameter;
520
620
  }
@@ -640,6 +740,7 @@ declare class Client {
640
740
  * headers: { ... }, // Optional headers
641
741
  * workflowRunId: "my-workflow", // Optional workflow run ID
642
742
  * retries: 3 // Optional retries for the initial request
743
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
643
744
  * });
644
745
  *
645
746
  * console.log(workflowRunId)
@@ -654,6 +755,7 @@ declare class Client {
654
755
  * headers: { ... }, // Optional headers
655
756
  * workflowRunId: "my-workflow", // Optional workflow run ID
656
757
  * retries: 3 // Optional retries for the initial request
758
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
657
759
  * },
658
760
  * {
659
761
  * url: "https://workflow-endpoint-2.com",
@@ -661,6 +763,7 @@ declare class Client {
661
763
  * headers: { ... }, // Optional headers
662
764
  * workflowRunId: "my-workflow-2", // Optional workflow run ID
663
765
  * retries: 5 // Optional retries for the initial request
766
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
664
767
  * },
665
768
  * ]);
666
769
  *
@@ -681,6 +784,7 @@ declare class Client {
681
784
  * with `wfr_`.
682
785
  * @param retries retry to use in the initial request. in the rest of
683
786
  * the workflow, `retries` option of the `serve` will be used.
787
+ * @param retryDelay delay between retries.
684
788
  * @param flowControl Settings for controlling the number of active requests
685
789
  * and number of requests per second with the same key.
686
790
  * @param delay Delay for the workflow run. This is used to delay the
@@ -732,4 +836,4 @@ declare class Client {
732
836
  get dlq(): DLQ;
733
837
  }
734
838
 
735
- export { Client, type DLQResumeRestartOptions, type DLQResumeRestartResponse, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
839
+ export { Client, type DLQResumeRestartOptions, type DLQResumeRestartResponse, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, type StepError, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types-Dd-3bPoU.js';
2
- export { A as AsyncStepFunction, C as CallResponse, u as CallSettings, D as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, w as InvokableWorkflow, v as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, x as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, t as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, z as WorkflowLogger, y as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types-Dd-3bPoU.js';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types--R_3XZXz.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, v as CallSettings, D as DetailedFinishCondition, t as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, x as InvokableWorkflow, w as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, y as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, u as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, B as WorkflowLogger, z as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types--R_3XZXz.js';
3
3
  import { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1 } from '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
@@ -64,6 +64,10 @@ type BaseStepLog = {
64
64
  * number of retries for the step
65
65
  */
66
66
  retries: number;
67
+ /**
68
+ * retry delay parameter for the step if it was set
69
+ */
70
+ retryDelay?: string;
67
71
  /**
68
72
  * number of parallel steps
69
73
  *
@@ -163,6 +167,25 @@ type StepLog = BaseStepLog & AsOptional<CallUrlGroup> & AsOptional<CallResponseS
163
167
  }> & AsOptional<{
164
168
  sleepUntil: number;
165
169
  }> & AsOptional<WaitEventGroup>;
170
+ type StepError = {
171
+ /**
172
+ * error message associated with the request
173
+ *
174
+ * example:
175
+ * ```
176
+ * detected a non-workflow destination for trigger/invoke.
177
+ * make sure you are sending the request to the correct endpoint
178
+ * ```
179
+ */
180
+ error: string;
181
+ /**
182
+ * response body returned in the request which resulted in an error
183
+ */
184
+ body: string;
185
+ headers: Record<string, string[]>;
186
+ status: number;
187
+ time: number;
188
+ };
166
189
  type StepLogGroup = {
167
190
  /**
168
191
  * Log which belongs to a single step
@@ -192,15 +215,14 @@ type StepLogGroup = {
192
215
  * retries
193
216
  */
194
217
  retries: number;
218
+ /**
219
+ * retry delay parameter for the step if it was set
220
+ */
221
+ retryDelay?: string;
195
222
  /**
196
223
  * errors which occured in the step
197
224
  */
198
- errors?: {
199
- error: string;
200
- headers: Record<string, string[]>;
201
- status: number;
202
- time: number;
203
- }[];
225
+ errors?: StepError[];
204
226
  }[];
205
227
  /**
206
228
  * Log which belongs to the next step
@@ -236,6 +258,22 @@ type FailureFunctionLog = {
236
258
  * @deprecated use dlqId field of the workflow run itself
237
259
  */
238
260
  dlqId: string;
261
+ /**
262
+ * Errors received while running failure function
263
+ */
264
+ errors?: StepError[];
265
+ /**
266
+ * String body returned from the failure function
267
+ */
268
+ responseBody?: string;
269
+ /**
270
+ * Headers received from the failure function
271
+ */
272
+ responseHeaders?: Record<string, string[]>;
273
+ /**
274
+ * Status code of the response from the failure function
275
+ */
276
+ responseStatus?: number;
239
277
  };
240
278
  type WorkflowRunLog = {
241
279
  /**
@@ -334,6 +372,37 @@ type TriggerOptions = {
334
372
  * @default 3
335
373
  */
336
374
  retries?: number;
375
+ /**
376
+ * Delay between retries.
377
+ *
378
+ * By default, the `retryDelay` is exponential backoff.
379
+ * More details can be found in: https://upstash.com/docs/qstash/features/retry.
380
+ *
381
+ * The `retryDelay` option allows you to customize the delay (in milliseconds) between retry attempts when message delivery fails.
382
+ *
383
+ * You can use mathematical expressions and the following built-in functions to calculate the delay dynamically.
384
+ * The special variable `retried` represents the current retry attempt count (starting from 0).
385
+ *
386
+ * Supported functions:
387
+ * - `pow`
388
+ * - `sqrt`
389
+ * - `abs`
390
+ * - `exp`
391
+ * - `floor`
392
+ * - `ceil`
393
+ * - `round`
394
+ * - `min`
395
+ * - `max`
396
+ *
397
+ * Examples of valid `retryDelay` values:
398
+ * ```ts
399
+ * 1000 // 1 second
400
+ * 1000 * (1 + retried) // 1 second multiplied by the current retry attempt
401
+ * pow(2, retried) // 2 to the power of the current retry attempt
402
+ * max(10, pow(2, retried)) // The greater of 10 or 2^retried
403
+ * ```
404
+ */
405
+ retryDelay?: string;
337
406
  /**
338
407
  * Flow control to use for the workflow run.
339
408
  * If not provided, no flow control will be used.
@@ -383,9 +452,22 @@ type DLQResumeRestartResponse = {
383
452
  };
384
453
 
385
454
  type QStashDLQFilterOptions = NonNullable<Required<Parameters<Client$1["dlq"]["listMessages"]>[0]>>["filter"];
386
- type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus">;
455
+ type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus"> & {
456
+ workflowRunId?: string;
457
+ workflowCreatedAt?: string;
458
+ failureFunctionState?: FailureCallbackInfo["state"];
459
+ };
460
+ type FailureCallbackInfo = {
461
+ state?: "CALLBACK_FAIL" | "CALLBACK_SUCCESS" | "CALLBACK_INPROGRESS";
462
+ responseStatus?: number;
463
+ responseBody?: string;
464
+ responseHeaders?: Record<string, string[]>;
465
+ };
387
466
  type DLQMessage = {
388
467
  messageId: string;
468
+ /**
469
+ * URL of the workflow
470
+ */
389
471
  url: string;
390
472
  method: string;
391
473
  header: Record<string, string[]>;
@@ -401,8 +483,16 @@ type DLQMessage = {
401
483
  responseHeader: Record<string, string[]>;
402
484
  responseBody: string;
403
485
  dlqId: string;
486
+ /**
487
+ * URL of the failure callback
488
+ */
489
+ failureCallback?: string;
490
+ /**
491
+ * status of the failure callback
492
+ */
493
+ failureCallbackInfo?: FailureCallbackInfo;
404
494
  };
405
- type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId">;
495
+ type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId" | "failureCallback" | "failureCallbackInfo">;
406
496
  declare class DLQ {
407
497
  private client;
408
498
  constructor(client: Client$1);
@@ -515,6 +605,16 @@ declare class DLQ {
515
605
  */
516
606
  restart(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
517
607
  restart(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
608
+ /**
609
+ * Retry the failure callback of a workflow run whose failureUrl/failureFunction
610
+ * request has failed.
611
+ *
612
+ * @param dlqId - The ID of the DLQ message to retry.
613
+ * @returns
614
+ */
615
+ retryFailureFunction({ dlqId }: Pick<DLQResumeRestartOptions<string>, "dlqId">): Promise<DLQResumeRestartResponse & {
616
+ error?: string;
617
+ }>;
518
618
  private static handleDLQOptions;
519
619
  private static getDlqIdQueryParameter;
520
620
  }
@@ -640,6 +740,7 @@ declare class Client {
640
740
  * headers: { ... }, // Optional headers
641
741
  * workflowRunId: "my-workflow", // Optional workflow run ID
642
742
  * retries: 3 // Optional retries for the initial request
743
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
643
744
  * });
644
745
  *
645
746
  * console.log(workflowRunId)
@@ -654,6 +755,7 @@ declare class Client {
654
755
  * headers: { ... }, // Optional headers
655
756
  * workflowRunId: "my-workflow", // Optional workflow run ID
656
757
  * retries: 3 // Optional retries for the initial request
758
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
657
759
  * },
658
760
  * {
659
761
  * url: "https://workflow-endpoint-2.com",
@@ -661,6 +763,7 @@ declare class Client {
661
763
  * headers: { ... }, // Optional headers
662
764
  * workflowRunId: "my-workflow-2", // Optional workflow run ID
663
765
  * retries: 5 // Optional retries for the initial request
766
+ * retryDelay: "1000" // Optional retry delay for the delay between retries
664
767
  * },
665
768
  * ]);
666
769
  *
@@ -681,6 +784,7 @@ declare class Client {
681
784
  * with `wfr_`.
682
785
  * @param retries retry to use in the initial request. in the rest of
683
786
  * the workflow, `retries` option of the `serve` will be used.
787
+ * @param retryDelay delay between retries.
684
788
  * @param flowControl Settings for controlling the number of active requests
685
789
  * and number of requests per second with the same key.
686
790
  * @param delay Delay for the workflow run. This is used to delay the
@@ -732,4 +836,4 @@ declare class Client {
732
836
  get dlq(): DLQ;
733
837
  }
734
838
 
735
- export { Client, type DLQResumeRestartOptions, type DLQResumeRestartResponse, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };
839
+ export { Client, type DLQResumeRestartOptions, type DLQResumeRestartResponse, ExclusiveValidationOptions, NotifyResponse, RawStep, RouteFunction, type StepError, type StepLog, StepType, Telemetry, type TriggerOptions, Waiter, type WorkflowRunLog, type WorkflowRunLogs, WorkflowServeOptions, serve };