@itentialopensource/adapter-iap 0.2.3 → 0.3.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.
Files changed (56) hide show
  1. package/AUTH.md +35 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +1125 -0
  4. package/CHANGELOG.md +8 -0
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +3 -148
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +235 -576
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +17 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +379 -261
  14. package/adapterBase.js +854 -408
  15. package/changelogs/changelog.md +40 -0
  16. package/entities/.generic/action.json +105 -0
  17. package/entities/.generic/schema.json +6 -1
  18. package/error.json +6 -0
  19. package/metadata.json +62 -0
  20. package/package.json +28 -22
  21. package/pronghorn.json +691 -88
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +827 -6
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapter-openapi.json +5980 -0
  26. package/report/adapter-openapi.yaml +5373 -0
  27. package/report/adapterInfo.json +10 -0
  28. package/report/updateReport1691507326854.json +120 -0
  29. package/report/updateReport1692202369162.json +120 -0
  30. package/report/updateReport1694459817194.json +120 -0
  31. package/report/updateReport1698420299974.json +120 -0
  32. package/sampleProperties.json +146 -3
  33. package/test/integration/adapterTestBasicGet.js +3 -5
  34. package/test/integration/adapterTestConnectivity.js +91 -42
  35. package/test/integration/adapterTestIntegration.js +155 -103
  36. package/test/unit/adapterBaseTestUnit.js +388 -308
  37. package/test/unit/adapterTestUnit.js +479 -241
  38. package/utils/adapterInfo.js +206 -0
  39. package/utils/addAuth.js +94 -0
  40. package/utils/artifactize.js +1 -1
  41. package/utils/basicGet.js +1 -14
  42. package/utils/checkMigrate.js +1 -1
  43. package/utils/entitiesToDB.js +179 -0
  44. package/utils/findPath.js +1 -1
  45. package/utils/methodDocumentor.js +273 -0
  46. package/utils/modify.js +14 -16
  47. package/utils/packModificationScript.js +1 -1
  48. package/utils/patches2bundledDeps.js +90 -0
  49. package/utils/pre-commit.sh +5 -0
  50. package/utils/removeHooks.js +20 -0
  51. package/utils/taskMover.js +309 -0
  52. package/utils/tbScript.js +129 -53
  53. package/utils/tbUtils.js +125 -25
  54. package/utils/testRunner.js +17 -17
  55. package/utils/troubleshootingAdapter.js +10 -31
  56. package/workflows/README.md +0 -3
package/adapter.js CHANGED
@@ -64,7 +64,6 @@ class Iap extends AdapterBaseCl {
64
64
  // }
65
65
  }
66
66
  */
67
-
68
67
  /**
69
68
  * @callback healthCallback
70
69
  * @param {Object} reqObj - the request to send into the healthcheck
@@ -80,10 +79,15 @@ class Iap extends AdapterBaseCl {
80
79
  }
81
80
 
82
81
  /**
83
- * @getWorkflowFunctions
82
+ * @iapGetAdapterWorkflowFunctions
84
83
  */
