@izara_project/izara-core-library-asynchronous-flow 1.0.44 → 1.0.45

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Sven Mason <thebarbariansven@gmail.com>",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow#readme",
6
- "version": "1.0.44",
6
+ "version": "1.0.45",
7
7
  "description": "Shared asynchronous flow logic",
8
8
  "type": "module",
9
9
  "main": "index.js",
@@ -551,3 +551,99 @@ export async function removeAwaitingMultipleStep(
551
551
 
552
552
  await Promise.all(promises);
553
553
  }
554
+
555
+ /**
556
+ * Complete an action and update the state of the awaiting step.
557
+ * @async
558
+ * @param {IzContext} _izContext - The Izara context.
559
+ * @param {string} parentFlowId - The ID of the parent flow.
560
+ * @returns {Promise<Object>} Status object containing completion details.
561
+ */
562
+ export async function completeAction(
563
+ _izContext,
564
+ parentFlowId,
565
+ prefix = '',
566
+ returnValue = {},
567
+ errorsFound = []
568
+ ){
569
+ _izContext.logger.debug('[Lib:CompleteAction] Input parameters', {
570
+ parentFlowId,
571
+ prefix
572
+ });
573
+
574
+ try {
575
+
576
+ const pendingStepId = findPendingStepAwaitingMultipleSteps(
577
+ _izContext,
578
+ createAwaitingStepId(
579
+ parentFlowId,
580
+ prefix
581
+ )
582
+ );
583
+
584
+ if (!pendingStepId) {
585
+ _izContext.logger.warn(
586
+ `No pending step found for awaitingStepId: ${awaitingStepId}`
587
+ );
588
+ return { returnValue, errorsFound };
589
+ }
590
+
591
+ const {
592
+ isComplete,
593
+ collectedReturnValueByAwaitingStepId,
594
+ collectedErrors,
595
+ returnValues,
596
+ additionalAttributes
597
+ } = await checkAllAwaitingStepsFinishedWithReturnParams(
598
+ _izContext,
599
+ pendingStepId,
600
+ createAwaitingStepId(
601
+ parentFlowId,
602
+ prefix
603
+ )
604
+ );
605
+
606
+ let status = true;
607
+
608
+ if (!isComplete) {
609
+ status = false
610
+ };
611
+
612
+ if (collectedErrors.length > 0 || errorsFound.length > 0) {
613
+ status =false
614
+ };
615
+
616
+ if (status) {
617
+ await Promise.all(
618
+ (pendingStepId.listOfRecords ?? []).flatMap((records) =>
619
+ Object.values(records).map(async (record) =>
620
+ dynamodbSharedLib.putItem(
621
+ _izContext,
622
+ await dynamodbSharedLib.tableName(
623
+ _izContext,
624
+ record.tableName,
625
+ record.serviceTag
626
+ ),
627
+ {
628
+ ...record.objInstanceFull.identifiers,
629
+ ...record.objInstanceFull.fields
630
+ }
631
+ )
632
+ )
633
+ )
634
+ );
635
+ }
636
+
637
+ return {
638
+ pendingStepId,
639
+ isComplete,
640
+ collectedReturnValueByAwaitingStepId,
641
+ collectedErrors,
642
+ returnValues,
643
+ additionalAttributes
644
+ }
645
+
646
+ } catch (err) {
647
+ _izContext.logger.error(err)
648
+ }
649
+ }