@itentialopensource/adapter-aws_lambda 0.1.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 (77) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +19 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +0 -0
  9. package/AUTH.md +39 -0
  10. package/BROKER.md +211 -0
  11. package/CALLS.md +603 -0
  12. package/CODE_OF_CONDUCT.md +43 -0
  13. package/CONTRIBUTING.md +13 -0
  14. package/ENHANCE.md +69 -0
  15. package/LICENSE +201 -0
  16. package/PROPERTIES.md +661 -0
  17. package/README.md +344 -0
  18. package/SUMMARY.md +9 -0
  19. package/SYSTEMINFO.md +14 -0
  20. package/TROUBLESHOOT.md +56 -0
  21. package/UTILITIES.md +473 -0
  22. package/adapter.js +8845 -0
  23. package/adapterBase.js +1488 -0
  24. package/entities/.generic/action.json +214 -0
  25. package/entities/.generic/schema.json +28 -0
  26. package/entities/.system/action.json +50 -0
  27. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  28. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  29. package/entities/.system/schema.json +19 -0
  30. package/entities/.system/schemaTokenReq.json +53 -0
  31. package/entities/.system/schemaTokenResp.json +53 -0
  32. package/entities/AccountSettings/action.json +25 -0
  33. package/entities/AccountSettings/schema.json +19 -0
  34. package/entities/CodeSigningConfigs/action.json +127 -0
  35. package/entities/CodeSigningConfigs/schema.json +57 -0
  36. package/entities/EventSourceMappings/action.json +106 -0
  37. package/entities/EventSourceMappings/schema.json +78 -0
  38. package/entities/Functions/action.json +860 -0
  39. package/entities/Functions/schema.json +170 -0
  40. package/entities/Layers/action.json +189 -0
  41. package/entities/Layers/schema.json +126 -0
  42. package/entities/Tags/action.json +65 -0
  43. package/entities/Tags/schema.json +32 -0
  44. package/error.json +190 -0
  45. package/metadata.json +58 -0
  46. package/package.json +77 -0
  47. package/pronghorn.json +4833 -0
  48. package/propertiesDecorators.json +14 -0
  49. package/propertiesSchema.json +1635 -0
  50. package/report/AWS Lambda-swagger.fixed.json +15883 -0
  51. package/report/adapterInfo.json +10 -0
  52. package/report/creationReport.json +615 -0
  53. package/sampleProperties.json +274 -0
  54. package/test/integration/adapterTestBasicGet.js +117 -0
  55. package/test/integration/adapterTestConnectivity.js +117 -0
  56. package/test/integration/adapterTestIntegration.js +2103 -0
  57. package/test/unit/adapterBaseTestUnit.js +1626 -0
  58. package/test/unit/adapterTestUnit.js +3942 -0
  59. package/utils/adapterInfo.js +156 -0
  60. package/utils/argParser.js +44 -0
  61. package/utils/checkMigrate.js +102 -0
  62. package/utils/entitiesToDB.js +190 -0
  63. package/utils/findPath.js +74 -0
  64. package/utils/logger.js +26 -0
  65. package/utils/methodDocumentor.js +273 -0
  66. package/utils/modify.js +153 -0
  67. package/utils/mongoDbConnection.js +79 -0
  68. package/utils/mongoUtils.js +162 -0
  69. package/utils/pre-commit.sh +32 -0
  70. package/utils/removeHooks.js +20 -0
  71. package/utils/setup.js +33 -0
  72. package/utils/taskMover.js +308 -0
  73. package/utils/tbScript.js +103 -0
  74. package/utils/tbUtils.js +347 -0
  75. package/utils/testRunner.js +298 -0
  76. package/utils/troubleshootingAdapter.js +177 -0
  77. package/utils/updateAdapterConfig.js +158 -0
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2025 */
3
+
4
+ /* eslint global-require:warn */
5
+ /* eslint import/no-dynamic-require:warn */
6
+ /* eslint prefer-destructuring:warn */
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
+
17
+ const path = require('path');
18
+ const fs = require('fs-extra');
19
+
20
+ /**
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
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
+ }
82
+
83
+ /**
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
87
+ */
88
+ function countTestsInFiles(filePaths) {
89
+ return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
90
+ }
91
+
92
+ function adapterInfo() {
93
+ // set the base pase of the adapter - tool shoud be one level up in utils
94
+ let adaptdir = __dirname;
95
+ const infoRes = {};
96
+
97
+ if (adaptdir.endsWith('/utils')) {
98
+ adaptdir = adaptdir.substring(0, adaptdir.length - 6);
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
+ }
105
+ const pack = require(`${adaptdir}/package.json`);
106
+ infoRes.version = pack.version;
107
+
108
+ let configCount = 0;
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
+
115
+ infoRes.configLines = configCount;
116
+
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));
120
+
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;
137
+
138
+ if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
139
+ // Read the entity schema from the file system
140
+ const phFile = path.join(adaptdir, '/pronghorn.json');
141
+ const prong = require(phFile);
142
+ infoRes.wfTasks = prong.methods.length;
143
+ } else {
144
+ console.log('Missing - pronghorn.json');
145
+ }
146
+
147
+ console.log(JSON.stringify(infoRes));
148
+ fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
149
+ }
150
+
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 };
@@ -0,0 +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
+
12
+ const { execSync } = require('child_process');
13
+ const semver = require('semver');
14
+ const packageJson = require('../package.json');
15
+ const { get } = require('./tbUtils');
16
+
17
+ const localAdaptVer = packageJson.version;
18
+ const localEngineVer = packageJson.engineVersion;
19
+ const localUtils = execSync('npm list @itentialopensource/adapter-utils', { encoding: 'utf-8' });
20
+ const localUtilsVer = localUtils.split('@').pop().replace(/(\r\n|\n|\r| )/gm, '');
21
+
22
+ /**
23
+ * @summary Checks if adapter is the latest version
24
+ *
25
+ * @function updateNeeded
26
+ */
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);
34
+ }
35
+
36
+ /**
37
+ * @summary Checks if adapter is up-to-date or if migration is needed
38
+ *
39
+ * @function migrateNeeded
40
+ */
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);
48
+ }
49
+
50
+ /**
51
+ * @summary Checks if adapter is up-to-date or if remediation is needed
52
+ *
53
+ * @function remediationNeeded
54
+ */
55
+ async function remediationNeeded() {
56
+ const utilsUrl = 'https://registry.npmjs.org/@itentialopensource/adapter-utils';
57
+ const latestUtilsVer = (await get(utilsUrl)).data['dist-tags'].latest;
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);
62
+ }
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
+ });
@@ -0,0 +1,190 @@
1
+ /* @copyright Itential, LLC 2021 */
2
+
3
+ // Set globals
4
+ /* global log */
5
+
6
+ /* eslint import/no-dynamic-require: warn */
7
+ /* eslint global-require: warn */
8
+ /* eslint no-unused-vars: warn */
9
+ /* eslint import/no-unresolved: warn */
10
+ /* eslint no-promise-executor-return: warn */
11
+
12
+ /**
13
+ * This script is used to read through an adapter's entities files
14
+ * and then creates documents and enters them into the IAP mongodb
15
+ */
16
+
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+ const tbUtils = require('./tbUtils');
20
+ const mongoUtils = require('./mongoUtils');
21
+
22
+ /**
23
+ * Function to load sample properties from the file system
24
+ */
25
+ const loadSampleProperties = async () => {
26
+ const samplePath = path.join(__dirname, '../sampleProperties.json');
27
+ if (fs.existsSync(samplePath)) {
28
+ const fullProps = JSON.parse(fs.readFileSync(samplePath, 'utf-8'));
29
+ return fullProps.properties.mongo;
30
+ }
31
+ throw new Error('sampleProperties.json not found');
32
+ };
33
+
34
+ /**
35
+ * Function used to take a file path to a entity directory and build
36
+ * a document that corresponds to the entity files.
37
+ */
38
+ const buildDoc = (pathstring) => {
39
+ let files = fs.readdirSync(pathstring);
40
+
41
+ // load the mockdatafiles
42
+ const mockdatafiles = {};
43
+ if (files.includes('mockdatafiles') && fs.lstatSync(`${pathstring}/mockdatafiles`).isDirectory()) {
44
+ fs.readdirSync(`${pathstring}/mockdatafiles`).forEach((file) => {
45
+ if (file.split('.').pop() === 'json') {
46
+ const mockpath = `${pathstring}/mockdatafiles/${file}`;
47
+ const data = JSON.parse(fs.readFileSync(mockpath));
48
+ mockdatafiles[mockpath.split('/').pop()] = data;
49
+ }
50
+ });
51
+ }
52
+
53
+ // load the action data
54
+ let actions;
55
+ if (files.includes('action.json')) {
56
+ actions = JSON.parse(fs.readFileSync(`${pathstring}/action.json`));
57
+ }
58
+
59
+ // Load schema.json and other schemas in remaining json files
60
+ files = files.filter((f) => (f !== 'action.json') && f.endsWith('.json'));
61
+ const schema = [];
62
+ files.forEach((file) => {
63
+ const data = JSON.parse(fs.readFileSync(`${pathstring}/${file}`));
64
+ schema.push({
65
+ name: file,
66
+ schema: data
67
+ });
68
+ });
69
+
70
+ // return the data
71
+ return {
72
+ actions: actions.actions,
73
+ schema,
74
+ mockdatafiles
75
+ };
76
+ };
77
+
78
+ /**
79
+ * Function used to get the database from the options or a provided directory
80
+ */
81
+ const optionsHandler = async (options) => {
82
+ try {
83
+ // Try mongo properties from service config first
84
+ const mongoPronghornProps = options?.pronghornProps?.mongo;
85
+ const validatedPronghornProps = mongoPronghornProps ? mongoUtils.getAndValidateMongoProps(mongoPronghornProps) : undefined;
86
+ if (validatedPronghornProps) return validatedPronghornProps;
87
+
88
+ // Fallback to sample properties
89
+ const sampleProps = await loadSampleProperties();
90
+ const validatedSampleProps = mongoUtils.getAndValidateMongoProps(sampleProps);
91
+ if (validatedSampleProps) return validatedSampleProps;
92
+
93
+ throw new Error('No mongo properties provided! Need either a complete URL or both host and database');
94
+ } catch (error) {
95
+ log.error('Error in optionsHandler:', error.message);
96
+ throw error;
97
+ }
98
+ };
99
+
100
+ /**
101
+ * Function used to put the adapter configuration into the provided database
102
+ */
103
+ const moveEntitiesToDB = async (targetPath, options) => {
104
+ // set local variables
105
+ let myOpts = options;
106
+ let myPath = targetPath;
107
+ let mongoConnection = null;
108
+
109
+ // if we got a string parse into a JSON object
110
+ if (typeof myOpts === 'string') {
111
+ myOpts = JSON.parse(myOpts);
112
+ }
113
+
114
+ // if there is no target collection - set the collection to the default
115
+ if (!myOpts.targetCollection) {
116
+ myOpts.targetCollection = 'adapter_configs';
117
+ }
118
+
119
+ // if there is no id error since we need an id for the entities
120
+ if (!myOpts.id) {
121
+ throw new Error('Adapter ID required!');
122
+ }
123
+
124
+ // Check valid filepath provided
125
+ if (!myPath) {
126
+ // if no path use the current directory without the utils
127
+ myPath = path.join(__dirname, '../');
128
+ } else if (myPath.slice(-1) === '/') {
129
+ myPath = myPath.slice(0, -1);
130
+ }
131
+
132
+ try {
133
+ // get the database properties from adapter service instance configs
134
+ const currentProps = await optionsHandler(options);
135
+
136
+ // verify set the entity path
137
+ const entitiesPath = `${myPath}/entities`;
138
+ if (!fs.existsSync(entitiesPath)) {
139
+ throw new Error(`Entities path does not exist in filesystem: ${entitiesPath}`);
140
+ } else {
141
+ log.trace('Target found on filesystem');
142
+ }
143
+
144
+ // Get adapter details
145
+ if (!fs.existsSync(`${myPath}/pronghorn.json`)) {
146
+ throw new Error(`pronghorn.json does not exist in path: ${myPath}`);
147
+ } else {
148
+ log.trace('pronghorn.json found on filesystem');
149
+ }
150
+ const adapterData = JSON.parse(fs.readFileSync(`${myPath}/pronghorn.json`));
151
+
152
+ // Load files from the filesystem
153
+ const docs = [];
154
+ const entities = fs.readdirSync(entitiesPath);
155
+ entities.forEach((entity) => {
156
+ const entityPath = `${entitiesPath}/${entity}`;
157
+ const isDir = fs.lstatSync(entitiesPath).isDirectory();
158
+
159
+ // Build doc for entity
160
+ if (isDir) {
161
+ let doc = buildDoc(entityPath);
162
+ doc = {
163
+ id: myOpts.id,
164
+ type: adapterData.id,
165
+ entity,
166
+ ...doc
167
+ };
168
+ docs.push(doc);
169
+ }
170
+ });
171
+
172
+ // Upload documents to db collection
173
+ mongoConnection = await tbUtils.connect(currentProps).catch((err) => { log.error(err); throw err; });
174
+ if (!mongoConnection) {
175
+ log.error('Error occurred when connecting to database', currentProps);
176
+ throw new Error('Database not found');
177
+ }
178
+
179
+ const collection = mongoConnection.db.collection(myOpts.targetCollection);
180
+ const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { log.error(err); throw err; });
181
+ return res;
182
+ } finally {
183
+ // Ensure connection is closed even if an error occurs
184
+ if (mongoConnection) {
185
+ await tbUtils.closeConnection(mongoConnection);
186
+ }
187
+ }
188
+ };
189
+
190
+ module.exports = { moveEntitiesToDB };
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+ /* eslint global-require:warn */
4
+ /* eslint import/no-dynamic-require:warn */
5
+ /* eslint prefer-destructuring:warn */
6
+
7
+ const path = require('path');
8
+ const fs = require('fs-extra');
9
+ const rls = require('readline-sync');
10
+
11
+ /**
12
+ * This script will determine the type of integration test to run
13
+ * based on input. If other information is needed, it will solicit
14
+ * that input and then edit the integration test accordingly.
15
+ */
16
+
17
+ /**
18
+ * Updates the action files
19
+ */
20
+ function checkActionFiles(apath) {
21
+ // verify the path
22
+ if (!apath) {
23
+ console.log(' NO PATH PROVIDED!');
24
+ return 'Done';
25
+ }
26
+
27
+ // make sure the entities directory exists
28
+ const entitydir = path.join(__dirname, '../entities');
29
+ if (!fs.statSync(entitydir).isDirectory()) {
30
+ console.log('Could not find the entities directory');
31
+ return 'error';
32
+ }
33
+
34
+ const entities = fs.readdirSync(entitydir);
35
+ let found = false;
36
+
37
+ // need to go through each entity in the entities directory
38
+ for (let e = 0; e < entities.length; e += 1) {
39
+ // make sure the entity is a directory - do not care about extra files
40
+ // only entities (dir)
41
+ if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
42
+ // see if the action file exists in the entity
43
+ if (fs.existsSync(`${entitydir}/${entities[e]}/action.json`)) {
44
+ // Read the entity actions from the file system
45
+ const actions = require(`${entitydir}/${entities[e]}/action.json`);
46
+
47
+ // go through all of the actions set the appropriate info in the newActions
48
+ for (let a = 0; a < actions.actions.length; a += 1) {
49
+ if (actions.actions[a].entitypath.indexOf(apath) >= 0) {
50
+ found = true;
51
+ console.log(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
52
+ console.log(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
53
+ console.log(' ');
54
+ }
55
+ }
56
+ } else {
57
+ console.log(`Could not find entities ${entities[e]} action.json file`);
58
+ return 'error';
59
+ }
60
+ } else {
61
+ console.log(`Could not find entities ${entities[e]} directory`);
62
+ return 'error';
63
+ }
64
+ }
65
+
66
+ if (!found) {
67
+ console.log(' PATH NOT FOUND!');
68
+ }
69
+ return 'Done';
70
+ }
71
+
72
+ const findPath = rls.question('Enter the path/partial path you are looking for: ');
73
+ console.log(`PATH: ${findPath}`);
74
+ checkActionFiles(findPath);
@@ -0,0 +1,26 @@
1
+ // utils/logger.js
2
+ const winston = require('winston');
3
+ const { parseArgs } = require('./argParser');
4
+
5
+ const customLevels = {
6
+ spam: 6,
7
+ trace: 5,
8
+ debug: 4,
9
+ info: 3,
10
+ warn: 2,
11
+ error: 1,
12
+ none: 0
13
+ };
14
+
15
+ // Only set global logger if it doesn't already exist (i.e., not provided by app)
16
+ if (!global.log) {
17
+ const { logLevel = 'info' } = parseArgs();
18
+
19
+ global.log = winston.createLogger({
20
+ level: logLevel,
21
+ levels: customLevels,
22
+ transports: [new winston.transports.Console()]
23
+ });
24
+ }
25
+
26
+ module.exports = global.log;