Add variable $mode

This commit is contained in:
Jan Oberhauser 2021-01-29 09:31:40 +01:00
parent 48362f50ef
commit 5398a06ff2
13 changed files with 81 additions and 67 deletions

View file

@ -277,7 +277,7 @@ export class ActiveWorkflowRunner {
path = node.parameters.path as string; path = node.parameters.path as string;
if (node.parameters.path === undefined) { if (node.parameters.path === undefined) {
path = workflow.expression.getSimpleParameterValue(node, webhookData.webhookDescription['path']) as string | undefined; path = workflow.expression.getSimpleParameterValue(node, webhookData.webhookDescription['path'], mode) as string | undefined;
if (path === undefined) { if (path === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
@ -286,7 +286,7 @@ export class ActiveWorkflowRunner {
} }
} }
const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookData.webhookDescription['isFullPath'], false) as boolean; const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookData.webhookDescription['isFullPath'], mode, false) as boolean;
const webhook = { const webhook = {
workflowId: webhookData.workflowId, workflowId: webhookData.workflowId,

View file

@ -14,6 +14,7 @@ import {
INodeTypes, INodeTypes,
NodeHelpers, NodeHelpers,
Workflow, Workflow,
WorkflowExecuteMode,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -101,7 +102,7 @@ export class CredentialsHelper extends ICredentialsHelper {
* @returns {ICredentialDataDecryptedObject} * @returns {ICredentialDataDecryptedObject}
* @memberof CredentialsHelper * @memberof CredentialsHelper
*/ */
getDecrypted(name: string, type: string, raw?: boolean, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject { getDecrypted(name: string, type: string, mode: WorkflowExecuteMode, raw?: boolean, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject {
const credentials = this.getCredentials(name, type); const credentials = this.getCredentials(name, type);
const decryptedDataOriginal = credentials.getData(this.encryptionKey); const decryptedDataOriginal = credentials.getData(this.encryptionKey);
@ -110,7 +111,7 @@ export class CredentialsHelper extends ICredentialsHelper {
return decryptedDataOriginal; return decryptedDataOriginal;
} }
return this.applyDefaultsAndOverwrites(decryptedDataOriginal, type, expressionResolveValues); return this.applyDefaultsAndOverwrites(decryptedDataOriginal, type, mode, expressionResolveValues);
} }
@ -122,7 +123,7 @@ export class CredentialsHelper extends ICredentialsHelper {
* @returns {ICredentialDataDecryptedObject} * @returns {ICredentialDataDecryptedObject}
* @memberof CredentialsHelper * @memberof CredentialsHelper
*/ */
applyDefaultsAndOverwrites(decryptedDataOriginal: ICredentialDataDecryptedObject, type: string, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject { applyDefaultsAndOverwrites(decryptedDataOriginal: ICredentialDataDecryptedObject, type: string, mode: WorkflowExecuteMode, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject {
const credentialsProperties = this.getCredentialsProperties(type); const credentialsProperties = this.getCredentialsProperties(type);
// Add the default credential values // Add the default credential values
@ -137,7 +138,7 @@ export class CredentialsHelper extends ICredentialsHelper {
if (expressionResolveValues) { if (expressionResolveValues) {
try { try {
const workflow = new Workflow({ nodes: Object.values(expressionResolveValues.workflow.nodes), connections: expressionResolveValues.workflow.connectionsBySourceNode, active: false, nodeTypes: expressionResolveValues.workflow.nodeTypes }); const workflow = new Workflow({ nodes: Object.values(expressionResolveValues.workflow.nodes), connections: expressionResolveValues.workflow.connectionsBySourceNode, active: false, nodeTypes: expressionResolveValues.workflow.nodeTypes });
decryptedData = workflow.expression.getParameterValue(decryptedData as INodeParameters, expressionResolveValues.runExecutionData, expressionResolveValues.runIndex, expressionResolveValues.itemIndex, expressionResolveValues.node.name, expressionResolveValues.connectionInputData, false, decryptedData) as ICredentialDataDecryptedObject; decryptedData = workflow.expression.getParameterValue(decryptedData as INodeParameters, expressionResolveValues.runExecutionData, expressionResolveValues.runIndex, expressionResolveValues.itemIndex, expressionResolveValues.node.name, expressionResolveValues.connectionInputData, mode, false, decryptedData) as ICredentialDataDecryptedObject;
} catch (e) { } catch (e) {
e.message += ' [Error resolving credentials]'; e.message += ' [Error resolving credentials]';
throw e; throw e;
@ -154,7 +155,7 @@ export class CredentialsHelper extends ICredentialsHelper {
const workflow = new Workflow({ nodes: [node!], connections: {}, active: false, nodeTypes: mockNodeTypes }); const workflow = new Workflow({ nodes: [node!], connections: {}, active: false, nodeTypes: mockNodeTypes });
// Resolve expressions if any are set // Resolve expressions if any are set
decryptedData = workflow.expression.getComplexParameterValue(node!, decryptedData as INodeParameters, undefined, decryptedData) as ICredentialDataDecryptedObject; decryptedData = workflow.expression.getComplexParameterValue(node!, decryptedData as INodeParameters, mode, undefined, decryptedData) as ICredentialDataDecryptedObject;
} }
// Load and apply the credentials overwrites if any exist // Load and apply the credentials overwrites if any exist

View file

@ -82,6 +82,7 @@ import {
IRunData, IRunData,
IWorkflowCredentials, IWorkflowCredentials,
Workflow, Workflow,
WorkflowExecuteMode,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -1078,9 +1079,10 @@ class App {
[result.name as string]: result as ICredentialsEncrypted, [result.name as string]: result as ICredentialsEncrypted,
}, },
}; };
const mode: WorkflowExecuteMode = 'internal';
const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey); const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey);
const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, true); const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, mode, true);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type); const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type, mode);
const signatureMethod = _.get(oauthCredentials, 'signatureMethod') as string; const signatureMethod = _.get(oauthCredentials, 'signatureMethod') as string;
@ -1168,9 +1170,10 @@ class App {
[result.name as string]: result as ICredentialsEncrypted, [result.name as string]: result as ICredentialsEncrypted,
}, },
}; };
const mode: WorkflowExecuteMode = 'internal';
const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey); const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey);
const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, true); const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, mode, true);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type); const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type, mode);
const options: OptionsWithUrl = { const options: OptionsWithUrl = {
method: 'POST', method: 'POST',
@ -1239,9 +1242,10 @@ class App {
[result.name as string]: result as ICredentialsEncrypted, [result.name as string]: result as ICredentialsEncrypted,
}, },
}; };
const mode: WorkflowExecuteMode = 'internal';
const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey); const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey);
const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, true); const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, mode, true);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type); const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type, mode);
const token = new csrf(); const token = new csrf();
// Generate a CSRF prevention token and send it as a OAuth2 state stringma/ERR // Generate a CSRF prevention token and send it as a OAuth2 state stringma/ERR
@ -1336,9 +1340,10 @@ class App {
[result.name as string]: result as ICredentialsEncrypted, [result.name as string]: result as ICredentialsEncrypted,
}, },
}; };
const mode: WorkflowExecuteMode = 'internal';
const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey); const credentialsHelper = new CredentialsHelper(workflowCredentials, encryptionKey);
const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, true); const decryptedDataOriginal = credentialsHelper.getDecrypted(result.name, result.type, mode, true);
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type); const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(decryptedDataOriginal, result.type, mode);
const token = new csrf(); const token = new csrf();
if (decryptedDataOriginal.csrfSecret === undefined || !token.verify(decryptedDataOriginal.csrfSecret as string, state.token)) { if (decryptedDataOriginal.csrfSecret === undefined || !token.verify(decryptedDataOriginal.csrfSecret as string, state.token)) {

View file

@ -115,8 +115,8 @@ export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
} }
// Get the responseMode // Get the responseMode
const responseMode = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseMode'], 'onReceived'); const responseMode = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseMode'], executionMode, 'onReceived');
const responseCode = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseCode'], 200) as number; const responseCode = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseCode'], executionMode, 200) as number;
if (!['onReceived', 'lastNode'].includes(responseMode as string)) { if (!['onReceived', 'lastNode'].includes(responseMode as string)) {
// If the mode is not known we error. Is probably best like that instead of using // If the mode is not known we error. Is probably best like that instead of using
@ -174,7 +174,7 @@ export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
await WorkflowHelpers.saveStaticData(workflow); await WorkflowHelpers.saveStaticData(workflow);
if (webhookData.webhookDescription['responseHeaders'] !== undefined) { if (webhookData.webhookDescription['responseHeaders'] !== undefined) {
const responseHeaders = workflow.expression.getComplexParameterValue(workflowStartNode, webhookData.webhookDescription['responseHeaders'], undefined) as { const responseHeaders = workflow.expression.getComplexParameterValue(workflowStartNode, webhookData.webhookDescription['responseHeaders'], executionMode, undefined) as {
entries?: Array<{ entries?: Array<{
name: string; name: string;
value: string; value: string;
@ -328,7 +328,7 @@ export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
return data; return data;
} }
const responseData = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseData'], 'firstEntryJson'); const responseData = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseData'], executionMode, 'firstEntryJson');
if (didSendResponse === false) { if (didSendResponse === false) {
let data: IDataObject | IDataObject[]; let data: IDataObject | IDataObject[];
@ -343,13 +343,13 @@ export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
data = returnData.data!.main[0]![0].json; data = returnData.data!.main[0]![0].json;
const responsePropertyName = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responsePropertyName'], undefined); const responsePropertyName = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responsePropertyName'], executionMode, undefined);
if (responsePropertyName !== undefined) { if (responsePropertyName !== undefined) {
data = get(data, responsePropertyName as string) as IDataObject; data = get(data, responsePropertyName as string) as IDataObject;
} }
const responseContentType = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseContentType'], undefined); const responseContentType = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseContentType'], executionMode, undefined);
if (responseContentType !== undefined) { if (responseContentType !== undefined) {
// Send the webhook response manually to be able to set the content-type // Send the webhook response manually to be able to set the content-type
@ -382,7 +382,7 @@ export function getWorkflowWebhooksBasic(workflow: Workflow): IWebhookData[] {
didSendResponse = true; didSendResponse = true;
} }
const responseBinaryPropertyName = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseBinaryPropertyName'], 'data'); const responseBinaryPropertyName = workflow.expression.getSimpleParameterValue(workflowStartNode, webhookData.webhookDescription['responseBinaryPropertyName'], executionMode, 'data');
if (responseBinaryPropertyName === undefined && didSendResponse === false) { if (responseBinaryPropertyName === undefined && didSendResponse === false) {
responseCallback(new Error('No "responseBinaryPropertyName" is set.'), {}); responseCallback(new Error('No "responseBinaryPropertyName" is set.'), {});

View file

@ -387,7 +387,7 @@ export function getNode(node: INode): INode {
* @param {*} [fallbackValue] * @param {*} [fallbackValue]
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object)} * @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object)}
*/ */
export function getNodeParameter(workflow: Workflow, runExecutionData: IRunExecutionData | null, runIndex: number, connectionInputData: INodeExecutionData[], node: INode, parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object { //tslint:disable-line:no-any export function getNodeParameter(workflow: Workflow, runExecutionData: IRunExecutionData | null, runIndex: number, connectionInputData: INodeExecutionData[], node: INode, parameterName: string, itemIndex: number, mode: WorkflowExecuteMode, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object { //tslint:disable-line:no-any
const nodeType = workflow.nodeTypes.getByName(node.type); const nodeType = workflow.nodeTypes.getByName(node.type);
if (nodeType === undefined) { if (nodeType === undefined) {
throw new Error(`Node type "${node.type}" is not known so can not return paramter value!`); throw new Error(`Node type "${node.type}" is not known so can not return paramter value!`);
@ -401,7 +401,7 @@ export function getNodeParameter(workflow: Workflow, runExecutionData: IRunExecu
let returnData; let returnData;
try { try {
returnData = workflow.expression.getParameterValue(value, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); returnData = workflow.expression.getParameterValue(value, runExecutionData, runIndex, itemIndex, node.name, connectionInputData, mode);
} catch (e) { } catch (e) {
e.message += ` [Error in parameter: "${parameterName}"]`; e.message += ` [Error in parameter: "${parameterName}"]`;
throw e; throw e;
@ -436,7 +436,7 @@ export function continueOnFail(node: INode): boolean {
* @param {boolean} [isTest] * @param {boolean} [isTest]
* @returns {(string | undefined)} * @returns {(string | undefined)}
*/ */
export function getNodeWebhookUrl(name: string, workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData, isTest?: boolean): string | undefined { export function getNodeWebhookUrl(name: string, workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData, mode: WorkflowExecuteMode, isTest?: boolean): string | undefined {
let baseUrl = additionalData.webhookBaseUrl; let baseUrl = additionalData.webhookBaseUrl;
if (isTest === true) { if (isTest === true) {
baseUrl = additionalData.webhookTestBaseUrl; baseUrl = additionalData.webhookTestBaseUrl;
@ -447,12 +447,12 @@ export function getNodeWebhookUrl(name: string, workflow: Workflow, node: INode,
return undefined; return undefined;
} }
const path = workflow.expression.getSimpleParameterValue(node, webhookDescription['path']); const path = workflow.expression.getSimpleParameterValue(node, webhookDescription['path'], mode);
if (path === undefined) { if (path === undefined) {
return undefined; return undefined;
} }
const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], mode, false) as boolean;
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath); return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath);
} }
@ -552,7 +552,7 @@ export function getExecutePollFunctions(workflow: Workflow, node: INode, additio
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = []; const connectionInputData: INodeExecutionData[] = [];
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getRestApiUrl: (): string => { getRestApiUrl: (): string => {
return additionalData.restApiUrl; return additionalData.restApiUrl;
@ -615,7 +615,7 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = []; const connectionInputData: INodeExecutionData[] = [];
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getRestApiUrl: (): string => { getRestApiUrl: (): string => {
return additionalData.restApiUrl; return additionalData.restApiUrl;
@ -667,7 +667,7 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
return continueOnFail(node); return continueOnFail(node);
}, },
evaluateExpression: (expression: string, itemIndex: number) => { evaluateExpression: (expression: string, itemIndex: number) => {
return workflow.expression.resolveSimpleParameterValue('=' + expression, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); return workflow.expression.resolveSimpleParameterValue('=' + expression, runExecutionData, runIndex, itemIndex, node.name, connectionInputData, mode);
}, },
async executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any> { // tslint:disable-line:no-any async executeWorkflow(workflowInfo: IExecuteWorkflowInfo, inputData?: INodeExecutionData[]): Promise<any> { // tslint:disable-line:no-any
return additionalData.executeWorkflow(workflowInfo, additionalData, inputData); return additionalData.executeWorkflow(workflowInfo, additionalData, inputData);
@ -700,7 +700,7 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
return inputData[inputName][inputIndex] as INodeExecutionData[]; return inputData[inputName][inputIndex] as INodeExecutionData[];
}, },
getNodeParameter: (parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
@ -718,7 +718,7 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
return getWorkflowMetadata(workflow); return getWorkflowMetadata(workflow);
}, },
getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => { getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => {
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData, mode);
return dataProxy.getDataProxy(); return dataProxy.getDataProxy();
}, },
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
@ -765,7 +765,7 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
}, },
evaluateExpression: (expression: string, evaluateItemIndex: number | undefined) => { evaluateExpression: (expression: string, evaluateItemIndex: number | undefined) => {
evaluateItemIndex = evaluateItemIndex === undefined ? itemIndex : evaluateItemIndex; evaluateItemIndex = evaluateItemIndex === undefined ? itemIndex : evaluateItemIndex;
return workflow.expression.resolveSimpleParameterValue('=' + expression, runExecutionData, runIndex, evaluateItemIndex, node.name, connectionInputData); return workflow.expression.resolveSimpleParameterValue('=' + expression, runExecutionData, runIndex, evaluateItemIndex, node.name, connectionInputData, mode);
}, },
getContext(type: string): IContextObject { getContext(type: string): IContextObject {
return NodeHelpers.getContext(runExecutionData, type, node); return NodeHelpers.getContext(runExecutionData, type, node);
@ -811,13 +811,13 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
}, },
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getWorkflow: () => { getWorkflow: () => {
return getWorkflowMetadata(workflow); return getWorkflowMetadata(workflow);
}, },
getWorkflowDataProxy: (): IWorkflowDataProxyData => { getWorkflowDataProxy: (): IWorkflowDataProxyData => {
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData, mode);
return dataProxy.getDataProxy(); return dataProxy.getDataProxy();
}, },
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
@ -872,7 +872,7 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = []; const connectionInputData: INodeExecutionData[] = [];
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, 'internal' as WorkflowExecuteMode, fallbackValue);
}, },
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
@ -924,10 +924,10 @@ export function getExecuteHookFunctions(workflow: Workflow, node: INode, additio
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = []; const connectionInputData: INodeExecutionData[] = [];
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getNodeWebhookUrl: (name: string): string | undefined => { getNodeWebhookUrl: (name: string): string | undefined => {
return getNodeWebhookUrl(name, workflow, node, additionalData, isTest); return getNodeWebhookUrl(name, workflow, node, additionalData, mode, isTest);
}, },
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
@ -1004,7 +1004,7 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
const runIndex = 0; const runIndex = 0;
const connectionInputData: INodeExecutionData[] = []; const connectionInputData: INodeExecutionData[] = [];
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, mode, fallbackValue);
}, },
getParamsData(): object { getParamsData(): object {
if (additionalData.httpRequest === undefined) { if (additionalData.httpRequest === undefined) {
@ -1031,7 +1031,7 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
return additionalData.httpResponse; return additionalData.httpResponse;
}, },
getNodeWebhookUrl: (name: string): string | undefined => { getNodeWebhookUrl: (name: string): string | undefined => {
return getNodeWebhookUrl(name, workflow, node, additionalData); return getNodeWebhookUrl(name, workflow, node, additionalData, mode);
}, },
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);

View file

@ -138,7 +138,7 @@ export default mixins(nodeBase, workflowHelpers).extend({
} }
if (this.nodeType !== null && this.nodeType.subtitle !== undefined) { if (this.nodeType !== null && this.nodeType.subtitle !== undefined) {
return this.workflow.expression.getSimpleParameterValue(this.data as INode, this.nodeType.subtitle) as string | undefined; return this.workflow.expression.getSimpleParameterValue(this.data as INode, this.nodeType.subtitle, 'internal') as string | undefined;
} }
if (this.data.parameters.operation !== undefined) { if (this.data.parameters.operation !== undefined) {

View file

@ -376,7 +376,7 @@ export default mixins(
return returnData; return returnData;
} }
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, nodeName, connectionInputData); const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, nodeName, connectionInputData, 'manual');
const proxy = dataProxy.getDataProxy(); const proxy = dataProxy.getDataProxy();
// @ts-ignore // @ts-ignore

