@itentialopensource/adapter-microsoft_graph 1.4.8 → 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
@@ -18,10 +18,10 @@ const { expect } = require('chai');
18
18
  const { use } = require('chai');
19
19
  const td = require('testdouble');
20
20
  const Ajv = require('ajv');
21
+ const log = require('../../utils/logger');
21
22
 
22
23
  const ajv = new Ajv({ strictSchema: false, allErrors: true, allowUnionTypes: true });
23
24
  const anything = td.matchers.anything();
24
- let logLevel = 'none';
25
25
  const isRapidFail = false;
26
26
 
27
27
  // read in the properties from the sampleProperties files
@@ -68,43 +68,6 @@ global.pronghornProps = {
68
68
 
69
69
  global.$HOME = `${__dirname}/../..`;
70
70
 
71
- // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
72
- // this you may error on log.trace calls.
73
- const myCustomLevels = {
74
- levels: {
75
- spam: 6,
76
- trace: 5,
77
- debug: 4,
78
- info: 3,
79
- warn: 2,
80
- error: 1,
81
- none: 0
82
- }
83
- };
84
-
85
- // need to see if there is a log level passed in
86
- process.argv.forEach((val) => {
87
- // is there a log level defined to be passed in?
88
- if (val.indexOf('--LOG') === 0) {
89
- // get the desired log level
90
- const inputVal = val.split('=')[1];
91
-
92
- // validate the log level is supported, if so set it
93
- if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
94
- logLevel = inputVal;
95
- }
96
- }
97
- });
98
-
99
- // need to set global logging
100
- global.log = winston.createLogger({
101
- level: logLevel,
102
- levels: myCustomLevels.levels,
103
- transports: [
104
- new winston.transports.Console()
105
- ]
106
- });
107
-
108
71
  /**
109
72
  * Runs the error asserts for the test
110
73
  */
