@itentialopensource/adapter-microsoft_graph 1.4.7 → 1.5.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 (45) hide show
  1. package/.eslintrc.js +1 -0
  2. package/AUTH.md +4 -4
  3. package/BROKER.md +4 -4
  4. package/CALLS.md +9 -9
  5. package/ENHANCE.md +3 -3
  6. package/PROPERTIES.md +24 -9
  7. package/README.md +24 -23
  8. package/SUMMARY.md +2 -2
  9. package/SYSTEMINFO.md +1 -1
  10. package/TAB1.md +2 -2
  11. package/TAB2.md +17 -11
  12. package/TROUBLESHOOT.md +10 -1
  13. package/UTILITIES.md +473 -0
  14. package/adapter.js +5 -5
  15. package/adapterBase.js +52 -16
  16. package/package.json +24 -28
  17. package/pronghorn.json +15 -13
  18. package/propertiesSchema.json +68 -7
  19. package/report/adapterInfo.json +7 -7
  20. package/report/auto-adapter-openapi.json +8063 -0
  21. package/report/updateReport1748551976792.json +120 -0
  22. package/sampleProperties.json +4 -0
  23. package/test/integration/adapterTestBasicGet.js +88 -54
  24. package/test/integration/adapterTestConnectivity.js +15 -16
  25. package/test/integration/adapterTestIntegration.js +1 -38
  26. package/test/unit/adapterBaseTestUnit.js +641 -39
  27. package/test/unit/adapterTestUnit.js +17 -54
  28. package/utils/adapterInfo.js +114 -164
  29. package/utils/argParser.js +44 -0
  30. package/utils/checkMigrate.js +77 -38
  31. package/utils/entitiesToDB.js +53 -42
  32. package/utils/logger.js +26 -0
  33. package/utils/modify.js +56 -55
  34. package/utils/mongoDbConnection.js +79 -0
  35. package/utils/mongoUtils.js +162 -0
  36. package/utils/taskMover.js +31 -32
  37. package/utils/tbScript.js +36 -172
  38. package/utils/tbUtils.js +84 -226
  39. package/utils/troubleshootingAdapter.js +68 -84
  40. package/utils/updateAdapterConfig.js +158 -0
  41. package/utils/addAuth.js +0 -94
  42. package/utils/artifactize.js +0 -146
  43. package/utils/basicGet.js +0 -50
  44. package/utils/packModificationScript.js +0 -35
  45. package/utils/patches2bundledDeps.js +0 -90
package/utils/tbUtils.js CHANGED
@@ -1,18 +1,59 @@
1
- /* @copyright Itential, LLC 2020 */
1
+ /* @copyright Itential, LLC 2025 */
2
2
 
3
3
  /* eslint import/no-extraneous-dependencies: warn */
4
4
  /* eslint global-require: warn */
5
5
  /* eslint import/no-dynamic-require: warn */
6
6
  /* eslint-disable no-console */
7
7
 
8
+ /**
9
+ * This script contains manhy of the basic troubleshooting scripts. In addition, it contains helper functions
10
+ * that are utilized by other utilities.
11
+ *
12
+ * This utility is utilized by tbScript when the troubleshooting scripts are run via the CLI. It is also utilized
13
+ * by the adapterBase.js when the troubleshooting scripts are exposed by the adapter and run through Platform
14
+ * Workflow or any other Platform component.
15
+ */
16
+
8
17
  const path = require('path');
9
18
  const cp = require('child_process');
10
- const fs = require('fs-extra');
19
+ const axios = require('axios');
20
+ const log = require('./logger');
21
+ const MongoDBConnection = require('./mongoDbConnection');
11
22
 
