Critical fixes based on Claude Desktop feedback:
1. Fixed crypto documentation: require('crypto') IS available despite editor warnings
- Added clear examples of crypto usage
- Updated validation to guide correct require() usage
2. Clarified $helpers vs standalone functions
- $getWorkflowStaticData() is standalone, NOT $helpers.getWorkflowStaticData()
- Added validation to catch incorrect usage (prevents '$helpers is not defined' errors)
- Enhanced examples showing proper $helpers availability checks
3. Fixed JMESPath numeric literal documentation
- n8n requires backticks around numbers in filters: [?age >= `18`]
- Added multiple examples and validation to detect missing backticks
- Prevents 'JMESPath syntax error' that Claude Desktop encountered
4. Fixed webhook data access gotcha
- Webhook payload is at items[0].json.body, NOT items[0].json
- Added dedicated 'Webhook Data Access' section with clear examples
- Created process_webhook_data task template
- Added validation to detect incorrect webhook data access patterns
All fixes based on production workflows TaNqYoZNNeHC4Hne and JZ9urD7PNClDZ1bm
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
|
|
import { EnhancedConfigValidator } from '../src/services/enhanced-config-validator.js';
|
|
|
|
console.log('🧪 Testing $helpers Validation\n');
|
|
|
|
const testCases = [
|
|
{
|
|
name: 'Incorrect $helpers.getWorkflowStaticData',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `const data = $helpers.getWorkflowStaticData('global');
|
|
data.counter = 1;
|
|
return [{json: {counter: data.counter}}];`
|
|
}
|
|
},
|
|
{
|
|
name: 'Correct $getWorkflowStaticData',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `const data = $getWorkflowStaticData('global');
|
|
data.counter = 1;
|
|
return [{json: {counter: data.counter}}];`
|
|
}
|
|
},
|
|
{
|
|
name: '$helpers without check',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `const response = await $helpers.httpRequest({
|
|
method: 'GET',
|
|
url: 'https://api.example.com'
|
|
});
|
|
return [{json: response}];`
|
|
}
|
|
},
|
|
{
|
|
name: '$helpers with proper check',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `if (typeof $helpers !== 'undefined' && $helpers.httpRequest) {
|
|
const response = await $helpers.httpRequest({
|
|
method: 'GET',
|
|
url: 'https://api.example.com'
|
|
});
|
|
return [{json: response}];
|
|
}
|
|
return [{json: {error: 'HTTP not available'}}];`
|
|
}
|
|
},
|
|
{
|
|
name: 'Crypto without require',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `const token = crypto.randomBytes(32).toString('hex');
|
|
return [{json: {token}}];`
|
|
}
|
|
},
|
|
{
|
|
name: 'Crypto with require',
|
|
config: {
|
|
language: 'javaScript',
|
|
jsCode: `const crypto = require('crypto');
|
|
const token = crypto.randomBytes(32).toString('hex');
|
|
return [{json: {token}}];`
|
|
}
|
|
}
|
|
];
|
|
|
|
for (const test of testCases) {
|
|
console.log(`Test: ${test.name}`);
|
|
const result = EnhancedConfigValidator.validateWithMode(
|
|
'nodes-base.code',
|
|
test.config,
|
|
[
|
|
{ name: 'language', type: 'options', options: ['javaScript', 'python'] },
|
|
{ name: 'jsCode', type: 'string' }
|
|
],
|
|
'operation',
|
|
'ai-friendly'
|
|
);
|
|
|
|
console.log(` Valid: ${result.valid}`);
|
|
if (result.errors.length > 0) {
|
|
console.log(` Errors: ${result.errors.map(e => e.message).join(', ')}`);
|
|
}
|
|
if (result.warnings.length > 0) {
|
|
console.log(` Warnings: ${result.warnings.map(w => w.message).join(', ')}`);
|
|
}
|
|
console.log();
|
|
}
|
|
|
|
console.log('✅ $helpers validation tests completed!'); |