@upstash/workflow 0.1.1-canary → 0.1.1-canary-2
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/{chunk-YW5KUHA2.mjs → chunk-BPN5JBNG.mjs} +116 -45
- package/cloudflare.d.mts +2 -4
- package/cloudflare.d.ts +2 -4
- package/cloudflare.js +100 -39
- package/cloudflare.mjs +4 -4
- package/h3.d.mts +5 -7
- package/h3.d.ts +5 -7
- package/h3.js +99 -38
- package/h3.mjs +3 -3
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +98 -37
- package/hono.mjs +2 -2
- package/index.d.mts +15 -9
- package/index.d.ts +15 -9
- package/index.js +116 -45
- package/index.mjs +1 -1
- package/nextjs.d.mts +4 -7
- package/nextjs.d.ts +4 -7
- package/nextjs.js +105 -46
- package/nextjs.mjs +9 -11
- package/package.json +1 -1
- package/solidjs.d.mts +2 -4
- package/solidjs.d.ts +2 -4
- package/solidjs.js +99 -38
- package/solidjs.mjs +3 -3
- package/svelte.d.mts +2 -4
- package/svelte.d.ts +2 -4
- package/svelte.js +100 -39
- package/svelte.mjs +4 -4
- package/{types-D8FBKkto.d.mts → types-CoXaNrxX.d.mts} +57 -18
- package/{types-D8FBKkto.d.ts → types-CoXaNrxX.d.ts} +57 -18
package/index.js
CHANGED
|
@@ -480,7 +480,6 @@ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
|
480
480
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
481
481
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
482
482
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
483
|
-
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
484
483
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
485
484
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
486
485
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -566,13 +565,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
566
565
|
try {
|
|
567
566
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
568
567
|
const callbackMessage = JSON.parse(requestPayload);
|
|
569
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)
|
|
568
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
570
569
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
571
570
|
status: callbackMessage.status,
|
|
572
571
|
body: atob(callbackMessage.body)
|
|
573
572
|
});
|
|
574
573
|
console.warn(
|
|
575
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
574
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (if there are retries remaining). Error Message:
|
|
576
575
|
${atob(callbackMessage.body)}`
|
|
577
576
|
);
|
|
578
577
|
return ok("call-will-retry");
|
|
@@ -609,11 +608,7 @@ ${atob(callbackMessage.body)}`
|
|
|
609
608
|
stepId: Number(stepIdString),
|
|
610
609
|
stepName,
|
|
611
610
|
stepType,
|
|
612
|
-
out:
|
|
613
|
-
status: callbackMessage.status,
|
|
614
|
-
body: atob(callbackMessage.body),
|
|
615
|
-
header: callbackMessage.header
|
|
616
|
-
},
|
|
611
|
+
out: atob(callbackMessage.body),
|
|
617
612
|
concurrent: Number(concurrentString)
|
|
618
613
|
};
|
|
619
614
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -648,24 +643,15 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
648
643
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
649
644
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
650
645
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
651
|
-
[
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
659
|
-
}
|
|
660
|
-
if (step?.callUrl) {
|
|
661
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
662
|
-
if (retries) {
|
|
663
|
-
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
664
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
646
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION,
|
|
647
|
+
...failureUrl ? {
|
|
648
|
+
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
649
|
+
"Upstash-Failure-Callback": failureUrl
|
|
650
|
+
} : {},
|
|
651
|
+
...retries === void 0 ? {} : {
|
|
652
|
+
"Upstash-Retries": retries.toString()
|
|
665
653
|
}
|
|
666
|
-
}
|
|
667
|
-
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
668
|
-
}
|
|
654
|
+
};
|
|
669
655
|
if (userHeaders) {
|
|
670
656
|
for (const header of userHeaders.keys()) {
|
|
671
657
|
if (step?.callHeaders) {
|
|
@@ -1130,6 +1116,23 @@ var sortSteps = (steps) => {
|
|
|
1130
1116
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1131
1117
|
};
|
|
1132
1118
|
|
|
1119
|
+
// src/client/utils.ts
|
|
1120
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1121
|
+
const result = await requester.request({
|
|
1122
|
+
path: ["v2", "notify", eventId],
|
|
1123
|
+
method: "POST",
|
|
1124
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1125
|
+
});
|
|
1126
|
+
return result;
|
|
1127
|
+
};
|
|
1128
|
+
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
1129
|
+
const result = await requester.request({
|
|
1130
|
+
path: ["v2", "waiters", eventId],
|
|
1131
|
+
method: "GET"
|
|
1132
|
+
});
|
|
1133
|
+
return result;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1133
1136
|
// src/context/steps.ts
|
|
1134
1137
|
var BaseLazyStep = class {
|
|
1135
1138
|
stepName;
|
|
@@ -1288,6 +1291,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1288
1291
|
});
|
|
1289
1292
|
}
|
|
1290
1293
|
};
|
|
1294
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1295
|
+
stepType = "Notify";
|
|
1296
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1297
|
+
super(stepName, async () => {
|
|
1298
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1299
|
+
return {
|
|
1300
|
+
eventId,
|
|
1301
|
+
eventData,
|
|
1302
|
+
notifyResponse
|
|
1303
|
+
};
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1291
1307
|
|
|
1292
1308
|
// src/context/context.ts
|
|
1293
1309
|
var WorkflowContext = class {
|
|
@@ -1524,13 +1540,48 @@ var WorkflowContext = class {
|
|
|
1524
1540
|
* @returns call result (parsed as JSON if possible)
|
|
1525
1541
|
*/
|
|
1526
1542
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
1527
|
-
async call(stepName,
|
|
1528
|
-
const { url, method = "GET", body, headers = {} } = callSettings;
|
|
1543
|
+
async call(stepName, url, method, body, headers) {
|
|
1529
1544
|
const result = await this.addStep(
|
|
1530
|
-
new LazyCallStep(stepName, url, method, body, headers)
|
|
1545
|
+
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1531
1546
|
);
|
|
1532
|
-
|
|
1547
|
+
try {
|
|
1548
|
+
return JSON.parse(result);
|
|
1549
|
+
} catch {
|
|
1550
|
+
return result;
|
|
1551
|
+
}
|
|
1533
1552
|
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1555
|
+
* timeout ends
|
|
1556
|
+
*
|
|
1557
|
+
* ```ts
|
|
1558
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1559
|
+
* "wait for event step",
|
|
1560
|
+
* "my-event-id",
|
|
1561
|
+
* 100 // timeout after 100 seconds
|
|
1562
|
+
* );
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1566
|
+
*
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* import { Client } from "@upstash/workflow";
|
|
1569
|
+
*
|
|
1570
|
+
* const client = new Client({ token: });
|
|
1571
|
+
*
|
|
1572
|
+
* await client.notify({
|
|
1573
|
+
* eventId: "my-event-id",
|
|
1574
|
+
* eventData: "eventData"
|
|
1575
|
+
* })
|
|
1576
|
+
* ```
|
|
1577
|
+
*
|
|
1578
|
+
* @param stepName
|
|
1579
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1580
|
+
* @param timeout timeout duration in seconds
|
|
1581
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1582
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1583
|
+
* is the value passed to `client.notify`.
|
|
1584
|
+
*/
|
|
1534
1585
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1535
1586
|
const result = await this.addStep(
|
|
1536
1587
|
new LazyWaitForEventStep(
|
|
@@ -1539,7 +1590,27 @@ var WorkflowContext = class {
|
|
|
1539
1590
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1540
1591
|
)
|
|
1541
1592
|
);
|
|
1542
|
-
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
async notify(stepName, eventId, eventData) {
|
|
1603
|
+
const result = await this.addStep(
|
|
1604
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1605
|
+
);
|
|
1606
|
+
try {
|
|
1607
|
+
return {
|
|
1608
|
+
...result,
|
|
1609
|
+
eventData: JSON.parse(result.eventData)
|
|
1610
|
+
};
|
|
1611
|
+
} catch {
|
|
1612
|
+
return result;
|
|
1613
|
+
}
|
|
1543
1614
|
}
|
|
1544
1615
|
/**
|
|
1545
1616
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1640,7 +1711,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1640
1711
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1641
1712
|
if (step.waitEventId) {
|
|
1642
1713
|
const newOut = {
|
|
1643
|
-
|
|
1714
|
+
eventData: step.out,
|
|
1644
1715
|
timeout: step.waitTimeout ?? false
|
|
1645
1716
|
};
|
|
1646
1717
|
step.out = newOut;
|
|
@@ -1897,7 +1968,6 @@ var serve = (routeFunction, options) => {
|
|
|
1897
1968
|
} = processOptions(options);
|
|
1898
1969
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1899
1970
|
const handler = async (request) => {
|
|
1900
|
-
await debug?.log("INFO", "ENDPOINT_START");
|
|
1901
1971
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1902
1972
|
request,
|
|
1903
1973
|
url,
|
|
@@ -1941,8 +2011,7 @@ var serve = (routeFunction, options) => {
|
|
|
1941
2011
|
url: workflowUrl,
|
|
1942
2012
|
failureUrl: workflowFailureUrl,
|
|
1943
2013
|
debug,
|
|
1944
|
-
env
|
|
1945
|
-
retries
|
|
2014
|
+
env
|
|
1946
2015
|
});
|
|
1947
2016
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1948
2017
|
routeFunction,
|
|
@@ -1985,7 +2054,7 @@ var serve = (routeFunction, options) => {
|
|
|
1985
2054
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
1986
2055
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
1987
2056
|
};
|
|
1988
|
-
|
|
2057
|
+
return async (request) => {
|
|
1989
2058
|
try {
|
|
1990
2059
|
return await handler(request);
|
|
1991
2060
|
} catch (error) {
|
|
@@ -1995,7 +2064,6 @@ var serve = (routeFunction, options) => {
|
|
|
1995
2064
|
});
|
|
1996
2065
|
}
|
|
1997
2066
|
};
|
|
1998
|
-
return { handler: safeHandler };
|
|
1999
2067
|
};
|
|
2000
2068
|
|
|
2001
2069
|
// src/client/index.ts
|
|
@@ -2003,7 +2071,7 @@ var import_qstash5 = require("@upstash/qstash");
|
|
|
2003
2071
|
var Client3 = class {
|
|
2004
2072
|
client;
|
|
2005
2073
|
constructor(clientConfig) {
|
|
2006
|
-
if (!clientConfig.
|
|
2074
|
+
if (!clientConfig.token) {
|
|
2007
2075
|
console.warn("[Upstash Workflow] url or the token is not set. client will not work.");
|
|
2008
2076
|
}
|
|
2009
2077
|
this.client = new import_qstash5.Client(clientConfig);
|
|
@@ -2026,18 +2094,21 @@ var Client3 = class {
|
|
|
2026
2094
|
* Notify a workflow run waiting for an event
|
|
2027
2095
|
*
|
|
2028
2096
|
* @param eventId event id to notify
|
|
2029
|
-
* @param
|
|
2097
|
+
* @param eventData data to provide to the workflow
|
|
2030
2098
|
*/
|
|
2031
2099
|
async notify({
|
|
2032
2100
|
eventId,
|
|
2033
|
-
|
|
2101
|
+
eventData
|
|
2034
2102
|
}) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2103
|
+
return await makeNotifyRequest(this.client.http, eventId, eventData);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Check waiters of an event
|
|
2107
|
+
*
|
|
2108
|
+
* @param eventId event id to check
|
|
2109
|
+
*/
|
|
2110
|
+
async getWaiters({ eventId }) {
|
|
2111
|
+
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
2041
2112
|
}
|
|
2042
2113
|
};
|
|
2043
2114
|
// Annotate the CommonJS export names for ESM import in node:
|
package/index.mjs
CHANGED
package/nextjs.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
|
-
import {
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.mjs';
|
|
3
4
|
import '@upstash/qstash';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -11,11 +12,7 @@ import '@upstash/qstash';
|
|
|
11
12
|
* @param options workflow options
|
|
12
13
|
* @returns
|
|
13
14
|
*/
|
|
14
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
declare const servePagesRouter: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
18
|
-
handler: NextApiHandler;
|
|
19
|
-
};
|
|
15
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<NextResponse, TInitialPayload>, "onStepFinish">) => ((request: Request) => Promise<NextResponse>);
|
|
16
|
+
declare const servePagesRouter: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => NextApiHandler;
|
|
20
17
|
|
|
21
18
|
export { serve, servePagesRouter };
|
package/nextjs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
|
-
import {
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.js';
|
|
3
4
|
import '@upstash/qstash';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -11,11 +12,7 @@ import '@upstash/qstash';
|
|
|
11
12
|
* @param options workflow options
|
|
12
13
|
* @returns
|
|
13
14
|
*/
|
|
14
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
declare const servePagesRouter: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
18
|
-
handler: NextApiHandler;
|
|
19
|
-
};
|
|
15
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<NextResponse, TInitialPayload>, "onStepFinish">) => ((request: Request) => Promise<NextResponse>);
|
|
16
|
+
declare const servePagesRouter: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => NextApiHandler;
|
|
20
17
|
|
|
21
18
|
export { serve, servePagesRouter };
|
package/nextjs.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(nextjs_exports, {
|
|
|
24
24
|
servePagesRouter: () => servePagesRouter
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(nextjs_exports);
|
|
27
|
+
var import_server = require("next/server");
|
|
27
28
|
|
|
28
29
|
// src/error.ts
|
|
29
30
|
var import_qstash = require("@upstash/qstash");
|
|
@@ -475,7 +476,6 @@ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
|
475
476
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
476
477
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
477
478
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
478
|
-
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
479
479
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
480
480
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
481
481
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -561,13 +561,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
561
561
|
try {
|
|
562
562
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
563
563
|
const callbackMessage = JSON.parse(requestPayload);
|
|
564
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)
|
|
564
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
565
565
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
566
566
|
status: callbackMessage.status,
|
|
567
567
|
body: atob(callbackMessage.body)
|
|
568
568
|
});
|
|
569
569
|
console.warn(
|
|
570
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
570
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (if there are retries remaining). Error Message:
|
|
571
571
|
${atob(callbackMessage.body)}`
|
|
572
572
|
);
|
|
573
573
|
return ok("call-will-retry");
|
|
@@ -604,11 +604,7 @@ ${atob(callbackMessage.body)}`
|
|
|
604
604
|
stepId: Number(stepIdString),
|
|
605
605
|
stepName,
|
|
606
606
|
stepType,
|
|
607
|
-
out:
|
|
608
|
-
status: callbackMessage.status,
|
|
609
|
-
body: atob(callbackMessage.body),
|
|
610
|
-
header: callbackMessage.header
|
|
611
|
-
},
|
|
607
|
+
out: atob(callbackMessage.body),
|
|
612
608
|
concurrent: Number(concurrentString)
|
|
613
609
|
};
|
|
614
610
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -643,24 +639,15 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
643
639
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
644
640
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
645
641
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
646
|
-
[
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
654
|
-
}
|
|
655
|
-
if (step?.callUrl) {
|
|
656
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
657
|
-
if (retries) {
|
|
658
|
-
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
659
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
642
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION,
|
|
643
|
+
...failureUrl ? {
|
|
644
|
+
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
645
|
+
"Upstash-Failure-Callback": failureUrl
|
|
646
|
+
} : {},
|
|
647
|
+
...retries === void 0 ? {} : {
|
|
648
|
+
"Upstash-Retries": retries.toString()
|
|
660
649
|
}
|
|
661
|
-
}
|
|
662
|
-
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
663
|
-
}
|
|
650
|
+
};
|
|
664
651
|
if (userHeaders) {
|
|
665
652
|
for (const header of userHeaders.keys()) {
|
|
666
653
|
if (step?.callHeaders) {
|
|
@@ -1125,6 +1112,16 @@ var sortSteps = (steps) => {
|
|
|
1125
1112
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1126
1113
|
};
|
|
1127
1114
|
|
|
1115
|
+
// src/client/utils.ts
|
|
1116
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1117
|
+
const result = await requester.request({
|
|
1118
|
+
path: ["v2", "notify", eventId],
|
|
1119
|
+
method: "POST",
|
|
1120
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1121
|
+
});
|
|
1122
|
+
return result;
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1128
1125
|
// src/context/steps.ts
|
|
1129
1126
|
var BaseLazyStep = class {
|
|
1130
1127
|
stepName;
|
|
@@ -1283,6 +1280,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1283
1280
|
});
|
|
1284
1281
|
}
|
|
1285
1282
|
};
|
|
1283
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1284
|
+
stepType = "Notify";
|
|
1285
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1286
|
+
super(stepName, async () => {
|
|
1287
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1288
|
+
return {
|
|
1289
|
+
eventId,
|
|
1290
|
+
eventData,
|
|
1291
|
+
notifyResponse
|
|
1292
|
+
};
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1286
1296
|
|
|
1287
1297
|
// src/context/context.ts
|
|
1288
1298
|
var WorkflowContext = class {
|
|
@@ -1519,13 +1529,48 @@ var WorkflowContext = class {
|
|
|
1519
1529
|
* @returns call result (parsed as JSON if possible)
|
|
1520
1530
|
*/
|
|
1521
1531
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
1522
|
-
async call(stepName,
|
|
1523
|
-
const { url, method = "GET", body, headers = {} } = callSettings;
|
|
1532
|
+
async call(stepName, url, method, body, headers) {
|
|
1524
1533
|
const result = await this.addStep(
|
|
1525
|
-
new LazyCallStep(stepName, url, method, body, headers)
|
|
1534
|
+
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1526
1535
|
);
|
|
1527
|
-
|
|
1536
|
+
try {
|
|
1537
|
+
return JSON.parse(result);
|
|
1538
|
+
} catch {
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1528
1541
|
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1544
|
+
* timeout ends
|
|
1545
|
+
*
|
|
1546
|
+
* ```ts
|
|
1547
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1548
|
+
* "wait for event step",
|
|
1549
|
+
* "my-event-id",
|
|
1550
|
+
* 100 // timeout after 100 seconds
|
|
1551
|
+
* );
|
|
1552
|
+
* ```
|
|
1553
|
+
*
|
|
1554
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1555
|
+
*
|
|
1556
|
+
* ```ts
|
|
1557
|
+
* import { Client } from "@upstash/workflow";
|
|
1558
|
+
*
|
|
1559
|
+
* const client = new Client({ token: });
|
|
1560
|
+
*
|
|
1561
|
+
* await client.notify({
|
|
1562
|
+
* eventId: "my-event-id",
|
|
1563
|
+
* eventData: "eventData"
|
|
1564
|
+
* })
|
|
1565
|
+
* ```
|
|
1566
|
+
*
|
|
1567
|
+
* @param stepName
|
|
1568
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1569
|
+
* @param timeout timeout duration in seconds
|
|
1570
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1571
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1572
|
+
* is the value passed to `client.notify`.
|
|
1573
|
+
*/
|
|
1529
1574
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1530
1575
|
const result = await this.addStep(
|
|
1531
1576
|
new LazyWaitForEventStep(
|
|
@@ -1534,7 +1579,27 @@ var WorkflowContext = class {
|
|
|
1534
1579
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1535
1580
|
)
|
|
1536
1581
|
);
|
|
1537
|
-
|
|
1582
|
+
try {
|
|
1583
|
+
return {
|
|
1584
|
+
...result,
|
|
1585
|
+
eventData: JSON.parse(result.eventData)
|
|
1586
|
+
};
|
|
1587
|
+
} catch {
|
|
1588
|
+
return result;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
async notify(stepName, eventId, eventData) {
|
|
1592
|
+
const result = await this.addStep(
|
|
1593
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1594
|
+
);
|
|
1595
|
+
try {
|
|
1596
|
+
return {
|
|
1597
|
+
...result,
|
|
1598
|
+
eventData: JSON.parse(result.eventData)
|
|
1599
|
+
};
|
|
1600
|
+
} catch {
|
|
1601
|
+
return result;
|
|
1602
|
+
}
|
|
1538
1603
|
}
|
|
1539
1604
|
/**
|
|
1540
1605
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1635,7 +1700,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1635
1700
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1636
1701
|
if (step.waitEventId) {
|
|
1637
1702
|
const newOut = {
|
|
1638
|
-
|
|
1703
|
+
eventData: step.out,
|
|
1639
1704
|
timeout: step.waitTimeout ?? false
|
|
1640
1705
|
};
|
|
1641
1706
|
step.out = newOut;
|
|
@@ -1892,7 +1957,6 @@ var serve = (routeFunction, options) => {
|
|
|
1892
1957
|
} = processOptions(options);
|
|
1893
1958
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1894
1959
|
const handler = async (request) => {
|
|
1895
|
-
await debug?.log("INFO", "ENDPOINT_START");
|
|
1896
1960
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1897
1961
|
request,
|
|
1898
1962
|
url,
|
|
@@ -1936,8 +2000,7 @@ var serve = (routeFunction, options) => {
|
|
|
1936
2000
|
url: workflowUrl,
|
|
1937
2001
|
failureUrl: workflowFailureUrl,
|
|
1938
2002
|
debug,
|
|
1939
|
-
env
|
|
1940
|
-
retries
|
|
2003
|
+
env
|
|
1941
2004
|
});
|
|
1942
2005
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1943
2006
|
routeFunction,
|
|
@@ -1980,7 +2043,7 @@ var serve = (routeFunction, options) => {
|
|
|
1980
2043
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
1981
2044
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
1982
2045
|
};
|
|
1983
|
-
|
|
2046
|
+
return async (request) => {
|
|
1984
2047
|
try {
|
|
1985
2048
|
return await handler(request);
|
|
1986
2049
|
} catch (error) {
|
|
@@ -1990,7 +2053,6 @@ var serve = (routeFunction, options) => {
|
|
|
1990
2053
|
});
|
|
1991
2054
|
}
|
|
1992
2055
|
};
|
|
1993
|
-
return { handler: safeHandler };
|
|
1994
2056
|
};
|
|
1995
2057
|
|
|
1996
2058
|
// src/client/index.ts
|
|
@@ -1998,19 +2060,17 @@ var import_qstash5 = require("@upstash/qstash");
|
|
|
1998
2060
|
|
|
1999
2061
|
// platforms/nextjs.ts
|
|
2000
2062
|
var serve2 = (routeFunction, options) => {
|
|
2001
|
-
const
|
|
2002
|
-
onStepFinish: (workflowRunId) => new
|
|
2063
|
+
const handler = serve(routeFunction, {
|
|
2064
|
+
onStepFinish: (workflowRunId) => new import_server.NextResponse(JSON.stringify({ workflowRunId }), { status: 200 }),
|
|
2003
2065
|
...options
|
|
2004
2066
|
});
|
|
2005
|
-
return {
|
|
2006
|
-
|
|
2007
|
-
return await serveHandler(request);
|
|
2008
|
-
}
|
|
2067
|
+
return async (request) => {
|
|
2068
|
+
return await handler(request);
|
|
2009
2069
|
};
|
|
2010
2070
|
};
|
|
2011
2071
|
var servePagesRouter = (routeFunction, options) => {
|
|
2012
|
-
const
|
|
2013
|
-
|
|
2072
|
+
const handler = serve(routeFunction, options);
|
|
2073
|
+
return async (request_, res) => {
|
|
2014
2074
|
if (request_.method?.toUpperCase() !== "POST") {
|
|
2015
2075
|
res.status(405).json("Only POST requests are allowed in worklfows");
|
|
2016
2076
|
return;
|
|
@@ -2026,10 +2086,9 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
2026
2086
|
headers: new Headers(request_.headersDistinct),
|
|
2027
2087
|
method: "POST"
|
|
2028
2088
|
});
|
|
2029
|
-
const response = await
|
|
2089
|
+
const response = await handler(request);
|
|
2030
2090
|
res.status(response.status).json(await response.json());
|
|
2031
2091
|
};
|
|
2032
|
-
return { handler };
|
|
2033
2092
|
};
|
|
2034
2093
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2035
2094
|
0 && (module.exports = {
|
package/nextjs.mjs
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BPN5JBNG.mjs";
|
|
4
4
|
|
|
5
5
|
// platforms/nextjs.ts
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
6
7
|
var serve2 = (routeFunction, options) => {
|
|
7
|
-
const
|
|
8
|
-
onStepFinish: (workflowRunId) => new
|
|
8
|
+
const handler = serve(routeFunction, {
|
|
9
|
+
onStepFinish: (workflowRunId) => new NextResponse(JSON.stringify({ workflowRunId }), { status: 200 }),
|
|
9
10
|
...options
|
|
10
11
|
});
|
|
11
|
-
return {
|
|
12
|
-
|
|
13
|
-
return await serveHandler(request);
|
|
14
|
-
}
|
|
12
|
+
return async (request) => {
|
|
13
|
+
return await handler(request);
|
|
15
14
|
};
|
|
16
15
|
};
|
|
17
16
|
var servePagesRouter = (routeFunction, options) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
const handler = serve(routeFunction, options);
|
|
18
|
+
return async (request_, res) => {
|
|
20
19
|
if (request_.method?.toUpperCase() !== "POST") {
|
|
21
20
|
res.status(405).json("Only POST requests are allowed in worklfows");
|
|
22
21
|
return;
|
|
@@ -32,10 +31,9 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
32
31
|
headers: new Headers(request_.headersDistinct),
|
|
33
32
|
method: "POST"
|
|
34
33
|
});
|
|
35
|
-
const response = await
|
|
34
|
+
const response = await handler(request);
|
|
36
35
|
res.status(response.status).json(await response.json());
|
|
37
36
|
};
|
|
38
|
-
return { handler };
|
|
39
37
|
};
|
|
40
38
|
export {
|
|
41
39
|
serve2 as serve,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/workflow","version":"v0.1.1-canary","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsc":"^2.0.4","tsup":"^8.3.0","typescript":"5.4.5","typescript-eslint":"^8.8.0"},"dependencies":{"@upstash/qstash":"^2.7.12"}
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.1.1-canary-2","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsc":"^2.0.4","tsup":"^8.3.0","typescript":"5.4.5","typescript-eslint":"^8.8.0"},"dependencies":{"@upstash/qstash":"^2.7.12"}}
|