UNPKG

n8n-nodes-arubacentralnextgen

Version:

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

382 lines (381 loc) 14.8 kB
"use strict"; // methods/networkServices/networkServices.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.getAllDHCP = getAllDHCP; exports.getDHCP = getDHCP; exports.createDHCP = createDHCP; exports.updateDHCP = updateDHCP; exports.deleteDHCP = deleteDHCP; exports.getAllQoS = getAllQoS; exports.getQoS = getQoS; exports.createQoS = createQoS; exports.updateQoS = updateQoS; exports.deleteQoS = deleteQoS; const apiRequest_1 = require("../../helpers/apiRequest"); const responseFormatter_1 = require("../../helpers/responseFormatter"); const logger = __importStar(require("../../helpers/logger")); /** * Network Services Methods — DHCP and QoS * API Base Path: /network-config/v1alpha1/ */ const DHCP_PATH = '/network-config/v1alpha1/dhcp'; const QOS_PATH = '/network-config/v1alpha1/qos'; // ============================================================================ // DHCP Methods // ============================================================================ /** * Get all DHCP profiles */ async function getAllDHCP() { var _a, _b; const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting getAllDHCP operation', undefined, this); } try { const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const queryParams = {}; if (additionalFields.viewType) queryParams['view-type'] = additionalFields.viewType; if (additionalFields.objectType) queryParams['object-type'] = additionalFields.objectType; if (additionalFields.scopeId) queryParams['scope-id'] = additionalFields.scopeId; if (additionalFields.persona) queryParams.persona = additionalFields.persona; if (additionalFields.effective !== undefined) queryParams.effective = additionalFields.effective; if (additionalFields.detailed !== undefined) queryParams.detailed = additionalFields.detailed; if (additionalFields.limit) queryParams.limit = additionalFields.limit; if (additionalFields.offset !== undefined) queryParams.offset = additionalFields.offset; if (debugMode) { logger.debug('Query parameters', queryParams, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', DHCP_PATH, {}, queryParams); if (debugMode) { logger.debug(`Retrieved ${((_a = response.items) === null || _a === void 0 ? void 0 : _a.length) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) || 0} DHCP profiles`, undefined, this); } return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in getAllDHCP', error); throw error; } } /** * Get a specific DHCP profile by name */ async function getDHCP() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting getDHCP operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const queryParams = {}; if (additionalFields.effective !== undefined) queryParams.effective = additionalFields.effective; if (additionalFields.detailed !== undefined) queryParams.detailed = additionalFields.detailed; if (debugMode) { logger.debug('Getting DHCP profile', { profileName }, this); } const endpoint = `${DHCP_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in getDHCP', error); throw error; } } /** * Create a new DHCP profile */ async function createDHCP() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting createDHCP operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}'); let profileBody = {}; try { profileBody = typeof profileBodyRaw === 'string' ? JSON.parse(profileBodyRaw) : profileBodyRaw; } catch (e) { throw new Error('Invalid JSON in Profile Body'); } if (debugMode) { logger.debug('Creating DHCP profile', { profileName, profileBody }, this); } const endpoint = `${DHCP_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, profileBody, {}); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in createDHCP', error); throw error; } } /** * Update an existing DHCP profile */ async function updateDHCP() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting updateDHCP operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}'); let profileBody = {}; try { profileBody = typeof profileBodyRaw === 'string' ? JSON.parse(profileBodyRaw) : profileBodyRaw; } catch (e) { throw new Error('Invalid JSON in Profile Body'); } if (debugMode) { logger.debug('Updating DHCP profile', { profileName, profileBody }, this); } const endpoint = `${DHCP_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, profileBody, {}); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in updateDHCP', error); throw error; } } /** * Delete a DHCP profile */ async function deleteDHCP() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting deleteDHCP operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); if (debugMode) { logger.debug('Deleting DHCP profile', { profileName }, this); } const endpoint = `${DHCP_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, {}); return responseFormatter_1.formatResponse.call(this, response && Object.keys(response).length > 0 ? response : { success: true, profileName, message: 'DHCP profile deleted successfully' }); } catch (error) { logger.error('Error in deleteDHCP', error); throw error; } } // ============================================================================ // QoS Methods // ============================================================================ /** * Get all QoS profiles */ async function getAllQoS() { var _a, _b; const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting getAllQoS operation', undefined, this); } try { const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const queryParams = {}; if (additionalFields.viewType) queryParams['view-type'] = additionalFields.viewType; if (additionalFields.objectType) queryParams['object-type'] = additionalFields.objectType; if (additionalFields.scopeId) queryParams['scope-id'] = additionalFields.scopeId; if (additionalFields.persona) queryParams.persona = additionalFields.persona; if (additionalFields.effective !== undefined) queryParams.effective = additionalFields.effective; if (additionalFields.detailed !== undefined) queryParams.detailed = additionalFields.detailed; if (additionalFields.limit) queryParams.limit = additionalFields.limit; if (additionalFields.offset !== undefined) queryParams.offset = additionalFields.offset; if (debugMode) { logger.debug('Query parameters', queryParams, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', QOS_PATH, {}, queryParams); if (debugMode) { logger.debug(`Retrieved ${((_a = response.items) === null || _a === void 0 ? void 0 : _a.length) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) || 0} QoS profiles`, undefined, this); } return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in getAllQoS', error); throw error; } } /** * Get a specific QoS profile by name */ async function getQoS() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting getQoS operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const queryParams = {}; if (additionalFields.effective !== undefined) queryParams.effective = additionalFields.effective; if (additionalFields.detailed !== undefined) queryParams.detailed = additionalFields.detailed; if (debugMode) { logger.debug('Getting QoS profile', { profileName }, this); } const endpoint = `${QOS_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in getQoS', error); throw error; } } /** * Create a new QoS profile */ async function createQoS() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting createQoS operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}'); let profileBody = {}; try { profileBody = typeof profileBodyRaw === 'string' ? JSON.parse(profileBodyRaw) : profileBodyRaw; } catch (e) { throw new Error('Invalid JSON in Profile Body'); } if (debugMode) { logger.debug('Creating QoS profile', { profileName, profileBody }, this); } const endpoint = `${QOS_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, profileBody, {}); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in createQoS', error); throw error; } } /** * Update an existing QoS profile */ async function updateQoS() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting updateQoS operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}'); let profileBody = {}; try { profileBody = typeof profileBodyRaw === 'string' ? JSON.parse(profileBodyRaw) : profileBodyRaw; } catch (e) { throw new Error('Invalid JSON in Profile Body'); } if (debugMode) { logger.debug('Updating QoS profile', { profileName, profileBody }, this); } const endpoint = `${QOS_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, profileBody, {}); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in updateQoS', error); throw error; } } /** * Delete a QoS profile */ async function deleteQoS() { const debugMode = logger.isDebugMode(this); if (debugMode) { logger.debug('Starting deleteQoS operation', undefined, this); } try { const profileName = this.getNodeParameter('profileName', 0); if (debugMode) { logger.debug('Deleting QoS profile', { profileName }, this); } const endpoint = `${QOS_PATH}/${encodeURIComponent(profileName)}`; const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, {}); return responseFormatter_1.formatResponse.call(this, response && Object.keys(response).length > 0 ? response : { success: true, profileName, message: 'QoS profile deleted successfully' }); } catch (error) { logger.error('Error in deleteQoS', error); throw error; } }