Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@itentialopensource/adapter-utils

Package Overview
Dependencies
Maintainers
3
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itentialopensource/adapter-utils - npm Package Compare versions

Comparing version 4.8.4 to 4.9.0

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## 4.9.0 [07-24-2019]
* Resolve PH-25577 "Minor/"
Closes PH-25577
See merge request itentialopensource/adapter-utils!100
---
## 4.8.4 [07-15-2019]

@@ -2,0 +11,0 @@ * try pinning async-lock to remove vulnerability

77

lib/restHandler.js

@@ -8,2 +8,3 @@ /* @copyright Itential, LLC 2018 */

const querystring = require('querystring');
const jsonQuery = require('json-query');

@@ -21,3 +22,3 @@ let transUtilInst = null;

/*
* INTERNAL FUNCTION: Get the best match for the moc k data response
* INTERNAL FUNCTION: Get the best match for the mock data response
*/

@@ -53,5 +54,6 @@ function matchResponse(uriPath, method, type, responseKeys) {

* @param {Object} callProperties - properties to override on this call (optional)
* @param {String} filter - json query filter to apply to the returned data (optional)
* @param {Function} callback - a callback function to return the result of the request
*/
function handleRestRequest(request, entityId, entitySchema, callProperties, callback) {
function handleRestRequest(request, entityId, entitySchema, callProperties, filter, callback) {
const origin = `${id}-restHandler-handleRestRequest`;

@@ -239,3 +241,3 @@ log.trace(origin);

// set the normal headers based on the type of data for the call
// if the data is not json we can not perform the extended capabilities so just return it
if (entitySchema && entitySchema.datatype && entitySchema.datatype.toUpperCase() === 'PLAIN') {

@@ -253,22 +255,40 @@ log.debug(`${origin}: RESPONSE: ${resObj.response}`);

}
// what if nothing comes back - nothing to do
if (resObj.response === null || resObj.response === '') {
log.warn(`${origin}: No data returned on call`);
return callback(retObject);
}
// process the response - parse it
if (resObj.response !== null && resObj.response !== '') {
try {
retResponse = JSON.parse(resObj.response);
} catch (ex) {
// otherwise log parse failure and return the unparsed response
log.warn(`${origin}: An error occurred parsing the resulting JSON: ${ex}`);
return callback(retObject);
}
try {
retResponse = JSON.parse(resObj.response);
} catch (ex) {
// otherwise log parse failure and return the unparsed response
log.warn(`${origin}: An error occurred parsing the resulting JSON: ${ex}`);
return callback(retObject);
}
// Make the call to translate the received Entity to Pronghorn Entity
if (respObjKey !== '') {
// get the return data and added the translated response to the return Object
const returnFieldData = jsonQuery(respObjKey, { data: retResponse }).value;
// if the response is an array, log the first item
if (retResponse[respObjKey].constructor === Array) {
log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(retResponse[respObjKey][0])}`);
if (Array.isArray(returnFieldData)) {
log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(returnFieldData[0])}`);
} else {
log.debug(`${origin}: RESPONSE: ${JSON.stringify(retResponse[respObjKey])}`);
log.debug(`${origin}: RESPONSE: ${JSON.stringify(returnFieldData)}`);
}
} else if (retResponse.constructor === Array) {
retObject.response = transUtilInst.mapFromOutboundEntity(returnFieldData, entitySchema.responseSchema);
// if filtering, filter the data
if (filter) {
retObject.response = jsonQuery(filter, { data: retObject.response }).value;
}
return callback(retObject);
}
if (Array.isArray(retResponse)) {
// if the response is an array, log the first item

@@ -280,11 +300,10 @@ log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(retResponse[0])}`);

// Make the call to translate the received Entity to Pronghorn Entity
if (respObjKey !== '') {
// added the translated response to the return Object
retObject.response = transUtilInst.mapFromOutboundEntity(retResponse[respObjKey], entitySchema.responseSchema);
return callback(retObject);
// added the translated response to the return Object
retObject.response = transUtilInst.mapFromOutboundEntity(retResponse, entitySchema.responseSchema);
// if filtering, filter the data
if (filter) {
retObject.response = jsonQuery(filter, { data: retObject.response }).value;
}
// added the translated response to the return Object
retObject.response = transUtilInst.mapFromOutboundEntity(retResponse, entitySchema.responseSchema);
return callback(retObject);

@@ -814,2 +833,3 @@ });

let callProperties = null;
let filter = null;

@@ -838,2 +858,5 @@ if (requestObj !== null) {

}
if (requestObj.filter) {
({ filter } = requestObj);
}
}

@@ -872,6 +895,6 @@

if (translateFlag) {
return handleRestRequest(request, 'map', entitySchema, callProperties, callback);
return handleRestRequest(request, 'map', entitySchema, callProperties, filter, callback);
}
return handleRestRequest(request, 'nomap', entitySchema, callProperties, callback);
return handleRestRequest(request, 'nomap', entitySchema, callProperties, filter, callback);
} catch (e) {

@@ -908,2 +931,3 @@ // handle any exception

let callProperties = null;
let filter = null;

@@ -932,2 +956,5 @@ if (requestObj !== null) {

}
if (requestObj.filter) {
({ filter } = requestObj);
}
}

@@ -984,3 +1011,3 @@

// actual call for the request
return handleRestRequest(request, 'nomap', healthSchema, callProperties, callback);
return handleRestRequest(request, 'nomap', healthSchema, callProperties, filter, callback);
}

@@ -987,0 +1014,0 @@

{
"name": "@itentialopensource/adapter-utils",
"version": "4.8.4",
"version": "4.9.0",
"description": "Itential Adapter Utility Libraries",

@@ -32,2 +32,3 @@ "scripts": {

"https-proxy-agent": "^2.2.1",
"json-query": "^2.2.2",
"mongodb": "^2.2.33",

@@ -34,0 +35,0 @@ "querystring": "^0.2.0",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc