@itentialopensource/adapter-utils
Advanced tools
Comparing version 5.4.0 to 5.5.0
## 5.5.0 [05-30-2024] | ||
* Add support for gzip responsedatatype | ||
Closes ADAPT-3270 | ||
See merge request itentialopensource/adapter-utils!293 | ||
--- | ||
## 5.4.0 [04-26-2024] | ||
@@ -3,0 +13,0 @@ |
@@ -11,2 +11,3 @@ /* @copyright Itential, LLC 2018 */ | ||
const xml2js = require('xml2js'); | ||
const pako = require('pako'); | ||
@@ -57,2 +58,15 @@ const globalSchema = JSON.parse(require('fs').readFileSync(require('path').join(__dirname, '/../schemas/globalSchema.json'))); | ||
/* | ||
* INTERNAL FUNCTION: Parse XML | ||
*/ | ||
function parseXML(xmlString, callback) { | ||
const parser = new xml2js.Parser({ explicitArray: false, attrkey: '_attr' }); | ||
parser.parseString(xmlString, (error, result) => { | ||
if (error) { | ||
return callback(error); | ||
} | ||
return callback(null, result); | ||
}); | ||
} | ||
/* | ||
* INTERNAL FUNCTION: recursively inspect body data if heirarchical | ||
@@ -482,2 +496,49 @@ */ | ||
retResponse = querystring.parse(resObj.response.trim()); | ||
} else if (entitySchema && entitySchema.responseDatatype && (entitySchema.responseDatatype.toUpperCase() === 'GZIP2PLAIN' | ||
|| entitySchema.responseDatatype.toUpperCase() === 'GZIP2JSON' || entitySchema.responseDatatype.toUpperCase() === 'GZIP2XML' | ||
|| entitySchema.responseDatatype.toUpperCase() === 'GZIP2XML2JSON')) { | ||
// If response is GZIP | ||
const responseDatatype = entitySchema.responseDatatype.toUpperCase(); | ||
const responseBody = pako.inflate(Buffer.from(resObj.response, 'binary'), { to: 'string' }); | ||
// Handle conversion based on responseDatatype | ||
if (responseDatatype === 'GZIP2PLAIN') { | ||
retObject.response = responseBody; | ||
} else if (responseDatatype === 'GZIP2JSON') { | ||
// Parse responseBody as JSON | ||
retObject.response = JSON.parse(responseBody); | ||
} else if (responseDatatype === 'GZIP2XML' || responseDatatype === 'GZIP2XML2JSON') { | ||
parseXML(responseBody, (error, xmlResult) => { | ||
if (error) { | ||
log.warn(`${origin}: Error parsing XML response: ${error}`); | ||
return callback(retObject); | ||
} | ||
retObject.response = xmlResult; | ||
if (responseDatatype === 'GZIP2XML2JSON') { | ||
// Optionally convert XML to JSON | ||
try { | ||
const parser = new xml2js.Parser({ explicitArray: false, attrkey: '_attr' }); | ||
return parser.parseString(xmlResult, (err, result) => { | ||
if (err) { | ||
log.warn(`${origin}: Unable to parse xml to json ${err}`); | ||
return callback(retObject); | ||
} | ||
// Logic to convert keys specified to array if object | ||
if (xmlArrayKeys) { | ||
setArrays(result, xmlArrayKeys); | ||
} | ||
retObject.response = result; | ||
return callback(retObject); | ||
}); | ||
} catch (ex) { | ||
log.warn(`${origin}: Unable to get json from xml ${ex}`); | ||
return callback(retObject); | ||
} | ||
} | ||
log.debug(`${origin}: RESPONSE: ${retObject.response}`); | ||
return callback(retObject); | ||
}); | ||
} | ||
} else { | ||
@@ -484,0 +545,0 @@ // process the response - parse it |
{ | ||
"name": "@itentialopensource/adapter-utils", | ||
"version": "5.4.0", | ||
"version": "5.5.0", | ||
"description": "Itential Adapter Utility Libraries", | ||
@@ -34,3 +34,3 @@ "scripts": { | ||
"crypto-js": "^4.1.1", | ||
"ejs": "^3.1.9", | ||
"ejs": "^3.1.10", | ||
"form-data": "^4.0.0", | ||
@@ -43,2 +43,3 @@ "fs-extra": "^11.1.1", | ||
"mongodb": "^3.7.4", | ||
"pako": "^2.1.0", | ||
"querystring": "^0.2.0", | ||
@@ -64,4 +65,3 @@ "readline-sync": "^1.4.10", | ||
}, | ||
"peerDependencies": {}, | ||
"private": false | ||
} |
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
810075
16289
20
+ Addedpako@^2.1.0
+ Addedpako@2.1.0(transitive)
Updatedejs@^3.1.10