n8n-mcp 2.98.0 → 2.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +3 -0
- package/dist/http-server-single-session.d.ts.map +1 -1
- package/dist/http-server-single-session.js +10 -1
- package/dist/http-server-single-session.js.map +1 -1
- package/dist/http-server.d.ts.map +1 -1
- package/dist/http-server.js +46 -5
- package/dist/http-server.js.map +1 -1
- package/dist/mcp/handlers-n8n-manager.d.ts.map +1 -1
- package/dist/mcp/handlers-n8n-manager.js +83 -1
- package/dist/mcp/handlers-n8n-manager.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +31 -18
- package/dist/mcp/server.js.map +1 -1
- package/dist/services/confidence-scorer.d.ts.map +1 -1
- package/dist/services/confidence-scorer.js +8 -6
- package/dist/services/confidence-scorer.js.map +1 -1
- package/dist/services/config-validator.d.ts +6 -0
- package/dist/services/config-validator.d.ts.map +1 -1
- package/dist/services/config-validator.js +131 -5
- package/dist/services/config-validator.js.map +1 -1
- package/dist/services/credential-scanner.d.ts +1 -0
- package/dist/services/credential-scanner.d.ts.map +1 -1
- package/dist/services/credential-scanner.js +102 -5
- package/dist/services/credential-scanner.js.map +1 -1
- package/dist/services/expression-format-validator.d.ts.map +1 -1
- package/dist/services/expression-format-validator.js +3 -0
- package/dist/services/expression-format-validator.js.map +1 -1
- package/dist/services/n8n-api-client.d.ts +8 -0
- package/dist/services/n8n-api-client.d.ts.map +1 -1
- package/dist/services/n8n-api-client.js +55 -2
- package/dist/services/n8n-api-client.js.map +1 -1
- package/dist/services/n8n-official-mcp-client.d.ts +2 -0
- package/dist/services/n8n-official-mcp-client.d.ts.map +1 -1
- package/dist/services/n8n-official-mcp-client.js +61 -1
- package/dist/services/n8n-official-mcp-client.js.map +1 -1
- package/dist/services/n8n-version.d.ts.map +1 -1
- package/dist/services/n8n-version.js +2 -0
- package/dist/services/n8n-version.js.map +1 -1
- package/dist/services/node-groups.d.ts +1 -1
- package/dist/services/node-groups.d.ts.map +1 -1
- package/dist/services/node-groups.js +167 -26
- package/dist/services/node-groups.js.map +1 -1
- package/dist/services/node-specific-validators.d.ts +5 -1
- package/dist/services/node-specific-validators.d.ts.map +1 -1
- package/dist/services/node-specific-validators.js +277 -92
- package/dist/services/node-specific-validators.js.map +1 -1
- package/dist/services/operation-similarity-service.d.ts +5 -0
- package/dist/services/operation-similarity-service.d.ts.map +1 -1
- package/dist/services/operation-similarity-service.js +35 -9
- package/dist/services/operation-similarity-service.js.map +1 -1
- package/dist/services/resource-similarity-service.d.ts +5 -0
- package/dist/services/resource-similarity-service.d.ts.map +1 -1
- package/dist/services/resource-similarity-service.js +33 -9
- package/dist/services/resource-similarity-service.js.map +1 -1
- package/dist/services/workflow-auto-fixer.d.ts.map +1 -1
- package/dist/services/workflow-auto-fixer.js +24 -4
- package/dist/services/workflow-auto-fixer.js.map +1 -1
- package/dist/services/workflow-diff-engine.d.ts +4 -0
- package/dist/services/workflow-diff-engine.d.ts.map +1 -1
- package/dist/services/workflow-diff-engine.js +355 -45
- package/dist/services/workflow-diff-engine.js.map +1 -1
- package/dist/services/workflow-validator.d.ts.map +1 -1
- package/dist/services/workflow-validator.js +8 -2
- package/dist/services/workflow-validator.js.map +1 -1
- package/dist/services/workflow-versioning-service.d.ts.map +1 -1
- package/dist/services/workflow-versioning-service.js +3 -0
- package/dist/services/workflow-versioning-service.js.map +1 -1
- package/dist/telemetry/email-redaction.d.ts +2 -0
- package/dist/telemetry/email-redaction.d.ts.map +1 -0
- package/dist/telemetry/email-redaction.js +34 -0
- package/dist/telemetry/email-redaction.js.map +1 -0
- package/dist/telemetry/event-tracker.d.ts.map +1 -1
- package/dist/telemetry/event-tracker.js +10 -2
- package/dist/telemetry/event-tracker.js.map +1 -1
- package/dist/telemetry/event-validator.d.ts +1 -0
- package/dist/telemetry/event-validator.d.ts.map +1 -1
- package/dist/telemetry/event-validator.js +34 -11
- package/dist/telemetry/event-validator.js.map +1 -1
- package/dist/telemetry/intent-sanitizer.d.ts.map +1 -1
- package/dist/telemetry/intent-sanitizer.js +8 -2
- package/dist/telemetry/intent-sanitizer.js.map +1 -1
- package/dist/telemetry/workflow-sanitizer.d.ts +27 -3
- package/dist/telemetry/workflow-sanitizer.d.ts.map +1 -1
- package/dist/telemetry/workflow-sanitizer.js +281 -36
- package/dist/telemetry/workflow-sanitizer.js.map +1 -1
- package/dist/triggers/handlers/chat-handler.d.ts.map +1 -1
- package/dist/triggers/handlers/chat-handler.js +4 -1
- package/dist/triggers/handlers/chat-handler.js.map +1 -1
- package/dist/triggers/handlers/form-handler.d.ts.map +1 -1
- package/dist/triggers/handlers/form-handler.js +4 -1
- package/dist/triggers/handlers/form-handler.js.map +1 -1
- package/dist/utils/expression-utils.d.ts.map +1 -1
- package/dist/utils/expression-utils.js +1 -4
- package/dist/utils/expression-utils.js.map +1 -1
- package/dist/utils/object-keys.d.ts +4 -0
- package/dist/utils/object-keys.d.ts.map +1 -0
- package/dist/utils/object-keys.js +13 -0
- package/dist/utils/object-keys.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WorkflowDiffEngine = void 0;
|
|
36
|
+
exports.WorkflowDiffEngine = exports.MAX_CONNECTION_INDEX = void 0;
|
|
4
37
|
const uuid_1 = require("uuid");
|
|
38
|
+
const vm = __importStar(require("vm"));
|
|
5
39
|
const workflow_diff_1 = require("../types/workflow-diff");
|
|
6
40
|
const logger_1 = require("../utils/logger");
|
|
41
|
+
const object_keys_1 = require("../utils/object-keys");
|
|
7
42
|
const node_groups_1 = require("./node-groups");
|
|
8
43
|
const node_sanitizer_1 = require("./node-sanitizer");
|
|
9
44
|
const node_type_utils_1 = require("../utils/node-type-utils");
|
|
@@ -12,26 +47,190 @@ const PATCH_LIMITS = {
|
|
|
12
47
|
MAX_PATCHES: 50,
|
|
13
48
|
MAX_REGEX_LENGTH: 500,
|
|
14
49
|
MAX_FIELD_SIZE_REGEX: 512 * 1024,
|
|
50
|
+
REGEX_EVAL_TIMEOUT_MS: 100,
|
|
51
|
+
REGEX_TIME_BUDGET_MS: 300,
|
|
52
|
+
MAX_PATCH_GROWTH: 512 * 1024,
|
|
15
53
|
};
|
|
16
|
-
const
|
|
54
|
+
const MAX_DIFF_OPERATIONS = 1000;
|
|
55
|
+
exports.MAX_CONNECTION_INDEX = 1000;
|
|
56
|
+
const DANGEROUS_PATH_KEYS = object_keys_1.RESERVED_OBJECT_KEYS;
|
|
57
|
+
function ownOutputs(connections, nodeName) {
|
|
58
|
+
return (0, object_keys_1.hasOwnKey)(connections, nodeName) ? connections[nodeName] : undefined;
|
|
59
|
+
}
|
|
60
|
+
function ownOutputSlots(connections, nodeName, output) {
|
|
61
|
+
const outputs = ownOutputs(connections, nodeName);
|
|
62
|
+
return outputs && (0, object_keys_1.hasOwnKey)(outputs, output) ? outputs[output] : undefined;
|
|
63
|
+
}
|
|
17
64
|
function isUnsafeRegex(pattern) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
65
|
+
const groups = [];
|
|
66
|
+
let closedGroupIsComplex = false;
|
|
67
|
+
let i = 0;
|
|
68
|
+
const markEnclosingGroup = () => {
|
|
69
|
+
if (groups.length > 0)
|
|
70
|
+
groups[groups.length - 1] = true;
|
|
71
|
+
};
|
|
72
|
+
while (i < pattern.length) {
|
|
73
|
+
const ch = pattern[i];
|
|
74
|
+
const afterGroup = closedGroupIsComplex;
|
|
75
|
+
closedGroupIsComplex = false;
|
|
76
|
+
if (ch === '\\') {
|
|
77
|
+
i += 2;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (ch === '[') {
|
|
81
|
+
i++;
|
|
82
|
+
if (pattern[i] === '^')
|
|
83
|
+
i++;
|
|
84
|
+
while (i < pattern.length && pattern[i] !== ']') {
|
|
85
|
+
i += pattern[i] === '\\' ? 2 : 1;
|
|
86
|
+
}
|
|
87
|
+
i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (ch === '(') {
|
|
91
|
+
groups.push(false);
|
|
92
|
+
i++;
|
|
93
|
+
if (pattern[i] === '?') {
|
|
94
|
+
const prefix = /^\?(?:<[A-Za-z_$][\w$]*>|<=|<!|[:=!])/.exec(pattern.slice(i, i + 64));
|
|
95
|
+
i += prefix ? prefix[0].length : 1;
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (ch === ')') {
|
|
100
|
+
const complex = groups.pop() ?? false;
|
|
101
|
+
if (complex)
|
|
102
|
+
markEnclosingGroup();
|
|
103
|
+
closedGroupIsComplex = complex;
|
|
104
|
+
i++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
let quantifierLength = 0;
|
|
108
|
+
let unbounded = false;
|
|
109
|
+
if (ch === '*' || ch === '+') {
|
|
110
|
+
quantifierLength = 1;
|
|
111
|
+
unbounded = true;
|
|
112
|
+
}
|
|
113
|
+
else if (ch === '?') {
|
|
114
|
+
quantifierLength = 1;
|
|
115
|
+
}
|
|
116
|
+
else if (ch === '{') {
|
|
117
|
+
const braces = /^\{\d+(,(\d*))?\}/.exec(pattern.slice(i, i + 32));
|
|
118
|
+
if (braces) {
|
|
119
|
+
quantifierLength = braces[0].length;
|
|
120
|
+
unbounded = braces[2] === '';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (quantifierLength > 0) {
|
|
124
|
+
if (unbounded) {
|
|
125
|
+
if (afterGroup)
|
|
126
|
+
return true;
|
|
127
|
+
markEnclosingGroup();
|
|
128
|
+
}
|
|
129
|
+
i += quantifierLength;
|
|
130
|
+
if (pattern[i] === '?')
|
|
131
|
+
i++;
|
|
132
|
+
continue;
|
|
31
133
|
}
|
|
134
|
+
i++;
|
|
32
135
|
}
|
|
33
136
|
return false;
|
|
34
137
|
}
|
|
138
|
+
const regexContext = vm.createContext(Object.create(null));
|
|
139
|
+
const regexPatchScript = new vm.Script(`(function (input, pattern, replacement, replaceAll, maxLength) {
|
|
140
|
+
var re = new RegExp(pattern, 'g');
|
|
141
|
+
var len = input.length;
|
|
142
|
+
var count = 0;
|
|
143
|
+
var tooLarge = false;
|
|
144
|
+
var tokens = null;
|
|
145
|
+
var delta = 0;
|
|
146
|
+
var m;
|
|
147
|
+
|
|
148
|
+
function parseTemplate(groupCount, hasNamedGroups) {
|
|
149
|
+
var refs = [];
|
|
150
|
+
var literal = 0;
|
|
151
|
+
var i = 0;
|
|
152
|
+
while (i < replacement.length) {
|
|
153
|
+
if (replacement[i] !== '$' || i + 1 >= replacement.length) { literal++; i++; continue; }
|
|
154
|
+
var next = replacement[i + 1];
|
|
155
|
+
if (next === '$') { literal++; i += 2; continue; }
|
|
156
|
+
if (next === '&') { refs.push(0); i += 2; continue; }
|
|
157
|
+
if (next.charCodeAt(0) === 96) { refs.push(-1); i += 2; continue; }
|
|
158
|
+
if (next === "'") { refs.push(-2); i += 2; continue; }
|
|
159
|
+
if (next >= '0' && next <= '9') {
|
|
160
|
+
var one = next.charCodeAt(0) - 48;
|
|
161
|
+
var third = replacement[i + 2];
|
|
162
|
+
if (third >= '0' && third <= '9') {
|
|
163
|
+
var two = one * 10 + third.charCodeAt(0) - 48;
|
|
164
|
+
if (two >= 1 && two <= groupCount) { refs.push(two); i += 3; continue; }
|
|
165
|
+
}
|
|
166
|
+
if (one >= 1 && one <= groupCount) { refs.push(one); i += 2; continue; }
|
|
167
|
+
literal++; i++; continue;
|
|
168
|
+
}
|
|
169
|
+
if (next === '<' && hasNamedGroups) {
|
|
170
|
+
var close = replacement.indexOf('>', i + 2);
|
|
171
|
+
if (close !== -1) { refs.push(replacement.slice(i + 2, close)); i = close + 1; continue; }
|
|
172
|
+
}
|
|
173
|
+
literal++; i++;
|
|
174
|
+
}
|
|
175
|
+
return { refs: refs, literal: literal };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function substitutionLength(match) {
|
|
179
|
+
var total = tokens.literal;
|
|
180
|
+
for (var k = 0; k < tokens.refs.length; k++) {
|
|
181
|
+
var ref = tokens.refs[k];
|
|
182
|
+
var part;
|
|
183
|
+
if (ref === 0) part = match[0];
|
|
184
|
+
else if (ref === -1) { total += match.index; continue; }
|
|
185
|
+
else if (ref === -2) { total += len - match.index - match[0].length; continue; }
|
|
186
|
+
else if (typeof ref === 'number') part = match[ref];
|
|
187
|
+
else part = match.groups[ref];
|
|
188
|
+
if (part !== undefined) total += part.length;
|
|
189
|
+
}
|
|
190
|
+
return total;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
while ((m = re.exec(input)) !== null) {
|
|
194
|
+
count++;
|
|
195
|
+
if (m[0].length === 0) re.lastIndex++;
|
|
196
|
+
if (count === 1) tokens = parseTemplate(m.length - 1, m.groups !== undefined);
|
|
197
|
+
if (count === 1 || replaceAll) {
|
|
198
|
+
delta += substitutionLength(m) - m[0].length;
|
|
199
|
+
if (replaceAll && len + delta > maxLength) { tooLarge = true; break; }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (count > 0 && len + delta > maxLength) tooLarge = true;
|
|
203
|
+
var output = null;
|
|
204
|
+
if (!tooLarge && (count === 1 || (count > 1 && replaceAll))) {
|
|
205
|
+
output = input.replace(replaceAll ? new RegExp(pattern, 'g') : new RegExp(pattern), replacement);
|
|
206
|
+
}
|
|
207
|
+
result = { count: count, tooLarge: tooLarge, output: output };
|
|
208
|
+
})(input, pattern, replacement, replaceAll, maxLength);`);
|
|
209
|
+
function runRegexPatch(input, pattern, replacement, replaceAll, timeoutMs, maxLength) {
|
|
210
|
+
const ctx = regexContext;
|
|
211
|
+
Object.assign(ctx, { input, pattern, replacement, replaceAll, maxLength, result: null });
|
|
212
|
+
try {
|
|
213
|
+
regexPatchScript.runInContext(regexContext, { timeout: Math.max(1, Math.ceil(timeoutMs)) });
|
|
214
|
+
const result = ctx.result;
|
|
215
|
+
return { count: result.count, output: result.output, tooLarge: result.tooLarge === true };
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (error?.code === 'ERR_SCRIPT_EXECUTION_TIMEOUT')
|
|
219
|
+
return 'timeout';
|
|
220
|
+
throw new Error(String(error?.message ?? error));
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
Object.assign(ctx, { input: null, pattern: null, replacement: null, result: null });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function connectionIndexError(name, index) {
|
|
227
|
+
if (index === undefined)
|
|
228
|
+
return null;
|
|
229
|
+
if (typeof index !== 'number' || !Number.isInteger(index) || index < 0 || index > exports.MAX_CONNECTION_INDEX) {
|
|
230
|
+
return `${name} ${String(index).slice(0, 40)} is out of range. Connection indexes must be integers between 0 and ${exports.MAX_CONNECTION_INDEX}.`;
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
35
234
|
function parsePropertyPath(path) {
|
|
36
235
|
const segments = [];
|
|
37
236
|
for (const part of path.split('.')) {
|
|
@@ -202,6 +401,8 @@ class WorkflowDiffEngine {
|
|
|
202
401
|
this.tagsToAdd = [];
|
|
203
402
|
this.tagsToRemove = [];
|
|
204
403
|
this.authoredGroupNames = new Set();
|
|
404
|
+
this.regexBudgetMs = PATCH_LIMITS.REGEX_TIME_BUDGET_MS;
|
|
405
|
+
this.patchGrowthBudget = PATCH_LIMITS.MAX_PATCH_GROWTH;
|
|
205
406
|
}
|
|
206
407
|
async applyDiff(workflow, request) {
|
|
207
408
|
try {
|
|
@@ -213,6 +414,17 @@ class WorkflowDiffEngine {
|
|
|
213
414
|
this.tagsToRemove = [];
|
|
214
415
|
this.transferToProjectId = undefined;
|
|
215
416
|
this.authoredGroupNames.clear();
|
|
417
|
+
this.regexBudgetMs = PATCH_LIMITS.REGEX_TIME_BUDGET_MS;
|
|
418
|
+
this.patchGrowthBudget = PATCH_LIMITS.MAX_PATCH_GROWTH;
|
|
419
|
+
if (Array.isArray(request.operations) && request.operations.length > MAX_DIFF_OPERATIONS) {
|
|
420
|
+
return {
|
|
421
|
+
success: false,
|
|
422
|
+
errors: [{
|
|
423
|
+
operation: -1,
|
|
424
|
+
message: `Too many operations (${request.operations.length}). Maximum is ${MAX_DIFF_OPERATIONS} per request; split the changes across requests.`
|
|
425
|
+
}]
|
|
426
|
+
};
|
|
427
|
+
}
|
|
216
428
|
const workflowCopy = JSON.parse(JSON.stringify(workflow));
|
|
217
429
|
const operationEntries = buildExecutionEntries(request.operations);
|
|
218
430
|
const nodeOperationCount = request.operations.filter(workflow_diff_1.isNodeOperation).length;
|
|
@@ -363,6 +575,10 @@ class WorkflowDiffEngine {
|
|
|
363
575
|
}
|
|
364
576
|
}
|
|
365
577
|
validateOperation(workflow, operation) {
|
|
578
|
+
const reservedKeyError = this.validateReservedKeys(workflow, operation);
|
|
579
|
+
if (reservedKeyError) {
|
|
580
|
+
return reservedKeyError;
|
|
581
|
+
}
|
|
366
582
|
switch (operation.type) {
|
|
367
583
|
case 'addNode':
|
|
368
584
|
return this.validateAddNode(workflow, operation);
|
|
@@ -406,6 +622,58 @@ class WorkflowDiffEngine {
|
|
|
406
622
|
return `Unknown operation type: ${operation.type}`;
|
|
407
623
|
}
|
|
408
624
|
}
|
|
625
|
+
validateReservedKeys(workflow, operation) {
|
|
626
|
+
const reservedNodeName = (name) => (0, object_keys_1.isReservedObjectKey)(name) ? `Node name "${name}" is reserved and cannot be used` : null;
|
|
627
|
+
const reservedConnectionKey = (key) => (0, object_keys_1.isReservedObjectKey)(key) ? `Connection type "${String(key)}" is reserved and cannot be used` : null;
|
|
628
|
+
const resolvedName = (ref) => typeof ref === 'string' ? this.findNode(workflow, ref, ref)?.name : undefined;
|
|
629
|
+
switch (operation.type) {
|
|
630
|
+
case 'addNode':
|
|
631
|
+
return reservedNodeName(operation.node?.name);
|
|
632
|
+
case 'updateNode': {
|
|
633
|
+
const updates = operation.updates;
|
|
634
|
+
return updates && typeof updates === 'object' ? reservedNodeName(updates.name) : null;
|
|
635
|
+
}
|
|
636
|
+
case 'addConnection':
|
|
637
|
+
case 'removeConnection':
|
|
638
|
+
case 'rewireConnection': {
|
|
639
|
+
const op = operation;
|
|
640
|
+
for (const ref of [op.source, op.target, op.from, op.to]) {
|
|
641
|
+
const error = reservedNodeName(resolvedName(ref));
|
|
642
|
+
if (error)
|
|
643
|
+
return error;
|
|
644
|
+
}
|
|
645
|
+
return reservedConnectionKey(op.sourceOutput) ?? reservedConnectionKey(op.targetInput);
|
|
646
|
+
}
|
|
647
|
+
case 'updateSettings': {
|
|
648
|
+
const settings = operation.settings;
|
|
649
|
+
if (!settings || typeof settings !== 'object')
|
|
650
|
+
return null;
|
|
651
|
+
const reservedKey = Object.keys(settings).find(key => (0, object_keys_1.isReservedObjectKey)(key));
|
|
652
|
+
return reservedKey !== undefined ? `Setting "${reservedKey}" is reserved and cannot be used` : null;
|
|
653
|
+
}
|
|
654
|
+
case 'replaceConnections': {
|
|
655
|
+
const connections = operation.connections;
|
|
656
|
+
if (!connections || typeof connections !== 'object')
|
|
657
|
+
return null;
|
|
658
|
+
for (const sourceName of Object.keys(connections)) {
|
|
659
|
+
const error = reservedNodeName(sourceName);
|
|
660
|
+
if (error)
|
|
661
|
+
return error;
|
|
662
|
+
const outputs = connections[sourceName];
|
|
663
|
+
if (outputs && typeof outputs === 'object') {
|
|
664
|
+
for (const outputName of Object.keys(outputs)) {
|
|
665
|
+
const outputError = reservedConnectionKey(outputName);
|
|
666
|
+
if (outputError)
|
|
667
|
+
return outputError;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
default:
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
409
677
|
applyOperation(workflow, operation) {
|
|
410
678
|
switch (operation.type) {
|
|
411
679
|
case 'addNode':
|
|
@@ -500,7 +768,7 @@ class WorkflowDiffEngine {
|
|
|
500
768
|
const hasConnections = Object.values(workflow.connections).some(conn => {
|
|
501
769
|
return Object.values(conn).some(outputs => outputs.some(connections => branchConnections(connections).some(c => c.node === node.name)));
|
|
502
770
|
});
|
|
503
|
-
if (hasConnections || workflow.connections
|
|
771
|
+
if (hasConnections || ownOutputs(workflow.connections, node.name)) {
|
|
504
772
|
logger.warn(`Removing node "${node.name}" will break existing connections`);
|
|
505
773
|
}
|
|
506
774
|
return null;
|
|
@@ -692,7 +960,10 @@ class WorkflowDiffEngine {
|
|
|
692
960
|
return `Target node not found: "${operation.target}". Available nodes: ${availableNodes}. Tip: Use node ID for names with special characters (apostrophes, quotes).`;
|
|
693
961
|
}
|
|
694
962
|
const { sourceOutput, sourceIndex } = this.resolveSmartParameters(workflow, operation, { silent: true });
|
|
695
|
-
const
|
|
963
|
+
const indexError = connectionIndexError('sourceIndex', sourceIndex) ?? connectionIndexError('targetIndex', operation.targetIndex);
|
|
964
|
+
if (indexError)
|
|
965
|
+
return indexError;
|
|
966
|
+
const existing = ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput);
|
|
696
967
|
if (existing) {
|
|
697
968
|
const slot = existing[sourceIndex];
|
|
698
969
|
if (Array.isArray(slot) && slot.some(c => c.node === targetNode.name)) {
|
|
@@ -726,7 +997,7 @@ class WorkflowDiffEngine {
|
|
|
726
997
|
return `Target node not found: "${operation.target}". Available nodes: ${availableNodes}. Tip: Use node ID for names with special characters.`;
|
|
727
998
|
}
|
|
728
999
|
const sourceOutput = operation.sourceOutput || 'main';
|
|
729
|
-
const connections = workflow.connections
|
|
1000
|
+
const connections = ownOutputSlots(workflow.connections, sourceNode.name, String(sourceOutput));
|
|
730
1001
|
if (!connections) {
|
|
731
1002
|
return `No connections found from "${sourceNode.name}"`;
|
|
732
1003
|
}
|
|
@@ -762,7 +1033,10 @@ class WorkflowDiffEngine {
|
|
|
762
1033
|
return `"To" node not found: "${operation.to}". Available nodes: ${availableNodes}. Tip: Use node ID for names with special characters.`;
|
|
763
1034
|
}
|
|
764
1035
|
const { sourceOutput, sourceIndex } = this.resolveSmartParameters(workflow, operation, { silent: true });
|
|
765
|
-
const
|
|
1036
|
+
const indexError = connectionIndexError('sourceIndex', sourceIndex);
|
|
1037
|
+
if (indexError)
|
|
1038
|
+
return indexError;
|
|
1039
|
+
const connections = ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput);
|
|
766
1040
|
if (!connections) {
|
|
767
1041
|
return `No connections found from "${sourceNode.name}" on output "${sourceOutput}"`;
|
|
768
1042
|
}
|
|
@@ -900,21 +1174,41 @@ class WorkflowDiffEngine {
|
|
|
900
1174
|
this.modifiedNodeIds.add(node.id);
|
|
901
1175
|
const original = this.getNestedProperty(node, operation.fieldPath);
|
|
902
1176
|
let current = original;
|
|
1177
|
+
const replacementLength = operation.patches.reduce((sum, p) => sum + p.replace.length, 0);
|
|
1178
|
+
const maxLength = original.length + replacementLength + this.patchGrowthBudget;
|
|
1179
|
+
const tooLargeError = (i) => new Error(`patchNodeField: patch index ${i} would grow "${operation.fieldPath}" beyond ${Math.round(maxLength / 1024)}KB ` +
|
|
1180
|
+
`(patches in one request may add at most ${PATCH_LIMITS.MAX_PATCH_GROWTH / 1024}KB beyond their replacement text). ` +
|
|
1181
|
+
`Use updateNode to set a large value directly.`);
|
|
903
1182
|
for (let i = 0; i < operation.patches.length; i++) {
|
|
904
1183
|
const patch = operation.patches[i];
|
|
905
1184
|
if (patch.regex) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1185
|
+
if (current.length > PATCH_LIMITS.MAX_FIELD_SIZE_REGEX) {
|
|
1186
|
+
throw new Error(`Field "${operation.fieldPath}" is too large for regex operations (${Math.round(current.length / 1024)}KB) at patch index ${i}. ` +
|
|
1187
|
+
`Maximum is ${PATCH_LIMITS.MAX_FIELD_SIZE_REGEX / 1024}KB. Use literal matching (regex: false) for large fields.`);
|
|
1188
|
+
}
|
|
1189
|
+
if (this.regexBudgetMs <= 0) {
|
|
1190
|
+
throw new Error(`patchNodeField: regex time limit for this request is used up (patch index ${i}). ` +
|
|
1191
|
+
`Use literal matching (regex: false) or split the changes across requests.`);
|
|
1192
|
+
}
|
|
1193
|
+
const timeoutMs = Math.min(PATCH_LIMITS.REGEX_EVAL_TIMEOUT_MS, this.regexBudgetMs);
|
|
1194
|
+
const startedAt = performance.now();
|
|
1195
|
+
const result = runRegexPatch(current, patch.find, patch.replace, patch.replaceAll === true, timeoutMs, maxLength);
|
|
1196
|
+
this.regexBudgetMs -= performance.now() - startedAt;
|
|
1197
|
+
if (result === 'timeout') {
|
|
1198
|
+
throw new Error(`patchNodeField: regex pattern at patch index ${i} took too long to evaluate on "${operation.fieldPath}". ` +
|
|
1199
|
+
`Simplify the pattern or use literal matching (regex: false).`);
|
|
1200
|
+
}
|
|
1201
|
+
if (result.count === 0) {
|
|
909
1202
|
throw new Error(`patchNodeField: regex pattern "${patch.find}" not found in "${operation.fieldPath}" (patch index ${i}). ` +
|
|
910
1203
|
`Use n8n_get_workflow to inspect the current value.`);
|
|
911
1204
|
}
|
|
912
|
-
if (
|
|
913
|
-
throw new Error(`patchNodeField: regex pattern "${patch.find}" matches ${
|
|
1205
|
+
if (result.count > 1 && !patch.replaceAll) {
|
|
1206
|
+
throw new Error(`patchNodeField: regex pattern "${patch.find}" matches ${result.count} times in "${operation.fieldPath}" (patch index ${i}). ` +
|
|
914
1207
|
`Set "replaceAll": true to replace all occurrences, or refine the pattern to match exactly once.`);
|
|
915
1208
|
}
|
|
916
|
-
|
|
917
|
-
|
|
1209
|
+
if (result.tooLarge)
|
|
1210
|
+
throw tooLargeError(i);
|
|
1211
|
+
current = result.output;
|
|
918
1212
|
}
|
|
919
1213
|
else {
|
|
920
1214
|
const occurrences = countOccurrences(current, patch.find);
|
|
@@ -927,11 +1221,15 @@ class WorkflowDiffEngine {
|
|
|
927
1221
|
throw new Error(`patchNodeField: "${patch.find.substring(0, 80)}" found ${occurrences} times in "${operation.fieldPath}" (patch index ${i}). ` +
|
|
928
1222
|
`Set "replaceAll": true to replace all occurrences, or use a more specific find string that matches exactly once.`);
|
|
929
1223
|
}
|
|
1224
|
+
if (current.length + occurrences * (patch.replace.length - patch.find.length) > maxLength) {
|
|
1225
|
+
throw tooLargeError(i);
|
|
1226
|
+
}
|
|
930
1227
|
current = current.split(patch.find).join(patch.replace);
|
|
931
1228
|
}
|
|
932
1229
|
}
|
|
933
1230
|
assertPatchedJsSyntax('patchNodeField', operation.fieldPath, current, original);
|
|
934
1231
|
this.setNestedProperty(node, operation.fieldPath, current);
|
|
1232
|
+
this.patchGrowthBudget -= Math.max(0, current.length - original.length - replacementLength);
|
|
935
1233
|
const sanitized = (0, node_sanitizer_1.sanitizeNode)(node);
|
|
936
1234
|
Object.assign(node, sanitized);
|
|
937
1235
|
}
|
|
@@ -1002,13 +1300,22 @@ class WorkflowDiffEngine {
|
|
|
1002
1300
|
targetInput = 'main';
|
|
1003
1301
|
}
|
|
1004
1302
|
const targetIndex = operation.targetIndex ?? 0;
|
|
1005
|
-
if (!
|
|
1006
|
-
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1303
|
+
if (!Number.isInteger(sourceIndex) || sourceIndex < 0) {
|
|
1304
|
+
throw new Error(`sourceIndex must be a non-negative integer, received ${JSON.stringify(sourceIndex)}`);
|
|
1305
|
+
}
|
|
1306
|
+
const indexError = connectionIndexError('sourceIndex', sourceIndex) ?? connectionIndexError('targetIndex', targetIndex);
|
|
1307
|
+
if (indexError)
|
|
1308
|
+
throw new Error(indexError);
|
|
1309
|
+
let nodeOutputs = ownOutputs(workflow.connections, sourceNode.name);
|
|
1310
|
+
if (!nodeOutputs) {
|
|
1311
|
+
nodeOutputs = {};
|
|
1312
|
+
workflow.connections[sourceNode.name] = nodeOutputs;
|
|
1313
|
+
}
|
|
1314
|
+
let outputArray = ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput);
|
|
1315
|
+
if (!outputArray) {
|
|
1316
|
+
outputArray = [];
|
|
1317
|
+
nodeOutputs[sourceOutput] = outputArray;
|
|
1010
1318
|
}
|
|
1011
|
-
const outputArray = workflow.connections[sourceNode.name][sourceOutput];
|
|
1012
1319
|
while (outputArray.length <= sourceIndex) {
|
|
1013
1320
|
outputArray.push([]);
|
|
1014
1321
|
}
|
|
@@ -1028,16 +1335,17 @@ class WorkflowDiffEngine {
|
|
|
1028
1335
|
return;
|
|
1029
1336
|
}
|
|
1030
1337
|
const sourceOutput = String(operation.sourceOutput ?? 'main');
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1338
|
+
const nodeOutputs = ownOutputs(workflow.connections, sourceNode.name);
|
|
1339
|
+
const connections = ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput);
|
|
1340
|
+
if (!nodeOutputs || !connections)
|
|
1033
1341
|
return;
|
|
1034
|
-
|
|
1035
|
-
|
|
1342
|
+
const outputConnections = connections.map(branch => filterBranch(branch, conn => conn.node !== targetNode.name));
|
|
1343
|
+
nodeOutputs[sourceOutput] = outputConnections;
|
|
1036
1344
|
trimTrailingEmptyBranches(outputConnections);
|
|
1037
1345
|
if (outputConnections.length === 0) {
|
|
1038
|
-
delete
|
|
1346
|
+
delete nodeOutputs[sourceOutput];
|
|
1039
1347
|
}
|
|
1040
|
-
if (Object.keys(
|
|
1348
|
+
if (Object.keys(nodeOutputs).length === 0) {
|
|
1041
1349
|
delete workflow.connections[sourceNode.name];
|
|
1042
1350
|
}
|
|
1043
1351
|
}
|
|
@@ -1058,11 +1366,11 @@ class WorkflowDiffEngine {
|
|
|
1058
1366
|
}
|
|
1059
1367
|
const { sourceOutput, sourceIndex } = this.resolveSmartParameters(workflow, operation);
|
|
1060
1368
|
const totalFromEdges = () => {
|
|
1061
|
-
const slots = workflow.connections
|
|
1369
|
+
const slots = ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput) ?? [];
|
|
1062
1370
|
return slots.reduce((acc, slot) => acc + (slot ?? []).filter(c => c.node === fromNode.name).length, 0);
|
|
1063
1371
|
};
|
|
1064
1372
|
const fromEdgesBefore = totalFromEdges();
|
|
1065
|
-
const toAlreadyPresent = (workflow.connections
|
|
1373
|
+
const toAlreadyPresent = (ownOutputSlots(workflow.connections, sourceNode.name, sourceOutput)?.[sourceIndex] ?? [])
|
|
1066
1374
|
.some(c => c.node === toNode.name);
|
|
1067
1375
|
this.applyRemoveConnection(workflow, {
|
|
1068
1376
|
type: 'removeConnection',
|
|
@@ -1283,6 +1591,9 @@ class WorkflowDiffEngine {
|
|
|
1283
1591
|
if (!Array.isArray(connections)) {
|
|
1284
1592
|
return `Connections for "${sourceName}" output "${outputName}" must be an array of output arrays, received ${describeValueType(connections)}`;
|
|
1285
1593
|
}
|
|
1594
|
+
if (connections.length > exports.MAX_CONNECTION_INDEX + 1) {
|
|
1595
|
+
return `Connections for "${sourceName}" output "${outputName}" have ${connections.length} outputs. Maximum is ${exports.MAX_CONNECTION_INDEX + 1}.`;
|
|
1596
|
+
}
|
|
1286
1597
|
for (const conns of connections) {
|
|
1287
1598
|
if (conns === null)
|
|
1288
1599
|
continue;
|
|
@@ -1296,6 +1607,9 @@ class WorkflowDiffEngine {
|
|
|
1296
1607
|
if (!nodeNames.has(conn.node)) {
|
|
1297
1608
|
return `Target node not found in connections: ${conn.node}`;
|
|
1298
1609
|
}
|
|
1610
|
+
const indexError = connectionIndexError(`Connection index from "${sourceName}" output "${outputName}"`, conn.index);
|
|
1611
|
+
if (indexError)
|
|
1612
|
+
return indexError;
|
|
1299
1613
|
}
|
|
1300
1614
|
}
|
|
1301
1615
|
}
|
|
@@ -1380,11 +1694,7 @@ class WorkflowDiffEngine {
|
|
|
1380
1694
|
return;
|
|
1381
1695
|
logger.debug(`Updating connection references for ${this.renameMap.size} renamed nodes`);
|
|
1382
1696
|
const renames = new Map(this.renameMap);
|
|
1383
|
-
const updatedConnections =
|
|
1384
|
-
for (const [sourceName, outputs] of Object.entries(workflow.connections)) {
|
|
1385
|
-
const newSourceName = renames.get(sourceName) || sourceName;
|
|
1386
|
-
updatedConnections[newSourceName] = outputs;
|
|
1387
|
-
}
|
|
1697
|
+
const updatedConnections = Object.fromEntries(Object.entries(workflow.connections).map(([sourceName, outputs]) => [renames.get(sourceName) || sourceName, outputs]));
|
|
1388
1698
|
for (const [sourceName, outputs] of Object.entries(updatedConnections)) {
|
|
1389
1699
|
for (const [outputType, connections] of Object.entries(outputs)) {
|
|
1390
1700
|
for (let outputIndex = 0; outputIndex < connections.length; outputIndex++) {
|