@@ -318,16 +281,16 @@ describe('[unit] Microsoft_graph Adapter Test', () => {
318
281
  assert.notEqual(undefined, packageDotJson.dependencies);
319
282
  assert.notEqual(null, packageDotJson.dependencies);
320
283
  assert.notEqual('', packageDotJson.dependencies);
321
- assert.equal('^8.17.1', packageDotJson.dependencies.ajv);
322
- assert.equal('^1.8.2', packageDotJson.dependencies.axios);
323
- assert.equal('^11.0.0', packageDotJson.dependencies.commander);
324
- assert.equal('^11.2.0', packageDotJson.dependencies['fs-extra']);
325
- assert.equal('^10.8.2', packageDotJson.dependencies.mocha);
326
- assert.equal('^2.0.1', packageDotJson.dependencies['mocha-param']);
327
- assert.equal('^0.4.4', packageDotJson.dependencies.ping);
328
- assert.equal('^1.4.10', packageDotJson.dependencies['readline-sync']);
329
- assert.equal('^7.6.3', packageDotJson.dependencies.semver);
330
- assert.equal('^3.17.0', packageDotJson.dependencies.winston);
284
+ assert.equal('8.17.1', packageDotJson.dependencies.ajv);
285
+ assert.equal('1.9.0', packageDotJson.dependencies.axios);
286
+ assert.equal('11.1.0', packageDotJson.dependencies.commander);
287
+ assert.equal('11.3.0', packageDotJson.dependencies['fs-extra']);
288
+ assert.equal('10.8.2', packageDotJson.dependencies.mocha);
289
+ assert.equal('2.0.1', packageDotJson.dependencies['mocha-param']);
290
+ assert.equal('0.4.4', packageDotJson.dependencies.ping);
291
+ assert.equal('1.4.10', packageDotJson.dependencies['readline-sync']);
292
+ assert.equal('7.7.2', packageDotJson.dependencies.semver);
293
+ assert.equal('3.17.0', packageDotJson.dependencies.winston);
331
294
  done();
332
295
  } catch (error) {
333
296
  log.error(`Test Failure: ${error}`);
@@ -340,12 +303,12 @@ describe('[unit] Microsoft_graph Adapter Test', () => {
340
303
  assert.notEqual(undefined, packageDotJson.devDependencies);
341
304
  assert.notEqual(null, packageDotJson.devDependencies);
342
305
  assert.notEqual('', packageDotJson.devDependencies);
343
- assert.equal('^4.3.7', packageDotJson.devDependencies.chai);
344
- assert.equal('^8.44.0', packageDotJson.devDependencies.eslint);
345
- assert.equal('^15.0.0', packageDotJson.devDependencies['eslint-config-airbnb-base']);
346
- assert.equal('^2.27.5', packageDotJson.devDependencies['eslint-plugin-import']);
347
- assert.equal('^3.1.0', packageDotJson.devDependencies['eslint-plugin-json']);
348
- assert.equal('^3.18.0', packageDotJson.devDependencies.testdouble);
306
+ assert.equal('4.5.0', packageDotJson.devDependencies.chai);
307
+ assert.equal('8.57.0', packageDotJson.devDependencies.eslint);
308
+ assert.equal('15.0.0', packageDotJson.devDependencies['eslint-config-airbnb-base']);
309
+ assert.equal('2.31.0', packageDotJson.devDependencies['eslint-plugin-import']);
310
+ assert.equal('3.1.0', packageDotJson.devDependencies['eslint-plugin-json']);
311
+ assert.equal('3.18.0', packageDotJson.devDependencies.testdouble);
349
312
  done();
350
313
  } catch (error) {
351
314
  log.error(`Test Failure: ${error}`);
@@ -1,20 +1,94 @@
1
1
  #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
2
+ /* @copyright Itential, LLC 2025 */
3
+
3
4
  /* eslint global-require:warn */
4
5
  /* eslint import/no-dynamic-require:warn */
5
6
  /* eslint prefer-destructuring:warn */
6
7
 
8
+ /**
9
+ * This script will determine the information about the adapter and store
10
+ * it into a file in the adapter. This is self contained and only depends on
11
+ * finding files within the adapter to gather information.
12
+ *
13
+ * This utility is used when adapters are committed and pushed. It is not used by
14
+ * any customers nor is it references in any scripts.
15
+ */
16
+
7
17
  const path = require('path');
8
18
  const fs = require('fs-extra');
9
19
 
10
20
  /**
11
- * This script will determine the information about the adapter and store
12
- * it into a file in the adapter.
21
+ * @summary Count the number of lines in a file
22
+ * @param {string} filePath - The path to the file
23
+ * @returns {number} The total number of lines in the file
24
+ */
25
+ function countLinesInFile(filePath) {
26
+ if (fs.existsSync(filePath)) {
27
+ const cFile = fs.readFileSync(filePath, 'utf8');
28
+ return cFile.split('\n').length;
29
+ }
30
+ console.log(`Missing - ${path.basename(filePath)}`);
31
+ return 0;
32
+ }
33
+
34
+ /**
35
+ * @summary Count the number of lines across multiple files
36
+ * @param {array} filePaths - An array of file paths
37
+ * @returns {number} The total number of lines across all files
38
+ */
39
+ function countLinesInFiles(filePaths) {
40
+ return filePaths.reduce((total, filePath) => total + countLinesInFile(filePath), 0);
41
+ }
42
+
43
+ /**
44
+ * @summary Count the number of lines in all json files within an entity directory
45
+ * @param {string} entityDir - The entity directory
46
+ * @returns {number} The total number of lines across all JSON files in the entity directory
47
+ */
48
+ function countEntityLines(entityDir) {
49
+ let totalLines = 0;
50
+
51
+ if (!fs.existsSync(entityDir)) {
52
+ console.log('Could not find the entities directory');
53
+ return totalLines;
54
+ }
55
+ const entities = fs.readdirSync(entityDir);
56
+ for (let e = 0; e < entities.length; e += 1) {
57
+ const entityPath = path.join(entityDir, entities[e]);
58
+ if (fs.statSync(entityPath).isDirectory()) {
59
+ const jsonFiles = fs.readdirSync(entityPath).filter((f) => f.endsWith('.json'));
60
+ for (let j = 0; j < jsonFiles.length; j += 1) {
61
+ totalLines += countLinesInFile(path.join(entityPath, jsonFiles[j]));
62
+ }
63
+ }
64
+ }
65
+ return totalLines;
66
+ }
67
+
68
+ /**
69
+ * @summary Count the number of test cases in a file
70
+ * @param {string} filePath - The path to the test file
71
+ * @returns {number} The total number of test cases in the file
13
72
  */
73
+ function countTestsInFile(filePath) {
74
+ if (fs.existsSync(filePath)) {
75
+ const tFile = fs.readFileSync(filePath, 'utf8');
76
+ const ttestCount = tFile.split('it(\'').length;
77
+ return ttestCount;
78
+ }
79
+ console.log(`Missing - ${path.basename(filePath)}`);
80
+ return 0;
81
+ }
14
82
 
15
83
  /**
16
- * get adapter information
84
+ * @summary Count the number of test cases across multiple files
85
+ * @param {array} filePaths - An array of test file paths
86
+ * @returns {number} The total number of test cases across all files
17
87
  */
88
+ function countTestsInFiles(filePaths) {
89
+ return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
90
+ }
91
+
18
92
  function adapterInfo() {
19
93
  // set the base pase of the adapter - tool shoud be one level up in utils
20
94
  let adaptdir = __dirname;
@@ -23,172 +97,43 @@ function adapterInfo() {
23
97
  if (adaptdir.endsWith('/utils')) {
24
98
  adaptdir = adaptdir.substring(0, adaptdir.length - 6);
25
99
  }
100
+
101
+ // if no package.json then not in right place - end with error
102
+ if (!fs.existsSync(`${adaptdir}/package.json`)) {
103
+ throw new Error('Missing - package.json');
104
+ }
26
105
  const pack = require(`${adaptdir}/package.json`);
27
106
  infoRes.version = pack.version;
28
107
 
29
108
  let configCount = 0;
30
- if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
31
- const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
32
- configCount += cFile.split('\n').length;
33
- } else {
34
- console.log('Missing - pronghorn.json');
35
- }
36
- if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
37
- const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
38
- configCount += cFile.split('\n').length;
39
- } else {
40
- console.log('Missing - propertiesSchema.json');
41
- }
42
- if (fs.existsSync(`${adaptdir}/error.json`)) {
43
- const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
44
- configCount += cFile.split('\n').length;
45
- } else {
46
- console.log('Missing - error.json');
47
- }
48
- const entitydir = path.join(adaptdir, '/entities');
49
- if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
50
- const entities = fs.readdirSync(entitydir);
51
- // need to go through each entity in the entities directory
52
- for (let e = 0; e < entities.length; e += 1) {
53
- if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
54
- const cfiles = fs.readdirSync(entitydir);
55
- for (let c = 0; c < cfiles.length; c += 1) {
56
- if (cfiles[c].endsWith('.json')) {
57
- const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
58
- configCount += ccFile.split('\n').length;
59
- }
60
- }
61
- }
62
- }
63
- } else {
64
- console.log('Could not find the entities directory');
65
- }
109
+ const configFiles = ['pronghorn.json', 'propertiesSchema.json', 'error.json'].map((f) => path.join(adaptdir, f));
110
+ configCount = countLinesInFiles(configFiles);
111
+
112
+ const entityDir = path.join(adaptdir, '/entities');
113
+ configCount += countEntityLines(entityDir);
114
+
66
115
  infoRes.configLines = configCount;
67
116
 
68
- let scodeCount = 0;
69
- if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
70
- const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
71
- scodeCount += sFile.split('\n').length;
72
- } else {
73
- console.log('Missing - utils/artifactize.js');
74
- }
75
- if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
76
- const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
77
- scodeCount += sFile.split('\n').length;
78
- } else {
79
- console.log('Missing - utils/basicGet.js');
80
- }
81
- if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
82
- const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
83
- scodeCount += sFile.split('\n').length;
84
- } else {
85
- console.log('Missing - utils/checkMigrate.js');
86
- }
87
- if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
88
- const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
89
- scodeCount += sFile.split('\n').length;
90
- } else {
91
- console.log('Missing - utils/findPath.js');
92
- }
93
- if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
94
- const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
95
- scodeCount += sFile.split('\n').length;
96
- } else {
97
- console.log('Missing - utils/modify.js');
98
- }
99
- if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
100
- const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
101
- scodeCount += sFile.split('\n').length;
102
- } else {
103
- console.log('Missing - utils/packModificationScript.js');
104
- }
105
- if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
106
- const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
107
- scodeCount += sFile.split('\n').length;
108
- } else {
109
- console.log('Missing - utils/setup.js');
110
- }
111
- if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
112
- const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
113
- scodeCount += sFile.split('\n').length;
114
- } else {
115
- console.log('Missing - utils/tbScript.js');
116
- }
117
- if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
118
- const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
119
- scodeCount += sFile.split('\n').length;
120
- } else {
121
- console.log('Missing - utils/tbUtils.js');
122
- }
123
- if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
124
- const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
125
- scodeCount += sFile.split('\n').length;
126
- } else {
127
- console.log('Missing - utils/testRunner.js');
128
- }
129
- if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
130
- const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
131
- scodeCount += sFile.split('\n').length;
132
- } else {
133
- console.log('Missing - utils/troubleshootingAdapter.js');
134
- }
135
- infoRes.scriptLines = scodeCount;
117
+ const utilFiles = ['argParser', 'checkMigrate.js', 'entitiesToDB.js', 'findPath.js', 'logger.js', 'methodDocumentor.js', 'modify.js', 'mongoDbConnection.js',
118
+ 'mongoUtils.js', 'setup.js', 'taskMover.js', 'tbScript.js', 'tbUtils.js', 'testRunner.js', 'troubleshootingAdapter.js', 'updateAdapterConfig.js'
119
+ ].map((f) => path.join(adaptdir, 'utils', f));
136
120
 
