UNPKG

n8n-nodes-tiny-erp-api-v2

Version:

Custom nodes for Tiny ERP integration with n8n, including AI tools for AI Agent workflows

94 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = exports.description = void 0; const n8n_workflow_1 = require("n8n-workflow"); const api_1 = require("../../transport/api"); exports.description = [ { displayName: 'Action', name: 'rateLimitAction', type: 'options', options: [ { name: 'Get Rate Limit Info', value: 'getRateLimit', description: 'Get current rate limit status and remaining quota', }, { name: 'Get Cache Stats', value: 'getCacheStats', description: 'Get cache statistics and entries', }, { name: 'Clear Cache', value: 'clearCache', description: 'Clear all cached data', }, ], default: 'getRateLimit', description: 'Choose the rate limit or cache action to perform', displayOptions: { show: { resource: ['products'], operation: ['rateLimitInfo'], }, }, required: true, }, ]; async function execute(index) { const credentials = await this.getCredentials('tinyErpApi'); const api = new api_1.TinyErpApi(this, credentials); const action = this.getNodeParameter('rateLimitAction', index); try { let responseData = { success: true, operation: 'rateLimitInfo', resource: 'products', action: action, timestamp: new Date().toISOString(), }; switch (action) { case 'getRateLimit': { const rateLimitInfo = api.getRateLimitInfo(); responseData = { ...responseData, message: 'Retrieved rate limit information', rateLimitInfo: rateLimitInfo || { message: 'No rate limit information available yet. Make an API call first.', }, }; break; } case 'getCacheStats': { const cacheStats = api_1.TinyErpApi.getCacheStats(); responseData = { ...responseData, message: `Cache contains ${cacheStats.size} entries`, cacheStats: cacheStats, }; break; } case 'clearCache': { api_1.TinyErpApi.clearCache(); responseData = { ...responseData, message: 'Cache cleared successfully', cacheCleared: true, }; break; } default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown action: ${action}`); } return [{ json: responseData }]; } catch (error) { if (error instanceof n8n_workflow_1.NodeOperationError) { throw error; } throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to execute rate limit action: ${error.message}`); } } exports.execute = execute; //# sourceMappingURL=rateLimitInfo.operation.js.map