@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
package/index.js
CHANGED
|
@@ -879,6 +879,10 @@ var triggerFirstInvocation = async (params) => {
|
|
|
879
879
|
workflowConfig: {
|
|
880
880
|
workflowRunId: workflowContext.workflowRunId,
|
|
881
881
|
workflowUrl: workflowContext.url,
|
|
882
|
+
// the run doesn't exist yet, so the trigger time is sent when the creation time
|
|
883
|
+
// is not known. serve and client.trigger set it on the context already, so a
|
|
884
|
+
// retry of this request carries the same value and is deduplicated.
|
|
885
|
+
workflowRunCreatedAt: workflowContext.workflowRunCreatedAt || Date.now(),
|
|
882
886
|
failureUrl,
|
|
883
887
|
retries,
|
|
884
888
|
retryDelay,
|
|
@@ -986,7 +990,10 @@ var triggerWorkflowDelete = async (workflowContext, result, cancel = false, disp
|
|
|
986
990
|
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
987
991
|
method: "DELETE",
|
|
988
992
|
parseResponseAsJson: false,
|
|
989
|
-
body: JSON.stringify(result)
|
|
993
|
+
body: JSON.stringify(result),
|
|
994
|
+
// with the creation time, QStash deletes the run only if it is the same run.
|
|
995
|
+
// a late delete of a previous run can't delete a new run with the same id.
|
|
996
|
+
headers: workflowContext.workflowRunCreatedAt ? { [WORKFLOW_CREATED_AT_HEADER]: workflowContext.workflowRunCreatedAt.toString() } : void 0
|
|
990
997
|
});
|
|
991
998
|
await dispatchDebug?.("onInfo", {
|
|
992
999
|
info: `Workflow run ${workflowContext.workflowRunId} deleted from QStash successfully.`
|
|
@@ -1063,6 +1070,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1063
1070
|
const concurrentString = request.headers.get("Upstash-Workflow-Concurrent");
|
|
1064
1071
|
const contentType = request.headers.get("Upstash-Workflow-ContentType");
|
|
1065
1072
|
const invokeCount = request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER);
|
|
1073
|
+
const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
|
|
1066
1074
|
if (!(workflowRunId && stepIdString && stepName && StepTypes.includes(stepType) && concurrentString && contentType)) {
|
|
1067
1075
|
throw new Error(
|
|
1068
1076
|
`Missing info in callback message source header: ${JSON.stringify({
|
|
@@ -1080,6 +1088,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1080
1088
|
workflowConfig: {
|
|
1081
1089
|
workflowRunId,
|
|
1082
1090
|
workflowUrl,
|
|
1091
|
+
workflowRunCreatedAt: Number(workflowRunCreatedAt ?? "0"),
|
|
1083
1092
|
telemetry
|
|
1084
1093
|
},
|
|
1085
1094
|
invokeCount: Number(invokeCount)
|
|
@@ -1254,6 +1263,7 @@ var BaseLazyStep = class _BaseLazyStep {
|
|
|
1254
1263
|
workflowConfig: {
|
|
1255
1264
|
workflowRunId: context.workflowRunId,
|
|
1256
1265
|
workflowUrl: context.url,
|
|
1266
|
+
workflowRunCreatedAt: context.workflowRunCreatedAt,
|
|
1257
1267
|
useJSONContent: false,
|
|
1258
1268
|
telemetry
|
|
1259
1269
|
},
|
|
@@ -1585,6 +1595,8 @@ var LazyWaitEventStep = class extends BaseLazyStep {
|
|
|
1585
1595
|
) : {},
|
|
1586
1596
|
// note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
|
|
1587
1597
|
"Upstash-Workflow-Runid": [context.workflowRunId],
|
|
1598
|
+
// same for WORKFLOW_CREATED_AT_HEADER, because Createdat -> CreatedAt:
|
|
1599
|
+
...context.workflowRunCreatedAt ? { "Upstash-Workflow-Createdat": [context.workflowRunCreatedAt.toString()] } : {},
|
|
1588
1600
|
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1589
1601
|
[WORKFLOW_URL_HEADER]: [context.url],
|
|
1590
1602
|
"Upstash-Workflow-CallType": ["step"]
|
|
@@ -1687,6 +1699,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1687
1699
|
workflowConfig: {
|
|
1688
1700
|
workflowRunId: context.workflowRunId,
|
|
1689
1701
|
workflowUrl: context.url,
|
|
1702
|
+
workflowRunCreatedAt: context.workflowRunCreatedAt,
|
|
1690
1703
|
telemetry,
|
|
1691
1704
|
useJSONContent: false
|
|
1692
1705
|
},
|
|
@@ -1696,6 +1709,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1696
1709
|
invokerHeaders[key] = value;
|
|
1697
1710
|
});
|
|
1698
1711
|
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
1712
|
+
if (context.workflowRunCreatedAt) {
|
|
1713
|
+
invokerHeaders["Upstash-Workflow-Createdat"] = context.workflowRunCreatedAt.toString();
|
|
1714
|
+
}
|
|
1699
1715
|
const request = {
|
|
1700
1716
|
body: stringifyBody(this.params.body),
|
|
1701
1717
|
headers: Object.fromEntries(
|
|
@@ -1724,6 +1740,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1724
1740
|
workflowConfig: {
|
|
1725
1741
|
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
1726
1742
|
workflowUrl: newUrl,
|
|
1743
|
+
// the invoked run doesn't exist yet, so the creation time of the invoker run is sent.
|
|
1744
|
+
// it separates the invocations made by different runs of the invoker.
|
|
1745
|
+
workflowRunCreatedAt: context.workflowRunCreatedAt,
|
|
1727
1746
|
retries,
|
|
1728
1747
|
retryDelay,
|
|
1729
1748
|
telemetry,
|
|
@@ -1893,6 +1912,9 @@ var WorkflowHeaders = class {
|
|
|
1893
1912
|
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1894
1913
|
...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {}
|
|
1895
1914
|
};
|
|
1915
|
+
if (this.workflowConfig.workflowRunCreatedAt) {
|
|
1916
|
+
this.headers.rawHeaders[WORKFLOW_CREATED_AT_HEADER] = this.workflowConfig.workflowRunCreatedAt.toString();
|
|
1917
|
+
}
|
|
1896
1918
|
if (this.stepInfo?.lazyStep.stepType !== "Call") {
|
|
1897
1919
|
this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
1898
1920
|
}
|
|
@@ -2091,6 +2113,7 @@ var submitParallelSteps = async ({
|
|
|
2091
2113
|
workflowConfig: {
|
|
2092
2114
|
workflowRunId: context.workflowRunId,
|
|
2093
2115
|
workflowUrl: context.url,
|
|
2116
|
+
workflowRunCreatedAt: context.workflowRunCreatedAt,
|
|
2094
2117
|
telemetry
|
|
2095
2118
|
},
|
|
2096
2119
|
invokeCount,
|
|
@@ -2181,6 +2204,7 @@ var publishStepConfigRequest = async ({
|
|
|
2181
2204
|
initHeaderValue: "false",
|
|
2182
2205
|
workflowConfig: {
|
|
2183
2206
|
workflowRunId: context.workflowRunId,
|
|
2207
|
+
workflowRunCreatedAt: context.workflowRunCreatedAt,
|
|
2184
2208
|
workflowUrl: context.url,
|
|
2185
2209
|
telemetry
|
|
2186
2210
|
},
|
|
@@ -2193,7 +2217,9 @@ var publishStepConfigRequest = async ({
|
|
|
2193
2217
|
const result = await context.qstashClient.publishJSON({
|
|
2194
2218
|
headers: {
|
|
2195
2219
|
...headers,
|
|
2196
|
-
"Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE
|
|
2220
|
+
"Upstash-Workflow-CallType": WORKFLOW_STEP_CONFIG_CALL_TYPE,
|
|
2221
|
+
"Upstash-Forward-Upstash-Workflow-StepId": targetStep.toString(),
|
|
2222
|
+
"Upstash-Forward-Upstash-Workflow-StepName": lazyStep.stepName
|
|
2197
2223
|
},
|
|
2198
2224
|
method: "POST",
|
|
2199
2225
|
body: { targetStep, invokeCount },
|
|
@@ -2212,6 +2238,19 @@ var publishStepConfigRequest = async ({
|
|
|
2212
2238
|
};
|
|
2213
2239
|
|
|
2214
2240
|
// src/qstash/step-config.ts
|
|
2241
|
+
var normalizeStepSettings = (settings) => {
|
|
2242
|
+
if (settings === void 0) {
|
|
2243
|
+
return void 0;
|
|
2244
|
+
}
|
|
2245
|
+
const { retries, retryDelay } = settings;
|
|
2246
|
+
if (retryDelay !== void 0 && typeof retryDelay !== "string") {
|
|
2247
|
+
throw new WorkflowNonRetryableError("Invalid step retryDelay: must be a string.");
|
|
2248
|
+
}
|
|
2249
|
+
if (retries !== void 0 && (!Number.isInteger(retries) || retries < 0)) {
|
|
2250
|
+
throw new WorkflowNonRetryableError("Invalid step retries: must be a non-negative integer.");
|
|
2251
|
+
}
|
|
2252
|
+
return { ...settings, retryDelay: retryDelay?.trim() || void 0 };
|
|
2253
|
+
};
|
|
2215
2254
|
var DEFAULT_PARALLELISM = 0;
|
|
2216
2255
|
var DEFAULT_RATE = 0;
|
|
2217
2256
|
var DEFAULT_PERIOD_SECONDS = 1;
|
|
@@ -2475,10 +2514,18 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2475
2514
|
dispatchLifecycle: this.dispatchLifecycle
|
|
2476
2515
|
});
|
|
2477
2516
|
if (lazyStep.supportsDeferredSubmission) {
|
|
2478
|
-
|
|
2517
|
+
const serializedOut = JSON.stringify(resultStep.out);
|
|
2518
|
+
this.pendingStep = {
|
|
2519
|
+
status: "held",
|
|
2520
|
+
lazyStep,
|
|
2521
|
+
resultStep: {
|
|
2522
|
+
...resultStep,
|
|
2523
|
+
out: serializedOut === void 0 ? void 0 : JSON.parse(serializedOut)
|
|
2524
|
+
}
|
|
2525
|
+
};
|
|
2479
2526
|
return lazyStep.parseOut({
|
|
2480
2527
|
...resultStep,
|
|
2481
|
-
out:
|
|
2528
|
+
out: serializedOut
|
|
2482
2529
|
});
|
|
2483
2530
|
}
|
|
2484
2531
|
await submitStepResult({
|
|
@@ -2823,6 +2870,11 @@ var BaseWorkflowApi = class {
|
|
|
2823
2870
|
|
|
2824
2871
|
// src/context/api/anthropic.ts
|
|
2825
2872
|
var AnthropicAPI = class extends BaseWorkflowApi {
|
|
2873
|
+
/**
|
|
2874
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
2875
|
+
*
|
|
2876
|
+
* @see node_modules/@upstash/workflow/docs/integrations/anthropic.mdx
|
|
2877
|
+
*/
|
|
2826
2878
|
async call(stepName, settings) {
|
|
2827
2879
|
const { token, operation, ...parameters } = settings;
|
|
2828
2880
|
return await this.callApi(stepName, {
|
|
@@ -2838,6 +2890,11 @@ var AnthropicAPI = class extends BaseWorkflowApi {
|
|
|
2838
2890
|
// src/context/api/openai.ts
|
|
2839
2891
|
var import_qstash7 = require("@upstash/qstash");
|
|
2840
2892
|
var OpenAIAPI = class extends BaseWorkflowApi {
|
|
2893
|
+
/**
|
|
2894
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
2895
|
+
*
|
|
2896
|
+
* @see node_modules/@upstash/workflow/docs/integrations/openai.mdx
|
|
2897
|
+
*/
|
|
2841
2898
|
async call(stepName, settings) {
|
|
2842
2899
|
const { token, organization, operation, baseURL, ...parameters } = settings;
|
|
2843
2900
|
const useOpenAI = baseURL === void 0;
|
|
@@ -2855,6 +2912,11 @@ var OpenAIAPI = class extends BaseWorkflowApi {
|
|
|
2855
2912
|
// src/context/api/resend.ts
|
|
2856
2913
|
var import_qstash8 = require("@upstash/qstash");
|
|
2857
2914
|
var ResendAPI = class extends BaseWorkflowApi {
|
|
2915
|
+
/**
|
|
2916
|
+
* Runs as a `context.call` step, so the `context.call` caveats apply.
|
|
2917
|
+
*
|
|
2918
|
+
* @see node_modules/@upstash/workflow/docs/integrations/resend.mdx
|
|
2919
|
+
*/
|
|
2858
2920
|
async call(stepName, settings) {
|
|
2859
2921
|
const { token, batch = false, ...parameters } = settings;
|
|
2860
2922
|
return await this.callApi(stepName, {
|
|
@@ -3029,8 +3091,9 @@ var WorkflowContext = class {
|
|
|
3029
3091
|
*
|
|
3030
3092
|
* ```ts
|
|
3031
3093
|
* import { Client } from "@upstash/qstash"
|
|
3094
|
+
* import { serve } from "@upstash/workflow/nextjs"
|
|
3032
3095
|
*
|
|
3033
|
-
* export const POST = serve(
|
|
3096
|
+
* export const { POST } = serve(
|
|
3034
3097
|
* async (context) => {
|
|
3035
3098
|
* ...
|
|
3036
3099
|
* },
|
|
@@ -3055,7 +3118,7 @@ var WorkflowContext = class {
|
|
|
3055
3118
|
* Can be overwritten by passing a `url` parameter in `serve`:
|
|
3056
3119
|
*
|
|
3057
3120
|
* ```ts
|
|
3058
|
-
* export const POST = serve(
|
|
3121
|
+
* export const { POST } = serve(
|
|
3059
3122
|
* async (context) => {
|
|
3060
3123
|
* ...
|
|
3061
3124
|
* },
|
|
@@ -3073,7 +3136,7 @@ var WorkflowContext = class {
|
|
|
3073
3136
|
*
|
|
3074
3137
|
* ```ts
|
|
3075
3138
|
* // set requestPayload type to MyPayload:
|
|
3076
|
-
* export const POST = serve<MyPayload>(
|
|
3139
|
+
* export const { POST } = serve<MyPayload>(
|
|
3077
3140
|
* async (context) => {
|
|
3078
3141
|
* ...
|
|
3079
3142
|
* }
|
|
@@ -3085,7 +3148,7 @@ var WorkflowContext = class {
|
|
|
3085
3148
|
* the `initialPayloadParser` parameter:
|
|
3086
3149
|
*
|
|
3087
3150
|
* ```ts
|
|
3088
|
-
* export const POST = serve<MyPayload>(
|
|
3151
|
+
* export const { POST } = serve<MyPayload>(
|
|
3089
3152
|
* async (context) => {
|
|
3090
3153
|
* ...
|
|
3091
3154
|
* },
|
|
@@ -3094,6 +3157,13 @@ var WorkflowContext = class {
|
|
|
3094
3157
|
* }
|
|
3095
3158
|
* )
|
|
3096
3159
|
* ```
|
|
3160
|
+
*
|
|
3161
|
+
* When a `context.call` response comes back, the route runs up to its first step with this
|
|
3162
|
+
* set to the call-result envelope (and `workflowRunId` set to a random id) before the SDK
|
|
3163
|
+
* recognizes the request. Code before the first step must not dereference, validate or
|
|
3164
|
+
* return early on the payload; read it inside `context.run`.
|
|
3165
|
+
*
|
|
3166
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve/advanced.mdx
|
|
3097
3167
|
*/
|
|
3098
3168
|
requestPayload;
|
|
3099
3169
|
/**
|
|
@@ -3106,7 +3176,7 @@ var WorkflowContext = class {
|
|
|
3106
3176
|
* Can be set using the `env` option of serve:
|
|
3107
3177
|
*
|
|
3108
3178
|
* ```ts
|
|
3109
|
-
* export const POST = serve<MyPayload>(
|
|
3179
|
+
* export const { POST } = serve<MyPayload>(
|
|
3110
3180
|
* async (context) => {
|
|
3111
3181
|
* const key = context.env["API_KEY"];
|
|
3112
3182
|
* },
|
|
@@ -3272,18 +3342,24 @@ var WorkflowContext = class {
|
|
|
3272
3342
|
* )
|
|
3273
3343
|
* ```
|
|
3274
3344
|
*
|
|
3345
|
+
* Do not wrap steps in try/catch or `.catch` without rethrowing `WorkflowAbort`: each step
|
|
3346
|
+
* throws it to end the request. To stop retrying a failed step, throw
|
|
3347
|
+
* `WorkflowNonRetryableError`.
|
|
3348
|
+
*
|
|
3275
3349
|
* @param stepName name of the step
|
|
3276
3350
|
* @param stepFunction step function to be executed
|
|
3277
3351
|
* @param stepSettings step-level settings for this step
|
|
3278
3352
|
* @returns result of the step function
|
|
3353
|
+
* @see node_modules/@upstash/workflow/docs/steps/run.mdx
|
|
3279
3354
|
*/
|
|
3280
3355
|
async run(stepName, stepFunction, stepSettings) {
|
|
3356
|
+
const normalizedSettings = normalizeStepSettings(stepSettings);
|
|
3281
3357
|
if (stepSettings) {
|
|
3282
3358
|
validateFlowControl(stepSettings.flowControl);
|
|
3283
3359
|
}
|
|
3284
3360
|
const wrappedStepFunction = (() => this.executor.wrapStep(stepName, stepFunction));
|
|
3285
3361
|
return await this.addStep(
|
|
3286
|
-
new LazyFunctionStep(this, stepName, wrappedStepFunction,
|
|
3362
|
+
new LazyFunctionStep(this, stepName, wrappedStepFunction, normalizedSettings)
|
|
3287
3363
|
);
|
|
3288
3364
|
}
|
|
3289
3365
|
/**
|
|
@@ -3294,8 +3370,9 @@ var WorkflowContext = class {
|
|
|
3294
3370
|
* ```
|
|
3295
3371
|
*
|
|
3296
3372
|
* @param stepName
|
|
3297
|
-
* @param duration sleep duration in seconds
|
|
3373
|
+
* @param duration sleep duration in seconds, or a duration string such as "10m"
|
|
3298
3374
|
* @returns undefined
|
|
3375
|
+
* @see node_modules/@upstash/workflow/docs/steps/sleep.mdx
|
|
3299
3376
|
*/
|
|
3300
3377
|
async sleep(stepName, duration) {
|
|
3301
3378
|
await this.addStep(new LazySleepStep(this, stepName, duration));
|
|
@@ -3309,8 +3386,11 @@ var WorkflowContext = class {
|
|
|
3309
3386
|
*
|
|
3310
3387
|
* @param stepName
|
|
3311
3388
|
* @param datetime time to sleep until. Can be provided as a number (in unix seconds),
|
|
3312
|
-
* as a Date object or a string (passed to `new Date(datetimeString)`)
|
|
3389
|
+
* as a Date object or a string (passed to `new Date(datetimeString)`).
|
|
3390
|
+
* A millisecond timestamp such as `Date.now()` is too far in the future, so QStash
|
|
3391
|
+
* rejects the step and the run fails. Pass `new Date(ms)` instead.
|
|
3313
3392
|
* @returns undefined
|
|
3393
|
+
* @see node_modules/@upstash/workflow/docs/steps/sleepUntil.mdx
|
|
3314
3394
|
*/
|
|
3315
3395
|
async sleepUntil(stepName, datetime) {
|
|
3316
3396
|
let time;
|
|
@@ -3361,7 +3441,7 @@ var WorkflowContext = class {
|
|
|
3361
3441
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
3362
3442
|
*
|
|
3363
3443
|
*```ts
|
|
3364
|
-
* const result = await
|
|
3444
|
+
* const result = await context.waitForEvent("payment-confirmed", "payment.confirmed", {
|
|
3365
3445
|
* timeout: "5m"
|
|
3366
3446
|
* });
|
|
3367
3447
|
*```
|
|
@@ -3385,11 +3465,14 @@ var WorkflowContext = class {
|
|
|
3385
3465
|
* Alternatively, you can use the `context.notify` method.
|
|
3386
3466
|
*
|
|
3387
3467
|
* @param stepName
|
|
3388
|
-
* @param eventId - Unique identifier for the event to wait for
|
|
3468
|
+
* @param eventId - Unique identifier for the event to wait for. Only letters, digits,
|
|
3469
|
+
* "-", "_" and "." are allowed. QStash rejects other characters, such as ":", which
|
|
3470
|
+
* stops the run with only a "Tried to append to a cancelled workflow" warning.
|
|
3389
3471
|
* @param options - Configuration options.
|
|
3390
3472
|
* @returns `{ timeout: boolean, eventData: TEventData }`.
|
|
3391
3473
|
* The `timeout` property specifies if the workflow has timed out. The `eventData`
|
|
3392
3474
|
* is the data passed when notifying this workflow of an event.
|
|
3475
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForEvent.mdx
|
|
3393
3476
|
*/
|
|
3394
3477
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
3395
3478
|
const { timeout = "7d" } = options;
|
|
@@ -3411,28 +3494,31 @@ var WorkflowContext = class {
|
|
|
3411
3494
|
* will receive the given event data and resume execution.
|
|
3412
3495
|
*
|
|
3413
3496
|
* The response includes the same eventId and eventData. Additionally, there is
|
|
3414
|
-
* a notifyResponse field which contains a list of `
|
|
3415
|
-
* to a notified workflow run.
|
|
3416
|
-
*
|
|
3417
|
-
* Optionally, you can pass a workflowRunId to enable lookback functionality:
|
|
3418
|
-
*
|
|
3419
|
-
* ```ts
|
|
3420
|
-
* const { eventId, eventData, notifyResponse } = await context.notify(
|
|
3421
|
-
* "notify step", "event-id", "event-data", "wfr_123"
|
|
3422
|
-
* );
|
|
3423
|
-
* ```
|
|
3497
|
+
* a notifyResponse field which contains a list of `NotifyResponse` objects, each corresponding
|
|
3498
|
+
* to a notified workflow run. The notified `Waiter` is under `notifyResponse[i].waiter`.
|
|
3424
3499
|
*
|
|
3425
3500
|
* @param stepName
|
|
3426
|
-
* @param eventId event id to notify
|
|
3501
|
+
* @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed.
|
|
3502
|
+
* QStash rejects other characters, such as ":", which stops the run with only a
|
|
3503
|
+
* "Tried to append to a cancelled workflow" warning.
|
|
3427
3504
|
* @param eventData event data to notify with
|
|
3428
|
-
* @param workflowRunId optional workflow run id for lookback
|
|
3429
|
-
*
|
|
3505
|
+
* @param workflowRunId optional workflow run id for lookback: the event is kept for the run
|
|
3506
|
+
* even if it has not reached `waitForEvent` yet
|
|
3507
|
+
* @returns notify response which has event id, event data and list of waiters which were
|
|
3508
|
+
* notified. With `workflowRunId`, QStash returns `notifyResponse` as a single object instead
|
|
3509
|
+
* of an array, despite the type.
|
|
3510
|
+
* @see node_modules/@upstash/workflow/docs/steps/notify.mdx
|
|
3430
3511
|
*/
|
|
3431
3512
|
async notify(stepName, eventId, eventData, workflowRunId) {
|
|
3432
3513
|
return await this.addStep(
|
|
3433
3514
|
new LazyNotifyStep(this, stepName, eventId, eventData, this.qstashClient.http, workflowRunId)
|
|
3434
3515
|
);
|
|
3435
3516
|
}
|
|
3517
|
+
/**
|
|
3518
|
+
* Starts another workflow run and waits for its result.
|
|
3519
|
+
*
|
|
3520
|
+
* @see node_modules/@upstash/workflow/docs/steps/invoke.mdx
|
|
3521
|
+
*/
|
|
3436
3522
|
async invoke(stepName, settings) {
|
|
3437
3523
|
validateLabel(settings.label);
|
|
3438
3524
|
validateFlowControl(settings.flowControl);
|
|
@@ -3440,9 +3526,15 @@ var WorkflowContext = class {
|
|
|
3440
3526
|
new LazyInvokeStep(this, stepName, settings)
|
|
3441
3527
|
);
|
|
3442
3528
|
}
|
|
3529
|
+
/**
|
|
3530
|
+
* @see node_modules/@upstash/workflow/docs/steps/createWebhook.mdx
|
|
3531
|
+
*/
|
|
3443
3532
|
async createWebhook(stepName) {
|
|
3444
3533
|
return await this.addStep(new LazyCreateWebhookStep(this, stepName));
|
|
3445
3534
|
}
|
|
3535
|
+
/**
|
|
3536
|
+
* @see node_modules/@upstash/workflow/docs/steps/waitForWebhook.mdx
|
|
3537
|
+
*/
|
|
3446
3538
|
async waitForWebhook(stepName, webhook, timeout) {
|
|
3447
3539
|
return await this.addStep(new LazyWaitForWebhookStep(this, stepName, webhook, timeout));
|
|
3448
3540
|
}
|
|
@@ -3451,6 +3543,8 @@ var WorkflowContext = class {
|
|
|
3451
3543
|
*
|
|
3452
3544
|
* Will throw WorkflowCancelAbort to stop workflow execution.
|
|
3453
3545
|
* Shouldn't be inside try/catch.
|
|
3546
|
+
*
|
|
3547
|
+
* @see node_modules/@upstash/workflow/docs/steps/cancel.mdx
|
|
3454
3548
|
*/
|
|
3455
3549
|
async cancel() {
|
|
3456
3550
|
throw new WorkflowCancelAbort();
|
|
@@ -3469,6 +3563,11 @@ var WorkflowContext = class {
|
|
|
3469
3563
|
throw error;
|
|
3470
3564
|
}
|
|
3471
3565
|
}
|
|
3566
|
+
/**
|
|
3567
|
+
* Calls OpenAI, Anthropic or Resend through QStash, like `context.call`.
|
|
3568
|
+
*
|
|
3569
|
+
* @see node_modules/@upstash/workflow/docs/steps/api.mdx
|
|
3570
|
+
*/
|
|
3472
3571
|
get api() {
|
|
3473
3572
|
return new WorkflowApi({
|
|
3474
3573
|
context: this
|
|
@@ -4251,7 +4350,8 @@ var serveBase = (routeFunction, telemetry, options, internalOptions) => {
|
|
|
4251
4350
|
const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
|
|
4252
4351
|
const retried = Number(request.headers.get(WORKFLOW_RETRIED_HEADER) ?? "0");
|
|
4253
4352
|
const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
|
|
4254
|
-
const
|
|
4353
|
+
const workflowRunCreatedAtHeader = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
|
|
4354
|
+
const workflowRunCreatedAt = workflowRunCreatedAtHeader ? Number(workflowRunCreatedAtHeader) : isFirstInvocation ? Date.now() : 0;
|
|
4255
4355
|
const effectiveConfig = getEffectiveConfig(request.headers);
|
|
4256
4356
|
const workflowContext = new WorkflowContext({
|
|
4257
4357
|
qstashClient: regionalClient,
|
|
@@ -4266,7 +4366,7 @@ var serveBase = (routeFunction, telemetry, options, internalOptions) => {
|
|
|
4266
4366
|
invokeCount,
|
|
4267
4367
|
label,
|
|
4268
4368
|
retried,
|
|
4269
|
-
workflowRunCreatedAt
|
|
4369
|
+
workflowRunCreatedAt,
|
|
4270
4370
|
middlewareManager
|
|
4271
4371
|
});
|
|
4272
4372
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
@@ -4453,6 +4553,7 @@ var DLQ = class {
|
|
|
4453
4553
|
* - `workflowCreatedAt`: Filter items by workflow creation time.
|
|
4454
4554
|
* - `failureFunctionState`: Filter items by failure callback state.
|
|
4455
4555
|
* - `label`: Filter items by label.
|
|
4556
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/list.mdx
|
|
4456
4557
|
*/
|
|
4457
4558
|
async list(parameters) {
|
|
4458
4559
|
const { cursor, count, filter } = parameters || {};
|
|
@@ -4529,6 +4630,7 @@ var DLQ = class {
|
|
|
4529
4630
|
*
|
|
4530
4631
|
* @param dlqId - The ID of the DLQ message to retry
|
|
4531
4632
|
* @returns response with workflow run information
|
|
4633
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/callback.mdx
|
|
4532
4634
|
*/
|
|
4533
4635
|
async retryFailureFunction({ dlqId }) {
|
|
4534
4636
|
assertNonEmptyId(dlqId, "DLQ id");
|
|
@@ -4578,6 +4680,7 @@ var DLQ = class {
|
|
|
4578
4680
|
* cursor = result.cursor;
|
|
4579
4681
|
* } while (cursor);
|
|
4580
4682
|
* ```
|
|
4683
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/delete.mdx
|
|
4581
4684
|
*/
|
|
4582
4685
|
async delete(request) {
|
|
4583
4686
|
if (typeof request === "string" || Array.isArray(request)) {
|
|
@@ -4638,19 +4741,14 @@ var Client4 = class {
|
|
|
4638
4741
|
* });
|
|
4639
4742
|
* ```
|
|
4640
4743
|
*
|
|
4641
|
-
*
|
|
4642
|
-
*
|
|
4643
|
-
* ```ts
|
|
4644
|
-
* await client.notify({
|
|
4645
|
-
* eventId: "my-event-id",
|
|
4646
|
-
* eventData: "my-data",
|
|
4647
|
-
* workflowRunId: "wfr_123" // enables lookback
|
|
4648
|
-
* });
|
|
4649
|
-
* ```
|
|
4650
|
-
*
|
|
4651
|
-
* @param eventId event id to notify
|
|
4744
|
+
* @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed;
|
|
4745
|
+
* QStash rejects other characters, such as ":".
|
|
4652
4746
|
* @param eventData data to provide to the workflow
|
|
4653
|
-
* @param workflowRunId optional workflow run id for lookback
|
|
4747
|
+
* @param workflowRunId optional workflow run id for lookback: the event is kept for the run
|
|
4748
|
+
* even if it has not reached `waitForEvent` yet
|
|
4749
|
+
* @returns the notified waiters. With `workflowRunId`, QStash returns a single object
|
|
4750
|
+
* instead of an array, despite the type.
|
|
4751
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/notify.mdx
|
|
4654
4752
|
*/
|
|
4655
4753
|
async notify({
|
|
4656
4754
|
eventId,
|
|
@@ -4672,6 +4770,7 @@ var Client4 = class {
|
|
|
4672
4770
|
* ```
|
|
4673
4771
|
*
|
|
4674
4772
|
* @param eventId event id to check
|
|
4773
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/waiters.mdx
|
|
4675
4774
|
*/
|
|
4676
4775
|
async getWaiters({ eventId }) {
|
|
4677
4776
|
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
@@ -4747,6 +4846,8 @@ var Client4 = class {
|
|
|
4747
4846
|
*
|
|
4748
4847
|
* const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
|
|
4749
4848
|
* ```
|
|
4849
|
+
*
|
|
4850
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/logs.mdx
|
|
4750
4851
|
*/
|
|
4751
4852
|
async logs(params) {
|
|
4752
4853
|
const { cursor, count, filter, ...legacyFilter } = params ?? {};
|
|
@@ -4761,6 +4862,9 @@ var Client4 = class {
|
|
|
4761
4862
|
}
|
|
4762
4863
|
});
|
|
4763
4864
|
}
|
|
4865
|
+
/**
|
|
4866
|
+
* @see node_modules/@upstash/workflow/docs/features/dlq.mdx
|
|
4867
|
+
*/
|
|
4764
4868
|
get dlq() {
|
|
4765
4869
|
return new DLQ(this.client);
|
|
4766
4870
|
}
|
package/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
triggerFirstInvocation,
|
|
24
24
|
validateFlowControl,
|
|
25
25
|
validateLabel
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-J3PXPHSB.mjs";
|
|
27
27
|
|
|
28
28
|
// src/client/index.ts
|
|
29
29
|
import { Client as QStashClient2 } from "@upstash/qstash";
|
|
@@ -62,6 +62,7 @@ var DLQ = class {
|
|
|
62
62
|
* - `workflowCreatedAt`: Filter items by workflow creation time.
|
|
63
63
|
* - `failureFunctionState`: Filter items by failure callback state.
|
|
64
64
|
* - `label`: Filter items by label.
|
|
65
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/list.mdx
|
|
65
66
|
*/
|
|
66
67
|
async list(parameters) {
|
|
67
68
|
const { cursor, count, filter } = parameters || {};
|
|
@@ -138,6 +139,7 @@ var DLQ = class {
|
|
|
138
139
|
*
|
|
139
140
|
* @param dlqId - The ID of the DLQ message to retry
|
|
140
141
|
* @returns response with workflow run information
|
|
142
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/callback.mdx
|
|
141
143
|
*/
|
|
142
144
|
async retryFailureFunction({ dlqId }) {
|
|
143
145
|
assertNonEmptyId(dlqId, "DLQ id");
|
|
@@ -187,6 +189,7 @@ var DLQ = class {
|
|
|
187
189
|
* cursor = result.cursor;
|
|
188
190
|
* } while (cursor);
|
|
189
191
|
* ```
|
|
192
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/dlq/delete.mdx
|
|
190
193
|
*/
|
|
191
194
|
async delete(request) {
|
|
192
195
|
if (typeof request === "string" || Array.isArray(request)) {
|
|
@@ -247,19 +250,14 @@ var Client = class {
|
|
|
247
250
|
* });
|
|
248
251
|
* ```
|
|
249
252
|
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* ```ts
|
|
253
|
-
* await client.notify({
|
|
254
|
-
* eventId: "my-event-id",
|
|
255
|
-
* eventData: "my-data",
|
|
256
|
-
* workflowRunId: "wfr_123" // enables lookback
|
|
257
|
-
* });
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* @param eventId event id to notify
|
|
253
|
+
* @param eventId event id to notify. Only letters, digits, "-", "_" and "." are allowed;
|
|
254
|
+
* QStash rejects other characters, such as ":".
|
|
261
255
|
* @param eventData data to provide to the workflow
|
|
262
|
-
* @param workflowRunId optional workflow run id for lookback
|
|
256
|
+
* @param workflowRunId optional workflow run id for lookback: the event is kept for the run
|
|
257
|
+
* even if it has not reached `waitForEvent` yet
|
|
258
|
+
* @returns the notified waiters. With `workflowRunId`, QStash returns a single object
|
|
259
|
+
* instead of an array, despite the type.
|
|
260
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/notify.mdx
|
|
263
261
|
*/
|
|
264
262
|
async notify({
|
|
265
263
|
eventId,
|
|
@@ -281,6 +279,7 @@ var Client = class {
|
|
|
281
279
|
* ```
|
|
282
280
|
*
|
|
283
281
|
* @param eventId event id to check
|
|
282
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/waiters.mdx
|
|
284
283
|
*/
|
|
285
284
|
async getWaiters({ eventId }) {
|
|
286
285
|
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
@@ -356,6 +355,8 @@ var Client = class {
|
|
|
356
355
|
*
|
|
357
356
|
* const { runs: nextRuns, cursor: nextCursor } = await client.logs({ cursor, count: 2 });
|
|
358
357
|
* ```
|
|
358
|
+
*
|
|
359
|
+
* @see node_modules/@upstash/workflow/docs/basics/client/logs.mdx
|
|
359
360
|
*/
|
|
360
361
|
async logs(params) {
|
|
361
362
|
const { cursor, count, filter, ...legacyFilter } = params ?? {};
|
|
@@ -370,6 +371,9 @@ var Client = class {
|
|
|
370
371
|
}
|
|
371
372
|
});
|
|
372
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* @see node_modules/@upstash/workflow/docs/features/dlq.mdx
|
|
376
|
+
*/
|
|
373
377
|
get dlq() {
|
|
374
378
|
return new DLQ(this.client);
|
|
375
379
|
}
|
package/nextjs.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { c as RouteFunction, d as WorkflowServeOptions, I as InvokableWorkflow } from './types-CrgK5P6p.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-BKukvLNl.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'neverthrow';
|
|
@@ -10,21 +10,58 @@ import 'neverthrow';
|
|
|
10
10
|
*
|
|
11
11
|
* See for options https://upstash.com/docs/qstash/workflows/basics/serve
|
|
12
12
|
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* // app/api/workflow/route.ts
|
|
15
|
+
* import { serve } from "@upstash/workflow/nextjs";
|
|
16
|
+
*
|
|
17
|
+
* export const { POST } = serve(async (context) => { ... });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Code outside steps runs again on every request of the run. Anything it branches on or
|
|
21
|
+
* returns early on (Date.now(), database rows, random values) must give the same answer on
|
|
22
|
+
* every request, or later requests fail with "Incompatible step name" or "Failed to
|
|
23
|
+
* authenticate Workflow request". Read such values inside `context.run` and branch on its
|
|
24
|
+
* result.
|
|
25
|
+
*
|
|
13
26
|
* @param routeFunction workflow function
|
|
14
27
|
* @param options workflow options
|
|
15
28
|
* @returns
|
|
29
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve.mdx
|
|
30
|
+
* @see node_modules/@upstash/workflow/docs/quickstarts/vercel-nextjs.mdx
|
|
16
31
|
*/
|
|
17
32
|
declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
|
|
18
33
|
POST: (request: Request) => Promise<Response>;
|
|
19
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* @see node_modules/@upstash/workflow/docs/features/invoke.mdx
|
|
37
|
+
*/
|
|
20
38
|
declare const createWorkflow: <TInitialPayload, TResult>(...params: Parameters<typeof serve<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
|
|
39
|
+
/**
|
|
40
|
+
* @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
|
|
41
|
+
*/
|
|
21
42
|
declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
|
|
22
43
|
POST: (request: Request) => Promise<any>;
|
|
23
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Code outside steps runs again on every request of the run. Anything it branches on or
|
|
47
|
+
* returns early on (Date.now(), database rows, random values) must give the same answer on
|
|
48
|
+
* every request, or later requests fail with "Incompatible step name" or "Failed to
|
|
49
|
+
* authenticate Workflow request". Read such values inside `context.run` and branch on its
|
|
50
|
+
* result.
|
|
51
|
+
*
|
|
52
|
+
* @see node_modules/@upstash/workflow/docs/basics/serve.mdx
|
|
53
|
+
* @see node_modules/@upstash/workflow/docs/quickstarts/vercel-nextjs.mdx
|
|
54
|
+
*/
|
|
24
55
|
declare const servePagesRouter: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
|
|
25
56
|
handler: NextApiHandler;
|
|
26
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* @see node_modules/@upstash/workflow/docs/features/invoke.mdx
|
|
60
|
+
*/
|
|
27
61
|
declare const createWorkflowPagesRouter: <TInitialPayload, TResult>(...params: Parameters<typeof servePagesRouter<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
|
|
62
|
+
/**
|
|
63
|
+
* @see node_modules/@upstash/workflow/docs/features/invoke/serveMany.mdx
|
|
64
|
+
*/
|
|
28
65
|
declare const serveManyPagesRouter: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
|
|
29
66
|
handler: (req: NextApiRequest, res: NextApiResponse<any>) => Promise<any>;
|
|
30
67
|
};
|