137
- let codeCount = 0;
138
- if (fs.existsSync(`${adaptdir}/adapter.js`)) {
139
- const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
140
- codeCount += aFile.split('\n').length;
141
- } else {
142
- console.log('Missing - utils/adapter.js');
143
- }
144
- if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
145
- const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
146
- codeCount += aFile.split('\n').length;
147
- } else {
148
- console.log('Missing - utils/adapterBase.js');
149
- }
150
- infoRes.codeLines = codeCount;
151
-
152
- let tcodeCount = 0;
153
- let ttestCount = 0;
154
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
155
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
156
- tcodeCount += tFile.split('\n').length;
157
- ttestCount += tFile.split('it(\'').length;
158
- } else {
159
- console.log('Missing - test/integration/adapterTestBasicGet.js');
160
- }
161
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
162
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
163
- tcodeCount += tFile.split('\n').length;
164
- ttestCount += tFile.split('it(\'').length;
165
- } else {
166
- console.log('Missing - test/integration/adapterTestConnectivity.js');
167
- }
168
- if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
169
- const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
170
- tcodeCount += tFile.split('\n').length;
171
- ttestCount += tFile.split('it(\'').length;
172
- } else {
173
- console.log('Missing - test/integration/adapterTestIntegration.js');
174
- }
175
- if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
176
- const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
177
- tcodeCount += tFile.split('\n').length;
178
- ttestCount += tFile.split('it(\'').length;
179
- } else {
180
- console.log('Missing - test/unit/adapterBaseTestUnit.js');
181
- }
182
- if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
183
- const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
184
- tcodeCount += tFile.split('\n').length;
185
- ttestCount += tFile.split('it(\'').length;
186
- } else {
187
- console.log('Missing - test/unit/adapterTestUnit.js');
188
- }
189
- infoRes.testLines = tcodeCount;
190
- infoRes.testCases = ttestCount;
191
- infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
121
+ infoRes.scriptLines = countLinesInFiles(utilFiles);
122
+
123
+ const adapterFiles = ['adapter.js', 'adapterBase.js'].map((f) => path.join(adaptdir, f));
124
+ infoRes.codeLines = countLinesInFiles(adapterFiles);
125
+
126
+ const testFiles = [
127
+ 'test/integration/adapterTestBasicGet.js',
128
+ 'test/integration/adapterTestConnectivity.js',
129
+ 'test/integration/adapterTestIntegration.js',
130
+ 'test/unit/adapterBaseTestUnit.js',
131
+ 'test/unit/adapterTestUnit.js'
132
+ ].map((f) => path.join(adaptdir, f));
133
+ infoRes.testLines = countLinesInFiles(testFiles);
134
+ infoRes.testCases = countTestsInFiles(testFiles);
135
+
136
+ infoRes.totalCodeLines = infoRes.scriptLines + infoRes.codeLines + infoRes.testLines;
192
137
 
