@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/solidjs.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,8 +11,6 @@ import '@upstash/qstash';
|
|
|
11
11
|
* @param options workflow options
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
15
|
-
POST: (event: APIEvent) => Promise<Response>;
|
|
16
|
-
};
|
|
14
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => (event: APIEvent) => Promise<Response>;
|
|
17
15
|
|
|
18
16
|
export { serve };
|
package/solidjs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,8 +11,6 @@ import '@upstash/qstash';
|
|
|
11
11
|
* @param options workflow options
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
15
|
-
POST: (event: APIEvent) => Promise<Response>;
|
|
16
|
-
};
|
|
14
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => (event: APIEvent) => Promise<Response>;
|
|
17
15
|
|
|
18
16
|
export { serve };
|
package/solidjs.js
CHANGED
|
@@ -474,7 +474,6 @@ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
|
474
474
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
475
475
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
476
476
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
477
|
-
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
478
477
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
479
478
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
480
479
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -560,13 +559,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
560
559
|
try {
|
|
561
560
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
562
561
|
const callbackMessage = JSON.parse(requestPayload);
|
|
563
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)
|
|
562
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
564
563
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
565
564
|
status: callbackMessage.status,
|
|
566
565
|
body: atob(callbackMessage.body)
|
|
567
566
|
});
|
|
568
567
|
console.warn(
|
|
569
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
568
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (if there are retries remaining). Error Message:
|
|
570
569
|
${atob(callbackMessage.body)}`
|
|
571
570
|
);
|
|
572
571
|
return ok("call-will-retry");
|
|
@@ -603,11 +602,7 @@ ${atob(callbackMessage.body)}`
|
|
|
603
602
|
stepId: Number(stepIdString),
|
|
604
603
|
stepName,
|
|
605
604
|
stepType,
|
|
606
|
-
out:
|
|
607
|
-
status: callbackMessage.status,
|
|
608
|
-
body: atob(callbackMessage.body),
|
|
609
|
-
header: callbackMessage.header
|
|
610
|
-
},
|
|
605
|
+
out: atob(callbackMessage.body),
|
|
611
606
|
concurrent: Number(concurrentString)
|
|
612
607
|
};
|
|
613
608
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -642,24 +637,15 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
642
637
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
643
638
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
644
639
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
645
|
-
[
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
653
|
-
}
|
|
654
|
-
if (step?.callUrl) {
|
|
655
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
656
|
-
if (retries) {
|
|
657
|
-
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
658
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
640
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION,
|
|
641
|
+
...failureUrl ? {
|
|
642
|
+
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
643
|
+
"Upstash-Failure-Callback": failureUrl
|
|
644
|
+
} : {},
|
|
645
|
+
...retries === void 0 ? {} : {
|
|
646
|
+
"Upstash-Retries": retries.toString()
|
|
659
647
|
}
|
|
660
|
-
}
|
|
661
|
-
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
662
|
-
}
|
|
648
|
+
};
|
|
663
649
|
if (userHeaders) {
|
|
664
650
|
for (const header of userHeaders.keys()) {
|
|
665
651
|
if (step?.callHeaders) {
|
|
@@ -1124,6 +1110,16 @@ var sortSteps = (steps) => {
|
|
|
1124
1110
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1125
1111
|
};
|
|
1126
1112
|
|
|
1113
|
+
// src/client/utils.ts
|
|
1114
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1115
|
+
const result = await requester.request({
|
|
1116
|
+
path: ["v2", "notify", eventId],
|
|
1117
|
+
method: "POST",
|
|
1118
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1119
|
+
});
|
|
1120
|
+
return result;
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1127
1123
|
// src/context/steps.ts
|
|
1128
1124
|
var BaseLazyStep = class {
|
|
1129
1125
|
stepName;
|
|
@@ -1282,6 +1278,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1282
1278
|
});
|
|
1283
1279
|
}
|
|
1284
1280
|
};
|
|
1281
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1282
|
+
stepType = "Notify";
|
|
1283
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1284
|
+
super(stepName, async () => {
|
|
1285
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1286
|
+
return {
|
|
1287
|
+
eventId,
|
|
1288
|
+
eventData,
|
|
1289
|
+
notifyResponse
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1285
1294
|
|
|
1286
1295
|
// src/context/context.ts
|
|
1287
1296
|
var WorkflowContext = class {
|
|
@@ -1518,13 +1527,48 @@ var WorkflowContext = class {
|
|
|
1518
1527
|
* @returns call result (parsed as JSON if possible)
|
|
1519
1528
|
*/
|
|
1520
1529
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
1521
|
-
async call(stepName,
|
|
1522
|
-
const { url, method = "GET", body, headers = {} } = callSettings;
|
|
1530
|
+
async call(stepName, url, method, body, headers) {
|
|
1523
1531
|
const result = await this.addStep(
|
|
1524
|
-
new LazyCallStep(stepName, url, method, body, headers)
|
|
1532
|
+
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1525
1533
|
);
|
|
1526
|
-
|
|
1534
|
+
try {
|
|
1535
|
+
return JSON.parse(result);
|
|
1536
|
+
} catch {
|
|
1537
|
+
return result;
|
|
1538
|
+
}
|
|
1527
1539
|
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1542
|
+
* timeout ends
|
|
1543
|
+
*
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1546
|
+
* "wait for event step",
|
|
1547
|
+
* "my-event-id",
|
|
1548
|
+
* 100 // timeout after 100 seconds
|
|
1549
|
+
* );
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1553
|
+
*
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* import { Client } from "@upstash/workflow";
|
|
1556
|
+
*
|
|
1557
|
+
* const client = new Client({ token: });
|
|
1558
|
+
*
|
|
1559
|
+
* await client.notify({
|
|
1560
|
+
* eventId: "my-event-id",
|
|
1561
|
+
* eventData: "eventData"
|
|
1562
|
+
* })
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* @param stepName
|
|
1566
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1567
|
+
* @param timeout timeout duration in seconds
|
|
1568
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1569
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1570
|
+
* is the value passed to `client.notify`.
|
|
1571
|
+
*/
|
|
1528
1572
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1529
1573
|
const result = await this.addStep(
|
|
1530
1574
|
new LazyWaitForEventStep(
|
|
@@ -1533,7 +1577,27 @@ var WorkflowContext = class {
|
|
|
1533
1577
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1534
1578
|
)
|
|
1535
1579
|
);
|
|
1536
|
-
|
|
1580
|
+
try {
|
|
1581
|
+
return {
|
|
1582
|
+
...result,
|
|
1583
|
+
eventData: JSON.parse(result.eventData)
|
|
1584
|
+
};
|
|
1585
|
+
} catch {
|
|
1586
|
+
return result;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
async notify(stepName, eventId, eventData) {
|
|
1590
|
+
const result = await this.addStep(
|
|
1591
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1592
|
+
);
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1537
1601
|
}
|
|
1538
1602
|
/**
|
|
1539
1603
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1634,7 +1698,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1634
1698
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1635
1699
|
if (step.waitEventId) {
|
|
1636
1700
|
const newOut = {
|
|
1637
|
-
|
|
1701
|
+
eventData: step.out,
|
|
1638
1702
|
timeout: step.waitTimeout ?? false
|
|
1639
1703
|
};
|
|
1640
1704
|
step.out = newOut;
|
|
@@ -1891,7 +1955,6 @@ var serve = (routeFunction, options) => {
|
|
|
1891
1955
|
} = processOptions(options);
|
|
1892
1956
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1893
1957
|
const handler = async (request) => {
|
|
1894
|
-
await debug?.log("INFO", "ENDPOINT_START");
|
|
1895
1958
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1896
1959
|
request,
|
|
1897
1960
|
url,
|
|
@@ -1935,8 +1998,7 @@ var serve = (routeFunction, options) => {
|
|
|
1935
1998
|
url: workflowUrl,
|
|
1936
1999
|
failureUrl: workflowFailureUrl,
|
|
1937
2000
|
debug,
|
|
1938
|
-
env
|
|
1939
|
-
retries
|
|
2001
|
+
env
|
|
1940
2002
|
});
|
|
1941
2003
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1942
2004
|
routeFunction,
|
|
@@ -1979,7 +2041,7 @@ var serve = (routeFunction, options) => {
|
|
|
1979
2041
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
1980
2042
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
1981
2043
|
};
|
|
1982
|
-
|
|
2044
|
+
return async (request) => {
|
|
1983
2045
|
try {
|
|
1984
2046
|
return await handler(request);
|
|
1985
2047
|
} catch (error) {
|
|
@@ -1989,7 +2051,6 @@ var serve = (routeFunction, options) => {
|
|
|
1989
2051
|
});
|
|
1990
2052
|
}
|
|
1991
2053
|
};
|
|
1992
|
-
return { handler: safeHandler };
|
|
1993
2054
|
};
|
|
1994
2055
|
|
|
1995
2056
|
// src/client/index.ts
|
|
@@ -2004,10 +2065,10 @@ var serve2 = (routeFunction, options) => {
|
|
|
2004
2065
|
status: 405
|
|
2005
2066
|
});
|
|
2006
2067
|
}
|
|
2007
|
-
const
|
|
2068
|
+
const serveHandler = serve(routeFunction, options);
|
|
2008
2069
|
return await serveHandler(event.request);
|
|
2009
2070
|
};
|
|
2010
|
-
return
|
|
2071
|
+
return handler;
|
|
2011
2072
|
};
|
|
2012
2073
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2013
2074
|
0 && (module.exports = {
|
package/solidjs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BPN5JBNG.mjs";
|
|
4
4
|
|
|
5
5
|
// platforms/solidjs.ts
|
|
6
6
|
var serve2 = (routeFunction, options) => {
|
|
@@ -11,10 +11,10 @@ var serve2 = (routeFunction, options) => {
|
|
|
11
11
|
status: 405
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const serveHandler = serve(routeFunction, options);
|
|
15
15
|
return await serveHandler(event.request);
|
|
16
16
|
};
|
|
17
|
-
return
|
|
17
|
+
return handler;
|
|
18
18
|
};
|
|
19
19
|
export {
|
|
20
20
|
serve2 as serve
|
package/svelte.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestHandler } from '@sveltejs/kit';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,8 +13,6 @@ import '@upstash/qstash';
|
|
|
13
13
|
*/
|
|
14
14
|
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish"> & {
|
|
15
15
|
env: WorkflowServeOptions["env"];
|
|
16
|
-
}) =>
|
|
17
|
-
POST: RequestHandler;
|
|
18
|
-
};
|
|
16
|
+
}) => RequestHandler;
|
|
19
17
|
|
|
20
18
|
export { serve };
|
package/svelte.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestHandler } from '@sveltejs/kit';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,8 +13,6 @@ import '@upstash/qstash';
|
|
|
13
13
|
*/
|
|
14
14
|
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish"> & {
|
|
15
15
|
env: WorkflowServeOptions["env"];
|
|
16
|
-
}) =>
|
|
17
|
-
POST: RequestHandler;
|
|
18
|
-
};
|
|
16
|
+
}) => RequestHandler;
|
|
19
17
|
|
|
20
18
|
export { serve };
|
package/svelte.js
CHANGED
|
@@ -474,7 +474,6 @@ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
|
474
474
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
475
475
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
476
476
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
477
|
-
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
478
477
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
479
478
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
480
479
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -560,13 +559,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
560
559
|
try {
|
|
561
560
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
562
561
|
const callbackMessage = JSON.parse(requestPayload);
|
|
563
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)
|
|
562
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
564
563
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
565
564
|
status: callbackMessage.status,
|
|
566
565
|
body: atob(callbackMessage.body)
|
|
567
566
|
});
|
|
568
567
|
console.warn(
|
|
569
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
568
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (if there are retries remaining). Error Message:
|
|
570
569
|
${atob(callbackMessage.body)}`
|
|
571
570
|
);
|
|
572
571
|
return ok("call-will-retry");
|
|
@@ -603,11 +602,7 @@ ${atob(callbackMessage.body)}`
|
|
|
603
602
|
stepId: Number(stepIdString),
|
|
604
603
|
stepName,
|
|
605
604
|
stepType,
|
|
606
|
-
out:
|
|
607
|
-
status: callbackMessage.status,
|
|
608
|
-
body: atob(callbackMessage.body),
|
|
609
|
-
header: callbackMessage.header
|
|
610
|
-
},
|
|
605
|
+
out: atob(callbackMessage.body),
|
|
611
606
|
concurrent: Number(concurrentString)
|
|
612
607
|
};
|
|
613
608
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -642,24 +637,15 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
642
637
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
643
638
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
644
639
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
645
|
-
[
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
653
|
-
}
|
|
654
|
-
if (step?.callUrl) {
|
|
655
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
656
|
-
if (retries) {
|
|
657
|
-
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
658
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
640
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION,
|
|
641
|
+
...failureUrl ? {
|
|
642
|
+
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
643
|
+
"Upstash-Failure-Callback": failureUrl
|
|
644
|
+
} : {},
|
|
645
|
+
...retries === void 0 ? {} : {
|
|
646
|
+
"Upstash-Retries": retries.toString()
|
|
659
647
|
}
|
|
660
|
-
}
|
|
661
|
-
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
662
|
-
}
|
|
648
|
+
};
|
|
663
649
|
if (userHeaders) {
|
|
664
650
|
for (const header of userHeaders.keys()) {
|
|
665
651
|
if (step?.callHeaders) {
|
|
@@ -1124,6 +1110,16 @@ var sortSteps = (steps) => {
|
|
|
1124
1110
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1125
1111
|
};
|
|
1126
1112
|
|
|
1113
|
+
// src/client/utils.ts
|
|
1114
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1115
|
+
const result = await requester.request({
|
|
1116
|
+
path: ["v2", "notify", eventId],
|
|
1117
|
+
method: "POST",
|
|
1118
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1119
|
+
});
|
|
1120
|
+
return result;
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1127
1123
|
// src/context/steps.ts
|
|
1128
1124
|
var BaseLazyStep = class {
|
|
1129
1125
|
stepName;
|
|
@@ -1282,6 +1278,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1282
1278
|
});
|
|
1283
1279
|
}
|
|
1284
1280
|
};
|
|
1281
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1282
|
+
stepType = "Notify";
|
|
1283
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1284
|
+
super(stepName, async () => {
|
|
1285
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1286
|
+
return {
|
|
1287
|
+
eventId,
|
|
1288
|
+
eventData,
|
|
1289
|
+
notifyResponse
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1285
1294
|
|
|
1286
1295
|
// src/context/context.ts
|
|
1287
1296
|
var WorkflowContext = class {
|
|
@@ -1518,13 +1527,48 @@ var WorkflowContext = class {
|
|
|
1518
1527
|
* @returns call result (parsed as JSON if possible)
|
|
1519
1528
|
*/
|
|
1520
1529
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
1521
|
-
async call(stepName,
|
|
1522
|
-
const { url, method = "GET", body, headers = {} } = callSettings;
|
|
1530
|
+
async call(stepName, url, method, body, headers) {
|
|
1523
1531
|
const result = await this.addStep(
|
|
1524
|
-
new LazyCallStep(stepName, url, method, body, headers)
|
|
1532
|
+
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1525
1533
|
);
|
|
1526
|
-
|
|
1534
|
+
try {
|
|
1535
|
+
return JSON.parse(result);
|
|
1536
|
+
} catch {
|
|
1537
|
+
return result;
|
|
1538
|
+
}
|
|
1527
1539
|
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1542
|
+
* timeout ends
|
|
1543
|
+
*
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1546
|
+
* "wait for event step",
|
|
1547
|
+
* "my-event-id",
|
|
1548
|
+
* 100 // timeout after 100 seconds
|
|
1549
|
+
* );
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1553
|
+
*
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* import { Client } from "@upstash/workflow";
|
|
1556
|
+
*
|
|
1557
|
+
* const client = new Client({ token: });
|
|
1558
|
+
*
|
|
1559
|
+
* await client.notify({
|
|
1560
|
+
* eventId: "my-event-id",
|
|
1561
|
+
* eventData: "eventData"
|
|
1562
|
+
* })
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* @param stepName
|
|
1566
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1567
|
+
* @param timeout timeout duration in seconds
|
|
1568
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1569
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1570
|
+
* is the value passed to `client.notify`.
|
|
1571
|
+
*/
|
|
1528
1572
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1529
1573
|
const result = await this.addStep(
|
|
1530
1574
|
new LazyWaitForEventStep(
|
|
@@ -1533,7 +1577,27 @@ var WorkflowContext = class {
|
|
|
1533
1577
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1534
1578
|
)
|
|
1535
1579
|
);
|
|
1536
|
-
|
|
1580
|
+
try {
|
|
1581
|
+
return {
|
|
1582
|
+
...result,
|
|
1583
|
+
eventData: JSON.parse(result.eventData)
|
|
1584
|
+
};
|
|
1585
|
+
} catch {
|
|
1586
|
+
return result;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
async notify(stepName, eventId, eventData) {
|
|
1590
|
+
const result = await this.addStep(
|
|
1591
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1592
|
+
);
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1537
1601
|
}
|
|
1538
1602
|
/**
|
|
1539
1603
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1634,7 +1698,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1634
1698
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1635
1699
|
if (step.waitEventId) {
|
|
1636
1700
|
const newOut = {
|
|
1637
|
-
|
|
1701
|
+
eventData: step.out,
|
|
1638
1702
|
timeout: step.waitTimeout ?? false
|
|
1639
1703
|
};
|
|
1640
1704
|
step.out = newOut;
|
|
@@ -1891,7 +1955,6 @@ var serve = (routeFunction, options) => {
|
|
|
1891
1955
|
} = processOptions(options);
|
|
1892
1956
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1893
1957
|
const handler = async (request) => {
|
|
1894
|
-
await debug?.log("INFO", "ENDPOINT_START");
|
|
1895
1958
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1896
1959
|
request,
|
|
1897
1960
|
url,
|
|
@@ -1935,8 +1998,7 @@ var serve = (routeFunction, options) => {
|
|
|
1935
1998
|
url: workflowUrl,
|
|
1936
1999
|
failureUrl: workflowFailureUrl,
|
|
1937
2000
|
debug,
|
|
1938
|
-
env
|
|
1939
|
-
retries
|
|
2001
|
+
env
|
|
1940
2002
|
});
|
|
1941
2003
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1942
2004
|
routeFunction,
|
|
@@ -1979,7 +2041,7 @@ var serve = (routeFunction, options) => {
|
|
|
1979
2041
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
1980
2042
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
1981
2043
|
};
|
|
1982
|
-
|
|
2044
|
+
return async (request) => {
|
|
1983
2045
|
try {
|
|
1984
2046
|
return await handler(request);
|
|
1985
2047
|
} catch (error) {
|
|
@@ -1989,7 +2051,6 @@ var serve = (routeFunction, options) => {
|
|
|
1989
2051
|
});
|
|
1990
2052
|
}
|
|
1991
2053
|
};
|
|
1992
|
-
return { handler: safeHandler };
|
|
1993
2054
|
};
|
|
1994
2055
|
|
|
1995
2056
|
// src/client/index.ts
|
|
@@ -1998,10 +2059,10 @@ var import_qstash5 = require("@upstash/qstash");
|
|
|
1998
2059
|
// platforms/svelte.ts
|
|
1999
2060
|
var serve2 = (routeFunction, options) => {
|
|
2000
2061
|
const handler = async ({ request }) => {
|
|
2001
|
-
const
|
|
2002
|
-
return await
|
|
2062
|
+
const serveMethod = serve(routeFunction, options);
|
|
2063
|
+
return await serveMethod(request);
|
|
2003
2064
|
};
|
|
2004
|
-
return
|
|
2065
|
+
return handler;
|
|
2005
2066
|
};
|
|
2006
2067
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2007
2068
|
0 && (module.exports = {
|
package/svelte.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BPN5JBNG.mjs";
|
|
4
4
|
|
|
5
5
|
// platforms/svelte.ts
|
|
6
6
|
var serve2 = (routeFunction, options) => {
|
|
7
7
|
const handler = async ({ request }) => {
|
|
8
|
-
const
|
|
9
|
-
return await
|
|
8
|
+
const serveMethod = serve(routeFunction, options);
|
|
9
|
+
return await serveMethod(request);
|
|
10
10
|
};
|
|
11
|
-
return
|
|
11
|
+
return handler;
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
14
|
serve2 as serve
|