@mimik/local 7.1.7 → 7.2.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.
package/README.md CHANGED
@@ -72,14 +72,14 @@ The same `domainName`/`port` rules as in `mSTConfig.json` apply.
72
72
  "secretAccessKey": "Secret access key for Kinesis",
73
73
  "streamNameInfo": "Name of the Kinesis stream for info",
74
74
  "streamNameError": "Name of the Kinesis stream for errors",
75
- "streamNameOther": "Name of the Kinesis stream for all other levels"
75
+ "streamNameOther": "Name of the Kinesis stream for all other levels",
76
76
  "maxEvents": "Number of events buffered before sending to Kinesis",
77
77
  "timeout": "Number of minutes before a timeout triggers sending to Kinesis",
78
78
  "maxSize": "Maximum size in bytes before sending to Kinesis",
79
79
  "maxRetries": "Maximum retries to connect to Kinesis",
80
80
  "httpOptions": {
81
81
  "socketTimeout": "Socket timeout for the HTTP handler (in millisecond)",
82
- "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)",
82
+ "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)"
83
83
  }
84
84
  }
85
85
  ```
@@ -166,9 +166,13 @@ In `standAlone` mode, the test can obtain tokens using `oauth-helper-temp`.
166
166
 
167
167
  **Example**
168
168
  ```js
169
+ // Default import
169
170
  import local from '@mimik/local';
170
- or
171
- import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFiles, scripts, unScripts, commitCheckMsg, start2process, testJsonFile} from '@mimik/local';
171
+ ```
172
+ **Example**
173
+ ```js
174
+ // Named imports
175
+ import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFiles, scripts, unScripts, commitCheckMsg, start2process, testJsonFile } from '@mimik/local';
172
176
  ```
173
177
 
174
178
  * [local](#module_local)
@@ -187,7 +191,7 @@ import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFi
187
191
  * [~dotFiles()](#module_local..dotFiles) ⇒
188
192
  * [~scripts()](#module_local..scripts) ⇒
189
193
  * [~unscripts()](#module_local..unscripts) ⇒
190
- * [~start2process(start)](#module_local..start2process) ⇒
194
+ * [~start2process(start)](#module_local..start2process) ⇒ <code>void</code>
191
195
 
192
196
  <a name="module_local.testJsonFile"></a>
193
197
 
@@ -442,7 +446,7 @@ The following files are needed to perform these actions:
442
446
 
443
447
  | Filename | Description |
444
448
  | -------- | ----------- |
445
- | `../sumo.json` | Sumo Logic endpoints and code
449
+ | `../sumoLog.json` | Sumo Logic endpoints and code
446
450
  | `../kinesisLog.json` | Kinesis configuration
447
451
  | `../s3Log.json` | S3 configuration
448
452
  | `../mSTConfig.json` | mST configuration
@@ -464,38 +468,37 @@ Utility to create `rule files`.
464
468
  Creates the `rule files` for:
465
469
 
466
470
  - `eslint` -> `eslint.config.js`.
467
- - `c8` -> `.nycrc`
468
471
  - `github` -> `.gitignore`
472
+ - `husky` -> `.husky/pre-commit`, `.husky/pre-push`, `.husky/commit-msg`
469
473
 
470
474
  If a file already exists, it will be overwritten.
471
475
  **Category**: sync
472
476
  <a name="module_local..scripts"></a>
473
477
 
474
478
  ### local~scripts() ⇒
475
- Utility to add `scripts` and `husky`.
479
+ Utility to add `scripts` to `package.json`.
476
480
 
477
481
  **Kind**: inner method of [<code>local</code>](#module_local)
478
482
  **Returns**: `null`.
479
483
 
480
- Adds `scripts` and `husky` to `package.json`. If a script already exists, it will be overwritten.
484
+ Adds `scripts` to `package.json`. If a script already exists, it will be overwritten.
481
485
  **Category**: sync
482
486
  <a name="module_local..unscripts"></a>
483
487
 
484
488
  ### local~unscripts() ⇒
485
- Utility to remove `scripts` and `husky`.
489
+ Utility to remove `scripts` from `package.json`.
486
490
 
487
491
  **Kind**: inner method of [<code>local</code>](#module_local)
488
492
  **Returns**: `null`.
489
493
 
490
- Removes `scripts` and `husky` from `package.json`. Only removes the scripts that are in the script file.
494
+ Removes `scripts` from `package.json`. Only removes the scripts that are in the script file.
491
495
  **Category**: sync
492
496
  <a name="module_local..start2process"></a>
493
497
 
494
- ### local~start2process(start) ⇒
498
+ ### local~start2process(start) ⇒ <code>void</code>
495
499
  Set up the environment variables based on given JSON object.
496
500
 
497
501
  **Kind**: inner method of [<code>local</code>](#module_local)
498
- **Returns**: `null`.
499
502
  **Category**: sync
500
503
 
501
504
  | Param | Type | Description |
@@ -2,6 +2,7 @@
2
2
  import globals from 'globals';
3
3
  import importPlugin from 'eslint-plugin-import';
4
4
  import js from '@eslint/js';
5
+ import loggerPlugin from '@mimik/eslint-plugin-logger';
5
6
  import processDoc from '@mimik/eslint-plugin-document-env';
6
7
  import stylistic from '@stylistic/eslint-plugin';
7
8
 
@@ -11,30 +12,27 @@ const MAX_LINES_IN_FILES = 600;
11
12
  const MAX_LINES_IN_FUNCTION = 150;
12
13
  const MAX_STATEMENTS_IN_FUNCTION = 45;
13
14
  const MIN_KEYS_IN_OBJECT = 10;
14
- const MAX_COMPLEXITY = 60;
15
+ const MAX_COMPLEXITY = 30;
15
16
  const ECMA_VERSION = 'latest';
16
17
  const MAX_DEPTH = 6;
17
18
  const ALLOWED_CONSTANTS = [0, 1, -1];
18
19
 
19
20
  export default [
20
21
  {
21
- ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**, coverage/**'],
22
+ ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**', 'coverage/**'],
22
23
  },
23
24
  importPlugin.flatConfigs.recommended,
24
25
  stylistic.configs.recommended,
25
26
  js.configs.all,
26
27
  {
27
28
  plugins: {
29
+ loggerPlugin,
28
30
  processDoc,
29
31
  },
30
32
  languageOptions: {
31
33
  ecmaVersion: ECMA_VERSION,
32
34
  globals: {
33
35
  ...globals.nodeBuiltin,
34
- console: 'readonly',
35
- describe: 'readonly',
36
- it: 'readonly',
37
- structuredClone: 'readonly',
38
36
  },
39
37
  sourceType: 'module',
40
38
  },
@@ -42,6 +40,7 @@ export default [
42
40
  '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
43
41
  '@stylistic/line-comment-position': ['off'],
44
42
  '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
43
+ '@stylistic/quotes': ['warn', 'single'],
45
44
  '@stylistic/semi': ['error', 'always'],
46
45
  'capitalized-comments': ['off'],
47
46
  'complexity': ['error', MAX_COMPLEXITY],
@@ -51,23 +50,43 @@ export default [
51
50
  'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
52
51
  'init-declarations': ['off'],
53
52
  'linebreak-style': ['off'],
53
+ 'loggerPlugin/validate-logger-args': ['error'],
54
54
  'max-depth': ['error', MAX_DEPTH],
55
+ 'max-len': ['off'],
55
56
  'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
56
57
  'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
57
58
  'max-params': ['error', MAX_FUNCTION_PARAMETERS],
58
59
  'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
59
60
  'no-confusing-arrow': ['off'],
60
61
  'no-inline-comments': ['off'],
61
- 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true }],
62
+ 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: true }],
62
63
  'no-process-env': ['error'],
63
64
  'no-ternary': ['off'],
64
65
  'no-undefined': ['off'],
65
- 'no-warning-comments': ['warn'],
66
66
  'one-var': ['error', 'never'],
67
67
  'processDoc/validate-document-env': ['error'],
68
- 'quotes': ['warn', 'single'],
68
+ 'quotes': ['off'],
69
69
  'sort-imports': ['error', { allowSeparatedGroups: true }],
70
70
  'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
71
71
  },
72
72
  },
73
+ {
74
+ files: ['test/**', 'manual-test/**'],
75
+ languageOptions: {
76
+ globals: {
77
+ ...globals.mocha,
78
+ },
79
+ },
80
+ rules: {
81
+ 'import/no-named-as-default-member': ['off'],
82
+ 'no-magic-numbers': ['off'],
83
+ 'no-unused-expressions': ['off'],
84
+ 'no-empty-function': ['off'],
85
+ 'max-lines-per-function': ['off'],
86
+ 'max-statements': ['off'],
87
+ 'max-lines': ['off'],
88
+ 'no-process-env': ['off'],
89
+ 'processDoc/validate-document-env': ['off'],
90
+ },
91
+ },
73
92
  ];
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node ./local/commitMsgCheck $1
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ npm run pre-commit
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ npm run pre-push
package/index.js CHANGED
@@ -8,7 +8,6 @@ import {
8
8
  } from './lib/common.js';
9
9
  import {
10
10
  baseUrl,
11
- colors,
12
11
  exitError,
13
12
  parse,
14
13
  read,
@@ -32,15 +31,8 @@ import {
32
31
  } from './lib/tasks.js';
33
32
  import { commitCheckMsg } from '@mimik/git-hooks';
34
33
  import { fileURLToPath } from 'node:url';
35
- import find from 'lodash.find';
36
- import { writeFileSync } from 'node:fs';
37
34
 
38
- colors.setTheme({
39
- success: 'green',
40
- warn: 'yellow',
41
- error: 'red',
42
- info: ['grey', 'bold'],
43
- });
35
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
44
36
 
45
37
  const INSTALL = 'install';
46
38
  const TAB = 2;
@@ -52,9 +44,11 @@ const getBasePath = apiDef => apiDef.basePath || apiDef.servers[FIRST].url;
52
44
  /**
53
45
  * @module local
54
46
  * @example
47
+ * // Default import
55
48
  * import local from '@mimik/local';
56
- * or
57
- * import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFiles, scripts, unScripts, commitCheckMsg, start2process, testJsonFile} from '@mimik/local';
49
+ * @example
50
+ * // Named imports
51
+ * import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFiles, scripts, unScripts, commitCheckMsg, start2process, testJsonFile } from '@mimik/local';
58
52
  *
59
53
  * @description Utilities for local deployment.
60
54
  *
@@ -127,14 +121,14 @@ const getBasePath = apiDef => apiDef.basePath || apiDef.servers[FIRST].url;
127
121
  * "secretAccessKey": "Secret access key for Kinesis",
128
122
  * "streamNameInfo": "Name of the Kinesis stream for info",
129
123
  * "streamNameError": "Name of the Kinesis stream for errors",
130
- * "streamNameOther": "Name of the Kinesis stream for all other levels"
124
+ * "streamNameOther": "Name of the Kinesis stream for all other levels",
131
125
  * "maxEvents": "Number of events buffered before sending to Kinesis",
132
126
  * "timeout": "Number of minutes before a timeout triggers sending to Kinesis",
133
127
  * "maxSize": "Maximum size in bytes before sending to Kinesis",
134
128
  * "maxRetries": "Maximum retries to connect to Kinesis",
135
129
  * "httpOptions": {
136
130
  * "socketTimeout": "Socket timeout for the HTTP handler (in millisecond)",
137
- * "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)",
131
+ * "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)"
138
132
  * }
139
133
  * }
140
134
  * ```
