UNPKG

n8n-nodes-tiny-erp-api-v2

Version:

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

99 lines 4.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TinyErp = void 0; const n8n_workflow_1 = require("n8n-workflow"); const actions_1 = require("./actions"); class TinyErp { constructor() { this.description = { displayName: 'Tiny ERP', name: 'tinyErp', icon: 'file:capi_ico.png', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with Tiny ERP API to manage products, orders, and users. Use this tool when you need to retrieve or manage ERP data.', defaults: { name: 'Tiny ERP', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'tinyErpApi', required: true, }, ], usableAsTool: true, properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: actions_1.allResources, default: 'products', }, ...actions_1.allOperations, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { let executionResult = []; if (resource === 'products' && operation === 'getProducts') { executionResult = await actions_1.productsOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'getStock') { executionResult = await actions_1.getStockOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'createProduct') { executionResult = await actions_1.createProductOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'createProductsBatch') { executionResult = await actions_1.createProductsBatchOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'updateStock') { executionResult = await actions_1.updateStockOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'updateStockBatch') { executionResult = await actions_1.updateStockBatchOperations.execute.call(this, i); } else if (resource === 'products' && operation === 'rateLimitInfo') { executionResult = await actions_1.rateLimitInfoOperations.execute.call(this, i); } else if (resource === 'orders' && operation === 'getOrderData') { executionResult = await actions_1.ordersOperations.execute.call(this, i); } else if (resource === 'users' && operation === 'getUserData') { executionResult = await actions_1.usersOperations.execute.call(this, i); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The operation "${operation}" is not supported for resource "${resource}"`); } returnData.push(...executionResult); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, resource, operation, }, }); continue; } throw error; } } return [returnData]; } } exports.TinyErp = TinyErp; //# sourceMappingURL=TinyErp.node.js.map