2022-06-23 07:07:56 -07:00
|
|
|
import * as tmpl from '@n8n_io/riot-tmpl';
|
2022-03-13 01:34:44 -08:00
|
|
|
import { DateTime, Duration, Interval } from 'luxon';
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line import/no-cycle
|
2020-09-12 03:16:07 -07:00
|
|
|
import {
|
2022-06-03 08:25:07 -07:00
|
|
|
ExpressionError,
|
|
|
|
IExecuteData,
|
2020-09-12 03:16:07 -07:00
|
|
|
INode,
|
|
|
|
INodeExecutionData,
|
2022-09-21 06:44:45 -07:00
|
|
|
INodeParameterResourceLocator,
|
2020-09-12 03:16:07 -07:00
|
|
|
INodeParameters,
|
|
|
|
IRunExecutionData,
|
2021-08-21 05:11:32 -07:00
|
|
|
IWorkflowDataProxyAdditionalKeys,
|
2022-09-09 07:34:50 -07:00
|
|
|
IWorkflowDataProxyData,
|
2020-09-12 03:16:07 -07:00
|
|
|
NodeParameterValue,
|
2022-09-21 06:44:45 -07:00
|
|
|
NodeParameterValueType,
|
2020-09-12 03:16:07 -07:00
|
|
|
Workflow,
|
|
|
|
WorkflowDataProxy,
|
2021-01-29 00:31:40 -08:00
|
|
|
WorkflowExecuteMode,
|
2021-08-29 11:58:11 -07:00
|
|
|
} from '.';
|
2020-09-12 03:16:07 -07:00
|
|
|
|
|
|
|
// Set it to use double curly brackets instead of single ones
|
|
|
|
tmpl.brackets.set('{{ }}');
|
|
|
|
|
2022-06-03 08:25:07 -07:00
|
|
|
// Make sure that error get forwarded
|
|
|
|
tmpl.tmpl.errorHandler = (error: Error) => {
|
2022-06-13 11:48:02 -07:00
|
|
|
if (error instanceof ExpressionError) {
|
|
|
|
if (error.context.failExecution) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 08:25:07 -07:00
|
|
|
};
|
2020-09-12 03:16:07 -07:00
|
|
|
|
|
|
|
export class Expression {
|
|
|
|
workflow: Workflow;
|
|
|
|
|
|
|
|
constructor(workflow: Workflow) {
|
|
|
|
this.workflow = workflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an object to a string in a way to make it clear that
|
|
|
|
* the value comes from an object
|
|
|
|
*
|
|
|
|
* @param {object} value
|
|
|
|
* @returns {string}
|
|
|
|
* @memberof Workflow
|
|
|
|
*/
|
|
|
|
convertObjectValueToString(value: object): string {
|
|
|
|
const typeName = Array.isArray(value) ? 'Array' : 'Object';
|
|
|
|
return `[${typeName}: ${JSON.stringify(value)}]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-02 07:13:17 -07:00
|
|
|
* Resolves the parameter value. If it is an expression it will execute it and
|
2020-09-12 03:16:07 -07:00
|
|
|
* return the result. For everything simply the supplied value will be returned.
|
|
|
|
*
|
|
|
|
* @param {NodeParameterValue} parameterValue
|
|
|
|
* @param {(IRunExecutionData | null)} runExecutionData
|
|
|
|
* @param {number} runIndex
|
|
|
|
* @param {number} itemIndex
|
|
|
|
* @param {string} activeNodeName
|
|
|
|
* @param {INodeExecutionData[]} connectionInputData
|
|
|
|
* @param {boolean} [returnObjectAsString=false]
|
|
|
|
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
|
|
|
|
* @memberof Workflow
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
resolveSimpleParameterValue(
|
|
|
|
parameterValue: NodeParameterValue,
|
|
|
|
siblingParameters: INodeParameters,
|
|
|
|
runExecutionData: IRunExecutionData | null,
|
|
|
|
runIndex: number,
|
|
|
|
itemIndex: number,
|
|
|
|
activeNodeName: string,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
mode: WorkflowExecuteMode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone: string,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2021-08-29 11:58:11 -07:00
|
|
|
returnObjectAsString = false,
|
|
|
|
selfData = {},
|
|
|
|
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
|
2020-09-12 03:16:07 -07:00
|
|
|
// Check if it is an expression
|
|
|
|
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
|
|
|
|
// Is no expression so return value
|
|
|
|
return parameterValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is an expression
|
|
|
|
|
|
|
|
// Remove the equal sign
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2020-09-12 03:16:07 -07:00
|
|
|
parameterValue = parameterValue.substr(1);
|
|
|
|
|
|
|
|
// Generate a data proxy which allows to query workflow data
|
2021-08-29 11:58:11 -07:00
|
|
|
const dataProxy = new WorkflowDataProxy(
|
|
|
|
this.workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
siblingParameters,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
-1,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
const data = dataProxy.getDataProxy();
|
|
|
|
|
2021-11-09 23:49:45 -08:00
|
|
|
// Support only a subset of process properties
|
|
|
|
data.process = {
|
|
|
|
arch: process.arch,
|
|
|
|
env: process.env,
|
|
|
|
platform: process.platform,
|
|
|
|
pid: process.pid,
|
|
|
|
ppid: process.ppid,
|
|
|
|
release: process.release,
|
|
|
|
version: process.pid,
|
|
|
|
versions: process.versions,
|
|
|
|
};
|
|
|
|
|
2022-06-17 22:09:37 -07:00
|
|
|
/**
|
|
|
|
* Denylist
|
|
|
|
*/
|
|
|
|
|
2021-11-13 15:11:50 -08:00
|
|
|
data.document = {};
|
2022-05-27 08:00:51 -07:00
|
|
|
data.global = {};
|
|
|
|
data.window = {};
|
|
|
|
data.Window = {};
|
|
|
|
data.this = {};
|
2022-06-17 22:09:37 -07:00
|
|
|
data.globalThis = {};
|
2022-05-27 08:00:51 -07:00
|
|
|
data.self = {};
|
|
|
|
|
|
|
|
// Alerts
|
|
|
|
data.alert = {};
|
|
|
|
data.prompt = {};
|
|
|
|
data.confirm = {};
|
|
|
|
|
|
|
|
// Prevent Remote Code Execution
|
|
|
|
data.eval = {};
|
2022-06-17 22:09:37 -07:00
|
|
|
data.uneval = {};
|
2022-05-27 08:00:51 -07:00
|
|
|
data.setTimeout = {};
|
|
|
|
data.setInterval = {};
|
|
|
|
data.Function = {};
|
|
|
|
|
|
|
|
// Prevent requests
|
|
|
|
data.fetch = {};
|
|
|
|
data.XMLHttpRequest = {};
|
2022-03-13 01:34:44 -08:00
|
|
|
|
2022-06-17 22:09:37 -07:00
|
|
|
// Prevent control abstraction
|
|
|
|
data.Promise = {};
|
|
|
|
data.Generator = {};
|
|
|
|
data.GeneratorFunction = {};
|
|
|
|
data.AsyncFunction = {};
|
|
|
|
data.AsyncGenerator = {};
|
|
|
|
data.AsyncGeneratorFunction = {};
|
|
|
|
|
|
|
|
// Prevent WASM
|
|
|
|
data.WebAssembly = {};
|
|
|
|
|
|
|
|
// Prevent Reflection
|
|
|
|
data.Reflect = {};
|
|
|
|
data.Proxy = {};
|
|
|
|
|
2022-03-13 01:34:44 -08:00
|
|
|
// @ts-ignore
|
2022-06-17 22:09:37 -07:00
|
|
|
data.constructor = {};
|
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
data.escape = {};
|
|
|
|
data.unescape = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allowlist
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Dates
|
|
|
|
data.Date = Date;
|
2022-03-13 01:34:44 -08:00
|
|
|
data.DateTime = DateTime;
|
|
|
|
data.Interval = Interval;
|
|
|
|
data.Duration = Duration;
|
|
|
|
|
2022-06-17 22:09:37 -07:00
|
|
|
// Objects
|
|
|
|
data.Object = Object;
|
|
|
|
|
|
|
|
// Arrays
|
|
|
|
data.Array = Array;
|
|
|
|
data.Int8Array = Int8Array;
|
|
|
|
data.Uint8Array = Uint8Array;
|
|
|
|
data.Uint8ClampedArray = Uint8ClampedArray;
|
|
|
|
data.Int16Array = Int16Array;
|
|
|
|
data.Uint16Array = Uint16Array;
|
|
|
|
data.Int32Array = Int32Array;
|
|
|
|
data.Uint32Array = Uint32Array;
|
|
|
|
data.Float32Array = Float32Array;
|
|
|
|
data.Float64Array = Float64Array;
|
|
|
|
data.BigInt64Array = typeof BigInt64Array !== 'undefined' ? BigInt64Array : {};
|
|
|
|
data.BigUint64Array = typeof BigUint64Array !== 'undefined' ? BigUint64Array : {};
|
|
|
|
|
|
|
|
// Collections
|
|
|
|
data.Map = typeof Map !== 'undefined' ? Map : {};
|
|
|
|
data.WeakMap = typeof WeakMap !== 'undefined' ? WeakMap : {};
|
|
|
|
data.Set = typeof Set !== 'undefined' ? Set : {};
|
|
|
|
data.WeakSet = typeof WeakSet !== 'undefined' ? WeakSet : {};
|
|
|
|
|
|
|
|
// Errors
|
|
|
|
data.Error = Error;
|
|
|
|
data.TypeError = TypeError;
|
|
|
|
data.SyntaxError = SyntaxError;
|
|
|
|
data.EvalError = EvalError;
|
|
|
|
data.RangeError = RangeError;
|
|
|
|
data.ReferenceError = ReferenceError;
|
|
|
|
data.URIError = URIError;
|
|
|
|
|
|
|
|
// Internationalization
|
|
|
|
data.Intl = typeof Intl !== 'undefined' ? Intl : {};
|
|
|
|
|
|
|
|
// Text
|
2022-09-09 07:34:50 -07:00
|
|
|
// eslint-disable-next-line id-denylist
|
2022-06-17 22:09:37 -07:00
|
|
|
data.String = String;
|
|
|
|
data.RegExp = RegExp;
|
|
|
|
|
|
|
|
// Math
|
|
|
|
data.Math = Math;
|
2022-09-09 07:34:50 -07:00
|
|
|
// eslint-disable-next-line id-denylist
|
2022-06-17 22:09:37 -07:00
|
|
|
data.Number = Number;
|
|
|
|
data.BigInt = typeof BigInt !== 'undefined' ? BigInt : {};
|
|
|
|
data.Infinity = Infinity;
|
|
|
|
data.NaN = NaN;
|
|
|
|
data.isFinite = Number.isFinite;
|
|
|
|
data.isNaN = Number.isNaN;
|
|
|
|
data.parseFloat = parseFloat;
|
|
|
|
data.parseInt = parseInt;
|
|
|
|
|
|
|
|
// Structured data
|
|
|
|
data.JSON = JSON;
|
|
|
|
data.ArrayBuffer = typeof ArrayBuffer !== 'undefined' ? ArrayBuffer : {};
|
|
|
|
data.SharedArrayBuffer = typeof SharedArrayBuffer !== 'undefined' ? SharedArrayBuffer : {};
|
|
|
|
data.Atomics = typeof Atomics !== 'undefined' ? Atomics : {};
|
|
|
|
data.DataView = typeof DataView !== 'undefined' ? DataView : {};
|
|
|
|
|
|
|
|
data.encodeURI = encodeURI;
|
|
|
|
data.encodeURIComponent = encodeURIComponent;
|
|
|
|
data.decodeURI = decodeURI;
|
|
|
|
data.decodeURIComponent = decodeURIComponent;
|
|
|
|
|
|
|
|
// Other
|
2022-09-09 07:34:50 -07:00
|
|
|
// eslint-disable-next-line id-denylist
|
2022-06-17 22:09:37 -07:00
|
|
|
data.Boolean = Boolean;
|
|
|
|
data.Symbol = Symbol;
|
2021-11-13 15:11:50 -08:00
|
|
|
|
2022-09-20 01:41:37 -07:00
|
|
|
const constructorValidation = new RegExp(/\.\s*constructor/gm);
|
|
|
|
if (parameterValue.match(constructorValidation)) {
|
|
|
|
throw new ExpressionError('Expression contains invalid constructor function call', {
|
|
|
|
causeDetailed: 'Constructor override attempt is not allowed due to security concerns',
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
// Execute the expression
|
2022-09-09 07:34:50 -07:00
|
|
|
const returnValue = this.renderExpression(parameterValue, data);
|
|
|
|
if (typeof returnValue === 'function') {
|
|
|
|
throw new Error('Expression resolved to a function. Please add "()"');
|
|
|
|
} else if (typeof returnValue === 'string') {
|
|
|
|
return returnValue;
|
|
|
|
} else if (returnValue !== null && typeof returnValue === 'object') {
|
|
|
|
if (returnObjectAsString) {
|
|
|
|
return this.convertObjectValueToString(returnValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderExpression(expression: string, data: IWorkflowDataProxyData): tmpl.ReturnValue {
|
2020-09-12 03:16:07 -07:00
|
|
|
try {
|
2022-09-09 07:34:50 -07:00
|
|
|
return tmpl.tmpl(expression, data);
|
2022-06-03 08:25:07 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof ExpressionError) {
|
|
|
|
// Ignore all errors except if they are ExpressionErrors and they are supposed
|
|
|
|
// to fail the execution
|
|
|
|
if (error.context.failExecution) {
|
|
|
|
throw error;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 07:34:50 -07:00
|
|
|
return null;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves value of parameter. But does not work for workflow-data.
|
|
|
|
*
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {(string | undefined)} parameterValue
|
|
|
|
* @param {string} [defaultValue]
|
|
|
|
* @returns {(string | undefined)}
|
|
|
|
* @memberof Workflow
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
getSimpleParameterValue(
|
|
|
|
node: INode,
|
|
|
|
parameterValue: string | boolean | undefined,
|
|
|
|
mode: WorkflowExecuteMode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone: string,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2021-08-29 11:58:11 -07:00
|
|
|
defaultValue?: boolean | number | string,
|
|
|
|
): boolean | number | string | undefined {
|
2020-09-12 03:16:07 -07:00
|
|
|
if (parameterValue === undefined) {
|
|
|
|
// Value is not set so return the default
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the value of the node (can be an expression)
|
|
|
|
const runIndex = 0;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
const runData: IRunExecutionData = {
|
|
|
|
resultData: {
|
|
|
|
runData: {},
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-09-12 03:16:07 -07:00
|
|
|
};
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
parameterValue,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
) as boolean | number | string | undefined;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves value of complex parameter. But does not work for workflow-data.
|
|
|
|
*
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])} parameterValue
|
|
|
|
* @param {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)} [defaultValue]
|
|
|
|
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)}
|
|
|
|
* @memberof Workflow
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
getComplexParameterValue(
|
|
|
|
node: INode,
|
|
|
|
parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
|
|
|
mode: WorkflowExecuteMode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone: string,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2022-09-21 06:44:45 -07:00
|
|
|
defaultValue: NodeParameterValueType | undefined = undefined,
|
2021-08-29 11:58:11 -07:00
|
|
|
selfData = {},
|
2022-09-21 06:44:45 -07:00
|
|
|
): NodeParameterValueType | undefined {
|
2020-09-12 03:16:07 -07:00
|
|
|
if (parameterValue === undefined) {
|
|
|
|
// Value is not set so return the default
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the value of the node (can be an expression)
|
|
|
|
const runIndex = 0;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
const runData: IRunExecutionData = {
|
|
|
|
resultData: {
|
|
|
|
runData: {},
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-09-12 03:16:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Resolve the "outer" main values
|
2021-08-29 11:58:11 -07:00
|
|
|
const returnData = this.getParameterValue(
|
|
|
|
parameterValue,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
false,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
|
|
|
|
// Resolve the "inner" values
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
returnData,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
false,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the resolved node parameter value. If it is an expression it will execute it and
|
|
|
|
* return the result. If the value to resolve is an array or object it will do the same
|
|
|
|
* for all of the items and values.
|
|
|
|
*
|
|
|
|
* @param {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])} parameterValue
|
|
|
|
* @param {(IRunExecutionData | null)} runExecutionData
|
|
|
|
* @param {number} runIndex
|
|
|
|
* @param {number} itemIndex
|
|
|
|
* @param {string} activeNodeName
|
|
|
|
* @param {INodeExecutionData[]} connectionInputData
|
|
|
|
* @param {boolean} [returnObjectAsString=false]
|
|
|
|
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
|
|
|
|
* @memberof Workflow
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
getParameterValue(
|
2022-09-21 06:44:45 -07:00
|
|
|
parameterValue: NodeParameterValueType | INodeParameterResourceLocator,
|
2021-08-29 11:58:11 -07:00
|
|
|
runExecutionData: IRunExecutionData | null,
|
|
|
|
runIndex: number,
|
|
|
|
itemIndex: number,
|
|
|
|
activeNodeName: string,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
mode: WorkflowExecuteMode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone: string,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2021-08-29 11:58:11 -07:00
|
|
|
returnObjectAsString = false,
|
|
|
|
selfData = {},
|
2022-09-21 06:44:45 -07:00
|
|
|
): NodeParameterValueType {
|
2020-09-12 03:16:07 -07:00
|
|
|
// Helper function which returns true when the parameter is a complex one or array
|
2022-09-21 06:44:45 -07:00
|
|
|
const isComplexParameter = (value: NodeParameterValueType) => {
|
2020-09-12 03:16:07 -07:00
|
|
|
return typeof value === 'object';
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper function which resolves a parameter value depending on if it is simply or not
|
2021-08-29 11:58:11 -07:00
|
|
|
const resolveParameterValue = (
|
2022-09-21 06:44:45 -07:00
|
|
|
value: NodeParameterValueType,
|
2021-08-29 11:58:11 -07:00
|
|
|
siblingParameters: INodeParameters,
|
|
|
|
) => {
|
2020-09-12 03:16:07 -07:00
|
|
|
if (isComplexParameter(value)) {
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
value,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.resolveSimpleParameterValue(
|
|
|
|
value as NodeParameterValue,
|
|
|
|
siblingParameters,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check if it value is a simple one that we can get it resolved directly
|
|
|
|
if (!isComplexParameter(parameterValue)) {
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.resolveSimpleParameterValue(
|
|
|
|
parameterValue as NodeParameterValue,
|
|
|
|
{},
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
2022-04-10 02:33:42 -07:00
|
|
|
timezone,
|
2021-08-29 11:58:11 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-29 11:58:11 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The parameter value is complex so resolve depending on type
|
|
|
|
if (Array.isArray(parameterValue)) {
|
|
|
|
// Data is an array
|
2022-09-09 07:34:50 -07:00
|
|
|
const returnData = parameterValue.map((item) => resolveParameterValue(item, {}));
|
2020-09-12 03:16:07 -07:00
|
|
|
return returnData as NodeParameterValue[] | INodeParameters[];
|
2021-08-29 11:58:11 -07:00
|
|
|
}
|
2022-09-09 07:34:50 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
if (parameterValue === null || parameterValue === undefined) {
|
2020-09-23 04:20:50 -07:00
|
|
|
return parameterValue;
|
2021-08-29 11:58:11 -07:00
|
|
|
}
|
2022-05-27 08:00:51 -07:00
|
|
|
|
2022-09-09 07:34:50 -07:00
|
|
|
if (typeof parameterValue !== 'object') {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// Data is an object
|
|
|
|
const returnData: INodeParameters = {};
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2022-09-09 07:34:50 -07:00
|
|
|
for (const [key, value] of Object.entries(parameterValue)) {
|
2022-09-21 06:44:45 -07:00
|
|
|
returnData[key] = resolveParameterValue(
|
|
|
|
value as NodeParameterValueType,
|
|
|
|
parameterValue as INodeParameters,
|
|
|
|
);
|
2021-08-29 11:58:11 -07:00
|
|
|
}
|
2020-09-12 03:16:07 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
if (returnObjectAsString && typeof returnData === 'object') {
|
|
|
|
return this.convertObjectValueToString(returnData);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
2022-05-27 08:00:51 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return returnData;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
}
|