n8n-nodes-surprise-dev
Version:
🎪 Magic node with universal instance support and mysterious features
284 lines (283 loc) • 13.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SurpriseDev = void 0;
class SurpriseDev {
constructor() {
this.description = {
displayName: 'Surprise Dev',
name: 'surpriseDev',
icon: 'fa:gift',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["authentication"] === "none" ? "🔓 Open" : "🔐 Protected"}} - {{$parameter["secretCode"] ? "🔮 Enhanced" : "🎯 Standard"}}',
description: '🎪 Magic node for creating surprise workflows with universal instance support',
defaults: {
name: 'Surprise Dev',
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [],
properties: [
{
displayName: '🔐 Authentication Method',
name: 'authentication',
type: 'options',
options: [
{
name: 'None (Recommended)',
value: 'none',
description: 'No authentication required - works with public endpoint',
},
{
name: 'Basic Auth',
value: 'basicAuth',
description: 'Use Basic Authentication if required',
},
],
default: 'none',
description: 'Choose authentication method',
},
{
displayName: '👤 Username',
name: 'username',
type: 'string',
displayOptions: {
show: {
authentication: ['basicAuth'],
},
},
default: '',
placeholder: 'Enter username',
description: 'Username for Basic Authentication',
},
{
displayName: '🔑 Password',
name: 'password',
type: 'string',
typeOptions: {
password: true,
},
displayOptions: {
show: {
authentication: ['basicAuth'],
},
},
default: '',
placeholder: 'Enter password',
description: 'Password for Basic Authentication',
},
{
displayName: '🏠 Your Instance URL',
name: 'instanceUrl',
type: 'string',
required: true,
default: '',
placeholder: 'https://your-instance.com',
description: '🌐 URL of your instance (where your API key was created)',
typeOptions: {
rows: 1,
},
},
{
displayName: '🎯 User API Key',
name: 'userApiKey',
type: 'string',
required: true,
default: '',
placeholder: 'Your personal API key',
description: '🔑 API key from your Settings → API Keys (REQUIRED)',
typeOptions: {
password: true,
},
},
{
displayName: '🎭 Secret Code',
name: 'secretCode',
type: 'string',
default: '',
placeholder: 'Enter your secret code if you have one...',
description: '🔮 Special code to unlock hidden features (optional)',
},
{
displayName: '📅 Week Number',
name: 'weekNumber',
type: 'number',
default: 0,
description: 'Week number (0 for automatic calculation)',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const userApiKey = this.getNodeParameter('userApiKey', i);
const instanceUrl = this.getNodeParameter('instanceUrl', i);
const secretCode = this.getNodeParameter('secretCode', i);
const weekNumber = this.getNodeParameter('weekNumber', i);
const authentication = this.getNodeParameter('authentication', i);
// Validate instance URL
if (!instanceUrl || instanceUrl.trim().length < 10) {
returnData.push({
json: {
success: false,
error: '🏠 Instance URL required',
instructions: {
message: '🌐 Please provide your instance URL',
step1: 'Enter the full URL of your instance',
step2: 'Format: https://your-instance.com',
step3: 'This should be where you created your API key',
step4: 'Do not include /api/v1/workflows at the end'
},
donation_info: {
message: '💝 Support Surprise Dev development!',
ethereum_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667',
accepted_cryptos: ['ETH', 'USDT', 'USDC', 'BTC'],
impact: '🎪 Your support enables universal compatibility!'
}
}
});
continue;
}
// Clean and validate URL
let cleanInstanceUrl = instanceUrl.trim();
if (!cleanInstanceUrl.startsWith('http://') && !cleanInstanceUrl.startsWith('https://')) {
cleanInstanceUrl = 'https://' + cleanInstanceUrl;
}
cleanInstanceUrl = cleanInstanceUrl.replace(/\/+$/, '');
cleanInstanceUrl = cleanInstanceUrl.replace(/\/api.*$/, '');
// Validate API key
if (!userApiKey || userApiKey.length < 15) {
returnData.push({
json: {
success: false,
error: '🔑 Invalid or missing API key',
instructions: {
message: '🎭 Please provide your API key',
step1: `Go to ${cleanInstanceUrl} → Settings → API Keys`,
step2: 'Create a new API key with workflow permissions',
step3: 'Copy it to the User API Key field',
step4: 'Re-execute the workflow'
},
donation_info: {
message: '💝 Support magical development!',
ethereum_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667'
}
}
});
continue;
}
// Prepare headers
const headers = {
'Content-Type': 'application/json',
'User-Agent': 'n8n-nodes-surprise-dev/1.0.8-universal',
'X-Magic-Source': 'surprise-dev-community',
'X-User-Instance': cleanInstanceUrl,
'X-Auth-Method': authentication
};
// Handle Basic Auth
if (authentication === 'basicAuth') {
const username = this.getNodeParameter('username', i);
const password = this.getNodeParameter('password', i);
if (username && password) {
const credentials = Buffer.from(`${username}:${password}`).toString('base64');
headers['Authorization'] = `Basic ${credentials}`;
}
else {
returnData.push({
json: {
success: false,
error: '🔐 Authentication method selected but credentials missing',
suggestion: 'Switch to "None" for standard access',
donation_info: {
message: '💝 Support development!',
ethereum_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667'
}
}
});
continue;
}
}
// Calculate current week
const currentWeek = weekNumber || Math.ceil(((new Date().getTime() - new Date(new Date().getFullYear(), 0, 1).getTime()) / 86400000 + 1) / 7);
// Prepare payload
const payload = {
user_api_key: userApiKey,
secret_code: secretCode,
week_number: currentWeek,
timestamp: new Date().toISOString(),
node_version: '1.0.8',
authentication_method: authentication,
user_instance_url: cleanInstanceUrl,
magic_signature: 'surprise_dev_universal'
};
// Make request to webhook
const response = await this.helpers.request({
method: 'POST',
url: 'https://n8n.srv740722.hstgr.cloud/webhook/superdevcestmortel',
body: payload,
json: true,
headers: headers,
timeout: 30000,
});
// Process response
if (response && typeof response === 'object') {
returnData.push({
json: {
...response,
magic_execution: {
node_version: '1.0.8-universal',
user_instance: cleanInstanceUrl,
timestamp: new Date().toISOString(),
authentication_method: authentication,
secret_code_used: secretCode ? 'provided' : 'none',
week_number: currentWeek,
magic_level: secretCode ? 'enhanced' : 'standard',
surprise_factor: '🎪 Maximum!',
universal_compatibility: true,
donation_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667'
}
}
});
}
else {
returnData.push({
json: {
success: false,
error: '🔮 Response processing failed',
raw_response: response,
donation_info: {
message: '🆘 Issues? Support the project!',
ethereum_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667'
}
}
});
}
}
catch (error) {
returnData.push({
json: {
success: false,
error: error.message || '🎭 Unknown magical error occurred',
magic_troubleshooting: {
step1: '🌐 Check your internet connection',
step2: '🔑 Verify your API key is valid',
step3: '🏠 Ensure your instance URL is correct',
step4: '🔮 Try different approaches if you know any',
step5: '💬 Join @magicshown8n for community support'
},
donation_info: {
message: '💝 Support magical development!',
ethereum_address: '0xfb1f5190Dd2498Cd25Db95d6b23C7145bc14E667',
impact: '🎪 Your donations help improve universal compatibility!'
}
}
});
}
}
return [returnData];
}
}
exports.SurpriseDev = SurpriseDev;