85
- getWorkflowFunctions(inIgnore) {
86
- let myIgnore = [];
84
+ iapGetAdapterWorkflowFunctions(inIgnore) {
85
+ let myIgnore = [
86
+ 'healthCheck',
87
+ 'iapGetAdapterWorkflowFunctions',
88
+ 'hasEntities',
89
+ 'getAuthorization'
90
+ ];
87
91
  if (!inIgnore && Array.isArray(inIgnore)) {
88
92
  myIgnore = inIgnore;
89
93
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -94,52 +98,44 @@ class Iap extends AdapterBaseCl {
94
98
  // you can add specific methods that you do not want to be workflow functions to ignore like below
95
99
  // myIgnore.push('myMethodNotInWorkflow');
96
100
 
97
- return super.getWorkflowFunctions(myIgnore);
101
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
98
102
  }
99
103
 
100
104
  /**
101
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
105
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
102
106
  * allows customers to make changes to adapter configuration without having to be on the
103
107
  * file system.
104
108
  *
105
- * @function updateAdapterConfiguration
109
+ * @function iapUpdateAdapterConfiguration
106
110
  * @param {string} configFile - the name of the file being updated (required)
107
111
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
108
112
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
109
113
  * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
110
114
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
115
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
111
116
  * @param {Callback} callback - The results of the call
112
117
  */
113
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
114
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
118
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
119
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
120
+ const origin = `${this.id}-${meth}`;
115
121
  log.trace(origin);
116
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
117
- }
118
122
 
119
- /**
120
- * See if the API path provided is found in this adapter
121
- *
122
- * @function findPath
123
- * @param {string} apiPath - the api path to check on
124
- * @param {Callback} callback - The results of the call
125
- */
126
- findPath(apiPath, callback) {
127
- const origin = `${this.id}-adapter-findPath`;
128
- log.trace(origin);
129
- super.findPath(apiPath, callback);
123
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
130
124
  }
131
125
 
132
126
  /**
133
127
  * @summary Suspends adapter
134
128
  *
135
- * @function suspend
129
+ * @function iapSuspendAdapter
136
130
  * @param {Callback} callback - callback function
137
131
  */
138
- suspend(mode, callback) {
139
- const origin = `${this.id}-adapter-suspend`;
132
+ iapSuspendAdapter(mode, callback) {
133
+ const meth = 'adapter-iapSuspendAdapter';
134
+ const origin = `${this.id}-${meth}`;
140
135
  log.trace(origin);
136
+
141
137
  try {
142
- return super.suspend(mode, callback);
138
+ return super.iapSuspendAdapter(mode, callback);
143
139
  } catch (error) {
144
140
  log.error(`${origin}: ${error}`);
145
141
  return callback(null, error);
@@ -149,14 +145,16 @@ class Iap extends AdapterBaseCl {
149
145
  /**
150
146
  * @summary Unsuspends adapter
151
147
  *
152
- * @function unsuspend
148
+ * @function iapUnsuspendAdapter
153
149
  * @param {Callback} callback - callback function
154
150
  */
155
- unsuspend(callback) {
156
- const origin = `${this.id}-adapter-unsuspend`;
151
+ iapUnsuspendAdapter(callback) {
152
+ const meth = 'adapter-iapUnsuspendAdapter';
153
+ const origin = `${this.id}-${meth}`;
157
154
  log.trace(origin);
155
+
158
156
  try {
159
- return super.unsuspend(callback);
157
+ return super.iapUnsuspendAdapter(callback);
160
158
  } catch (error) {
161
159
  log.error(`${origin}: ${error}`);
162
160
  return callback(null, error);
@@ -164,31 +162,51 @@ class Iap extends AdapterBaseCl {
164
162
  }
165
163
 
166
164
  /**
167
- * @summary Get the Adaoter Queue
165
+ * @summary Get the Adapter Queue
168
166
  *
169
- * @function getQueue
167
+ * @function iapGetAdapterQueue
170
168
  * @param {Callback} callback - callback function
171
169
  */
172
- getQueue(callback) {
173
- const origin = `${this.id}-adapter-getQueue`;
170
+ iapGetAdapterQueue(callback) {
171
+ const meth = 'adapter-iapGetAdapterQueue';
172
+ const origin = `${this.id}-${meth}`;
174
173
  log.trace(origin);
175
- return super.getQueue(callback);
174
+
175
+ return super.iapGetAdapterQueue(callback);
176
+ }
177
+
178
+ /* SCRIPT CALLS */
179
+ /**
180
+ * See if the API path provided is found in this adapter
181
+ *
182
+ * @function iapFindAdapterPath
183
+ * @param {string} apiPath - the api path to check on
184
+ * @param {Callback} callback - The results of the call
185
+ */
186
+ iapFindAdapterPath(apiPath, callback) {
187
+ const meth = 'adapter-iapFindAdapterPath';
188
+ const origin = `${this.id}-${meth}`;
189
+ log.trace(origin);
190
+
191
+ super.iapFindAdapterPath(apiPath, callback);
176
192
  }
177
193
 
178
194
  /**
179
195
  * @summary Runs troubleshoot scripts for adapter
180
196
  *
181
- * @function troubleshoot
197
+ * @function iapTroubleshootAdapter
182
198
  * @param {Object} props - the connection, healthcheck and authentication properties
183
199
  *
184
200
  * @param {boolean} persistFlag - whether the adapter properties should be updated
185
201
  * @param {Callback} callback - The results of the call
186
202
  */
187
- troubleshoot(props, persistFlag, callback) {
188
- const origin = `${this.id}-adapter-troubleshoot`;
203
+ iapTroubleshootAdapter(props, persistFlag, callback) {
204
+ const meth = 'adapter-iapTroubleshootAdapter';
205
+ const origin = `${this.id}-${meth}`;
189
206
  log.trace(origin);
207
+
190
208
  try {
191
- return super.troubleshoot(props, persistFlag, this, callback);
209
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
192
210
  } catch (error) {
193
211
  log.error(`${origin}: ${error}`);
194
212
  return callback(null, error);
@@ -198,15 +216,17 @@ class Iap extends AdapterBaseCl {
198
216
  /**
199
217
  * @summary runs healthcheck script for adapter
200
218
  *
201
- * @function runHealthcheck
219
+ * @function iapRunAdapterHealthcheck
202
220
  * @param {Adapter} adapter - adapter instance to troubleshoot
203
221
  * @param {Callback} callback - callback function
204
222
  */
205
- runHealthcheck(callback) {
206
- const origin = `${this.id}-adapter-runHealthcheck`;
223
+ iapRunAdapterHealthcheck(callback) {
224
+ const meth = 'adapter-iapRunAdapterHealthcheck';
225
+ const origin = `${this.id}-${meth}`;
207
226
  log.trace(origin);
227
+
208
228
  try {
209
- return super.runHealthcheck(this, callback);
229
+ return super.iapRunAdapterHealthcheck(this, callback);
210
230
  } catch (error) {
211
231
  log.error(`${origin}: ${error}`);
212
232
  return callback(null, error);
@@ -216,14 +236,16 @@ class Iap extends AdapterBaseCl {
216
236
  /**
217
237
  * @summary runs connectivity check script for adapter
218
238
  *
219
- * @function runConnectivity
239
+ * @function iapRunAdapterConnectivity
220
240
  * @param {Callback} callback - callback function
221
241
  */
222
- runConnectivity(callback) {
223
- const origin = `${this.id}-adapter-runConnectivity`;
242
+ iapRunAdapterConnectivity(callback) {
243
+ const meth = 'adapter-iapRunAdapterConnectivity';
244
+ const origin = `${this.id}-${meth}`;
224
245
  log.trace(origin);
246
+
225
247
  try {
226
- return super.runConnectivity(callback);
248
+ return super.iapRunAdapterConnectivity(callback);
227
249
  } catch (error) {
228
250
  log.error(`${origin}: ${error}`);
229
251
  return callback(null, error);
@@ -233,14 +255,16 @@ class Iap extends AdapterBaseCl {
233
255
  /**
234
256
  * @summary runs basicGet script for adapter
235
257
  *
236
- * @function runBasicGet
258
+ * @function iapRunAdapterBasicGet
237
259
  * @param {Callback} callback - callback function
238
260
  */
239
- runBasicGet(callback) {
240
- const origin = `${this.id}-adapter-runBasicGet`;
261
+ iapRunAdapterBasicGet(callback) {
262
+ const meth = 'adapter-iapRunAdapterBasicGet';
263
+ const origin = `${this.id}-${meth}`;
241
264
  log.trace(origin);
265
+
242
266
  try {
243
- return super.runBasicGet(callback);
267
+ return super.iapRunAdapterBasicGet(callback);
244
268
  } catch (error) {
245
269
  log.error(`${origin}: ${error}`);
246
270
  return callback(null, error);
@@ -248,171 +272,275 @@ class Iap extends AdapterBaseCl {
248
272
  }
249
273
 
250
274
  /**
251
- * @summary Determines if this adapter supports the specific entity
252
- *
253
- * @function hasEntity
254
- * @param {String} entityType - the entity type to check for
255
- * @param {String/Array} entityId - the specific entity we are looking for
275
+ * @summary moves entites into Mongo DB
256
276
  *
257
- * @param {Callback} callback - An array of whether the adapter can has the
258
- * desired capability or an error
277
+ * @function iapMoveAdapterEntitiesToDB
278
+ * @param {getCallback} callback - a callback function to return the result (Generics)
279
+ * or the error
259
280
  */
260
- hasEntity(entityType, entityId, callback) {
261
- const origin = `${this.id}-adapter-hasEntity`;
281
+ iapMoveAdapterEntitiesToDB(callback) {
282
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
283
+ const origin = `${this.id}-${meth}`;
262
284
  log.trace(origin);
263
285
 
264
- // Make the call -
265
- // verifyCapability(entityType, actionType, entityId, callback)
266
- return this.verifyCapability(entityType, null, entityId, callback);
286
+ try {
287
+ return super.iapMoveAdapterEntitiesToDB(callback);
288
+ } catch (err) {
289
+ log.error(`${origin}: ${err}`);
290
+ return callback(null, err);
291
+ }
267
292
  }
268
293
 
269
294
  /**
270
- * @summary Provides a way for the adapter to tell north bound integrations
271
- * whether the adapter supports type, action and specific entity
295
+ * @summary Deactivate adapter tasks
272
296
  *
273
- * @function verifyCapability
274
- * @param {String} entityType - the entity type to check for
275
- * @param {String} actionType - the action type to check for
276
- * @param {String/Array} entityId - the specific entity we are looking for
277
- *
278
- * @param {Callback} callback - An array of whether the adapter can has the
279
- * desired capability or an error
280
- */
281
- verifyCapability(entityType, actionType, entityId, callback) {
282
- const meth = 'adapterBase-verifyCapability';
283
- const origin = `${this.id}-${meth}`;
284
- log.trace(origin);
285
-
286
- // if caching
287
- if (this.caching) {
288
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
289
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
290
- if (error) {
291
- return callback(null, error);
292
- }
297
+ * @function iapDeactivateTasks
298
+ *
299
+ * @param {Array} tasks - List of tasks to deactivate
300
+ * @param {Callback} callback
301
+ */
302
+ iapDeactivateTasks(tasks, callback) {
303
+ const meth = 'adapter-iapDeactivateTasks';
304
+ const origin = `${this.id}-${meth}`;
305
+ log.trace(origin);
293
306
 
294
- // if the cache needs to be updated, update and try again
295
- if (results && results[0] === 'needupdate') {
296
- switch (entityType) {
297
- case 'template_entity': {
298
- // if the cache is invalid, update the cache
299
- return this.getEntities(null, null, null, null, (data, err) => {
300
- if (err) {
301
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
302
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
303
- return callback(null, errorObj);
304
- }
307
+ try {
308
+ return super.iapDeactivateTasks(tasks, callback);
309
+ } catch (err) {
310
+ log.error(`${origin}: ${err}`);
311
+ return callback(null, err);
312
+ }
313
+ }
305
314
 
306
- // need to check the cache again since it has been updated
307
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
308
- if (verror) {
309
- return callback(null, verror);
310
- }
315
+ /**
316
+ * @summary Activate adapter tasks that have previously been deactivated
317
+ *
318
+ * @function iapActivateTasks
319
+ *
320
+ * @param {Array} tasks - List of tasks to activate
321
+ * @param {Callback} callback
322
+ */
323
+ iapActivateTasks(tasks, callback) {
324
+ const meth = 'adapter-iapActivateTasks';
325
+ const origin = `${this.id}-${meth}`;
326
+ log.trace(origin);
311
327
 
312
- return this.capabilityResults(vcapable, callback);
313
- });
314
- });
315
- }
316
- default: {
317
- // unsupported entity type
318
- const result = [false];
328
+ try {
329
+ return super.iapActivateTasks(tasks, callback);
330
+ } catch (err) {
331
+ log.error(`${origin}: ${err}`);
332
+ return callback(null, err);
333
+ }
334
+ }
319
335
 
320
- // put false in array for all entities
321
- if (Array.isArray(entityId)) {
322
- for (let e = 1; e < entityId.length; e += 1) {
323
- result.push(false);
324
- }
325
- }
336
+ /* CACHE CALLS */
337
+ /**
338
+ * @summary Populate the cache for the given entities
339
+ *
340
+ * @function iapPopulateEntityCache
341
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
342
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
343
+ *
344
+ * @returns status of the populate
345
+ */
346
+ iapPopulateEntityCache(entityTypes, callback) {
347
+ const meth = 'adapter-iapPopulateEntityCache';
348
+ const origin = `${this.id}-${meth}`;
349
+ log.trace(origin);
326
350
 
327
- return callback(result);
328
- }
329
- }
330
- }
351
+ try {
352
+ return super.iapPopulateEntityCache(entityTypes, callback);
353
+ } catch (err) {
354
+ log.error(`${origin}: ${err}`);
355
+ return callback(null, err);
356
+ }
357
+ }
331
358
 
332
- // return the results
333
- return this.capabilityResults(results, callback);
334
- });
359
+ /**
360
+ * @summary Retrieves data from cache for specified entity type
361
+ *
362
+ * @function iapRetrieveEntitiesCache
363
+ * @param {String} entityType - entity of which to retrieve
364
+ * @param {Object} options - settings of which data to return and how to return it
365
+ * @param {Callback} callback - the data if it was retrieved
366
+ */
367
+ iapRetrieveEntitiesCache(entityType, options, callback) {
368
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
369
+ const origin = `${this.id}-${meth}`;
370
+ log.trace(origin);
371
+
372
+ try {
373
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
374
+ } catch (err) {
375
+ log.error(`${origin}: ${err}`);
376
+ return callback(null, err);
335
377
  }
378
+ }
336
379
 
337
- // if no entity id
338
- if (!entityId) {
339
- // need to check the cache again since it has been updated
340
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
341
- if (verror) {
342
- return callback(null, verror);
343
- }
380
+ /* BROKER CALLS */
381
+ /**
382
+ * @summary Determines if this adapter supports any in a list of entities
383
+ *
384
+ * @function hasEntities
385
+ * @param {String} entityType - the entity type to check for
386
+ * @param {Array} entityList - the list of entities we are looking for
387
+ *
388
+ * @param {Callback} callback - A map where the entity is the key and the
389
+ * value is true or false
390
+ */
391
+ hasEntities(entityType, entityList, callback) {
392
+ const meth = 'adapter-hasEntities';
393
+ const origin = `${this.id}-${meth}`;
394
+ log.trace(origin);
344
395
 
345
- return this.capabilityResults(vcapable, callback);
346
- });
396
+ try {
397
+ return super.hasEntities(entityType, entityList, callback);
398
+ } catch (err) {
399
+ log.error(`${origin}: ${err}`);
400
+ return callback(null, err);
347
401
  }
402
+ }
348
403
 
349
- // if not caching
350
- switch (entityType) {
351
- case 'template_entity': {
352
- // need to get the entities to check
353
- return this.getEntities(null, null, null, null, (data, err) => {
354
- if (err) {
355
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
356
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
357
- return callback(null, errorObj);
358
- }
404
+ /**
405
+ * @summary Get Appliance that match the deviceName
406
+ *
407
+ * @function getDevice
408
+ * @param {String} deviceName - the deviceName to find (required)
409
+ *
410
+ * @param {getCallback} callback - a callback function to return the result
411
+ * (appliance) or the error
412
+ */
413
+ getDevice(deviceName, callback) {
414
+ const meth = 'adapter-getDevice';
415
+ const origin = `${this.id}-${meth}`;
416
+ log.trace(origin);
359
417
 
360
- // need to check the cache again since it has been updated
361
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
362
- if (verror) {
363
- return callback(null, verror);
364
- }
418
+ try {
419
+ return super.getDevice(deviceName, callback);
420
+ } catch (err) {
421
+ log.error(`${origin}: ${err}`);
422
+ return callback(null, err);
423
+ }
424
+ }
365
425
 
366
- // is the entity in the list?
367
- const isEntity = this.entityInList(entityId, data.response, callback);
368
- const res = [];
426
+ /**
427
+ * @summary Get Appliances that match the filter
428
+ *
429
+ * @function getDevicesFiltered
430
+ * @param {Object} options - the data to use to filter the appliances (optional)
431
+ *
432
+ * @param {getCallback} callback - a callback function to return the result
433
+ * (appliances) or the error
434
+ */
435
+ getDevicesFiltered(options, callback) {
436
+ const meth = 'adapter-getDevicesFiltered';
437
+ const origin = `${this.id}-${meth}`;
438
+ log.trace(origin);
369
439
 
370
- // not found
371
- for (let i = 0; i < isEntity.length; i += 1) {
372
- if (vcapable) {
373
- res.push(isEntity[i]);
374
- } else {
375
- res.push(false);
376
- }
377
- }
440
+ try {
441
+ return super.getDevicesFiltered(options, callback);
442
+ } catch (err) {
443
+ log.error(`${origin}: ${err}`);
444
+ return callback(null, err);
445
+ }
446
+ }
378
447
 
379
- return callback(res);
380
- });
381
- });
382
- }
383
- default: {
384
- // unsupported entity type
385
- const result = [false];
448
+ /**
449
+ * @summary Gets the status for the provided appliance
450
+ *
451
+ * @function isAlive
452
+ * @param {String} deviceName - the deviceName of the appliance. (required)
453
+ *
454
+ * @param {configCallback} callback - callback function to return the result
455
+ * (appliance isAlive) or the error
456
+ */
457
+ isAlive(deviceName, callback) {
458
+ const meth = 'adapter-isAlive';
459
+ const origin = `${this.id}-${meth}`;
460
+ log.trace(origin);
386
461
 
387
- // put false in array for all entities
388
- if (Array.isArray(entityId)) {
389
- for (let e = 1; e < entityId.length; e += 1) {
390
- result.push(false);
391
- }
392
- }
462
+ try {
463
+ return super.isAlive(deviceName, callback);
464
+ } catch (err) {
465
+ log.error(`${origin}: ${err}`);
466
+ return callback(null, err);
467
+ }
468
+ }
393
469
 
394
- return callback(result);
395
- }
470
+ /**
471
+ * @summary Gets a config for the provided Appliance
472
+ *
473
+ * @function getConfig
474
+ * @param {String} deviceName - the deviceName of the appliance. (required)
475
+ * @param {String} format - the desired format of the config. (optional)
476
+ *
477
+ * @param {configCallback} callback - callback function to return the result
478
+ * (appliance config) or the error
479
+ */
480
+ getConfig(deviceName, format, callback) {
481
+ const meth = 'adapter-getConfig';
482
+ const origin = `${this.id}-${meth}`;
483
+ log.trace(origin);
484
+
485
+ try {
486
+ return super.getConfig(deviceName, format, callback);
487
+ } catch (err) {
488
+ log.error(`${origin}: ${err}`);
489
+ return callback(null, err);
396
490
  }
397
491
  }
398
492
 
399
493
  /**
400
- * @summary Updates the cache for all entities by call the get All entity method
494
+ * @summary Gets the device count from the system
401
495
  *
402
- * @function updateEntityCache
496
+ * @function iapGetDeviceCount
403
497
  *
498
+ * @param {getCallback} callback - callback function to return the result
499
+ * (count) or the error
404
500
  */
405
- updateEntityCache() {
406
- const origin = `${this.id}-adapter-updateEntityCache`;
501
+ iapGetDeviceCount(callback) {
502
+ const meth = 'adapter-iapGetDeviceCount';
503
+ const origin = `${this.id}-${meth}`;
407
504
  log.trace(origin);
408
505
 
409
- if (this.caching) {
410
- // if the cache is invalid, update the cache
411
- this.getEntities(null, null, null, null, (data, err) => {
412
- if (err) {
413
- log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
414
- }
415
- });
506
+ try {
507
+ return super.iapGetDeviceCount(callback);
508
+ } catch (err) {
509
+ log.error(`${origin}: ${err}`);
510
+ return callback(null, err);
511
+ }
512
+ }
513
+
514
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
515
+ /**
516
+ * Makes the requested generic call
517
+ *
518
+ * @function iapExpandedGenericAdapterRequest
519
+ * @param {Object} metadata - metadata for the call (optional).
520
+ * Can be a stringified Object.
521
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
522
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
523
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
524
+ * Can be a stringified Object.
525
+ * @param {Object} queryData - the parameters to be put on the url (optional).
526
+ * Can be a stringified Object.
527
+ * @param {Object} requestBody - the body to add to the request (optional).
528
+ * Can be a stringified Object.
529
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
530
+ * Can be a stringified Object.
531
+ * @param {getCallback} callback - a callback function to return the result (Generics)
532
+ * or the error
533
+ */
534
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
535
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
536
+ const origin = `${this.id}-${meth}`;
537
+ log.trace(origin);
538
+
539
+ try {
540
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
541
+ } catch (err) {
542
+ log.error(`${origin}: ${err}`);
543
+ return callback(null, err);
416
544
  }
417
545
  }
418
546
 
@@ -436,94 +564,84 @@ class Iap extends AdapterBaseCl {
436
564
  const origin = `${this.id}-${meth}`;
437
565
  log.trace(origin);
438
566
 
439
- if (this.suspended && this.suspendMode === 'error') {
440
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
441
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
442
- return callback(null, errorObj);
567
+ try {
568
+ return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
569
+ } catch (err) {
570
+ log.error(`${origin}: ${err}`);
571
+ return callback(null, err);
443
572
  }
573
+ }
444
574
 
445
- /* HERE IS WHERE YOU VALIDATE DATA */
446
- if (uriPath === undefined || uriPath === null || uriPath === '') {
447
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
448
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
449
- return callback(null, errorObj);
450
- }
451
- if (restMethod === undefined || restMethod === null || restMethod === '') {
452
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
453
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
454
- return callback(null, errorObj);
455
- }
575
+ /**
576
+ * Makes the requested generic call with no base path or version
577
+ *
578
+ * @function genericAdapterRequestNoBasePath
579
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
580
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
581
+ * @param {Object} queryData - the parameters to be put on the url (optional).
582
+ * Can be a stringified Object.
583
+ * @param {Object} requestBody - the body to add to the request (optional).
584
+ * Can be a stringified Object.
585
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
586
+ * Can be a stringified Object.
587
+ * @param {getCallback} callback - a callback function to return the result (Generics)
588
+ * or the error
589
+ */
590
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
591
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
592
+ const origin = `${this.id}-${meth}`;
593
+ log.trace(origin);
456
594
 
457
- /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
458
- // remove any leading / and split the uripath into path variables
459
- let myPath = uriPath;
460
- while (myPath.indexOf('/') === 0) {
461
- myPath = myPath.substring(1);
595
+ try {
596
+ return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
597
+ } catch (err) {
598
+ log.error(`${origin}: ${err}`);
599
+ return callback(null, err);
462
600
  }
463
- const pathVars = myPath.split('/');
464
- const queryParamsAvailable = queryData;
465
- const queryParams = {};
466
- const bodyVars = requestBody;
601
+ }
467
602
 
468
- // loop in template. long callback arg name to avoid identifier conflicts
469
- Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
470
- if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
471
- && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
472
- queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
473
- }
474
- });
603
+ /* INVENTORY CALLS */
604
+ /**
605
+ * @summary run the adapter lint script to return the results.
606
+ *
607
+ * @function iapRunAdapterLint
608
+ * @param {Callback} callback - callback function
609
+ */
610
+ iapRunAdapterLint(callback) {
611
+ const meth = 'adapter-iapRunAdapterLint';
612
+ const origin = `${this.id}-${meth}`;
613
+ log.trace(origin);
475
614
 
476
- // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
477
- const reqObj = {
478
- payload: bodyVars,
479
- uriPathVars: pathVars,
480
- uriQuery: queryParams,
481
- uriOptions: {}
482
- };
483
- // add headers if provided
484
- if (addlHeaders) {
485
- reqObj.addlHeaders = addlHeaders;
486
- }
615
+ return super.iapRunAdapterLint(callback);
616
+ }
487
617
 
488
- // determine the call and return flag
489
- let action = 'getGenerics';
490
- let returnF = true;
491
- if (restMethod.toUpperCase() === 'POST') {
492
- action = 'createGeneric';
493
- } else if (restMethod.toUpperCase() === 'PUT') {
494
- action = 'updateGeneric';
495
- } else if (restMethod.toUpperCase() === 'PATCH') {
496
- action = 'patchGeneric';
497
- } else if (restMethod.toUpperCase() === 'DELETE') {
498
- action = 'deleteGeneric';
499
- returnF = false;
500
- }
618
+ /**
619
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
620
+ * can not run integration as there can be implications with that.
621
+ *
622
+ * @function iapRunAdapterTests
623
+ * @param {Callback} callback - callback function
624
+ */
625
+ iapRunAdapterTests(callback) {
626
+ const meth = 'adapter-iapRunAdapterTests';
627
+ const origin = `${this.id}-${meth}`;
628
+ log.trace(origin);
501
629
 
502
- try {
503
- // Make the call -
504
- // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
505
- return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
506
- // if we received an error or their is no response on the results
507
- // return an error
508
- if (irReturnError) {
509
- /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
510
- return callback(null, irReturnError);
511
- }
512
- if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
513
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
514
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
515
- return callback(null, errorObj);
516
- }
630
+ return super.iapRunAdapterTests(callback);
631
+ }
517
632
 
518
- /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
519
- // return the response
520
- return callback(irReturnData, null);
521
- });
522
- } catch (ex) {
523
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
524
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
525
- return callback(null, errorObj);
526
- }
633
+ /**
634
+ * @summary provide inventory information abbout the adapter
635
+ *
636
+ * @function iapGetAdapterInventory
637
+ * @param {Callback} callback - callback function
638
+ */
639
+ iapGetAdapterInventory(callback) {
640
+ const meth = 'adapter-iapGetAdapterInventory';
641
+ const origin = `${this.id}-${meth}`;
642
+ log.trace(origin);
643
+
644
+ return super.iapGetAdapterInventory(callback);
527
645
  }
528
646
 
529
647
  /**