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

96 lines 5.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaxExemptionResource = void 0; const GenericFunctions_1 = require("../utils/GenericFunctions"); const TaxUtils_1 = require("../utils/TaxUtils"); const EditionGuard_1 = require("../utils/EditionGuard"); const Cache_1 = require("../utils/Cache"); class TaxExemptionResource { resourceName = 'Tax Exemption'; endpoint = '/settings/taxexemptions'; async validateEditionSupport(executeFunctions) { await EditionGuard_1.EditionGuard.requireTaxExemptionsSupport(executeFunctions); } async create(executeFunctions, itemIndex, additionalFields) { await this.validateEditionSupport(executeFunctions); const taxExemptionCode = executeFunctions.getNodeParameter('taxExemptionCode', itemIndex); const description = executeFunctions.getNodeParameter('description', itemIndex, ''); const type = executeFunctions.getNodeParameter('type', itemIndex, 'customer'); const params = { tax_exemption_code: taxExemptionCode, description: description || undefined, type, ...additionalFields, }; const validation = (0, TaxUtils_1.validateTaxExemptionData)(params); if (!validation.isValid) { throw new Error(`Invalid tax exemption 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)(`taxexemptions:${organizationId}*`); return (0, TaxUtils_1.normalizeTaxExemptionResponse)(response?.tax_exemption); } async get(executeFunctions, itemIndex, _additionalFields) { await this.validateEditionSupport(executeFunctions); const taxExemptionId = executeFunctions.getNodeParameter('taxExemptionId', itemIndex); const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'GET', `${this.endpoint}/${taxExemptionId}`); return (0, TaxUtils_1.normalizeTaxExemptionResponse)(response?.tax_exemption); } async getAll(executeFunctions, itemIndex, _additionalFields) { await this.validateEditionSupport(executeFunctions); 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 taxExemptions = response?.tax_exemptions || response?.taxexemptions || []; return taxExemptions.slice(0, limit); } } async update(executeFunctions, itemIndex, _additionalFields) { await this.validateEditionSupport(executeFunctions); const taxExemptionId = executeFunctions.getNodeParameter('taxExemptionId', itemIndex); const updateFields = executeFunctions.getNodeParameter('updateFields', itemIndex, {}); if (Object.keys(updateFields).length > 0) { const validation = (0, TaxUtils_1.validateTaxExemptionData)(updateFields); if (!validation.isValid) { throw new Error(`Invalid tax exemption update data: ${(0, TaxUtils_1.createValidationErrorMessage)(validation)}`); } } const body = { JSONString: JSON.stringify(updateFields), }; const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'PUT', `${this.endpoint}/${taxExemptionId}`, body); const credentials = await executeFunctions.getCredentials('zohoBooksOAuth2'); const organizationId = credentials.organizationId; (0, Cache_1.delCachedPattern)(`taxexemptions:${organizationId}*`); return (0, TaxUtils_1.normalizeTaxExemptionResponse)(response?.tax_exemption); } async delete(executeFunctions, itemIndex, _additionalFields) { await this.validateEditionSupport(executeFunctions); const taxExemptionId = executeFunctions.getNodeParameter('taxExemptionId', itemIndex); const response = await GenericFunctions_1.zohoApiRequest.call(executeFunctions, 'DELETE', `${this.endpoint}/${taxExemptionId}`); const credentials = await executeFunctions.getCredentials('zohoBooksOAuth2'); const organizationId = credentials.organizationId; (0, Cache_1.delCachedPattern)(`taxexemptions:${organizationId}*`); return response; } async list(executeFunctions, _itemIndex, _additionalFields) { await this.validateEditionSupport(executeFunctions); return GenericFunctions_1.zohoApiRequestAllItems.call(executeFunctions, 'GET', this.endpoint, {}, {}); } } exports.TaxExemptionResource = TaxExemptionResource; //# sourceMappingURL=TaxExemption.resource.js.map