@itentialopensource/adapter-robustel 0.2.0 → 0.3.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.
Files changed (42) hide show
  1. package/CALLS.md +36 -0
  2. package/CHANGELOG.md +16 -0
  3. package/CONTRIBUTING.md +1 -160
  4. package/ENHANCE.md +2 -2
  5. package/README.md +32 -23
  6. package/adapter.js +155 -163
  7. package/adapterBase.js +549 -879
  8. package/changelogs/changelog.md +16 -0
  9. package/metadata.json +47 -0
  10. package/package.json +23 -25
  11. package/pronghorn.json +983 -644
  12. package/propertiesSchema.json +431 -31
  13. package/refs?service=git-upload-pack +0 -0
  14. package/report/adapter-openapi.json +204 -0
  15. package/report/adapter-openapi.yaml +163 -0
  16. package/report/adapterInfo.json +8 -8
  17. package/report/updateReport1691507608338.json +120 -0
  18. package/report/updateReport1692202610637.json +120 -0
  19. package/report/updateReport1694462053440.json +120 -0
  20. package/report/updateReport1698421016757.json +120 -0
  21. package/sampleProperties.json +62 -2
  22. package/test/integration/adapterTestBasicGet.js +2 -4
  23. package/test/integration/adapterTestConnectivity.js +91 -42
  24. package/test/integration/adapterTestIntegration.js +130 -2
  25. package/test/unit/adapterBaseTestUnit.js +388 -313
  26. package/test/unit/adapterTestUnit.js +338 -112
  27. package/utils/adapterInfo.js +1 -1
  28. package/utils/addAuth.js +1 -1
  29. package/utils/artifactize.js +1 -1
  30. package/utils/checkMigrate.js +1 -1
  31. package/utils/entitiesToDB.js +2 -2
  32. package/utils/findPath.js +1 -1
  33. package/utils/methodDocumentor.js +273 -0
  34. package/utils/modify.js +13 -15
  35. package/utils/packModificationScript.js +1 -1
  36. package/utils/pre-commit.sh +2 -0
  37. package/utils/taskMover.js +309 -0
  38. package/utils/tbScript.js +89 -34
  39. package/utils/tbUtils.js +41 -21
  40. package/utils/testRunner.js +1 -1
  41. package/utils/troubleshootingAdapter.js +9 -6
  42. package/workflows/README.md +0 -3
