n8n-nodes-arubacentralnextgen
Version:
n8n community node for Aruba Central NextGen API integration with modern monitoring and management capabilities
1,179 lines (1,178 loc) • 45.1 kB
JavaScript
"use strict";
// methods/configuration/scopeManagement.methods.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllSites = getAllSites;
exports.getSite = getSite;
exports.createSite = createSite;
exports.updateSite = updateSite;
exports.deleteSite = deleteSite;
exports.bulkDeleteSites = bulkDeleteSites;
exports.addDevicesToSite = addDevicesToSite;
exports.getAllSiteCollections = getAllSiteCollections;
exports.getSiteCollection = getSiteCollection;
exports.createSiteCollection = createSiteCollection;
exports.updateSiteCollection = updateSiteCollection;
exports.deleteSiteCollection = deleteSiteCollection;
exports.bulkDeleteSiteCollections = bulkDeleteSiteCollections;
exports.addSitesToCollection = addSitesToCollection;
exports.removeSitesFromCollection = removeSitesFromCollection;
exports.getAllDeviceGroups = getAllDeviceGroups;
exports.getDeviceGroup = getDeviceGroup;
exports.createDeviceGroup = createDeviceGroup;
exports.createDeviceGroupWithDevices = createDeviceGroupWithDevices;
exports.updateDeviceGroup = updateDeviceGroup;
exports.bulkDeleteDeviceGroups = bulkDeleteDeviceGroups;
exports.addDevicesToGroup = addDevicesToGroup;
exports.removeDevicesFromGroup = removeDevicesFromGroup;
exports.getAllDeviceCollections = getAllDeviceCollections;
exports.getDeviceCollection = getDeviceCollection;
exports.createDeviceCollection = createDeviceCollection;
exports.createDeviceCollectionWithDevices = createDeviceCollectionWithDevices;
exports.updateDeviceCollection = updateDeviceCollection;
exports.deleteDeviceCollection = deleteDeviceCollection;
exports.bulkDeleteDeviceCollections = bulkDeleteDeviceCollections;
exports.addDevicesToDeviceCollection = addDevicesToDeviceCollection;
exports.removeDevicesFromDeviceCollection = removeDevicesFromDeviceCollection;
exports.getScopeHierarchy = getScopeHierarchy;
const apiRequest_1 = require("../../helpers/apiRequest");
const responseFormatter_1 = require("../../helpers/responseFormatter");
const logger_1 = require("../../helpers/logger");
/**
* Scope Management Methods
* Handles Sites, Site Collections, Device Groups, Device Collections, and Hierarchy operations
* API Endpoint Base: /network-config/v1alpha1/
*/
// ============================================================================
// Sites Operations
// ============================================================================
/**
* Get all sites
*/
async function getAllSites() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getAllSites operation', undefined, this);
}
try {
const returnAll = this.getNodeParameter('returnAll', 0, false);
const limit = this.getNodeParameter('limit', 0, 100);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = {};
if (additionalFields.filter) {
queryParams.filter = additionalFields.filter;
}
if (additionalFields.search) {
queryParams.search = additionalFields.search;
}
if (additionalFields.sort) {
queryParams.sort = additionalFields.sort;
}
const endpoint = '/network-config/v1alpha1/sites';
if (returnAll) {
const pageSize = 100;
let allItems = [];
let currentOffset = 0;
let hasMore = true;
if (debugMode) {
logger_1.logger.debug('Paginating getAllSites to retrieve all results', undefined, this);
}
while (hasMore) {
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {
...queryParams,
limit: pageSize,
offset: currentOffset,
});
const items = (response.items || []);
allItems = [...allItems, ...items];
if (items.length < pageSize || allItems.length >= response.total) {
hasMore = false;
}
else {
currentOffset += pageSize;
}
}
if (debugMode) {
logger_1.logger.debug(`getAllSites pagination complete, total: ${allItems.length}`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, { items: allItems, count: allItems.length, total: allItems.length, offset: 0 });
}
else {
if (debugMode) {
logger_1.logger.debug('Getting all sites', { queryParams, limit }, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, { ...queryParams, limit, offset: 0 });
return responseFormatter_1.formatResponse.call(this, response);
}
}
catch (error) {
logger_1.logger.error('Error in getAllSites', error);
throw error;
}
}
/**
* Get a specific site by scopeId
*/
async function getSite() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getSite operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
if (debugMode) {
logger_1.logger.debug('Getting site', { scopeId }, this);
}
// Use list endpoint with filter since there's no dedicated GET by ID endpoint
const queryParams = {
limit: 1,
offset: 0,
filter: `scopeId eq '${scopeId}'`,
};
const endpoint = '/network-config/v1alpha1/sites';
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in getSite', error);
throw error;
}
}
/**
* Create a new site
*/
async function createSite() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createSite operation', undefined, this);
}
try {
const name = this.getNodeParameter('name', 0);
const address = this.getNodeParameter('address', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
name,
};
if (address) {
body.address = address;
}
// Add additional fields
if (additionalFields.city) {
body.city = additionalFields.city;
}
if (additionalFields.state) {
body.state = additionalFields.state;
}
if (additionalFields.country) {
body.country = additionalFields.country;
}
if (additionalFields.zipcode) {
body.zipcode = additionalFields.zipcode;
}
if (additionalFields.latitude !== undefined) {
body.latitude = additionalFields.latitude;
}
if (additionalFields.longitude !== undefined) {
body.longitude = additionalFields.longitude;
}
if (debugMode) {
logger_1.logger.debug('Creating site', { body }, this);
}
const endpoint = '/network-config/v1alpha1/sites';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createSite', error);
throw error;
}
}
/**
* Update an existing site
*/
async function updateSite() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting updateSite operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
const updateFields = this.getNodeParameter('updateFields', 0, {});
// Build the request body
const body = {
scopeId,
};
if (updateFields.name) {
body.name = updateFields.name;
}
if (updateFields.address) {
body.address = updateFields.address;
}
if (updateFields.city) {
body.city = updateFields.city;
}
if (updateFields.state) {
body.state = updateFields.state;
}
if (updateFields.country) {
body.country = updateFields.country;
}
if (updateFields.zipcode) {
body.zipcode = updateFields.zipcode;
}
if (updateFields.latitude !== undefined) {
body.latitude = updateFields.latitude;
}
if (updateFields.longitude !== undefined) {
body.longitude = updateFields.longitude;
}
if (debugMode) {
logger_1.logger.debug('Updating site', { scopeId, body }, this);
}
const endpoint = '/network-config/v1alpha1/sites';
const response = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in updateSite', error);
throw error;
}
}
/**
* Delete a site by scopeId
*/
async function deleteSite() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting deleteSite operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
// Build query parameters
const queryParams = {
'scope-id': scopeId,
};
if (debugMode) {
logger_1.logger.debug('Deleting site', { scopeId }, this);
}
const endpoint = '/network-config/v1alpha1/sites';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in deleteSite', error);
throw error;
}
}
/**
* Bulk delete multiple sites
*/
async function bulkDeleteSites() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting bulkDeleteSites operation', undefined, this);
}
try {
const siteIds = this.getNodeParameter('siteIds', 0);
// Build the request body
const body = {
items: siteIds.map((id) => ({ id })),
};
if (debugMode) {
logger_1.logger.debug('Bulk deleting sites', { siteIds }, this);
}
const endpoint = '/network-config/v1alpha1/sites/bulk';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in bulkDeleteSites', error);
throw error;
}
}
/**
* Add devices to a site
*/
async function addDevicesToSite() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting addDevicesToSite operation', undefined, this);
}
try {
const desScopeId = this.getNodeParameter('desScopeId', 0);
const devices = this.getNodeParameter('devices', 0);
// Build the request body
const body = {
desScopeId,
devices,
};
if (debugMode) {
logger_1.logger.debug('Adding devices to site', { desScopeId, devices }, this);
}
const endpoint = '/network-config/v1alpha1/site-add-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in addDevicesToSite', error);
throw error;
}
}
// ============================================================================
// Site Collections Operations
// ============================================================================
/**
* Get all site collections
*/
async function getAllSiteCollections() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getAllSiteCollections operation', undefined, this);
}
try {
const returnAll = this.getNodeParameter('returnAll', 0, false);
const limit = this.getNodeParameter('limit', 0, 100);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = {};
if (additionalFields.filter) {
queryParams.filter = additionalFields.filter;
}
if (additionalFields.search) {
queryParams.search = additionalFields.search;
}
if (additionalFields.sort) {
queryParams.sort = additionalFields.sort;
}
const endpoint = '/network-config/v1alpha1/site-collections';
if (returnAll) {
const pageSize = 100;
let allItems = [];
let currentOffset = 0;
let hasMore = true;
if (debugMode) {
logger_1.logger.debug('Paginating getAllSiteCollections to retrieve all results', undefined, this);
}
while (hasMore) {
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {
...queryParams,
limit: pageSize,
offset: currentOffset,
});
const items = (response.items || []);
allItems = [...allItems, ...items];
if (items.length < pageSize || allItems.length >= response.total) {
hasMore = false;
}
else {
currentOffset += pageSize;
}
}
if (debugMode) {
logger_1.logger.debug(`getAllSiteCollections pagination complete, total: ${allItems.length}`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, { items: allItems, count: allItems.length, total: allItems.length, offset: 0 });
}
else {
if (debugMode) {
logger_1.logger.debug('Getting all site collections', { queryParams, limit }, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, { ...queryParams, limit, offset: 0 });
return responseFormatter_1.formatResponse.call(this, response);
}
}
catch (error) {
logger_1.logger.error('Error in getAllSiteCollections', error);
throw error;
}
}
/**
* Get a specific site collection by scopeId (using filter)
*/
async function getSiteCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getSiteCollection operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
// Build query parameters - using filter to get specific site collection
const queryParams = {
limit: 1,
offset: 0,
filter: `scopeId eq '${scopeId}'`,
};
if (debugMode) {
logger_1.logger.debug('Getting site collection', { scopeId }, this);
}
const endpoint = '/network-config/v1alpha1/site-collections';
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in getSiteCollection', error);
throw error;
}
}
/**
* Create a new site collection
*/
async function createSiteCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createSiteCollection operation', undefined, this);
}
try {
const scopeName = this.getNodeParameter('scopeName', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
scopeName,
};
if (additionalFields.description) {
body.description = additionalFields.description;
}
if (additionalFields.siteIds) {
body.siteIds = additionalFields.siteIds;
}
if (debugMode) {
logger_1.logger.debug('Creating site collection', { body }, this);
}
const endpoint = '/network-config/v1alpha1/site-collections';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createSiteCollection', error);
throw error;
}
}
/**
* Update an existing site collection
*/
async function updateSiteCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting updateSiteCollection operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
const updateFields = this.getNodeParameter('updateFields', 0, {});
// Build the request body
const body = {
scopeId,
};
if (updateFields.scopeName) {
body.scopeName = updateFields.scopeName;
}
if (updateFields.description) {
body.description = updateFields.description;
}
if (debugMode) {
logger_1.logger.debug('Updating site collection', { scopeId, body }, this);
}
const endpoint = '/network-config/v1alpha1/site-collections';
const response = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in updateSiteCollection', error);
throw error;
}
}
/**
* Delete a site collection by scopeId
*/
async function deleteSiteCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting deleteSiteCollection operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
// Build query parameters
const queryParams = {
'scope-id': scopeId,
};
if (debugMode) {
logger_1.logger.debug('Deleting site collection', { scopeId }, this);
}
const endpoint = '/network-config/v1alpha1/site-collections';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in deleteSiteCollection', error);
throw error;
}
}
/**
* Bulk delete multiple site collections
*/
async function bulkDeleteSiteCollections() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting bulkDeleteSiteCollections operation', undefined, this);
}
try {
const siteCollectionIds = this.getNodeParameter('siteCollectionIds', 0);
// Build the request body
const body = {
items: siteCollectionIds.map((id) => ({ id })),
};
if (debugMode) {
logger_1.logger.debug('Bulk deleting site collections', { siteCollectionIds }, this);
}
const endpoint = '/network-config/v1alpha1/site-collections/bulk';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in bulkDeleteSiteCollections', error);
throw error;
}
}
/**
* Add sites to a site collection
*/
async function addSitesToCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting addSitesToCollection operation', undefined, this);
}
try {
const siteCollectionId = this.getNodeParameter('siteCollectionId', 0);
const siteIds = this.getNodeParameter('siteIds', 0);
// Build the request body
const body = {
siteCollectionId,
siteIds,
};
if (debugMode) {
logger_1.logger.debug('Adding sites to collection', { siteCollectionId, siteIds }, this);
}
const endpoint = '/network-config/v1alpha1/site-collection-add-sites';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in addSitesToCollection', error);
throw error;
}
}
/**
* Remove sites from a site collection
*/
async function removeSitesFromCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting removeSitesFromCollection operation', undefined, this);
}
try {
const siteIds = this.getNodeParameter('siteIds', 0);
// Build query parameters
const queryParams = {
'site-ids': siteIds.join(','),
};
if (debugMode) {
logger_1.logger.debug('Removing sites from collection', { siteIds }, this);
}
const endpoint = '/network-config/v1alpha1/site-collection-remove-sites';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in removeSitesFromCollection', error);
throw error;
}
}
// ============================================================================
// Device Groups Operations
// ============================================================================
/**
* Get all device groups
*/
async function getAllDeviceGroups() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getAllDeviceGroups operation', undefined, this);
}
try {
const returnAll = this.getNodeParameter('returnAll', 0, false);
const limit = this.getNodeParameter('limit', 0, 100);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = {};
if (additionalFields.filter) {
queryParams.filter = additionalFields.filter;
}
if (additionalFields.search) {
queryParams.search = additionalFields.search;
}
if (additionalFields.sort) {
queryParams.sort = additionalFields.sort;
}
const endpoint = '/network-config/v1alpha1/device-groups';
if (returnAll) {
const pageSize = 100;
let allItems = [];
let currentOffset = 0;
let hasMore = true;
if (debugMode) {
logger_1.logger.debug('Paginating getAllDeviceGroups to retrieve all results', undefined, this);
}
while (hasMore) {
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {
...queryParams,
limit: pageSize,
offset: currentOffset,
});
const items = (response.items || []);
allItems = [...allItems, ...items];
if (items.length < pageSize || allItems.length >= response.total) {
hasMore = false;
}
else {
currentOffset += pageSize;
}
}
if (debugMode) {
logger_1.logger.debug(`getAllDeviceGroups pagination complete, total: ${allItems.length}`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, { items: allItems, count: allItems.length, total: allItems.length, offset: 0 });
}
else {
if (debugMode) {
logger_1.logger.debug('Getting all device groups', { queryParams, limit }, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, { ...queryParams, limit, offset: 0 });
return responseFormatter_1.formatResponse.call(this, response);
}
}
catch (error) {
logger_1.logger.error('Error in getAllDeviceGroups', error);
throw error;
}
}
/**
* Get a specific device group by scopeId (using filter)
*/
async function getDeviceGroup() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getDeviceGroup operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
// Build query parameters - using filter to get specific device group
const queryParams = {
limit: 1,
offset: 0,
filter: `scopeId eq '${scopeId}'`,
};
if (debugMode) {
logger_1.logger.debug('Getting device group', { scopeId }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups';
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in getDeviceGroup', error);
throw error;
}
}
/**
* Create a new device group
*/
async function createDeviceGroup() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createDeviceGroup operation', undefined, this);
}
try {
const scopeName = this.getNodeParameter('scopeName', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
scopeName,
};
if (additionalFields.description) {
body.description = additionalFields.description;
}
if (debugMode) {
logger_1.logger.debug('Creating device group', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createDeviceGroup', error);
throw error;
}
}
/**
* Create a new device group with devices
*/
async function createDeviceGroupWithDevices() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createDeviceGroupWithDevices operation', undefined, this);
}
try {
const scopeName = this.getNodeParameter('scopeName', 0);
const devices = this.getNodeParameter('devices', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
scopeName,
devices,
};
if (additionalFields.description) {
body.description = additionalFields.description;
}
if (debugMode) {
logger_1.logger.debug('Creating device group with devices', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups-create-and-add-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createDeviceGroupWithDevices', error);
throw error;
}
}
/**
* Update an existing device group
*/
async function updateDeviceGroup() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting updateDeviceGroup operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
const scopeName = this.getNodeParameter('scopeName', 0);
const description = this.getNodeParameter('description', 0);
// Build the request body
const body = {
scopeId,
scopeName,
description,
};
if (debugMode) {
logger_1.logger.debug('Updating device group', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups';
const response = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in updateDeviceGroup', error);
throw error;
}
}
/**
* Bulk delete multiple device groups
*/
async function bulkDeleteDeviceGroups() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting bulkDeleteDeviceGroups operation', undefined, this);
}
try {
const deviceGroupIds = this.getNodeParameter('deviceGroupIds', 0);
// Build the request body
const body = {
items: deviceGroupIds.map((id) => ({ id })),
};
if (debugMode) {
logger_1.logger.debug('Bulk deleting device groups', { deviceGroupIds }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups/bulk';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in bulkDeleteDeviceGroups', error);
throw error;
}
}
/**
* Add devices to a device group
*/
async function addDevicesToGroup() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting addDevicesToGroup operation', undefined, this);
}
try {
const desScopeId = this.getNodeParameter('desScopeId', 0);
const devices = this.getNodeParameter('devices', 0);
// Build the request body
const body = {
desScopeId,
devices,
};
if (debugMode) {
logger_1.logger.debug('Adding devices to group', { desScopeId, devices }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups-add-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in addDevicesToGroup', error);
throw error;
}
}
/**
* Remove devices from a device group
*/
async function removeDevicesFromGroup() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting removeDevicesFromGroup operation', undefined, this);
}
try {
const devices = this.getNodeParameter('devices', 0);
// Build the request body
const body = {
devices,
};
if (debugMode) {
logger_1.logger.debug('Removing devices from group', { devices }, this);
}
const endpoint = '/network-config/v1alpha1/device-groups-remove-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in removeDevicesFromGroup', error);
throw error;
}
}
// ============================================================================
// Device Collections Operations (Deprecated)
// ============================================================================
/**
* Get all device collections (Deprecated)
*/
async function getAllDeviceCollections() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getAllDeviceCollections operation', undefined, this);
}
try {
const returnAll = this.getNodeParameter('returnAll', 0, false);
const limit = this.getNodeParameter('limit', 0, 100);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = {};
if (additionalFields.filter) {
queryParams.filter = additionalFields.filter;
}
if (additionalFields.search) {
queryParams.search = additionalFields.search;
}
if (additionalFields.sort) {
queryParams.sort = additionalFields.sort;
}
const endpoint = '/network-config/v1alpha1/device-collections';
if (returnAll) {
const pageSize = 100;
let allItems = [];
let currentOffset = 0;
let hasMore = true;
if (debugMode) {
logger_1.logger.debug('Paginating getAllDeviceCollections to retrieve all results', undefined, this);
}
while (hasMore) {
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {
...queryParams,
limit: pageSize,
offset: currentOffset,
});
const items = (response.items || []);
allItems = [...allItems, ...items];
if (items.length < pageSize || allItems.length >= response.total) {
hasMore = false;
}
else {
currentOffset += pageSize;
}
}
if (debugMode) {
logger_1.logger.debug(`getAllDeviceCollections pagination complete, total: ${allItems.length}`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, { items: allItems, count: allItems.length, total: allItems.length, offset: 0 });
}
else {
if (debugMode) {
logger_1.logger.debug('Getting all device collections (deprecated)', { queryParams, limit }, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, { ...queryParams, limit, offset: 0 });
return responseFormatter_1.formatResponse.call(this, response);
}
}
catch (error) {
logger_1.logger.error('Error in getAllDeviceCollections', error);
throw error;
}
}
/**
* Get a specific device collection by scopeId (Deprecated)
*/
async function getDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getDeviceCollection operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
// Build query parameters - using filter to get specific device collection
const queryParams = {
limit: 1,
offset: 0,
filter: `scopeId eq '${scopeId}'`,
};
if (debugMode) {
logger_1.logger.debug('Getting device collection (deprecated)', { scopeId }, this);
}
const endpoint = '/network-config/v1alpha1/device-collections';
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in getDeviceCollection', error);
throw error;
}
}
/**
* Create a new device collection (Deprecated)
*/
async function createDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createDeviceCollection operation', undefined, this);
}
try {
const scopeName = this.getNodeParameter('scopeName', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
scopeName,
};
if (additionalFields.description) {
body.description = additionalFields.description;
}
if (debugMode) {
logger_1.logger.debug('Creating device collection (deprecated)', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-collections';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createDeviceCollection', error);
throw error;
}
}
/**
* Create a new device collection with devices (Deprecated)
*/
async function createDeviceCollectionWithDevices() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting createDeviceCollectionWithDevices operation', undefined, this);
}
try {
const scopeName = this.getNodeParameter('scopeName', 0);
const devices = this.getNodeParameter('devices', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build the request body
const body = {
scopeName,
devices,
};
if (additionalFields.description) {
body.description = additionalFields.description;
}
if (debugMode) {
logger_1.logger.debug('Creating device collection with devices (deprecated)', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-collection-create-and-add-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in createDeviceCollectionWithDevices', error);
throw error;
}
}
/**
* Update an existing device collection (Deprecated)
*/
async function updateDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting updateDeviceCollection operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
const scopeName = this.getNodeParameter('scopeName', 0);
const description = this.getNodeParameter('description', 0);
// Build the request body
const body = {
scopeId,
scopeName,
description,
};
if (debugMode) {
logger_1.logger.debug('Updating device collection (deprecated)', { body }, this);
}
const endpoint = '/network-config/v1alpha1/device-collections';
const response = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in updateDeviceCollection', error);
throw error;
}
}
/**
* Delete a device collection (Deprecated)
*/
async function deleteDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting deleteDeviceCollection operation', undefined, this);
}
try {
const scopeIds = this.getNodeParameter('scopeIds', 0);
// Build the request body
const body = {
scopeIds,
};
if (debugMode) {
logger_1.logger.debug('Deleting device collection (deprecated)', { scopeIds }, this);
}
const endpoint = '/network-config/v1alpha1/device-collections';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in deleteDeviceCollection', error);
throw error;
}
}
/**
* Bulk delete multiple device collections (Deprecated)
*/
async function bulkDeleteDeviceCollections() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting bulkDeleteDeviceCollections operation', undefined, this);
}
try {
const scopeIds = this.getNodeParameter('scopeIds', 0);
// Build the request body
const body = {
scopeIds,
};
if (debugMode) {
logger_1.logger.debug('Bulk deleting device collections (deprecated)', { scopeIds }, this);
}
const endpoint = '/network-config/v1alpha1/device-collections/bulk';
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in bulkDeleteDeviceCollections', error);
throw error;
}
}
/**
* Add devices to a device collection (Deprecated)
*/
async function addDevicesToDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting addDevicesToDeviceCollection operation', undefined, this);
}
try {
const desScopeId = this.getNodeParameter('desScopeId', 0);
const devices = this.getNodeParameter('devices', 0);
// Build the request body
const body = {
desScopeId,
devices,
};
if (debugMode) {
logger_1.logger.debug('Adding devices to device collection (deprecated)', { desScopeId, devices }, this);
}
const endpoint = '/network-config/v1alpha1/device-collection-add-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in addDevicesToDeviceCollection', error);
throw error;
}
}
/**
* Remove devices from a device collection (Deprecated)
*/
async function removeDevicesFromDeviceCollection() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting removeDevicesFromDeviceCollection operation', undefined, this);
}
try {
const devices = this.getNodeParameter('devices', 0);
// Build the request body
const body = {
devices,
};
if (debugMode) {
logger_1.logger.debug('Removing devices from device collection (deprecated)', { devices }, this);
}
const endpoint = '/network-config/v1alpha1/device-collection-remove-devices';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in removeDevicesFromDeviceCollection', error);
throw error;
}
}
// ============================================================================
// Hierarchy Operations
// ============================================================================
/**
* Get scope hierarchy
*/
async function getScopeHierarchy() {
const debugMode = logger_1.logger.isDebugMode(this);
if (debugMode) {
logger_1.logger.debug('Starting getScopeHierarchy operation', undefined, this);
}
try {
const scopeId = this.getNodeParameter('scopeId', 0);
const scopeType = this.getNodeParameter('scopeType', 0);
// Build query parameters
const queryParams = {
'scope-id': scopeId,
'scope-type': scopeType,
};
if (debugMode) {
logger_1.logger.debug('Getting scope hierarchy', { scopeId, scopeType }, this);
}
const endpoint = '/network-config/v1alpha1/hierarchy';
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger_1.logger.error('Error in getScopeHierarchy', error);
throw error;
}
}