@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
100 lines (96 loc) • 4.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EditionGuard = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const GenericFunctions_1 = require("./GenericFunctions");
const Cache_1 = require("./Cache");
class EditionGuard {
static CACHE_KEY_PREFIX = 'org_info_';
static CACHE_TTL = 3600_000;
static async isTaxExemptionsSupported(context) {
try {
const orgInfo = await this.getOrganizationInfo(context);
return orgInfo.is_us_edition === true;
}
catch (error) {
return false;
}
}
static async getOrganizationInfo(context) {
const credentials = await context.getCredentials('zohoBooksOAuth2');
const organizationId = credentials.organizationId;
const cacheKey = `${this.CACHE_KEY_PREFIX}${organizationId}`;
const cached = (0, Cache_1.getCached)(cacheKey);
if (cached) {
return cached;
}
try {
const response = await GenericFunctions_1.zohoApiRequest.call(context, 'GET', '/organizations', {}, {});
if (!response || !response.organizations || !Array.isArray(response.organizations)) {
throw new Error('Invalid organization response from Zoho API');
}
const organizations = response.organizations;
const currentOrg = organizations.find((org) => org.organization_id === organizationId);
if (!currentOrg) {
throw new Error(`Organization with ID ${organizationId} not found`);
}
const countryCode = currentOrg.country_code || '';
const country = (currentOrg.country || '').toLowerCase();
const isUSEdition = countryCode === 'US' || country === 'united states' || country === 'usa';
const orgInfo = {
organization_id: currentOrg.organization_id,
name: currentOrg.name || '',
country: currentOrg.country,
country_code: currentOrg.country_code,
time_zone: currentOrg.time_zone,
fiscal_year_start_month: currentOrg.fiscal_year_start_month,
date_format: currentOrg.date_format,
currency_id: currentOrg.currency_id,
currency_code: currentOrg.currency_code,
currency_symbol: currentOrg.currency_symbol,
language_code: currentOrg.language_code,
is_us_edition: isUSEdition,
};
(0, Cache_1.setCached)(cacheKey, orgInfo, this.CACHE_TTL);
return orgInfo;
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new n8n_workflow_1.NodeApiError(context.getNode(), {
message: 'Failed to retrieve organization information',
description: `Could not determine organization edition: ${errorMessage}. This is required for tax exemption functionality.`,
httpCode: '500',
});
}
}
static async requireTaxExemptionsSupport(context) {
const isSupported = await this.isTaxExemptionsSupported(context);
if (!isSupported) {
const orgInfo = await this.getOrganizationInfo(context);
const countryInfo = orgInfo.country || orgInfo.country_code || 'Unknown';
throw new n8n_workflow_1.NodeApiError(context.getNode(), {
message: 'Tax Exemptions are not available for this organization',
description: `Tax Exemptions are only available in the US edition of Zoho Books.
🔍 CURRENT ORGANIZATION:
• Country: ${countryInfo}
• Edition: ${orgInfo.is_us_edition ? 'US' : 'Non-US'}
⚠️ REQUIREMENTS:
• Organization must be in US edition
• Tax Exemptions functionality is region-locked by Zoho
💡 SOLUTIONS:
• Contact Zoho support to migrate to US edition
• Use the Tax or Tax Group resources instead for your region
📖 Reference: https://www.zoho.com/books/api/v3/taxes/#overview`,
httpCode: '400',
});
}
}
static clearCache(organizationId) {
if (organizationId) {
}
else {
}
}
}
exports.EditionGuard = EditionGuard;
//# sourceMappingURL=EditionGuard.js.map