package/adapter.js CHANGED
@@ -88,9 +88,6 @@ class Robustel extends AdapterBaseCl {
88
88
  let myIgnore = [
89
89
  'healthCheck',
90
90
  'iapGetAdapterWorkflowFunctions',
91
- 'iapHasAdapterEntity',
92
- 'iapVerifyAdapterCapability',
93
- 'iapUpdateAdapterEntityCache',
94
91
  'hasEntities',
95
92
  'getAuthorization'
96
93
  ];
@@ -118,29 +115,15 @@ class Robustel extends AdapterBaseCl {
118
115
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
119
116
  * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
120
117
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
118
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
121
119
  * @param {Callback} callback - The results of the call
122
120
  */
123
- iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
121
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
124
122
  const meth = 'adapter-iapUpdateAdapterConfiguration';
125
123
  const origin = `${this.id}-${meth}`;
126
124
  log.trace(origin);
127
125
 
128
- super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
129
- }
130
-
131
- /**
132
- * See if the API path provided is found in this adapter
133
- *
134
- * @function iapFindAdapterPath
135
- * @param {string} apiPath - the api path to check on
136
- * @param {Callback} callback - The results of the call
137
- */
138
- iapFindAdapterPath(apiPath, callback) {
139
- const meth = 'adapter-iapFindAdapterPath';
140
- const origin = `${this.id}-${meth}`;
141
- log.trace(origin);
142
-
143
- super.iapFindAdapterPath(apiPath, callback);
126
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
144
127
  }
145
128
 
146
129
  /**
@@ -182,7 +165,7 @@ class Robustel extends AdapterBaseCl {
182
165
  }
183
166
 
184
167
  /**
185
- * @summary Get the Adaoter Queue
168
+ * @summary Get the Adapter Queue
186
169
  *
187
170
  * @function iapGetAdapterQueue
188
171
  * @param {Callback} callback - callback function
@@ -195,6 +178,22 @@ class Robustel extends AdapterBaseCl {
195
178
  return super.iapGetAdapterQueue(callback);
196
179
  }
197
180
 
181
+ /* SCRIPT CALLS */
182
+ /**
183
+ * See if the API path provided is found in this adapter
184
+ *
185
+ * @function iapFindAdapterPath
186
+ * @param {string} apiPath - the api path to check on
187
+ * @param {Callback} callback - The results of the call
188
+ */
189
+ iapFindAdapterPath(apiPath, callback) {
190
+ const meth = 'adapter-iapFindAdapterPath';
191
+ const origin = `${this.id}-${meth}`;
192
+ log.trace(origin);
193
+
194
+ super.iapFindAdapterPath(apiPath, callback);
195
+ }
196
+
198
197
  /**
199
198
  * @summary Runs troubleshoot scripts for adapter
200
199
  *
@@ -295,176 +294,93 @@ class Robustel extends AdapterBaseCl {
295
294
  }
296
295
  }
297
296
 
298
- /* BROKER CALLS */
299
297
  /**
300
- * @summary Determines if this adapter supports the specific entity
298
+ * @summary Deactivate adapter tasks
301
299
  *
302
- * @function iapHasAdapterEntity
303
- * @param {String} entityType - the entity type to check for
304
- * @param {String/Array} entityId - the specific entity we are looking for
300
+ * @function iapDeactivateTasks
305
301
  *
306
- * @param {Callback} callback - An array of whether the adapter can has the
307
- * desired capability or an error
302
+ * @param {Array} tasks - List of tasks to deactivate
303
+ * @param {Callback} callback
308
304
  */
309
- iapHasAdapterEntity(entityType, entityId, callback) {
310
- const origin = `${this.id}-adapter-iapHasAdapterEntity`;
305
+ iapDeactivateTasks(tasks, callback) {
306
+ const meth = 'adapter-iapDeactivateTasks';
307
+ const origin = `${this.id}-${meth}`;
311
308
  log.trace(origin);
312
309
 
313
- // Make the call -
314
- // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
315
- return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
310
+ try {
311
+ return super.iapDeactivateTasks(tasks, callback);
312
+ } catch (err) {
313
+ log.error(`${origin}: ${err}`);
314
+ return callback(null, err);
315
+ }
316
316
  }
317
317
 
318
318
  /**
319
- * @summary Provides a way for the adapter to tell north bound integrations
320
- * whether the adapter supports type, action and specific entity
319
+ * @summary Activate adapter tasks that have previously been deactivated
321
320
  *
322
- * @function iapVerifyAdapterCapability
323
- * @param {String} entityType - the entity type to check for
324
- * @param {String} actionType - the action type to check for
325
- * @param {String/Array} entityId - the specific entity we are looking for
321
+ * @function iapActivateTasks
326
322
  *
327
- * @param {Callback} callback - An array of whether the adapter can has the
328
- * desired capability or an error
323
+ * @param {Array} tasks - List of tasks to activate
324
+ * @param {Callback} callback
329
325
  */
330
- iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
331
- const meth = 'adapterBase-iapVerifyAdapterCapability';
326
+ iapActivateTasks(tasks, callback) {
327
+ const meth = 'adapter-iapActivateTasks';
332
328
  const origin = `${this.id}-${meth}`;
333
329
  log.trace(origin);
334
330
 
335
- // if caching
336
- if (this.caching) {
337
- // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
338
- return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
339
- if (error) {
340
- return callback(null, error);
341
- }
342
-
343
- // if the cache needs to be updated, update and try again
344
- if (results && results[0] === 'needupdate') {
345
- switch (entityType) {
346
- case 'template_entity': {
347
- // if the cache is invalid, update the cache
348
- return this.getEntities(null, null, null, null, (data, err) => {
349
- if (err) {
350
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
351
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
352
- return callback(null, errorObj);
353
- }
354
-
355
- // need to check the cache again since it has been updated
356
- return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
357
- if (verror) {
358
- return callback(null, verror);
359
- }
360
-
361
- return this.capabilityResults(vcapable, callback);
362
- });
363
- });
364
- }
365
- default: {
366
- // unsupported entity type
367
- const result = [false];
368
-
369
- // put false in array for all entities
370
- if (Array.isArray(entityId)) {
371
- for (let e = 1; e < entityId.length; e += 1) {
372
- result.push(false);
373
- }
374
- }
375
-
376
- return callback(result);
377
- }
378
- }
379
- }
380
-
381
- // return the results
382
- return this.capabilityResults(results, callback);
383
- });
384
- }
385
-
386
- // if no entity id
387
- if (!entityId) {
388
- // need to check the cache again since it has been updated
389
- return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
390
- if (verror) {
391
- return callback(null, verror);
392
- }
393
-
394
- return this.capabilityResults(vcapable, callback);
395
- });
331
+ try {
332
+ return super.iapActivateTasks(tasks, callback);
333
+ } catch (err) {
334
+ log.error(`${origin}: ${err}`);
335
+ return callback(null, err);
396
336
  }
337
+ }
397
338
 
398
- // if not caching
399
- switch (entityType) {
400
- case 'template_entity': {
401
- // need to get the entities to check
402
- return this.getEntities(null, null, null, null, (data, err) => {
403
- if (err) {
404
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
405
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
406
- return callback(null, errorObj);
407
- }
408
-
409
- // need to check the cache again since it has been updated
410
- return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
411
- if (verror) {
412
- return callback(null, verror);
413
- }
414
-
415
- // is the entity in the list?
416
- const isEntity = this.entityInList(entityId, data.response, callback);
417
- const res = [];
418
-
419
- // not found
420
- for (let i = 0; i < isEntity.length; i += 1) {
421
- if (vcapable) {
422
- res.push(isEntity[i]);
423
- } else {
424
- res.push(false);
425
- }
426
- }
427
-
428
- return callback(res);
429
- });
430
- });
431
- }
432
- default: {
433
- // unsupported entity type
434
- const result = [false];
435
-
436
- // put false in array for all entities
437
- if (Array.isArray(entityId)) {
438
- for (let e = 1; e < entityId.length; e += 1) {
439
- result.push(false);
440
- }
441
- }
339
+ /* CACHE CALLS */
340
+ /**
341
+ * @summary Populate the cache for the given entities
342
+ *
343
+ * @function iapPopulateEntityCache
344
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
345
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
346
+ *
347
+ * @returns status of the populate
348
+ */
349
+ iapPopulateEntityCache(entityTypes, callback) {
350
+ const meth = 'adapter-iapPopulateEntityCache';
351
+ const origin = `${this.id}-${meth}`;
352
+ log.trace(origin);
442
353
 
443
- return callback(result);
444
- }
354
+ try {
355
+ return super.iapPopulateEntityCache(entityTypes, callback);
356
+ } catch (err) {
357
+ log.error(`${origin}: ${err}`);
358
+ return callback(null, err);
445
359
  }
446
360
  }
447
361
 
448
362
  /**
449
- * @summary Updates the cache for all entities by call the get All entity method
450
- *
451
- * @function iapUpdateAdapterEntityCache
363
+ * @summary Retrieves data from cache for specified entity type
452
364
  *
365
+ * @function iapRetrieveEntitiesCache
366
+ * @param {String} entityType - entity of which to retrieve
367
+ * @param {Object} options - settings of which data to return and how to return it
368
+ * @param {Callback} callback - the data if it was retrieved
453
369
  */
