UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

75 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IF = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); exports.IF = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "if", defaultLabel: "If", summary: "UI__NODE_EDITOR__IF__SUMMARY", appearance: { color: '#9483D4', textColor: 'white', contrastTextColor: 'black', variant: 'hexagon', showIcon: false }, dependencies: { children: ["then", "else"], }, constraints: { collapsable: true, placement: { children: { whitelist: ["then", "else"], }, }, }, fields: [ { key: "condition", type: "condition", label: "UI__NODE_EDITOR__IF__CONDITION__FIELDS__LABEL", defaultValue: { condition: "", type: "rule", rule: { left: "1", operand: "eq", right: "1" } } }, ], preview: { key: "condition", type: "custom", }, tags: ["basic", "logic", "condition"], function: async ({ cognigy, config, childConfigs }) => { const { api } = cognigy; const { condition: conditionObject } = config; const { condition, rule, type } = conditionObject; let isConditionTrue; /** normal CS condition */ switch (type) { case "rule": { isConditionTrue = api.evaluateRule(rule); } break; case "condition": default: { isConditionTrue = api.parseCognigyScriptCondition(condition); } break; } const child = childConfigs.find(child => isConditionTrue ? child.type === "then" : child.type === "else"); if (!child) { throw new Error("Unable to find child to execute"); } api.setNextNode(child.id); } }); //# sourceMappingURL=if.js.map