UNPKG

n8n-nodes-arubacentralnextgen

Version:

n8n community node for Aruba Central NextGen API integration with modern monitoring and management capabilities

170 lines (169 loc) 7.38 kB
"use strict"; // methods/monitoring/sites/sites.methods.ts var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllSites = getAllSites; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); const logger = __importStar(require("../../../helpers/logger")); /** * Get all sites from network monitoring */ async function getAllSites() { var _a, _b; const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting getAllSites operation', undefined, this); } try { // Get parameters from node const limit = this.getNodeParameter('limit', 0, 20); const returnAll = this.getNodeParameter('returnAll', 0, false); const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const filters = additionalFields.filters || {}; const sortOptions = additionalFields.sortOptions || ''; if (debugMode) { logger.debug('Retrieved parameters', { limit, returnAll, sortOptions, filters }, this); } // Prepare query parameters const queryParams = {}; // Build filter string based on provided options if (Object.keys(filters).length) { const filterExpressions = []; for (const [field, value] of Object.entries(filters)) { if (value !== undefined && value !== '') { if (Array.isArray(value)) { // Handle 'in' operator for arrays filterExpressions.push(`${field} in (${value.map((v) => `'${v}'`).join(',')})`); } else { // Handle 'eq' operator for single values filterExpressions.push(`${field} eq '${value}'`); } } } if (filterExpressions.length) { queryParams.filter = filterExpressions.join(' and '); if (debugMode) { logger.debug('Generated filter expression', { filter: queryParams.filter }, this); } } } // Add sort if provided if (sortOptions) { queryParams.sort = sortOptions; } const endpoint = '/network-monitoring/v1alpha1/sites-health'; // Now implement proper pagination based on the actual API response structure if (returnAll) { let allSites = []; let currentOffset = 0; let hasMore = true; let pageCount = 0; const pageSize = 100; // Maximum limit per request if (debugMode) { logger.debug('Starting pagination to retrieve all sites', undefined, this); } while (hasMore) { pageCount++; queryParams.limit = pageSize; queryParams.offset = currentOffset; if (debugMode) { logger.debug(`Fetching page ${pageCount}`, { offset: currentOffset, limit: pageSize, }, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams); if (debugMode && pageCount === 1) { logger.debug(`API response structure:`, { type: typeof response, keys: Object.keys(response || {}), count: response.count, total: response.total, itemsLength: (_a = response.items) === null || _a === void 0 ? void 0 : _a.length, }, this); } // Extract sites from the response const sites = response.items || []; if (sites.length > 0) { allSites = [...allSites, ...sites]; if (debugMode && pageCount % 5 === 0) { logger.debug(`Retrieved ${allSites.length} sites so far (page ${pageCount})`, undefined, this); } // Check if we've got all items (response.total tells us the total count) if (allSites.length >= response.total || sites.length < pageSize) { hasMore = false; } else { currentOffset += pageSize; } } else { hasMore = false; } if (debugMode && !hasMore) { logger.debug(`Pagination complete, fetched ${allSites.length} sites from ${pageCount} pages (total: ${response.total})`, undefined, this); } } // Return the aggregated results in the expected format return responseFormatter_1.formatResponse.call(this, { response: { count: allSites.length, total: allSites.length, items: allSites, offset: 0, } }); } else { // Single page request queryParams.limit = limit; queryParams.offset = 0; if (debugMode) { logger.debug(`Making single page request with limit ${limit}`, undefined, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams); if (debugMode) { logger.debug(`Retrieved ${((_b = response.items) === null || _b === void 0 ? void 0 : _b.length) || 0} sites (total available: ${response.total})`, undefined, this); } return responseFormatter_1.formatResponse.call(this, response); } } catch (error) { logger.error('Error in getAllSites', error); throw error; } }