454
- iapUpdateAdapterEntityCache() {
455
- const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
370
+ iapRetrieveEntitiesCache(entityType, options, callback) {
371
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
372
+ const origin = `${this.id}-${meth}`;
456
373
  log.trace(origin);
457
374
 
458
- if (this.caching) {
459
- // if the cache is invalid, update the cache
460
- this.getEntities(null, null, null, null, (data, err) => {
461
- if (err) {
462
- log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
463
- }
464
- });
375
+ try {
376
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
377
+ } catch (err) {
378
+ log.error(`${origin}: ${err}`);
379
+ return callback(null, err);
465
380
  }
466
381
  }
467
382
 
383
+ /* BROKER CALLS */
468
384
  /**
469
385
  * @summary Determines if this adapter supports any in a list of entities
470
386
  *
@@ -599,6 +515,38 @@ class Robustel extends AdapterBaseCl {
599
515
  }
600
516
 
601
517
  /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
518
+ /**
519
+ * Makes the requested generic call
520
+ *
521
+ * @function iapExpandedGenericAdapterRequest
522
+ * @param {Object} metadata - metadata for the call (optional).
523
+ * Can be a stringified Object.
524
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
525
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
526
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
527
+ * Can be a stringified Object.
528
+ * @param {Object} queryData - the parameters to be put on the url (optional).
529
+ * Can be a stringified Object.
530
+ * @param {Object} requestBody - the body to add to the request (optional).
531
+ * Can be a stringified Object.
532
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
533
+ * Can be a stringified Object.
534
+ * @param {getCallback} callback - a callback function to return the result (Generics)
535
+ * or the error
536
+ */
537
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
538
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
539
+ const origin = `${this.id}-${meth}`;
540
+ log.trace(origin);
541
+
542
+ try {
543
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
544
+ } catch (err) {
545
+ log.error(`${origin}: ${err}`);
546
+ return callback(null, err);
547
+ }
548
+ }
549
+
602
550
  /**
603
551
  * Makes the requested generic call
604
552
  *
@@ -847,6 +795,50 @@ class Robustel extends AdapterBaseCl {
847
795
  }
848
796
  }
849
797
 
798
+ /* INVENTORY CALLS */
799
+ /**
800
+ * @summary run the adapter lint script to return the results.
801
+ *
802
+ * @function iapRunAdapterLint
803
+ * @param {Callback} callback - callback function
804
+ */
805
+ iapRunAdapterLint(callback) {
806
+ const meth = 'adapter-iapRunAdapterLint';
807
+ const origin = `${this.id}-${meth}`;
808
+ log.trace(origin);
809
+
810
+ return super.iapRunAdapterLint(callback);
811
+ }
812
+
813
+ /**
814
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
815
+ * can not run integration as there can be implications with that.
816
+ *
817
+ * @function iapRunAdapterTests
818
+ * @param {Callback} callback - callback function
819
+ */
820
+ iapRunAdapterTests(callback) {
821
+ const meth = 'adapter-iapRunAdapterTests';
822
+ const origin = `${this.id}-${meth}`;
823
+ log.trace(origin);
824
+
825
+ return super.iapRunAdapterTests(callback);
826
+ }
827
+
828
+ /**
829
+ * @summary provide inventory information abbout the adapter
830
+ *
831
+ * @function iapGetAdapterInventory
832
+ * @param {Callback} callback - callback function
833
+ */
834
+ iapGetAdapterInventory(callback) {
835
+ const meth = 'adapter-iapGetAdapterInventory';
836
+ const origin = `${this.id}-${meth}`;
837
+ log.trace(origin);
838
+
839
+ return super.iapGetAdapterInventory(callback);
840
+ }
841
+
850
842
  /**
851
843
  * @callback healthCallback
852
844
  * @param {Object} result - the result of the get request (contains an id and a status)
@@ -1311,7 +1303,7 @@ class Robustel extends AdapterBaseCl {
1311
1303
  * @name runCommandOnDevice
1312
1304
  * @summary Run Command on Device
1313
1305
  *
1314
- * @param {} serialNumber - device serial number
1306
+ * @param {string} serialNumber - device serial number
1315
1307
  * @param {object} body - { commandType: , softwareVersionId: }
1316
1308
  * @param {getCallback} callback - a callback function to return the result
1317
1309
  * @return {object} results - An object containing the response of the action