n8n-mcp 2.98.1 → 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/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 +6 -1
- package/dist/services/workflow-auto-fixer.js.map +1 -1
- package/dist/services/workflow-diff-engine.d.ts +3 -0
- package/dist/services/workflow-diff-engine.d.ts.map +1 -1
- package/dist/services/workflow-diff-engine.js +271 -21
- 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/package.json +1 -1
|
@@ -4,6 +4,14 @@ exports.NodeSpecificValidators = void 0;
|
|
|
4
4
|
const jmespath_checks_1 = require("../utils/jmespath-checks");
|
|
5
5
|
const MAX_CODE_LENGTH = 200000;
|
|
6
6
|
const MAX_SHORT_INPUT_LENGTH = 2000;
|
|
7
|
+
const JS_SPACE = /\s/;
|
|
8
|
+
const PY_LINE_BREAK = /[\n\r\u2028\u2029]/;
|
|
9
|
+
function isJsSpace(char) {
|
|
10
|
+
return char !== undefined && JS_SPACE.test(char);
|
|
11
|
+
}
|
|
12
|
+
function isWordChar(char) {
|
|
13
|
+
return char !== undefined && /\w/.test(char);
|
|
14
|
+
}
|
|
7
15
|
const MAX_PARAM_SCAN = 2000;
|
|
8
16
|
const MAX_HEADER_LINES = 50;
|
|
9
17
|
const MAX_RETURN_LOOKAHEAD = 5000;
|
|
@@ -1019,11 +1027,9 @@ class NodeSpecificValidators {
|
|
|
1019
1027
|
});
|
|
1020
1028
|
}
|
|
1021
1029
|
});
|
|
1022
|
-
const functionWithAwait = /function\s+\w*\s*\([^)]*\)\s*{[^}]*await/;
|
|
1023
|
-
const arrowWithAwait = /\([^)]*\)\s*=>\s*{[^}]*await/;
|
|
1024
1030
|
if (code.length <= MAX_CODE_LENGTH
|
|
1025
|
-
&&
|
|
1026
|
-
&&
|
|
1031
|
+
&& !code.includes('async')
|
|
1032
|
+
&& this.hasAwaitInFunctionBody(code)) {
|
|
1027
1033
|
warnings.push({
|
|
1028
1034
|
type: 'best_practice',
|
|
1029
1035
|
message: 'Using await inside a non-async function',
|
|
@@ -1041,6 +1047,76 @@ class NodeSpecificValidators {
|
|
|
1041
1047
|
});
|
|
1042
1048
|
}
|
|
1043
1049
|
}
|
|
1050
|
+
static hasAwaitInFunctionBody(code) {
|
|
1051
|
+
const finder = (needle) => {
|
|
1052
|
+
let askedFrom = Infinity;
|
|
1053
|
+
let found = -1;
|
|
1054
|
+
return (from) => {
|
|
1055
|
+
if (askedFrom <= from && (found === -1 || found >= from))
|
|
1056
|
+
return found;
|
|
1057
|
+
askedFrom = from;
|
|
1058
|
+
found = code.indexOf(needle, from);
|
|
1059
|
+
return found;
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
const paramsChecker = (arrow) => {
|
|
1063
|
+
const nextParen = finder(')');
|
|
1064
|
+
const nextBrace = finder('}');
|
|
1065
|
+
const nextAwait = finder('await');
|
|
1066
|
+
let lastClose = -1;
|
|
1067
|
+
return (openParen) => {
|
|
1068
|
+
const close = nextParen(openParen + 1);
|
|
1069
|
+
if (close === -1)
|
|
1070
|
+
return null;
|
|
1071
|
+
if (close === lastClose)
|
|
1072
|
+
return false;
|
|
1073
|
+
lastClose = close;
|
|
1074
|
+
let at = close + 1;
|
|
1075
|
+
while (isJsSpace(code[at]))
|
|
1076
|
+
at++;
|
|
1077
|
+
if (arrow) {
|
|
1078
|
+
if (code[at] !== '=' || code[at + 1] !== '>')
|
|
1079
|
+
return false;
|
|
1080
|
+
at += 2;
|
|
1081
|
+
while (isJsSpace(code[at]))
|
|
1082
|
+
at++;
|
|
1083
|
+
}
|
|
1084
|
+
if (code[at] !== '{')
|
|
1085
|
+
return false;
|
|
1086
|
+
const bodyEnd = nextBrace(at + 1);
|
|
1087
|
+
const awaitAt = nextAwait(at + 1);
|
|
1088
|
+
return awaitAt !== -1 && (bodyEnd === -1 || awaitAt < bodyEnd);
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
const checkFunction = paramsChecker(false);
|
|
1092
|
+
for (let at = code.indexOf('function'); at !== -1; at = code.indexOf('function', at + 1)) {
|
|
1093
|
+
let i = at + 8;
|
|
1094
|
+
if (!isJsSpace(code[i]))
|
|
1095
|
+
continue;
|
|
1096
|
+
while (isJsSpace(code[i]))
|
|
1097
|
+
i++;
|
|
1098
|
+
while (isWordChar(code[i]))
|
|
1099
|
+
i++;
|
|
1100
|
+
while (isJsSpace(code[i]))
|
|
1101
|
+
i++;
|
|
1102
|
+
if (code[i] !== '(')
|
|
1103
|
+
continue;
|
|
1104
|
+
const awaits = checkFunction(i);
|
|
1105
|
+
if (awaits === null)
|
|
1106
|
+
break;
|
|
1107
|
+
if (awaits)
|
|
1108
|
+
return true;
|
|
1109
|
+
}
|
|
1110
|
+
const checkArrow = paramsChecker(true);
|
|
1111
|
+
for (let at = code.indexOf('('); at !== -1; at = code.indexOf('(', at + 1)) {
|
|
1112
|
+
const awaits = checkArrow(at);
|
|
1113
|
+
if (awaits === null)
|
|
1114
|
+
break;
|
|
1115
|
+
if (awaits)
|
|
1116
|
+
return true;
|
|
1117
|
+
}
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1044
1120
|
static pythonRemovedGlobalFix(name, isEachItem) {
|
|
1045
1121
|
switch (name) {
|
|
1046
1122
|
case '_input':
|
|
@@ -1083,7 +1159,14 @@ class NodeSpecificValidators {
|
|
|
1083
1159
|
return delta;
|
|
1084
1160
|
}
|
|
1085
1161
|
static pythonTargetName(target) {
|
|
1086
|
-
const
|
|
1162
|
+
const trimmed = target.trim();
|
|
1163
|
+
let from = 0;
|
|
1164
|
+
let to = trimmed.length;
|
|
1165
|
+
while (from < to && (trimmed[from] === '(' || trimmed[from] === '[' || JS_SPACE.test(trimmed[from])))
|
|
1166
|
+
from++;
|
|
1167
|
+
while (to > from && (trimmed[to - 1] === ')' || trimmed[to - 1] === ']' || JS_SPACE.test(trimmed[to - 1])))
|
|
1168
|
+
to--;
|
|
1169
|
+
const bare = trimmed.slice(from, to).replace(/^\*+/, '').trim();
|
|
1087
1170
|
const name = bare.split(/[:=]/)[0].trim();
|
|
1088
1171
|
return /^[A-Za-z_]\w*$/.test(name) ? name : null;
|
|
1089
1172
|
}
|
|
@@ -1178,19 +1261,46 @@ class NodeSpecificValidators {
|
|
|
1178
1261
|
}
|
|
1179
1262
|
return names;
|
|
1180
1263
|
}
|
|
1264
|
+
static pythonForTarget(line, afterFor, inEnds) {
|
|
1265
|
+
let start = afterFor;
|
|
1266
|
+
while (line[start] === ' ' || line[start] === '\t')
|
|
1267
|
+
start++;
|
|
1268
|
+
if (start >= line.length || PY_LINE_BREAK.test(line[start]))
|
|
1269
|
+
return { target: null, stop: start };
|
|
1270
|
+
for (let i = start + 1; i < line.length; i++) {
|
|
1271
|
+
const char = line[i];
|
|
1272
|
+
if (PY_LINE_BREAK.test(char))
|
|
1273
|
+
return { target: null, stop: i };
|
|
1274
|
+
if (char !== ' ' && char !== '\t')
|
|
1275
|
+
continue;
|
|
1276
|
+
let runEnd = i;
|
|
1277
|
+
while (line[runEnd] === ' ' || line[runEnd] === '\t')
|
|
1278
|
+
runEnd++;
|
|
1279
|
+
if (line.startsWith('in', runEnd) && inEnds(line[runEnd + 2])) {
|
|
1280
|
+
return { target: line.slice(start, i), resume: runEnd + 2 };
|
|
1281
|
+
}
|
|
1282
|
+
i = runEnd - 1;
|
|
1283
|
+
}
|
|
1284
|
+
return { target: null, stop: line.length };
|
|
1285
|
+
}
|
|
1181
1286
|
static pythonBindingsOnLine(line) {
|
|
1182
1287
|
const names = [];
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
|
|
1288
|
+
const equals = line.indexOf('=');
|
|
1289
|
+
const newline = line.indexOf('\n');
|
|
1290
|
+
if (equals > 0 && (newline === -1 || newline > equals)
|
|
1291
|
+
&& !'=!<>+-*/%&|^~'.includes(line[equals - 1]) && line[equals + 1] !== '=') {
|
|
1292
|
+
this.pythonSplitTopLevel(line.slice(0, equals)).forEach(target => {
|
|
1186
1293
|
const name = this.pythonTargetName(target);
|
|
1187
1294
|
if (name)
|
|
1188
1295
|
names.push(name);
|
|
1189
1296
|
});
|
|
1190
1297
|
}
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
this.
|
|
1298
|
+
const forHead = /^[ \t]*(?:async[ \t]+)?for[ \t]/.exec(line);
|
|
1299
|
+
const forStatement = forHead
|
|
1300
|
+
? this.pythonForTarget(line, forHead[0].length - 1, next => next === ' ' || next === '\t')
|
|
1301
|
+
: null;
|
|
1302
|
+
if (forStatement && forStatement.target !== null) {
|
|
1303
|
+
this.pythonSplitTopLevel(forStatement.target).forEach(target => {
|
|
1194
1304
|
const name = this.pythonTargetName(target);
|
|
1195
1305
|
if (name)
|
|
1196
1306
|
names.push(name);
|
|
@@ -1213,35 +1323,23 @@ class NodeSpecificValidators {
|
|
|
1213
1323
|
}
|
|
1214
1324
|
return false;
|
|
1215
1325
|
}
|
|
1216
|
-
static
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
closers++;
|
|
1223
|
-
else if (char === '(' || char === '[' || char === '{') {
|
|
1224
|
-
if (closers === 0) {
|
|
1225
|
-
start = i;
|
|
1226
|
-
break;
|
|
1227
|
-
}
|
|
1228
|
-
closers--;
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
if (start === -1)
|
|
1232
|
-
return null;
|
|
1233
|
-
let depth = 0;
|
|
1234
|
-
for (let i = start; i < line.length; i++) {
|
|
1326
|
+
static pythonBracketGroups(line) {
|
|
1327
|
+
const openAt = new Int32Array(line.length + 1);
|
|
1328
|
+
const closeOf = new Int32Array(line.length).fill(line.length);
|
|
1329
|
+
const stack = [];
|
|
1330
|
+
for (let i = 0; i < line.length; i++) {
|
|
1331
|
+
openAt[i] = stack.length > 0 ? stack[stack.length - 1] : -1;
|
|
1235
1332
|
const char = line[i];
|
|
1236
1333
|
if (char === '(' || char === '[' || char === '{')
|
|
1237
|
-
|
|
1238
|
-
else if (char === ')' || char === ']' || char === '}')
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1334
|
+
stack.push(i);
|
|
1335
|
+
else if ((char === ')' || char === ']' || char === '}') && stack.length > 0)
|
|
1336
|
+
closeOf[stack.pop()] = i;
|
|
1337
|
+
}
|
|
1338
|
+
openAt[line.length] = stack.length > 0 ? stack[stack.length - 1] : -1;
|
|
1339
|
+
return index => {
|
|
1340
|
+
const start = openAt[index];
|
|
1341
|
+
return start === -1 ? null : { start, end: closeOf[start] };
|
|
1342
|
+
};
|
|
1245
1343
|
}
|
|
1246
1344
|
static pythonLineLocalBindings(line) {
|
|
1247
1345
|
const bindings = [];
|
|
@@ -1252,15 +1350,42 @@ class NodeSpecificValidators {
|
|
|
1252
1350
|
bindings.push({ name, ...range });
|
|
1253
1351
|
});
|
|
1254
1352
|
};
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1353
|
+
let groups = null;
|
|
1354
|
+
const enclosingGroup = (index) => (groups ?? (groups = this.pythonBracketGroups(line)))(index);
|
|
1355
|
+
let at = line.indexOf('for');
|
|
1356
|
+
while (at !== -1) {
|
|
1357
|
+
if (isWordChar(line[at - 1]) || (line[at + 3] !== ' ' && line[at + 3] !== '\t')) {
|
|
1358
|
+
at = line.indexOf('for', at + 1);
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
const head = this.pythonForTarget(line, at + 3, next => !isWordChar(next));
|
|
1362
|
+
if (head.target === null) {
|
|
1363
|
+
at = line.indexOf('for', head.stop + 1);
|
|
1364
|
+
continue;
|
|
1365
|
+
}
|
|
1366
|
+
add(head.target, enclosingGroup(at) ?? { start: at, end: line.length });
|
|
1367
|
+
at = line.indexOf('for', head.resume);
|
|
1259
1368
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1369
|
+
let newline = line.indexOf('\n');
|
|
1370
|
+
at = line.indexOf('lambda');
|
|
1371
|
+
while (at !== -1) {
|
|
1372
|
+
const after = at + 6;
|
|
1373
|
+
if (isWordChar(line[at - 1]) || isWordChar(line[after])) {
|
|
1374
|
+
at = line.indexOf('lambda', at + 1);
|
|
1375
|
+
continue;
|
|
1376
|
+
}
|
|
1377
|
+
const colon = line.indexOf(':', after);
|
|
1378
|
+
if (colon === -1)
|
|
1379
|
+
break;
|
|
1380
|
+
if (newline !== -1 && newline < after)
|
|
1381
|
+
newline = line.indexOf('\n', after);
|
|
1382
|
+
if (newline !== -1 && newline < colon) {
|
|
1383
|
+
at = line.indexOf('lambda', newline + 1);
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
const group = enclosingGroup(at);
|
|
1387
|
+
add(line.slice(after, colon), { start: at, end: group ? group.end : line.length });
|
|
1388
|
+
at = line.indexOf('lambda', colon + 1);
|
|
1264
1389
|
}
|
|
1265
1390
|
return bindings;
|
|
1266
1391
|
}
|
|
@@ -1372,24 +1497,41 @@ class NodeSpecificValidators {
|
|
|
1372
1497
|
static pythonHasUnboundReference(index, name, reference) {
|
|
1373
1498
|
const { lineScope, scopes, lineLocal, referenceText } = index;
|
|
1374
1499
|
const matcher = new RegExp(reference.source, reference.flags.includes('g') ? reference.flags : `${reference.flags}g`);
|
|
1375
|
-
|
|
1500
|
+
const resolved = new Int8Array(scopes.length);
|
|
1501
|
+
const isBound = (from) => {
|
|
1502
|
+
const path = [];
|
|
1376
1503
|
let bound = false;
|
|
1377
|
-
for (let scope =
|
|
1504
|
+
for (let scope = from; scope !== -1; scope = scopes[scope].parent) {
|
|
1505
|
+
if (resolved[scope] !== 0) {
|
|
1506
|
+
bound = resolved[scope] === 1;
|
|
1507
|
+
break;
|
|
1508
|
+
}
|
|
1509
|
+
path.push(scope);
|
|
1378
1510
|
if (scopes[scope].names.has(name)) {
|
|
1379
1511
|
bound = true;
|
|
1380
1512
|
break;
|
|
1381
1513
|
}
|
|
1382
1514
|
}
|
|
1383
|
-
|
|
1515
|
+
for (const scope of path)
|
|
1516
|
+
resolved[scope] = bound ? 1 : 2;
|
|
1517
|
+
return bound;
|
|
1518
|
+
};
|
|
1519
|
+
return referenceText.some((line, lineNumber) => {
|
|
1520
|
+
if (isBound(lineScope[lineNumber]))
|
|
1384
1521
|
return false;
|
|
1385
1522
|
matcher.lastIndex = 0;
|
|
1386
1523
|
let match;
|
|
1524
|
+
let locals = null;
|
|
1525
|
+
let next = 0;
|
|
1526
|
+
let reach = -1;
|
|
1387
1527
|
while ((match = matcher.exec(line)) !== null) {
|
|
1388
1528
|
if (match[0].length === 0)
|
|
1389
1529
|
matcher.lastIndex++;
|
|
1390
1530
|
const at = match.index;
|
|
1391
|
-
|
|
1392
|
-
|
|
1531
|
+
locals ?? (locals = lineLocal[lineNumber].filter(local => local.name === name).sort((a, b) => a.start - b.start));
|
|
1532
|
+
while (next < locals.length && locals[next].start <= at)
|
|
1533
|
+
reach = Math.max(reach, locals[next++].end);
|
|
1534
|
+
if (reach < at)
|
|
1393
1535
|
return true;
|
|
1394
1536
|
}
|
|
1395
1537
|
return false;
|
|
@@ -1643,7 +1785,13 @@ class NodeSpecificValidators {
|
|
|
1643
1785
|
continue;
|
|
1644
1786
|
const lineEnd = scan.indexOf('\n', closed);
|
|
1645
1787
|
const rest = scan.slice(closed + 1, lineEnd === -1 ? scan.length : lineEnd);
|
|
1646
|
-
|
|
1788
|
+
let restEnd = rest.length;
|
|
1789
|
+
while (restEnd > 0 && (rest[restEnd - 1] === ' ' || rest[restEnd - 1] === '\t'))
|
|
1790
|
+
restEnd--;
|
|
1791
|
+
let separatorsStart = restEnd;
|
|
1792
|
+
while (separatorsStart > 0 && rest[separatorsStart - 1] === ';')
|
|
1793
|
+
separatorsStart--;
|
|
1794
|
+
if (rest.slice(0, separatorsStart).trim() !== '')
|
|
1647
1795
|
continue;
|
|
1648
1796
|
if (!innerTest)
|
|
1649
1797
|
return true;
|
|
@@ -1657,16 +1805,17 @@ class NodeSpecificValidators {
|
|
|
1657
1805
|
const lines = code.split('\n');
|
|
1658
1806
|
const result = [];
|
|
1659
1807
|
let blockIndent = null;
|
|
1660
|
-
let
|
|
1808
|
+
let headerDepth = null;
|
|
1661
1809
|
for (const line of lines) {
|
|
1662
1810
|
const indentMatch = line.match(/^[ \t]*/);
|
|
1663
1811
|
const indent = indentMatch ? indentMatch[0].length : 0;
|
|
1664
1812
|
const isBlank = line.trim() === '';
|
|
1665
|
-
if (
|
|
1666
|
-
header += `\n${line}`;
|
|
1813
|
+
if (headerDepth !== null) {
|
|
1667
1814
|
result.push('');
|
|
1668
|
-
if (this.pythonHeaderColonIndex(
|
|
1669
|
-
|
|
1815
|
+
if (this.pythonHeaderColonIndex(line, headerDepth) !== -1)
|
|
1816
|
+
headerDepth = null;
|
|
1817
|
+
else
|
|
1818
|
+
headerDepth += this.pythonBracketDelta(line);
|
|
1670
1819
|
continue;
|
|
1671
1820
|
}
|
|
1672
1821
|
if (blockIndent !== null) {
|
|
@@ -1678,7 +1827,7 @@ class NodeSpecificValidators {
|
|
|
1678
1827
|
}
|
|
1679
1828
|
if (/^[ \t]*(?:async[ \t]+)?(?:def|class)[ \t]+\w/.test(line)) {
|
|
1680
1829
|
blockIndent = indent;
|
|
1681
|
-
|
|
1830
|
+
headerDepth = this.pythonHeaderColonIndex(line) === -1 ? this.pythonBracketDelta(line) : null;
|
|
1682
1831
|
result.push('');
|
|
1683
1832
|
continue;
|
|
1684
1833
|
}
|
|
@@ -1700,6 +1849,7 @@ class NodeSpecificValidators {
|
|
|
1700
1849
|
const templateInterpolationDepths = [];
|
|
1701
1850
|
let state = 'code';
|
|
1702
1851
|
let inRegexClass = false;
|
|
1852
|
+
const backLinks = this.javaScriptBackLinks(code);
|
|
1703
1853
|
for (let i = 0; i < code.length; i++) {
|
|
1704
1854
|
const char = code[i];
|
|
1705
1855
|
const next = code[i + 1];
|
|
@@ -1799,7 +1949,7 @@ class NodeSpecificValidators {
|
|
|
1799
1949
|
continue;
|
|
1800
1950
|
}
|
|
1801
1951
|
if (char === '{') {
|
|
1802
|
-
if (this.startsJavaScriptFunctionBody(code, i)) {
|
|
1952
|
+
if (this.startsJavaScriptFunctionBody(code, i, backLinks)) {
|
|
1803
1953
|
functionBodyDepths.push(braceDepth + 1);
|
|
1804
1954
|
}
|
|
1805
1955
|
braceDepth++;
|
|
@@ -1909,41 +2059,63 @@ class NodeSpecificValidators {
|
|
|
1909
2059
|
}
|
|
1910
2060
|
return result;
|
|
1911
2061
|
}
|
|
1912
|
-
static
|
|
1913
|
-
|
|
1914
|
-
|
|
2062
|
+
static javaScriptBackLinks(code) {
|
|
2063
|
+
let before = null;
|
|
2064
|
+
let parens = null;
|
|
2065
|
+
return {
|
|
2066
|
+
codeBefore: index => {
|
|
2067
|
+
if (before === null) {
|
|
2068
|
+
before = new Int32Array(code.length);
|
|
2069
|
+
const openers = new Int32Array(code.length);
|
|
2070
|
+
let last = -1;
|
|
2071
|
+
for (let k = 0; k < code.length; k++) {
|
|
2072
|
+
if (k >= 1 && code[k - 1] === '/' && code[k] === '*')
|
|
2073
|
+
last = k;
|
|
2074
|
+
openers[k] = last;
|
|
2075
|
+
}
|
|
2076
|
+
for (let k = 0; k < code.length; k++) {
|
|
2077
|
+
if (JS_SPACE.test(code[k])) {
|
|
2078
|
+
before[k] = k > 0 ? before[k - 1] : -1;
|
|
2079
|
+
}
|
|
2080
|
+
else if (code[k] === '/' && k > 0 && code[k - 1] === '*') {
|
|
2081
|
+
const opener = k >= 2 ? openers[k - 2] : -1;
|
|
2082
|
+
before[k] = opener >= 2 ? before[opener - 2] : -1;
|
|
2083
|
+
}
|
|
2084
|
+
else {
|
|
2085
|
+
before[k] = k;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
return index < 0 ? -1 : before[index];
|
|
2090
|
+
},
|
|
2091
|
+
matchingOpenParen: index => {
|
|
2092
|
+
if (parens === null) {
|
|
2093
|
+
parens = new Int32Array(code.length).fill(-1);
|
|
2094
|
+
const stack = [];
|
|
2095
|
+
for (let k = 0; k < code.length; k++) {
|
|
2096
|
+
if (code[k] === '(')
|
|
2097
|
+
stack.push(k);
|
|
2098
|
+
else if (code[k] === ')' && stack.length > 0)
|
|
2099
|
+
parens[k] = stack.pop();
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return parens[index];
|
|
2103
|
+
},
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
static startsJavaScriptFunctionBody(code, openBraceIndex, links) {
|
|
2107
|
+
const arrowFloor = Math.max(0, openBraceIndex - 500);
|
|
2108
|
+
let arrowEnd = openBraceIndex - 1;
|
|
2109
|
+
while (arrowEnd >= arrowFloor && JS_SPACE.test(code[arrowEnd]))
|
|
2110
|
+
arrowEnd--;
|
|
2111
|
+
if (arrowEnd - 1 >= arrowFloor && code[arrowEnd] === '>' && code[arrowEnd - 1] === '=')
|
|
1915
2112
|
return true;
|
|
1916
|
-
|
|
1917
|
-
while (i >= 0) {
|
|
1918
|
-
if (/\s/.test(code[i])) {
|
|
1919
|
-
i--;
|
|
1920
|
-
continue;
|
|
1921
|
-
}
|
|
1922
|
-
if (code[i] === '/' && i > 0 && code[i - 1] === '*') {
|
|
1923
|
-
i -= 2;
|
|
1924
|
-
while (i >= 1 && !(code[i - 1] === '/' && code[i] === '*'))
|
|
1925
|
-
i--;
|
|
1926
|
-
i -= 2;
|
|
1927
|
-
continue;
|
|
1928
|
-
}
|
|
1929
|
-
break;
|
|
1930
|
-
}
|
|
2113
|
+
const i = links.codeBefore(openBraceIndex - 1);
|
|
1931
2114
|
if (i < 0 || code[i] !== ')')
|
|
1932
2115
|
return false;
|
|
1933
2116
|
const scanFloor = Math.max(0, i - MAX_PARAM_SCAN);
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
for (; j >= scanFloor; j--) {
|
|
1937
|
-
const c = code[j];
|
|
1938
|
-
if (c === ')')
|
|
1939
|
-
depth++;
|
|
1940
|
-
else if (c === '(') {
|
|
1941
|
-
depth--;
|
|
1942
|
-
if (depth === 0)
|
|
1943
|
-
break;
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
if (depth !== 0)
|
|
2117
|
+
const j = links.matchingOpenParen(i);
|
|
2118
|
+
if (j === -1 || j < scanFloor)
|
|
1947
2119
|
return false;
|
|
1948
2120
|
const head = code.slice(Math.max(0, j - 60), j);
|
|
1949
2121
|
if (/(?:^|[^\w$])(?:async\s+)?function\s*\*?(?:\s+[\w$]+)?\s*$/.test(head))
|
|
@@ -2156,11 +2328,10 @@ class NodeSpecificValidators {
|
|
|
2156
2328
|
}
|
|
2157
2329
|
const fsModuleUsagePatterns = [
|
|
2158
2330
|
/require\s*\(\s*['"`](?:node:)?(?:fs|path|child_process)['"`]\s*\)/,
|
|
2159
|
-
/\bimport\b[^;\n]*\bfrom\s*['"](?:node:)?(?:fs|path|child_process)['"]/,
|
|
2160
2331
|
/\bimport\s*\(\s*['"`](?:node:)?(?:fs|path|child_process)['"`]\s*\)/,
|
|
2161
2332
|
/(?<![.\w$])(?:fs|child_process)\s*\.\s*\w/
|
|
2162
2333
|
];
|
|
2163
|
-
if (fsModuleUsagePatterns.some(pattern => pattern.test(code))) {
|
|
2334
|
+
if (fsModuleUsagePatterns.some(pattern => pattern.test(code)) || this.importsFromFsModule(code)) {
|
|
2164
2335
|
warnings.push({
|
|
2165
2336
|
type: 'security',
|
|
2166
2337
|
message: 'File system and process access not available in Code nodes',
|
|
@@ -2168,6 +2339,20 @@ class NodeSpecificValidators {
|
|
|
2168
2339
|
});
|
|
2169
2340
|
}
|
|
2170
2341
|
}
|
|
2342
|
+
static importsFromFsModule(code) {
|
|
2343
|
+
const token = /\bimport\b|[;\n]|\bfrom\s*['"](?:node:)?(?:fs|path|child_process)['"]/g;
|
|
2344
|
+
let inImport = false;
|
|
2345
|
+
let match;
|
|
2346
|
+
while ((match = token.exec(code)) !== null) {
|
|
2347
|
+
if (match[0] === ';' || match[0] === '\n')
|
|
2348
|
+
inImport = false;
|
|
2349
|
+
else if (match[0] === 'import')
|
|
2350
|
+
inImport = true;
|
|
2351
|
+
else if (inImport)
|
|
2352
|
+
return true;
|
|
2353
|
+
}
|
|
2354
|
+
return false;
|
|
2355
|
+
}
|
|
2171
2356
|
static validateSet(context) {
|
|
2172
2357
|
const { config, errors, warnings } = context;
|
|
2173
2358
|
const jsonOutputIsExpression = typeof config.jsonOutput === 'string'
|