@upstash/workflow 0.2.13 → 0.2.14
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.js +66 -53
- package/astro.mjs +1 -1
- package/{chunk-XVNSBBDC.mjs → chunk-RMS2NQ3K.mjs} +66 -53
- package/cloudflare.js +66 -53
- package/cloudflare.mjs +1 -1
- package/express.js +66 -53
- package/express.mjs +1 -1
- package/h3.js +66 -53
- package/h3.mjs +1 -1
- package/hono.js +66 -53
- package/hono.mjs +1 -1
- package/index.d.mts +117 -14
- package/index.d.ts +117 -14
- package/index.js +97 -115
- package/index.mjs +32 -63
- package/nextjs.js +66 -53
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/solidjs.js +66 -53
- package/solidjs.mjs +1 -1
- package/svelte.js +66 -53
- package/svelte.mjs +1 -1
package/astro.js
CHANGED
|
@@ -91,7 +91,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
91
91
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
92
92
|
var NO_CONCURRENCY = 1;
|
|
93
93
|
var DEFAULT_RETRIES = 3;
|
|
94
|
-
var VERSION = "v0.2.
|
|
94
|
+
var VERSION = "v0.2.14";
|
|
95
95
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
96
96
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
97
97
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -599,59 +599,72 @@ var StepTypes = [
|
|
|
599
599
|
|
|
600
600
|
// src/workflow-requests.ts
|
|
601
601
|
var import_qstash3 = require("@upstash/qstash");
|
|
602
|
-
var triggerFirstInvocation = async ({
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
try {
|
|
631
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
632
|
-
const result = await workflowContext.qstashClient.publish({
|
|
633
|
-
headers,
|
|
634
|
-
method: "POST",
|
|
635
|
-
body,
|
|
636
|
-
url: workflowContext.url,
|
|
637
|
-
delay
|
|
638
|
-
});
|
|
639
|
-
if (result.deduplicated) {
|
|
640
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
641
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
602
|
+
var triggerFirstInvocation = async (params) => {
|
|
603
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
604
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
605
|
+
const invocationBatch = firstInvocationParams.map(
|
|
606
|
+
({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
|
|
607
|
+
const { headers } = getHeaders({
|
|
608
|
+
initHeaderValue: "true",
|
|
609
|
+
workflowConfig: {
|
|
610
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
611
|
+
workflowUrl: workflowContext.url,
|
|
612
|
+
failureUrl: workflowContext.failureUrl,
|
|
613
|
+
retries: workflowContext.retries,
|
|
614
|
+
telemetry: telemetry2,
|
|
615
|
+
flowControl: workflowContext.flowControl,
|
|
616
|
+
useJSONContent: useJSONContent ?? false
|
|
617
|
+
},
|
|
618
|
+
invokeCount: invokeCount ?? 0,
|
|
619
|
+
userHeaders: workflowContext.headers
|
|
620
|
+
});
|
|
621
|
+
if (workflowContext.headers.get("content-type")) {
|
|
622
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
623
|
+
}
|
|
624
|
+
if (useJSONContent) {
|
|
625
|
+
headers["content-type"] = "application/json";
|
|
626
|
+
}
|
|
627
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
628
|
+
return {
|
|
642
629
|
headers,
|
|
643
|
-
|
|
630
|
+
method: "POST",
|
|
631
|
+
body,
|
|
644
632
|
url: workflowContext.url,
|
|
645
|
-
|
|
646
|
-
}
|
|
633
|
+
delay
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
try {
|
|
638
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
639
|
+
const invocationStatuses = [];
|
|
640
|
+
for (let i = 0; i < results.length; i++) {
|
|
641
|
+
const result = results[i];
|
|
642
|
+
const invocationParams = firstInvocationParams[i];
|
|
643
|
+
if (result.deduplicated) {
|
|
644
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
645
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
646
|
+
headers: invocationBatch[i].headers,
|
|
647
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
648
|
+
url: invocationParams.workflowContext.url,
|
|
649
|
+
messageId: result.messageId
|
|
650
|
+
});
|
|
651
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
652
|
+
} else {
|
|
653
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
654
|
+
headers: invocationBatch[i].headers,
|
|
655
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
656
|
+
url: invocationParams.workflowContext.url,
|
|
657
|
+
messageId: result.messageId
|
|
658
|
+
});
|
|
659
|
+
invocationStatuses.push("success");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
663
|
+
(status) => status === "workflow-run-already-exists"
|
|
664
|
+
);
|
|
665
|
+
if (hasAnyDeduplicated) {
|
|
647
666
|
return ok("workflow-run-already-exists");
|
|
648
667
|
} else {
|
|
649
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
650
|
-
headers,
|
|
651
|
-
requestPayload: workflowContext.requestPayload,
|
|
652
|
-
url: workflowContext.url,
|
|
653
|
-
messageId: result.messageId
|
|
654
|
-
});
|
|
655
668
|
return ok("success");
|
|
656
669
|
}
|
|
657
670
|
} catch (error) {
|
|
@@ -1141,7 +1154,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1141
1154
|
return { header, status, body };
|
|
1142
1155
|
}
|
|
1143
1156
|
}
|
|
1144
|
-
static
|
|
1157
|
+
static applicationContentTypes = [
|
|
1145
1158
|
"application/json",
|
|
1146
1159
|
"application/xml",
|
|
1147
1160
|
"application/javascript",
|
|
@@ -1150,12 +1163,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1150
1163
|
"application/ld+json",
|
|
1151
1164
|
"application/rss+xml",
|
|
1152
1165
|
"application/atom+xml"
|
|
1153
|
-
]
|
|
1166
|
+
];
|
|
1154
1167
|
static isText = (contentTypeHeader) => {
|
|
1155
1168
|
if (!contentTypeHeader) {
|
|
1156
1169
|
return false;
|
|
1157
1170
|
}
|
|
1158
|
-
if (_LazyCallStep.
|
|
1171
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1159
1172
|
return true;
|
|
1160
1173
|
}
|
|
1161
1174
|
if (contentTypeHeader.startsWith("text/")) {
|
package/astro.mjs
CHANGED
|
@@ -42,7 +42,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
42
42
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
43
43
|
var NO_CONCURRENCY = 1;
|
|
44
44
|
var DEFAULT_RETRIES = 3;
|
|
45
|
-
var VERSION = "v0.2.
|
|
45
|
+
var VERSION = "v0.2.14";
|
|
46
46
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
47
47
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
48
48
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -809,59 +809,72 @@ var fromThrowable = Result.fromThrowable;
|
|
|
809
809
|
|
|
810
810
|
// src/workflow-requests.ts
|
|
811
811
|
import { QstashError as QstashError3 } from "@upstash/qstash";
|
|
812
|
-
var triggerFirstInvocation = async ({
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
try {
|
|
841
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
842
|
-
const result = await workflowContext.qstashClient.publish({
|
|
843
|
-
headers,
|
|
844
|
-
method: "POST",
|
|
845
|
-
body,
|
|
846
|
-
url: workflowContext.url,
|
|
847
|
-
delay
|
|
848
|
-
});
|
|
849
|
-
if (result.deduplicated) {
|
|
850
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
851
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
812
|
+
var triggerFirstInvocation = async (params) => {
|
|
813
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
814
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
815
|
+
const invocationBatch = firstInvocationParams.map(
|
|
816
|
+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
|
|
817
|
+
const { headers } = getHeaders({
|
|
818
|
+
initHeaderValue: "true",
|
|
819
|
+
workflowConfig: {
|
|
820
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
821
|
+
workflowUrl: workflowContext.url,
|
|
822
|
+
failureUrl: workflowContext.failureUrl,
|
|
823
|
+
retries: workflowContext.retries,
|
|
824
|
+
telemetry,
|
|
825
|
+
flowControl: workflowContext.flowControl,
|
|
826
|
+
useJSONContent: useJSONContent ?? false
|
|
827
|
+
},
|
|
828
|
+
invokeCount: invokeCount ?? 0,
|
|
829
|
+
userHeaders: workflowContext.headers
|
|
830
|
+
});
|
|
831
|
+
if (workflowContext.headers.get("content-type")) {
|
|
832
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
833
|
+
}
|
|
834
|
+
if (useJSONContent) {
|
|
835
|
+
headers["content-type"] = "application/json";
|
|
836
|
+
}
|
|
837
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
838
|
+
return {
|
|
852
839
|
headers,
|
|
853
|
-
|
|
840
|
+
method: "POST",
|
|
841
|
+
body,
|
|
854
842
|
url: workflowContext.url,
|
|
855
|
-
|
|
856
|
-
}
|
|
843
|
+
delay
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
try {
|
|
848
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
849
|
+
const invocationStatuses = [];
|
|
850
|
+
for (let i = 0; i < results.length; i++) {
|
|
851
|
+
const result = results[i];
|
|
852
|
+
const invocationParams = firstInvocationParams[i];
|
|
853
|
+
if (result.deduplicated) {
|
|
854
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
855
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
856
|
+
headers: invocationBatch[i].headers,
|
|
857
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
858
|
+
url: invocationParams.workflowContext.url,
|
|
859
|
+
messageId: result.messageId
|
|
860
|
+
});
|
|
861
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
862
|
+
} else {
|
|
863
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
864
|
+
headers: invocationBatch[i].headers,
|
|
865
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
866
|
+
url: invocationParams.workflowContext.url,
|
|
867
|
+
messageId: result.messageId
|
|
868
|
+
});
|
|
869
|
+
invocationStatuses.push("success");
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
873
|
+
(status) => status === "workflow-run-already-exists"
|
|
874
|
+
);
|
|
875
|
+
if (hasAnyDeduplicated) {
|
|
857
876
|
return ok("workflow-run-already-exists");
|
|
858
877
|
} else {
|
|
859
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
860
|
-
headers,
|
|
861
|
-
requestPayload: workflowContext.requestPayload,
|
|
862
|
-
url: workflowContext.url,
|
|
863
|
-
messageId: result.messageId
|
|
864
|
-
});
|
|
865
878
|
return ok("success");
|
|
866
879
|
}
|
|
867
880
|
} catch (error) {
|
|
@@ -1351,7 +1364,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1351
1364
|
return { header, status, body };
|
|
1352
1365
|
}
|
|
1353
1366
|
}
|
|
1354
|
-
static
|
|
1367
|
+
static applicationContentTypes = [
|
|
1355
1368
|
"application/json",
|
|
1356
1369
|
"application/xml",
|
|
1357
1370
|
"application/javascript",
|
|
@@ -1360,12 +1373,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1360
1373
|
"application/ld+json",
|
|
1361
1374
|
"application/rss+xml",
|
|
1362
1375
|
"application/atom+xml"
|
|
1363
|
-
]
|
|
1376
|
+
];
|
|
1364
1377
|
static isText = (contentTypeHeader) => {
|
|
1365
1378
|
if (!contentTypeHeader) {
|
|
1366
1379
|
return false;
|
|
1367
1380
|
}
|
|
1368
|
-
if (_LazyCallStep.
|
|
1381
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1369
1382
|
return true;
|
|
1370
1383
|
}
|
|
1371
1384
|
if (contentTypeHeader.startsWith("text/")) {
|
package/cloudflare.js
CHANGED
|
@@ -38,7 +38,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
38
38
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
39
39
|
var NO_CONCURRENCY = 1;
|
|
40
40
|
var DEFAULT_RETRIES = 3;
|
|
41
|
-
var VERSION = "v0.2.
|
|
41
|
+
var VERSION = "v0.2.14";
|
|
42
42
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
43
43
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
44
44
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -599,59 +599,72 @@ var StepTypes = [
|
|
|
599
599
|
|
|
600
600
|
// src/workflow-requests.ts
|
|
601
601
|
var import_qstash3 = require("@upstash/qstash");
|
|
602
|
-
var triggerFirstInvocation = async ({
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
try {
|
|
631
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
632
|
-
const result = await workflowContext.qstashClient.publish({
|
|
633
|
-
headers,
|
|
634
|
-
method: "POST",
|
|
635
|
-
body,
|
|
636
|
-
url: workflowContext.url,
|
|
637
|
-
delay
|
|
638
|
-
});
|
|
639
|
-
if (result.deduplicated) {
|
|
640
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
641
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
602
|
+
var triggerFirstInvocation = async (params) => {
|
|
603
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
604
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
605
|
+
const invocationBatch = firstInvocationParams.map(
|
|
606
|
+
({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
|
|
607
|
+
const { headers } = getHeaders({
|
|
608
|
+
initHeaderValue: "true",
|
|
609
|
+
workflowConfig: {
|
|
610
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
611
|
+
workflowUrl: workflowContext.url,
|
|
612
|
+
failureUrl: workflowContext.failureUrl,
|
|
613
|
+
retries: workflowContext.retries,
|
|
614
|
+
telemetry: telemetry2,
|
|
615
|
+
flowControl: workflowContext.flowControl,
|
|
616
|
+
useJSONContent: useJSONContent ?? false
|
|
617
|
+
},
|
|
618
|
+
invokeCount: invokeCount ?? 0,
|
|
619
|
+
userHeaders: workflowContext.headers
|
|
620
|
+
});
|
|
621
|
+
if (workflowContext.headers.get("content-type")) {
|
|
622
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
623
|
+
}
|
|
624
|
+
if (useJSONContent) {
|
|
625
|
+
headers["content-type"] = "application/json";
|
|
626
|
+
}
|
|
627
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
628
|
+
return {
|
|
642
629
|
headers,
|
|
643
|
-
|
|
630
|
+
method: "POST",
|
|
631
|
+
body,
|
|
644
632
|
url: workflowContext.url,
|
|
645
|
-
|
|
646
|
-
}
|
|
633
|
+
delay
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
try {
|
|
638
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
639
|
+
const invocationStatuses = [];
|
|
640
|
+
for (let i = 0; i < results.length; i++) {
|
|
641
|
+
const result = results[i];
|
|
642
|
+
const invocationParams = firstInvocationParams[i];
|
|
643
|
+
if (result.deduplicated) {
|
|
644
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
645
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
646
|
+
headers: invocationBatch[i].headers,
|
|
647
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
648
|
+
url: invocationParams.workflowContext.url,
|
|
649
|
+
messageId: result.messageId
|
|
650
|
+
});
|
|
651
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
652
|
+
} else {
|
|
653
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
654
|
+
headers: invocationBatch[i].headers,
|
|
655
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
656
|
+
url: invocationParams.workflowContext.url,
|
|
657
|
+
messageId: result.messageId
|
|
658
|
+
});
|
|
659
|
+
invocationStatuses.push("success");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
663
|
+
(status) => status === "workflow-run-already-exists"
|
|
664
|
+
);
|
|
665
|
+
if (hasAnyDeduplicated) {
|
|
647
666
|
return ok("workflow-run-already-exists");
|
|
648
667
|
} else {
|
|
649
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
650
|
-
headers,
|
|
651
|
-
requestPayload: workflowContext.requestPayload,
|
|
652
|
-
url: workflowContext.url,
|
|
653
|
-
messageId: result.messageId
|
|
654
|
-
});
|
|
655
668
|
return ok("success");
|
|
656
669
|
}
|
|
657
670
|
} catch (error) {
|
|
@@ -1141,7 +1154,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1141
1154
|
return { header, status, body };
|
|
1142
1155
|
}
|
|
1143
1156
|
}
|
|
1144
|
-
static
|
|
1157
|
+
static applicationContentTypes = [
|
|
1145
1158
|
"application/json",
|
|
1146
1159
|
"application/xml",
|
|
1147
1160
|
"application/javascript",
|
|
@@ -1150,12 +1163,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1150
1163
|
"application/ld+json",
|
|
1151
1164
|
"application/rss+xml",
|
|
1152
1165
|
"application/atom+xml"
|
|
1153
|
-
]
|
|
1166
|
+
];
|
|
1154
1167
|
static isText = (contentTypeHeader) => {
|
|
1155
1168
|
if (!contentTypeHeader) {
|
|
1156
1169
|
return false;
|
|
1157
1170
|
}
|
|
1158
|
-
if (_LazyCallStep.
|
|
1171
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1159
1172
|
return true;
|
|
1160
1173
|
}
|
|
1161
1174
|
if (contentTypeHeader.startsWith("text/")) {
|
package/cloudflare.mjs
CHANGED
package/express.js
CHANGED
|
@@ -23710,7 +23710,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
23710
23710
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
23711
23711
|
var NO_CONCURRENCY = 1;
|
|
23712
23712
|
var DEFAULT_RETRIES = 3;
|
|
23713
|
-
var VERSION = "v0.2.
|
|
23713
|
+
var VERSION = "v0.2.14";
|
|
23714
23714
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
23715
23715
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
23716
23716
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -24271,59 +24271,72 @@ var StepTypes = [
|
|
|
24271
24271
|
|
|
24272
24272
|
// src/workflow-requests.ts
|
|
24273
24273
|
var import_qstash3 = require("@upstash/qstash");
|
|
24274
|
-
var triggerFirstInvocation = async ({
|
|
24275
|
-
|
|
24276
|
-
|
|
24277
|
-
|
|
24278
|
-
|
|
24279
|
-
|
|
24280
|
-
|
|
24281
|
-
|
|
24282
|
-
|
|
24283
|
-
|
|
24284
|
-
|
|
24285
|
-
|
|
24286
|
-
|
|
24287
|
-
|
|
24288
|
-
|
|
24289
|
-
|
|
24290
|
-
|
|
24291
|
-
|
|
24292
|
-
|
|
24293
|
-
|
|
24294
|
-
|
|
24295
|
-
|
|
24296
|
-
|
|
24297
|
-
|
|
24298
|
-
|
|
24299
|
-
|
|
24300
|
-
|
|
24301
|
-
}
|
|
24302
|
-
try {
|
|
24303
|
-
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
24304
|
-
const result = await workflowContext.qstashClient.publish({
|
|
24305
|
-
headers,
|
|
24306
|
-
method: "POST",
|
|
24307
|
-
body,
|
|
24308
|
-
url: workflowContext.url,
|
|
24309
|
-
delay
|
|
24310
|
-
});
|
|
24311
|
-
if (result.deduplicated) {
|
|
24312
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
24313
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
24274
|
+
var triggerFirstInvocation = async (params) => {
|
|
24275
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
24276
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
24277
|
+
const invocationBatch = firstInvocationParams.map(
|
|
24278
|
+
({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
|
|
24279
|
+
const { headers } = getHeaders({
|
|
24280
|
+
initHeaderValue: "true",
|
|
24281
|
+
workflowConfig: {
|
|
24282
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
24283
|
+
workflowUrl: workflowContext.url,
|
|
24284
|
+
failureUrl: workflowContext.failureUrl,
|
|
24285
|
+
retries: workflowContext.retries,
|
|
24286
|
+
telemetry: telemetry2,
|
|
24287
|
+
flowControl: workflowContext.flowControl,
|
|
24288
|
+
useJSONContent: useJSONContent ?? false
|
|
24289
|
+
},
|
|
24290
|
+
invokeCount: invokeCount ?? 0,
|
|
24291
|
+
userHeaders: workflowContext.headers
|
|
24292
|
+
});
|
|
24293
|
+
if (workflowContext.headers.get("content-type")) {
|
|
24294
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
24295
|
+
}
|
|
24296
|
+
if (useJSONContent) {
|
|
24297
|
+
headers["content-type"] = "application/json";
|
|
24298
|
+
}
|
|
24299
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
24300
|
+
return {
|
|
24314
24301
|
headers,
|
|
24315
|
-
|
|
24302
|
+
method: "POST",
|
|
24303
|
+
body,
|
|
24316
24304
|
url: workflowContext.url,
|
|
24317
|
-
|
|
24318
|
-
}
|
|
24305
|
+
delay
|
|
24306
|
+
};
|
|
24307
|
+
}
|
|
24308
|
+
);
|
|
24309
|
+
try {
|
|
24310
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
24311
|
+
const invocationStatuses = [];
|
|
24312
|
+
for (let i = 0; i < results.length; i++) {
|
|
24313
|
+
const result = results[i];
|
|
24314
|
+
const invocationParams = firstInvocationParams[i];
|
|
24315
|
+
if (result.deduplicated) {
|
|
24316
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
24317
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
24318
|
+
headers: invocationBatch[i].headers,
|
|
24319
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
24320
|
+
url: invocationParams.workflowContext.url,
|
|
24321
|
+
messageId: result.messageId
|
|
24322
|
+
});
|
|
24323
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
24324
|
+
} else {
|
|
24325
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
24326
|
+
headers: invocationBatch[i].headers,
|
|
24327
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
24328
|
+
url: invocationParams.workflowContext.url,
|
|
24329
|
+
messageId: result.messageId
|
|
24330
|
+
});
|
|
24331
|
+
invocationStatuses.push("success");
|
|
24332
|
+
}
|
|
24333
|
+
}
|
|
24334
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
24335
|
+
(status) => status === "workflow-run-already-exists"
|
|
24336
|
+
);
|
|
24337
|
+
if (hasAnyDeduplicated) {
|
|
24319
24338
|
return ok("workflow-run-already-exists");
|
|
24320
24339
|
} else {
|
|
24321
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
24322
|
-
headers,
|
|
24323
|
-
requestPayload: workflowContext.requestPayload,
|
|
24324
|
-
url: workflowContext.url,
|
|
24325
|
-
messageId: result.messageId
|
|
24326
|
-
});
|
|
24327
24340
|
return ok("success");
|
|
24328
24341
|
}
|
|
24329
24342
|
} catch (error) {
|
|
@@ -24813,7 +24826,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
24813
24826
|
return { header, status, body };
|
|
24814
24827
|
}
|
|
24815
24828
|
}
|
|
24816
|
-
static
|
|
24829
|
+
static applicationContentTypes = [
|
|
24817
24830
|
"application/json",
|
|
24818
24831
|
"application/xml",
|
|
24819
24832
|
"application/javascript",
|
|
@@ -24822,12 +24835,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
24822
24835
|
"application/ld+json",
|
|
24823
24836
|
"application/rss+xml",
|
|
24824
24837
|
"application/atom+xml"
|
|
24825
|
-
]
|
|
24838
|
+
];
|
|
24826
24839
|
static isText = (contentTypeHeader) => {
|
|
24827
24840
|
if (!contentTypeHeader) {
|
|
24828
24841
|
return false;
|
|
24829
24842
|
}
|
|
24830
|
-
if (_LazyCallStep.
|
|
24843
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
24831
24844
|
return true;
|
|
24832
24845
|
}
|
|
24833
24846
|
if (contentTypeHeader.startsWith("text/")) {
|