@upstash/qstash 2.6.4-workflow-alpha.0 → 2.6.4-workflow-alpha.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/{dist/chunk-OAS6SVLB.js → chunk-AIRND3SP.js} +95 -217
- package/{dist/chunk-EXC7PGHF.mjs → chunk-FRFK4HSB.mjs} +87 -209
- package/{dist/index.d.mts → index.d.mts} +2 -3
- package/{dist/index.d.ts → index.d.ts} +2 -3
- package/{dist/nextjs.d.mts → nextjs.d.mts} +1 -2
- package/{dist/nextjs.d.ts → nextjs.d.ts} +1 -2
- package/{dist/nextjs.js → nextjs.js} +2 -2
- package/{dist/nextjs.mjs → nextjs.mjs} +1 -1
- package/{dist/nuxt.d.mts → nuxt.d.mts} +1 -2
- package/{dist/nuxt.d.ts → nuxt.d.ts} +1 -2
- package/{dist/nuxt.js → nuxt.js} +2 -2
- package/{dist/nuxt.mjs → nuxt.mjs} +1 -1
- package/package.json +1 -105
- package/{dist/solidjs.d.mts → solidjs.d.mts} +1 -2
- package/{dist/solidjs.d.ts → solidjs.d.ts} +1 -2
- package/{dist/solidjs.js → solidjs.js} +2 -2
- package/{dist/solidjs.mjs → solidjs.mjs} +1 -1
- package/{dist/svelte.d.mts → svelte.d.mts} +1 -2
- package/{dist/svelte.d.ts → svelte.d.ts} +1 -2
- package/{dist/svelte.js → svelte.js} +2 -2
- package/{dist/svelte.mjs → svelte.mjs} +1 -1
- package/{dist/types-BBuddmpw.d.ts → types-C4BlT_L_.d.mts} +17 -78
- package/{dist/types-BBuddmpw.d.mts → types-C4BlT_L_.d.ts} +17 -78
- package/{dist/workflow.d.mts → workflow.d.mts} +2 -3
- package/{dist/workflow.d.ts → workflow.d.ts} +2 -3
- package/workflow.js +13 -0
- package/{dist/workflow.mjs → workflow.mjs} +1 -3
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -160
- package/dist/package.json +0 -105
- package/dist/workflow.js +0 -15
- /package/{dist/chunk-AP5AZGAQ.mjs → chunk-AP5AZGAQ.mjs} +0 -0
- /package/{dist/chunk-F6QRAN74.js → chunk-F6QRAN74.js} +0 -0
- /package/{dist/chunk-TAUBWUPA.mjs → chunk-TAUBWUPA.mjs} +0 -0
- /package/{dist/chunk-Z3TALRVS.js → chunk-Z3TALRVS.js} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.mjs → index.mjs} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -381,7 +381,6 @@ var fromThrowable = Result.fromThrowable;
|
|
|
381
381
|
var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
|
|
382
382
|
var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
|
|
383
383
|
var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
384
|
-
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
385
384
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
386
385
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
387
386
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
@@ -395,9 +394,7 @@ var triggerFirstInvocation = async (workflowContext, debug) => {
|
|
|
395
394
|
"true",
|
|
396
395
|
workflowContext.workflowRunId,
|
|
397
396
|
workflowContext.url,
|
|
398
|
-
workflowContext.headers
|
|
399
|
-
void 0,
|
|
400
|
-
workflowContext.failureUrl
|
|
397
|
+
workflowContext.headers
|
|
401
398
|
);
|
|
402
399
|
await _optionalChain([debug, 'optionalAccess', _2 => _2.log, 'call', _3 => _3("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
403
400
|
headers,
|
|
@@ -448,10 +445,12 @@ var recreateUserHeaders = (headers) => {
|
|
|
448
445
|
}
|
|
449
446
|
return filteredHeaders;
|
|
450
447
|
};
|
|
451
|
-
var handleThirdPartyCallResult = async (request,
|
|
448
|
+
var handleThirdPartyCallResult = async (request, client, debug, verifier) => {
|
|
452
449
|
try {
|
|
453
450
|
if (request.headers.get("Upstash-Workflow-Callback")) {
|
|
454
|
-
const
|
|
451
|
+
const callbackBody = await request.text();
|
|
452
|
+
await verifyRequest(callbackBody, request.headers.get("upstash-signature"), verifier);
|
|
453
|
+
const callbackMessage = JSON.parse(callbackBody);
|
|
455
454
|
if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
|
|
456
455
|
await _optionalChain([debug, 'optionalAccess', _8 => _8.log, 'call', _9 => _9("WARN", "SUBMIT_THIRD_PARTY_RESULT", callbackMessage)]);
|
|
457
456
|
return ok("call-will-retry");
|
|
@@ -475,20 +474,14 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, failure
|
|
|
475
474
|
);
|
|
476
475
|
}
|
|
477
476
|
const userHeaders = recreateUserHeaders(request.headers);
|
|
478
|
-
const requestHeaders = getHeaders(
|
|
479
|
-
"false",
|
|
480
|
-
workflowRunId,
|
|
481
|
-
request.url,
|
|
482
|
-
userHeaders,
|
|
483
|
-
void 0,
|
|
484
|
-
failureUrl
|
|
485
|
-
);
|
|
477
|
+
const requestHeaders = getHeaders("false", workflowRunId, request.url, userHeaders);
|
|
486
478
|
const callResultStep = {
|
|
487
479
|
stepId: Number(stepIdString),
|
|
488
480
|
stepName,
|
|
489
481
|
stepType,
|
|
490
482
|
out: Buffer.from(callbackMessage.body, "base64").toString(),
|
|
491
|
-
concurrent: Number(concurrentString)
|
|
483
|
+
concurrent: Number(concurrentString),
|
|
484
|
+
targetStep: 0
|
|
492
485
|
};
|
|
493
486
|
await _optionalChain([debug, 'optionalAccess', _10 => _10.log, 'call', _11 => _11("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
|
|
494
487
|
step: callResultStep,
|
|
@@ -517,16 +510,12 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, failure
|
|
|
517
510
|
);
|
|
518
511
|
}
|
|
519
512
|
};
|
|
520
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
513
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step) => {
|
|
521
514
|
const baseHeaders = {
|
|
522
515
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
523
516
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
524
517
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
525
|
-
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION
|
|
526
|
-
...failureUrl ? {
|
|
527
|
-
[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`]: "true",
|
|
528
|
-
"Upstash-Failure-Callback": failureUrl
|
|
529
|
-
} : {}
|
|
518
|
+
[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION
|
|
530
519
|
};
|
|
531
520
|
if (userHeaders) {
|
|
532
521
|
for (const header of userHeaders.keys()) {
|
|
@@ -585,7 +574,6 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
585
574
|
__init() {this.promises = /* @__PURE__ */ new WeakMap()}
|
|
586
575
|
|
|
587
576
|
|
|
588
|
-
|
|
589
577
|
__init2() {this.indexInCurrentList = 0}
|
|
590
578
|
__init3() {this.stepCount = 0}
|
|
591
579
|
__init4() {this.planStepCount = 0}
|
|
@@ -593,7 +581,6 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
593
581
|
constructor(context, debug) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
|
|
594
582
|
this.context = context;
|
|
595
583
|
this.debug = debug;
|
|
596
|
-
this.nonPlanStepCount = this.context.steps.filter((step) => !step.targetStep).length;
|
|
597
584
|
}
|
|
598
585
|
/**
|
|
599
586
|
* Adds the step function to the list of step functions to run in
|
|
@@ -667,7 +654,7 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
667
654
|
* @returns step result
|
|
668
655
|
*/
|
|
669
656
|
async runSingle(lazyStep) {
|
|
670
|
-
if (this.stepCount < this.nonPlanStepCount) {
|
|
657
|
+
if (this.stepCount < this.context.nonPlanStepCount) {
|
|
671
658
|
const step = this.context.steps[this.stepCount + this.planStepCount];
|
|
672
659
|
validateStep(lazyStep, step);
|
|
673
660
|
await _optionalChain([this, 'access', _16 => _16.debug, 'optionalAccess', _17 => _17.log, 'call', _18 => _18("INFO", "RUN_SINGLE", {
|
|
@@ -677,7 +664,7 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
677
664
|
})]);
|
|
678
665
|
return step.out;
|
|
679
666
|
}
|
|
680
|
-
const resultStep = await lazyStep.getResultStep(
|
|
667
|
+
const resultStep = await lazyStep.getResultStep(this.stepCount, true);
|
|
681
668
|
await _optionalChain([this, 'access', _19 => _19.debug, 'optionalAccess', _20 => _20.log, 'call', _21 => _21("INFO", "RUN_SINGLE", {
|
|
682
669
|
fromRequest: false,
|
|
683
670
|
step: resultStep,
|
|
@@ -720,7 +707,7 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
720
707
|
}
|
|
721
708
|
case "partial": {
|
|
722
709
|
const planStep = this.context.steps.at(-1);
|
|
723
|
-
if (!planStep || planStep.targetStep ===
|
|
710
|
+
if (!planStep || planStep.targetStep === 0) {
|
|
724
711
|
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowError)(
|
|
725
712
|
`There must be a last step and it should have targetStep larger than 0.Received: ${JSON.stringify(planStep)}`
|
|
726
713
|
);
|
|
@@ -729,8 +716,8 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
729
716
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
730
717
|
try {
|
|
731
718
|
const resultStep = await parallelSteps[stepIndex].getResultStep(
|
|
732
|
-
|
|
733
|
-
|
|
719
|
+
planStep.targetStep,
|
|
720
|
+
false
|
|
734
721
|
);
|
|
735
722
|
await this.submitStepsToQstash([resultStep]);
|
|
736
723
|
} catch (error) {
|
|
@@ -776,7 +763,7 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
776
763
|
*/
|
|
777
764
|
getParallelCallState(parallelStepCount, initialStepCount) {
|
|
778
765
|
const remainingSteps = this.context.steps.filter(
|
|
779
|
-
(step) => (
|
|
766
|
+
(step) => (step.stepId === 0 ? step.targetStep : step.stepId) >= initialStepCount
|
|
780
767
|
);
|
|
781
768
|
if (remainingSteps.length === 0) {
|
|
782
769
|
return "first";
|
|
@@ -807,10 +794,8 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
807
794
|
this.context.workflowRunId,
|
|
808
795
|
this.context.url,
|
|
809
796
|
this.context.headers,
|
|
810
|
-
singleStep
|
|
811
|
-
this.context.failureUrl
|
|
797
|
+
singleStep
|
|
812
798
|
);
|
|
813
|
-
const willWait = singleStep.concurrent === 1 || singleStep.stepId === 0;
|
|
814
799
|
return singleStep.callUrl ? (
|
|
815
800
|
// if the step is a third party call, we call the third party
|
|
816
801
|
// url (singleStep.callUrl) and pass information about the workflow
|
|
@@ -833,8 +818,8 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
833
818
|
method: "POST",
|
|
834
819
|
body: singleStep,
|
|
835
820
|
url: this.context.url,
|
|
836
|
-
notBefore:
|
|
837
|
-
delay:
|
|
821
|
+
notBefore: singleStep.sleepUntil,
|
|
822
|
+
delay: singleStep.sleepFor
|
|
838
823
|
}
|
|
839
824
|
);
|
|
840
825
|
})
|
|
@@ -883,12 +868,12 @@ var AutoExecutor = (_class = class _AutoExecutor {
|
|
|
883
868
|
var validateStep = (lazyStep, stepFromRequest) => {
|
|
884
869
|
if (lazyStep.stepName !== stepFromRequest.stepName) {
|
|
885
870
|
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowError)(
|
|
886
|
-
`Incompatible step name. Expected
|
|
871
|
+
`Incompatible step name. Expected ${lazyStep.stepName}, got ${stepFromRequest.stepName} from the request`
|
|
887
872
|
);
|
|
888
873
|
}
|
|
889
874
|
if (lazyStep.stepType !== stepFromRequest.stepType) {
|
|
890
875
|
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowError)(
|
|
891
|
-
`Incompatible step type. Expected
|
|
876
|
+
`Incompatible step type. Expected ${lazyStep.stepType}, got ${stepFromRequest.stepType} from the request`
|
|
892
877
|
);
|
|
893
878
|
}
|
|
894
879
|
};
|
|
@@ -905,17 +890,17 @@ var validateParallelSteps = (lazySteps, stepsFromRequest) => {
|
|
|
905
890
|
const requestStepTypes = stepsFromRequest.map((step) => step.stepType);
|
|
906
891
|
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowError)(
|
|
907
892
|
`Incompatible steps detected in parallel execution: ${error.message}
|
|
908
|
-
> Step Names from the request: ${
|
|
909
|
-
Step Types from the request: ${
|
|
910
|
-
> Step Names expected: ${
|
|
911
|
-
Step Types expected: ${
|
|
893
|
+
> Step Names from the request: ${requestStepNames}
|
|
894
|
+
Step Types from the request: ${requestStepTypes}
|
|
895
|
+
> Step Names expected: ${lazyStepNames}
|
|
896
|
+
Step Types expected: ${lazyStepTypes}`
|
|
912
897
|
);
|
|
913
898
|
}
|
|
914
899
|
throw error;
|
|
915
900
|
}
|
|
916
901
|
};
|
|
917
902
|
var sortSteps = (steps) => {
|
|
918
|
-
const getStepId = (step) =>
|
|
903
|
+
const getStepId = (step) => step.stepId === 0 ? step.targetStep : step.stepId;
|
|
919
904
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
920
905
|
};
|
|
921
906
|
|
|
@@ -945,14 +930,15 @@ var LazyFunctionStep = (_class2 = class extends BaseLazyStep {
|
|
|
945
930
|
};
|
|
946
931
|
}
|
|
947
932
|
}
|
|
948
|
-
async getResultStep(
|
|
933
|
+
async getResultStep(stepId, _singleStep) {
|
|
949
934
|
const result = await this.stepFunction();
|
|
950
935
|
return {
|
|
951
936
|
stepId,
|
|
952
937
|
stepName: this.stepName,
|
|
953
938
|
stepType: this.stepType,
|
|
954
939
|
out: result,
|
|
955
|
-
concurrent
|
|
940
|
+
concurrent: 1,
|
|
941
|
+
targetStep: 0
|
|
956
942
|
};
|
|
957
943
|
}
|
|
958
944
|
}, _class2);
|
|
@@ -975,13 +961,16 @@ var LazySleepStep = (_class3 = class extends BaseLazyStep {
|
|
|
975
961
|
};
|
|
976
962
|
}
|
|
977
963
|
}
|
|
978
|
-
async getResultStep(
|
|
964
|
+
async getResultStep(stepId, singleStep) {
|
|
979
965
|
return await Promise.resolve({
|
|
980
966
|
stepId,
|
|
981
967
|
stepName: this.stepName,
|
|
982
968
|
stepType: this.stepType,
|
|
983
|
-
sleepFor
|
|
984
|
-
|
|
969
|
+
// apply sleepFor if the step is running by itself. If it's running parallel,
|
|
970
|
+
// the sleepFor is already applied in the plan step
|
|
971
|
+
sleepFor: singleStep ? this.sleep : void 0,
|
|
972
|
+
concurrent: 1,
|
|
973
|
+
targetStep: 0
|
|
985
974
|
});
|
|
986
975
|
}
|
|
987
976
|
}, _class3);
|
|
@@ -1004,13 +993,16 @@ var LazySleepUntilStep = (_class4 = class extends BaseLazyStep {
|
|
|
1004
993
|
};
|
|
1005
994
|
}
|
|
1006
995
|
}
|
|
1007
|
-
async getResultStep(
|
|
996
|
+
async getResultStep(stepId, singleStep) {
|
|
1008
997
|
return await Promise.resolve({
|
|
1009
998
|
stepId,
|
|
1010
999
|
stepName: this.stepName,
|
|
1011
1000
|
stepType: this.stepType,
|
|
1012
|
-
sleepUntil
|
|
1013
|
-
|
|
1001
|
+
// apply sleepUntil if the step is running by itself. If it's running parallel,
|
|
1002
|
+
// the sleepUntil is already applied in the plan step
|
|
1003
|
+
sleepUntil: singleStep ? this.sleepUntil : void 0,
|
|
1004
|
+
concurrent: 1,
|
|
1005
|
+
targetStep: 0
|
|
1014
1006
|
});
|
|
1015
1007
|
}
|
|
1016
1008
|
}, _class4);
|
|
@@ -1038,12 +1030,13 @@ var LazyCallStep = (_class5 = class extends BaseLazyStep {
|
|
|
1038
1030
|
};
|
|
1039
1031
|
}
|
|
1040
1032
|
}
|
|
1041
|
-
async getResultStep(
|
|
1033
|
+
async getResultStep(stepId) {
|
|
1042
1034
|
return await Promise.resolve({
|
|
1043
1035
|
stepId,
|
|
1044
1036
|
stepName: this.stepName,
|
|
1045
1037
|
stepType: this.stepType,
|
|
1046
|
-
concurrent,
|
|
1038
|
+
concurrent: 1,
|
|
1039
|
+
targetStep: 0,
|
|
1047
1040
|
callUrl: this.url,
|
|
1048
1041
|
callMethod: this.method,
|
|
1049
1042
|
callBody: this.body,
|
|
@@ -1062,26 +1055,22 @@ var WorkflowContext = class {
|
|
|
1062
1055
|
|
|
1063
1056
|
|
|
1064
1057
|
|
|
1065
|
-
|
|
1066
1058
|
constructor({
|
|
1067
1059
|
client,
|
|
1068
1060
|
workflowRunId,
|
|
1061
|
+
initialPayload,
|
|
1069
1062
|
headers,
|
|
1070
1063
|
steps,
|
|
1071
1064
|
url,
|
|
1072
|
-
|
|
1073
|
-
debug,
|
|
1074
|
-
initialPayload,
|
|
1075
|
-
rawInitialPayload
|
|
1065
|
+
debug
|
|
1076
1066
|
}) {
|
|
1077
1067
|
this.client = client;
|
|
1078
1068
|
this.workflowRunId = workflowRunId;
|
|
1079
1069
|
this.steps = steps;
|
|
1080
1070
|
this.url = url;
|
|
1081
|
-
this.failureUrl = failureUrl;
|
|
1082
|
-
this.headers = headers;
|
|
1083
1071
|
this.requestPayload = initialPayload;
|
|
1084
|
-
this.
|
|
1072
|
+
this.headers = headers;
|
|
1073
|
+
this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
|
|
1085
1074
|
this.executor = new AutoExecutor(this, debug);
|
|
1086
1075
|
}
|
|
1087
1076
|
/**
|
|
@@ -1113,7 +1102,7 @@ var WorkflowContext = class {
|
|
|
1113
1102
|
*/
|
|
1114
1103
|
async run(stepName, stepFunction) {
|
|
1115
1104
|
const wrappedStepFunction = async () => this.executor.wrapStep(stepName, stepFunction);
|
|
1116
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
1105
|
+
return this.executor.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
1117
1106
|
}
|
|
1118
1107
|
/**
|
|
1119
1108
|
* Stops the execution for the duration provided.
|
|
@@ -1123,7 +1112,7 @@ var WorkflowContext = class {
|
|
|
1123
1112
|
* @returns
|
|
1124
1113
|
*/
|
|
1125
1114
|
async sleep(stepName, duration) {
|
|
1126
|
-
await this.addStep(new LazySleepStep(stepName, duration));
|
|
1115
|
+
await this.executor.addStep(new LazySleepStep(stepName, duration));
|
|
1127
1116
|
}
|
|
1128
1117
|
/**
|
|
1129
1118
|
* Stops the execution until the date time provided.
|
|
@@ -1141,73 +1130,21 @@ var WorkflowContext = class {
|
|
|
1141
1130
|
datetime = typeof datetime === "string" ? new Date(datetime) : datetime;
|
|
1142
1131
|
time = Math.round(datetime.getTime() / 1e3);
|
|
1143
1132
|
}
|
|
1144
|
-
await this.addStep(new LazySleepUntilStep(stepName, time));
|
|
1133
|
+
await this.executor.addStep(new LazySleepUntilStep(stepName, time));
|
|
1145
1134
|
}
|
|
1146
1135
|
async call(stepName, url, method, body, headers) {
|
|
1147
|
-
return await this.addStep(
|
|
1136
|
+
return await this.executor.addStep(
|
|
1148
1137
|
new LazyCallStep(stepName, url, method, body, _nullishCoalesce(headers, () => ( {})))
|
|
1149
1138
|
);
|
|
1150
1139
|
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
1153
|
-
* DisabledWorkflowContext.
|
|
1154
|
-
*/
|
|
1155
|
-
async addStep(step) {
|
|
1156
|
-
return await this.executor.addStep(step);
|
|
1157
|
-
}
|
|
1158
1140
|
};
|
|
1159
|
-
var DisabledWorkflowContext = (_class6 = class _DisabledWorkflowContext extends WorkflowContext {
|
|
1160
|
-
static __initStatic() {this.disabledMessage = "disabled-qstash-worklfow-run"}
|
|
1161
|
-
/**
|
|
1162
|
-
* overwrite the WorkflowContext.addStep method to always raise QstashWorkflowAbort
|
|
1163
|
-
* error in order to stop the execution whenever we encounter a step.
|
|
1164
|
-
*
|
|
1165
|
-
* @param _step
|
|
1166
|
-
*/
|
|
1167
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1168
|
-
async addStep(_step) {
|
|
1169
|
-
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowAbort)(_DisabledWorkflowContext.disabledMessage);
|
|
1170
|
-
}
|
|
1171
|
-
/**
|
|
1172
|
-
* copies the passed context to create a DisabledWorkflowContext. Then, runs the
|
|
1173
|
-
* route function with the new context.
|
|
1174
|
-
*
|
|
1175
|
-
* - returns "run-ended" if there are no steps found or
|
|
1176
|
-
* if the auth failed and user called `return`
|
|
1177
|
-
* - returns "step-found" if DisabledWorkflowContext.addStep is called.
|
|
1178
|
-
* - if there is another error, returns the error.
|
|
1179
|
-
*
|
|
1180
|
-
* @param routeFunction
|
|
1181
|
-
*/
|
|
1182
|
-
static async tryAuthentication(routeFunction, context) {
|
|
1183
|
-
const disabledContext = new _DisabledWorkflowContext({
|
|
1184
|
-
client: new (0, _chunkZ3TALRVSjs.Client)({ baseUrl: "disabled-client", token: "disabled-client" }),
|
|
1185
|
-
workflowRunId: context.workflowRunId,
|
|
1186
|
-
headers: context.headers,
|
|
1187
|
-
steps: context.steps,
|
|
1188
|
-
url: context.url,
|
|
1189
|
-
failureUrl: context.failureUrl,
|
|
1190
|
-
initialPayload: context.requestPayload,
|
|
1191
|
-
rawInitialPayload: context.rawInitialPayload
|
|
1192
|
-
});
|
|
1193
|
-
try {
|
|
1194
|
-
await routeFunction(disabledContext);
|
|
1195
|
-
} catch (error) {
|
|
1196
|
-
if (error instanceof _chunkZ3TALRVSjs.QstashWorkflowAbort && error.stepName === this.disabledMessage) {
|
|
1197
|
-
return ok("step-found");
|
|
1198
|
-
}
|
|
1199
|
-
return err(error);
|
|
1200
|
-
}
|
|
1201
|
-
return ok("run-ended");
|
|
1202
|
-
}
|
|
1203
|
-
}, _class6.__initStatic(), _class6);
|
|
1204
1141
|
|
|
1205
1142
|
// src/client/workflow/logger.ts
|
|
1206
1143
|
var LOG_LEVELS = ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
|
|
1207
|
-
var WorkflowLogger = (
|
|
1144
|
+
var WorkflowLogger = (_class6 = class _WorkflowLogger {
|
|
1208
1145
|
__init10() {this.logs = []}
|
|
1209
1146
|
|
|
1210
|
-
constructor(options) {;
|
|
1147
|
+
constructor(options) {;_class6.prototype.__init10.call(this);
|
|
1211
1148
|
this.options = options;
|
|
1212
1149
|
}
|
|
1213
1150
|
async log(level, eventType, details) {
|
|
@@ -1243,7 +1180,7 @@ var WorkflowLogger = (_class7 = class _WorkflowLogger {
|
|
|
1243
1180
|
}) : void 0;
|
|
1244
1181
|
}
|
|
1245
1182
|
}
|
|
1246
|
-
},
|
|
1183
|
+
}, _class6);
|
|
1247
1184
|
|
|
1248
1185
|
// node_modules/nanoid/index.js
|
|
1249
1186
|
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
@@ -1288,13 +1225,14 @@ var decodeBase64 = (encodedString) => {
|
|
|
1288
1225
|
};
|
|
1289
1226
|
var parsePayload = (rawPayload) => {
|
|
1290
1227
|
const [encodedInitialPayload, ...encodedSteps] = JSON.parse(rawPayload);
|
|
1291
|
-
const
|
|
1228
|
+
const initialPayload = decodeBase64(encodedInitialPayload.body);
|
|
1292
1229
|
const initialStep = {
|
|
1293
1230
|
stepId: 0,
|
|
1294
1231
|
stepName: "init",
|
|
1295
1232
|
stepType: "Initial",
|
|
1296
|
-
out:
|
|
1297
|
-
concurrent: 1
|
|
1233
|
+
out: initialPayload,
|
|
1234
|
+
concurrent: 1,
|
|
1235
|
+
targetStep: 0
|
|
1298
1236
|
};
|
|
1299
1237
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
1300
1238
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
@@ -1302,7 +1240,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1302
1240
|
});
|
|
1303
1241
|
const steps = [initialStep, ...otherSteps];
|
|
1304
1242
|
return {
|
|
1305
|
-
|
|
1243
|
+
initialPayload,
|
|
1306
1244
|
steps
|
|
1307
1245
|
};
|
|
1308
1246
|
};
|
|
@@ -1312,9 +1250,9 @@ var deduplicateSteps = (steps) => {
|
|
|
1312
1250
|
const deduplicatedSteps = [];
|
|
1313
1251
|
for (const step of steps) {
|
|
1314
1252
|
if (step.stepId === 0) {
|
|
1315
|
-
if (!targetStepIds.includes(
|
|
1253
|
+
if (!targetStepIds.includes(step.targetStep)) {
|
|
1316
1254
|
deduplicatedSteps.push(step);
|
|
1317
|
-
targetStepIds.push(
|
|
1255
|
+
targetStepIds.push(step.targetStep);
|
|
1318
1256
|
}
|
|
1319
1257
|
} else {
|
|
1320
1258
|
if (!stepIds.includes(step.stepId)) {
|
|
@@ -1365,7 +1303,7 @@ var parseRequest = async (request, isFirstInvocation, verifier, debug) => {
|
|
|
1365
1303
|
await verifyRequest(_nullishCoalesce(payload, () => ( "")), request.headers.get("upstash-signature"), verifier);
|
|
1366
1304
|
if (isFirstInvocation) {
|
|
1367
1305
|
return {
|
|
1368
|
-
|
|
1306
|
+
initialPayload: _nullishCoalesce(payload, () => ( "")),
|
|
1369
1307
|
steps: [],
|
|
1370
1308
|
isLastDuplicate: false
|
|
1371
1309
|
};
|
|
@@ -1373,36 +1311,16 @@ var parseRequest = async (request, isFirstInvocation, verifier, debug) => {
|
|
|
1373
1311
|
if (!payload) {
|
|
1374
1312
|
throw new (0, _chunkZ3TALRVSjs.QstashWorkflowError)("Only first call can have an empty body");
|
|
1375
1313
|
}
|
|
1376
|
-
const {
|
|
1314
|
+
const { initialPayload, steps } = parsePayload(payload);
|
|
1377
1315
|
const isLastDuplicate = await checkIfLastOneIsDuplicate(steps, debug);
|
|
1378
1316
|
const deduplicatedSteps = deduplicateSteps(steps);
|
|
1379
1317
|
return {
|
|
1380
|
-
|
|
1318
|
+
initialPayload,
|
|
1381
1319
|
steps: deduplicatedSteps,
|
|
1382
1320
|
isLastDuplicate
|
|
1383
1321
|
};
|
|
1384
1322
|
}
|
|
1385
1323
|
};
|
|
1386
|
-
var handleFailure = async (request, failureFunction) => {
|
|
1387
|
-
if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
|
|
1388
|
-
return ok("not-failure-callback");
|
|
1389
|
-
}
|
|
1390
|
-
if (!failureFunction) {
|
|
1391
|
-
return err(
|
|
1392
|
-
new (0, _chunkZ3TALRVSjs.QstashWorkflowError)(
|
|
1393
|
-
"Workflow endpoint is called to handle a failure, but a failureFunction is not provided in serve options. Either provide a failureUrl or a failureFunction."
|
|
1394
|
-
)
|
|
1395
|
-
);
|
|
1396
|
-
}
|
|
1397
|
-
try {
|
|
1398
|
-
const { status, header, body } = await request.json();
|
|
1399
|
-
const decodedBody = atob(body);
|
|
1400
|
-
await failureFunction(status, header, decodedBody);
|
|
1401
|
-
} catch (error) {
|
|
1402
|
-
return err(error);
|
|
1403
|
-
}
|
|
1404
|
-
return ok("is-failure-callback");
|
|
1405
|
-
};
|
|
1406
1324
|
|
|
1407
1325
|
// src/client/workflow/serve.ts
|
|
1408
1326
|
var processOptions = (options) => {
|
|
@@ -1414,9 +1332,7 @@ var processOptions = (options) => {
|
|
|
1414
1332
|
baseUrl: process.env.QSTASH_URL,
|
|
1415
1333
|
token: process.env.QSTASH_TOKEN
|
|
1416
1334
|
}),
|
|
1417
|
-
onStepFinish: (workflowRunId
|
|
1418
|
-
status: 200
|
|
1419
|
-
}),
|
|
1335
|
+
onStepFinish: (workflowRunId) => new Response(JSON.stringify({ workflowRunId }), { status: 200 }),
|
|
1420
1336
|
initialPayloadParser: (initialRequest) => {
|
|
1421
1337
|
if (!initialRequest) {
|
|
1422
1338
|
return void 0;
|
|
@@ -1438,8 +1354,6 @@ var processOptions = (options) => {
|
|
|
1438
1354
|
currentSigningKey: process.env.QSTASH_CURRENT_SIGNING_KEY,
|
|
1439
1355
|
nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY
|
|
1440
1356
|
}),
|
|
1441
|
-
failureUrl: false,
|
|
1442
|
-
failureFunction: false,
|
|
1443
1357
|
...options
|
|
1444
1358
|
};
|
|
1445
1359
|
};
|
|
@@ -1447,70 +1361,35 @@ var serve = ({
|
|
|
1447
1361
|
routeFunction,
|
|
1448
1362
|
options
|
|
1449
1363
|
}) => {
|
|
1450
|
-
const {
|
|
1451
|
-
client,
|
|
1452
|
-
onStepFinish,
|
|
1453
|
-
initialPayloadParser,
|
|
1454
|
-
url,
|
|
1455
|
-
verbose,
|
|
1456
|
-
receiver,
|
|
1457
|
-
failureUrl,
|
|
1458
|
-
failureFunction
|
|
1459
|
-
} = processOptions(options);
|
|
1364
|
+
const { client, onStepFinish, initialPayloadParser, url, verbose, receiver } = processOptions(options);
|
|
1460
1365
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
1461
1366
|
const verifier = receiver || void 0;
|
|
1462
1367
|
return async (request) => {
|
|
1463
|
-
const workflowUrl = url || request.url;
|
|
1464
|
-
const workflowFailureUrl = failureFunction ? workflowUrl : failureUrl;
|
|
1465
1368
|
await _optionalChain([debug, 'optionalAccess', _38 => _38.log, 'call', _39 => _39("INFO", "ENDPOINT_START")]);
|
|
1466
|
-
const
|
|
1467
|
-
if (failureCheck.isErr()) {
|
|
1468
|
-
throw failureCheck.error;
|
|
1469
|
-
} else if (failureCheck.value === "is-failure-callback") {
|
|
1470
|
-
return onStepFinish("no-workflow-id", "failure-callback");
|
|
1471
|
-
}
|
|
1472
|
-
const { isFirstInvocation, workflowRunId } = validateRequest(request);
|
|
1473
|
-
const { rawInitialPayload, steps, isLastDuplicate } = await parseRequest(
|
|
1474
|
-
request,
|
|
1475
|
-
isFirstInvocation,
|
|
1476
|
-
verifier,
|
|
1477
|
-
debug
|
|
1478
|
-
);
|
|
1479
|
-
if (isLastDuplicate) {
|
|
1480
|
-
return onStepFinish("no-workflow-id", "duplicate-step");
|
|
1481
|
-
}
|
|
1482
|
-
const workflowContext = new WorkflowContext({
|
|
1483
|
-
client,
|
|
1484
|
-
workflowRunId,
|
|
1485
|
-
initialPayload: initialPayloadParser(rawInitialPayload),
|
|
1486
|
-
rawInitialPayload,
|
|
1487
|
-
headers: recreateUserHeaders(request.headers),
|
|
1488
|
-
steps,
|
|
1489
|
-
url: workflowUrl,
|
|
1490
|
-
failureUrl: workflowFailureUrl,
|
|
1491
|
-
debug
|
|
1492
|
-
});
|
|
1493
|
-
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
1494
|
-
routeFunction,
|
|
1495
|
-
workflowContext
|
|
1496
|
-
);
|
|
1497
|
-
if (authCheck.isErr()) {
|
|
1498
|
-
await _optionalChain([debug, 'optionalAccess', _40 => _40.log, 'call', _41 => _41("ERROR", "ERROR", { error: authCheck.error })]);
|
|
1499
|
-
throw authCheck.error;
|
|
1500
|
-
} else if (authCheck.value === "run-ended") {
|
|
1501
|
-
return onStepFinish("no-workflow-id", "auth-fail");
|
|
1502
|
-
}
|
|
1503
|
-
const callReturnCheck = await handleThirdPartyCallResult(
|
|
1504
|
-
request,
|
|
1505
|
-
rawInitialPayload,
|
|
1506
|
-
client,
|
|
1507
|
-
workflowFailureUrl,
|
|
1508
|
-
debug
|
|
1509
|
-
);
|
|
1369
|
+
const callReturnCheck = await handleThirdPartyCallResult(request, client, debug, verifier);
|
|
1510
1370
|
if (callReturnCheck.isErr()) {
|
|
1511
|
-
await _optionalChain([debug, 'optionalAccess',
|
|
1371
|
+
await _optionalChain([debug, 'optionalAccess', _40 => _40.log, 'call', _41 => _41("ERROR", "SUBMIT_THIRD_PARTY_RESULT", { error: callReturnCheck.error })]);
|
|
1512
1372
|
throw callReturnCheck.error;
|
|
1513
1373
|
} else if (callReturnCheck.value === "continue-workflow") {
|
|
1374
|
+
const { isFirstInvocation, workflowRunId } = validateRequest(request);
|
|
1375
|
+
const { initialPayload, steps, isLastDuplicate } = await parseRequest(
|
|
1376
|
+
request,
|
|
1377
|
+
isFirstInvocation,
|
|
1378
|
+
verifier,
|
|
1379
|
+
debug
|
|
1380
|
+
);
|
|
1381
|
+
if (isLastDuplicate) {
|
|
1382
|
+
return onStepFinish("no-workflow-id-duplicate-step");
|
|
1383
|
+
}
|
|
1384
|
+
const workflowContext = new WorkflowContext({
|
|
1385
|
+
client,
|
|
1386
|
+
workflowRunId,
|
|
1387
|
+
initialPayload: initialPayloadParser(initialPayload),
|
|
1388
|
+
headers: recreateUserHeaders(request.headers),
|
|
1389
|
+
steps,
|
|
1390
|
+
url: url || request.url,
|
|
1391
|
+
debug
|
|
1392
|
+
});
|
|
1514
1393
|
const result = isFirstInvocation ? await triggerFirstInvocation(workflowContext, debug) : await triggerRouteFunction({
|
|
1515
1394
|
onStep: async () => routeFunction(workflowContext),
|
|
1516
1395
|
onCleanup: async () => {
|
|
@@ -1518,16 +1397,16 @@ var serve = ({
|
|
|
1518
1397
|
}
|
|
1519
1398
|
});
|
|
1520
1399
|
if (result.isErr()) {
|
|
1521
|
-
await _optionalChain([debug, 'optionalAccess',
|
|
1400
|
+
await _optionalChain([debug, 'optionalAccess', _42 => _42.log, 'call', _43 => _43("ERROR", "ERROR", { error: result.error })]);
|
|
1522
1401
|
throw result.error;
|
|
1523
1402
|
}
|
|
1524
|
-
await _optionalChain([debug, 'optionalAccess',
|
|
1403
|
+
await _optionalChain([debug, 'optionalAccess', _44 => _44.log, 'call', _45 => _45("INFO", "RESPONSE_WORKFLOW", {
|
|
1525
1404
|
workflowRunId: workflowContext.workflowRunId
|
|
1526
1405
|
})]);
|
|
1527
|
-
return onStepFinish(workflowContext.workflowRunId
|
|
1406
|
+
return onStepFinish(workflowContext.workflowRunId);
|
|
1528
1407
|
}
|
|
1529
|
-
await _optionalChain([debug, 'optionalAccess',
|
|
1530
|
-
return onStepFinish("no-workflow-id"
|
|
1408
|
+
await _optionalChain([debug, 'optionalAccess', _46 => _46.log, 'call', _47 => _47("INFO", "RESPONSE_DEFAULT")]);
|
|
1409
|
+
return onStepFinish("no-workflow-id");
|
|
1531
1410
|
};
|
|
1532
1411
|
};
|
|
1533
1412
|
|
|
@@ -1536,5 +1415,4 @@ var serve = ({
|
|
|
1536
1415
|
|
|
1537
1416
|
|
|
1538
1417
|
|
|
1539
|
-
|
|
1540
|
-
exports.StepTypes = StepTypes; exports.WorkflowContext = WorkflowContext; exports.DisabledWorkflowContext = DisabledWorkflowContext; exports.WorkflowLogger = WorkflowLogger; exports.serve = serve;
|
|
1418
|
+
exports.StepTypes = StepTypes; exports.WorkflowContext = WorkflowContext; exports.WorkflowLogger = WorkflowLogger; exports.serve = serve;
|