193
138
  if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
194
139
  // Read the entity schema from the file system
@@ -203,4 +148,9 @@ function adapterInfo() {
203
148
  fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
204
149
  }
205
150
 
206
- adapterInfo();
151
+ try {
152
+ adapterInfo();
153
+ } catch (err) {
154
+ console.error(err.message);
155
+ process.exit();
156
+ }
@@ -0,0 +1,44 @@
1
+ const customLevels = {
2
+ spam: 6,
3
+ trace: 5,
4
+ debug: 4,
5
+ info: 3,
6
+ warn: 2,
7
+ error: 1,
8
+ none: 0
9
+ };
10
+
11
+ function parseArgs(argv = process.argv) {
12
+ let properties = null;
13
+ let logLevel = 'none';
14
+ let maxCalls = 5;
15
+ let host = null;
16
+
17
+ argv.forEach((val) => {
18
+ if (val.startsWith('--PROPS=')) {
19
+ // get the properties
20
+ const inputVal = val.split('=')[1];
21
+ properties = JSON.parse(inputVal);
22
+ } else if (val.startsWith('--LOG=')) {
23
+ // get the desired log level
24
+ const level = val.split('=')[1];
25
+ // validate the log level is supported, if so set it
26
+ if (Object.hasOwnProperty.call(customLevels, level)) {
27
+ logLevel = level;
28
+ }
29
+ } else if (val.startsWith('--MAXCALLS=')) {
30
+ const override = parseInt(val.split('=')[1], 10);
31
+ if (!Number.isNaN(override) && override > 0) {
32
+ maxCalls = override;
33
+ }
34
+ } else if (val.startsWith('--HOST=')) {
35
+ [, host] = val.split('=');
36
+ }
37
+ });
38
+
39
+ return {
40
+ properties, logLevel, maxCalls, host
41
+ };
42
+ }
43
+
44
+ module.exports = { parseArgs };
@@ -1,63 +1,102 @@
1
+ /* @copyright Itential, LLC 2025 */
2
+
3
+ /**
4
+ * This script will determine if the adapter needs to be upgraded, a migration is needed or
5
+ * a remediation is needed. This is self contained and depends on accessing GitLab repos as well as
6
+ * finding files within the adapter to gather and compare information.
7
+ *
8
+ * This utility is executed from a script in the package.json by `npm run adapter:checkMigrate`. As a result,
9
+ * this utility is exposed and available to customers but exclusively through the CLI.
10
+ */
11
+
1
12
  const { execSync } = require('child_process');
