@upstash/workflow 1.2.0 → 1.3.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 (51) hide show
  1. package/README.md +10 -0
  2. package/astro.d.mts +2 -2
  3. package/astro.d.ts +2 -2
  4. package/astro.js +31 -5
  5. package/astro.mjs +1 -1
  6. package/{chunk-V5ZUHMAF.mjs → chunk-G24J5PCC.mjs} +93 -5
  7. package/cloudflare.d.mts +2 -2
  8. package/cloudflare.d.ts +2 -2
  9. package/cloudflare.js +31 -5
  10. package/cloudflare.mjs +1 -1
  11. package/express.d.mts +2 -2
  12. package/express.d.ts +2 -2
  13. package/express.js +31 -5
  14. package/express.mjs +1 -1
  15. package/h3.d.mts +2 -2
  16. package/h3.d.ts +2 -2
  17. package/h3.js +31 -5
  18. package/h3.mjs +1 -1
  19. package/hono.d.mts +2 -2
  20. package/hono.d.ts +2 -2
  21. package/hono.js +31 -5
  22. package/hono.mjs +1 -1
  23. package/index.d.mts +201 -128
  24. package/index.d.ts +201 -128
  25. package/index.js +212 -160
  26. package/index.mjs +124 -156
  27. package/nextjs.d.mts +2 -2
  28. package/nextjs.d.ts +2 -2
  29. package/nextjs.js +31 -5
  30. package/nextjs.mjs +1 -1
  31. package/package.json +1 -1
  32. package/react-router.d.mts +2 -2
  33. package/react-router.d.ts +2 -2
  34. package/react-router.js +31 -5
  35. package/react-router.mjs +1 -1
  36. package/{serve-many-C6sa_DxN.d.mts → serve-many-D3D9uE4u.d.mts} +1 -1
  37. package/{serve-many-B-fe7bh7.d.ts → serve-many-kPOasiyb.d.ts} +1 -1
  38. package/solidjs.d.mts +1 -1
  39. package/solidjs.d.ts +1 -1
  40. package/solidjs.js +31 -5
  41. package/solidjs.mjs +1 -1
  42. package/svelte.d.mts +2 -2
  43. package/svelte.d.ts +2 -2
  44. package/svelte.js +31 -5
  45. package/svelte.mjs +1 -1
  46. package/tanstack.d.mts +2 -2
  47. package/tanstack.d.ts +2 -2
  48. package/tanstack.js +31 -5
  49. package/tanstack.mjs +1 -1
  50. package/{types-B2S08hRU.d.ts → types-B_E1VAK6.d.mts} +9 -1
  51. package/{types-B2S08hRU.d.mts → types-B_E1VAK6.d.ts} +9 -1
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as StepType, R as RawStep, W as WorkflowMiddleware, a as WorkflowClient, b as WorkflowReceiver, c as RouteFunction, d as WorkflowServeOptions, T as Telemetry, N as NotifyResponse, e as Waiter } from './types-B2S08hRU.js';
2
- export { A as AsyncStepFunction, C as CallResponse, f as CallSettings, D as DetailedFinishCondition, g as Duration, E as ExclusiveValidationOptions, F as FailureFunctionPayload, h as FinishCondition, H as HeaderParams, I as InvokableWorkflow, i as InvokeStepResponse, j as InvokeWorkflowRequest, L as LazyInvokeStepParams, k as NotifyStepResponse, P as ParallelCallState, Q as QStashClientExtraConfig, l as RequiredExceptFields, m as Step, n as StepFunction, o as StepTypes, p as SyncStepFunction, q as WaitEventOptions, r as WaitRequest, s as WaitStepResponse, t as WorkflowAbort, u as WorkflowContext, v as WorkflowError, w as WorkflowNonRetryableError, x as WorkflowRetryAfterError } from './types-B2S08hRU.js';
1
+ import { S as StepType, R as RawStep, W as WorkflowMiddleware, a as WorkflowClient, b as WorkflowReceiver, c as RouteFunction, d as WorkflowServeOptions, T as Telemetry, N as NotifyResponse, e as Waiter } from './types-B_E1VAK6.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, f as CallSettings, D as DetailedFinishCondition, g as Duration, E as ExclusiveValidationOptions, F as FailureFunctionPayload, h as FinishCondition, H as HeaderParams, I as InvokableWorkflow, i as InvokeStepResponse, j as InvokeWorkflowRequest, L as LazyInvokeStepParams, k as NotifyStepResponse, P as ParallelCallState, Q as QStashClientExtraConfig, l as RequiredExceptFields, m as Step, n as StepFunction, o as StepTypes, p as SyncStepFunction, q as WaitEventOptions, r as WaitRequest, s as WaitStepResponse, t as WorkflowAbort, u as WorkflowContext, v as WorkflowError, w as WorkflowNonRetryableError, x as WorkflowRetryAfterError } from './types-B_E1VAK6.js';
3
3
  import { FlowControl, PublishRequest, HTTPMethods, Client as Client$1 } from '@upstash/qstash';
