@upstash/workflow 1.4.0-rc → 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 +18 -2
- package/astro.d.ts +18 -2
- package/astro.js +129 -29
- package/astro.mjs +1 -1
- package/{chunk-UH6O5IJY.mjs → chunk-J3PXPHSB.mjs} +129 -29
- package/cloudflare.d.mts +16 -2
- package/cloudflare.d.ts +16 -2
- package/cloudflare.js +129 -29
- 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 +18 -2
- package/express.d.ts +18 -2
- package/express.js +129 -29
- package/express.mjs +1 -1
- package/h3.d.mts +18 -2
- package/h3.d.ts +18 -2
- package/h3.js +129 -29
- package/h3.mjs +1 -1
- package/hono.d.mts +16 -2
- package/hono.d.ts +16 -2
- package/hono.js +129 -29
- package/hono.mjs +1 -1
- package/index.d.mts +49 -21
- package/index.d.ts +49 -21
- package/index.js +145 -41
- package/index.mjs +17 -13
- package/nextjs.d.mts +39 -2
- package/nextjs.d.ts +39 -2
- package/nextjs.js +129 -29
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +15 -2
- package/react-router.d.ts +15 -2
- package/react-router.js +129 -29
- package/react-router.mjs +1 -1
- package/{serve-many-CbIV7145.d.mts → serve-many-BKukvLNl.d.mts} +1 -1
- package/{serve-many-BCtZg31b.d.ts → serve-many-CrLKQpuZ.d.ts} +1 -1
- package/solidjs.d.mts +9 -1
- package/solidjs.d.ts +9 -1
- package/solidjs.js +129 -29
- 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 +16 -2
- package/svelte.d.ts +16 -2
- package/svelte.js +129 -29
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +14 -2
- package/tanstack.d.ts +14 -2
- package/tanstack.js +129 -29
- package/tanstack.mjs +1 -1
- package/{types-ffLPVG5_.d.ts → types-CrgK5P6p.d.mts} +124 -24
- package/{types-ffLPVG5_.d.mts → types-CrgK5P6p.d.ts} +124 -24
|
@@ -23,6 +23,8 @@ declare class WorkflowAbort extends Error {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Raised when the workflow is failed due to a non-retryable error
|
|
26
|
+
*
|
|
27
|
+
* @see node_modules/@upstash/workflow/docs/features/retries/prevent-retries.mdx
|
|
26
28
|
*/
|
|
27
29
|
declare class WorkflowNonRetryableError extends WorkflowAbort {
|
|
28
30
|
/**
|
|
@@ -93,6 +95,9 @@ type DispatchDebug = <K extends DebugEvent>(event: K, params: DebugEventParamete
|
|
|
93
95
|
*/
|
|
94
96
|
type DispatchLifecycle<TResult = unknown> = <K extends LifeCycleEvent>(event: K, params: LifeCycleEventParameters<TResult>[K]) => Promise<void>;
|
|
95
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @see node_modules/@upstash/workflow/docs/howto/middlewares.mdx
|
|
100
|
+
*/
|
|
96
101
|
declare class WorkflowMiddleware<TInitialPayload = unknown, TResult = unknown> {
|
|
97
102
|
readonly name: string;
|
|
98
103
|
private initCallbacks?;
|
|
@@ -579,6 +584,11 @@ type ChatCompletion$1 = {
|
|
|
579
584
|
usage: unknown;
|
|
580
585
|
};
|
|
581
586
|
declare class AnthropicAPI extends BaseWorkflowApi {
|
|
587
|
+
/**
|
|
588
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
589
|
+
*
|
|
590
|
+
* @see node_modules/@upstash/workflow/docs/integrations/anthropic.mdx
|
|
591
|
+
*/
|
|
582
592
|
call<TResult = ChatCompletion$1, TBody = CreateChatCompletion$1>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
583
593
|
token: string;
|
|
584
594
|
operation: "messages.create";
|
|
@@ -663,6 +673,11 @@ type ChatCompletionChoice = {
|
|
|
663
673
|
};
|
|
664
674
|
};
|
|
665
675
|
declare class OpenAIAPI extends BaseWorkflowApi {
|
|
676
|
+
/**
|
|
677
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
678
|
+
*
|
|
679
|
+
* @see node_modules/@upstash/workflow/docs/integrations/openai.mdx
|
|
680
|
+
*/
|
|
666
681
|
call<TResult = ChatCompletion, TBody = CreateChatCompletion>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
667
682
|
token: string;
|
|
668
683
|
organization?: string;
|
|
@@ -696,6 +711,11 @@ type SendBatchEmailResponse = {
|
|
|
696
711
|
data: SendEmailResponse[];
|
|
697
712
|
};
|
|
698
713
|
declare class ResendAPI extends BaseWorkflowApi {
|
|
714
|
+
/**
|
|
715
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
716
|
+
*
|
|
717
|
+
* @see node_modules/@upstash/workflow/docs/integrations/resend.mdx
|
|
718
|
+
*/
|
|
699
719
|
call<TBatch extends boolean = false, TResult = TBatch extends true ? SendBatchEmailResponse : SendEmailResponse, TBody = TBatch extends true ? SendBatchEmail : SendEmail>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
700
720
|
token: string;
|
|
701
721
|
batch?: TBatch;
|
|
@@ -712,6 +732,16 @@ declare class WorkflowApi extends BaseWorkflowApi {
|
|
|
712
732
|
* Upstash Workflow context
|
|
713
733
|
*
|
|
714
734
|
* See the docs for fields and methods https://upstash.com/docs/qstash/workflows/basics/context
|
|
735
|
+
*
|
|
736
|
+
* Code outside steps runs again on every request of the run. Anything it branches on or
|
|
737
|
+
* returns early on (Date.now(), database rows, random values) must give the same answer on
|
|
738
|
+
* every request, or later requests fail with "Incompatible step name" or "Failed to
|
|
739
|
+
* authenticate Workflow request". Read such values inside `context.run` and branch on its
|
|
740
|
+
* result.
|
|
741
|
+
*
|
|
742
|
+
* @see node_modules/@upstash/workflow/docs/steps.mdx
|
|
743
|
+
* @see node_modules/@upstash/workflow/docs/basics/best-practices/deterministic-code.mdx
|
|
744
|
+
* @see node_modules/@upstash/workflow/docs/basics/best-practices/business-logic-in-steps.mdx
|
|
715
745
|
*/
|
|
716
746
|
declare class WorkflowContext<TInitialPayload = unknown> {
|
|
717
747
|
protected readonly executor: AutoExecutor;
|
|
@@ -723,8 +753,9 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
723
753
|
*
|
|
724
754
|
* ```ts
|
|
725
755
|
* import { Client } from "@upstash/qstash"
|
|
756
|
+
* import { serve } from "@upstash/workflow/nextjs"
|
|
726
757
|
*
|
|
727
|
-
* export const POST = serve(
|
|
758
|
+
* export const { POST } = serve(
|
|
728
759
|
* async (context) => {
|
|
729
760
|
* ...
|
|
730
761
|
* },
|
|
@@ -749,7 +780,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
749
780
|
* Can be overwritten by passing a `url` parameter in `serve`:
|
|
750
781
|
*
|
|
751
782
|
* ```ts
|
|
752
|
-
* export const POST = serve(
|
|
783
|
+
* export const { POST } = serve(
|
|
753
784
|
* async (context) => {
|
|
754
785
|
* ...
|
|
755
786
|
* },
|
|
@@ -767,7 +798,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
767
798
|
*
|
|
768
799
|
* ```ts
|
|
769
800
|
* // set requestPayload type to MyPayload:
|
|
770
|
-
* export const POST = serve<MyPayload>(
|
|
801
|
+
* export const { POST } = serve<MyPayload>(
|
|
771
802
|
* async (context) => {
|
|
772
803
|
* ...
|
|
773
804
|
* }
|
|
@@ -779,7 +810,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
779
810
|
* the `initialPayloadParser` parameter:
|
|
780
811
|
*
|
|
781
812
|
* ```ts
|
|
782
|
-
* export const POST = serve<MyPayload>(
|
|
813
|
+
* export const { POST } = serve<MyPayload>(
|
|
783
814
|
* async (context) => {
|
|
784
815
|
* ...
|
|
785
816
|
* },
|
|
@@ -788,6 +819,13 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
788
819
|
* }
|
|
789
820
|
* )
|
|
790
821
|
* ```
|
|
822
|
+
*
|
|
823
|
+
* When a `context.call` response comes back, the route runs up to its first step with this
|
|
824
|
+
* set to the call-result envelope (and `workflowRunId` set to a random id) before the SDK
|
|
825
|
+
* recognizes the request. Code before the first step must not dereference, validate or
|
|
826
|
+
* return early on the payload; read it inside `context.run`.
|
|
827
|
+
*
|
|
828
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
|
|
791
829
|
*/
|
|
792
830
|
readonly requestPayload: TInitialPayload;
|
|
793
831
|
/**
|
|
@@ -800,7 +838,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
800
838
|
* Can be set using the `env` option of serve:
|
|
801
839
|
*
|
|
802
840
|
* ```ts
|
|
803
|
-
* export const POST = serve<MyPayload>(
|
|
841
|
+
* export const { POST } = serve<MyPayload>(
|
|
804
842
|
* async (context) => {
|
|
805
843
|
* const key = context.env["API_KEY"];
|
|
806
844
|
* },
|
|
@@ -940,10 +978,15 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
940
978
|
* )
|
|
941
979
|
* ```
|
|
942
980
|
*
|
|
981
|
+
* Do not wrap steps in try/catch or `.catch` without rethrowing `WorkflowAbort`: each step
|
|
982
|
+
* throws it to end the request. To stop retrying a failed step, throw
|
|
983
|
+
* `WorkflowNonRetryableError`.
|
|
984
|
+
*
|
|
943
985
|
* @param stepName name of the step
|
|
944
986
|
* @param stepFunction step function to be executed
|
|
945
987
|
* @param stepSettings step-level settings for this step
|
|
946
988
|
* @returns result of the step function
|
|
989
|
+
* @see node_modules/@upstash/workflow/docs/steps/run.mdx
|
|
947
990
|
*/
|
|
948
991
|
run<TResult>(stepName: string, stepFunction: StepFunction<TResult>, stepSettings?: StepSettings): Promise<TResult>;
|
|
949
992
|
/**
|
|
@@ -954,8 +997,9 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
954
997
|
* ```
|
|
955
998
|
*
|
|
956
999
|
* @param stepName
|
|
957
|
-
* @param duration sleep duration in seconds
|
|
1000
|
+
* @param duration sleep duration in seconds, or a duration string such as "10m"
|
|
958
1001
|
* @returns undefined
|
|
1002
|
+
* @see node_modules/@upstash/workflow/docs/steps/sleep.mdx
|
|
959
1003
|
*/
|
|
960
1004
|
sleep(stepName: string, duration: number | Duration): Promise<void>;
|
|
961
1005
|
/**
|
|
@@ -967,8 +1011,11 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
967
1011
|
*
|
|
968
1012
|
* @param stepName
|
|
969
1013
|
* @param datetime time to sleep until. Can be provided as a number (in unix seconds),
|
|
970
|
-
* as a Date object or a string (passed to `new Date(datetimeString)`)
|
|
1014
|
+
* as a Date object or a string (passed to `new Date(datetimeString)`).
|
|
1015
|
+
* A millisecond timestamp such as `Date.now()` is too far in the future, so QStash
|
|
1016
|
+
* rejects the step and the run fails. Pass `new Date(ms)` instead.
|
|
971
1017
|
* @returns undefined
|
|
1018
|
+
* @see node_modules/@upstash/workflow/docs/steps/sleepUntil.mdx
|
|
972
1019
|
*/
|
|
973
1020
|
sleepUntil(stepName: string, datetime: Date | string | number): Promise<void>;
|
|
974
1021
|
/**
|
|
@@ -988,7 +1035,17 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
988
1035
|
*
|
|
989
1036
|
* tries to parse the result of the request as JSON. If it's
|
|
990
1037
|
* not a JSON which can be parsed, simply returns the response
|
|
991
|
-
* body as it is.
|
|
1038
|
+
* body as it is. This applies to text/plain too: "42" comes back as the number 42,
|
|
1039
|
+
* "3.10" as 3.1 and "null" as null. To keep text exact, use fetch inside `context.run`.
|
|
1040
|
+
*
|
|
1041
|
+
* The response comes back to this endpoint as a separate request. Before the SDK
|
|
1042
|
+
* recognizes it, your route runs up to its first step with `requestPayload` set to the
|
|
1043
|
+
* call-result envelope and a random `workflowRunId`. Code before the first step must not
|
|
1044
|
+
* dereference, validate or return early on the payload, or look anything up by
|
|
1045
|
+
* `workflowRunId`; do that inside `context.run`.
|
|
1046
|
+
*
|
|
1047
|
+
* Do not wrap steps in try/catch or `.catch` without rethrowing `WorkflowAbort`: each step
|
|
1048
|
+
* throws it to end the request. A non-2xx response is returned, not thrown; check `status`.
|
|
992
1049
|
*
|
|
993
1050
|
* @param stepName
|
|
994
1051
|
* @param url url to call
|
|
@@ -997,12 +1054,14 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
997
1054
|
* @param headers call headers
|
|
998
1055
|
* @param retries number of call retries. 0 by default
|
|
999
1056
|
* @param retryDelay delay / time gap between retries.
|
|
1000
|
-
* @param timeout max duration to wait for the endpoint to respond
|
|
1057
|
+
* @param timeout max duration to wait for the endpoint to respond, as a duration string
|
|
1058
|
+
* such as "10s". See `CallSettings.timeout`.
|
|
1001
1059
|
* @returns call result as {
|
|
1002
1060
|
* status: number;
|
|
1003
1061
|
* body: unknown;
|
|
1004
1062
|
* header: Record<string, string[]>
|
|
1005
1063
|
* }
|
|
1064
|
+
* @see node_modules/@upstash/workflow/docs/steps/call.mdx
|
|
1006
1065
|
*/
|
|
1007
1066
|
call<TResult = unknown>(stepName: string, settings: CallSettings): Promise<CallResponse<TResult>>;
|
|
1008
1067
|
call<TResult extends {
|
|
@@ -1014,7 +1073,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
1014
1073
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
1015
1074
|
*
|
|
1016
1075
|
*```ts
|
|
1017
|
-
* const result = await
|
|
1076
|
+
* const result = await context.waitForEvent("payment-confirmed", "payment.confirmed", {
|
|
1018
1077
|
* timeout: "5m"
|
|
1019
1078
|
* });
|
|
1020
1079
|
*```
|
|
@@ -1038,11 +1097,14 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
1038
1097
|
* Alternatively, you can use the `context.notify` method.
|
|
1039
1098
|
*
|
|
1040
1099
|
* @param stepName
|
|
1041
|
-
* @param eventId - Unique identifier for the event to wait for
|
|
1100
|
+
* @param eventId - Unique identifier for the event to wait for. Only letters, digits,
|
|
1101
|
+
* "-", "_" and "." are allowed. QStash rejects other characters, such as ":", which
|
|
1102
|
+
* stops the run with only a "Tried to append to a cancelled workflow" warning.
|
|
1042
1103
|
* @param options - Configuration options.
|
|
1043
1104
|
* @returns `{ timeout: boolean, eventData: TEventData }`.
|
|
1044
1105
|
* The `timeout` property specifies if the workflow has timed out. The `eventData`
|
|
1045
1106
|
* is the data passed when notifying this workflow of an event.
|
|
1107
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
|
|
1046
1108
|
*/
|
|
1047
1109
|
waitForEvent<TEventData = unknown>(stepName: string, eventId: string, options?: WaitEventOptions): Promise<WaitStepResponse<TEventData>>;
|
|
1048
1110
|
/**
|
|
@@ -1058,32 +1120,43 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
1058
1120
|
* will receive the given event data and resume execution.
|
|
1059
1121
|
*
|
|
1060
1122
|
* The response includes the same eventId and eventData. Additionally, there is
|
|
1061
|
-
* a notifyResponse field which contains a list of `
|
|
1062
|
-
* to a notified workflow run.
|
|
1063
|
-
*
|
|
1064
|
-
* Optionally, you can pass a workflowRunId to enable lookback functionality:
|
|
1065
|
-
*
|
|
1066
|
-
* ```ts
|
|
1067
|
-
* const { eventId, eventData, notifyResponse } = await context.notify(
|
|
1068
|
-
* "notify step", "event-id", "event-data", "wfr_123"
|
|
1069
|
-
* );
|
|
1070
|
-
* ```
|
|
1123
|
+
* a notifyResponse field which contains a list of `NotifyResponse` objects, each corresponding
|
|
1124
|
+
* to a notified workflow run. The notified `Waiter` is under `notifyResponse[i].waiter`.
|
|
1071
1125
|
*
|
|
1072
1126
|
* @param stepName
|
|
1073
|
-
* @param eventId event id to notify
|
|
1127
|
+
* @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed.
|
|
1128
|
+
* QStash rejects other characters, such as ":", which stops the run with only a
|
|
1129
|
+
* "Tried to append to a cancelled workflow" warning.
|
|
1074
1130
|
* @param eventData event data to notify with
|
|
1075
|
-
* @param workflowRunId optional workflow run id for lookback
|
|
1076
|
-
*
|
|
1131
|
+
* @param workflowRunId optional workflow run id for lookback: the event is kept for the run
|
|
1132
|
+
* even if it has not reached `waitForEvent` yet
|
|
1133
|
+
* @returns notify response which has event id, event data and list of waiters which were
|
|
1134
|
+
* notified. With `workflowRunId`, QStash returns `notifyResponse` as a single object instead
|
|
1135
|
+
* of an array, despite the type.
|
|
1136
|
+
* @see node_modules/@upstash/workflow/docs/steps/notify.mdx
|
|
1077
1137
|
*/
|
|
1078
1138
|
notify(stepName: string, eventId: string, eventData: unknown, workflowRunId?: string): Promise<NotifyStepResponse>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Starts another workflow run and waits for its result.
|
|
1141
|
+
*
|
|
1142
|
+
* @see node_modules/@upstash/workflow/docs/steps/invoke.mdx
|
|
1143
|
+
*/
|
|
1079
1144
|
invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
|
|
1145
|
+
/**
|
|
1146
|
+
* @see node_modules/@upstash/workflow/docs/steps/createWebhook.mdx
|
|
1147
|
+
*/
|
|
1080
1148
|
createWebhook(stepName: string): Promise<Webhook>;
|
|
1149
|
+
/**
|
|
1150
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForWebhook.mdx
|
|
1151
|
+
*/
|
|
1081
1152
|
waitForWebhook(stepName: string, webhook: Webhook, timeout: Duration): Promise<WaitForWebhookResponse>;
|
|
1082
1153
|
/**
|
|
1083
1154
|
* Cancel the current workflow run
|
|
1084
1155
|
*
|
|
1085
1156
|
* Will throw WorkflowCancelAbort to stop workflow execution.
|
|
1086
1157
|
* Shouldn't be inside try/catch.
|
|
1158
|
+
*
|
|
1159
|
+
* @see node_modules/@upstash/workflow/docs/steps/cancel.mdx
|
|
1087
1160
|
*/
|
|
1088
1161
|
cancel(): Promise<void>;
|
|
1089
1162
|
/**
|
|
@@ -1091,6 +1164,11 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
1091
1164
|
* DisabledWorkflowContext.
|
|
1092
1165
|
*/
|
|
1093
1166
|
protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
|
|
1167
|
+
/**
|
|
1168
|
+
* Calls OpenAI, Anthropic or Resend through QStash, like `context.call`.
|
|
1169
|
+
*
|
|
1170
|
+
* @see node_modules/@upstash/workflow/docs/steps/api.mdx
|
|
1171
|
+
*/
|
|
1094
1172
|
get api(): WorkflowApi;
|
|
1095
1173
|
}
|
|
1096
1174
|
|
|
@@ -1214,6 +1292,11 @@ type DetailedFinishCondition = {
|
|
|
1214
1292
|
};
|
|
1215
1293
|
type WorkflowContextWithoutMethods<TInitialPayload> = Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api" | "invoke" | "createWebhook" | "waitForWebhook">;
|
|
1216
1294
|
type QStashClientExtraConfig = Omit<NonNullable<ConstructorParameters<typeof Client>[0]>, "baseUrl" | "token">;
|
|
1295
|
+
/**
|
|
1296
|
+
* Options of `serve`.
|
|
1297
|
+
*
|
|
1298
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
|
|
1299
|
+
*/
|
|
1217
1300
|
type WorkflowServeOptions<TInitialPayload = unknown, TResult = unknown> = {
|
|
1218
1301
|
/**
|
|
1219
1302
|
* QStash client or client configuration
|
|
@@ -1244,6 +1327,7 @@ type WorkflowServeOptions<TInitialPayload = unknown, TResult = unknown> = {
|
|
|
1244
1327
|
* @param failStatus error status
|
|
1245
1328
|
* @param failResponse error message
|
|
1246
1329
|
* @returns void
|
|
1330
|
+
* @see node_modules/@upstash/workflow/docs/features/failure-callback.mdx
|
|
1247
1331
|
*/
|
|
1248
1332
|
failureFunction?: (failureData: {
|
|
1249
1333
|
context: WorkflowContextWithoutMethods<TInitialPayload>;
|
|
@@ -1282,6 +1366,8 @@ type WorkflowServeOptions<TInitialPayload = unknown, TResult = unknown> = {
|
|
|
1282
1366
|
disableTelemetry?: boolean;
|
|
1283
1367
|
/**
|
|
1284
1368
|
* List of workflow middlewares to use
|
|
1369
|
+
*
|
|
1370
|
+
* @see node_modules/@upstash/workflow/docs/howto/middlewares.mdx
|
|
1285
1371
|
*/
|
|
1286
1372
|
middlewares?: WorkflowMiddleware<TInitialPayload, TResult>[];
|
|
1287
1373
|
/**
|
|
@@ -1394,6 +1480,9 @@ type CallResponse<TResult = unknown> = {
|
|
|
1394
1480
|
* @example "1d" // 1 day
|
|
1395
1481
|
*/
|
|
1396
1482
|
type Duration = `${bigint}${"s" | "m" | "h" | "d"}`;
|
|
1483
|
+
/**
|
|
1484
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
|
|
1485
|
+
*/
|
|
1397
1486
|
interface WaitEventOptions {
|
|
1398
1487
|
/**
|
|
1399
1488
|
* Duration in seconds to wait for an event before timing out the workflow.
|
|
@@ -1452,9 +1541,14 @@ type StepSettings = {
|
|
|
1452
1541
|
retries?: number;
|
|
1453
1542
|
/**
|
|
1454
1543
|
* Delay between retries of the delivery which executes this step.
|
|
1544
|
+
* Leading and trailing whitespace is trimmed. An empty or whitespace-only
|
|
1545
|
+
* string leaves the workflow run's retry delay unchanged.
|
|
1455
1546
|
*/
|
|
1456
1547
|
retryDelay?: string;
|
|
1457
1548
|
};
|
|
1549
|
+
/**
|
|
1550
|
+
* @see node_modules/@upstash/workflow/docs/steps/call.mdx
|
|
1551
|
+
*/
|
|
1458
1552
|
type CallSettings = {
|
|
1459
1553
|
url: string;
|
|
1460
1554
|
method?: HTTPMethods$1;
|
|
@@ -1462,6 +1556,12 @@ type CallSettings = {
|
|
|
1462
1556
|
headers?: Record<string, string>;
|
|
1463
1557
|
retries?: number;
|
|
1464
1558
|
retryDelay?: string;
|
|
1559
|
+
/**
|
|
1560
|
+
* Max time to wait for the endpoint to respond. Pass a duration string such as "10s".
|
|
1561
|
+
* A number is sent without a unit and QStash rejects the step ("missing unit in
|
|
1562
|
+
* duration"), which stops the run with only a "Tried to append to a cancelled workflow"
|
|
1563
|
+
* warning.
|
|
1564
|
+
*/
|
|
1465
1565
|
timeout?: Duration | number;
|
|
1466
1566
|
flowControl?: FlowControl;
|
|
1467
1567
|
};
|