@arathron/n8n-nodes-zoho-books
Version:
n8n community nodes for Zoho Books and Zoho Inventory API integration - Complete CRUD operations for Sales Orders, Invoices, Items, Vendors, Credit Notes, Payments, Purchase Orders, Bills, Composite Items, Tax Management, Tax Groups, and Tax Exemptions
227 lines • 7.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateTaxPercentage = validateTaxPercentage;
exports.validateTaxName = validateTaxName;
exports.validateTaxGroupName = validateTaxGroupName;
exports.validateTaxIds = validateTaxIds;
exports.validateTaxExemptionCode = validateTaxExemptionCode;
exports.validateTaxExemptionType = validateTaxExemptionType;
exports.validateTaxData = validateTaxData;
exports.validateTaxGroupData = validateTaxGroupData;
exports.validateTaxExemptionData = validateTaxExemptionData;
exports.normalizeTaxResponse = normalizeTaxResponse;
exports.normalizeTaxGroupResponse = normalizeTaxGroupResponse;
exports.normalizeTaxExemptionResponse = normalizeTaxExemptionResponse;
exports.formatTaxPercentage = formatTaxPercentage;
exports.createValidationErrorMessage = createValidationErrorMessage;
function validateTaxPercentage(percentage) {
const errors = [];
if (typeof percentage !== 'number') {
errors.push('Tax percentage must be a number');
}
else {
if (percentage < 0) {
errors.push('Tax percentage cannot be negative');
}
if (percentage > 100) {
errors.push('Tax percentage cannot exceed 100%');
}
const decimalPlaces = (percentage.toString().split('.')[1] || '').length;
if (decimalPlaces > 2) {
errors.push('Tax percentage can have at most 2 decimal places');
}
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxName(name) {
const errors = [];
if (!name || typeof name !== 'string') {
errors.push('Tax name is required and must be a string');
}
else {
const trimmed = name.trim();
if (trimmed.length === 0) {
errors.push('Tax name cannot be empty');
}
else if (trimmed.length > 100) {
errors.push('Tax name cannot exceed 100 characters');
}
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxGroupName(name) {
const errors = [];
if (!name || typeof name !== 'string') {
errors.push('Tax group name is required and must be a string');
}
else {
const trimmed = name.trim();
if (trimmed.length === 0) {
errors.push('Tax group name cannot be empty');
}
else if (trimmed.length > 100) {
errors.push('Tax group name cannot exceed 100 characters');
}
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxIds(taxIds) {
const errors = [];
if (!Array.isArray(taxIds)) {
errors.push('Tax IDs must be an array');
}
else {
if (taxIds.length === 0) {
errors.push('At least one tax ID is required');
}
else if (taxIds.length > 50) {
errors.push('Cannot include more than 50 taxes in a tax group');
}
const uniqueIds = [...new Set(taxIds)];
if (uniqueIds.length !== taxIds.length) {
errors.push('Duplicate tax IDs are not allowed in a tax group');
}
taxIds.forEach((id, index) => {
if (!id || typeof id !== 'string') {
errors.push(`Tax ID at position ${index + 1} is invalid`);
}
});
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxExemptionCode(code) {
const errors = [];
if (!code || typeof code !== 'string') {
errors.push('Tax exemption code is required and must be a string');
}
else {
const trimmed = code.trim();
if (trimmed.length === 0) {
errors.push('Tax exemption code cannot be empty');
}
else if (trimmed.length > 50) {
errors.push('Tax exemption code cannot exceed 50 characters');
}
if (!/^[A-Za-z0-9\s\-_]+$/.test(trimmed)) {
errors.push('Tax exemption code can only contain letters, numbers, spaces, hyphens, and underscores');
}
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxExemptionType(type) {
const errors = [];
const validTypes = ['customer'];
if (!type || typeof type !== 'string') {
errors.push('Tax exemption type is required and must be a string');
}
else {
const trimmed = type.trim().toLowerCase();
if (!validTypes.includes(trimmed)) {
errors.push(`Invalid tax exemption type. Supported types: ${validTypes.join(', ')}`);
}
}
return {
isValid: errors.length === 0,
errors,
};
}
function validateTaxData(data) {
const allErrors = [];
const nameValidation = validateTaxName(data.tax_name || '');
if (!nameValidation.isValid) {
allErrors.push(...nameValidation.errors);
}
if (data.tax_percentage !== undefined) {
const percentageValidation = validateTaxPercentage(data.tax_percentage);
if (!percentageValidation.isValid) {
allErrors.push(...percentageValidation.errors);
}
}
return {
isValid: allErrors.length === 0,
errors: allErrors,
};
}
function validateTaxGroupData(data) {
const allErrors = [];
const nameValidation = validateTaxGroupName(data.tax_group_name || '');
if (!nameValidation.isValid) {
allErrors.push(...nameValidation.errors);
}
if (data.tax_ids) {
const taxIdsValidation = validateTaxIds(data.tax_ids);
if (!taxIdsValidation.isValid) {
allErrors.push(...taxIdsValidation.errors);
}
}
return {
isValid: allErrors.length === 0,
errors: allErrors,
};
}
function validateTaxExemptionData(data) {
const allErrors = [];
const codeValidation = validateTaxExemptionCode(data.tax_exemption_code || '');
if (!codeValidation.isValid) {
allErrors.push(...codeValidation.errors);
}
if (data.type) {
const typeValidation = validateTaxExemptionType(data.type);
if (!typeValidation.isValid) {
allErrors.push(...typeValidation.errors);
}
}
return {
isValid: allErrors.length === 0,
errors: allErrors,
};
}
function normalizeTaxResponse(response) {
if (!response)
return null;
if (response.tax) {
return response.tax;
}
return response;
}
function normalizeTaxGroupResponse(response) {
if (!response)
return null;
if (response.tax_group) {
return response.tax_group;
}
return response;
}
function normalizeTaxExemptionResponse(response) {
if (!response)
return null;
if (response.tax_exemption) {
return response.tax_exemption;
}
return response;
}
function formatTaxPercentage(percentage) {
return `${percentage.toFixed(2)}%`;
}
function createValidationErrorMessage(result) {
if (result.isValid) {
return '';
}
return result.errors.join('. ') + '.';
}
//# sourceMappingURL=TaxUtils.js.map