@itentialopensource/adapter-utils 5.6.0 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lib/connectorRest.js +46 -19
- package/lib/propertyUtil.js +6 -4
- package/lib/restHandler.js +46 -63
- package/package.json +1 -2
- package/refs?service=git-upload-pack +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
|
|
2
|
+
## 5.7.1 [09-06-2024]
|
|
3
|
+
|
|
4
|
+
* Update zlib library to node native
|
|
5
|
+
|
|
6
|
+
See merge request itentialopensource/adapter-utils!299
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 5.7.0 [08-21-2024]
|
|
11
|
+
|
|
12
|
+
* Update gzip logic
|
|
13
|
+
|
|
14
|
+
See merge request itentialopensource/adapter-utils!297
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
2
18
|
## 5.6.0 [07-31-2024]
|
|
3
19
|
|
|
4
20
|
* Add abilities to refresh token and set msa query
|
package/lib/connectorRest.js
CHANGED
|
@@ -780,34 +780,61 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
|
|
|
780
780
|
// make the call to System
|
|
781
781
|
const httpRequest = useProt.request(request.header, (res) => {
|
|
782
782
|
let respStr = '';
|
|
783
|
-
res.
|
|
784
|
-
|
|
783
|
+
if (res.headers['content-encoding'] !== 'gzip') {
|
|
784
|
+
res.setEncoding('utf8');
|
|
785
|
+
}
|
|
786
|
+
const chunks = [];
|
|
785
787
|
// process data from response
|
|
786
788
|
res.on('data', (replyData) => {
|
|
789
|
+
chunks.push(replyData);
|
|
787
790
|
respStr += replyData;
|
|
788
791
|
});
|
|
789
792
|
|
|
790
793
|
// process end of response
|
|
791
794
|
res.on('end', () => {
|
|
795
|
+
let buffer = '';
|
|
796
|
+
if (res.headers['content-encoding'] === 'gzip') {
|
|
797
|
+
buffer = Buffer.concat(chunks);
|
|
798
|
+
}
|
|
799
|
+
|
|
792
800
|
const tripDiff = process.hrtime(roundTTime);
|
|
793
801
|
const tripEnd = `${Math.round(((tripDiff[0] * NS_PER_SEC) + tripDiff[1]) / 1000000)}ms`;
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
802
|
+
let callResp = {};
|
|
803
|
+
if (res.headers['content-encoding'] === 'gzip') {
|
|
804
|
+
callResp = {
|
|
805
|
+
status: 'success',
|
|
806
|
+
code: res.statusCode,
|
|
807
|
+
headers: res.headers,
|
|
808
|
+
response: buffer,
|
|
809
|
+
request: {
|
|
810
|
+
protocol: protStr,
|
|
811
|
+
host: request.header.hostname,
|
|
812
|
+
port: request.header.port,
|
|
813
|
+
uri: request.header.path,
|
|
814
|
+
method: request.header.method,
|
|
815
|
+
payload: request.body
|
|
816
|
+
},
|
|
817
|
+
redirects: attempt,
|
|
818
|
+
tripTime: tripEnd
|
|
819
|
+
};
|
|
820
|
+
} else {
|
|
821
|
+
callResp = {
|
|
822
|
+
status: 'success',
|
|
823
|
+
code: res.statusCode,
|
|
824
|
+
headers: res.headers,
|
|
825
|
+
response: respStr,
|
|
826
|
+
request: {
|
|
827
|
+
protocol: protStr,
|
|
828
|
+
host: request.header.hostname,
|
|
829
|
+
port: request.header.port,
|
|
830
|
+
uri: request.header.path,
|
|
831
|
+
method: request.header.method,
|
|
832
|
+
payload: request.body
|
|
833
|
+
},
|
|
834
|
+
redirects: attempt,
|
|
835
|
+
tripTime: tripEnd
|
|
836
|
+
};
|
|
837
|
+
}
|
|
811
838
|
// if there was a cookie or biscotti returned, need to set cookie on the new request
|
|
812
839
|
if (request.header.headers) {
|
|
813
840
|
const headKeys = Object.keys(request.header.headers);
|
package/lib/propertyUtil.js
CHANGED
|
@@ -534,8 +534,8 @@ class AdapterPropertyUtil {
|
|
|
534
534
|
}
|
|
535
535
|
if (entitySchema.responseDatatype.toUpperCase() !== 'JSON' && entitySchema.responseDatatype.toUpperCase() !== 'XML'
|
|
536
536
|
&& entitySchema.responseDatatype.toUpperCase() !== 'URLENCODE' && entitySchema.responseDatatype.toUpperCase() !== 'XML2JSON'
|
|
537
|
-
&& entitySchema.
|
|
538
|
-
&& entitySchema.
|
|
537
|
+
&& entitySchema.responseDatatype.toUpperCase() !== 'GZIP2XML2JSON' && entitySchema.responseDatatype.toUpperCase() !== 'GZIP2XML'
|
|
538
|
+
&& entitySchema.responseDatatype.toUpperCase() !== 'GZIP2JSON' && entitySchema.responseDatatype.toUpperCase() !== 'GZIP2PLAIN') {
|
|
539
539
|
entitySchema.responseDatatype = 'PLAIN';
|
|
540
540
|
}
|
|
541
541
|
|
|
@@ -952,7 +952,9 @@ class AdapterPropertyUtil {
|
|
|
952
952
|
entitySchema.requestDatatype = 'PLAIN';
|
|
953
953
|
}
|
|
954
954
|
if (entitySchema.responseDatatype.toUpperCase() !== 'JSON' && entitySchema.responseDatatype.toUpperCase() !== 'XML'
|
|
955
|
-
&& entitySchema.responseDatatype.toUpperCase() !== 'URLENCODE' && entitySchema.responseDatatype.toUpperCase() !== 'XML2JSON'
|
|
955
|
+
&& entitySchema.responseDatatype.toUpperCase() !== 'URLENCODE' && entitySchema.responseDatatype.toUpperCase() !== 'XML2JSON'
|
|
956
|
+
&& entitySchema.responseDatatype.toUpperCase() !== 'GZIP2XML2JSON' && entitySchema.responseDatatype.toUpperCase() !== 'GZIP2XML'
|
|
957
|
+
&& entitySchema.responseDatatype.toUpperCase() !== 'GZIP2JSON' && entitySchema.responseDatatype.toUpperCase() !== 'GZIP2PLAIN') {
|
|
956
958
|
entitySchema.responseDatatype = 'PLAIN';
|
|
957
959
|
}
|
|
958
960
|
|
|
@@ -1151,7 +1153,7 @@ class AdapterPropertyUtil {
|
|
|
1151
1153
|
}
|
|
1152
1154
|
|
|
1153
1155
|
// This is the array of sensitive keys
|
|
1154
|
-
let sensList = ['authorization', 'x-auth-token', 'x-csrf-token', 'x-amz-security-token', 'x-aws-ec2-metadata-token', 'cookie', 'set-cookie', 'token', 'tokenp2', 'user', 'username', 'passwd', 'password', 'api-key', 'client-id', 'client-secret', 'session', 'session-id', 'jsessionid'];
|
|
1156
|
+
let sensList = ['authorization', 'x-auth-token', 'x-csrf-token', 'x-amz-security-token', 'x-aws-ec2-metadata-token', 'cookie', 'set-cookie', 'token', 'tokenp2', 'user', 'username', 'passwd', 'password', 'api-key', 'client-id', 'client-secret', 'client_id', 'client_secret', 'session', 'session-id', 'jsessionid'];
|
|
1155
1157
|
|
|
1156
1158
|
// add any additional items to scrub
|
|
1157
1159
|
if (addItems && Array.isArray(addItems) && addItems.length > 0) {
|
package/lib/restHandler.js
CHANGED
|
@@ -8,7 +8,7 @@ const querystring = require('querystring');
|
|
|
8
8
|
const jsonQuery = require('json-query');
|
|
9
9
|
const jsonxml = require('jsontoxml');
|
|
10
10
|
const xml2js = require('xml2js');
|
|
11
|
-
const
|
|
11
|
+
const zlib = require('node:zlib');
|
|
12
12
|
|
|
13
13
|
const globalSchema = JSON.parse(require('fs').readFileSync(require('path').join(__dirname, '/../schemas/globalSchema.json')));
|
|
14
14
|
|
|
@@ -53,19 +53,6 @@ function matchResponse(uriPath, method, type, mockresponses) {
|
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/*
|
|
57
|
-
* INTERNAL FUNCTION: Parse XML
|
|
58
|
-
*/
|
|
59
|
-
function parseXML(xmlString, callback) {
|
|
60
|
-
const parser = new xml2js.Parser({ explicitArray: false, attrkey: '_attr' });
|
|
61
|
-
parser.parseString(xmlString, (error, result) => {
|
|
62
|
-
if (error) {
|
|
63
|
-
return callback(error);
|
|
64
|
-
}
|
|
65
|
-
return callback(null, result);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
56
|
/*
|
|
70
57
|
* INTERNAL FUNCTION: recursively inspect body data if heirarchical
|
|
71
58
|
*/
|
|
@@ -491,62 +478,58 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
491
478
|
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'URLENCODE') {
|
|
492
479
|
// return the response
|
|
493
480
|
retResponse = querystring.parse(resObj.response.trim());
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|| entitySchema.responseDatatype.toUpperCase() === 'GZIP2XML2JSON')) {
|
|
497
|
-
// If response is GZIP
|
|
481
|
+
} if (entitySchema && entitySchema.responseDatatype
|
|
482
|
+
&& ['GZIP2PLAIN', 'GZIP2JSON', 'GZIP2XML', 'GZIP2XML2JSON'].includes(entitySchema.responseDatatype.toUpperCase())) {
|
|
498
483
|
const responseDatatype = entitySchema.responseDatatype.toUpperCase();
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
484
|
+
|
|
485
|
+
return zlib.gunzip(resObj.response, (err, unzipresponse) => {
|
|
486
|
+
if (err) {
|
|
487
|
+
log.warn(`${origin}: Error inflating gzip response: ${err}`);
|
|
488
|
+
return callback(retObject);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const responseBody = unzipresponse.toString('utf8'); // Convert buffer to string
|
|
492
|
+
if (responseDatatype === 'GZIP2PLAIN') {
|
|
493
|
+
retObject.response = responseBody;
|
|
494
|
+
log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
495
|
+
return callback(retObject);
|
|
496
|
+
} if (responseDatatype === 'GZIP2JSON') {
|
|
497
|
+
try {
|
|
498
|
+
retObject.response = JSON.parse(responseBody);
|
|
499
|
+
log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
500
|
+
return callback(retObject); // Parse responseBody as JSON
|
|
501
|
+
} catch (jsonErr) {
|
|
502
|
+
log.warn(`${origin}: Error parsing JSON response: ${jsonErr}`);
|
|
510
503
|
return callback(retObject);
|
|
511
504
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
// Optionally convert XML to JSON
|
|
517
|
-
try {
|
|
518
|
-
const parser = new xml2js.Parser({ explicitArray: false, attrkey: '_attr' });
|
|
519
|
-
return parser.parseString(xmlResult, (err, result) => {
|
|
520
|
-
if (err) {
|
|
521
|
-
log.warn(`${origin}: Unable to parse xml to json ${err}`);
|
|
522
|
-
return callback(retObject);
|
|
523
|
-
}
|
|
524
|
-
// Logic to convert keys specified to array if object
|
|
525
|
-
if (xmlArrayKeys) {
|
|
526
|
-
setArrays(result, xmlArrayKeys);
|
|
527
|
-
}
|
|
528
|
-
retObject.response = result;
|
|
529
|
-
return callback(retObject);
|
|
530
|
-
});
|
|
531
|
-
} catch (ex) {
|
|
532
|
-
log.warn(`${origin}: Unable to get json from xml ${ex}`);
|
|
505
|
+
} else if (responseDatatype === 'GZIP2XML' || responseDatatype === 'GZIP2XML2JSON') {
|
|
506
|
+
xml2js.parseString(responseBody, { explicitArray: false, attrkey: '_attr' }, (xmlErr, xmlResult) => {
|
|
507
|
+
if (xmlErr) {
|
|
508
|
+
log.warn(`${origin}: Error parsing XML response: ${xmlErr}`);
|
|
533
509
|
return callback(retObject);
|
|
534
510
|
}
|
|
535
|
-
}
|
|
536
511
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
512
|
+
retObject.response = xmlResult;
|
|
513
|
+
|
|
514
|
+
if (responseDatatype === 'GZIP2XML2JSON') {
|
|
515
|
+
// Optionally convert XML to JSON, already done above by xml2js
|
|
516
|
+
if (xmlArrayKeys) {
|
|
517
|
+
setArrays(retObject.response, xmlArrayKeys); // Handle array conversion
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return callback(retObject);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
548
523
|
return callback(retObject);
|
|
549
|
-
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
// process the response - parse it
|
|
527
|
+
try {
|
|
528
|
+
retResponse = JSON.parse(resObj.response.trim());
|
|
529
|
+
} catch (ex) {
|
|
530
|
+
// otherwise log parse failure and return the unparsed response
|
|
531
|
+
log.warn(`${origin}: An error occurred parsing the resulting JSON: ${ex}: Actual Response is: ${resObj}`);
|
|
532
|
+
return callback(retObject);
|
|
550
533
|
}
|
|
551
534
|
|
|
552
535
|
// Make the call to translate the received Entity to Pronghorn Entity
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"description": "Itential Adapter Utility Libraries",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"postinstall": "node utils/setup.js",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"jsontoxml": "^1.0.1",
|
|
40
40
|
"jsonwebtoken": "^9.0.1",
|
|
41
41
|
"mongodb": "^3.7.4",
|
|
42
|
-
"pako": "^2.1.0",
|
|
43
42
|
"querystring": "^0.2.0",
|
|
44
43
|
"readline-sync": "^1.4.10",
|
|
45
44
|
"socks-proxy-agent": "^8.0.1",
|
|
Binary file
|