UNPKG

n8n-nodes-smartsuite

Version:
52 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const utils_1 = require("../../helpers/utils"); const smartSuiteApi_1 = require("../../transport/smartSuiteApi"); const validation_1 = require("../../helpers/validation"); async function execute() { const solutionId = await validation_1.getSolutionId.call(this, 0); const tableId = await validation_1.getTableId.call(this, 0); (0, utils_1.debugLog)('[Record] listRecord.execute called', this.getNode().parameters, 2); const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const hydrated = this.getNodeParameter('hydrated', i); const returnAll = this.getNodeParameter('returnAll', i); const limit = returnAll ? undefined : this.getNodeParameter('limit', i); (0, utils_1.debugLog)('[Record] listRecord.request', { solutionId, tableId, hydrated, returnAll, limit }, 2); let recordsArray = []; try { const body = { hydrated }; if (returnAll) { // fetch all pages recordsArray = await smartSuiteApi_1.paginatedRequest.call(this, 'POST', `/applications/${tableId}/records/list/`, body); returnData.push(...this.helpers.returnJsonArray(recordsArray)); continue; } // single‐page case body.limit = limit; const resp = (await smartSuiteApi_1.apiRequest.call(this, 'POST', `/applications/${tableId}/records/list/`, body)); if (Array.isArray(resp)) { recordsArray = resp; } else if (resp && typeof resp === 'object') { recordsArray = resp.data ?? resp.items ?? resp.results ?? []; } // enforce client‐side limit if (limit !== undefined && recordsArray.length > limit) { const sliced = recordsArray.slice(0, limit); returnData.push(...this.helpers.returnJsonArray(sliced)); } else { returnData.push(...this.helpers.returnJsonArray(recordsArray)); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message, { itemIndex: i }); } } return returnData; } //# sourceMappingURL=listRecord.operation.js.map