UNPKG

n8n-nodes-nocodb-self-host

Version:

Custom n8n node for Nocodb Self Host.

126 lines 5.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.App = void 0; const n8n_workflow_1 = require("n8n-workflow"); const ModuleDetails_1 = require("./ModuleDetails"); class App { constructor() { this.description = { displayName: 'Nocodb Self Host', name: 'app', icon: 'file:app.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Nocodb Self Host operations', defaults: { name: 'Nocodb Self Host', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'appCustomApi', required: false, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Action', value: 'actions', }, ], default: 'actions', }, ...ModuleDetails_1.extractNumberOperations, ...ModuleDetails_1.getRowFields, ], }; } async execute() { const items = this.getInputData(); const returnData = []; let operation; let resource; for (let i = 0; i < items.length; i++) { try { resource = this.getNodeParameter('resource', i); operation = this.getNodeParameter('operation', i); if (resource === 'actions') { if (operation === 'get-all-rows') { const nocodbToken = this.getNodeParameter('nocodb_token', i); const baseUrl = this.getNodeParameter('base_url', i); const baseIdParam = this.getNodeParameter('base_id', i); const tableIdParam = this.getNodeParameter('table_id', i); const baseId = baseIdParam; const tableId = tableIdParam; const apiUrl = `${baseUrl.replace(/\/$/, '')}/api/v1/db/data/noco/${baseId}/${tableId}`; const options = { method: 'GET', headers: { 'xc-token': nocodbToken, 'Content-Type': 'application/json', }, }; try { const response = await this.helpers.request(apiUrl, options); let rows = []; let pageInfo = null; if (Array.isArray(response)) { rows = response; } else if (response && response.list && Array.isArray(response.list)) { rows = response.list; pageInfo = response.pageInfo || null; } else { rows = [response]; } const structuredOutput = { success: true, operation: 'get-all-rows', metadata: { source: 'nocodb', baseId: baseId, tableId: tableId, timestamp: new Date().toISOString(), totalRows: rows.length, pageInfo: pageInfo }, data: rows }; returnData.push(structuredOutput); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `NocoDB API request failed: ${error.message}`, { itemIndex: i }); } } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The operation "${operation}" is not supported yet.`, { itemIndex: i }); } } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, { itemIndex: i, }); } } catch (error) { if (this.continueOnFail()) { returnData.push({ error: error.message }); continue; } throw error; } } return [this.helpers.returnJsonArray(returnData)]; } } exports.App = App; //# sourceMappingURL=App.node.js.map