@upstash/workflow 0.2.0 → 0.2.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/astro.d.mts +1 -1
- package/astro.d.ts +1 -1
- package/astro.js +54 -13
- package/astro.mjs +1 -1
- package/{chunk-5R2BFC3N.mjs → chunk-ADOBNR4O.mjs} +54 -13
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +54 -13
- package/cloudflare.mjs +1 -1
- package/express.d.mts +1 -1
- package/express.d.ts +1 -1
- package/express.js +54 -13
- package/express.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +54 -13
- package/h3.mjs +1 -1
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +54 -13
- package/hono.mjs +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +54 -13
- package/index.mjs +1 -1
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +58 -17
- package/nextjs.mjs +5 -5
- package/package.json +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +54 -13
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +54 -13
- package/svelte.mjs +1 -1
- package/{types-Cki_MHrh.d.mts → types-Be4hC1mu.d.mts} +2 -0
- package/{types-Cki_MHrh.d.ts → types-Be4hC1mu.d.ts} +2 -0
package/express.js
CHANGED
|
@@ -23654,6 +23654,11 @@ var BaseLazyStep = class {
|
|
|
23654
23654
|
stepName;
|
|
23655
23655
|
// will be set in the subclasses
|
|
23656
23656
|
constructor(stepName) {
|
|
23657
|
+
if (!stepName) {
|
|
23658
|
+
throw new WorkflowError(
|
|
23659
|
+
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
23660
|
+
);
|
|
23661
|
+
}
|
|
23657
23662
|
this.stepName = stepName;
|
|
23658
23663
|
}
|
|
23659
23664
|
};
|
|
@@ -23746,15 +23751,17 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
23746
23751
|
method;
|
|
23747
23752
|
body;
|
|
23748
23753
|
headers;
|
|
23749
|
-
stepType = "Call";
|
|
23750
23754
|
retries;
|
|
23751
|
-
|
|
23755
|
+
timeout;
|
|
23756
|
+
stepType = "Call";
|
|
23757
|
+
constructor(stepName, url, method, body, headers, retries, timeout) {
|
|
23752
23758
|
super(stepName);
|
|
23753
23759
|
this.url = url;
|
|
23754
23760
|
this.method = method;
|
|
23755
23761
|
this.body = body;
|
|
23756
23762
|
this.headers = headers;
|
|
23757
23763
|
this.retries = retries;
|
|
23764
|
+
this.timeout = timeout;
|
|
23758
23765
|
}
|
|
23759
23766
|
getPlanStep(concurrent, targetStep) {
|
|
23760
23767
|
return {
|
|
@@ -24366,7 +24373,10 @@ var recreateUserHeaders = (headers) => {
|
|
|
24366
24373
|
const pairs = headers.entries();
|
|
24367
24374
|
for (const [header, value] of pairs) {
|
|
24368
24375
|
const headerLowerCase = header.toLowerCase();
|
|
24369
|
-
if (!headerLowerCase.startsWith("upstash-workflow-") &&
|
|
24376
|
+
if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
|
|
24377
|
+
!headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
|
|
24378
|
+
headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
|
|
24379
|
+
headerLowerCase !== "render-proxy-ttl") {
|
|
24370
24380
|
filteredHeaders.append(header, value);
|
|
24371
24381
|
}
|
|
24372
24382
|
}
|
|
@@ -24469,7 +24479,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
24469
24479
|
);
|
|
24470
24480
|
}
|
|
24471
24481
|
};
|
|
24472
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
24482
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries, callTimeout) => {
|
|
24473
24483
|
const baseHeaders = {
|
|
24474
24484
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
24475
24485
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -24479,6 +24489,9 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
24479
24489
|
if (!step?.callUrl) {
|
|
24480
24490
|
baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
24481
24491
|
}
|
|
24492
|
+
if (callTimeout) {
|
|
24493
|
+
baseHeaders[`Upstash-Timeout`] = callTimeout.toString();
|
|
24494
|
+
}
|
|
24482
24495
|
if (failureUrl) {
|
|
24483
24496
|
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
24484
24497
|
if (!step?.callUrl) {
|
|
@@ -24854,7 +24867,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
24854
24867
|
singleStep,
|
|
24855
24868
|
this.context.failureUrl,
|
|
24856
24869
|
this.context.retries,
|
|
24857
|
-
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
24870
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
|
|
24871
|
+
lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0
|
|
24858
24872
|
);
|
|
24859
24873
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
24860
24874
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -25204,6 +25218,7 @@ var WorkflowContext = class {
|
|
|
25204
25218
|
* @param body call body
|
|
25205
25219
|
* @param headers call headers
|
|
25206
25220
|
* @param retries number of call retries. 0 by default
|
|
25221
|
+
* @param timeout max duration to wait for the endpoint to respond. in seconds.
|
|
25207
25222
|
* @returns call result as {
|
|
25208
25223
|
* status: number;
|
|
25209
25224
|
* body: unknown;
|
|
@@ -25211,9 +25226,17 @@ var WorkflowContext = class {
|
|
|
25211
25226
|
* }
|
|
25212
25227
|
*/
|
|
25213
25228
|
async call(stepName, settings) {
|
|
25214
|
-
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
25229
|
+
const { url, method = "GET", body, headers = {}, retries = 0, timeout } = settings;
|
|
25215
25230
|
const result = await this.addStep(
|
|
25216
|
-
new LazyCallStep(
|
|
25231
|
+
new LazyCallStep(
|
|
25232
|
+
stepName,
|
|
25233
|
+
url,
|
|
25234
|
+
method,
|
|
25235
|
+
body,
|
|
25236
|
+
headers,
|
|
25237
|
+
retries,
|
|
25238
|
+
timeout
|
|
25239
|
+
)
|
|
25217
25240
|
);
|
|
25218
25241
|
if (typeof result === "string") {
|
|
25219
25242
|
try {
|
|
@@ -25613,7 +25636,7 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
25613
25636
|
const workflowContext = new WorkflowContext({
|
|
25614
25637
|
qstashClient,
|
|
25615
25638
|
workflowRunId,
|
|
25616
|
-
initialPayload: initialPayloadParser(decodeBase64(sourceBody)),
|
|
25639
|
+
initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
|
|
25617
25640
|
headers: recreateUserHeaders(new Headers(sourceHeader)),
|
|
25618
25641
|
steps: [],
|
|
25619
25642
|
url,
|
|
@@ -25655,10 +25678,23 @@ var processOptions = (options) => {
|
|
|
25655
25678
|
baseUrl: environment.QSTASH_URL,
|
|
25656
25679
|
token: environment.QSTASH_TOKEN
|
|
25657
25680
|
}),
|
|
25658
|
-
|
|
25659
|
-
|
|
25660
|
-
|
|
25661
|
-
|
|
25681
|
+
onStepFinish: (workflowRunId, finishCondition) => {
|
|
25682
|
+
if (finishCondition === "auth-fail") {
|
|
25683
|
+
console.error(AUTH_FAIL_MESSAGE);
|
|
25684
|
+
return new Response(
|
|
25685
|
+
JSON.stringify({
|
|
25686
|
+
message: AUTH_FAIL_MESSAGE,
|
|
25687
|
+
workflowRunId
|
|
25688
|
+
}),
|
|
25689
|
+
{
|
|
25690
|
+
status: 400
|
|
25691
|
+
}
|
|
25692
|
+
);
|
|
25693
|
+
}
|
|
25694
|
+
return new Response(JSON.stringify({ workflowRunId }), {
|
|
25695
|
+
status: 200
|
|
25696
|
+
});
|
|
25697
|
+
},
|
|
25662
25698
|
initialPayloadParser: (initialRequest) => {
|
|
25663
25699
|
if (!initialRequest) {
|
|
25664
25700
|
return void 0;
|
|
@@ -25700,6 +25736,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
25700
25736
|
workflowFailureUrl
|
|
25701
25737
|
};
|
|
25702
25738
|
};
|
|
25739
|
+
var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
|
|
25703
25740
|
|
|
25704
25741
|
// src/serve/index.ts
|
|
25705
25742
|
var serve = (routeFunction, options) => {
|
|
@@ -25776,7 +25813,11 @@ var serve = (routeFunction, options) => {
|
|
|
25776
25813
|
await debug?.log("ERROR", "ERROR", { error: authCheck.error.message });
|
|
25777
25814
|
throw authCheck.error;
|
|
25778
25815
|
} else if (authCheck.value === "run-ended") {
|
|
25779
|
-
|
|
25816
|
+
await debug?.log("ERROR", "ERROR", { error: AUTH_FAIL_MESSAGE });
|
|
25817
|
+
return onStepFinish(
|
|
25818
|
+
isFirstInvocation ? "no-workflow-id" : workflowContext.workflowRunId,
|
|
25819
|
+
"auth-fail"
|
|
25820
|
+
);
|
|
25780
25821
|
}
|
|
25781
25822
|
const callReturnCheck = await handleThirdPartyCallResult(
|
|
25782
25823
|
request,
|
package/express.mjs
CHANGED
package/h3.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-Be4hC1mu.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
package/h3.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-Be4hC1mu.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => {
|
package/h3.js
CHANGED
|
@@ -430,6 +430,11 @@ var BaseLazyStep = class {
|
|
|
430
430
|
stepName;
|
|
431
431
|
// will be set in the subclasses
|
|
432
432
|
constructor(stepName) {
|
|
433
|
+
if (!stepName) {
|
|
434
|
+
throw new WorkflowError(
|
|
435
|
+
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
436
|
+
);
|
|
437
|
+
}
|
|
433
438
|
this.stepName = stepName;
|
|
434
439
|
}
|
|
435
440
|
};
|
|
@@ -522,15 +527,17 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
522
527
|
method;
|
|
523
528
|
body;
|
|
524
529
|
headers;
|
|
525
|
-
stepType = "Call";
|
|
526
530
|
retries;
|
|
527
|
-
|
|
531
|
+
timeout;
|
|
532
|
+
stepType = "Call";
|
|
533
|
+
constructor(stepName, url, method, body, headers, retries, timeout) {
|
|
528
534
|
super(stepName);
|
|
529
535
|
this.url = url;
|
|
530
536
|
this.method = method;
|
|
531
537
|
this.body = body;
|
|
532
538
|
this.headers = headers;
|
|
533
539
|
this.retries = retries;
|
|
540
|
+
this.timeout = timeout;
|
|
534
541
|
}
|
|
535
542
|
getPlanStep(concurrent, targetStep) {
|
|
536
543
|
return {
|
|
@@ -1142,7 +1149,10 @@ var recreateUserHeaders = (headers) => {
|
|
|
1142
1149
|
const pairs = headers.entries();
|
|
1143
1150
|
for (const [header, value] of pairs) {
|
|
1144
1151
|
const headerLowerCase = header.toLowerCase();
|
|
1145
|
-
if (!headerLowerCase.startsWith("upstash-workflow-") &&
|
|
1152
|
+
if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
|
|
1153
|
+
!headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
|
|
1154
|
+
headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
|
|
1155
|
+
headerLowerCase !== "render-proxy-ttl") {
|
|
1146
1156
|
filteredHeaders.append(header, value);
|
|
1147
1157
|
}
|
|
1148
1158
|
}
|
|
@@ -1245,7 +1255,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1245
1255
|
);
|
|
1246
1256
|
}
|
|
1247
1257
|
};
|
|
1248
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
1258
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries, callTimeout) => {
|
|
1249
1259
|
const baseHeaders = {
|
|
1250
1260
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
1251
1261
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -1255,6 +1265,9 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
1255
1265
|
if (!step?.callUrl) {
|
|
1256
1266
|
baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
1257
1267
|
}
|
|
1268
|
+
if (callTimeout) {
|
|
1269
|
+
baseHeaders[`Upstash-Timeout`] = callTimeout.toString();
|
|
1270
|
+
}
|
|
1258
1271
|
if (failureUrl) {
|
|
1259
1272
|
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
1260
1273
|
if (!step?.callUrl) {
|
|
@@ -1630,7 +1643,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1630
1643
|
singleStep,
|
|
1631
1644
|
this.context.failureUrl,
|
|
1632
1645
|
this.context.retries,
|
|
1633
|
-
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1646
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
|
|
1647
|
+
lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0
|
|
1634
1648
|
);
|
|
1635
1649
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1636
1650
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1980,6 +1994,7 @@ var WorkflowContext = class {
|
|
|
1980
1994
|
* @param body call body
|
|
1981
1995
|
* @param headers call headers
|
|
1982
1996
|
* @param retries number of call retries. 0 by default
|
|
1997
|
+
* @param timeout max duration to wait for the endpoint to respond. in seconds.
|
|
1983
1998
|
* @returns call result as {
|
|
1984
1999
|
* status: number;
|
|
1985
2000
|
* body: unknown;
|
|
@@ -1987,9 +2002,17 @@ var WorkflowContext = class {
|
|
|
1987
2002
|
* }
|
|
1988
2003
|
*/
|
|
1989
2004
|
async call(stepName, settings) {
|
|
1990
|
-
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
2005
|
+
const { url, method = "GET", body, headers = {}, retries = 0, timeout } = settings;
|
|
1991
2006
|
const result = await this.addStep(
|
|
1992
|
-
new LazyCallStep(
|
|
2007
|
+
new LazyCallStep(
|
|
2008
|
+
stepName,
|
|
2009
|
+
url,
|
|
2010
|
+
method,
|
|
2011
|
+
body,
|
|
2012
|
+
headers,
|
|
2013
|
+
retries,
|
|
2014
|
+
timeout
|
|
2015
|
+
)
|
|
1993
2016
|
);
|
|
1994
2017
|
if (typeof result === "string") {
|
|
1995
2018
|
try {
|
|
@@ -2389,7 +2412,7 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
2389
2412
|
const workflowContext = new WorkflowContext({
|
|
2390
2413
|
qstashClient,
|
|
2391
2414
|
workflowRunId,
|
|
2392
|
-
initialPayload: initialPayloadParser(decodeBase64(sourceBody)),
|
|
2415
|
+
initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
|
|
2393
2416
|
headers: recreateUserHeaders(new Headers(sourceHeader)),
|
|
2394
2417
|
steps: [],
|
|
2395
2418
|
url,
|
|
@@ -2431,10 +2454,23 @@ var processOptions = (options) => {
|
|
|
2431
2454
|
baseUrl: environment.QSTASH_URL,
|
|
2432
2455
|
token: environment.QSTASH_TOKEN
|
|
2433
2456
|
}),
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2457
|
+
onStepFinish: (workflowRunId, finishCondition) => {
|
|
2458
|
+
if (finishCondition === "auth-fail") {
|
|
2459
|
+
console.error(AUTH_FAIL_MESSAGE);
|
|
2460
|
+
return new Response(
|
|
2461
|
+
JSON.stringify({
|
|
2462
|
+
message: AUTH_FAIL_MESSAGE,
|
|
2463
|
+
workflowRunId
|
|
2464
|
+
}),
|
|
2465
|
+
{
|
|
2466
|
+
status: 400
|
|
2467
|
+
}
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
return new Response(JSON.stringify({ workflowRunId }), {
|
|
2471
|
+
status: 200
|
|
2472
|
+
});
|
|
2473
|
+
},
|
|
2438
2474
|
initialPayloadParser: (initialRequest) => {
|
|
2439
2475
|
if (!initialRequest) {
|
|
2440
2476
|
return void 0;
|
|
@@ -2476,6 +2512,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
2476
2512
|
workflowFailureUrl
|
|
2477
2513
|
};
|
|
2478
2514
|
};
|
|
2515
|
+
var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
|
|
2479
2516
|
|
|
2480
2517
|
// src/serve/index.ts
|
|
2481
2518
|
var serve = (routeFunction, options) => {
|
|
@@ -2552,7 +2589,11 @@ var serve = (routeFunction, options) => {
|
|
|
2552
2589
|
await debug?.log("ERROR", "ERROR", { error: authCheck.error.message });
|
|
2553
2590
|
throw authCheck.error;
|
|
2554
2591
|
} else if (authCheck.value === "run-ended") {
|
|
2555
|
-
|
|
2592
|
+
await debug?.log("ERROR", "ERROR", { error: AUTH_FAIL_MESSAGE });
|
|
2593
|
+
return onStepFinish(
|
|
2594
|
+
isFirstInvocation ? "no-workflow-id" : workflowContext.workflowRunId,
|
|
2595
|
+
"auth-fail"
|
|
2596
|
+
);
|
|
2556
2597
|
}
|
|
2557
2598
|
const callReturnCheck = await handleThirdPartyCallResult(
|
|
2558
2599
|
request,
|
package/h3.mjs
CHANGED
package/hono.d.mts
CHANGED
package/hono.d.ts
CHANGED
package/hono.js
CHANGED
|
@@ -118,6 +118,11 @@ var BaseLazyStep = class {
|
|
|
118
118
|
stepName;
|
|
119
119
|
// will be set in the subclasses
|
|
120
120
|
constructor(stepName) {
|
|
121
|
+
if (!stepName) {
|
|
122
|
+
throw new WorkflowError(
|
|
123
|
+
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
124
|
+
);
|
|
125
|
+
}
|
|
121
126
|
this.stepName = stepName;
|
|
122
127
|
}
|
|
123
128
|
};
|
|
@@ -210,15 +215,17 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
210
215
|
method;
|
|
211
216
|
body;
|
|
212
217
|
headers;
|
|
213
|
-
stepType = "Call";
|
|
214
218
|
retries;
|
|
215
|
-
|
|
219
|
+
timeout;
|
|
220
|
+
stepType = "Call";
|
|
221
|
+
constructor(stepName, url, method, body, headers, retries, timeout) {
|
|
216
222
|
super(stepName);
|
|
217
223
|
this.url = url;
|
|
218
224
|
this.method = method;
|
|
219
225
|
this.body = body;
|
|
220
226
|
this.headers = headers;
|
|
221
227
|
this.retries = retries;
|
|
228
|
+
this.timeout = timeout;
|
|
222
229
|
}
|
|
223
230
|
getPlanStep(concurrent, targetStep) {
|
|
224
231
|
return {
|
|
@@ -830,7 +837,10 @@ var recreateUserHeaders = (headers) => {
|
|
|
830
837
|
const pairs = headers.entries();
|
|
831
838
|
for (const [header, value] of pairs) {
|
|
832
839
|
const headerLowerCase = header.toLowerCase();
|
|
833
|
-
if (!headerLowerCase.startsWith("upstash-workflow-") &&
|
|
840
|
+
if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
|
|
841
|
+
!headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
|
|
842
|
+
headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
|
|
843
|
+
headerLowerCase !== "render-proxy-ttl") {
|
|
834
844
|
filteredHeaders.append(header, value);
|
|
835
845
|
}
|
|
836
846
|
}
|
|
@@ -933,7 +943,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
933
943
|
);
|
|
934
944
|
}
|
|
935
945
|
};
|
|
936
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
946
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries, callTimeout) => {
|
|
937
947
|
const baseHeaders = {
|
|
938
948
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
939
949
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -943,6 +953,9 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
943
953
|
if (!step?.callUrl) {
|
|
944
954
|
baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
945
955
|
}
|
|
956
|
+
if (callTimeout) {
|
|
957
|
+
baseHeaders[`Upstash-Timeout`] = callTimeout.toString();
|
|
958
|
+
}
|
|
946
959
|
if (failureUrl) {
|
|
947
960
|
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
948
961
|
if (!step?.callUrl) {
|
|
@@ -1318,7 +1331,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1318
1331
|
singleStep,
|
|
1319
1332
|
this.context.failureUrl,
|
|
1320
1333
|
this.context.retries,
|
|
1321
|
-
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1334
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
|
|
1335
|
+
lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0
|
|
1322
1336
|
);
|
|
1323
1337
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1324
1338
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1668,6 +1682,7 @@ var WorkflowContext = class {
|
|
|
1668
1682
|
* @param body call body
|
|
1669
1683
|
* @param headers call headers
|
|
1670
1684
|
* @param retries number of call retries. 0 by default
|
|
1685
|
+
* @param timeout max duration to wait for the endpoint to respond. in seconds.
|
|
1671
1686
|
* @returns call result as {
|
|
1672
1687
|
* status: number;
|
|
1673
1688
|
* body: unknown;
|
|
@@ -1675,9 +1690,17 @@ var WorkflowContext = class {
|
|
|
1675
1690
|
* }
|
|
1676
1691
|
*/
|
|
1677
1692
|
async call(stepName, settings) {
|
|
1678
|
-
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1693
|
+
const { url, method = "GET", body, headers = {}, retries = 0, timeout } = settings;
|
|
1679
1694
|
const result = await this.addStep(
|
|
1680
|
-
new LazyCallStep(
|
|
1695
|
+
new LazyCallStep(
|
|
1696
|
+
stepName,
|
|
1697
|
+
url,
|
|
1698
|
+
method,
|
|
1699
|
+
body,
|
|
1700
|
+
headers,
|
|
1701
|
+
retries,
|
|
1702
|
+
timeout
|
|
1703
|
+
)
|
|
1681
1704
|
);
|
|
1682
1705
|
if (typeof result === "string") {
|
|
1683
1706
|
try {
|
|
@@ -2077,7 +2100,7 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
2077
2100
|
const workflowContext = new WorkflowContext({
|
|
2078
2101
|
qstashClient,
|
|
2079
2102
|
workflowRunId,
|
|
2080
|
-
initialPayload: initialPayloadParser(decodeBase64(sourceBody)),
|
|
2103
|
+
initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
|
|
2081
2104
|
headers: recreateUserHeaders(new Headers(sourceHeader)),
|
|
2082
2105
|
steps: [],
|
|
2083
2106
|
url,
|
|
@@ -2119,10 +2142,23 @@ var processOptions = (options) => {
|
|
|
2119
2142
|
baseUrl: environment.QSTASH_URL,
|
|
2120
2143
|
token: environment.QSTASH_TOKEN
|
|
2121
2144
|
}),
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2145
|
+
onStepFinish: (workflowRunId, finishCondition) => {
|
|
2146
|
+
if (finishCondition === "auth-fail") {
|
|
2147
|
+
console.error(AUTH_FAIL_MESSAGE);
|
|
2148
|
+
return new Response(
|
|
2149
|
+
JSON.stringify({
|
|
2150
|
+
message: AUTH_FAIL_MESSAGE,
|
|
2151
|
+
workflowRunId
|
|
2152
|
+
}),
|
|
2153
|
+
{
|
|
2154
|
+
status: 400
|
|
2155
|
+
}
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
return new Response(JSON.stringify({ workflowRunId }), {
|
|
2159
|
+
status: 200
|
|
2160
|
+
});
|
|
2161
|
+
},
|
|
2126
2162
|
initialPayloadParser: (initialRequest) => {
|
|
2127
2163
|
if (!initialRequest) {
|
|
2128
2164
|
return void 0;
|
|
@@ -2164,6 +2200,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
2164
2200
|
workflowFailureUrl
|
|
2165
2201
|
};
|
|
2166
2202
|
};
|
|
2203
|
+
var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
|
|
2167
2204
|
|
|
2168
2205
|
// src/serve/index.ts
|
|
2169
2206
|
var serve = (routeFunction, options) => {
|
|
@@ -2240,7 +2277,11 @@ var serve = (routeFunction, options) => {
|
|
|
2240
2277
|
await debug?.log("ERROR", "ERROR", { error: authCheck.error.message });
|
|
2241
2278
|
throw authCheck.error;
|
|
2242
2279
|
} else if (authCheck.value === "run-ended") {
|
|
2243
|
-
|
|
2280
|
+
await debug?.log("ERROR", "ERROR", { error: AUTH_FAIL_MESSAGE });
|
|
2281
|
+
return onStepFinish(
|
|
2282
|
+
isFirstInvocation ? "no-workflow-id" : workflowContext.workflowRunId,
|
|
2283
|
+
"auth-fail"
|
|
2284
|
+
);
|
|
2244
2285
|
}
|
|
2245
2286
|
const callReturnCheck = await handleThirdPartyCallResult(
|
|
2246
2287
|
request,
|
package/hono.mjs
CHANGED
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-
|
|
2
|
-
export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-
|
|
1
|
+
import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Be4hC1mu.mjs';
|
|
2
|
+
export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Be4hC1mu.mjs';
|
|
3
3
|
import { Client as Client$1, QstashError } from '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-
|
|
2
|
-
export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-
|
|
1
|
+
import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Be4hC1mu.js';
|
|
2
|
+
export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Be4hC1mu.js';
|
|
3
3
|
import { Client as Client$1, QstashError } from '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
/**
|