@itentialopensource/adapter-utils 4.48.15 → 4.49.0

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 CHANGED
@@ -1,4 +1,24 @@
1
1
 
2
+ ## 4.49.0 [05-15-2023]
3
+
4
+ * Resolve ADAPT-2362 - Adapter Inventory from Utils Perspective (still more in AdapterBase)
5
+
6
+ Closes ADAPT-2362
7
+
8
+ See merge request itentialopensource/adapter-utils!257
9
+
10
+ ---
11
+
12
+ ## 4.48.16 [05-10-2023]
13
+
14
+ * Fix issue of instantiating AJV, also mock data fix for generic call
15
+
16
+ Closes ADAPT-2511
17
+
18
+ See merge request itentialopensource/adapter-utils!243
19
+
20
+ ---
21
+
2
22
  ## 4.48.15 [05-09-2023]
3
23
 
4
24
  * Add healthcheck headers to adapter properties
@@ -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) {
@@ -442,7 +442,7 @@ class AdapterPropertyUtil {
442
442
  // add the specific pieces of the error object
443
443
  errorObj.type = 'Missing Data';
444
444
  errorObj.vars = ['Entity'];
445
- log.error(`${origin}: Entity is required to get entity schema for action`);
445
+ log.debug(`${origin}: Entity is required to get entity schema for action`);
446
446
  errorObj.error = [`${origin}: Entity is required to get entity schema for action`];
447
447
  return callback(null, errorObj);
448
448
  }
@@ -453,7 +453,7 @@ class AdapterPropertyUtil {
453
453
 
454
454
  // log (if not system entity) and return the error
455
455
  if (entityName !== '.system') {
456
- log.error(`${origin}: Action is required to get entity schema for action`);
456
+ log.debug(`${origin}: Action is required to get entity schema for action`);
457
457
  errorObj.error = [`${origin}: Action is required to get entity schema for action`];
458
458
  }
459
459
  return callback(null, errorObj);
@@ -476,7 +476,7 @@ class AdapterPropertyUtil {
476
476
  // add the specific pieces of the error object
477
477
  errorObj.type = 'Database Error';
478
478
  errorObj.vars = ['dbError'];
479
- log.error(`${origin}: Database Error: ${dbError}`);
479
+ log.debug(`${origin}: Database Error: ${dbError}`);
480
480
  errorObj.error = [`${origin}: Database Error: ${dbError}`];
481
481
  return callback(null, errorObj);
482
482
  }
@@ -484,7 +484,7 @@ class AdapterPropertyUtil {
484
484
  // add the specific pieces of the error object
485
485
  errorObj.type = 'Missing Data';
486
486
  errorObj.vars = ['Entity'];
487
- log.error(`${origin}: Entity was not found in the database`);
487
+ log.debug(`${origin}: Entity was not found in the database`);
488
488
  errorObj.error = [`${origin}: Entity was not found in the database`];
489
489
  return callback(null, errorObj);
490
490
  }
@@ -500,7 +500,7 @@ class AdapterPropertyUtil {
500
500
 
501
501
  // log (if not system entity) and return the error
502
502
  if (entityName !== '.system') {
503
- log.error(`${origin}: Invalid entity action file, please verify file: ${entityName}`);
503
+ log.warn(`${origin}: Invalid entity action file, please verify file: ${entityName}`);
504
504
  errorObj.error = [`${origin}: Invalid entity action file, please verify file: ${entityName}`];
505
505
  }
506
506
  return callback(null, errorObj);
@@ -512,7 +512,7 @@ class AdapterPropertyUtil {
512
512
 
513
513
  // log (if not system entity) and return the error
514
514
  if (entityName !== '.system') {
515
- log.error(`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`);
515
+ log.warn(`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`);
516
516
  errorObj.error = [`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`];
517
517
  }
518
518
  return callback(null, errorObj);
@@ -535,7 +535,7 @@ class AdapterPropertyUtil {
535
535
 
536
536
  // log (if not system entity) and return the error
537
537
  if (entityName !== '.system') {
538
- log.error(`${origin}: Entity ${entityName} - action file missing action: ${actionName}`);
538
+ log.warn(`${origin}: Entity ${entityName} - action file missing action: ${actionName}`);
539
539
  errorObj.error = [`${origin}: Entity ${entityName} - action file missing action: ${actionName}`];
540
540
  }
541
541
  return callback(null, errorObj);
@@ -549,7 +549,7 @@ class AdapterPropertyUtil {
549
549
 
550
550
  // log (if not system entity) and return the error
551
551
  if (entityName !== '.system') {
552
- log.error(`${origin}: Entity ${entityName} action ${actionName} - missing protocol`);
552
+ log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing protocol`);
553
553
  errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing protocol`];
554
554
  }
555
555
  return callback(null, errorObj);
@@ -561,7 +561,7 @@ class AdapterPropertyUtil {
561
561
 
562
562
  // log (if not system entity) and return the error
563
563
  if (entityName !== '.system') {
564
- log.error(`${origin}: Entity ${entityName} action ${actionName} - missing method`);
564
+ log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing method`);
565
565
  errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing method`];
566
566
  }
567
567
  return callback(null, errorObj);
@@ -573,7 +573,7 @@ class AdapterPropertyUtil {
573
573
 
574
574
  // log (if not system entity) and return the error
575
575
  if (entityName !== '.system') {
576
- log.error(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
576
+ log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
577
577
  errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing entity path`];
578
578
  }
579
579
  return callback(null, errorObj);
@@ -585,7 +585,7 @@ class AdapterPropertyUtil {
585
585
 
586
586
  // log (if not system entity) and return the error
587
587
  if (entityName !== '.system') {
588
- log.error(`${origin}: Entity ${entityName} action ${actionName} - missing schema`);
588
+ log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing schema`);
589
589
  errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing schema`];
590
590
  }
591
591
  return callback(null, errorObj);
@@ -611,7 +611,7 @@ class AdapterPropertyUtil {
611
611
 
612
612
  // log (if not system entity) and return the error
613
613
  if (entityName !== '.system') {
614
- log.error(`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`);
614
+ log.warn(`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`);
615
615
  errorObj.error = [`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`];
616
616
  }
617
617
  return callback(null, errorObj);
@@ -638,7 +638,7 @@ class AdapterPropertyUtil {
638
638
 
639
639
  // log (if not system entity) and return the error
640
640
  if (entityName !== '.system') {
641
- log.error(`${origin}: Could not find file - ${reqSchemaName}`);
641
+ log.warn(`${origin}: Could not find file - ${reqSchemaName}`);
642
642
  errorObj.error = [`${origin}: Could not find file - ${reqSchemaName}`];
643
643
  }
644
644
  return callback(null, errorObj);
@@ -652,7 +652,7 @@ class AdapterPropertyUtil {
652
652
 
653
653
  // log (if not system entity) and return the error
654
654
  if (entityName !== '.system') {
655
- log.error(`${origin}: Could not find file - ${respSchemaName}`);
655
+ log.warn(`${origin}: Could not find file - ${respSchemaName}`);
656
656
  errorObj.error = [`${origin}: Could not find file - ${respSchemaName}`];
657
657
  }
658
658
  return callback(null, errorObj);
@@ -666,7 +666,7 @@ class AdapterPropertyUtil {
666
666
 
667
667
  // log (if not system entity) and return the error
668
668
  if (entityName !== '.system') {
669
- log.error(`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`);
669
+ log.warn(`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`);
670
670
  errorObj.error = [`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`];
671
671
  }
672
672
  return callback(null, errorObj);
@@ -678,7 +678,7 @@ class AdapterPropertyUtil {
678
678
 
679
679
  // log (if not system entity) and return the error
680
680
  if (entityName !== '.system') {
681
- log.error(`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`);
681
+ log.warn(`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`);
682
682
  errorObj.error = [`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`];
683
683
  }
684
684
  return callback(null, errorObj);
@@ -720,7 +720,7 @@ class AdapterPropertyUtil {
720
720
 
721
721
  // log (if not system entity) and return the error
722
722
  if (entityName !== '.system') {
723
- log.error(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
723
+ log.warn(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);
724
724
  errorObj.error = [`${origin}: Entity ${entityName} action ${actionName} - missing entity path`];
725
725
  }
726
726
  return callback(null, errorObj);
@@ -1175,6 +1175,103 @@ class RequestHandler {
1175
1175
  return callback(null, errorObj);
1176
1176
  }
1177
1177
  }
1178
+
1179
+ /**
1180
+ * @summary provide inventory information abbout the adapter
1181
+ *
1182
+ * @function getAdapterInventory
1183
+ *
1184
+ * @return {Object} - containing the adapter inventory information
1185
+ */
1186
+ getAdapterInventory(callback) {
1187
+ const origin = `${this.myid}-requestHandler-getAdapterInventory`;
1188
+ log.trace(origin);
1189
+
1190
+ try {
1191
+ const adapterInv = {
1192
+ issues: {}
1193
+ };
1194
+
1195
+ // are the utils within the adapter
1196
+ if (__dirname.indexOf(this.directory) === 0) {
1197
+ adapterInv.issues.embedUtils = true;
1198
+ } else {
1199
+ adapterInv.issues.embedUtils = false;
1200
+ }
1201
+
1202
+ // get the adapter package.json
1203
+ if (fs.existsSync(path.join(this.directory, 'package.json'))) {
1204
+ const adaptPackage = require(path.join(this.directory, 'package.json'));
1205
+
1206
+ // Namespace - package & directory
1207
+ const [tempNS, tempName] = adaptPackage.name.split('/');
1208
+ adapterInv.namespace = tempNS;
1209
+ if (this.directory.indexOf(adapterInv.namespace) > 0) {
1210
+ adapterInv.issues.inNamespace = true;
1211
+ } else {
1212
+ adapterInv.issues.inNamespace = false;
1213
+ }
1214
+
1215
+ // Name - package & directory
1216
+ adapterInv.name = tempName;
1217
+ if (this.directory.indexOf(adapterInv.name) > 0) {
1218
+ adapterInv.issues.inName = true;
1219
+ } else {
1220
+ adapterInv.issues.inName = false;
1221
+ }
1222
+
1223
+ // Version - package
1224
+ adapterInv.version = adaptPackage.version;
1225
+ } else {
1226
+ adapterInv.namespace = 'TBD';
1227
+ adapterInv.issues.inNamespace = false;
1228
+ adapterInv.name = 'TBD';
1229
+ adapterInv.issues.inName = false;
1230
+ adapterInv.version = 'TBD';
1231
+ }
1232
+
1233
+ // get the adapter pronghorn.json
1234
+ adapterInv.brokerDefined = false;
1235
+ adapterInv.cacheDefined = false;
1236
+ if (fs.existsSync(path.join(this.directory, 'pronghorn.json'))) {
1237
+ const adaptPronghorn = require(path.join(this.directory, 'pronghorn.json'));
1238
+
1239
+ // Active WF Tasks - pronghorn.json
1240
+ let wfCount = 0;
1241
+ for (let i = 0; i < adaptPronghorn.methods.length; i += 1) {
1242
+ if (adaptPronghorn.methods[i].task === true) {
1243
+ wfCount += 1;
1244
+ }
1245
+ if (adaptPronghorn.methods[i].name === 'getDevicesFiltered') {
1246
+ adapterInv.brokerDefined = true;
1247
+ }
1248
+ if (adaptPronghorn.methods[i].name === 'iapUpdateAdapterCache') {
1249
+ adapterInv.cacheDefined = true;
1250
+ }
1251
+ }
1252
+ adapterInv.activeWFTasks = wfCount;
1253
+ } else {
1254
+ adapterInv.activeWFTasks = -1;
1255
+ }
1256
+
1257
+ // get the utils package.json
1258
+ if (fs.existsSync('../package.json')) {
1259
+ const utilsPackage = require('../package.json');
1260
+
1261
+ // Version of adapter-utils - utils package
1262
+ adapterInv.utilVersion = utilsPackage.version;
1263
+ } else {
1264
+ adapterInv.utilVersion = 'TBD';
1265
+ }
1266
+
1267
+ // return the results
1268
+ return callback(adapterInv);
1269
+ } catch (e) {
1270
+ // handle any exception
1271
+ const errorObj = this.transUtil.checkAndReturn(e, origin, 'Issue getting Inventory information');
1272
+ return callback(null, errorObj);
1273
+ }
1274
+ }
1178
1275
  }
1179
1276
 
1180
1277
  module.exports = RequestHandler;
@@ -176,7 +176,7 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
176
176
  retError = JSON.parse(perror.response.trim());
177
177
  } catch (ex) {
178
178
  // otherwise log parse failure but still return the unparsed error
179
- log.error(`${origin}: An error occurred parsing the error JSON: ${ex}`);
179
+ log.warn(`${origin}: An error occurred parsing the error JSON: ${ex}: Error Response is: ${perror}`);
180
180
  }
181
181
  }
182
182
  }
@@ -429,7 +429,7 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
429
429
  retResponse = JSON.parse(resObj.response.trim());
430
430
  } catch (ex) {
431
431
  // otherwise log parse failure and return the unparsed response
432
- 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}`);
433
433
  return callback(retObject);
434
434
  }
435
435
  }
@@ -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
- const ajvInst = new AjvCl();
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
- const ajvInst = new AjvCl();
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "4.48.15",
3
+ "version": "4.49.0",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",