next-workflow-builder 0.4.3 → 0.4.5

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.
@@ -463,7 +463,7 @@ function replaceTemplateVariable(match, nodeId, rest, outputs, evalContext, varC
463
463
  const fields = fieldPath.split(".");
464
464
  let current = output.data;
465
465
  const firstField = fields[0];
466
- if (current && typeof current === "object" && "success" in current && "data" in current && firstField !== "success" && firstField !== "data" && firstField !== "error") {
466
+ if (current && typeof current === "object" && "success" in current && "data" in current && firstField !== "success" && firstField !== "data" && firstField !== "error" && !(firstField in current)) {
467
467
  current = current.data;
468
468
  }
469
469
  for (const field of fields) {
@@ -620,7 +620,7 @@ function processTemplates(config, outputs) {
620
620
  const fields = fieldPath.split(".");
621
621
  let current = output.data;
622
622
  const firstField = fields[0];
623
- if (current && typeof current === "object" && "success" in current && "data" in current && firstField !== "success" && firstField !== "data" && firstField !== "error") {
623
+ if (current && typeof current === "object" && "success" in current && "data" in current && firstField !== "success" && firstField !== "data" && firstField !== "error" && !(firstField in current)) {
624
624
  current = current.data;
625
625
  }
626
626
  for (const field of fields) {
@@ -660,10 +660,14 @@ async function executeWorkflow(input) {
660
660
  const results = {};
661
661
  const nodeMap = new Map(nodes.map((n) => [n.id, n]));
662
662
  const edgesBySource = /* @__PURE__ */ new Map();
663
+ const edgesByTarget = /* @__PURE__ */ new Map();
663
664
  for (const edge of edges) {
664
665
  const targets = edgesBySource.get(edge.source) || [];
665
666
  targets.push(edge.target);
666
667
  edgesBySource.set(edge.source, targets);
668
+ const sources = edgesByTarget.get(edge.target) || [];
669
+ sources.push(edge.source);
670
+ edgesByTarget.set(edge.target, sources);
667
671
  }
668
672
  const nodesWithIncoming = new Set(edges.map((e) => e.target));
669
673
  const triggerNodes = nodes.filter(
@@ -788,10 +792,27 @@ async function executeWorkflow(input) {
788
792
  nodeName: getNodeName(node),
789
793
  nodeType: actionType
790
794
  };
795
+ const predecessorData = {};
796
+ const predecessorIds = edgesByTarget.get(nodeId) || [];
797
+ for (const predId of predecessorIds) {
798
+ const sanitizedPredId = predId.replace(/[^a-zA-Z0-9]/g, "_");
799
+ const predOutput = outputs[sanitizedPredId];
800
+ if (predOutput?.data && typeof predOutput.data === "object") {
801
+ let payload = predOutput.data;
802
+ if ("success" in payload && "data" in payload && payload.data && typeof payload.data === "object") {
803
+ payload = payload.data;
804
+ }
805
+ for (const [key, value] of Object.entries(payload)) {
806
+ if (key !== "success" && key !== "error") {
807
+ predecessorData[key] = value;
808
+ }
809
+ }
810
+ }
811
+ }
791
812
  console.log("[Workflow Executor] Calling executeActionStep");
792
813
  const stepResult = await executeActionStep({
793
814
  actionType,
794
- config: processedConfig,
815
+ config: { ...predecessorData, ...processedConfig },
795
816
  outputs,
796
817
  context: stepContext
797
818
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-workflow-builder",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "type": "module",
5
5
  "description": "Next.js plugin for Workflow Builder",
6
6
  "repository": "https://github.com/emulienfou/next-workflow-builder",