UNPKG

admin-api-aurum-connector

Version:

Module to connect to the Admin API Aurum Core

46 lines (37 loc) 1.63 kB
const { module_name, configurations_key } = require("../../utils/Constants.js"); const { logger } = require("../../utils/Logger.js"); const getMiscellaneous = async (token, miscellaneousType) => { try { logger.info(`module-hub-aurum-core-connector :: get miscellaneous ${miscellaneousType} "${module_name}" ...`); if(!token) { return { responseCode: 401, message: "A token is required to consume the API" }; } const config = global[configurations_key]; let endpoint = config?.catalog?.getMiscellaneous?.endpoint || ""; endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl); endpoint = endpoint.replace("{miscellaneousEnviroment}", config.miscellaneousEnviroment); endpoint = endpoint.replace("{miscellaneousType}", miscellaneousType); logger.info(`module-hub-aurum-core-connector :: get miscellaneous ${miscellaneousType} to endpoint: ${endpoint}`); const response = await fetch(endpoint, { method: "GET", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + token } }); const responseJson = await response.json(); logger.info(`module-hub-aurum-core-connector :: getMiscellaneous ${miscellaneousType} response: ${JSON.stringify(responseJson)}`); return responseJson; } catch (error) { logger.error(`module-hub-aurum-core-connector :: Error at getMiscellaneous ${miscellaneousType}: ${error}`); return { responseCode: 500, error: error, message: `Error getting miscellaneous ${miscellaneousType}` }; } }; module.exports = getMiscellaneous;