View file

@ -362,7 +362,7 @@ export const workflowHelpers = mixins(
connectionInputData = []; connectionInputData = [];
} }
return workflow.expression.getParameterValue(expression, runExecutionData, runIndex, itemIndex, activeNode.name, connectionInputData, true); return workflow.expression.getParameterValue(expression, runExecutionData, runIndex, itemIndex, activeNode.name, connectionInputData, 'manual', true);
}, },
// Saves the currently loaded workflow to the database. // Saves the currently loaded workflow to the database.

View file

@ -7,6 +7,7 @@ import {
NodeParameterValue, NodeParameterValue,
Workflow, Workflow,
WorkflowDataProxy, WorkflowDataProxy,
WorkflowExecuteMode,
} from './'; } from './';
// @ts-ignore // @ts-ignore
@ -58,7 +59,7 @@ export class Expression {
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])} * @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
* @memberof Workflow * @memberof Workflow
*/ */
resolveSimpleParameterValue(parameterValue: NodeParameterValue, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] { resolveSimpleParameterValue(parameterValue: NodeParameterValue, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], mode: WorkflowExecuteMode, returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
// Check if it is an expression // Check if it is an expression
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') { if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
// Is no expression so return value // Is no expression so return value
@ -71,7 +72,7 @@ export class Expression {
parameterValue = parameterValue.substr(1); parameterValue = parameterValue.substr(1);
// Generate a data proxy which allows to query workflow data // Generate a data proxy which allows to query workflow data
const dataProxy = new WorkflowDataProxy(this.workflow, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, -1, selfData); const dataProxy = new WorkflowDataProxy(this.workflow, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, -1, selfData);
const data = dataProxy.getDataProxy(); const data = dataProxy.getDataProxy();
// Execute the expression // Execute the expression
@ -101,7 +102,7 @@ export class Expression {
* @returns {(string | undefined)} * @returns {(string | undefined)}
* @memberof Workflow * @memberof Workflow
*/ */
getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined { getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, mode: WorkflowExecuteMode, defaultValue?: boolean | number | string): boolean | number | string | undefined {
if (parameterValue === undefined) { if (parameterValue === undefined) {
// Value is not set so return the default // Value is not set so return the default
return defaultValue; return defaultValue;
@ -117,7 +118,7 @@ export class Expression {
}, },
}; };
return this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData) as boolean | number | string | undefined; return this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData, mode) as boolean | number | string | undefined;
} }
@ -131,7 +132,7 @@ export class Expression {
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)} * @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)}
* @memberof Workflow * @memberof Workflow
*/ */
getComplexParameterValue(node: INode, parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], defaultValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined = undefined, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined { getComplexParameterValue(node: INode, parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], mode: WorkflowExecuteMode, defaultValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined = undefined, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined {
if (parameterValue === undefined) { if (parameterValue === undefined) {
// Value is not set so return the default // Value is not set so return the default
return defaultValue; return defaultValue;
@ -148,10 +149,10 @@ export class Expression {
}; };
// Resolve the "outer" main values // Resolve the "outer" main values
const returnData = this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData, false, selfData); const returnData = this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData, mode, false, selfData);
// Resolve the "inner" values // Resolve the "inner" values
return this.getParameterValue(returnData, runData, runIndex, itemIndex, node.name, connectionInputData, false, selfData); return this.getParameterValue(returnData, runData, runIndex, itemIndex, node.name, connectionInputData, mode, false, selfData);
} }
@ -171,7 +172,7 @@ export class Expression {
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])} * @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
* @memberof Workflow * @memberof Workflow
*/ */
getParameterValue(parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] { getParameterValue(parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], mode: WorkflowExecuteMode, returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
// Helper function which returns true when the parameter is a complex one or array // Helper function which returns true when the parameter is a complex one or array
const isComplexParameter = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) => { const isComplexParameter = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) => {
return typeof value === 'object'; return typeof value === 'object';
@ -180,15 +181,15 @@ export class Expression {
// Helper function which resolves a parameter value depending on if it is simply or not // Helper function which resolves a parameter value depending on if it is simply or not
const resolveParameterValue = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) => { const resolveParameterValue = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) => {
if (isComplexParameter(value)) { if (isComplexParameter(value)) {
return this.getParameterValue(value, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString, selfData); return this.getParameterValue(value, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, returnObjectAsString, selfData);
} else { } else {
return this.resolveSimpleParameterValue(value as NodeParameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString, selfData); return this.resolveSimpleParameterValue(value as NodeParameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, returnObjectAsString, selfData);
} }
}; };
// Check if it value is a simple one that we can get it resolved directly // Check if it value is a simple one that we can get it resolved directly
if (!isComplexParameter(parameterValue)) { if (!isComplexParameter(parameterValue)) {
return this.resolveSimpleParameterValue(parameterValue as NodeParameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString, selfData); return this.resolveSimpleParameterValue(parameterValue as NodeParameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, returnObjectAsString, selfData);
} }
// The parameter value is complex so resolve depending on type // The parameter value is complex so resolve depending on type

