mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 13:33:11 +00:00
feat: add _cnd conditional operator support and n8n 2.0+ executeWorkflowTrigger fix
Added: - Support for all 12 _cnd operators in displayOptions validation (eq, not, gte, lte, gt, lt, between, startsWith, endsWith, includes, regex, exists) - Version-based visibility checking with @version in config - 42 new unit tests for _cnd operators Fixed: - n8n 2.0+ breaking change: executeWorkflowTrigger now recognized as activatable trigger - Removed outdated validation blocking Execute Workflow Trigger workflows 🤖 Generated with [Claude Code](https://claude.com/claude-code) Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
46
dist/services/config-validator.js
vendored
46
dist/services/config-validator.js
vendored
@@ -83,6 +83,46 @@ class ConfigValidator {
|
||||
}
|
||||
return { visible, hidden };
|
||||
}
|
||||
static evaluateCondition(condition, configValue) {
|
||||
const cnd = condition._cnd;
|
||||
if ('eq' in cnd)
|
||||
return configValue === cnd.eq;
|
||||
if ('not' in cnd)
|
||||
return configValue !== cnd.not;
|
||||
if ('gte' in cnd)
|
||||
return configValue >= cnd.gte;
|
||||
if ('lte' in cnd)
|
||||
return configValue <= cnd.lte;
|
||||
if ('gt' in cnd)
|
||||
return configValue > cnd.gt;
|
||||
if ('lt' in cnd)
|
||||
return configValue < cnd.lt;
|
||||
if ('between' in cnd) {
|
||||
return configValue >= cnd.between.from && configValue <= cnd.between.to;
|
||||
}
|
||||
if ('startsWith' in cnd) {
|
||||
return typeof configValue === 'string' && configValue.startsWith(cnd.startsWith);
|
||||
}
|
||||
if ('endsWith' in cnd) {
|
||||
return typeof configValue === 'string' && configValue.endsWith(cnd.endsWith);
|
||||
}
|
||||
if ('includes' in cnd) {
|
||||
return typeof configValue === 'string' && configValue.includes(cnd.includes);
|
||||
}
|
||||
if ('regex' in cnd) {
|
||||
return typeof configValue === 'string' && new RegExp(cnd.regex).test(configValue);
|
||||
}
|
||||
if ('exists' in cnd) {
|
||||
return configValue !== undefined && configValue !== null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static valueMatches(expectedValue, configValue) {
|
||||
if (expectedValue && typeof expectedValue === 'object' && '_cnd' in expectedValue) {
|
||||
return this.evaluateCondition(expectedValue, configValue);
|
||||
}
|
||||
return configValue === expectedValue;
|
||||
}
|
||||
static isPropertyVisible(prop, config) {
|
||||
if (!prop.displayOptions)
|
||||
return true;
|
||||
@@ -90,7 +130,8 @@ class ConfigValidator {
|
||||
for (const [key, values] of Object.entries(prop.displayOptions.show)) {
|
||||
const configValue = config[key];
|
||||
const expectedValues = Array.isArray(values) ? values : [values];
|
||||
if (!expectedValues.includes(configValue)) {
|
||||
const anyMatch = expectedValues.some(expected => this.valueMatches(expected, configValue));
|
||||
if (!anyMatch) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +140,8 @@ class ConfigValidator {
|
||||
for (const [key, values] of Object.entries(prop.displayOptions.hide)) {
|
||||
const configValue = config[key];
|
||||
const expectedValues = Array.isArray(values) ? values : [values];
|
||||
if (expectedValues.includes(configValue)) {
|
||||
const anyMatch = expectedValues.some(expected => this.valueMatches(expected, configValue));
|
||||
if (anyMatch) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user