n8n-nodes-arubacentral
Version:
n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities
84 lines (83 loc) • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIapVariables = getIapVariables;
exports.replaceIapVariables = replaceIapVariables;
const apiRequest_1 = require("../../../helpers/apiRequest");
const responseFormatter_1 = require("../../../helpers/responseFormatter");
const pagination_1 = require("../../../helpers/pagination");
async function getIapVariables() {
try {
// Get parameters
const groupNameOrGuidOrSerial = this.getNodeParameter('groupNameOrGuidOrSerial', 0);
const returnAll = this.getNodeParameter('returnAll', 0, false);
let limit;
if (!returnAll) {
limit = this.getNodeParameter('limit', 0, 50);
}
const additionalOptions = this.getNodeParameter('additionalOptions', 0, {});
// Build query parameters
const queryParams = {};
// Use additionalOptions only if not using returnAll/limit
if (!returnAll && !limit) {
if (additionalOptions.limit) {
queryParams.limit = additionalOptions.limit;
}
if (additionalOptions.offset) {
queryParams.offset = additionalOptions.offset;
}
}
// Log the request
console.log('Getting IAP variables with parameters:', {
groupNameOrGuidOrSerial,
returnAll,
limit,
additionalOptions,
});
// Build the endpoint
const endpoint = `/configuration/v1/iap_variables/${groupNameOrGuidOrSerial}`;
if (returnAll || limit) {
// Use pagination helper with a custom batch size of 100 (conservative default)
return await pagination_1.handlePagination.call(this, endpoint, 'GET', {}, queryParams, {
path: ['variables'],
fallbackPaths: [['data', 'variables']],
}, returnAll, limit, 100);
}
else {
// Make a single API call without pagination
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams);
console.log('Received IAP variables');
return responseFormatter_1.formatResponse.call(this, response);
}
}
catch (error) {
console.log('ERROR in getIapVariables:', error);
throw error;
}
}
async function replaceIapVariables() {
try {
// Get parameters
const groupNameOrGuidOrSerial = this.getNodeParameter('groupNameOrGuidOrSerial', 0);
const iapVariablesJson = this.getNodeParameter('iapVariables', 0);
// Parse the IAP variables JSON
let iapVariables;
try {
iapVariables = JSON.parse(iapVariablesJson);
}
catch (parseError) {
throw new Error(`Invalid JSON format for IAP variables: ${parseError.message}`);
}
// Log the request
console.log('Replacing IAP variables:', { groupNameOrGuidOrSerial, iapVariables });
// Build the endpoint
const endpoint = `/configuration/v1/iap_variables/${groupNameOrGuidOrSerial}`;
// Make API call
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, iapVariables, {});
console.log('IAP variables replaced successfully');
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
console.log('ERROR in replaceIapVariables:', error);
throw error;
}
}