2
- const fs = require('fs');
3
13
  const semver = require('semver');
4
- const axios = require('axios');
5
14
  const packageJson = require('../package.json');
15
+ const { get } = require('./tbUtils');
6
16
 
17
+ const localAdaptVer = packageJson.version;
7
18
  const localEngineVer = packageJson.engineVersion;
8
19
  const localUtils = execSync('npm list @itentialopensource/adapter-utils', { encoding: 'utf-8' });
9
20
  const localUtilsVer = localUtils.split('@').pop().replace(/(\r\n|\n|\r| )/gm, '');
10
21
 
11
22
  /**
12
- * @summary Makes a GET call using axios
23
+ * @summary Checks if adapter is the latest version
13
24
  *
14
- * @function get
15
- * @param {String} url - url to make the call to
25
+ * @function updateNeeded
16
26
  */
17
- function get(url) {
18
- const config = {
19
- method: 'get',
20
- url
21
- };
22
- return axios(config);
27
+ async function updateNeeded() {
28
+ const adapterUrl = `https://registry.npmjs.org/${packageJson.name}`;
29
+ const latestAdapterVer = (await get(adapterUrl)).data['dist-tags'].latest;
30
+ console.log('\n[Upgrade Check]');
31
+ console.log(`Local Adapter Version : ${localAdaptVer}`);
32
+ console.log(`Latest Adapter Version: ${latestAdapterVer}`);
33
+ return semver.lt(localAdaptVer, latestAdapterVer);
23
34
  }
24
35
 
25
36
  /**
26
- * @summary Checks if adapter can be migrated using migration package
37
+ * @summary Checks if adapter is up-to-date or if migration is needed
27
38
  *
28
- * @function migratePossible
39
+ * @function migrateNeeded
29
40
  */
30
- function migratePossible() {
31
- const adapterTestUnit = fs.readFileSync('./test/unit/adapterTestUnit.js', { encoding: 'utf-8' });
32
- const readme = fs.readFileSync('./README.md', { encoding: 'utf-8' });
33
- return packageJson.keywords !== null && adapterTestUnit.indexOf('DO NOT REMOVE THIS COMMENT BLOCK') !== -1
34
- && readme.indexOf('available at ') !== -1 && readme.indexOf('You will need to change the credentials and possibly the host information below.') !== -1;
41
+ async function migrateNeeded() {
42
+ const engineUrl = 'https://adapters.itential.io/engineVersion';
43
+ const latestEngineVer = (await get(engineUrl)).data;
44
+ console.log('\n[Migration Check]');
45
+ console.log(`Local Engine Version : ${localEngineVer}`);
46
+ console.log(`Latest Engine Version: ${latestEngineVer}`);
47
+ return semver.lt(localEngineVer, latestEngineVer);
35
48
  }
36
49
 
37
50
  /**
38
- * @summary Checks if adapter is up-to-date or if migration is needed
51
+ * @summary Checks if adapter is up-to-date or if remediation is needed
39
52
  *
40
- * @function migrateNeeded
53
+ * @function remediationNeeded
41
54
  */
42
- async function migrateNeeded() {
43
- const engineUrl = 'https://adapters.itential.io/engineVersion';
55
+ async function remediationNeeded() {
44
56
  const utilsUrl = 'https://registry.npmjs.org/@itentialopensource/adapter-utils';
45
- const latestEngineVer = (await get(engineUrl)).data;
46
57
  const latestUtilsVer = (await get(utilsUrl)).data['dist-tags'].latest;
47
- return semver.lt(localEngineVer, latestEngineVer) || semver.lt(localUtilsVer, latestUtilsVer);
58
+ console.log('\n[Remediation Check]');
59
+ console.log(`Local Utils Version : ${localUtilsVer}`);
60
+ console.log(`Latest Utils Version: ${latestUtilsVer}`);
61
+ return semver.lt(localUtilsVer, latestUtilsVer);
48
62
  }
49
63
 
50
- // Main Script
51
- if (migratePossible()) {
52
- migrateNeeded().then((needed) => {
53
- if (needed) {
54
- console.log('Migration is needed and possible -- go to dev site to download migration package');
55
- } else {
56
- console.log('Migration is possible but not needed at the current time.');
57
- }
58
- }).catch((error) => {
59
- console.log('Could not get latest engine or utils version.', error.message);
60
- });
61
- } else {
62
- console.log('Migration is not possible. Please contact Itential support for assistance');
63
- }
64
+ /**
65
+ * @summary Main Script (rest of file)
66
+ *
67
+ * Input - None
68
+ * Process - gets the adapter version from the package.json and compares it to the latest version of the adapter,
69
+ * then get the engine version from the package.json and compare it to the adapter engine version in the repo.
70
+ * then get the local adapter-utils version and compare that to the latest version of adapter-utils.
71
+ * Output - console logs providing state and path forward
72
+ *
73
+ */
74
+ updateNeeded().then((needed) => {
75
+ if (needed) {
76
+ console.log('You should update the adapter to the latest available version -- git pull');
77
+ } else {
78
+ console.log('Update is not needed at the current time.');
79
+ }
80
+ }).catch((error) => {
81
+ console.log('Could not get latest adapter version. Confirm the adapter is an open source adapter.', error.message);
82
+ });
83
+
84
+ migrateNeeded().then((needed) => {
85
+ if (needed) {
86
+ console.log('Migration is needed -- if open source, request Itential migrate the adapter');
87
+ } else {
88
+ console.log('Migration is not needed at the current time.');
89
+ }
90
+ }).catch((error) => {
91
+ console.log('Could not get latest engine version. Confirm the adapter was built by the Itential Adapter Builder.', error.message);
92
+ });
93
+
94
+ remediationNeeded().then((needed) => {
95
+ if (needed) {
96
+ console.log('Remediation is needed -- update the version of adapter-utils in the package.json, remove node modules and package-lock and run npm install');
97
+ } else {
98
+ console.log('Remediation is not needed at the current time.');
99
+ }
100
+ }).catch((error) => {
101
+ console.log('Could not get latest utils version. Confirm the adapter utilizes the Itential adapter foundation.', error.message);
102
+ });