UNPKG

@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

84 lines 4.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaxResource = void 0; const GenericFunctions_1 = require("../utils/GenericFunctions"); const TaxUtils_1 = require("../utils/TaxUtils"); const Cache_1 = require("../utils/Cache"); class TaxResource { resourceName = 'Tax'; endpoint = '/settings/taxes'; async create(executeFunctions, itemIndex, additionalFields) { const taxName = executeFunctions.getNodeParameter('taxName', itemIndex); const taxPercentage = executeFunctions.getNodeParameter('taxPercentage', itemIndex); const params = { tax_name: taxName, tax_percentage: taxPercentage, ...additionalFields, }; const validation = (0, TaxUtils_1.validateTaxData)(params); if (!validation.isValid) { throw new Error(`Invalid tax data: ${(0, TaxUtils_1.createValidationErrorMessage)(validation)}`); } const body = { JSONString: JSON.stringify(params), }; const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'POST', this.endpoint, body); const credentials = await executeFunctions.getCredentials('zohoBooksOAuth2'); const organizationId = credentials.organizationId; (0, Cache_1.delCachedPattern)(`taxes:${organizationId}*`); return (0, TaxUtils_1.normalizeTaxResponse)(response?.tax); } async get(executeFunctions, itemIndex, _additionalFields) { const taxId = executeFunctions.getNodeParameter('taxId', itemIndex); const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'GET', `${this.endpoint}/${taxId}`); return (0, TaxUtils_1.normalizeTaxResponse)(response?.tax); } async getAll(executeFunctions, itemIndex, _additionalFields) { const returnAll = executeFunctions.getNodeParameter('returnAll', itemIndex); const limit = executeFunctions.getNodeParameter('limit', itemIndex, 50); const page = executeFunctions.getNodeParameter('page', itemIndex, 1); const perPage = executeFunctions.getNodeParameter('perPage', itemIndex, 50); const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'GET', this.endpoint, {}, { page, per_page: returnAll ? 200 : Math.min(perPage, 200), }); if (returnAll) { return GenericFunctions_1.zohoApiRequestAllItems.call(executeFunctions, 'GET', this.endpoint, {}, {}); } else { const taxes = response?.taxes || []; return taxes.slice(0, limit); } } async update(executeFunctions, itemIndex, _additionalFields) { const taxId = executeFunctions.getNodeParameter('taxId', itemIndex); const updateFields = executeFunctions.getNodeParameter('updateFields', itemIndex, {}); if (Object.keys(updateFields).length > 0) { const validation = (0, TaxUtils_1.validateTaxData)(updateFields); if (!validation.isValid) { throw new Error(`Invalid tax update data: ${(0, TaxUtils_1.createValidationErrorMessage)(validation)}`); } } const body = { JSONString: JSON.stringify(updateFields), }; const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'PUT', `${this.endpoint}/${taxId}`, body); const credentials = await executeFunctions.getCredentials('zohoBooksOAuth2'); const organizationId = credentials.organizationId; (0, Cache_1.delCachedPattern)(`taxes:${organizationId}*`); return (0, TaxUtils_1.normalizeTaxResponse)(response?.tax); } async delete(executeFunctions, itemIndex, _additionalFields) { const taxId = executeFunctions.getNodeParameter('taxId', itemIndex); const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'DELETE', `${this.endpoint}/${taxId}`); const credentials = await executeFunctions.getCredentials('zohoBooksOAuth2'); const organizationId = credentials.organizationId; (0, Cache_1.delCachedPattern)(`taxes:${organizationId}*`); return response; } async list(executeFunctions, _itemIndex, _additionalFields) { return GenericFunctions_1.zohoApiRequestAllItems.call(executeFunctions, 'GET', this.endpoint, {}, {}); } } exports.TaxResource = TaxResource; //# sourceMappingURL=Tax.resource.js.map