From ccc2e65d98ce8f91c57315dc658a2877f5e12efd Mon Sep 17 00:00:00 2001 From: Marton Moro Date: Fri, 20 Dec 2024 18:53:23 +0100 Subject: [PATCH 1/2] chore(private-credential): ifThenElse in formatLogicNode --- .../features/src/web-connector/utils/render-payload.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/features/src/web-connector/utils/render-payload.tsx b/packages/features/src/web-connector/utils/render-payload.tsx index 2cd7dcc9..2eb20481 100644 --- a/packages/features/src/web-connector/utils/render-payload.tsx +++ b/packages/features/src/web-connector/utils/render-payload.tsx @@ -184,6 +184,13 @@ const formatLogicNode = (node: LogicNode, level = 0): string => { throw Error("CONSTANT node must have 'data'") } return `${node.data}` + case "ifThenElse": + if (!node.condition || !node.thenNode || !node.elseNode) { + throw Error( + "IF_THEN_ELSE node must have 'condition', 'thenNode', and 'elseNode'", + ) + } + return `${indent}If this condition is true:\n${indent}- ${formatLogicNode(node.condition, level + 1)}\n${indent}Then:\n${indent}- ${formatLogicNode(node.thenNode, level + 1)}\n${indent}Otherwise:\n${indent}- ${formatLogicNode(node.elseNode, level + 1)}` default: throw Error(`Unknown node type: ${node.type}`) From ebba555fa1a63c10dcba8bd78bfac10d47e89bbe Mon Sep 17 00:00:00 2001 From: Marton Moro Date: Fri, 20 Dec 2024 19:43:46 +0100 Subject: [PATCH 2/2] chore(private-credential): change constant node rendering --- .../src/web-connector/utils/render-payload.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/features/src/web-connector/utils/render-payload.tsx b/packages/features/src/web-connector/utils/render-payload.tsx index 2eb20481..780d6307 100644 --- a/packages/features/src/web-connector/utils/render-payload.tsx +++ b/packages/features/src/web-connector/utils/render-payload.tsx @@ -18,7 +18,7 @@ type LogicNode = { right?: LogicNode key?: string inner?: LogicNode - data?: Record + data?: Record credentialKey?: string input?: LogicNode options?: LogicNode[] | LogicNode @@ -179,11 +179,15 @@ const formatLogicNode = (node: LogicNode, level = 0): string => { .map(([key, value]) => `${key}: ${formatLogicNode(value, level)}`) .join(`\n${indent}`) } - case "constant": - if (!node.data) { - throw Error("CONSTANT node must have 'data'") + case "constant": { + if (!node.data || typeof node.data !== "object") { + throw Error("CONSTANT node must have 'data' object") + } + if (node.data._type === "Undefined") { + return "undefined" } - return `${node.data}` + return JSON.stringify(node.data.value) + } case "ifThenElse": if (!node.condition || !node.thenNode || !node.elseNode) { throw Error(