4
4
  import 'zod';
5
5
 
@@ -431,6 +431,7 @@ type TriggerOptions = {
431
431
  header?: true | string[];
432
432
  };
433
433
  };
434
+ /** @deprecated Use `resume(dlqId)` or `resume([dlqId1, dlqId2])` instead of `resume({ dlqId })` */
434
435
  type DLQResumeRestartOptions<TDLQId extends string | string[] = string | string[]> = {
435
436
  dlqId: TDLQId;
436
437
  } & Pick<TriggerOptions, "flowControl" | "retries">;
@@ -517,12 +518,116 @@ declare const serveBase: <TInitialPayload = unknown, TRequest extends Request =
517
518
  */
518
519
  declare const serve: <TInitialPayload = unknown, TRequest extends Request = Request, TResponse extends Response = Response, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => ReturnType<typeof serveBase<TInitialPayload, TRequest, TResponse, TResult>>;
519
520
 
520
- type QStashDLQFilterOptions = NonNullable<Required<Parameters<Client$1["dlq"]["listMessages"]>[0]>>["filter"];
521
- type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "url" | "responseStatus"> & {
522
- workflowRunId?: string;
523
- workflowCreatedAt?: string;
524
- failureFunctionState?: FailureCallbackInfo["state"];
521
+ type RequireAtLeastOne<T> = {
522
+ [K in keyof T]-?: Required<Pick<T, K>>;
523
+ }[keyof T];
524
+ /** Shared filter fields accepted by every qstash & workflow endpoint. */
525
+ type UniversalFilterFields = {
526
+ fromDate?: Date | number;
527
+ toDate?: Date | number;
528
+ callerIp?: string;
525
529
  label?: string;
530
+ flowControlKey?: string;
531
+ };
532
+ /** Workflow-specific filter fields for DLQ and bulk endpoints. */
533
+ type WorkflowFilterFields = {
534
+ workflowUrl?: string;
535
+ workflowRunId?: string;
536
+ workflowCreatedAt?: number;
537
+ failureFunctionState?: string;
538
+ };
539
+ type WorkflowLogsFilterFields = {
540
+ state?: WorkflowRunLog["workflowState"];
541
+ messageId?: string;
542
+ };
543
+ type DLQActionFilterFields = UniversalFilterFields & WorkflowFilterFields;
544
+ /** Cancel filter: exact URL match. Cannot combine with `workflowUrlStartingWith`. */
545
+ type CancelFilterWithExactUrl = UniversalFilterFields & {
546
+ workflowUrl: string;
547
+ workflowUrlStartingWith?: never;
548
+ };
549
+ /** Cancel filter: URL prefix match. Cannot combine with `workflowUrl`. */
550
+ type CancelFilterWithPrefixUrl = UniversalFilterFields & {
551
+ workflowUrlStartingWith: string;
552
+ workflowUrl?: never;
553
+ };
554
+ /** Cancel filter: no URL. Requires at least one other filter field. */
555
+ type CancelFilterWithoutUrl = RequireAtLeastOne<UniversalFilterFields> & {
556
+ workflowUrl?: never;
557
+ workflowUrlStartingWith?: never;
558
+ };
559
+ type CancelFilter = CancelFilterWithExactUrl | CancelFilterWithPrefixUrl | CancelFilterWithoutUrl;
560
+ type WorkflowDLQBulkCount = {
561
+ cursor?: string;
562
+ /**
563
+ * Maximum number of messages to process per call.
564
+ *
565
+ * @default 100
566
+ */
567
+ count?: number;
568
+ };
569
+ /**
570
+ * DLQ bulk actions (resume, restart, delete) support three modes:
571
+ * - By dlqIds (no cursor)
572
+ * - By filter fields (with optional cursor and count)
573
+ * - All (with optional cursor and count)
574
+ */
575
+ type WorkflowDLQActionFilters = {
576
+ dlqIds: string | string[];
577
+ filter?: never;
578
+ all?: never;
579
+ count?: never;
580
+ cursor?: never;
581
+ } | ({
582
+ filter: RequireAtLeastOne<DLQActionFilterFields>;
583
+ dlqIds?: never;
584
+ all?: never;
585
+ } & WorkflowDLQBulkCount) | ({
586
+ all: true;
587
+ dlqIds?: never;
588
+ filter?: never;
589
+ } & WorkflowDLQBulkCount);
590
+ type WorkflowDLQListFilters = UniversalFilterFields & WorkflowFilterFields & {
591
+ /** @deprecated Use `workflowUrl` instead. */
592
+ url?: string;
593
+ /** @deprecated No longer supported in the new API. */
594
+ responseStatus?: number;
595
+ };
596
+ type WorkflowCancelCount = {
597
+ /**
598
+ * Maximum number of workflow runs to cancel per call.
599
+ *
600
+ * @default 100
601
+ */
602
+ count?: number;
603
+ };
604
+ /**
605
+ * We don't accept a single workflowRunId or workflowCreatedAt because there
606
+ * could only be one running workflow with a single wfrid at the same time.
607
+ * So using these do not make sense.
608
+ *
609
+ * Also failureFunctionState is not available.
610
+ * Cancel does not support cursor.
611
+ */
612
+ type WorkflowRunCancelFilters = {
613
+ workflowRunIds: string[];
614
+ filter?: never;
615
+ all?: never;
616
+ count?: never;
617
+ } | ({
618
+ filter: CancelFilter;
619
+ workflowRunIds?: never;
620
+ all?: never;
621
+ } & WorkflowCancelCount) | ({
622
+ all: true;
623
+ workflowRunIds?: never;
624
+ filter?: never;
625
+ } & WorkflowCancelCount);
626
+ type WorkflowLogsListFilters = UniversalFilterFields & Pick<WorkflowFilterFields, "workflowUrl" | "workflowRunId" | "workflowCreatedAt"> & WorkflowLogsFilterFields;
627
+
628
+ type ResumeRestartOptions = {
629
+ flowControl?: FlowControl;
630
+ retries?: number;
526
631
  };
527
632
  type FailureCallbackInfo = {
528
633
  state?: "CALLBACK_FAIL" | "CALLBACK_SUCCESS" | "CALLBACK_INPROGRESS";
@@ -587,7 +692,7 @@ declare class DLQ {
587
692
  list(parameters?: {
588
693
  cursor?: string;
589
694
  count?: number;
590
- filter?: DLQFilterOptions;
695
+ filter?: WorkflowDLQListFilters;
591
696
  }): Promise<{
592
697
  messages: PublicDLQMessage[];
593
698
  cursor?: string;
@@ -601,41 +706,31 @@ declare class DLQ {
601
706
  * If you want to restart the workflow run from the beginning, use
602
707
  * `restart` method instead.
603
708
  *
604
- * Example with a single DLQ ID:
605
- * ```ts
606
- * const response = await client.dlq.resume({
607
- * dlqId: "dlq-12345",
608
- * flowControl: {
609
- * key: "my-flow-control-key",
610
- * value: "my-flow-control-value",
611
- * },
612
- * retries: 3,
613
- * });
709
+ * Can be called with:
710
+ * - A single dlqId: `resume("id")`
711
+ * - An array of dlqIds: `resume(["id1", "id2"])`
712
+ * - A filter object: `resume({ filter: { label: "my-label", fromDate: 1640995200000 } })`
713
+ * - To target all entries: `resume({ all: true })`
614
714
  *
615
- * console.log(response.workflowRunId); // ID of the new workflow run
616
- * ```
715
+ * Processes up to `count` messages per call (defaults to 100).
716
+ * Call in a loop until cursor is undefined to process all:
617
717
  *
618
- * Example with multiple DLQ IDs:
619
718
  * ```ts
620
- * const response = await client.dlq.resume({
621
- * dlqId: ["dlq-12345", "dlq-67890"],
622
- * // other parameters...
623
- * });
624
- * console.log(response[0].workflowRunId); // ID of the first workflow run
625
- * console.log(response[1].workflowRunId); // ID of the second workflow run
719
+ * let cursor: string | undefined;
720
+ * do {
721
+ * const result = await client.dlq.resume({ all: true, count: 100, cursor });
722
+ * cursor = result.cursor;
723
+ * } while (cursor);
626
724
  * ```
627
- *
628
- * if the dlqId is not found, throws an error.
629
- *
630
- * @param dlqId - The ID(s) of the DLQ message(s) to resume.
631
- * @param flowControl - Optional flow control parameters. If not passed, flow
632
- * control of the failing workflow will be used
633
- * @param retries - Optional number of retries to perform if the request fails.
634
- * If not passed, retries settings of the failing workflow will be used.
635
- * @returns run id and creation time of the new workflow run(s).
636
725
  */
637
- resume(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
638
- resume(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
726
+ resume(request: string | string[] | WorkflowDLQActionFilters, options?: ResumeRestartOptions): Promise<{
727
+ cursor?: string;
728
+ workflowRuns: DLQResumeRestartResponse[];
729
+ }>;
730
+ /** @deprecated Use `resume(dlqId)` instead */
731
+ resume(request: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
732
+ /** @deprecated Use `resume([dlqId1, dlqId2])` instead */
733
+ resume(request: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
639
734
  /**
640
735
  * Restarts the workflow run for the given DLQ message(s).
641
736
  *
@@ -645,41 +740,31 @@ declare class DLQ {
645
740
  * If you want to resume the workflow run from where it failed, use
646
741
  * `resume` method instead.
647
742
  *
648
- * Example with a single DLQ ID:
649
- * ```ts
650
- * const response = await client.dlq.restart({
651
- * dlqId: "dlq-12345",
652
- * flowControl: {
653
- * key: "my-flow-control-key",
654
- * value: "my-flow-control-value",
655
- * },
656
- * retries: 3,
657
- * });
743
+ * Can be called with:
744
+ * - A single dlqId: `restart("id")`
745
+ * - An array of dlqIds: `restart(["id1", "id2"])`
746
+ * - A filter object: `restart({ filter: { label: "my-label", fromDate: 1640995200000 } })`
747
+ * - To target all entries: `restart({ all: true })`
658
748
  *
659
- * console.log(response.workflowRunId); // ID of the new workflow run
660
- * ```
749
+ * Processes up to `count` messages per call (defaults to 100).
750
+ * Call in a loop until cursor is undefined to process all:
661
751
  *
662
- * Example with multiple DLQ IDs:
663
752
  * ```ts
664
- * const response = await client.dlq.restart({
665
- * dlqId: ["dlq-12345", "dlq-67890"],
666
- * // other parameters...
667
- * });
668
- * console.log(response[0].workflowRunId); // ID of the first workflow run
669
- * console.log(response[1].workflowRunId); // ID of the second workflow run
753
+ * let cursor: string | undefined;
754
+ * do {
755
+ * const result = await client.dlq.restart({ all: true, count: 100, cursor });
756
+ * cursor = result.cursor;
757
+ * } while (cursor);
670
758
  * ```
671
- *
672
- * if the dlqId is not found, throws an error.
673
- *
674
- * @param dlqId - The ID(s) of the DLQ message(s) to restart.
675
- * @param flowControl - Optional flow control parameters. If not passed, flow
676
- * control of the failing workflow will be used
677
- * @param retries - Optional number of retries to perform if the request fails.
678
- * If not passed, retries settings of the failing workflow will be used.
679
- * @returns run id and creation time of the new workflow run(s).
680
759
  */
681
- restart(parameters: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
682
- restart(parameters: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
760
+ restart(request: string | string[] | WorkflowDLQActionFilters, options?: ResumeRestartOptions): Promise<{
761
+ cursor?: string;
762
+ workflowRuns: DLQResumeRestartResponse[];
763
+ }>;
764
+ /** @deprecated Use `restart(dlqId)` instead */
765
+ restart(request: DLQResumeRestartOptions<string>): Promise<DLQResumeRestartResponse>;
766
+ /** @deprecated Use `restart([dlqId1, dlqId2])` instead */
767
+ restart(request: DLQResumeRestartOptions<string[]>): Promise<DLQResumeRestartResponse[]>;
683
768
  /**
684
769
  * Retry the failure callback of a workflow run whose failureUrl/failureFunction
685
770
  * request has failed.
@@ -691,17 +776,31 @@ declare class DLQ {
691
776
  error?: string;
692
777
  }>;
693
778
  /**
694
- * Handles DLQ options and prepares headers and query parameters.
779
+ * Delete DLQ messages.
695
780
  *
696
- * @param options - DLQ resume/restart options
697
- */
698
- private static handleDLQOptions;
699
- /**
700
- * Converts DLQ ID(s) to query parameter string.
781
+ * Can be called with:
782
+ * - A single dlqId: `delete("id")`
783
+ * - An array of dlqIds: `delete(["id1", "id2"])`
784
+ * - A filter object: `delete({ filter: { label: "my-label", fromDate: 1640995200000 } })`
785
+ * - To target all entries: `delete({ all: true })`
786
+ *
787
+ * Processes up to `count` messages per call (defaults to 100).
788
+ * Call in a loop until cursor is undefined to process all:
701
789
  *
702
- * @param dlqId - Single DLQ ID or array of DLQ IDs
790
+ * ```ts
791
+ * let cursor: string | undefined;
792
+ * do {
793
+ * const result = await client.dlq.delete({ all: true, count: 100, cursor });
794
+ * cursor = result.cursor;
795
+ * } while (cursor);
796
+ * ```
703
797
  */
704
- private static getDlqIdQueryParameter;
798
+ delete(request: string | string[] | WorkflowDLQActionFilters): Promise<{
799
+ cursor?: string;
800
+ deleted: number;
801
+ } & {
802
+ error?: string;
803
+ }>;
705
804
  }
706
805
 
707
806
  type ClientConfig = ConstructorParameters<typeof Client$1>[0];
@@ -718,64 +817,32 @@ declare class Client {
718
817
  private client;
719
818
  constructor(clientConfig: ClientConfig);
720
819
  /**
721
- * Cancel an ongoing workflow
722
- *
723
- * Returns true if workflow is canceled succesfully. Otherwise, throws error.
820
+ * Cancel an ongoing workflow.
724
821
  *
725
- * There are multiple ways you can cancel workflows:
726
- * - pass one or more workflow run ids to cancel them
727
- * - pass a workflow url to cancel all runs starting with this url
728
- * - cancel all pending or active workflow runs
822
+ * Can be called with:
823
+ * - A single workflow run id: `cancel("wfr_123")`
824
+ * - An array of workflow run ids: `cancel(["wfr_123", "wfr_456"])`
825
+ * - By exact URL: `cancel({ filter: { workflowUrl: "https://..." } })`
826
+ * - By URL prefix: `cancel({ filter: { workflowUrlStartingWith: "https://..." } })`
827
+ * - With other filters: `cancel({ filter: { label: "my-label" } })`
828
+ * - To target all: `cancel({ all: true })`
729
829
  *
730
- * ### Cancel a set of workflow runs
830
+ * Cancels up to `count` workflow runs per call (defaults to 100).
731
831
  *
732
832
  * ```ts
733
- * // cancel a single workflow
734
- * await client.cancel({ ids: "<WORKFLOW_RUN_ID>" })
735
- *
736
- * // cancel a set of workflow runs
737
- * await client.cancel({ ids: [
738
- * "<WORKFLOW_RUN_ID_1>",
739
- * "<WORKFLOW_RUN_ID_2>",
740
- * ]})
833
+ * const result = await client.cancel({ all: true, count: 50 });
741
834
  * ```
742
- *
743
- * ### Cancel workflows starting with a url
744
- *
745
- * If you have an endpoint called `https://your-endpoint.com` and you
746
- * want to cancel all workflow runs on it, you can use `urlStartingWith`.
747
- *
748
- * Note that this will cancel workflows in all endpoints under
749
- * `https://your-endpoint.com`.
750
- *
751
- * ```ts
752
- * await client.cancel({ urlStartingWith: "https://your-endpoint.com" })
753
- * ```
754
- *
755
- * ### Cancel *all* workflows
756
- *
757
- * To cancel all pending and currently running workflows, you can
758
- * do it like this:
759
- *
760
- * ```ts
761
- * await client.cancel({ all: true })
762
- * ```
763
- *
764
- * @param ids run id of the workflow to delete
765
- * @param urlStartingWith cancel workflows starting with this url. Will be ignored
766
- * if `ids` parameter is set.
767
- * @param all set to true in order to cancel all workflows. Will be ignored
768
- * if `ids` or `urlStartingWith` parameters are set.
769
- * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
770
835
  */
771
- cancel({ ids, urlStartingWith, all, }: {
836
+ cancel(request: string | string[] | WorkflowRunCancelFilters): Promise<{
837
+ cancelled: number;
838
+ }>;
839
+ /** @deprecated Use `cancel(id)`, `cancel([id1, id2])`, `cancel({ filter: { workflowUrlStartingWith } })` instead. */
840
+ cancel(request: {
772
841
  ids?: string | string[];
773
842
  urlStartingWith?: string;
774
843
  all?: true;
775
844
  }): Promise<{
776
845
  cancelled: number;
777
- } & {
778
- error?: string;
779
846
  }>;
780
847
  /**
781
848
  * Notify a workflow run waiting for an event
@@ -923,13 +990,19 @@ declare class Client {
923
990
  * ```
924
991
  */
925
992
  logs(params?: {
926
- workflowRunId?: WorkflowRunLog["workflowRunId"];
927
993
  cursor?: string;
928
994
  count?: number;
929
- state?: WorkflowRunLog["workflowState"];
930
- workflowUrl?: WorkflowRunLog["workflowUrl"];
931
- workflowCreatedAt?: WorkflowRunLog["workflowRunCreatedAt"];
932
- label?: WorkflowRunLog["label"];
995
+ filter?: WorkflowLogsListFilters;
996
+ /** @deprecated Use `filter.workflowRunId` instead. */
997
+ workflowRunId?: string;
998
+ /** @deprecated Use `filter.state` instead. */
999
+ state?: string;
1000
+ /** @deprecated Use `filter.workflowUrl` instead. */
1001
+ workflowUrl?: string;
1002
+ /** @deprecated Use `filter.label` instead. */
1003
+ label?: string;
1004
+ /** @deprecated Use `filter.workflowCreatedAt` instead. */
1005
+ workflowCreatedAt?: number;
933
1006
  }): Promise<WorkflowRunLogs>;
934
1007
  get dlq(): DLQ;
935
1008
  }