@itentialopensource/adapter-utils
Advanced tools
Comparing version 5.1.7 to 5.2.0
## 5.2.0 [10-04-2023] | ||
* Broker Changes | ||
Closes ADAPT-2848 | ||
See merge request itentialopensource/adapter-utils!277 | ||
--- | ||
## 5.1.7 [09-09-2023] | ||
@@ -3,0 +13,0 @@ |
@@ -10,3 +10,2 @@ /* @copyright Itential, LLC 2023 */ | ||
const path = require('path'); | ||
const jsonQuery = require('json-query'); | ||
@@ -37,12 +36,2 @@ const lock = new AsyncLockCl(); | ||
/** | ||
* @summary Generates name for data object. Currently non-unique | ||
* @function generateName | ||
* @returns {String} - generated name | ||
*/ | ||
function generateName() { | ||
log.warn('Name for entity not found, generated name placeholder'); | ||
return 'GeneratedName'; | ||
} | ||
/** | ||
* @summary Deletes cache data and properties. Data deletion | ||
@@ -364,94 +353,2 @@ * saves considerable memory. | ||
/** | ||
* @function getDataFromSources | ||
* @summary INTERNAL FUNCTION: get data from source(s) - nested | ||
* @param {*} loopField - fields | ||
* @param {Array} sources - sources to look into | ||
* @returns {*} - nested field value | ||
*/ | ||
function getDataFromSources(loopField, sources) { | ||
let fieldValue = loopField; | ||
// go through the sources to find the field | ||
for (let s = 0; s < sources.length; s += 1) { | ||
// find the field value using jsonquery | ||
const nestedValue = jsonQuery(loopField, { data: sources[s] }).value; | ||
// if we found in source - set and no need to check other sources | ||
if (nestedValue) { | ||
fieldValue = nestedValue; | ||
break; | ||
} | ||
} | ||
return fieldValue; | ||
} | ||
/** | ||
* @summary Manipulates data from call to only represent the specified fields and id and name if they do not have one | ||
* | ||
* @function parseResponseFields | ||
* @param {Boolean} responseFull - whether or not to take in all fields | ||
* @param {Object of output to call result} responseFields - fields to take in | ||
* - ie response field of "name": "id" will give the iap call output a name field | ||
* with the value being the id | ||
* @param {Array of Objects} allData - data returned from IAP Call | ||
* @return {Array of Objects} - modified data | ||
*/ | ||
function parseResponseFields(responseFields, allData, end, requestFields) { | ||
const origin = `${id}-cacheHandler-createCacheData`; | ||
log.trace(origin); | ||
const parsedData = []; | ||
const rfKeys = Object.keys(responseFields); | ||
log.debug(rfKeys); | ||
let ostypePrefix = ''; | ||
if (responseFields.ostypePrefix) { | ||
ostypePrefix = responseFields.ostypePrefix; | ||
} | ||
let statusValue = true; | ||
if (responseFields.statusValue) { | ||
statusValue = responseFields.statusValue; | ||
} | ||
allData.response.forEach((currData) => { | ||
const newObj = currData; | ||
for (let rf = 0; rf < rfKeys.length; rf += 1) { | ||
if (rfKeys[rf] !== 'ostypePrefix') { | ||
let fieldValue = getDataFromSources(responseFields[rfKeys[rf]], [currData, { fake: 'fakedata' }, requestFields]); | ||
// if the field is ostype - need to add prefix | ||
if (rfKeys[rf] === 'ostype' && typeof fieldValue === 'string') { | ||
fieldValue = ostypePrefix + fieldValue; | ||
} | ||
// if there is a status to set, set it | ||
if (rfKeys[rf] === 'status') { | ||
// if really looking for just a good response | ||
if (responseFields[rfKeys[rf]] === 'return2xx' && allData.icode === statusValue.toString()) { | ||
newObj.isAlive = true; | ||
} else if (fieldValue.toString() === statusValue.toString()) { | ||
newObj.isAlive = true; | ||
} else { | ||
newObj.isAlive = false; | ||
} | ||
} | ||
// if we found a good value | ||
newObj[rfKeys[rf]] = fieldValue; | ||
} | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(currData, 'name')) { | ||
newObj.name = generateName(); | ||
} | ||
// no longer requiring id field | ||
parsedData.push(newObj); | ||
}); | ||
return parsedData; | ||
} | ||
/** | ||
* @summary makes IAP Calls through Generic Handler | ||
@@ -464,5 +361,5 @@ * | ||
*/ | ||
function makeIAPCall(calls, requestHandler, callback) { // todo pass in properties from cacheHandler | ||
function makeIAPCall(calls, requestHandler, callback) { | ||
const callPromises = []; | ||
log.debug('Starting an iap call from cache.'); | ||
for (let i = 0; i < calls.length; i += 1) { | ||
@@ -476,3 +373,3 @@ log.debug('Response :', calls[i].responseFields); | ||
} | ||
requestHandler.expandedGenericAdapterRequest(metadata, calls[i].path, calls[i].method, null, calls[i].query, calls[i].body, calls[i].headers, (callRet, callErr) => { | ||
requestHandler.iapMakeGenericCall(metadata, calls[i].path, calls[i], [{ fake: 'fakedata' }], [], (callRet, callErr) => { | ||
if (callErr) { | ||
@@ -485,6 +382,2 @@ log.error('Make iap call failed with error'); | ||
} | ||
if (calls[i].handleFailure === 'ignore') { | ||
log.info(`Call failed for path ${calls[i].path} with error code ${callErr.icode}. Ignoring.`); | ||
return resolve([]); | ||
} | ||
log.warn(`Call failed for path ${calls[i].path} with error code ${callErr.icode}. Rejecting.`); | ||
@@ -496,7 +389,3 @@ return reject(callErr); | ||
log.info(`Sucessful Call. Adding to cache from path ${calls[i].path}`); | ||
const result = callRet; | ||
if (calls[i].responseDatakey) { | ||
result.response = jsonQuery(calls[i].responseDatakey, { data: result.response }).value; | ||
} | ||
return resolve(parseResponseFields(calls[i].responseFields, result, i, calls[i].requestFields)); | ||
return resolve(callRet); | ||
}); | ||
@@ -503,0 +392,0 @@ })); |
{ | ||
"name": "@itentialopensource/adapter-utils", | ||
"version": "5.1.7", | ||
"version": "5.2.0", | ||
"description": "Itential Adapter Utility Libraries", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
800988
16047