function getSubflowType(subflow) { if (subflow.meta && subflow.meta.type) { return subflow.meta.type } return "sf:"+subflow.id } function generateSubflowConfig(subflow) { const subflowType = getSubflowType(subflow) const label = subflow.name || subflowType; const category = subflow.category || "function"; const color = subflow.color || "#C0DEED"; const inputCount = subflow.in?subflow.in.length:0; const outputCount = subflow.out?subflow.out.length:0; const icon = subflow.icon || "arrow-in.svg"; const defaults = { name: {value: ""} } const credentials = {} if (subflow.env) { subflow.env.forEach(prop => { var defaultValue; switch(prop.type) { case "cred": defaultValue = ""; break; case "str": defaultValue = prop.value||""; break; case "bool": defaultValue = (typeof prop.value === 'boolean')?prop.value:prop.value === "true" ; break; case "num": defaultValue = (typeof prop.value === 'number')?prop.value:Number(prop.value); break; default: defaultValue = { type: prop.type, value: prop.value||"" } } defaults[prop.name] = { value: defaultValue, ui: prop.ui } if (prop.type === 'cred') { defaults[prop.name].ui.type = "cred"; credentials[prop.name] = {type:"password"} } }) } const defaultString = JSON.stringify(defaults); const credentialsString = JSON.stringify(credentials); let nodeHelp = ""; if (subflow.info) { nodeHelp = `` } return ` ${nodeHelp} ` } function register(id,subflow) { return { subflow: subflow, type: getSubflowType(subflow), config: generateSubflowConfig(subflow) } } module.exports = { register: register }