UNPKG

n8n-nodes-tenable-community

Version:

n8n node for the Tenable One platform

43 lines (42 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handlePaginatedOperation = handlePaginatedOperation; // eslint-disable-next-line @typescript-eslint/no-explicit-any async function handlePaginatedOperation(client, operation, baseParams = {}) { const allItems = []; let offset = 0; const limit = 50; // Max limit supported by most Tenable endpoints let hasMore = true; while (hasMore) { const paramsWithPagination = Object.assign(Object.assign({}, baseParams), { offset, limit }); // eslint-disable-next-line @typescript-eslint/no-explicit-any const response = await client[operation](paramsWithPagination); // Architectural Improvement: Standardized how paginated responses are handled. // It now dynamically finds the key containing the array of results (e.g., 'assets', 'users'). const responseKey = Object.keys(response).find(key => Array.isArray(response[key])); if (responseKey && Array.isArray(response[responseKey])) { const items = response[responseKey]; if (items.length > 0) { allItems.push(...items); offset += items.length; // If the API returns fewer items than the limit, we can assume it's the last page. if (items.length < limit) { hasMore = false; } } else { // Page was empty, so we stop. hasMore = false; } } else { // If there's no array key in the response, we can't paginate further. hasMore = false; } // Additionally, stop if the API explicitly tells us we have reached the total. if (response.pagination && response.pagination.total <= allItems.length) { hasMore = false; } } return allItems; }