@upstash/workflow 0.1.1-canary-2 → 0.1.1
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 +119 -2
- package/{chunk-BPN5JBNG.mjs → chunk-XPMFG3Q4.mjs} +85 -18
- package/cloudflare.d.mts +4 -2
- package/cloudflare.d.ts +4 -2
- package/cloudflare.js +62 -21
- package/cloudflare.mjs +4 -4
- package/h3.d.mts +7 -5
- package/h3.d.ts +7 -5
- package/h3.js +61 -20
- package/h3.mjs +3 -3
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +60 -19
- package/hono.mjs +2 -2
- package/index.d.mts +41 -4
- package/index.d.ts +41 -4
- package/index.js +85 -18
- package/index.mjs +1 -1
- package/nextjs.d.mts +7 -4
- package/nextjs.d.ts +7 -4
- package/nextjs.js +69 -26
- package/nextjs.mjs +11 -9
- package/package.json +1 -1
- package/solidjs.d.mts +4 -2
- package/solidjs.d.ts +4 -2
- package/solidjs.js +61 -20
- package/solidjs.mjs +3 -3
- package/svelte.d.mts +4 -2
- package/svelte.d.ts +4 -2
- package/svelte.js +62 -21
- package/svelte.mjs +4 -4
- package/{types-CoXaNrxX.d.mts → types-p7sxktVE.d.mts} +23 -9
- package/{types-CoXaNrxX.d.ts → types-p7sxktVE.d.ts} +23 -9
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
# Upstash Workflow
|
|
1
|
+
# Upstash Workflow SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> **This project is in GA Stage.**
|
|
7
|
+
> The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
|
|
8
|
+
> The Upstash team is committed to maintaining and improving its functionality.
|
|
9
|
+
|
|
10
|
+
**Upstash Workflow** lets you write durable, reliable and performant serverless functions. Get delivery guarantees, automatic retries on failure, scheduling and more without managing any infrastructure.
|
|
11
|
+
|
|
12
|
+
See [the documentation](https://upstash.com/docs/qstash/workflow/getstarted) for more details
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
Here, we will briefly showcase how you can get started with Upstash Workflow.
|
|
17
|
+
|
|
18
|
+
Alternatively, you can check [our quickstarts for different frameworks](https://upstash.com/docs/qstash/workflow/quickstarts/platforms), including [Next.js](https://upstash.com/docs/qstash/workflow/quickstarts/vercel-nextjs) and [Cloudflare](https://upstash.com/docs/qstash/workflow/quickstarts/cloudflare-workers).
|
|
19
|
+
|
|
20
|
+
### Install
|
|
21
|
+
|
|
22
|
+
First, install the package with:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install @upstash/workflow
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Get QStash token
|
|
29
|
+
|
|
30
|
+
Go to [Upstash Console](https://console.upstash.com/qstash) and copy the QSTASH_TOKEN.
|
|
31
|
+
|
|
32
|
+
### Define a Workflow Endpoint
|
|
33
|
+
|
|
34
|
+
To declare workflow endpoints, use the `serve` method:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
38
|
+
|
|
39
|
+
// mock function
|
|
40
|
+
const someWork = (input: string) => {
|
|
41
|
+
return `processed '${JSON.stringify(input)}'`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// serve endpoint which expects a string payload:
|
|
45
|
+
export const { POST } = serve<string>(async (context) => {
|
|
46
|
+
// get request body:
|
|
47
|
+
const input = context.requestPayload;
|
|
48
|
+
|
|
49
|
+
// run the first step:
|
|
50
|
+
const result1 = await context.run("step1", async () => {
|
|
51
|
+
const output = someWork(input);
|
|
52
|
+
console.log("step 1 input", input, "output", output);
|
|
53
|
+
return output;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// run the second step:
|
|
57
|
+
await context.run("step2", async () => {
|
|
58
|
+
const output = someWork(result1);
|
|
59
|
+
console.log("step 2 input", result1, "output", output);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In the example, you can see that steps are declared through the `context` object.
|
|
65
|
+
|
|
66
|
+
The kinds of steps which are available are:
|
|
67
|
+
|
|
68
|
+
- `context.run`: execute a function
|
|
69
|
+
- `context.sleep`: sleep for some time
|
|
70
|
+
- `context.sleepUntil`: sleep until some timestamp
|
|
71
|
+
- `context.call`: make a third party call without consuming any runtime
|
|
72
|
+
- `context.waitForEvent`: wait for an event
|
|
73
|
+
- `context.notify`: notify an event to make workflows waiting for the event continue
|
|
74
|
+
|
|
75
|
+
You can [learn more about these methods from our documentation](https://upstash.com/docs/qstash/workflow/basics/context).
|
|
76
|
+
|
|
77
|
+
### Workflow Client
|
|
78
|
+
|
|
79
|
+
You can use [the Upstash Workflow client](https://upstash.com/docs/qstash/workflow/basics/client) to cancel workflows, notify workflows
|
|
80
|
+
waiting for an event or get the workflows waiting for an event:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Client } from "@upstash/workflow";
|
|
84
|
+
const client = new Client({ token: "<QSTASH_TOKEN>" });
|
|
85
|
+
|
|
86
|
+
// cancel workflow:
|
|
87
|
+
await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" });
|
|
88
|
+
|
|
89
|
+
// notify workflows:
|
|
90
|
+
await client.notify({
|
|
91
|
+
eventId: "my-event-id",
|
|
92
|
+
eventData: "my-data", // data passed to the workflow run
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// get waiters:
|
|
96
|
+
const result = await client.getWaiters({
|
|
97
|
+
eventId: "my-event-id",
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
### Setup
|
|
104
|
+
|
|
105
|
+
This project requires [Bun](https://bun.sh/) to be installed. Please see the [Bun installation documentation](https://bun.sh/docs/installation) for further instructions.
|
|
106
|
+
|
|
107
|
+
Once you have cloned the project, you will need to install the dependencies and then you can run the project.
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
bun install
|
|
111
|
+
bun run build
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Testing
|
|
115
|
+
|
|
116
|
+
To begin testing, environment variables will need to be setup. First, create a `.env` file in the root of the project. [`.env.template`](/.env.template) can be used as a template. Your values can be found in the [Qstash Console](https://console.upstash.com/qstash).
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
bun run test
|
|
120
|
+
```
|
|
@@ -448,6 +448,7 @@ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
|
448
448
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
449
449
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
450
450
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
451
|
+
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
451
452
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
452
453
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
453
454
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -533,13 +534,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
533
534
|
try {
|
|
534
535
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
535
536
|
const callbackMessage = JSON.parse(requestPayload);
|
|
536
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
537
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300) && callbackMessage.maxRetries && callbackMessage.retried !== callbackMessage.maxRetries) {
|
|
537
538
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
538
539
|
status: callbackMessage.status,
|
|
539
540
|
body: atob(callbackMessage.body)
|
|
540
541
|
});
|
|
541
542
|
console.warn(
|
|
542
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
543
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (retried ${callbackMessage.retried ?? 0} out of ${callbackMessage.maxRetries} times). Error Message:
|
|
543
544
|
${atob(callbackMessage.body)}`
|
|
544
545
|
);
|
|
545
546
|
return ok("call-will-retry");
|
|
@@ -576,7 +577,11 @@ ${atob(callbackMessage.body)}`
|
|
|
576
577
|
stepId: Number(stepIdString),
|
|
577
578
|
stepName,
|
|
578
579
|
stepType,
|
|
579
|
-
out:
|
|
580
|
+
out: {
|
|
581
|
+
status: callbackMessage.status,
|
|
582
|
+
body: atob(callbackMessage.body),
|
|
583
|
+
header: callbackMessage.header
|
|
584
|
+
},
|
|
580
585
|
concurrent: Number(concurrentString)
|
|
581
586
|
};
|
|
582
587
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -611,15 +616,24 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
611
616
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
612
617
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
613
618
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
614
|
-
[
|
|
615
|
-
|
|
616
|
-
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
617
|
-
"Upstash-Failure-Callback": failureUrl
|
|
618
|
-
} : {},
|
|
619
|
-
...retries === void 0 ? {} : {
|
|
620
|
-
"Upstash-Retries": retries.toString()
|
|
621
|
-
}
|
|
619
|
+
[WORKFLOW_FEATURE_HEADER]: "WF_NoDelete",
|
|
620
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION
|
|
622
621
|
};
|
|
622
|
+
if (failureUrl) {
|
|
623
|
+
if (!step?.callUrl) {
|
|
624
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
625
|
+
}
|
|
626
|
+
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
627
|
+
}
|
|
628
|
+
if (step?.callUrl) {
|
|
629
|
+
baseHeaders["Upstash-Retries"] = "0";
|
|
630
|
+
if (retries) {
|
|
631
|
+
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
632
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
633
|
+
}
|
|
634
|
+
} else if (retries !== void 0) {
|
|
635
|
+
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
636
|
+
}
|
|
623
637
|
if (userHeaders) {
|
|
624
638
|
for (const header of userHeaders.keys()) {
|
|
625
639
|
if (step?.callHeaders) {
|
|
@@ -959,7 +973,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
959
973
|
path: ["v2", "wait", waitStep.waitEventId],
|
|
960
974
|
body: JSON.stringify(waitBody),
|
|
961
975
|
headers,
|
|
962
|
-
method: "POST"
|
|
976
|
+
method: "POST",
|
|
977
|
+
parseResponseAsJson: false
|
|
963
978
|
});
|
|
964
979
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
965
980
|
}
|
|
@@ -1505,15 +1520,38 @@ var WorkflowContext = class {
|
|
|
1505
1520
|
* @param method call method
|
|
1506
1521
|
* @param body call body
|
|
1507
1522
|
* @param headers call headers
|
|
1508
|
-
* @returns call result
|
|
1523
|
+
* @returns call result as {
|
|
1524
|
+
* status: number;
|
|
1525
|
+
* body: unknown;
|
|
1526
|
+
* header: Record<string, string[]>
|
|
1527
|
+
* }
|
|
1509
1528
|
*/
|
|
1510
|
-
|
|
1511
|
-
|
|
1529
|
+
async call(stepName, settings) {
|
|
1530
|
+
const { url, method = "GET", body, headers = {} } = settings;
|
|
1512
1531
|
const result = await this.addStep(
|
|
1513
1532
|
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1514
1533
|
);
|
|
1534
|
+
if (typeof result === "string") {
|
|
1535
|
+
try {
|
|
1536
|
+
const body2 = JSON.parse(result);
|
|
1537
|
+
return {
|
|
1538
|
+
status: 200,
|
|
1539
|
+
header: {},
|
|
1540
|
+
body: body2
|
|
1541
|
+
};
|
|
1542
|
+
} catch {
|
|
1543
|
+
return {
|
|
1544
|
+
status: 200,
|
|
1545
|
+
header: {},
|
|
1546
|
+
body: result
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1515
1550
|
try {
|
|
1516
|
-
return
|
|
1551
|
+
return {
|
|
1552
|
+
...result,
|
|
1553
|
+
body: JSON.parse(result.body)
|
|
1554
|
+
};
|
|
1517
1555
|
} catch {
|
|
1518
1556
|
return result;
|
|
1519
1557
|
}
|
|
@@ -1936,6 +1974,7 @@ var serve = (routeFunction, options) => {
|
|
|
1936
1974
|
} = processOptions(options);
|
|
1937
1975
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1938
1976
|
const handler = async (request) => {
|
|
1977
|
+
await debug?.log("INFO", "ENDPOINT_START");
|
|
1939
1978
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1940
1979
|
request,
|
|
1941
1980
|
url,
|
|
@@ -1979,7 +2018,8 @@ var serve = (routeFunction, options) => {
|
|
|
1979
2018
|
url: workflowUrl,
|
|
1980
2019
|
failureUrl: workflowFailureUrl,
|
|
1981
2020
|
debug,
|
|
1982
|
-
env
|
|
2021
|
+
env,
|
|
2022
|
+
retries
|
|
1983
2023
|
});
|
|
1984
2024
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1985
2025
|
routeFunction,
|
|
@@ -2022,7 +2062,7 @@ var serve = (routeFunction, options) => {
|
|
|
2022
2062
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
2023
2063
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
2024
2064
|
};
|
|
2025
|
-
|
|
2065
|
+
const safeHandler = async (request) => {
|
|
2026
2066
|
try {
|
|
2027
2067
|
return await handler(request);
|
|
2028
2068
|
} catch (error) {
|
|
@@ -2032,6 +2072,7 @@ var serve = (routeFunction, options) => {
|
|
|
2032
2072
|
});
|
|
2033
2073
|
}
|
|
2034
2074
|
};
|
|
2075
|
+
return { handler: safeHandler };
|
|
2035
2076
|
};
|
|
2036
2077
|
|
|
2037
2078
|
// src/client/index.ts
|
|
@@ -2047,6 +2088,13 @@ var Client3 = class {
|
|
|
2047
2088
|
/**
|
|
2048
2089
|
* Cancel an ongoing workflow
|
|
2049
2090
|
*
|
|
2091
|
+
* ```ts
|
|
2092
|
+
* import { Client } from "@upstash/workflow";
|
|
2093
|
+
*
|
|
2094
|
+
* const client = new Client({ token: "<QSTASH_TOKEN>" })
|
|
2095
|
+
* await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" })
|
|
2096
|
+
* ```
|
|
2097
|
+
*
|
|
2050
2098
|
* @param workflowRunId run id of the workflow to delete
|
|
2051
2099
|
* @returns true if workflow is succesfully deleted. Otherwise throws QStashError
|
|
2052
2100
|
*/
|
|
@@ -2061,6 +2109,16 @@ var Client3 = class {
|
|
|
2061
2109
|
/**
|
|
2062
2110
|
* Notify a workflow run waiting for an event
|
|
2063
2111
|
*
|
|
2112
|
+
* ```ts
|
|
2113
|
+
* import { Client } from "@upstash/workflow";
|
|
2114
|
+
*
|
|
2115
|
+
* const client = new Client({ token: "<QSTASH_TOKEN>" })
|
|
2116
|
+
* await client.notify({
|
|
2117
|
+
* eventId: "my-event-id",
|
|
2118
|
+
* eventData: "my-data" // data passed to the workflow run
|
|
2119
|
+
* });
|
|
2120
|
+
* ```
|
|
2121
|
+
*
|
|
2064
2122
|
* @param eventId event id to notify
|
|
2065
2123
|
* @param eventData data to provide to the workflow
|
|
2066
2124
|
*/
|
|
@@ -2073,6 +2131,15 @@ var Client3 = class {
|
|
|
2073
2131
|
/**
|
|
2074
2132
|
* Check waiters of an event
|
|
2075
2133
|
*
|
|
2134
|
+
* ```ts
|
|
2135
|
+
* import { Client } from "@upstash/workflow";
|
|
2136
|
+
*
|
|
2137
|
+
* const client = new Client({ token: "<QSTASH_TOKEN>" })
|
|
2138
|
+
* const result = await client.getWaiters({
|
|
2139
|
+
* eventId: "my-event-id"
|
|
2140
|
+
* })
|
|
2141
|
+
* ```
|
|
2142
|
+
*
|
|
2076
2143
|
* @param eventId event id to check
|
|
2077
2144
|
*/
|
|
2078
2145
|
async getWaiters({ eventId }) {
|
package/cloudflare.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
1
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-p7sxktVE.mjs';
|
|
2
2
|
import '@upstash/qstash';
|
|
3
3
|
|
|
4
4
|
type WorkflowBindings = {
|
|
@@ -28,6 +28,8 @@ type WorkersHandlerArgs = [Request, Record<string, string | undefined>];
|
|
|
28
28
|
* @param options workflow options
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
31
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
32
|
+
fetch: (...args: PagesHandlerArgs | WorkersHandlerArgs) => Promise<Response>;
|
|
33
|
+
};
|
|
32
34
|
|
|
33
35
|
export { type PagesHandlerArgs, type WorkersHandlerArgs, type WorkflowBindings, serve };
|
package/cloudflare.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
1
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-p7sxktVE.js';
|
|
2
2
|
import '@upstash/qstash';
|
|
3
3
|
|
|
4
4
|
type WorkflowBindings = {
|
|
@@ -28,6 +28,8 @@ type WorkersHandlerArgs = [Request, Record<string, string | undefined>];
|
|
|
28
28
|
* @param options workflow options
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
31
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
32
|
+
fetch: (...args: PagesHandlerArgs | WorkersHandlerArgs) => Promise<Response>;
|
|
33
|
+
};
|
|
32
34
|
|
|
33
35
|
export { type PagesHandlerArgs, type WorkersHandlerArgs, type WorkflowBindings, serve };
|
package/cloudflare.js
CHANGED
|
@@ -474,6 +474,7 @@ 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";
|
|
477
478
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
478
479
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
479
480
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -559,13 +560,13 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
559
560
|
try {
|
|
560
561
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
561
562
|
const callbackMessage = JSON.parse(requestPayload);
|
|
562
|
-
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
563
|
+
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300) && callbackMessage.maxRetries && callbackMessage.retried !== callbackMessage.maxRetries) {
|
|
563
564
|
await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
564
565
|
status: callbackMessage.status,
|
|
565
566
|
body: atob(callbackMessage.body)
|
|
566
567
|
});
|
|
567
568
|
console.warn(
|
|
568
|
-
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (
|
|
569
|
+
`Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (retried ${callbackMessage.retried ?? 0} out of ${callbackMessage.maxRetries} times). Error Message:
|
|
569
570
|
${atob(callbackMessage.body)}`
|
|
570
571
|
);
|
|
571
572
|
return ok("call-will-retry");
|
|
@@ -602,7 +603,11 @@ ${atob(callbackMessage.body)}`
|
|
|
602
603
|
stepId: Number(stepIdString),
|
|
603
604
|
stepName,
|
|
604
605
|
stepType,
|
|
605
|
-
out:
|
|
606
|
+
out: {
|
|
607
|
+
status: callbackMessage.status,
|
|
608
|
+
body: atob(callbackMessage.body),
|
|
609
|
+
header: callbackMessage.header
|
|
610
|
+
},
|
|
606
611
|
concurrent: Number(concurrentString)
|
|
607
612
|
};
|
|
608
613
|
await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
@@ -637,15 +642,24 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
637
642
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
638
643
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
639
644
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
640
|
-
[
|
|
641
|
-
|
|
642
|
-
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
643
|
-
"Upstash-Failure-Callback": failureUrl
|
|
644
|
-
} : {},
|
|
645
|
-
...retries === void 0 ? {} : {
|
|
646
|
-
"Upstash-Retries": retries.toString()
|
|
647
|
-
}
|
|
645
|
+
[WORKFLOW_FEATURE_HEADER]: "WF_NoDelete",
|
|
646
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION
|
|
648
647
|
};
|
|
648
|
+
if (failureUrl) {
|
|
649
|
+
if (!step?.callUrl) {
|
|
650
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
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();
|
|
659
|
+
}
|
|
660
|
+
} else if (retries !== void 0) {
|
|
661
|
+
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
662
|
+
}
|
|
649
663
|
if (userHeaders) {
|
|
650
664
|
for (const header of userHeaders.keys()) {
|
|
651
665
|
if (step?.callHeaders) {
|
|
@@ -985,7 +999,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
985
999
|
path: ["v2", "wait", waitStep.waitEventId],
|
|
986
1000
|
body: JSON.stringify(waitBody),
|
|
987
1001
|
headers,
|
|
988
|
-
method: "POST"
|
|
1002
|
+
method: "POST",
|
|
1003
|
+
parseResponseAsJson: false
|
|
989
1004
|
});
|
|
990
1005
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
991
1006
|
}
|
|
@@ -1524,15 +1539,38 @@ var WorkflowContext = class {
|
|
|
1524
1539
|
* @param method call method
|
|
1525
1540
|
* @param body call body
|
|
1526
1541
|
* @param headers call headers
|
|
1527
|
-
* @returns call result
|
|
1542
|
+
* @returns call result as {
|
|
1543
|
+
* status: number;
|
|
1544
|
+
* body: unknown;
|
|
1545
|
+
* header: Record<string, string[]>
|
|
1546
|
+
* }
|
|
1528
1547
|
*/
|
|
1529
|
-
|
|
1530
|
-
|
|
1548
|
+
async call(stepName, settings) {
|
|
1549
|
+
const { url, method = "GET", body, headers = {} } = settings;
|
|
1531
1550
|
const result = await this.addStep(
|
|
1532
1551
|
new LazyCallStep(stepName, url, method, body, headers ?? {})
|
|
1533
1552
|
);
|
|
1553
|
+
if (typeof result === "string") {
|
|
1554
|
+
try {
|
|
1555
|
+
const body2 = JSON.parse(result);
|
|
1556
|
+
return {
|
|
1557
|
+
status: 200,
|
|
1558
|
+
header: {},
|
|
1559
|
+
body: body2
|
|
1560
|
+
};
|
|
1561
|
+
} catch {
|
|
1562
|
+
return {
|
|
1563
|
+
status: 200,
|
|
1564
|
+
header: {},
|
|
1565
|
+
body: result
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1534
1569
|
try {
|
|
1535
|
-
return
|
|
1570
|
+
return {
|
|
1571
|
+
...result,
|
|
1572
|
+
body: JSON.parse(result.body)
|
|
1573
|
+
};
|
|
1536
1574
|
} catch {
|
|
1537
1575
|
return result;
|
|
1538
1576
|
}
|
|
@@ -1955,6 +1993,7 @@ var serve = (routeFunction, options) => {
|
|
|
1955
1993
|
} = processOptions(options);
|
|
1956
1994
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1957
1995
|
const handler = async (request) => {
|
|
1996
|
+
await debug?.log("INFO", "ENDPOINT_START");
|
|
1958
1997
|
const { workflowUrl, workflowFailureUrl } = await determineUrls(
|
|
1959
1998
|
request,
|
|
1960
1999
|
url,
|
|
@@ -1998,7 +2037,8 @@ var serve = (routeFunction, options) => {
|
|
|
1998
2037
|
url: workflowUrl,
|
|
1999
2038
|
failureUrl: workflowFailureUrl,
|
|
2000
2039
|
debug,
|
|
2001
|
-
env
|
|
2040
|
+
env,
|
|
2041
|
+
retries
|
|
2002
2042
|
});
|
|
2003
2043
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
2004
2044
|
routeFunction,
|
|
@@ -2041,7 +2081,7 @@ var serve = (routeFunction, options) => {
|
|
|
2041
2081
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
2042
2082
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
2043
2083
|
};
|
|
2044
|
-
|
|
2084
|
+
const safeHandler = async (request) => {
|
|
2045
2085
|
try {
|
|
2046
2086
|
return await handler(request);
|
|
2047
2087
|
} catch (error) {
|
|
@@ -2051,6 +2091,7 @@ var serve = (routeFunction, options) => {
|
|
|
2051
2091
|
});
|
|
2052
2092
|
}
|
|
2053
2093
|
};
|
|
2094
|
+
return { handler: safeHandler };
|
|
2054
2095
|
};
|
|
2055
2096
|
|
|
2056
2097
|
// src/client/index.ts
|
|
@@ -2076,15 +2117,15 @@ var getArgs = (args) => {
|
|
|
2076
2117
|
throw new Error("Could not derive handler arguments from input. Please check how serve is used.");
|
|
2077
2118
|
};
|
|
2078
2119
|
var serve2 = (routeFunction, options) => {
|
|
2079
|
-
const
|
|
2120
|
+
const fetch = async (...args) => {
|
|
2080
2121
|
const { request, env } = getArgs(args);
|
|
2081
|
-
const serveHandler = serve(routeFunction, {
|
|
2122
|
+
const { handler: serveHandler } = serve(routeFunction, {
|
|
2082
2123
|
env,
|
|
2083
2124
|
...options
|
|
2084
2125
|
});
|
|
2085
2126
|
return await serveHandler(request);
|
|
2086
2127
|
};
|
|
2087
|
-
return
|
|
2128
|
+
return { fetch };
|
|
2088
2129
|
};
|
|
2089
2130
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2090
2131
|
0 && (module.exports = {
|
package/cloudflare.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XPMFG3Q4.mjs";
|
|
4
4
|
|
|
5
5
|
// platforms/cloudflare.ts
|
|
6
6
|
var getArgs = (args) => {
|
|
@@ -22,15 +22,15 @@ var getArgs = (args) => {
|
|
|
22
22
|
throw new Error("Could not derive handler arguments from input. Please check how serve is used.");
|
|
23
23
|
};
|
|
24
24
|
var serve2 = (routeFunction, options) => {
|
|
25
|
-
const
|
|
25
|
+
const fetch = async (...args) => {
|
|
26
26
|
const { request, env } = getArgs(args);
|
|
27
|
-
const serveHandler = serve(routeFunction, {
|
|
27
|
+
const { handler: serveHandler } = serve(routeFunction, {
|
|
28
28
|
env,
|
|
29
29
|
...options
|
|
30
30
|
});
|
|
31
31
|
return await serveHandler(request);
|
|
32
32
|
};
|
|
33
|
-
return
|
|
33
|
+
return { fetch };
|
|
34
34
|
};
|
|
35
35
|
export {
|
|
36
36
|
serve2 as serve
|
package/h3.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-p7sxktVE.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
6
|
+
handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
7
|
+
status: number;
|
|
8
|
+
body: string;
|
|
9
|
+
}>>;
|
|
10
|
+
};
|
|
9
11
|
|
|
10
12
|
export { serve };
|
package/h3.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-p7sxktVE.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
|
6
|
+
handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
7
|
+
status: number;
|
|
8
|
+
body: string;
|
|
9
|
+
}>>;
|
|
10
|
+
};
|
|
9
11
|
|
|
10
12
|
export { serve };
|