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).

204 lines (203 loc) 7.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResourceValidator = exports.GermanBusinessValidator = void 0; class GermanBusinessValidator { static validateVATNumber(vatNumber) { const germanVATPattern = /^DE\d{9}$/; return germanVATPattern.test(vatNumber); } static validatePostalCode(postalCode) { const postalCodePattern = /^\d{5}$/; return postalCodePattern.test(postalCode); } static validatePhoneNumber(phoneNumber) { const phonePattern = /^(\+49|0)[1-9]\d{1,14}$/; return phonePattern.test(phoneNumber.replace(/[\s\-\(\)]/g, '')); } static validateIBAN(iban) { const germanIBANPattern = /^DE\d{20}$/; return germanIBANPattern.test(iban.replace(/\s/g, '')); } static validateTaxNumber(taxNumber) { const taxNumberPattern = /^\d{2,3}\/\d{3}\/\d{5}$/; return taxNumberPattern.test(taxNumber); } } exports.GermanBusinessValidator = GermanBusinessValidator; class ResourceValidator { static registerSchema(schema) { const schemas = this.validationSchemas.get(schema.resource) || []; const filteredSchemas = schemas.filter(s => s.operation !== schema.operation); filteredSchemas.push(schema); this.validationSchemas.set(schema.resource, filteredSchemas); } static getSchema(resource, operation) { const schemas = this.validationSchemas.get(resource); if (!schemas) return null; return schemas.find(s => s.operation === operation) || null; } static validate(data, resource, operation) { const schema = this.getSchema(resource, operation); if (!schema) { return { isValid: true, errors: [] }; } const errors = []; for (const rule of schema.rules) { const value = data[rule.field]; const error = this.validateField(rule.field, value, rule); if (error) { errors.push(error); } } return { isValid: errors.length === 0, errors, }; } static validateField(field, value, rule) { if (rule.type === 'required' && (value === undefined || value === null || value === '')) { return { field, message: rule.message || `Field '${field}' is required`, value, }; } if (value === undefined || value === null || value === '') { return null; } switch (rule.type) { case 'string': if (typeof value !== 'string') { return { field, message: rule.message || `Field '${field}' must be a string`, value, }; } break; case 'number': if (typeof value !== 'number' || isNaN(value)) { return { field, message: rule.message || `Field '${field}' must be a number`, value, }; } break; case 'email': const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailPattern.test(value)) { return { field, message: rule.message || `Field '${field}' must be a valid email address`, value, }; } break; case 'date': const date = new Date(value); if (isNaN(date.getTime())) { return { field, message: rule.message || `Field '${field}' must be a valid date`, value, }; } break; case 'boolean': if (typeof value !== 'boolean') { return { field, message: rule.message || `Field '${field}' must be a boolean`, value, }; } break; case 'array': if (!Array.isArray(value)) { return { field, message: rule.message || `Field '${field}' must be an array`, value, }; } break; case 'object': if (typeof value !== 'object' || Array.isArray(value)) { return { field, message: rule.message || `Field '${field}' must be an object`, value, }; } break; case 'custom': if (rule.validator && !rule.validator(value)) { return { field, message: rule.message || `Field '${field}' failed custom validation`, value, }; } break; case 'allowedValues': if (rule.allowedValues && !rule.allowedValues.includes(value)) { return { field, message: rule.message || `Field '${field}' must be one of: ${rule.allowedValues.join(', ')}`, value, }; } break; } if (typeof value === 'string') { if (rule.minLength !== undefined && value.length < rule.minLength) { return { field, message: rule.message || `Field '${field}' must be at least ${rule.minLength} characters long`, value, }; } if (rule.maxLength !== undefined && value.length > rule.maxLength) { return { field, message: rule.message || `Field '${field}' must be at most ${rule.maxLength} characters long`, value, }; } } if (typeof value === 'number') { if (rule.min !== undefined && value < rule.min) { return { field, message: rule.message || `Field '${field}' must be at least ${rule.min}`, value, }; } if (rule.max !== undefined && value > rule.max) { return { field, message: rule.message || `Field '${field}' must be at most ${rule.max}`, value, }; } } if (rule.pattern && typeof value === 'string' && !rule.pattern.test(value)) { return { field, message: rule.message || `Field '${field}' does not match the required pattern`, value, }; } return null; } static getAllSchemas() { return new Map(this.validationSchemas); } static clearSchemas() { this.validationSchemas.clear(); } } exports.ResourceValidator = ResourceValidator; ResourceValidator.validationSchemas = new Map();