@itentialopensource/adapter-utils 4.48.14 → 4.48.16
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 +20 -0
- package/lib/connectorRest.js +7 -0
- package/lib/propertyUtil.js +19 -17
- package/lib/restHandler.js +14 -2
- package/lib/translatorUtil.js +16 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
|
|
2
|
+
## 4.48.16 [05-10-2023]
|
|
3
|
+
|
|
4
|
+
* Fix issue of instantiating AJV, also mock data fix for generic call
|
|
5
|
+
|
|
6
|
+
Closes ADAPT-2511
|
|
7
|
+
|
|
8
|
+
See merge request itentialopensource/adapter-utils!243
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 4.48.15 [05-09-2023]
|
|
13
|
+
|
|
14
|
+
* Add healthcheck headers to adapter properties
|
|
15
|
+
|
|
16
|
+
Closes ADAPT-2662
|
|
17
|
+
|
|
18
|
+
See merge request itentialopensource/adapter-utils!256
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
2
22
|
## 4.48.14 [05-09-2023]
|
|
3
23
|
|
|
4
24
|
* modified connectorRest.js so that if there is a field named 'ca_file_content'...
|
package/lib/connectorRest.js
CHANGED
|
@@ -451,6 +451,13 @@ function returnStub(request, entitySchema, callProperties) {
|
|
|
451
451
|
const uriArray = uriTemp[0].split('/');
|
|
452
452
|
const actArray = actTemp[0].split('/');
|
|
453
453
|
|
|
454
|
+
// if this is one of the generic requests need to pad the actual array or mock data for specific path variable will not work
|
|
455
|
+
if (entitySchema.entitypath.indexOf('/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}') >= 0) {
|
|
456
|
+
for (let e = actArray.length; e < uriArray.length; e += 1) {
|
|
457
|
+
actArray.push('');
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
454
461
|
// the number of items in both should be the same
|
|
455
462
|
if (uriArray.length === actArray.length) {
|
|
456
463
|
for (let i = 0; i < uriArray.length; i += 1) {
|
package/lib/propertyUtil.js
CHANGED
|
@@ -256,6 +256,7 @@ class AdapterPropertyUtil {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// Merge the information into the entity schema
|
|
259
|
+
entitySchema.name = actionName;
|
|
259
260
|
entitySchema.protocol = actionInfo.protocol;
|
|
260
261
|
entitySchema.method = actionInfo.method;
|
|
261
262
|
entitySchema.timeout = actionInfo.timeout;
|
|
@@ -441,7 +442,7 @@ class AdapterPropertyUtil {
|
|
|
441
442
|
// add the specific pieces of the error object
|
|
442
443
|
errorObj.type = 'Missing Data';
|
|
443
444
|
errorObj.vars = ['Entity'];
|
|
444
|
-
log.
|
|
445
|
+
log.debug(`${origin}: Entity is required to get entity schema for action`);
|
|
445
446
|
errorObj.error = [`${origin}: Entity is required to get entity schema for action`];
|
|
446
447
|
return callback(null, errorObj);
|
|
447
448
|
}
|
|
@@ -452,7 +453,7 @@ class AdapterPropertyUtil {
|
|
|
452
453
|
|
|
453
454
|
// log (if not system entity) and return the error
|
|
454
455
|
if (entityName !== '.system') {
|
|
455
|
-
log.
|
|
456
|
+
log.debug(`${origin}: Action is required to get entity schema for action`);
|
|
456
457
|
errorObj.error = [`${origin}: Action is required to get entity schema for action`];
|
|
457
458
|
}
|
|
458
459
|
return callback(null, errorObj);
|
|
@@ -475,7 +476,7 @@ class AdapterPropertyUtil {
|
|
|
475
476
|
// add the specific pieces of the error object
|
|
476
477
|
errorObj.type = 'Database Error';
|
|
477
478
|
errorObj.vars = ['dbError'];
|
|
478
|
-
log.
|
|
479
|
+
log.debug(`${origin}: Database Error: ${dbError}`);
|
|
479
480
|
errorObj.error = [`${origin}: Database Error: ${dbError}`];
|
|
480
481
|
return callback(null, errorObj);
|
|
481
482
|
}
|
|
@@ -483,7 +484,7 @@ class AdapterPropertyUtil {
|
|
|
483
484
|
// add the specific pieces of the error object
|
|
484
485
|
errorObj.type = 'Missing Data';
|
|
485
486
|
errorObj.vars = ['Entity'];
|
|
486
|
-
log.
|
|
487
|
+
log.debug(`${origin}: Entity was not found in the database`);
|
|
487
488
|
errorObj.error = [`${origin}: Entity was not found in the database`];
|
|
488
489
|
return callback(null, errorObj);
|
|
489
490
|
}
|
|
@@ -499,7 +500,7 @@ class AdapterPropertyUtil {
|
|
|
499
500
|
|
|
500
501
|
// log (if not system entity) and return the error
|
|
501
502
|
if (entityName !== '.system') {
|
|
502
|
-
log.
|
|
503
|
+
log.warn(`${origin}: Invalid entity action file, please verify file: ${entityName}`);
|
|
503
504
|
errorObj.error = [`${origin}: Invalid entity action file, please verify file: ${entityName}`];
|
|
504
505
|
}
|
|
505
506
|
return callback(null, errorObj);
|
|
@@ -511,7 +512,7 @@ class AdapterPropertyUtil {
|
|
|
511
512
|
|
|
512
513
|
// log (if not system entity) and return the error
|
|
513
514
|
if (entityName !== '.system') {
|
|
514
|
-
log.
|
|
515
|
+
log.warn(`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`);
|
|
515
516
|
errorObj.error = [`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`];
|
|
516
517
|
}
|
|
517
518
|
return callback(null, errorObj);
|
|
@@ -534,7 +535,7 @@ class AdapterPropertyUtil {
|
|
|
534
535
|
|
|
535
536
|
// log (if not system entity) and return the error
|
|
536
537
|
if (entityName !== '.system') {
|
|
537
|
-
log.
|
|
538
|
+
log.warn(`${origin}: Entity ${entityName} - action file missing action: ${actionName}`);
|
|
538
539
|
errorObj.error = [`${origin}: Entity ${entityName} - action file missing action: ${actionName}`];
|
|
539
540
|
}
|
|
540
541
|
return callback(null, errorObj);
|
|
@@ -548,7 +549,7 @@ class AdapterPropertyUtil {
|
|
|
548
549
|
|
|
549
550
|
// log (if not system entity) and return the error
|
|
550
551
|
if (entityName !== '.system') {
|
|
551
|
-
log.
|
|
552
|
+
log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing protocol`);
|
|
552
553
|
errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing protocol`];
|
|
553
554
|
}
|
|
554
555
|
return callback(null, errorObj);
|
|
@@ -560,7 +561,7 @@ class AdapterPropertyUtil {
|
|
|
560
561
|
|
|
561
562
|
// log (if not system entity) and return the error
|
|
562
563
|
if (entityName !== '.system') {
|
|
563
|
-
log.
|
|
564
|
+
log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing method`);
|
|
564
565
|
errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing method`];
|
|
565
566
|
}
|
|
566
567
|
return callback(null, errorObj);
|
|
@@ -572,7 +573,7 @@ class AdapterPropertyUtil {
|
|
|
572
573
|
|
|
573
574
|
// log (if not system entity) and return the error
|
|
574
575
|
if (entityName !== '.system') {
|
|
575
|
-
log.
|
|
576
|
+
log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
|
|
576
577
|
errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing entity path`];
|
|
577
578
|
}
|
|
578
579
|
return callback(null, errorObj);
|
|
@@ -584,7 +585,7 @@ class AdapterPropertyUtil {
|
|
|
584
585
|
|
|
585
586
|
// log (if not system entity) and return the error
|
|
586
587
|
if (entityName !== '.system') {
|
|
587
|
-
log.
|
|
588
|
+
log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing schema`);
|
|
588
589
|
errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing schema`];
|
|
589
590
|
}
|
|
590
591
|
return callback(null, errorObj);
|
|
@@ -610,7 +611,7 @@ class AdapterPropertyUtil {
|
|
|
610
611
|
|
|
611
612
|
// log (if not system entity) and return the error
|
|
612
613
|
if (entityName !== '.system') {
|
|
613
|
-
log.
|
|
614
|
+
log.warn(`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`);
|
|
614
615
|
errorObj.error = [`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`];
|
|
615
616
|
}
|
|
616
617
|
return callback(null, errorObj);
|
|
@@ -637,7 +638,7 @@ class AdapterPropertyUtil {
|
|
|
637
638
|
|
|
638
639
|
// log (if not system entity) and return the error
|
|
639
640
|
if (entityName !== '.system') {
|
|
640
|
-
log.
|
|
641
|
+
log.warn(`${origin}: Could not find file - ${reqSchemaName}`);
|
|
641
642
|
errorObj.error = [`${origin}: Could not find file - ${reqSchemaName}`];
|
|
642
643
|
}
|
|
643
644
|
return callback(null, errorObj);
|
|
@@ -651,7 +652,7 @@ class AdapterPropertyUtil {
|
|
|
651
652
|
|
|
652
653
|
// log (if not system entity) and return the error
|
|
653
654
|
if (entityName !== '.system') {
|
|
654
|
-
log.
|
|
655
|
+
log.warn(`${origin}: Could not find file - ${respSchemaName}`);
|
|
655
656
|
errorObj.error = [`${origin}: Could not find file - ${respSchemaName}`];
|
|
656
657
|
}
|
|
657
658
|
return callback(null, errorObj);
|
|
@@ -665,7 +666,7 @@ class AdapterPropertyUtil {
|
|
|
665
666
|
|
|
666
667
|
// log (if not system entity) and return the error
|
|
667
668
|
if (entityName !== '.system') {
|
|
668
|
-
log.
|
|
669
|
+
log.warn(`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`);
|
|
669
670
|
errorObj.error = [`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`];
|
|
670
671
|
}
|
|
671
672
|
return callback(null, errorObj);
|
|
@@ -677,7 +678,7 @@ class AdapterPropertyUtil {
|
|
|
677
678
|
|
|
678
679
|
// log (if not system entity) and return the error
|
|
679
680
|
if (entityName !== '.system') {
|
|
680
|
-
log.
|
|
681
|
+
log.warn(`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`);
|
|
681
682
|
errorObj.error = [`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`];
|
|
682
683
|
}
|
|
683
684
|
return callback(null, errorObj);
|
|
@@ -690,6 +691,7 @@ class AdapterPropertyUtil {
|
|
|
690
691
|
};
|
|
691
692
|
|
|
692
693
|
// Merge the information into the entity schema
|
|
694
|
+
entitySchema.name = actionName;
|
|
693
695
|
entitySchema.protocol = actionInfo.protocol;
|
|
694
696
|
entitySchema.method = actionInfo.method;
|
|
695
697
|
entitySchema.timeout = actionInfo.timeout;
|
|
@@ -718,7 +720,7 @@ class AdapterPropertyUtil {
|
|
|
718
720
|
|
|
719
721
|
// log (if not system entity) and return the error
|
|
720
722
|
if (entityName !== '.system') {
|
|
721
|
-
log.
|
|
723
|
+
log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
|
|
722
724
|
errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing entity path`];
|
|
723
725
|
}
|
|
724
726
|
return callback(null, errorObj);
|
package/lib/restHandler.js
CHANGED
|
@@ -24,6 +24,7 @@ let encodePath = true;
|
|
|
24
24
|
let encodeUri = true;
|
|
25
25
|
let stripEscapes = false;
|
|
26
26
|
let returnResponseHeaders = true;
|
|
27
|
+
let healthcheckHeaders = null;
|
|
27
28
|
// INTERNAL FUNCTIONS
|
|
28
29
|
/*
|
|
29
30
|
* INTERNAL FUNCTION: Get the best match for the mock data response
|
|
@@ -175,7 +176,7 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
175
176
|
retError = JSON.parse(perror.response.trim());
|
|
176
177
|
} catch (ex) {
|
|
177
178
|
// otherwise log parse failure but still return the unparsed error
|
|
178
|
-
log.
|
|
179
|
+
log.warn(`${origin}: An error occurred parsing the error JSON: ${ex}: Error Response is: ${perror}`);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
@@ -428,7 +429,7 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
428
429
|
retResponse = JSON.parse(resObj.response.trim());
|
|
429
430
|
} catch (ex) {
|
|
430
431
|
// otherwise log parse failure and return the unparsed response
|
|
431
|
-
log.warn(`${origin}: An error occurred parsing the resulting JSON: ${ex}`);
|
|
432
|
+
log.warn(`${origin}: An error occurred parsing the resulting JSON: ${ex}: Actual Response is: ${resObj}`);
|
|
432
433
|
return callback(retObject);
|
|
433
434
|
}
|
|
434
435
|
}
|
|
@@ -825,6 +826,13 @@ function mergeHeaders(addlHeaders, entitySchema) {
|
|
|
825
826
|
thisAHdata = transUtilInst.mergeObjects(thisAHdata, entitySchema.headers);
|
|
826
827
|
}
|
|
827
828
|
|
|
829
|
+
// add healthcheck headers if there are healthcheck headers to add
|
|
830
|
+
if (entitySchema && entitySchema.name === 'healthcheck') {
|
|
831
|
+
if (healthcheckHeaders && Object.keys(healthcheckHeaders).length > 0) {
|
|
832
|
+
thisAHdata = transUtilInst.mergeObjects(thisAHdata, healthcheckHeaders);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
828
836
|
// only add global headers if there are global headers to add
|
|
829
837
|
if (globalRequestGl && globalRequestGl.addlHeaders && Object.keys(globalRequestGl.addlHeaders).length > 0) {
|
|
830
838
|
thisAHdata = transUtilInst.mergeObjects(thisAHdata, globalRequestGl.addlHeaders);
|
|
@@ -1051,6 +1059,10 @@ class RestHandler {
|
|
|
1051
1059
|
if (typeof properties.request.returnResponseHeaders === 'boolean') {
|
|
1052
1060
|
returnResponseHeaders = properties.request.returnResponseHeaders;
|
|
1053
1061
|
}
|
|
1062
|
+
|
|
1063
|
+
if (properties.healthcheck && typeof properties.healthcheck.addlHeaders === 'object') {
|
|
1064
|
+
healthcheckHeaders = properties.healthcheck.addlHeaders;
|
|
1065
|
+
}
|
|
1054
1066
|
}
|
|
1055
1067
|
|
|
1056
1068
|
/**
|
package/lib/translatorUtil.js
CHANGED
|
@@ -423,7 +423,7 @@ function parseFields(retObject, dataSchema) {
|
|
|
423
423
|
*
|
|
424
424
|
* @return {Object} the IAP Entity
|
|
425
425
|
*/
|
|
426
|
-
function extractJSONEntity(dataObj, entitySchema) {
|
|
426
|
+
function extractJSONEntity(dataObj, entitySchema, ajvInstance) {
|
|
427
427
|
const origin = `${id}-translatorUtil-extractJSONEntity`;
|
|
428
428
|
log.trace(origin);
|
|
429
429
|
const returnObj = extractObject(dataObj, entitySchema, false);
|
|
@@ -433,7 +433,10 @@ function extractJSONEntity(dataObj, entitySchema) {
|
|
|
433
433
|
let combinedEntity = propUtilInst.mergeProperties(returnObj, propUtilInst.setDefaults(entitySchema));
|
|
434
434
|
|
|
435
435
|
// validate the entity against the schema
|
|
436
|
-
|
|
436
|
+
let ajvInst = ajvInstance;
|
|
437
|
+
if (!ajvInst) {
|
|
438
|
+
ajvInst = new AjvCl();
|
|
439
|
+
}
|
|
437
440
|
const validate = ajvInst.compile(entitySchema);
|
|
438
441
|
const result = validate(combinedEntity);
|
|
439
442
|
|
|
@@ -664,7 +667,7 @@ function buildObject(dataObj, entitySchema, dynamicFields) {
|
|
|
664
667
|
*
|
|
665
668
|
* @return {Object} the Entity for the other system
|
|
666
669
|
*/
|
|
667
|
-
function buildJSONEntity(dataObj, entitySchema) {
|
|
670
|
+
function buildJSONEntity(dataObj, entitySchema, ajvInstance) {
|
|
668
671
|
const origin = `${id}-translatorUtil-buildJSONEntity`;
|
|
669
672
|
log.trace(origin);
|
|
670
673
|
|
|
@@ -673,7 +676,10 @@ function buildJSONEntity(dataObj, entitySchema) {
|
|
|
673
676
|
const combinedEntity = propUtilInst.mergeProperties(dataObj, propUtilInst.setDefaults(entitySchema));
|
|
674
677
|
|
|
675
678
|
// validate the entity against the schema
|
|
676
|
-
|
|
679
|
+
let ajvInst = ajvInstance;
|
|
680
|
+
if (!ajvInst) {
|
|
681
|
+
ajvInst = new AjvCl();
|
|
682
|
+
}
|
|
677
683
|
const validate = ajvInst.compile(entitySchema);
|
|
678
684
|
const result = validate(combinedEntity);
|
|
679
685
|
|
|
@@ -789,6 +795,7 @@ class AdapterTranslatorUtil {
|
|
|
789
795
|
|
|
790
796
|
// make sure we are working with a JSON object instead of strigified object
|
|
791
797
|
const transObj = this.formatInputData(inEntity);
|
|
798
|
+
const ajvInst = new AjvCl();
|
|
792
799
|
|
|
793
800
|
// if an array of Entities, just translate the data (no objects)
|
|
794
801
|
if (Array.isArray(transObj)) {
|
|
@@ -798,7 +805,7 @@ class AdapterTranslatorUtil {
|
|
|
798
805
|
// is this just an array of data or something that needs to be translated?
|
|
799
806
|
if (typeof transObj[i] === 'object') {
|
|
800
807
|
// move the fields we care about into a IAP Entity Object
|
|
801
|
-
outEntities.push(extractJSONEntity(transObj[i], entitySchema));
|
|
808
|
+
outEntities.push(extractJSONEntity(transObj[i], entitySchema, ajvInst));
|
|
802
809
|
} else {
|
|
803
810
|
outEntities.push(transObj[i]);
|
|
804
811
|
}
|
|
@@ -809,7 +816,7 @@ class AdapterTranslatorUtil {
|
|
|
809
816
|
|
|
810
817
|
// if a single System Entity, should translate data and get value for objects
|
|
811
818
|
// move the fields we care about into a IAP Entity Object
|
|
812
|
-
return extractJSONEntity(transObj, entitySchema);
|
|
819
|
+
return extractJSONEntity(transObj, entitySchema, ajvInst);
|
|
813
820
|
} catch (e) {
|
|
814
821
|
return this.checkAndThrow(e, origin, 'Issue mapping from outbound entity');
|
|
815
822
|
}
|
|
@@ -870,6 +877,7 @@ class AdapterTranslatorUtil {
|
|
|
870
877
|
|
|
871
878
|
// make sure we are working with a JSON object instead of strigified object
|
|
872
879
|
const transObj = this.formatInputData(outEntity);
|
|
880
|
+
const ajvInst = new AjvCl();
|
|
873
881
|
|
|
874
882
|
// if this is an array of Objects, translate each of the objects
|
|
875
883
|
if (Array.isArray(transObj)) {
|
|
@@ -877,7 +885,7 @@ class AdapterTranslatorUtil {
|
|
|
877
885
|
|
|
878
886
|
for (let i = 0; i < transObj.length; i += 1) {
|
|
879
887
|
// move the fields the other system cares about into the Object
|
|
880
|
-
retObjects.push(buildJSONEntity(transObj[i], entitySchema));
|
|
888
|
+
retObjects.push(buildJSONEntity(transObj[i], entitySchema, ajvInst));
|
|
881
889
|
}
|
|
882
890
|
|
|
883
891
|
return retObjects;
|
|
@@ -885,7 +893,7 @@ class AdapterTranslatorUtil {
|
|
|
885
893
|
|
|
886
894
|
// if a single Object, should translate data and get value for objects
|
|
887
895
|
// move the fields the other system cares about into the Object
|
|
888
|
-
return buildJSONEntity(transObj, entitySchema);
|
|
896
|
+
return buildJSONEntity(transObj, entitySchema, ajvInst);
|
|
889
897
|
} catch (e) {
|
|
890
898
|
return this.checkAndThrow(e, origin, 'Issue mapping to outbound entity');
|
|
891
899
|
}
|