@itentialopensource/adapter-utils 5.3.7 → 5.3.8
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 +10 -0
- package/lib/requestHandler.js +33 -18
- package/package.json +1 -1
- package/refs?service=git-upload-pack +0 -0
package/CHANGELOG.md
CHANGED
package/lib/requestHandler.js
CHANGED
|
@@ -84,14 +84,14 @@ function validateProperties(properties) {
|
|
|
84
84
|
|
|
85
85
|
// need to decode/decrypt the static token if it is encoded/encrypted
|
|
86
86
|
if (combinedProps.authentication && combinedProps.authentication.token
|
|
87
|
-
|
|
87
|
+
&& (combinedProps.authentication.token.indexOf('{code}') === 0
|
|
88
88
|
|| combinedProps.authentication.token.indexOf('{crypt}') === 0)) {
|
|
89
89
|
combinedProps.authentication.token = propUtilInst.decryptProperty(combinedProps.authentication.token);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// need to decode/decrypt the password if it is encoded/encrypted
|
|
93
93
|
if (combinedProps.authentication && combinedProps.authentication.password
|
|
94
|
-
|
|
94
|
+
&& (combinedProps.authentication.password.indexOf('{code}') === 0
|
|
95
95
|
|| combinedProps.authentication.password.indexOf('{crypt}') === 0)) {
|
|
96
96
|
combinedProps.authentication.password = propUtilInst.decryptProperty(combinedProps.authentication.password);
|
|
97
97
|
}
|
|
@@ -220,14 +220,14 @@ function walkThroughActionFiles(directory) {
|
|
|
220
220
|
|
|
221
221
|
// check that the action is in the schemas
|
|
222
222
|
if (!reqSchema || !reqSchema.properties || !reqSchema.properties.ph_request_type
|
|
223
|
-
|
|
223
|
+
|| !reqSchema.properties.ph_request_type.enum || !reqSchema.properties.ph_request_type.enum.includes(act.name)) {
|
|
224
224
|
let msg = `${origin}: Error on validation of actions for entity `;
|
|
225
225
|
msg += `${entities[e]}: ${act.name} - missing from ph_request_type in request schema`;
|
|
226
226
|
clean.push(msg);
|
|
227
227
|
log.warn(msg);
|
|
228
228
|
}
|
|
229
229
|
if (!respSchema || !respSchema.properties || !respSchema.properties.ph_request_type
|
|
230
|
-
|
|
230
|
+
|| !respSchema.properties.ph_request_type.enum || !respSchema.properties.ph_request_type.enum.includes(act.name)) {
|
|
231
231
|
let msg = `${origin}: Error on validation of actions for entity `;
|
|
232
232
|
msg += `${entities[e]}: ${act.name} - missing from ph_request_type in response schema`;
|
|
233
233
|
clean.push(msg);
|
|
@@ -348,9 +348,13 @@ function getDataFromSources(loopField, sources, props) {
|
|
|
348
348
|
// Check for field in adapter properties
|
|
349
349
|
if (!foundProp && props && props[loopField]) {
|
|
350
350
|
fieldValue = props[loopField];
|
|
351
|
+
foundProp = true;
|
|
351
352
|
}
|
|
352
353
|
|
|
353
|
-
|
|
354
|
+
if (foundProp) {
|
|
355
|
+
return fieldValue;
|
|
356
|
+
}
|
|
357
|
+
return null;
|
|
354
358
|
}
|
|
355
359
|
|
|
356
360
|
/**
|
|
@@ -394,7 +398,7 @@ function setConditionalValue(valueField, sources, props) {
|
|
|
394
398
|
let finalValue = operands[0]; // {name}
|
|
395
399
|
for (let i = 0; i < operandA.length; i += 1) {
|
|
396
400
|
const fieldValue = getDataFromSources(operandA[i], sources, props);
|
|
397
|
-
if (fieldValue === operandA[i]) {
|
|
401
|
+
if (fieldValue === operandA[i] || fieldValue === null) {
|
|
398
402
|
// did not find value - break here to try second part of conditional
|
|
399
403
|
[, finalValue] = operands;
|
|
400
404
|
break;
|
|
@@ -410,12 +414,11 @@ function setConditionalValue(valueField, sources, props) {
|
|
|
410
414
|
// Look for values for keys to the right of {||}
|
|
411
415
|
for (let j = 0; j < operandB.length; j += 1) {
|
|
412
416
|
const fieldValue = getDataFromSources(operandB[j], sources, props);
|
|
413
|
-
if (fieldValue === operandB[j]) {
|
|
417
|
+
if (fieldValue === operandB[j] || fieldValue === null) {
|
|
414
418
|
throw new Error(`Could not find value in sources for ${operandA} or ${operandB}`);
|
|
415
419
|
}
|
|
416
420
|
finalValue = finalValue.replace(`{${operandB[j]}}`, fieldValue);
|
|
417
421
|
}
|
|
418
|
-
|
|
419
422
|
return finalValue;
|
|
420
423
|
}
|
|
421
424
|
|
|
@@ -429,9 +432,10 @@ function setResponseDataFromSources(loopField, sources, props) {
|
|
|
429
432
|
for (let k = 0; k < keys.length; k += 1) {
|
|
430
433
|
const responseKey = keys[k];
|
|
431
434
|
const fieldValue = getDataFromSources(responseKey, sources, props);
|
|
432
|
-
|
|
435
|
+
if (fieldValue) {
|
|
436
|
+
myField = myField.replace(`{${responseKey}}`, fieldValue);
|
|
437
|
+
}
|
|
433
438
|
}
|
|
434
|
-
|
|
435
439
|
return myField;
|
|
436
440
|
}
|
|
437
441
|
|
|
@@ -510,7 +514,7 @@ class RequestHandler {
|
|
|
510
514
|
this.failoverCodes = [];
|
|
511
515
|
|
|
512
516
|
if (this.props.request && this.props.request.failover_codes
|
|
513
|
-
|
|
517
|
+
&& Array.isArray(this.props.request.failover_codes)) {
|
|
514
518
|
this.failoverCodes = this.props.request.failover_codes;
|
|
515
519
|
}
|
|
516
520
|
|
|
@@ -650,6 +654,9 @@ class RequestHandler {
|
|
|
650
654
|
const pathKeys = extractKeysFromBraces(uriPath);
|
|
651
655
|
for (let pathKey = 0; pathKey < pathKeys.length; pathKey += 1) {
|
|
652
656
|
const fieldValue = getDataFromSources(pathKeys[pathKey], sources, this.props);
|
|
657
|
+
if (fieldValue === null) {
|
|
658
|
+
return callback(null, `Value for path key {${pathKeys[pathKey]}} not found`);
|
|
659
|
+
}
|
|
653
660
|
uriPath = uriPath.replace(`{${pathKeys[pathKey]}}`, fieldValue);
|
|
654
661
|
}
|
|
655
662
|
}
|
|
@@ -667,6 +674,9 @@ class RequestHandler {
|
|
|
667
674
|
for (let m = 0; m < matches.length; m += 1) {
|
|
668
675
|
const queryKey = matches[m];
|
|
669
676
|
const fieldValue = getDataFromSources(queryKey, sources, this.props);
|
|
677
|
+
if (fieldValue === null) {
|
|
678
|
+
return callback(null, `Value for query key {${queryKey}} not found`);
|
|
679
|
+
}
|
|
670
680
|
callQuery[cpKeys[cp]] = callQuery[cpKeys[cp]].replace(`{${queryKey}}`, fieldValue);
|
|
671
681
|
}
|
|
672
682
|
}
|
|
@@ -678,9 +688,12 @@ class RequestHandler {
|
|
|
678
688
|
for (let cb = 0; cb < cbKeys.length; cb += 1) {
|
|
679
689
|
const matches = extractKeysFromBraces(callBody[cbKeys[cb]]);
|
|
680
690
|
for (let m = 0; m < matches.length; m += 1) {
|
|
681
|
-
|
|
691
|
+
// make any necessary changes to the query params
|
|
682
692
|
const bodyKey = matches[m];
|
|
683
693
|
const fieldValue = getDataFromSources(bodyKey, sources, this.props);
|
|
694
|
+
if (fieldValue === null) {
|
|
695
|
+
return callback(null, `Value for body key {${bodyKey}} not found`);
|
|
696
|
+
}
|
|
684
697
|
callBody[cbKeys[cb]] = callBody[cbKeys[cb]].replace(`{${bodyKey}}`, fieldValue);
|
|
685
698
|
}
|
|
686
699
|
}
|
|
@@ -695,6 +708,9 @@ class RequestHandler {
|
|
|
695
708
|
const headerKey = matches[m];
|
|
696
709
|
// make any necessary changes to the query params
|
|
697
710
|
const fieldValue = getDataFromSources(headerKey, sources, this.props);
|
|
711
|
+
if (fieldValue === null) {
|
|
712
|
+
return callback(null, `Value for header key {${headerKey}} not found`);
|
|
713
|
+
}
|
|
698
714
|
callHeaders[chKeys[ch]] = callQuery[chKeys[ch]].replace(`{${headerKey}}`, fieldValue);
|
|
699
715
|
}
|
|
700
716
|
}
|
|
@@ -756,7 +772,6 @@ class RequestHandler {
|
|
|
756
772
|
if (rfKeys[rf] !== 'ostypePrefix') {
|
|
757
773
|
// devResp removed due to conditional issues
|
|
758
774
|
let fieldValue = setResponseDataFromSources(callProps.responseFields[rfKeys[rf]], [thisDevice, callProps.requestFields]);
|
|
759
|
-
|
|
760
775
|
// if the field is ostype - need to add prefix
|
|
761
776
|
if (rfKeys[rf] === 'ostype' && typeof fieldValue === 'string') {
|
|
762
777
|
fieldValue = ostypePrefix + fieldValue;
|
|
@@ -920,15 +935,15 @@ class RequestHandler {
|
|
|
920
935
|
if (requestObj && requestObj.datatype) {
|
|
921
936
|
// must have a legitimate request data type
|
|
922
937
|
if (requestObj.datatype.request && (requestObj.datatype.request.toUpperCase() === 'JSON'
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
938
|
+
|| requestObj.datatype.request.toUpperCase() === 'XML' || requestObj.datatype.request.toUpperCase() === 'URLENCODE'
|
|
939
|
+
|| requestObj.datatype.request.toUpperCase() === 'URLQUERY' || requestObj.datatype.request.toUpperCase() === 'FORM'
|
|
940
|
+
|| requestObj.datatype.request.toUpperCase() === 'JSON2XML' || requestObj.datatype.request.toUpperCase() === 'PLAIN')) {
|
|
926
941
|
entitySchema.requestDatatype = requestObj.datatype.request;
|
|
927
942
|
}
|
|
928
943
|
// must have a legitimate response data type
|
|
929
944
|
if (requestObj.datatype.response && (requestObj.datatype.response.toUpperCase() === 'JSON'
|
|
930
|
-
|
|
931
|
-
|
|
945
|
+
|| requestObj.datatype.response.toUpperCase() === 'XML' || requestObj.datatype.response.toUpperCase() === 'URLENCODE'
|
|
946
|
+
|| requestObj.datatype.response.toUpperCase() === 'XML2JSON' || requestObj.datatype.response.toUpperCase() === 'PLAIN')) {
|
|
932
947
|
entitySchema.responseDatatype = requestObj.datatype.response;
|
|
933
948
|
}
|
|
934
949
|
}
|
package/package.json
CHANGED
|
Binary file
|