@@ -282,7 +276,7 @@ const mITInit = (confType) => {
282
276
  start = updatedStart;
283
277
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
284
278
  .then((adminType) => {
285
- const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
279
+ const adminAudience = adminType.audiences.find(audienceItem => audienceItem.type === type);
286
280
  if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
287
281
  return undefined;
288
282
  })
@@ -353,7 +347,7 @@ const serverInit = (confType) => {
353
347
  start = updatedStart;
354
348
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
355
349
  .then((adminType) => {
356
- const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
350
+ const adminAudience = adminType.audiences.find(audienceItem => audienceItem.type === type);
357
351
  if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
358
352
  return undefined;
359
353
  })
@@ -368,7 +362,7 @@ const serverInit = (confType) => {
368
362
 
369
363
  if (startConfig.oauthImplicitNeeded === 'yes') {
370
364
  return settingUpAdminClient('mID', `admin_${customer.name}_${start.NODE_ENV}_mID`, customer, start.MST_TOKEN, mSTBaseUrl)
371
- .then(mIDAdminType => getAdminToken(find(mIDAdminType.audiences, audienceItem => audienceItem.type === 'mID'), mIDAdminType.data, mSTBaseUrl))
365
+ .then(mIDAdminType => getAdminToken(mIDAdminType.audiences.find(audienceItem => audienceItem.type === 'mID'), mIDAdminType.data, mSTBaseUrl))
372
366
  .then((mIDAdminToken) => {
373
367
  start.MID_TOKEN = mIDAdminToken;
374
368
  testResponse.content = JSON.stringify(start2env(start), null, TAB);
@@ -642,7 +636,7 @@ export const testSetup = () => serverInit(TEST);
642
636
  *
643
637
  * | Filename | Description |
644
638
  * | -------- | ----------- |
645
- * | `../sumo.json` | Sumo Logic endpoints and code
639
+ * | `../sumoLog.json` | Sumo Logic endpoints and code
646
640
  * | `../kinesisLog.json` | Kinesis configuration
647
641
  * | `../s3Log.json` | S3 configuration
648
642
  * | `../mSTConfig.json` | mST configuration
@@ -667,27 +661,30 @@ export const setup = () => serverInit();
667
661
  * Creates the `rule files` for:
668
662
  *
669
663
  * - `eslint` -> `eslint.config.js`.
670
- * - `c8` -> `.nycrc`
671
664
  * - `github` -> `.gitignore`
665
+ * - `husky` -> `.husky/pre-commit`, `.husky/pre-push`, `.husky/commit-msg`
672
666
  *
673
667
  * If a file already exists, it will be overwritten.
674
668
  */
675
669
  export const dotFiles = () => {
676
670
  write('./eslint.config.js', read(join(localDirname, 'dotFiles', 'eslint.config.js'), INSTALL), INSTALL);
677
- write('./.nycrc', parse(read(join(localDirname, 'dotFiles', 'nycrc.json'), 'nycrc.json', INSTALL)), INSTALL, true);
678
671
  write('./.gitignore', read(join(localDirname, 'dotFiles', 'gitIgnore.txt'), INSTALL), INSTALL);
672
+ if (!existsSync('./.husky')) mkdirSync('./.husky', { recursive: true });
673
+ write('./.husky/pre-commit', read(join(localDirname, 'dotFiles', 'husky', 'pre-commit'), INSTALL), INSTALL);
674
+ write('./.husky/pre-push', read(join(localDirname, 'dotFiles', 'husky', 'pre-push'), INSTALL), INSTALL);
675
+ write('./.husky/commit-msg', read(join(localDirname, 'dotFiles', 'husky', 'commit-msg'), INSTALL), INSTALL);
679
676
  };
680
677
 
681
678
  /**
682
679
  *
683
- * Utility to add `scripts` and `husky`.
680
+ * Utility to add `scripts` to `package.json`.
684
681
  *
685
682
  * @function scripts
686
683
  * @category sync
687
684
  *
688
685
  * @return `null`.
689
686
  *
690
- * Adds `scripts` and `husky` to `package.json`. If a script already exists, it will be overwritten.
687
+ * Adds `scripts` to `package.json`. If a script already exists, it will be overwritten.
691
688
  */
692
689
  export const scripts = () => {
693
690
  const scriptsContent = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
@@ -696,20 +693,19 @@ export const scripts = () => {
696
693
  Object.keys(scriptsContent.scripts).forEach((script) => {
697
694
  packageContent.scripts[script] = scriptsContent.scripts[script];
698
695
  });
699
- packageContent.husky = scriptsContent.husky;
700
696
  write(DEFAULT.FILE.packageFile, packageContent, DEFAULT.FILE.packageFile, INSTALL, true);
701
697
  };
702
698
 
703
699
  /**
704
700
  *
705
- * Utility to remove `scripts` and `husky`.
701
+ * Utility to remove `scripts` from `package.json`.
706
702
  *
707
703
  * @function unscripts
708
704
  * @category sync
709
705
  *
710
706
  * @return `null`.
711
707
  *
712
- * Removes `scripts` and `husky` from `package.json`. Only removes the scripts that are in the script file.
708
+ * Removes `scripts` from `package.json`. Only removes the scripts that are in the script file.
713
709
  */
714
710
  export const unScripts = () => {
715
711
  const scriptsContent = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
@@ -718,7 +714,6 @@ export const unScripts = () => {
718
714
  Object.keys(scriptsContent.scripts).forEach((script) => {
719
715
  delete packageContent.scripts[script];
720
716
  });
721
- delete packageContent.husky;
722
717
  write(DEFAULT.FILE.packageFile, packageContent, DEFAULT.FILE.packageFile, INSTALL, true);
723
718
  };
724
719
 
@@ -749,7 +744,7 @@ export { commitCheckMsg };
749
744
  * @function start2process
750
745
  * @category sync
751
746
  * @param {object} start - JSON object that is used to configure the environment variables. The comments (starting by //) are ignored.
752
- * @return `null`.
747
+ * @return {void}
753
748
  */
754
749
  export { start2process };
755
750
 
package/lib/common.js CHANGED
@@ -15,9 +15,12 @@ const DEFAULT_MST_PORT = 8025;
15
15
  const DEFAULT_MIT_PORT = 8050;
16
16
  const DEFAULT_MID_PORT = 8015;
17
17
 
18
+ const STATUS_NOT_FOUND = 404;
19
+ const STATUS_SYSTEM = 500;
20
+
18
21
  const ERROR_CODE = {
19
- NOT_FOUND: 404,
20
- SYSTEM: 500,
22
+ NOT_FOUND: STATUS_NOT_FOUND,
23
+ SYSTEM: STATUS_SYSTEM,
21
24
  };
22
25
 
23
26
  const DEFAULT_ADMIN_EXTERNAL_ID_BASE = 'admin_default_local';
@@ -149,7 +152,7 @@ const DUMMY = {
149
152
  },
150
153
  MST: {
151
154
  basePath: '/mST/v1',
152
- protocol: 'http',
155
+ protocol: 'http:',
153
156
  domainName: 'dummy-mST',
154
157
  port: DEFAULT_MST_PORT,
155
158
  admin: {
@@ -164,8 +167,7 @@ const API_PROVIDER_SWAGGERHUB = 'https://api.swaggerhub.com/apis';
164
167
  const API_SOURCE = '/src';
165
168
  const SWAGGER = 'swagger';
166
169
  const EXTENSION_YML = '.yml';
167
- const EXTENSION_JSON = '.json';
168
- const POSTFIX = `${SWAGGER}${EXTENSION_JSON}`;
170
+ const POSTFIX = `${SWAGGER}.json`;
169
171
  const SWAGGERHUB = 'swaggerhub';
170
172
  const BITBUCKET = 'bitbucket';
171
173
  const RESOLVED = 'resolved=true';
package/lib/commonExt.js CHANGED
@@ -1,13 +1,10 @@
1
- import findIndex from 'lodash.findindex';
2
- import union from 'lodash.union';
3
-
4
1
  // duplicate of functions in mST lib/common.js
5
2
  const ALL_TYPE = 'all';
6
3
  const CLUSTER_TYPE = 'cluster';
7
4
  const NOT_FOUND = -1;
8
5
  const FIRST = 0;
9
6
 
10
- const inList = (type, list) => findIndex(list, listItem => listItem.type === type);
7
+ const inList = (type, list) => list.findIndex(listItem => listItem.type === type);
11
8
 
12
9
  const setServiceInfo = (sharedWith, type, scopes, customer) => {
13
10
  const result = { type };
@@ -36,7 +33,7 @@ const getAllTargets = (serviceType, custConfig, serviceIndex) => {
36
33
  const allTargetIndex = inList(allTarget.type === CLUSTER_TYPE ? serviceType : allTarget.type, targets);
37
34
 
38
35
  if (allTargetIndex === NOT_FOUND) targets.push(serviceInfo(allTarget, serviceType));
39
- else targets[allTargetIndex].scopes = union(targets[allTargetIndex].scopes, allTarget.scopes);
36
+ else targets[allTargetIndex].scopes = [...new Set([...targets[allTargetIndex].scopes, ...allTarget.scopes])];
40
37
  }
41
38
  });
42
39
  }
package/lib/helpers.js CHANGED
@@ -4,8 +4,6 @@ import { ERROR_CODE } from './common.js';
4
4
  import colors from 'colors';
5
5
  import ip from 'ip';
6
6
  import { isIP } from 'node:net';
7
- import isNumber from 'lodash.isnumber';
8
- import isObject from 'lodash.isobject';
9
7
  import json from 'comment-json';
10
8
  import process from 'node:process';
11
9
 
@@ -50,7 +48,7 @@ const read = (filename, regType) => {
50
48
  const write = (fname, content, regType, withJSON) => {
51
49
  try {
52
50
  if (withJSON) writeFileSync(fname, json.stringify(content, null, TAB));
53
- else writeFileSync(fname, content, null, TAB);
51
+ else writeFileSync(fname, content);
54
52
  }
55
53
  catch (err) { exitError(regType, err, fname); }
56
54
  return content;
@@ -68,8 +66,8 @@ const start2shell = (start) => {
68
66
 
69
67
  Object.keys(start).forEach((key) => {
70
68
  if (key[FIRST] !== '/' && key[SECOND] !== '/') {
71
- if (isNumber(start[key])) result = `${result}export ${key}=${start[key]}\n`;
72
- else if (isObject(start[key])) result = `${result}export ${key}='${JSON.stringify(start[key])}'\n`;
69
+ if (typeof start[key] === 'number') result = `${result}export ${key}=${start[key]}\n`;
70
+ else if (typeof start[key] === 'object' && start[key] !== null) result = `${result}export ${key}='${JSON.stringify(start[key])}'\n`;
73
71
  else result = `${result}export ${key}="${start[key]}"\n`;
74
72
  }
75
73
  });
@@ -95,7 +93,7 @@ const start2env = (start) => {
95
93
  * @function start2process
96
94
  * @category sync
97
95
  * @param {object} start - JSON object that is used to configure the environment variables. The comments (starting by //) are ignored.
98
- * @return `null`.
96
+ * @return {void}
99
97
  */
100
98
  const start2process = (start) => {
101
99
  Object.keys(start).forEach((key) => {
@@ -123,10 +121,10 @@ const baseUrl = (serverType, regType, config, literal) => {
123
121
  *
124
122
  * @function retrieve
125
123
  * @category sync
126
- * @params {string} regType - Type of registration to be executed.
127
- * @params {PATH<string>} filename - Filename to retrieve. If the filename does not retrieve any file altFilename will be used.
128
- * @params options {object} - Options to be added for the retrieval
129
- * @return {object} The JSON object contained in the file.
124
+ * @param {string} regType - Type of registration to be executed.
125
+ * @param {PATH<string>} filename - Filename to retrieve. If the filename does not retrieve any file altFilename will be used.
126
+ * @param {object} options - Options to be added for the retrieval.
127
+ * @return {object} The JSON object contained in the file. Exits with code 1 on error.
130
128
  *
131
129
  * The options parameters has the following structure:
132
130
  *``` javascript
@@ -208,7 +206,7 @@ const retrieve = (regType, filename, options) => {
208
206
  return result;
209
207
  }
210
208
  catch (errAltFilename) {
211
- if (!options.sourceFileName) {
209
+ if (!options.sourceFilename) {
212
210
  if (!options.default) exitError(regType, { statusCode: ERROR_CODE.NOT_FOUND, message: `no files or default (${errAltFilename})` }, filename);
213
211
  console.log('- using ' + 'default'.warn + ' for ' + filename.info);
214
212
  return write(filename, options.default, regType, true);
@@ -3,18 +3,10 @@ import { STATUS_CODES } from 'node:http';
3
3
  import axios from 'axios';
4
4
 
5
5
  const rp = (origOptions) => {
6
- const options = origOptions;
6
+ const options = { ...origOptions, headers: { ...origOptions.headers } };
7
7
 
8
- if (options.headers) {
9
- options.headers['user-agent'] = userAgent;
10
- if (!options.headers['x-correlation-id']) options.headers['x-correlationId'] = correlationId;
11
- }
12
- else {
13
- options.headers = {
14
- 'user-agent': userAgent,
15
- 'x-correlationId': correlationId,
16
- };
17
- }
8
+ options.headers['user-agent'] = userAgent;
9
+ if (!options.headers['x-correlation-id']) options.headers['x-correlation-id'] = correlationId;
18
10
  return axios(options)
19
11
  .then((res) => {
20
12
  if (options.resolveWithFullResponse) return res;
package/lib/tasks.js CHANGED
@@ -37,16 +37,13 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
37
37
  import { Base64 } from 'js-base64';
38
38
  import Promise from 'bluebird';
39
39
  import SwaggerClient from 'swagger-client';
40
- import difference from 'lodash.difference';
41
40
  import { getAllTargets } from './commonExt.js';
42
- import isEmpty from 'lodash.isempty';
43
41
  import { join } from 'node:path';
44
42
  import json from 'comment-json';
45
43
  import { load } from 'js-yaml';
46
44
  import process from 'node:process';
45
+ import { randomUUID } from 'node:crypto';
47
46
  import { rp } from './rp-axios-wrapper.js';
48
- import split from 'lodash.split';
49
- import { v4 as uuidv4 } from 'uuid';
50
47
 
51
48
  const EMPTY = 0;
52
49
  const NOT_FOUND_ERROR = 404;
@@ -100,7 +97,7 @@ const init = (regType, standAlone, isMSTSet) => {
100
97
 
101
98
  if (isMSTSet && pack.mimik.type !== TOKEN_SERVICE && pack.mimik.type !== IT_REGISTRY) {
102
99
  config.customer = retrieve(regType, DEFAULT.FILE.customerConfigFile); // we don't need customer for mST or mIT
103
- };
100
+ }
104
101
  if (standAlone || !isMSTSet) {
105
102
  config.mST = DUMMY.MST;
106
103
  console.log('- using ' + 'dummy mSTConfig'.warn);
@@ -118,33 +115,24 @@ const init = (regType, standAlone, isMSTSet) => {
118
115
  config.MITBaseUrl = baseUrl(IT_REGISTRY, regType, config.mIT);
119
116
  if (config.mST.domainName === 'localhost') {
120
117
  console.log('- in ' + `${TOKEN_SERVICE} localhost, updating ${TOKEN_SERVICE} is true`.warn);
121
- config.mST.update = true;
118
+ config.mST = { ...config.mST, update: true };
122
119
  }
123
120
  return config;
124
121
  };
125
122
 
126
- const startSetup = (config, origStart) => {
127
- const start = structuredClone(origStart);
128
- const { regType } = config;
129
- const { type } = config.pack.mimik;
130
- // basic check
131
- if (start.standAlone === 'yes') {
132
- if (start.NODE_ENV !== 'local') exitError(regType, Error('standAlone is only for local environment'));
133
- if (type === TOKEN_SERVICE) exitError(regType, Error(`standAlone does not apply to ${type}`));
134
- }
135
- // references
136
- start.MIT_URL = baseUrl(IT_REGISTRY, regType, config.mIT);
137
- start.MST_URL = baseUrl(TOKEN_SERVICE, regType, config.mST);
138
- // logs
139
- let logMode = null;
140
-
141
- if (start.LOG_MODE) {
142
- logMode = split(start.LOG_MODE.trim(), /\s*,\s*/u);
143
- if (logMode.length === EMPTY) exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
144
- if (difference(logMode, ALL_MODES).length !== EMPTY) exitError(regType, `Invalid items in LOG_MODE: ${logMode}`);
145
- if (logMode.includes(NONE) && logMode.length !== DUPLICATE) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
146
- if (logMode.includes(ALL)) logMode = [SUMOLOGIC, AWS_S3]; // legacy support
147
- }
123
+ const setupLogMode = (start, regType) => {
124
+ if (!start.LOG_MODE) return null;
125
+
126
+ const logMode = start.LOG_MODE.trim().split(/\s*,\s*/u);
127
+
128
+ if (logMode[FIRST] === '') exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
129
+ if (logMode.some(mode => !ALL_MODES.includes(mode))) exitError(regType, `Invalid items in LOG_MODE: ${logMode}`);
130
+ if (logMode.includes(NONE) && logMode.length !== DUPLICATE) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
131
+ if (logMode.includes(ALL)) return [SUMOLOGIC, AWS_S3]; // legacy support
132
+ return logMode;
133
+ };
134
+
135
+ const setupLogs = (start, config, logMode, regType, type) => {
148
136
  if (!logMode || logMode.includes(SUMOLOGIC)) {
149
137
  let sumoLog = config.sumoLog[type];
150
138
 
@@ -177,54 +165,31 @@ const startSetup = (config, origStart) => {
177
165
  start.KINESIS_AWS_STREAM_NAME_ERROR ||= kinesisLog.streamNameError;
178
166
  start.KINESIS_AWS_STREAM_NAME_OTHER ||= kinesisLog.streamNameOther;
179
167
  }
180
- // server basics
181
- start.SERVER_TYPE = type;
182
- start.SERVER_ID ||= uuidv4();
183
- // api access
184
- start.BITBUCKET_USERNAME = config.key.username;
185
- start.BITBUCKET_PASSWORD = config.key.password;
186
- // passphrase to be shared to all the servers
187
- if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
188
- // oauth issuer full address
189
- start.OAUTH_ISSUER = `${baseUrl(TOKEN_SERVICE, regType, config.mST, LITERAL)}/oauth/token`;
190
- // setting admin
191
- start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name : SYSTEM_NAME}_${start.NODE_ENV}_${type}`;
192
- // setting up dummy variables which will be updating by mST seeding
193
- start.OAUTH_CLIENT_ID = '--noId--';
194
- start.OAUTH_CLIENT_SECRET = '--noSecret--';
195
- start.OAUTH_CLIENT_ACCESS_KEY = '--noKey--';
196
- start.OAUTH_CLIENT_AUDIENCE = '--noAudience--';
197
- // specific to mST
168
+ };
169
+
170
+ const setupServerTypeConfig = (start, config, regType, type) => {
198
171
  if (type === TOKEN_SERVICE) {
199
- // use the port from config
200
172
  start.SERVER_PORT = config.mST.port;
201
- // setting admin
202
173
  start.ADMIN_CLIENT_ID = config.mST.admin.clientId;
203
174
  start.ADMIN_CLIENT_SECRET = config.mST.admin.clientSecret;
204
- // default audience
205
175
  start.MIT_AUDIENCE = '--noAudience--';
206
176
  start.MST_AUDIENCE = '--noAudience--';
207
- // setting public address for platform independence
208
177
  start.SERVER_PUBLIC_DOMAIN_NAME = setDomainName(type, regType, config.mST.domainName, config.mST.port, LITERAL);
209
178
  start.SERVER_PUBLIC_PROTOCOL = config.mST.protocol;
210
179
  }
211
- // specific to mID
212
180
  if (type === IDENTITY_SERVICE) {
213
181
  start.SERVER_PORT = config.mID.port;
214
- // setting url
215
182
  start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
216
183
  }
217
184
  if (type === IT_REGISTRY) {
218
185
  start.SERVER_PORT = config.mIT.port;
219
186
  }
220
- // specific to servers that need to handle user token and mID
221
187
  if (start.oauthImplicitNeeded === 'yes' || type === IDENTITY_SERVICE) {
222
188
  delete start.oauthImplicitNeeded;
223
189
  start.OAUTH_IMPLICIT_AUDIENCE = config.mID.implicit.audience;
224
190
  start.OAUTH_IMPLICIT_KEY = config.mID.implicit.key;
225
191
  start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(IDENTITY_SERVICE, regType, config.mID, LITERAL)}/oauth/token`;
226
192
  }
227
- // specific to servers than need to interact with mID
228
193
  if (start.mIDNeeded === 'yes') {
229
194
  delete start.mIDNeeded;
230
195
  start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
@@ -234,6 +199,43 @@ const startSetup = (config, origStart) => {
234
199
  start.LOCATION_PROVIDER = config.locationProvider.url;
235
200
  if (config.locationProvider.key) start.LOCATION_PROVIDER_KEY = config.locationProvider.key;
236
201
  }
202
+ };
203
+
204
+ const startSetup = (config, origStart) => {
205
+ const start = structuredClone(origStart);
206
+ const { regType } = config;
207
+ const { type } = config.pack.mimik;
208
+ // basic check
209
+ if (start.standAlone === 'yes') {
210
+ if (start.NODE_ENV !== 'local') exitError(regType, Error('standAlone is only for local environment'));
211
+ if (type === TOKEN_SERVICE) exitError(regType, Error(`standAlone does not apply to ${type}`));
212
+ }
213
+ // references
214
+ start.MIT_URL = baseUrl(IT_REGISTRY, regType, config.mIT);
215
+ start.MST_URL = baseUrl(TOKEN_SERVICE, regType, config.mST);
216
+ // logs
217
+ const logMode = setupLogMode(start, regType);
218
+
219
+ setupLogs(start, config, logMode, regType, type);
220
+ // server basics
221
+ start.SERVER_TYPE = type;
222
+ start.SERVER_ID ||= randomUUID();
223
+ // api access
224
+ start.BITBUCKET_USERNAME = config.key.username;
225
+ start.BITBUCKET_PASSWORD = config.key.password;
226
+ // passphrase to be shared to all the servers
227
+ if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
228
+ // oauth issuer full address
229
+ start.OAUTH_ISSUER = `${baseUrl(TOKEN_SERVICE, regType, config.mST, LITERAL)}/oauth/token`;
230
+ // setting admin
231
+ start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name : SYSTEM_NAME}_${start.NODE_ENV}_${type}`;
232
+ // setting up dummy variables which will be updating by mST seeding
233
+ start.OAUTH_CLIENT_ID = '--noId--';
234
+ start.OAUTH_CLIENT_SECRET = '--noSecret--';
235
+ start.OAUTH_CLIENT_ACCESS_KEY = '--noKey--';
236
+ start.OAUTH_CLIENT_AUDIENCE = '--noAudience--';
237
+ // server type specific setup
238
+ setupServerTypeConfig(start, config, regType, type);
237
239
 
238
240
  return start;
239
241
  };
@@ -246,7 +248,7 @@ const startSetup = (config, origStart) => {
246
248
  * @category async
247
249
  * @param {PATH<string>} directory - Directory to store the API file.
248
250
  * @param {object} swaggerFile - Information from package.swaggerFile.
249
- * @param {string} key - `bitbucket` with username password to access the bitbucket account or string to access `swaggerhub`.
251
+ * @param {object} key - Object with `bitbucket` (username/password) or `swaggerhub` (API key) properties.
250
252
  * .
251
253
  * @return {Promise}.
252
254
  * @fulfil {object} The API file itself.
@@ -378,6 +380,8 @@ const getAPI = (directory, swaggerFile, key) => {
378
380
  });
379
381
  };
380
382
 
383
+ const isEmptyObject = obj => !obj || Object.keys(obj).length === EMPTY;
384
+
381
385
  const gettingSystemCustomer = (authorization, mSTbaseUrl) => {
382
386
  process.stdout.write('- getting customer (' + SYSTEM_NAME.info + '): ');
383
387
  return rp({
@@ -466,13 +470,13 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
466
470
  throw err;
467
471
  }).then((result) => {
468
472
  console.log(SUCCESS_CHECK.success);
469
- const updatedStart = origStart;
473
+ const updatedStart = structuredClone(origStart);
470
474
  const client = result.data;
471
475
 
472
476
  // oauth
473
477
  updatedStart.OAUTH_CLIENT_ID = `${client.id}`;
474
478
  updatedStart.OAUTH_CLIENT_SECRET = `${client.secret}`;
475
- if (isEmpty(client.accessKeyPair) || !client.accessKeyPair.publicKey) updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKey}`;
479
+ if (isEmptyObject(client.accessKeyPair) || !client.accessKeyPair.publicKey) updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKey}`;
476
480
  else updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKeyPair.publicKey}`;
477
481
  updatedStart.OAUTH_CLIENT_AUDIENCE = `${client.audience}`;
478
482
  // generic
@@ -491,7 +495,7 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
491
495
 
492
496
  const settingUpDummyServer = (serverType, serverId, customer, origStart) => {
493
497
  process.stdout.write('- setting up ' + serverType.info + ' server with serverId (' + `${serverId}`.info + '): ');
494
- const updatedStart = origStart;
498
+ const updatedStart = structuredClone(origStart);
495
499
 
496
500
  updatedStart.OAUTH_GENERIC_KEY = 'a-secret-key-for-generic';
497
501
  updatedStart.OAUTH_GENERIC_AUDIENCE = `http://dummy-${serverType}-generic-audience`;
@@ -537,7 +541,7 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
537
541
  throw errGET;
538
542
  }).then((resultGET) => {
539
543
  if (resultGET.data.customerName !== customer.name) {
540
- console.log(ERR_CHECK.error + ' customer name expected: '.warn + `${customer.name}`.error + ' recieved: '.warn + `${resultGET.data.customerName}`.error);
544
+ console.log(ERR_CHECK.error + ' customer name expected: '.warn + `${customer.name}`.error + ' received: '.warn + `${resultGET.data.customerName}`.error);
541
545
  throw new Error(`customer name conflict, admin cannot use externalId: ${adminExternalId}`);
542
546
  }
543
547
  console.log('already setup'.warn);
package/package.json CHANGED
@@ -1,26 +1,21 @@
1
1
  {
2
2
  "name": "@mimik/local",
3
- "version": "7.1.7",
3
+ "version": "7.2.1",
4
4
  "description": "Local setup configuration for normal and test operation",
5
5
  "main": "./index.js",
6
6
  "type": "module",
7
+ "exports": "./index.js",
7
8
  "engines": {
8
9
  "node": ">=24.0.0"
9
10
  },
10
11
  "scripts": {
11
12
  "lint": "eslint . --no-error-on-unmatched-pattern",
12
13
  "docs": "jsdoc2md index.js > README.md",
13
- "test": "echo \"Error: no test specified\" && exit 0",
14
- "test-ci": "echo \"Error: no test specified\" && exit 0",
14
+ "test": "mocha --reporter mochawesome --bail --exit test/",
15
+ "test-ci": "c8 --reporter=lcov --reporter=text npm test",
15
16
  "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
16
17
  "commit-ready": "npm run docs && npm run lint && npm run test-ci"
17
18
  },
18
- "husky": {
19
- "hooks": {
20
- "pre-commit": "npm run commit-ready",
21
- "pre-push": "npm run test"
22
- }
23
- },
24
19
  "keywords": [
25
20
  "mimik",
26
21
  "microservice"
@@ -32,39 +27,29 @@
32
27
  "url": "https://bitbucket.org/mimiktech/local"
33
28
  },
34
29
  "dependencies": {
35
- "@eslint/js": "9.39.1",
36
- "@mimik/eslint-plugin-document-env": "^2.0.8",
37
- "@mimik/git-hooks": "^2.0.0",
38
- "@mimik/request-helper": "^2.0.2",
39
- "@stylistic/eslint-plugin": "5.6.1",
40
- "axios": "1.13.2",
30
+ "@eslint/js": "9.39.4",
31
+ "@mimik/eslint-plugin-document-env": "^2.0.9",
32
+ "@mimik/eslint-plugin-logger": "^1.0.3",
33
+ "@mimik/git-hooks": "^2.1.0",
34
+ "@mimik/request-helper": "^2.0.6",
35
+ "@stylistic/eslint-plugin": "5.10.0",
36
+ "axios": "1.13.6",
41
37
  "bluebird": "3.7.2",
42
- "c8": "10.1.3",
43
- "chai": "6.2.1",
38
+ "c8": "11.0.0",
39
+ "chai": "6.2.2",
44
40
  "colors": "1.4.0",
45
- "comment-json": "4.4.1",
46
- "eslint": "9.39.1",
41
+ "comment-json": "4.6.2",
42
+ "eslint": "9.39.4",
47
43
  "eslint-plugin-import": "2.32.0",
48
- "globals": "16.5.0",
44
+ "globals": "17.4.0",
49
45
  "husky": "9.1.7",
50
46
  "ip": "2.0.1",
51
47
  "js-base64": "3.7.8",
52
48
  "js-yaml": "4.1.1",
53
49
  "jsdoc-to-markdown": "9.1.3",
54
- "lodash.difference": "4.5.0",
55
- "lodash.find": "4.6.0",
56
- "lodash.findindex": "4.6.0",
57
- "lodash.isempty": "4.4.0",
58
- "lodash.isnumber": "3.0.3",
59
- "lodash.isobject": "3.0.2",
60
- "lodash.split": "4.4.2",
61
- "lodash.union": "4.6.0",
62
50
  "mocha": "11.7.5",
63
51
  "mochawesome": "7.1.4",
64
- "rewire": "9.0.1",
65
- "sinon": "21.0.0",
66
- "supertest": "7.1.4",
67
- "swagger-client": "3.36.0",
68
- "uuid": "11.1.0"
52
+ "sinon": "21.0.3",
53
+ "swagger-client": "3.37.1"
69
54
  }
70
55
  }
package/scripts.json CHANGED
@@ -5,17 +5,10 @@
5
5
  "pretest": "node ./local/testSetup.js",
6
6
  "test": "mocha --reporter mochawesome --bail --exit --file test/src/set-env.js test/normal/",
7
7
  "test-detached": "node ./local/testSetup.js && mocha --reporter mochawesome --bail --exit --file test/src/set-env.js test/detached/",
8
- "test-ci": "c8 --reporter=lcov --reporter=text npm test --exit",
8
+ "test-ci": "c8 --reporter=lcov --reporter=text npm test",
9
9
  "prestart": "node ./local/setup.js",
10
10
  "start": "sh server-start.sh",
11
- "pre-push": "npm run docs && npm run lint && npm run test",
11
+ "pre-push": "npm run docs && npm run lint && npm run test-ci",
12
12
  "pre-commit": "npm run docs && npm run lint"
13
- },
14
- "husky": {
15
- "hooks": {
16
- "pre-commit": "npm run pre-commit",
17
- "pre-push": "npm run pre-push",
18
- "commit-msg": "node ./local/commitMsgCheck $1"
19
- }
20
13
  }
21
14
  }
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npm run commit-ready
package/.husky/pre-push DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npm run test
package/.nycrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "exclude": ["gulpfile.js"],
3
- "reporter": ["lcov", "text"]
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "exclude": ["gulpfile.js"],
3
- "reporter": ["lcov", "text"]
4
- }
package/eslint.config.js DELETED
@@ -1,72 +0,0 @@
1
- import globals from 'globals';
2
- import importPlugin from 'eslint-plugin-import';
3
- import js from '@eslint/js';
4
- import processDoc from '@mimik/eslint-plugin-document-env';
5
- import stylistic from '@stylistic/eslint-plugin';
6
-
7
- const MAX_LENGTH_LINE = 180;
8
- const MAX_FUNCTION_PARAMETERS = 6;
9
- const MAX_LINES_IN_FILES = 600;
10
- const MAX_LINES_IN_FUNCTION = 150;
11
- const MAX_STATEMENTS_IN_FUNCTION = 80;
12
- const MIN_KEYS_IN_OBJECT = 10;
13
- const MAX_COMPLEXITY = 80;
14
- const ECMA_VERSION = 'latest';
15
- const MAX_DEPTH = 6;
16
- const ALLOWED_CONSTANTS = [0, 1, -1];
17
-
18
- export default [
19
- {
20
- ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
21
- },
22
- importPlugin.flatConfigs.recommended,
23
- stylistic.configs.recommended,
24
- js.configs.all,
25
- {
26
- plugins: {
27
- processDoc,
28
- },
29
- languageOptions: {
30
- ecmaVersion: ECMA_VERSION,
31
- globals: {
32
- ...globals.nodeBuiltin,
33
- console: 'readonly',
34
- describe: 'readonly',
35
- it: 'readonly',
36
- structuredClone: 'readonly',
37
- },
38
- sourceType: 'module',
39
- },
40
- rules: {
41
- '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
42
- '@stylistic/line-comment-position': ['off'],
43
- '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
44
- '@stylistic/semi': ['error', 'always'],
45
- 'capitalized-comments': ['off'],
46
- 'complexity': ['error', MAX_COMPLEXITY],
47
- 'curly': ['off'],
48
- 'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
49
- 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
50
- 'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
51
- 'init-declarations': ['off'],
52
- 'linebreak-style': ['off'],
53
- 'max-depth': ['error', MAX_DEPTH],
54
- 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
55
- 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
56
- 'max-params': ['error', MAX_FUNCTION_PARAMETERS],
57
- 'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
58
- 'no-confusing-arrow': ['off'],
59
- 'no-inline-comments': ['off'],
60
- 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true }],
61
- 'no-process-env': ['error'],
62
- 'no-ternary': ['off'],
63
- 'no-undefined': ['off'],
64
- 'no-warning-comments': ['warn'],
65
- 'one-var': ['error', 'never'],
66
- 'processDoc/validate-document-env': ['error'],
67
- 'quotes': ['warn', 'single'],
68
- 'sort-imports': ['error', { allowSeparatedGroups: true }],
69
- 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
70
- },
71
- },
72
- ];
@@ -1,6 +0,0 @@
1
- {
2
- "a": "a test",
3
- "b": "b test",
4
- // comment
5
- "c": "c test"
6
- }
@@ -1,3 +0,0 @@
1
- import { getAPI } from '../lib/tasks.js';
2
-
3
- getAPI('./testing', 'mimik', 'mDS', '1.1.1');
@@ -1,8 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { retrieve } from '../lib/helpers.js';
3
-
4
- // console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json', sourceFilenameSupp: 'startTest-example.json' } ));
5
-
6
- // console.log(retrieve('test', 'test.json'));
7
- // console.log(retrieve('test', 'test.json', { sourceFilename: './nonexistent.json', sourceFilenameSupp: 'startTest-example.json' }));
8
- console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json' }));
@@ -1,46 +0,0 @@
1
- {
2
- // "SERVER_ID": "mST-12345",
3
- // "DEBUG": "swagger-tools:middleware.*",
4
- // -- logs
5
- "LOG_LEVEL": "info",
6
- "CONSOLE_LEVEL": "debug",
7
- "NO_STACK": "yes",
8
- // "LOG_MODE": "all",
9
- // "LOG_MODE": "awsS3",
10
- "LOG_MODE": "sumologic",
11
- // -- providers
12
- // "LOCATION_PROVIDER": "http://ip-api.com/json",
13
- // "LOCATION_PROVIDER_KEY": "---a key---",
14
- // "CLOUD_PROVIDER": "AWS",
15
- // -- server public address
16
- // "SERVER_PUBLIC_DOMAIN_NAME": "mst.mimik360.com",
17
- // "SERVER_PUBLIC_PROTOCOL": "https:",
18
- // -- database
19
- "DATABASE_NAME": "tokens",
20
- "MONGO_MAX_POOL_SIZE": 60,
21
- // "MONGO_REPLICAT_SET": "test",
22
- // "DATABASE_IP": "localhost:27018,localhost:27019,localhost:27020",
23
- // -- specific parameters
24
- "OAUTH_ACCESS_TOKEN_EXPIRE": "24h",
25
- "OAUTH_REFRESH_TOKEN_EXPIRE": "30d",
26
- // "PASSPHRASE": "This is a passphrase",
27
- // "MST_STANDALONE_SET": "off"
28
- // "SUB_MST_SET": "off"
29
- // information retriveved from super mST client registration
30
- // "OAUTH_SUB_CLIENT_ID": "a sub client id",
31
- // "OAUTH_SUB_CLIENT_SECRET": "a sub client secret",
32
- // "OAUTH_SUB_CLIENT_ACCESS_KEY": "a sub client access key",
33
- // "OAUTH_SUB_CLIENT_AUDIENCE": "a sub client audience",
34
- // "OAUTH_SUB_ISSUER": "sub client token issuer",
35
- // "OAUTH_SUB_GENERIC_KEY": "a sub client generic key",
36
- // "OAUTH_SUB_GENERIC_AUDIENCE": "a sub client geneic audience",
37
- // "SUPER_MST_AUDIENCE": "the super mST audience ",
38
- // "SUB_MST_AUDIENCE": "the sub mST audience",
39
- // information to be provided
40
- // "SUPER_MST_URL": "url of super mST",
41
- // -- security
42
- // "SERVER_SECURITY_SET": "off",
43
- // -- environment
44
- // "REGISTRATION_RETRY": 200000,
45
- "NODE_ENV": "local"
46
- }
@@ -1,8 +0,0 @@
1
- {
2
- "CONSOLE_LEVEL": "info",
3
- "NO_STACK": "no",
4
- "LOG_MODE": "all",
5
- // Required by @mimik/test-helper if USE_MOCK_PROFILES is "no":
6
- // "MST_TOKEN": "mST-token",
7
- "USE_MOCK_PROFILES": "yes"
8
- }
@@ -1,46 +0,0 @@
1
- {
2
- // "SERVER_ID": "mST-12345",
3
- // "DEBUG": "swagger-tools:middleware.*",
4
- // -- logs
5
- "LOG_LEVEL": "info",
6
- "CONSOLE_LEVEL": "debug",
7
- "NO_STACK": "yes",
8
- // "LOG_MODE": "all",
9
- // "LOG_MODE": "awsS3",
10
- "LOG_MODE": "sumologic",
11
- // -- providers
12
- // "LOCATION_PROVIDER": "http://ip-api.com/json",
13
- // "LOCATION_PROVIDER_KEY": "---a key---",
14
- // "CLOUD_PROVIDER": "AWS",
15
- // -- server public address
16
- // "SERVER_PUBLIC_DOMAIN_NAME": "mst.mimik360.com",
17
- // "SERVER_PUBLIC_PROTOCOL": "https:",
18
- // -- database
19
- "DATABASE_NAME": "tokens",
20
- "MONGO_MAX_POOL_SIZE": 60,
21
- // "MONGO_REPLICAT_SET": "test",
22
- // "DATABASE_IP": "localhost:27018,localhost:27019,localhost:27020",
23
- // -- specific parameters
24
- "OAUTH_ACCESS_TOKEN_EXPIRE": "24h",
25
- "OAUTH_REFRESH_TOKEN_EXPIRE": "30d",
26
- // "PASSPHRASE": "This is a passphrase",
27
- // "MST_STANDALONE_SET": "off"
28
- // "SUB_MST_SET": "off"
29
- // information retriveved from super mST client registration
30
- // "OAUTH_SUB_CLIENT_ID": "a sub client id",
31
- // "OAUTH_SUB_CLIENT_SECRET": "a sub client secret",
32
- // "OAUTH_SUB_CLIENT_ACCESS_KEY": "a sub client access key",
33
- // "OAUTH_SUB_CLIENT_AUDIENCE": "a sub client audience",
34
- // "OAUTH_SUB_ISSUER": "sub client token issuer",
35
- // "OAUTH_SUB_GENERIC_KEY": "a sub client generic key",
36
- // "OAUTH_SUB_GENERIC_AUDIENCE": "a sub client geneic audience",
37
- // "SUPER_MST_AUDIENCE": "the super mST audience ",
38
- // "SUB_MST_AUDIENCE": "the sub mST audience",
39
- // information to be provided
40
- // "SUPER_MST_URL": "url of super mST",
41
- // -- security
42
- // "SERVER_SECURITY_SET": "off",
43
- // -- environment
44
- // "REGISTRATION_RETRY": 200000,
45
- "NODE_ENV": "local"
46
- }
@@ -1,82 +0,0 @@
1
- /* eslint-disable prefer-template, no-console */
2
- import colors from 'colors';
3
- import json from 'comment-json';
4
- import process from 'process';
5
- import { readFileSync } from 'node:fs';
6
-
7
- colors.setTheme({
8
- success: 'green',
9
- warn: 'yellow',
10
- error: 'red',
11
- info: ['grey', 'bold'],
12
- });
13
-
14
- const SYSTEM_ERROR = 500;
15
- const EXIT_ERROR = 1;
16
- const TAB = 2;
17
- const START = 0;
18
- const EXT = 2;
19
- const SUB = 1;
20
-
21
- const exitError = (regType, error, filename) => {
22
- let details = `{ statusCode: ${error.statusCode || SYSTEM_ERROR}, message: ${error.message || error}`;
23
-
24
- if (filename) details = `, ${details}, filename: ${filename}`;
25
- details = `${details} }`;
26
- console.error(`${regType}status: ` + 'error'.error + ', ' + details.info);
27
- process.exit(EXIT_ERROR);
28
- };
29
-
30
- const regType = 'test';
31
-
32
- const readMerge = (fname, fnameSupp) => {
33
- const parse = (rawFile, rawFilename) => {
34
- try {
35
- return json.parse(rawFile);
36
- }
37
- catch (errParse) {
38
- return exitError(regType, errParse, rawFilename);
39
- }
40
- };
41
-
42
- const merge = (origRawFile, parsedFile, origRawFileSupp, parsedFileSupp) => {
43
- const keysParsedFile = Object.keys(parsedFile);
44
- let rawFile = origRawFile;
45
- let rawFileSupp = origRawFileSupp;
46
-
47
- Object.keys(parsedFileSupp).forEach((key) => {
48
- if (keysParsedFile.includes(key)) {
49
- const regex = new RegExp(`\n[ \t]+"${key}"`, 'u');
50
-
51
- rawFile = rawFile.replace(regex, `\n// "${key}"`);
52
- }
53
- });
54
- rawFile = rawFile.substring(START, rawFile.length - EXT);
55
- rawFileSupp = rawFileSupp.substring(SUB);
56
- return `${rawFile},\n//-- test\n${rawFileSupp}`;
57
- };
58
-
59
- let readFileRaw;
60
- let readFileSuppRaw;
61
-
62
- try {
63
- readFileRaw = readFileSync(fname).toString();
64
- }
65
- catch (errFname) {
66
- if (errFname.code !== 'ENOENT') exitError(regType, errFname, fname);
67
- throw errFname;
68
- }
69
- const readFile = parse(readFileRaw, fname);
70
-
71
- try {
72
- readFileSuppRaw = readFileSync(fnameSupp).toString();
73
- }
74
- catch (errFnameSupp) {
75
- if (errFnameSupp.code !== 'ENOENT') exitError(regType, errFnameSupp, fnameSupp);
76
- return readFile;
77
- }
78
-
79
- return parse(merge(readFileRaw, readFile, readFileSuppRaw, parse(readFileSuppRaw, fnameSupp)), `${fname} + ${fnameSupp}`);
80
- };
81
-
82
- console.log(json.stringify(readMerge('../../../mst-2297/local/start-example.json', '../../../mst-2297/local/startTest-example.json'), null, TAB));
@@ -1,8 +0,0 @@
1
- /* eslint-disable no-console */
2
- import split from 'lodash.split';
3
-
4
- const test = ' a, b ,c,d ';
5
- const allTest = 'all ';
6
-
7
- console.log(split(test.trim(), /\s*,\s*/u));
8
- console.log(split(allTest.trim(), /\s*,\s*/u));
@@ -1,6 +0,0 @@
1
- {
2
- "a": "a test",
3
- "b": "b test",
4
- // comment
5
- "c": "c test"
6
- }