12
23
  module.exports = {
13
24
  SERVICE_CONFIGS_COLLECTION: 'service_configs',
14
25
  IAP_PROFILES_COLLECTION: 'iap_profiles',
15
26
 
27
+ /**
28
+ * @summary create Adapter instance
29
+ *
30
+ * @function getAdapterInstance
31
+ * @param {Object} adapter - adaper configuration object required by IAP
32
+ */
33
+ getAdapterInstance: (adapter) => {
34
+ const Adapter = require('../adapter');
35
+ const adapterProps = JSON.parse(JSON.stringify(adapter.properties.properties));
36
+ adapterProps.stub = false;
37
+ return new Adapter(
38
+ adapter.id,
39
+ adapterProps
40
+ );
41
+ },
42
+
43
+ /**
44
+ * @summary Makes a GET call using axios
45
+ *
46
+ * @function get
47
+ * @param {String} url - url to make the call to
48
+ */
49
+ get: (url) => {
50
+ const config = {
51
+ method: 'get',
52
+ url
53
+ };
54
+ return axios(config);
55
+ },
56
+
16
57
  /**
17
58
  * @summary update newConnection properties in adapter config
18
59
  *
@@ -37,28 +78,20 @@ module.exports = {
37
78
  */
38
79
  getHealthCheckEndpointURL: (endpoint, config) => {
39
80
  const p = config.properties.properties;
40
- const healthCheckEndpointURL = `${p.protocol}://${p.host}${p.base_path}${p.version}${endpoint.healthCheckEndpoint}`;
41
- console.log({ healthCheckEndpointURL });
42
- return healthCheckEndpointURL;
43
- },
81
+ // Handle base_path and version properly
82
+ let basePath = '';
83
+ if (p.base_path && p.base_path !== '/') {
84
+ basePath = p.base_path.startsWith('/') ? p.base_path : `/${p.base_path}`;
85
+ }
44
86
 
45
- /**
46
- * @summary persist healthcheck endpoint when user make update
47
- *
48
- * @function updateHealthCheckEndpoint
49
- * @param {Object} newHealthCheckEndpoint - user confirmed healthcheck object
50
- * @param {Object} healthCheckEndpoint - existing healthcheck object
51
- * @param {Object} healthcheck - ./entities/.system/action.json object
52
- */
53
- updateHealthCheckEndpoint: (newHealthCheckEndpoint, healthCheckEndpoint, healthcheck) => {
54
- if (newHealthCheckEndpoint.healthCheckEndpoint !== healthCheckEndpoint.healthCheckEndpoint) {
55
- const p = healthcheck.actions[1].entitypath;
56
- const newEntitypath = p.slice(0, 21) + newHealthCheckEndpoint.healthCheckEndpoint + p.slice(p.length - 8);
57
- const updatedHealthcheck = JSON.parse(JSON.stringify(healthcheck));
58
- updatedHealthcheck.actions[1].entitypath = newEntitypath;
59
- console.log('updating healthcheck setting');
60
- fs.writeFileSync('./entities/.system/action.json', JSON.stringify(updatedHealthcheck, null, 2));
87
+ let version = '';
88
+ if (p.version) {
89
+ version = p.version.startsWith('/') ? p.version : `/${p.version}`;
61
90
  }
91
+
92
+ const healthCheckEndpointURL = `${p.protocol}://${p.host}${basePath}${version}${endpoint.healthCheckEndpoint}`;
93
+ log.info({ healthCheckEndpointURL });
94
+ return healthCheckEndpointURL;
62
95
  },
63
96
 
64
97
  /**
@@ -78,7 +111,7 @@ module.exports = {
78
111
  Object.keys(newAuth).forEach((key) => {
79
112
  updatedConfig.properties.properties.authentication[key] = newAuth[key];
80
113
  });
81
- console.log(updatedConfig.properties.properties.authentication);
114
+ log.info(updatedConfig.properties.properties.authentication);
82
115
  return updatedConfig;
83
116
  },
84
117
 
@@ -95,22 +128,6 @@ module.exports = {
95
128
  return displayAuthOptions;
96
129
  },
97
130
 
98
- /**
99
- * @summary decrypt IAP properties
100
- * code from pronghorn-core/migration_scripts/installService.js
101
- *
102
- * @function decryptProperties
103
- */
104
- decryptProperties: (props, iapDir) => {
105
- const { PropertyEncryption } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
106
- const propertyEncryption = new PropertyEncryption({
107
- algorithm: 'aes-256-ctr',
108
- key: 'TG9uZ0Rpc3RhbmNlUnVubmVyUHJvbmdob3JuCg==',
109
- encoding: 'utf-8'
110
- });
111
- return propertyEncryption.decryptProps(props);
112
- },
113
-
114
131
  /**
115
132
  * @summary create connection object for verification
116
133
  *
@@ -162,31 +179,6 @@ module.exports = {
162
179
  return { healthCheckEndpoint: endpoint };
163
180
  },
164
181
 
165
- /**
166
- * @summary Verify that the adapter is in the correct directory
167
- * - Within IAP
168
- * - In node_modules/@ namespace
169
- * verify the adapter is installed under node_modules/
170
- * and is consistent with the name property of package.json
171
- * and the node_modules/ is in the correct path within IAP
172
- * @param {String} dirname - current path
173
- * @param {String} name - name property from package.json
174
- */
175
- verifyInstallationDir: (dirname, name) => {
176
- const pathArray = dirname.split(path.sep);
177
- const expectedPath = `node_modules/${name}`;
178
- const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
179
- if (currentPath.trim() !== expectedPath.trim()) {
180
- throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
181
- }
182
-
183
- const serverFile = path.join(dirname, '../../../', 'server.js');
184
- if (!fs.existsSync(serverFile)) {
185
- throw new Error(`adapter should be installed under IAP/${expectedPath}`);
186
- }
187
- console.log(`adapter correctly installed at ${currentPath}`);
188
- },
189
-
190
182
  /**
191
183
  * @summary execute command and preserve the output the same as run command in shell
192
184
  *
@@ -200,7 +192,7 @@ module.exports = {
200
192
  try {
201
193
  stdout = cp.execSync(cmd).toString();
202
194
  } catch (error) {
203
- console.log('execute command error', error.stdout.toString(), error.stderr.toString());
195
+ log.info('execute command error', error.stdout.toString(), error.stderr.toString());
204
196
  stdout = error.stdout.toString();
205
197
  }
206
198
  const output = this.getTestCount(stdout);
@@ -247,17 +239,6 @@ module.exports = {
247
239
  return { passCount, failCount };
248
240
  },
249
241
 
250
- /**
251
- * @summary remove package-lock.json and node_modules directory if exists
252
- * run npm install and print result to stdout
253
- */
254
- npmInstall: function npmInstall() {
255
- fs.removeSync('../package-lock.json');
256
- fs.removeSync('../node_modules/');
257
- console.log('Run npm install ...');
258
- this.systemSync('npm install');
259
- },
260
-
261
242
  /**
262
243
  * @summary run lint, unit test and integration test
263
244
  * print result to stdout
@@ -271,12 +252,21 @@ module.exports = {
271
252
  /**
272
253
  * @summary run basicget with mocha
273
254
  * @param {boolean} scriptFlag - whether the function is ran from a script
255
+ * @param {number} maxCalls - how many GETs to run (defaults to 5)
274
256
  * print result to stdout
275
257
  * returns mocha test results otherwise
276
258
  */
277
- runBasicGet: function runBasicGet(scriptFlag) {
278
- const testPath = path.resolve(__dirname, '..', 'test/integration/adapterTestBasicGet.js');
279
- return this.systemSync(`mocha ${testPath} --exit`, !scriptFlag);
259
+ runBasicGet: function runBasicGet(props, scriptFlag, maxCalls = 5) {
260
+ let testPath = 'test/integration/adapterTestBasicGet.js';
261
+ let executable = 'mocha';
262
+ if (!scriptFlag) {
263
+ testPath = path.resolve(__dirname, '..', testPath);
264
+ executable = path.join(__dirname, '..', 'node_modules/mocha/bin/mocha.js');
265
+ }
266
+ // if caller passed a number, add the flag
267
+ const mcFlag = Number.isInteger(maxCalls) ? ` --MAXCALLS=${maxCalls}` : '';
268
+ const cmd = `${executable} ${testPath} --PROPS='${JSON.stringify(props)}'${mcFlag} --timeout 60000 --exit`;
269
+ return this.systemSync(cmd, !scriptFlag);
280
270
  },
281
271
 
282
272
  /**
@@ -291,94 +281,11 @@ module.exports = {
291
281
  let executable = 'mocha';
292
282
  if (!scriptFlag) {
293
283
  testPath = path.resolve(__dirname, '..', testPath);
294
- executable = path.join(__dirname, '..', 'node_modules/mocha/bin/mocha');
284
+ executable = path.join(__dirname, '..', 'node_modules/mocha/bin/mocha.js');
295
285
  }
296
286
  return this.systemSync(`${executable} ${testPath} --HOST=${host} --timeout 10000 --exit`, !scriptFlag);
297
287
  },
298
288
 
299
- /**
300
- * @summary create Adapter property
301
- *
302
- * @function createAdapter
303
- * @param {Object} pronghornProps - decrypted 'properties.json' from IAP root directory
304
- * @param {Object} profileItem - pronghorn props saved in database
305
- * @param {Object} adapterPronghorn - ./pronghorn.json in adapter dir
306
- * @param {Object} sampleProperties - './sampleProperties.json' in adapter dir
307
- */
308
- createAdapter: function createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn) {
309
- const iapDir = this.getIAPHome();
310
- const packageFile = path.join(iapDir, 'package.json');
311
- const info = JSON.parse(fs.readFileSync(packageFile));
312
- const version = parseInt(info.version.split('.')[0], 10);
313
-
314
- let adapter = {};
315
- if (version >= 2020) {
316
- adapter = {
317
- isEncrypted: pronghornProps.pathProps.encrypted,
318
- model: adapterPronghorn.id,
319
- name: sampleProperties.id,
320
- type: adapterPronghorn.type,
321
- properties: sampleProperties,
322
- loggerProps: profileItem.loggerProps
323
- };
324
- } else {
325
- adapter = {
326
- mongoProps: pronghornProps.mongoProps,
327
- isEncrypted: pronghornProps.pathProps.encrypted,
328
- model: adapterPronghorn.id,
329
- name: sampleProperties.id,
330
- type: adapterPronghorn.type,
331
- properties: sampleProperties,
332
- redisProps: profileItem.redisProps,
333
- loggerProps: profileItem.loggerProps,
334
- rabbitmq: profileItem.rabbitmq
335
- };
336
- adapter.mongoProps.pdb = true;
337
- }
338
-
339
- adapter.loggerProps.log_filename = `adapter-${adapter.name}.log`;
340
- return adapter;
341
- },
342
-
343
- getPronghornProps: function getPronghornProps() {
344
- const iapDir = this.getIAPHome();
345
- console.log('Retrieving properties.json file...');
346
- const rawProps = require(path.join(iapDir, 'properties.json'));
347
- console.log('Decrypting properties...');
348
- const pronghornProps = this.decryptProperties(rawProps, iapDir);
349
- console.log('Found properties.\n');
350
- return pronghornProps;
351
- },
352
-
353
- getAllAdapterInstances: async function getAllAdapterInstances() {
354
- const database = await this.getIAPDatabaseConnection();
355
- const { name } = require(path.join(__dirname, '..', 'package.json'));
356
- const query = { model: name };
357
- const options = { projection: { name: 1 } };
358
- const adapterInstancesNames = await database.collection(this.SERVICE_CONFIGS_COLLECTION).find(
359
- query,
360
- options
361
- ).toArray();
362
- return adapterInstancesNames;
363
- },
364
-
365
- // get database connection and existing adapter config
366
- getAdapterConfig: async function getAdapterConfig(adapterId) {
367
- const database = await this.getIAPDatabaseConnection();
368
- const { name } = require(path.join(__dirname, '..', 'package.json'));
369
- let query = {};
370
- if (!adapterId) {
371
- query = { model: name };
372
- } else {
373
- query = { _id: adapterId };
374
- }
375
- const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
376
- query
377
- );
378
- const pronghornProps = await this.getPronghornProps();
379
- return { database, serviceItem, pronghornProps };
380
- },
381
-
382
289
  /**
383
290
  * @summary return async healthcheck result as a Promise
384
291
  *
@@ -403,7 +310,7 @@ module.exports = {
403
310
  healthCheck: async function healthCheck(a) {
404
311
  const result = await this.request(a)
405
312
  .then((res) => {
406
- console.log('healthCheckEndpoint OK');
313
+ log.info('healthCheckEndpoint OK');
407
314
  return res;
408
315
  })
409
316
  .catch((error) => {
@@ -414,76 +321,27 @@ module.exports = {
414
321
  },
415
322
 
416
323
  /**
417
- * @summary Obtain the IAP installation directory depending on how adapter is used:
418
- * by IAP, or by npm run CLI interface
419
- * @returns IAP installation directory or null if adapter running without IAP
420
- * @function getIAPHome
421
- */
422
- getIAPHome: function getIAPHome() {
423
- let IAPHomePath = null;
424
- // check if adapter started via IAP, use path injected by core
425
- if (process.env.iap_home) IAPHomePath = process.env.iap_home;
426
- // check if adapter started via CLI `npm run <command>` so we have to be located under
427
- // <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ directory
428
- const currentExecutionPath = this.getCurrentExecutionPath();
429
- if (currentExecutionPath.indexOf('/node_modules') >= 0) {
430
- [IAPHomePath] = currentExecutionPath.split('/node_modules');
431
- }
432
- return IAPHomePath;
433
- },
434
-
435
- /**
436
- * @summary get current execution path without resolving symbolic links,
437
- * use `pwd` command wihout '-P' option (resolving symlinks) https://linux.die.net/man/1/pwd
438
- * @returns
439
- * @function getCurrentExecutionPAth
440
- */
441
- getCurrentExecutionPath: function getCurrentExecutionPAth() {
442
- const { stdout } = this.systemSync('pwd', true);
443
- return stdout.trim();
444
- },
445
-
446
- /**
447
- * @summary checks if command executed from <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ location
448
- * @returns true if command executed under <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ path
449
- * @function areWeUnderIAPinstallationDirectory
324
+ * @summary connect to mongodb
325
+ *
326
+ * @function connect
327
+ * @param {Object} properties - pronghornProps
450
328
  */
451
- areWeUnderIAPinstallationDirectory: function areWeUnderIAPinstallationDirectory() {
452
- return path.join(this.getCurrentExecutionPath(), '../../..') === this.getIAPHome();
453
- },
454
-
455
- getIAPDatabaseConnection: async function getIAPDatabaseConnection() {
456
- const pronghornProps = await this.getPronghornProps();
457
- const database = await this.connect(pronghornProps);
329
+ connect: async function connect(properties) {
330
+ const connection = new MongoDBConnection(properties);
331
+ const database = await connection.connect();
458
332
  return database;
459
333
  },
460
334
 
461
335
  /**
462
- * @summary connect to mongodb
336
+ * @summary close mongodb connection
463
337
  *
464
- * @function connect
465
- * @param {Object} properties - pronghornProps
338
+ * @function closeConnection
339
+ * @param {Object} connection - MongoDB connection instance
466
340
  */
467
- connect: async function connect(properties) {
468
- let dbConnectionProperties = {};
469
- if (properties.mongoProps) {
470
- dbConnectionProperties = properties.mongoProps;
471
- } else if (properties.mongo) {
472
- if (properties.mongo.url) {
473
- dbConnectionProperties.url = properties.mongo.url;
474
- } else {
475
- dbConnectionProperties.url = `mongodb://${properties.mongo.host}:${properties.mongo.port}`;
476
- }
477
- dbConnectionProperties.db = properties.mongo.database;
341
+ closeConnection: async function closeConnection(connection) {
342
+ if (connection && connection.closeConnection) {
343
+ await connection.closeConnection();
478
344
  }
479
- if (!dbConnectionProperties.url || !dbConnectionProperties.db) {
480
- throw new Error('Mongo properties are not specified in IAP configuration!');
481
- }
482
- const iapDir = this.getIAPHome();
483
- const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
484
- const connection = new MongoDBConnection(dbConnectionProperties);
485
- const database = await connection.connect(true);
486
- return database;
487
345
  }
488
346
 
489
347
  };
@@ -6,10 +6,8 @@
6
6
 
7
7
  const path = require('path');
8
8
  const rls = require('readline-sync');
9
- const fs = require('fs-extra');
10
9
 
11
- const utils = require(path.join(__dirname, 'tbUtils'));
12
- const basicGet = require(path.join(__dirname, 'basicGet'));
10
+ const tbUtils = require(path.join(__dirname, 'tbUtils'));
13
11
  const { name } = require(path.join(__dirname, '..', 'package.json'));
14
12
  const sampleProperties = require(path.join(__dirname, '..', 'sampleProperties.json'));
15
13
 
@@ -21,7 +19,7 @@ const collectAnswersSync = (questions, props) => {
21
19
  const answer = rls.question(q);
22
20
  answers.push(answer);
23
21
  });
24
- return utils.getNewProps(answers, props);
22
+ return tbUtils.getNewProps(answers, props);
25
23
  };
26
24
 
27
25
  // change object into array of questions
@@ -33,7 +31,7 @@ const confirm = (props) => {
33
31
  // allow user to change auth_method
34
32
  const confirmAuthOptions = (authentication) => {
35
33
  const authOptions = ['basic user_password', 'request_token', 'static_token', 'no_authentication'];
36
- const displayAuthOptions = utils.getDisplayAuthOptions(authentication.auth_method, authOptions);
34
+ const displayAuthOptions = tbUtils.getDisplayAuthOptions(authentication.auth_method, authOptions);
37
35
  const index = rls.keyInSelect(displayAuthOptions, 'Which authentication?');
38
36
  if (index === -1) {
39
37
  return authentication.auth_method;
@@ -45,7 +43,7 @@ const confirmAuthOptions = (authentication) => {
45
43
  // helper function to update auth properties
46
44
  const confirmAndUpdate = (auth, config) => {
47
45
  const newAuth = confirm(auth);
48
- return utils.updateAuth(newAuth, auth, config);
46
+ return tbUtils.updateAuth(newAuth, auth, config);
49
47
  };
50
48
 
51
49
  // extract basic auth properties
@@ -69,34 +67,40 @@ const updateStaticAuth = (config, authentication) => {
69
67
 
70
68
  // troubleshooting connection and healthcheck endpoint setting of adapter
71
69
  const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
72
- // Updates connectivity params and runs connectivity
73
70
  let connConfig;
74
71
  const result = {};
72
+
75
73
  if (scriptFlag) {
76
- const connection = utils.getConnection(serviceItem.properties);
74
+ const connection = tbUtils.getConnection(serviceItem.properties);
77
75
  const newConnection = confirm(connection);
78
- utils.runConnectivity(newConnection.host, scriptFlag);
79
- connConfig = utils.updateNewConnection(serviceItem, newConnection);
76
+ tbUtils.runConnectivity(newConnection.host, scriptFlag);
77
+ connConfig = tbUtils.updateNewConnection(serviceItem, newConnection);
80
78
  } else {
81
79
  let { properties: { properties: { host } } } = serviceItem;
80
+
81
+ connConfig = props.connProps
82
+ ? tbUtils.updateNewConnection(serviceItem, props.connProps)
83
+ : serviceItem;
84
+
82
85
  if (props.connProps) {
83
- connConfig = utils.updateNewConnection(serviceItem, props.connProps);
84
86
  host = connConfig.properties.properties.host;
85
- } else {
86
- connConfig = serviceItem;
87
87
  }
88
- result.connectivity = utils.runConnectivity(host, scriptFlag);
88
+
89
+ result.connectivity = tbUtils.runConnectivity(host, scriptFlag);
89
90
  }
90
- // Updates the healthcheck endpoing
91
- const healthcheck = require('../entities/.system/action.json');
92
- const healthCheckEndpoint = utils.getHealthCheckEndpoint(healthcheck);
91
+
92
+ // Updates the healthcheck endpoint
93
+ const healthcheck = require(path.resolve(__dirname, '../entities/.system/action.json'));
94
+ const healthCheckEndpoint = tbUtils.getHealthCheckEndpoint(healthcheck);
93
95
  let newHealthCheckEndpoint = healthCheckEndpoint;
96
+
94
97
  if (scriptFlag) {
95
98
  newHealthCheckEndpoint = confirm(healthCheckEndpoint);
96
- utils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
99
+ tbUtils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
97
100
  } else if (props.healthCheckEndpoint) {
98
101
  newHealthCheckEndpoint = props.healthCheckEndpoint;
99
102
  }
103
+
100
104
  // Updates the authorization params
101
105
  const { authentication } = connConfig.properties.properties;
102
106
  let updatedAdapter = connConfig;
@@ -110,84 +114,64 @@ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
110
114
  console.log('current troubleshooting script does not support updating request_token authentication');
111
115
  }
112
116
  } else if (props.auth) {
113
- updatedAdapter = utils.updateAuth(props.auth, authentication, connConfig);
117
+ updatedAdapter = tbUtils.updateAuth(props.auth, authentication, connConfig);
114
118
  }
115
- // Writes the new healthcheck endpoint into action.json
116
- utils.updateHealthCheckEndpoint(newHealthCheckEndpoint, healthCheckEndpoint, healthcheck);
117
119
  return { result, updatedAdapter };
118
120
  };
119
121
 
120
- const offline = async () => {
121
- console.log('Start offline troubleshooting');
122
- const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
123
- const a = basicGet.getAdapterInstance(updatedAdapter);
124
- const res = await utils.healthCheck(a);
125
- if (!res) {
126
- console.log('run `npm run troubleshoot` again to update settings');
127
- process.exit(0);
128
- }
129
- console.log('Save changes to sampleProperties.json');
130
- await fs.writeFile('sampleProperties.json', JSON.stringify(updatedAdapter.properties, null, 2));
131
- if (rls.keyInYN('Test with more GET request')) {
132
- await utils.runBasicGet(true);
133
- }
134
- };
135
-
136
- const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
122
+ const troubleshoot = async (props, scriptFlag, adapter) => {
137
123
  let serviceItem;
124
+
138
125
  if (adapter && adapter.allProps) {
139
126
  serviceItem = { properties: { properties: adapter.allProps } };
140
- }
141
- if (adapter && adapter.properties && adapter.properties.properties) {
127
+ } else if (adapter && adapter.properties && adapter.properties.properties) {
142
128
  serviceItem = adapter.properties;
129
+ } else {
130
+ serviceItem = { properties: sampleProperties };
131
+ }
132
+
133
+ if (!serviceItem) {
134
+ console.log(`${name} not installed`);
135
+ console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
136
+ if (scriptFlag) {
137
+ process.exit(1);
138
+ }
139
+ return null;
140
+ }
141
+
142
+ const shouldRun = !scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`);
143
+ if (!shouldRun) {
144
+ console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
145
+ console.log('You can update authentication credientials under Settings/Services');
146
+ if (scriptFlag) {
147
+ process.exit(0);
148
+ }
149
+ return null;
150
+ }
151
+
152
+ const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
153
+ const a = scriptFlag ? tbUtils.getAdapterInstance(updatedAdapter) : adapter;
154
+
155
+ const healthRes = await tbUtils.healthCheck(a);
156
+ result.healthCheck = healthRes;
157
+
158
+ if (scriptFlag && !healthRes) {
159
+ console.log('run `npm run troubleshoot` again to update settings');
160
+ process.exit(1);
143
161
  }
144
- if (serviceItem) {
145
- if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
146
- const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
147
- let a;
148
- if (scriptFlag) {
149
- a = basicGet.getAdapterInstance(updatedAdapter);
150
- } else {
151
- a = adapter;
152
- }
153
- const healthRes = await utils.healthCheck(a);
154
- result.healthCheck = healthRes;
155
- if (scriptFlag && !healthRes) {
156
- console.log('run `npm run troubleshoot` again to update settings');
157
- process.exit(0);
158
- }
159
-
160
- if (persistFlag && healthRes) {
161
- const { database } = await utils.getIAPDatabaseConnection();
162
- const update = { $set: { properties: updatedAdapter.properties } };
163
- await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne({ model: name }, update);
164
- if (scriptFlag) {
165
- console.log(`${name} updated.`);
166
- }
167
- }
168
- if (scriptFlag) {
169
- if (rls.keyInYN('Test with more GET request')) {
170
- await utils.runBasicGet(scriptFlag);
171
- process.exit(0);
172
- } else {
173
- console.log('Exiting');
174
- process.exit(0);
175
- }
176
- } else {
177
- result.basicGet = await utils.runBasicGet(scriptFlag);
178
- return result;
179
- }
162
+
163
+ if (scriptFlag) {
164
+ if (rls.keyInYN('Test with more GET request')) {
165
+ await tbUtils.runBasicGet(serviceItem.properties.properties, true);
180
166
  } else {
181
- console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
182
- console.log('You can update authentication credientials under Settings/Services');
183
167
  console.log('Exiting');
184
- process.exit(0);
185
168
  }
186
- } else {
187
- console.log(`${name} not installed`);
188
- console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
169
+ process.exit(0);
189
170
  }
190
- return null;
171
+
172
+ result.basicGet = await tbUtils.runBasicGet(serviceItem.properties.properties, false);
173
+
174
+ return result;
191
175
  };
192
176
 
193
- module.exports = { troubleshoot, offline };
177
+ module.exports = { troubleshoot };