n8n-workflow
Advanced tools
Comparing version 0.39.0 to 0.40.0
export * from './Interfaces'; | ||
export * from './Expression'; | ||
export * from './Workflow'; | ||
@@ -3,0 +4,0 @@ export * from './WorkflowDataProxy'; |
@@ -7,2 +7,3 @@ "use strict"; | ||
__export(require("./Interfaces")); | ||
__export(require("./Expression")); | ||
__export(require("./Workflow")); | ||
@@ -9,0 +10,0 @@ __export(require("./WorkflowDataProxy")); |
@@ -543,3 +543,3 @@ "use strict"; | ||
for (const webhookDescription of nodeType.description.webhooks) { | ||
let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']); | ||
let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path']); | ||
if (nodeWebhookPath === undefined) { | ||
@@ -553,5 +553,5 @@ console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); | ||
} | ||
const isFullPath = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false); | ||
const isFullPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], false); | ||
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); | ||
const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); | ||
const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); | ||
if (httpMethod === undefined) { | ||
@@ -584,3 +584,3 @@ console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflowId}" could not be added because the httpMethod is not defined.`); | ||
for (const webhookDescription of nodeType.description.webhooks) { | ||
let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']); | ||
let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path']); | ||
if (nodeWebhookPath === undefined) { | ||
@@ -594,5 +594,5 @@ console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); | ||
} | ||
const isFullPath = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false); | ||
const isFullPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], false); | ||
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); | ||
const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod']); | ||
const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod']); | ||
if (httpMethod === undefined) { | ||
@@ -599,0 +599,0 @@ console.error(`The webhook "${path}" for node "${node.name}" in workflow "${workflowId}" could not be added because the httpMethod is not defined.`); |
@@ -1,2 +0,2 @@ | ||
import { IConnections, IGetExecuteTriggerFunctions, INode, INodes, INodeExecuteFunctions, INodeExecutionData, INodeParameters, INodeType, INodeTypes, IPollFunctions, IRunExecutionData, ITaskDataConnections, ITriggerResponse, IWebhookData, IWebhookResponseData, IWorfklowIssues, IWorkflowExecuteAdditionalData, IWorkflowSettings, NodeParameterValue, WebhookSetupMethodNames, WorkflowExecuteMode } from './'; | ||
import { Expression, IConnections, IGetExecuteTriggerFunctions, INode, INodes, INodeExecuteFunctions, INodeExecutionData, INodeParameters, INodeType, INodeTypes, IPollFunctions, IRunExecutionData, ITaskDataConnections, ITriggerResponse, IWebhookData, IWebhookResponseData, IWorfklowIssues, IWorkflowExecuteAdditionalData, IWorkflowSettings, NodeParameterValue, WebhookSetupMethodNames, WorkflowExecuteMode } from './'; | ||
import { IDataObject } from './Interfaces'; | ||
@@ -10,2 +10,3 @@ export declare class Workflow { | ||
nodeTypes: INodeTypes; | ||
expression: Expression; | ||
active: boolean; | ||
@@ -25,3 +26,2 @@ settings: IWorkflowSettings; | ||
__getConnectionsByDestination(connections: IConnections): IConnections; | ||
convertObjectValueToString(value: object): string; | ||
checkIfWorkflowCanBeActivated(ignoreNodeTypes?: string[]): boolean; | ||
@@ -41,8 +41,4 @@ checkReadyForExecution(): IWorfklowIssues | null; | ||
getNodeConnectionOutputIndex(nodeName: string, parentNodeName: string, type?: string, depth?: number, checkedNodes?: string[]): number | undefined; | ||
getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined; | ||
getComplexParameterValue(node: INode, parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], defaultValue?: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined; | ||
__getStartNode(nodeNames: string[]): INode | undefined; | ||
getStartNode(destinationNode?: string): INode | undefined; | ||
getParameterValue(parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], returnObjectAsString?: boolean): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]; | ||
resolveSimpleParameterValue(parameterValue: NodeParameterValue, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], returnObjectAsString?: boolean): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]; | ||
runWebhookMethod(method: WebhookSetupMethodNames, webhookData: IWebhookData, nodeExecuteFunctions: INodeExecuteFunctions, mode: WorkflowExecuteMode, isTest?: boolean): Promise<boolean | undefined>; | ||
@@ -49,0 +45,0 @@ runTrigger(node: INode, getTriggerFunctions: IGetExecuteTriggerFunctions, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode): Promise<ITriggerResponse | undefined>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("./"); | ||
const tmpl = require("riot-tmpl"); | ||
tmpl.brackets.set('{{ }}'); | ||
tmpl.tmpl.errorHandler = () => { }; | ||
class Workflow { | ||
@@ -28,2 +25,3 @@ constructor(parameters) { | ||
this.settings = parameters.settings || {}; | ||
this.expression = new _1.Expression(this); | ||
} | ||
@@ -68,6 +66,2 @@ __getConnectionsByDestination(connections) { | ||
} | ||
convertObjectValueToString(value) { | ||
const typeName = Array.isArray(value) ? 'Array' : 'Object'; | ||
return `[${typeName}: ${JSON.stringify(value)}]`; | ||
} | ||
checkIfWorkflowCanBeActivated(ignoreNodeTypes) { | ||
@@ -345,31 +339,2 @@ let node; | ||
} | ||
getSimpleParameterValue(node, parameterValue, defaultValue) { | ||
if (parameterValue === undefined) { | ||
return defaultValue; | ||
} | ||
const runIndex = 0; | ||
const itemIndex = 0; | ||
const connectionInputData = []; | ||
const runData = { | ||
resultData: { | ||
runData: {}, | ||
} | ||
}; | ||
return this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData); | ||
} | ||
getComplexParameterValue(node, parameterValue, defaultValue = undefined) { | ||
if (parameterValue === undefined) { | ||
return defaultValue; | ||
} | ||
const runIndex = 0; | ||
const itemIndex = 0; | ||
const connectionInputData = []; | ||
const runData = { | ||
resultData: { | ||
runData: {}, | ||
} | ||
}; | ||
const returnData = this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData); | ||
return this.getParameterValue(returnData, runData, runIndex, itemIndex, node.name, connectionInputData); | ||
} | ||
__getStartNode(nodeNames) { | ||
@@ -411,61 +376,2 @@ let node; | ||
} | ||
getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString = false) { | ||
const isComplexParameter = (value) => { | ||
return typeof value === 'object'; | ||
}; | ||
const resolveParameterValue = (value) => { | ||
if (isComplexParameter(value)) { | ||
return this.getParameterValue(value, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString); | ||
} | ||
else { | ||
return this.resolveSimpleParameterValue(value, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString); | ||
} | ||
}; | ||
if (!isComplexParameter(parameterValue)) { | ||
return this.resolveSimpleParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString); | ||
} | ||
if (Array.isArray(parameterValue)) { | ||
const returnData = []; | ||
for (const item of parameterValue) { | ||
returnData.push(resolveParameterValue(item)); | ||
} | ||
if (returnObjectAsString === true && typeof returnData === 'object') { | ||
return this.convertObjectValueToString(returnData); | ||
} | ||
return returnData; | ||
} | ||
else { | ||
const returnData = {}; | ||
for (const key of Object.keys(parameterValue)) { | ||
returnData[key] = resolveParameterValue(parameterValue[key]); | ||
} | ||
if (returnObjectAsString === true && typeof returnData === 'object') { | ||
return this.convertObjectValueToString(returnData); | ||
} | ||
return returnData; | ||
} | ||
} | ||
resolveSimpleParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString = false) { | ||
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') { | ||
return parameterValue; | ||
} | ||
parameterValue = parameterValue.substr(1); | ||
const dataProxy = new _1.WorkflowDataProxy(this, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); | ||
const data = dataProxy.getDataProxy(); | ||
try { | ||
const returnValue = tmpl.tmpl(parameterValue, data); | ||
if (typeof returnValue === 'function') { | ||
throw new Error('Expression resolved to a function. Please add "()"'); | ||
} | ||
else if (returnValue !== null && typeof returnValue === 'object') { | ||
if (returnObjectAsString === true) { | ||
return this.convertObjectValueToString(returnValue); | ||
} | ||
} | ||
return returnValue; | ||
} | ||
catch (e) { | ||
throw new Error(`Expression is not valid: ${e.message}`); | ||
} | ||
} | ||
async runWebhookMethod(method, webhookData, nodeExecuteFunctions, mode, isTest) { | ||
@@ -472,0 +378,0 @@ const node = this.getNode(webhookData.node); |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (typeof returnValue === 'string' && returnValue.charAt(0) === '=') { | ||
return that.workflow.getParameterValue(returnValue, that.runExecutionData, that.runIndex, that.itemIndex, that.activeNodeName, that.connectionInputData); | ||
return that.workflow.expression.getParameterValue(returnValue, that.runExecutionData, that.runIndex, that.itemIndex, that.activeNodeName, that.connectionInputData); | ||
} | ||
@@ -184,3 +184,3 @@ return returnValue; | ||
itemIndex = itemIndex || that.itemIndex; | ||
return that.workflow.getParameterValue('=' + expression, that.runExecutionData, that.runIndex, itemIndex, that.activeNodeName, that.connectionInputData); | ||
return that.workflow.expression.getParameterValue('=' + expression, that.runExecutionData, that.runIndex, itemIndex, that.activeNodeName, that.connectionInputData); | ||
}, | ||
@@ -187,0 +187,0 @@ $item: (itemIndex, runIndex) => { |
@@ -1018,3 +1018,3 @@ "use strict"; | ||
const parameterValue = nodes.find((node) => node.name === activeNodeName).parameters[parameterName]; | ||
const result = workflow.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); | ||
const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); | ||
expect(result).toEqual(testData.output[parameterName]); | ||
@@ -1080,3 +1080,3 @@ } | ||
const parameterValue = nodes.find((node) => node.name === activeNodeName).parameters[parameterName]; | ||
const result = workflow.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); | ||
const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); | ||
expect(result).toEqual({ | ||
@@ -1083,0 +1083,0 @@ string: [ |
{ | ||
"name": "n8n-workflow", | ||
"version": "0.39.0", | ||
"version": "0.40.0", | ||
"description": "Workflow base code of n8n", | ||
@@ -29,7 +29,7 @@ "license": "SEE LICENSE IN LICENSE.md", | ||
"@types/express": "^4.17.6", | ||
"@types/jest": "^25.2.1", | ||
"@types/jest": "^26.0.13", | ||
"@types/lodash.get": "^4.4.6", | ||
"@types/node": "^14.0.27", | ||
"jest": "^24.9.0", | ||
"ts-jest": "^25.4.0", | ||
"@types/node": "14.0.27", | ||
"jest": "^26.4.2", | ||
"ts-jest": "^26.3.0", | ||
"tslint": "^6.1.2", | ||
@@ -36,0 +36,0 @@ "typescript": "~3.7.4" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
418295
39
6657