View file

@ -103,7 +103,7 @@ export abstract class ICredentialsHelper {
} }
abstract getCredentials(name: string, type: string): ICredentials; abstract getCredentials(name: string, type: string): ICredentials;
abstract getDecrypted(name: string, type: string, raw?: boolean, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject; abstract getDecrypted(name: string, type: string, mode: WorkflowExecuteMode, raw?: boolean, expressionResolveValues?: ICredentialsExpressionResolveValues): ICredentialDataDecryptedObject;
abstract updateCredentials(name: string, type: string, data: ICredentialDataDecryptedObject): Promise<void>; abstract updateCredentials(name: string, type: string, data: ICredentialDataDecryptedObject): Promise<void>;
} }

View file

@ -752,10 +752,11 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData:
} }
const workflowId = workflow.id || '__UNSAVED__'; const workflowId = workflow.id || '__UNSAVED__';
const mode = 'internal';
const returnData: IWebhookData[] = []; const returnData: IWebhookData[] = [];
for (const webhookDescription of nodeType.description.webhooks) { for (const webhookDescription of nodeType.description.webhooks) {
let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path']); let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path'], mode);
if (nodeWebhookPath === undefined) { if (nodeWebhookPath === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
@ -768,10 +769,10 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData:
nodeWebhookPath = nodeWebhookPath.slice(1); nodeWebhookPath = nodeWebhookPath.slice(1);
} }
const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], 'internal', false) as boolean;
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath);
const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod'], mode, 'GET');
if (httpMethod === undefined) { if (httpMethod === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
@ -813,9 +814,11 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD
const workflowId = workflow.id || '__UNSAVED__'; const workflowId = workflow.id || '__UNSAVED__';
const mode = 'internal';
const returnData: IWebhookData[] = []; const returnData: IWebhookData[] = [];
for (const webhookDescription of nodeType.description.webhooks) { for (const webhookDescription of nodeType.description.webhooks) {
let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path']); let nodeWebhookPath = workflow.expression.getSimpleParameterValue(node, webhookDescription['path'], mode);
if (nodeWebhookPath === undefined) { if (nodeWebhookPath === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
@ -828,11 +831,11 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD
nodeWebhookPath = nodeWebhookPath.slice(1); nodeWebhookPath = nodeWebhookPath.slice(1);
} }
const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean; const isFullPath: boolean = workflow.expression.getSimpleParameterValue(node, webhookDescription['isFullPath'], mode, false) as boolean;
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath); const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath);
const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod']); const httpMethod = workflow.expression.getSimpleParameterValue(node, webhookDescription['httpMethod'], mode);
if (httpMethod === undefined) { if (httpMethod === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger

View file

@ -5,6 +5,7 @@ import {
IWorkflowDataProxyData, IWorkflowDataProxyData,
NodeHelpers, NodeHelpers,
Workflow, Workflow,
WorkflowExecuteMode,
} from './'; } from './';
@ -17,11 +18,12 @@ export class WorkflowDataProxy {
private itemIndex: number; private itemIndex: number;
private activeNodeName: string; private activeNodeName: string;
private connectionInputData: INodeExecutionData[]; private connectionInputData: INodeExecutionData[];
private mode: WorkflowExecuteMode;
private selfData: IDataObject; private selfData: IDataObject;
constructor(workflow: Workflow, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], defaultReturnRunIndex = -1, selfData = {}) { constructor(workflow: Workflow, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], mode: WorkflowExecuteMode, defaultReturnRunIndex = -1, selfData = {}) {
this.workflow = workflow; this.workflow = workflow;
this.runExecutionData = runExecutionData; this.runExecutionData = runExecutionData;
this.defaultReturnRunIndex = defaultReturnRunIndex; this.defaultReturnRunIndex = defaultReturnRunIndex;
@ -29,6 +31,7 @@ export class WorkflowDataProxy {
this.itemIndex = itemIndex; this.itemIndex = itemIndex;
this.activeNodeName = activeNodeName; this.activeNodeName = activeNodeName;
this.connectionInputData = connectionInputData; this.connectionInputData = connectionInputData;
this.mode = mode;
this.selfData = selfData; this.selfData = selfData;
} }
@ -114,7 +117,7 @@ export class WorkflowDataProxy {
if (typeof returnValue === 'string' && returnValue.charAt(0) === '=') { if (typeof returnValue === 'string' && returnValue.charAt(0) === '=') {
// The found value is an expression so resolve it // The found value is an expression so resolve it
return that.workflow.expression.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, that.mode);
} }
return returnValue; return returnValue;
@ -354,11 +357,11 @@ export class WorkflowDataProxy {
$env: this.envGetter(), $env: this.envGetter(),
$evaluateExpression: (expression: string, itemIndex?: number) => { $evaluateExpression: (expression: string, itemIndex?: number) => {
itemIndex = itemIndex || that.itemIndex; itemIndex = itemIndex || that.itemIndex;
return that.workflow.expression.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, that.mode);
}, },
$item: (itemIndex: number, runIndex?: number) => { $item: (itemIndex: number, runIndex?: number) => {
const defaultReturnRunIndex = runIndex === undefined ? -1 : runIndex; const defaultReturnRunIndex = runIndex === undefined ? -1 : runIndex;
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData, defaultReturnRunIndex); const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData, that.mode, defaultReturnRunIndex);
return dataProxy.getDataProxy(); return dataProxy.getDataProxy();
}, },
$items: (nodeName?: string, outputIndex?: number, runIndex?: number) => { $items: (nodeName?: string, outputIndex?: number, runIndex?: number) => {
@ -379,6 +382,7 @@ export class WorkflowDataProxy {
$self: this.selfGetter(), $self: this.selfGetter(),
$parameter: this.nodeParameterGetter(this.activeNodeName), $parameter: this.nodeParameterGetter(this.activeNodeName),
$runIndex: this.runIndex, $runIndex: this.runIndex,
$mode: this.mode,
$workflow: this.workflowGetter(), $workflow: this.workflowGetter(),
}; };

View file

@ -1097,7 +1097,7 @@ describe('Workflow', () => {
for (const parameterName of Object.keys(testData.output)) { for (const parameterName of Object.keys(testData.output)) {
const parameterValue = nodes.find((node) => node.name === activeNodeName)!.parameters[parameterName]; const parameterValue = nodes.find((node) => node.name === activeNodeName)!.parameters[parameterName];
const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, 'manual');
// @ts-ignore // @ts-ignore
expect(result).toEqual(testData.output[parameterName]); expect(result).toEqual(testData.output[parameterName]);
} }
@ -1247,7 +1247,7 @@ describe('Workflow', () => {
const parameterName = 'values'; const parameterName = 'values';
const parameterValue = nodes.find((node) => node.name === activeNodeName)!.parameters[parameterName]; const parameterValue = nodes.find((node) => node.name === activeNodeName)!.parameters[parameterName];
const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); const result = workflow.expression.getParameterValue(parameterValue, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, 'manual');
expect(result).toEqual({ expect(result).toEqual({
string: [ string: [