2022-03-13 01:34:44 -08:00
|
|
|
import { DateTime, Duration, Interval } from 'luxon';
|
2023-09-21 05:57:45 -07:00
|
|
|
import * as tmpl from '@n8n_io/riot-tmpl';
|
2022-03-13 01:34:44 -08:00
|
|
|
|
2023-01-27 05:56:56 -08:00
|
|
|
import type {
|
2023-08-25 01:33:46 -07:00
|
|
|
IDataObject,
|
2022-06-03 08:25:07 -07:00
|
|
|
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,
|
2021-01-29 00:31:40 -08:00
|
|
|
WorkflowExecuteMode,
|
2022-09-23 07:14:28 -07:00
|
|
|
} from './Interfaces';
|
2023-11-27 06:33:21 -08:00
|
|
|
import { ExpressionError } from './errors/expression.error';
|
|
|
|
import { ExpressionExtensionError } from './errors/expression-extension.error';
|
2022-09-23 07:14:28 -07:00
|
|
|
import { WorkflowDataProxy } from './WorkflowDataProxy';
|
|
|
|
import type { Workflow } from './Workflow';
|
2020-09-12 03:16:07 -07:00
|
|
|
|
2023-03-14 08:22:52 -07:00
|
|
|
import { extend, extendOptional } from './Extensions';
|
2023-01-10 05:06:12 -08:00
|
|
|
import { extendedFunctions } from './Extensions/ExtendedFunctions';
|
2023-03-14 08:22:52 -07:00
|
|
|
import { extendSyntax } from './Extensions/ExpressionExtension';
|
2023-09-21 05:57:45 -07:00
|
|
|
import { evaluateExpression, setErrorHandler } from './ExpressionEvaluatorProxy';
|
2023-10-27 05:17:52 -07:00
|
|
|
import { getGlobalState } from './GlobalState';
|
2023-11-30 03:46:45 -08:00
|
|
|
import { ApplicationError } from './errors/application.error';
|
2023-07-12 03:31:32 -07:00
|
|
|
|
|
|
|
const IS_FRONTEND_IN_DEV_MODE =
|
|
|
|
typeof process === 'object' &&
|
|
|
|
Object.keys(process).length === 1 &&
|
|
|
|
'env' in process &&
|
|
|
|
Object.keys(process.env).length === 0;
|
|
|
|
|
|
|
|
const IS_FRONTEND = typeof process === 'undefined' || IS_FRONTEND_IN_DEV_MODE;
|
|
|
|
|
2023-10-27 05:17:52 -07:00
|
|
|
const isSyntaxError = (error: unknown): error is SyntaxError =>
|
2023-07-12 03:31:32 -07:00
|
|
|
error instanceof SyntaxError || (error instanceof Error && error.name === 'SyntaxError');
|
|
|
|
|
2023-10-27 05:17:52 -07:00
|
|
|
const isExpressionError = (error: unknown): error is ExpressionError =>
|
2023-07-12 03:31:32 -07:00
|
|
|
error instanceof ExpressionError || error instanceof ExpressionExtensionError;
|
|
|
|
|
2023-10-27 05:17:52 -07:00
|
|
|
const isTypeError = (error: unknown): error is TypeError =>
|
2023-07-12 03:31:32 -07:00
|
|
|
error instanceof TypeError || (error instanceof Error && error.name === 'TypeError');
|
2023-01-10 05:06:12 -08:00
|
|
|
|
2022-06-03 08:25:07 -07:00
|
|
|
// Make sure that error get forwarded
|
2023-09-21 05:57:45 -07:00
|
|
|
setErrorHandler((error: Error) => {
|
2023-06-08 02:06:09 -07:00
|
|
|
if (isExpressionError(error)) throw error;
|
2023-09-21 05:57:45 -07:00
|
|
|
});
|
2020-09-12 03:16:07 -07:00
|
|
|
|
2023-06-14 04:15:27 -07:00
|
|
|
const AsyncFunction = (async () => {}).constructor as FunctionConstructor;
|
|
|
|
|
|
|
|
const fnConstructors = {
|
|
|
|
sync: Function.prototype.constructor,
|
2023-07-31 02:00:48 -07:00
|
|
|
|
2023-06-14 04:15:27 -07:00
|
|
|
async: AsyncFunction.prototype.constructor,
|
|
|
|
mock: () => {
|
|
|
|
throw new ExpressionError('Arbitrary code execution detected');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
export class Expression {
|
2023-10-27 05:17:52 -07:00
|
|
|
constructor(private readonly workflow: Workflow) {}
|
2020-09-12 03:16:07 -07:00
|
|
|
|
2023-08-25 01:33:46 -07:00
|
|
|
static resolveWithoutWorkflow(expression: string, data: IDataObject = {}) {
|
|
|
|
return tmpl.tmpl(expression, data);
|
2023-02-02 03:35:38 -08:00
|
|
|
}
|
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
/**
|
|
|
|
* Converts an object to a string in a way to make it clear that
|
|
|
|
* the value comes from an object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
convertObjectValueToString(value: object): string {
|
2023-02-15 01:50:16 -08:00
|
|
|
if (value instanceof DateTime && value.invalidReason !== null) {
|
2023-11-30 03:46:45 -08:00
|
|
|
throw new ApplicationError('invalid DateTime');
|
2023-02-02 03:35:38 -08:00
|
|
|
}
|
|
|
|
|
2024-05-30 04:51:45 -07:00
|
|
|
if (value === null) {
|
|
|
|
return 'null';
|
|
|
|
}
|
|
|
|
|
2024-05-16 05:53:22 -07:00
|
|
|
let typeName = value.constructor.name ?? 'Object';
|
|
|
|
if (DateTime.isDateTime(value)) {
|
|
|
|
typeName = 'DateTime';
|
|
|
|
}
|
|
|
|
|
2023-02-15 01:50:16 -08:00
|
|
|
let result = '';
|
|
|
|
if (value instanceof Date) {
|
|
|
|
// We don't want to use JSON.stringify for dates since it disregards workflow timezone
|
|
|
|
result = DateTime.fromJSDate(value, {
|
2023-10-27 05:17:52 -07:00
|
|
|
zone: this.workflow.settings?.timezone ?? getGlobalState().defaultTimezone,
|
2023-02-15 01:50:16 -08:00
|
|
|
}).toISO();
|
2024-05-16 05:53:22 -07:00
|
|
|
} else if (DateTime.isDateTime(value)) {
|
|
|
|
result = value.toString();
|
2023-02-15 01:50:16 -08:00
|
|
|
} else {
|
|
|
|
result = JSON.stringify(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = result
|
2023-02-02 03:35:38 -08:00
|
|
|
.replace(/,"/g, ', "') // spacing for
|
|
|
|
.replace(/":/g, '": '); // readability
|
|
|
|
|
|
|
|
return `[${typeName}: ${result}]`;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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 {(IRunExecutionData | null)} runExecutionData
|
|
|
|
* @param {boolean} [returnObjectAsString=false]
|
|
|
|
*/
|
2023-10-02 08:33:43 -07:00
|
|
|
// TODO: Clean that up at some point and move all the options into an options object
|
2024-04-10 05:02:02 -07:00
|
|
|
// eslint-disable-next-line complexity
|
2021-08-21 05:11:32 -07:00
|
|
|
resolveSimpleParameterValue(
|
|
|
|
parameterValue: NodeParameterValue,
|
|
|
|
siblingParameters: INodeParameters,
|
|
|
|
runExecutionData: IRunExecutionData | null,
|
|
|
|
runIndex: number,
|
|
|
|
itemIndex: number,
|
|
|
|
activeNodeName: string,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2021-08-21 05:11:32 -07:00
|
|
|
returnObjectAsString = false,
|
|
|
|
selfData = {},
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName?: string,
|
2021-08-21 05:11:32 -07:00
|
|
|
): 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
|
2023-07-31 02:00:48 -07:00
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
parameterValue = parameterValue.substr(1);
|
|
|
|
|
|
|
|
// Generate a data proxy which allows to query workflow data
|
2021-08-21 05:11:32 -07:00
|
|
|
const dataProxy = new WorkflowDataProxy(
|
|
|
|
this.workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
siblingParameters,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -07:00
|
|
|
-1,
|
|
|
|
selfData,
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName,
|
2021-08-21 05:11:32 -07:00
|
|
|
);
|
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
|
2022-09-23 07:14:28 -07:00
|
|
|
data.process =
|
|
|
|
typeof process !== 'undefined'
|
|
|
|
? {
|
|
|
|
arch: process.arch,
|
2022-10-13 13:47:41 -07:00
|
|
|
env: process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE === 'true' ? {} : process.env,
|
2022-09-23 07:14:28 -07:00
|
|
|
platform: process.platform,
|
|
|
|
pid: process.pid,
|
|
|
|
ppid: process.ppid,
|
|
|
|
release: process.release,
|
|
|
|
version: process.pid,
|
|
|
|
versions: process.versions,
|
2024-03-26 06:22:57 -07:00
|
|
|
}
|
2022-09-23 07:14:28 -07:00
|
|
|
: {};
|
2021-11-09 23:49:45 -08:00
|
|
|
|
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 = {};
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-01-10 05:06:12 -08:00
|
|
|
// expression extensions
|
|
|
|
data.extend = extend;
|
2023-02-09 05:57:45 -08:00
|
|
|
data.extendOptional = extendOptional;
|
2023-01-10 05:06:12 -08:00
|
|
|
|
|
|
|
Object.assign(data, extendedFunctions);
|
|
|
|
|
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
|
2023-03-14 08:22:52 -07:00
|
|
|
const extendedExpression = extendSyntax(parameterValue);
|
2023-01-10 05:06:12 -08:00
|
|
|
const returnValue = this.renderExpression(extendedExpression, data);
|
2022-09-09 07:34:50 -07:00
|
|
|
if (typeof returnValue === 'function') {
|
2023-11-30 03:46:45 -08:00
|
|
|
if (returnValue.name === '$') throw new ApplicationError('invalid syntax');
|
2023-02-02 03:35:38 -08:00
|
|
|
|
|
|
|
if (returnValue.name === 'DateTime')
|
2023-11-30 03:46:45 -08:00
|
|
|
throw new ApplicationError('this is a DateTime, please access its methods');
|
2023-02-02 03:35:38 -08:00
|
|
|
|
2023-11-30 03:46:45 -08:00
|
|
|
throw new ApplicationError('this is a function, please add ()');
|
2022-09-09 07:34:50 -07:00
|
|
|
} else if (typeof returnValue === 'string') {
|
|
|
|
return returnValue;
|
|
|
|
} else if (returnValue !== null && typeof returnValue === 'object') {
|
|
|
|
if (returnObjectAsString) {
|
|
|
|
return this.convertObjectValueToString(returnValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2023-01-10 05:06:12 -08:00
|
|
|
private renderExpression(
|
|
|
|
expression: string,
|
|
|
|
data: IWorkflowDataProxyData,
|
|
|
|
): tmpl.ReturnValue | undefined {
|
2020-09-12 03:16:07 -07:00
|
|
|
try {
|
2023-06-14 04:15:27 -07:00
|
|
|
[Function, AsyncFunction].forEach(({ prototype }) =>
|
|
|
|
Object.defineProperty(prototype, 'constructor', { value: fnConstructors.mock }),
|
|
|
|
);
|
2023-09-21 05:57:45 -07:00
|
|
|
return evaluateExpression(expression, data);
|
2022-06-03 08:25:07 -07:00
|
|
|
} catch (error) {
|
2023-06-08 02:06:09 -07:00
|
|
|
if (isExpressionError(error)) throw error;
|
2023-01-11 03:15:42 -08:00
|
|
|
|
2023-11-30 03:46:45 -08:00
|
|
|
if (isSyntaxError(error)) throw new ApplicationError('invalid syntax');
|
2023-02-02 03:35:38 -08:00
|
|
|
|
2023-06-08 02:06:09 -07:00
|
|
|
if (isTypeError(error) && IS_FRONTEND && error.message.endsWith('is not a function')) {
|
2023-02-02 03:35:38 -08:00
|
|
|
const match = error.message.match(/(?<msg>[^.]+is not a function)/);
|
|
|
|
|
|
|
|
if (!match?.groups?.msg) return null;
|
|
|
|
|
2023-11-30 03:46:45 -08:00
|
|
|
throw new ApplicationError(match.groups.msg);
|
2023-02-02 03:35:38 -08:00
|
|
|
}
|
2023-06-14 04:15:27 -07:00
|
|
|
} finally {
|
|
|
|
Object.defineProperty(Function.prototype, 'constructor', { value: fnConstructors.sync });
|
|
|
|
Object.defineProperty(AsyncFunction.prototype, 'constructor', {
|
|
|
|
value: fnConstructors.async,
|
|
|
|
});
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
2023-06-08 02:06:09 -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 {(string | undefined)} parameterValue
|
|
|
|
*/
|
2021-08-21 05:11:32 -07:00
|
|
|
getSimpleParameterValue(
|
|
|
|
node: INode,
|
|
|
|
parameterValue: string | boolean | undefined,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2023-06-23 03:07:52 -07:00
|
|
|
defaultValue?: boolean | number | string | unknown[],
|
|
|
|
): boolean | number | string | undefined | unknown[] {
|
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-21 05:11:32 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
parameterValue,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -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 {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])} parameterValue
|
|
|
|
* @param {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)} [defaultValue]
|
|
|
|
*/
|
2021-08-21 05:11:32 -07:00
|
|
|
getComplexParameterValue(
|
|
|
|
node: INode,
|
|
|
|
parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
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-21 05:11:32 -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-21 05:11:32 -07:00
|
|
|
const returnData = this.getParameterValue(
|
|
|
|
parameterValue,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -07:00
|
|
|
false,
|
|
|
|
selfData,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
|
|
|
|
// Resolve the "inner" values
|
2021-08-21 05:11:32 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
returnData,
|
|
|
|
runData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -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 {boolean} [returnObjectAsString=false]
|
|
|
|
*/
|
2023-10-02 08:33:43 -07:00
|
|
|
// TODO: Clean that up at some point and move all the options into an options object
|
2021-08-21 05:11:32 -07:00
|
|
|
getParameterValue(
|
2022-09-21 06:44:45 -07:00
|
|
|
parameterValue: NodeParameterValueType | INodeParameterResourceLocator,
|
2021-08-21 05:11:32 -07:00
|
|
|
runExecutionData: IRunExecutionData | null,
|
|
|
|
runIndex: number,
|
|
|
|
itemIndex: number,
|
|
|
|
activeNodeName: string,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData?: IExecuteData,
|
2021-08-21 05:11:32 -07:00
|
|
|
returnObjectAsString = false,
|
|
|
|
selfData = {},
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName?: string,
|
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-05-14 16:16:48 -07:00
|
|
|
const resolveParameterValue = (
|
2022-09-21 06:44:45 -07:00
|
|
|
value: NodeParameterValueType,
|
2021-05-14 16:16:48 -07:00
|
|
|
siblingParameters: INodeParameters,
|
|
|
|
) => {
|
2020-09-12 03:16:07 -07:00
|
|
|
if (isComplexParameter(value)) {
|
2021-08-21 05:11:32 -07:00
|
|
|
return this.getParameterValue(
|
|
|
|
value,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName,
|
2021-08-21 05:11:32 -07:00
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
2023-01-10 05:06:12 -08:00
|
|
|
|
2021-08-21 05:11:32 -07:00
|
|
|
return this.resolveSimpleParameterValue(
|
|
|
|
value as NodeParameterValue,
|
|
|
|
siblingParameters,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
2021-08-29 11:58:11 -07:00
|
|
|
mode,
|
2021-08-21 05:11:32 -07:00
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName,
|
2021-08-29 11:58:11 -07:00
|
|
|
);
|
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-21 05:11:32 -07:00
|
|
|
return this.resolveSimpleParameterValue(
|
|
|
|
parameterValue as NodeParameterValue,
|
|
|
|
{},
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
activeNodeName,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
2022-06-03 08:25:07 -07:00
|
|
|
executeData,
|
2021-08-21 05:11:32 -07:00
|
|
|
returnObjectAsString,
|
|
|
|
selfData,
|
2023-10-02 08:33:43 -07:00
|
|
|
contextNodeName,
|
2021-08-21 05:11:32 -07:00
|
|
|
);
|
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
|
feat(editor): Implement Resource Mapper component (#6207)
* :zap: scaffolding
* :zap: finished scaffolding
* :zap: renamed types
* :zap: updated subtitle
* :zap: renamed functions file, UI updates
* :zap: query parameters fixes, ui updates, refactoring
* :zap: fixes for credentials test, setup for error parsing
* :zap: rlc for schema and table, error handling tweaks
* :zap: delete operation, new options
* :zap: columns loader
* :zap: linter fixes
* :zap: where clauses setup
* :zap: logic for processing where clauses
* :zap: select operation
* :zap: refactoring
* :zap: data mode for insert and update, wip
* :zap: data mapping, insert update, skip on conflict option
* :zap: select columns with spaces fix
* :zap: update operation update, wip
* :zap: finished update operation
* :zap: upsert operation
* :zap: ui fixes
* Copy updates.
* Copy updates.
* :zap: option to convert empty strings to nulls, schema checks
* :zap: UI requested updates
* :zap: ssh setup WIP
* :zap: fixes, ssh WIP
* :zap: ssh fixes, credentials
* :zap: credentials testing update
* :zap: uncaught error fix
* :zap: clean up
* :zap: address in use fix
* :zap: improved error message
* :zap: tests setup
* :zap: unit tests wip
* :zap: config files clean up
* :zap: utils unit tests
* :zap: refactoring
* :zap: setup for testing operations, tests for deleteTable operation
* :zap: executeQuery and insert operations tests
* :zap: select, update, upsert operations tests
* :zap: runQueries tests setup
* :zap: hint to query
* Copy updates.
* :zap: ui fixes
* :zap: clean up
* :zap: error message update
* :zap: ui update
* Minor tweaks to query params decription.
* feat(Google Sheets Node): Implement Resource mapper in Google Sheets node (#5752)
* ✨ Added initial resource mapping support in google sheets node
* ✨ Wired mapping API endpoint with node-specific logic for fetching mapping fields
* ✨ Implementing mapping fields logic for google sheets
* ✨ Updating Google Sheets execute methods to support resource mapper fields
* 🚧 Added initial version of `ResourceLocator` component
* 👌 Added `update` mode to resource mapper modes
* 👌 Addressing PR feedback
* 👌 Removing leftover const reference
* 👕 Fixing lint errors
* :zap: singlton for conections
* :zap: credentials test fix, clean up
* feat(Postgres Node): Add resource mapper to new version of Postgres node (#5814)
* :zap: scaffolding
* :zap: finished scaffolding
* :zap: renamed types
* :zap: updated subtitle
* :zap: renamed functions file, UI updates
* :zap: query parameters fixes, ui updates, refactoring
* :zap: fixes for credentials test, setup for error parsing
* :zap: rlc for schema and table, error handling tweaks
* :zap: delete operation, new options
* :zap: columns loader
* :zap: linter fixes
* :zap: where clauses setup
* :zap: logic for processing where clauses
* :zap: select operation
* :zap: refactoring
* :zap: data mode for insert and update, wip
* :zap: data mapping, insert update, skip on conflict option
* :zap: select columns with spaces fix
* :zap: update operation update, wip
* :zap: finished update operation
* :zap: upsert operation
* :zap: ui fixes
* Copy updates.
* Copy updates.
* :zap: option to convert empty strings to nulls, schema checks
* :zap: UI requested updates
* :zap: ssh setup WIP
* :zap: fixes, ssh WIP
* :zap: ssh fixes, credentials
* :zap: credentials testing update
* :zap: uncaught error fix
* :zap: clean up
* :zap: address in use fix
* :zap: improved error message
* :zap: tests setup
* :zap: unit tests wip
* :zap: config files clean up
* :zap: utils unit tests
* :zap: refactoring
* :zap: setup for testing operations, tests for deleteTable operation
* :zap: executeQuery and insert operations tests
* :zap: select, update, upsert operations tests
* :zap: runQueries tests setup
* :zap: hint to query
* Copy updates.
* :zap: ui fixes
* :zap: clean up
* :zap: error message update
* :zap: ui update
* Minor tweaks to query params decription.
* ✨ Updated Postgres node to use resource mapper component
* ✨ Implemented postgres <-> resource mapper type mapping
* ✨ Updated Postgres node execution to use resource mapper fields in v3
* 🔥 Removing unused import
---------
Co-authored-by: Michael Kret <michael.k@radency.com>
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
* feat(core): Resource editor componend P0 (#5970)
* ✨ Added inital value of mapping mode dropdown
* ✨ Finished mapping mode selector
* ✨ Finished implementing mapping mode selector
* ✨ Implemented 'Columns to match on' dropdown
* ✨ Implemented `loadOptionsDependOn` support in resource mapper
* ✨ Implemented initial version of mapping fields
* ✨ Implementing dependant fields watcher in new component setup
* ✨ Generating correct resource mapper field types. Added `supportAutoMap` to node specification and UI. Not showing fields with `display=false`. Pre-selecting matching columns if it's the only one
* ✨ Handling matching columns correctly in UI
* ✨ Saving and loading resourceMapper values in component
* ✨ Implemented proper data saving and loading
* ✨ ResourceMapper component refactor, fixing value save/load
* ✨ Refactoring MatchingColumnSelect component. Updating Sheets node to use single key match and Postgres to use multi key
* ✨ Updated Google Sheets node to work with the new UI
* ✨ Updating Postgres Node to work with new UI
* ✨ Additional loading indicator that shown if there is no mapping mode selector
* ✨ Removing hard-coded values, fixing matching columns ordering, refactoring
* ✨ Updating field names in nodes
* ✨ Fixing minor UI issues
* ✨ Implemented matching fields filter logic
* ✨ Moving loading label outside of fields list
* ✅ Added initial unit tests for resource mapper
* ✅ Finished default rendering test
* ✅ Test refactoring
* ✅ Finished unit tests
* 🔨 Updating the way i18n is used in resource mapper components
* ✔️ Fixing value to match on logic for postgres node
* ✨ Hiding mapping fields when auto-map mode is selected
* ✨ Syncing selected mapping mode between components
* ✨ Fixing dateTime input rendering and adding update check to Postgres node
* ✨ Properly handling database connections. Sending null for empty string values.
* 💄 Updated wording in the error message for non-existing rows
* ✨ Fixing issues with selected matching values
* ✔️ Updating unit tests after matching logic update
* ✨ Updating matching columns when new fields are loaded
* ✨ Defaulting to null for empty parameter values
* ✨ Allowing zero as valid value for number imputs
* ✨ Updated list of types that use datepicker as widger
* ✨ Using text inputs for time types
* ✨ Initial mapping field rework
* ✨ Added new component for mapping fields, moved bit of logic from root component to matching selector, fixing some lint errors
* ✨ Added tooltip for columns that cannot be deleted
* ✨ Saving deleted values in parameter value
* ✨ Implemented control to add/remove mapping fields
* ✨ Syncing field list with add field dropdown when changing dependent values
* ✨ Not showing removed fields in matching columns selector. Updating wording in matching columns selector description
* ✨ Implementing disabled states for add/remove all fields options
* ✨ Saving removed columns separately, updating copy
* ✨ Implemented resource mapper values validation
* ✨ Updated validation logic and error input styling
* ✨ Validating resource mapper fields when new nodes are added
* ✨ Using node field words in validation, refactoring resource mapper component
* ✨ Implemented schema syncing and add/remove all fields
* ✨ Implemented custom parameter actions
* ✨ Implemented loading indicator in parameter options
* 🔨 Removing unnecessary constants and vue props
* ✨ Handling default values properly
* ✨ Fixing validation logic
* 👕 Fixing lint errors
* ⚡ Fixing type issues
* ⚡ Not showing fields by default if `addAllFields` is set to `false`
* ✨ Implemented field type validation in resource mapper
* ✨ Updated casing in copy, removed all/remove all option from bottom menu
* ✨ Added auto mapping mode notice
* ✨ Added support for more types in validation
* ✨ Added support for enumerated values
* ✨ Fixing imports after merging
* ✨ Not showing removed fields in matching columns selector. Refactoring validation logic.
* 👕 Fixing imports
* ✔️ Updating unit tests
* ✅ Added resource mapper schema tests
* ⚡ Removing `match` from resource mapper field definition, fixing matching columns loading
* ⚡ Fixed schema merging
* :zap: update operation return data fix
* :zap: review
* 🐛 Added missing import
* 💄 Updating parameter actions icon based on the ui review
* 💄 Updating word capitalisation in tooltips
* 💄 Added empty state to mapping fields list
* 💄 Removing asterisk from fields, updating tooltips for matching fields
* ⚡ Preventing matching fields from being removed by 'Remove All option'
* ⚡ Not showing hidden fields in the `Add field` dropdown
* ⚡ Added support for custom matching columns labels
* :zap: query optimization
* :zap: fix
* ⚡ Optimizing Postgres node enumeration logic
* ⚡ Added empty state for matching columns
* ⚡ Only fully loading fields if there is no schema fetched
* ⚡ Hiding mapping fields if there is no matching columns available in the schema
* ✔️ Fixing minor issues
* ✨ Implemented runtime type validation
* 🔨 Refactoring validation logic
* ✨ Implemented required check, added more custom messages
* ✨ Skipping boolean type in required check
* Type check improvements
* ✨ Only reloading fields if dependent values actually change
* ✨ Adding item index to validation error title
* ✨ Updating Postgres fetching logic, using resource mapper mode to determine if a field can be deleted
* ✨ Resetting field values when adding them via the addAll option
* ⚡ Using minor version (2.2) for new Postgres node
* ⚡ Implemented proper date validation and type casting
* 👕 Consolidating typing
* ✅ Added unit tests for type validations
* 👌 Addressing front-end review comments
* ⚡ More refactoring to address review changes
* ⚡ Updating leftover props
* ⚡ Added fallback for ISO dates with invalid timezones
* Added timestamp to datetime test cases
* ⚡ Reseting matching columns if operation changes
* ⚡ Not forcing auto-increment fields to be filled in in Postgres node. Handling null values
* 💄 Added a custom message for invalid dates
* ⚡ Better handling of JSON values
* ⚡ Updating codemirror readonly stauts based on component property, handling objects in json validation
* Deleting leftover console.log
* ⚡ Better time validation
* ⚡ Fixing build error after merging
* 👕 Fixing lint error
* ⚡ Updating node configuration values
* ⚡ Handling postgres arrays better
* ⚡ Handling SQL array syntax
* ⚡ Updating time validation rules to include timezone
* ⚡ Sending expressions that resolve to `null` or `undefined` by the resource mapper to delete cell content in Google Sheets
* ⚡ Allowing removed fields to be selected for match
* ⚡ Updated the query for fetching unique columns and primary keys
* ⚡ Optimizing the unique query
* ⚡ Setting timezone to all parsed dates
* ⚡ Addressing PR review feedback
* ⚡ Configuring Sheets node for production, minor vue component update
* New cases added to the TypeValidation test.
* ✅ Tweaking validation rules for arrays/objects and updating test cases
---------
Co-authored-by: Michael Kret <michael.k@radency.com>
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
2023-05-31 02:56:09 -07:00
|
|
|
const returnData = parameterValue.map((item) =>
|
|
|
|
resolveParameterValue(item as NodeParameterValueType, {}),
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
return returnData as NodeParameterValue[] | INodeParameters[];
|
2020-10-26 01:26:07 -07:00
|
|
|
}
|
2022-09-09 07:34:50 -07:00
|
|
|
|
2020-10-26 01:26:07 -07:00
|
|
|
if (parameterValue === null || parameterValue === undefined) {
|
2020-09-23 04:20:50 -07:00
|
|
|
return parameterValue;
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
2022-05-27 08:00:51 -07:00
|
|
|
|
2022-09-09 07:34:50 -07:00
|
|
|
if (typeof parameterValue !== 'object') {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
// Data is an object
|
|
|
|
const returnData: INodeParameters = {};
|
2023-07-31 02:00:48 -07:00
|
|
|
|
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,
|
|
|
|
);
|
2020-09-12 03:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (returnObjectAsString && typeof returnData === 'object') {
|
|
|
|
return this.convertObjectValueToString(returnData);
|
|
|
|
}
|
2022-05-27 08:00:51 -07:00
|
|
|
|
2020-09-12 03:16:07 -07:00
|
|
|
return returnData;
|
|
|
|
}
|
|
|
|
}
|