UNPKG

n8n-nodes-sevdesk-v2

Version:

n8n community node for SevDesk API v2 integration with 24 production-ready workflow templates. Direct API access without external dependencies - simplified, secure, and optimized for German accounting automation (n8n 1.101.1 compatible).

185 lines (184 loc) 6.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnvironmentValidationError = void 0; exports.loadEnvironmentConfig = loadEnvironmentConfig; exports.getEnvironmentConfig = getEnvironmentConfig; exports.resetEnvironmentConfig = resetEnvironmentConfig; exports.isDevelopment = isDevelopment; exports.isProduction = isProduction; exports.isStaging = isStaging; exports.isTest = isTest; exports.getEnvironmentSpecificConfig = getEnvironmentSpecificConfig; exports.getDeploymentEnvironment = getDeploymentEnvironment; exports.isDebugEnabled = isDebugEnabled; exports.getN8nConfig = getN8nConfig; exports.validateAndWarnEnvironmentConfig = validateAndWarnEnvironmentConfig; const DEFAULT_CONFIG = { n8n: { host: 'localhost', port: '5678', protocol: 'http', apiKey: undefined, apiUrl: 'http://localhost:5678/api/v1', }, nodeEnv: 'development', debug: { enabled: true, logLevel: 'info', }, docker: { installLocalNode: true, nodePath: '/sevdesk-node', }, }; const REQUIRED_ENV_VARS = []; class EnvironmentValidationError extends Error { constructor(message, missingVars = []) { super(message); this.missingVars = missingVars; this.name = 'EnvironmentValidationError'; } } exports.EnvironmentValidationError = EnvironmentValidationError; function loadEnvironmentConfig() { const missingVars = REQUIRED_ENV_VARS.filter(varName => !process.env[varName]); if (missingVars.length > 0) { throw new EnvironmentValidationError(`Missing required environment variables: ${missingVars.join(', ')}`, missingVars); } const config = { n8n: { host: process.env.N8N_HOST || DEFAULT_CONFIG.n8n.host, port: process.env.N8N_PORT || DEFAULT_CONFIG.n8n.port, protocol: process.env.N8N_PROTOCOL || DEFAULT_CONFIG.n8n.protocol, apiKey: process.env.N8N_API_KEY, apiUrl: process.env.N8N_API_URL || `${process.env.N8N_PROTOCOL || DEFAULT_CONFIG.n8n.protocol}://${process.env.N8N_HOST || DEFAULT_CONFIG.n8n.host}:${process.env.N8N_PORT || DEFAULT_CONFIG.n8n.port}/api/v1`, }, nodeEnv: process.env.NODE_ENV || DEFAULT_CONFIG.nodeEnv, debug: { enabled: process.env.NODE_ENV === 'development' || process.env.DEBUG === 'true', logLevel: process.env.LOG_LEVEL || DEFAULT_CONFIG.debug.logLevel, }, docker: { installLocalNode: process.env.INSTALL_LOCAL_SEVDESK_NODE !== 'false', nodePath: process.env.SEVDESK_NODE_PATH || DEFAULT_CONFIG.docker.nodePath, }, }; return config; } let cachedConfig = null; function getEnvironmentConfig() { if (!cachedConfig) { cachedConfig = loadEnvironmentConfig(); } return cachedConfig; } function resetEnvironmentConfig() { cachedConfig = null; } function isDevelopment() { return getEnvironmentConfig().nodeEnv === 'development'; } function isProduction() { return getEnvironmentConfig().nodeEnv === 'production'; } function isStaging() { return getEnvironmentConfig().nodeEnv === 'staging'; } function isTest() { return getEnvironmentConfig().nodeEnv === 'test'; } function getEnvironmentSpecificConfig() { const nodeEnv = getEnvironmentConfig().nodeEnv; switch (nodeEnv) { case 'production': return { debug: { enabled: false, logLevel: 'error', }, docker: { installLocalNode: false, nodePath: '/sevdesk-node', }, }; case 'staging': return { debug: { enabled: true, logLevel: 'warn', }, docker: { installLocalNode: false, nodePath: '/sevdesk-node', }, }; case 'test': return { debug: { enabled: true, logLevel: 'info', }, docker: { installLocalNode: true, nodePath: '/sevdesk-node-test', }, }; case 'development': default: return { debug: { enabled: true, logLevel: 'info', }, docker: { installLocalNode: true, nodePath: '/sevdesk-node-dev', }, }; } } function getDeploymentEnvironment() { const nodeEnv = getEnvironmentConfig().nodeEnv.toLowerCase(); if (['development', 'dev'].includes(nodeEnv)) return 'development'; if (['test', 'testing'].includes(nodeEnv)) return 'test'; if (['staging', 'stage'].includes(nodeEnv)) return 'staging'; if (['production', 'prod'].includes(nodeEnv)) return 'production'; return 'unknown'; } function isDebugEnabled() { return getEnvironmentConfig().debug.enabled; } function getN8nConfig() { return getEnvironmentConfig().n8n; } function validateAndWarnEnvironmentConfig() { try { const config = getEnvironmentConfig(); if (!config.n8n.apiKey) { console.warn('⚠️ N8N_API_KEY is not set. Some features may not work correctly.'); } if (isProduction() && config.debug.enabled) { console.warn('⚠️ Debug logging is enabled in production environment.'); } const port = parseInt(config.n8n.port, 10); if (isNaN(port) || port < 1 || port > 65535) { console.warn(`⚠️ Invalid N8N_PORT value: ${config.n8n.port}. Using default: ${DEFAULT_CONFIG.n8n.port}`); } if (!['http', 'https'].includes(config.n8n.protocol)) { console.warn(`⚠️ Invalid N8N_PROTOCOL value: ${config.n8n.protocol}. Should be 'http' or 'https'.`); } } catch (error) { if (error instanceof EnvironmentValidationError) { console.error(`❌ Environment validation failed: ${error.message}`); throw error; } console.error('❌ Unexpected error during environment validation:', error); throw error; } }