@mimik/local 7.1.6 → 7.2.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.
package/README.md CHANGED
@@ -72,7 +72,15 @@ 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
+ "maxEvents": "Number of events buffered before sending to Kinesis",
77
+ "timeout": "Number of minutes before a timeout triggers sending to Kinesis",
78
+ "maxSize": "Maximum size in bytes before sending to Kinesis",
79
+ "maxRetries": "Maximum retries to connect to Kinesis",
80
+ "httpOptions": {
81
+ "socketTimeout": "Socket timeout for the HTTP handler (in millisecond)",
82
+ "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)"
83
+ }
76
84
  }
77
85
  ```
78
86
 
@@ -83,9 +91,9 @@ The same `domainName`/`port` rules as in `mSTConfig.json` apply.
83
91
  "accessKeyId": "Access key ID for S3",
84
92
  "secretAccessKey": "Secret access key for S3",
85
93
  "bucketname": "Name of the S3 bucket used to store information",
86
- "maxEvents": "Number of events buffered before sending to S3 (integer)",
87
- "timeout": "Number of seconds before a timeout triggers sending to S3 (integer)",
88
- "maxSize": "Maximum size in bytes before sending to S3 (integer)"
94
+ "maxEvents": "Number of events buffered before sending to S3",
95
+ "timeout": "Number of minutes before a timeout triggers sending to S3",
96
+ "maxSize": "Maximum size in bytes before sending to S3"
89
97
  }
90
98
  ```
91
99
 
@@ -111,9 +119,9 @@ The same `domainName`/`port` rules as in `mSTConfig.json` apply.
111
119
  A property may be defined for each `serverType` involved. If the `serverType` does not exist, the `default` entry is used.
112
120
 
113
121
  - for `customerConfig.json`: see `mST` `README.md` file for an example of a customer configuration. This may have to be updated to reflect the new server.
114
- - In the `local` directory under the servers root directory: two files, `start.json` and `testStart.json`, may exist. `start.json` is used when `npm start` is executed; `testStart.json` is used when `npm test` is executed.
115
- If these files dont exist, `example-start.json` is used to create `start.json` and `testStart.json`. Additionally, `example-testStart.json` is used to create `testStart.json`; values in `example-testStart.json` take precedence over values in `example-start.json`.
116
- The configuration of these files depends on the servers configuration parameters.
122
+ - In the `local` directory under the server's root directory: two files, `start.json` and `testStart.json`, may exist. `start.json` is used when `npm start` is executed; `testStart.json` is used when `npm test` is executed.
123
+ If these files don't exist, `example-start.json` is used to create `start.json` and `testStart.json`. Additionally, `example-testStart.json` is used to create `testStart.json`; values in `example-testStart.json` take precedence over values in `example-start.json`.
124
+ The configuration of these files depends on the server's configuration parameters.
117
125
 
118
126
  Example `start.json` for `mIT`:
119
127
  ```javascript
@@ -158,9 +166,13 @@ In `standAlone` mode, the test can obtain tokens using `oauth-helper-temp`.
158
166
 
159
167
  **Example**
160
168
  ```js
169
+ // Default import
161
170
  import local from '@mimik/local';
162
- or
163
- 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';
164
176
  ```
165
177
 
166
178
  * [local](#module_local)
@@ -179,7 +191,7 @@ import { mSTTestSetup, mSTSetup, mITTestSetup, mITSetup, testSetup, setup, dotFi
179
191
  * [~dotFiles()](#module_local..dotFiles) ⇒
180
192
  * [~scripts()](#module_local..scripts) ⇒
181
193
  * [~unscripts()](#module_local..unscripts) ⇒
182
- * [~start2process(start)](#module_local..start2process) ⇒
194
+ * [~start2process(start)](#module_local..start2process) ⇒ <code>void</code>
183
195
 
184
196
  <a name="module_local.testJsonFile"></a>
185
197
 
@@ -434,7 +446,7 @@ The following files are needed to perform these actions:
434
446
 
435
447
  | Filename | Description |
436
448
  | -------- | ----------- |
437
- | `../sumo.json` | Sumo Logic endpoints and code
449
+ | `../sumoLog.json` | Sumo Logic endpoints and code
438
450
  | `../kinesisLog.json` | Kinesis configuration
439
451
  | `../s3Log.json` | S3 configuration
440
452
  | `../mSTConfig.json` | mST configuration
@@ -456,38 +468,37 @@ Utility to create `rule files`.
456
468
  Creates the `rule files` for:
457
469
 
458
470
  - `eslint` -> `eslint.config.js`.
459
- - `c8` -> `.nycrc`
460
471
  - `github` -> `.gitignore`
472
+ - `husky` -> `.husky/pre-commit`, `.husky/pre-push`, `.husky/commit-msg`
461
473
 
462
474
  If a file already exists, it will be overwritten.
463
475
  **Category**: sync
464
476
  <a name="module_local..scripts"></a>
465
477
 
466
478
  ### local~scripts() ⇒
467
- Utility to add `scripts` and `husky`.
479
+ Utility to add `scripts` to `package.json`.
468
480
 
469
481
  **Kind**: inner method of [<code>local</code>](#module_local)
470
482
  **Returns**: `null`.
471
483
 
472
- 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.
473
485
  **Category**: sync
474
486
  <a name="module_local..unscripts"></a>
475
487
 
476
488
  ### local~unscripts() ⇒
477
- Utility to remove `scripts` and `husky`.
489
+ Utility to remove `scripts` from `package.json`.
478
490
 
479
491
  **Kind**: inner method of [<code>local</code>](#module_local)
480
492
  **Returns**: `null`.
481
493
 
482
- 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.
483
495
  **Category**: sync
484
496
  <a name="module_local..start2process"></a>
485
497
 
486
- ### local~start2process(start) ⇒
498
+ ### local~start2process(start) ⇒ <code>void</code>
487
499
  Set up the environment variables based on given JSON object.
488
500
 
489
501
  **Kind**: inner method of [<code>local</code>](#module_local)
490
- **Returns**: `null`.
491
502
  **Category**: sync
492
503
 
493
504
  | Param | Type | Description |
@@ -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,7 +121,15 @@ 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",
125
+ * "maxEvents": "Number of events buffered before sending to Kinesis",
126
+ * "timeout": "Number of minutes before a timeout triggers sending to Kinesis",
127
+ * "maxSize": "Maximum size in bytes before sending to Kinesis",
128
+ * "maxRetries": "Maximum retries to connect to Kinesis",
129
+ * "httpOptions": {
130
+ * "socketTimeout": "Socket timeout for the HTTP handler (in millisecond)",
131
+ * "connectionTimeout": "Connection timeout for the HTTP handler (in millisecond)"
132
+ * }
131
133
  * }
132
134
  * ```
133
135
  *
@@ -138,9 +140,9 @@ const getBasePath = apiDef => apiDef.basePath || apiDef.servers[FIRST].url;
138
140
  * "accessKeyId": "Access key ID for S3",
139
141
  * "secretAccessKey": "Secret access key for S3",
140
142
  * "bucketname": "Name of the S3 bucket used to store information",
141
- * "maxEvents": "Number of events buffered before sending to S3 (integer)",
142
- * "timeout": "Number of seconds before a timeout triggers sending to S3 (integer)",
143
- * "maxSize": "Maximum size in bytes before sending to S3 (integer)"
143
+ * "maxEvents": "Number of events buffered before sending to S3",
144
+ * "timeout": "Number of minutes before a timeout triggers sending to S3",
145
+ * "maxSize": "Maximum size in bytes before sending to S3"
144
146
  * }
145
147
  * ```
146
148
  *
@@ -166,9 +168,9 @@ const getBasePath = apiDef => apiDef.basePath || apiDef.servers[FIRST].url;
166
168
  * A property may be defined for each `serverType` involved. If the `serverType` does not exist, the `default` entry is used.
167
169
  *
168
170
  * - for `customerConfig.json`: see `mST` `README.md` file for an example of a customer configuration. This may have to be updated to reflect the new server.
169
- * - In the `local` directory under the servers root directory: two files, `start.json` and `testStart.json`, may exist. `start.json` is used when `npm start` is executed; `testStart.json` is used when `npm test` is executed.
170
- * If these files dont exist, `example-start.json` is used to create `start.json` and `testStart.json`. Additionally, `example-testStart.json` is used to create `testStart.json`; values in `example-testStart.json` take precedence over values in `example-start.json`.
171
- * The configuration of these files depends on the servers configuration parameters.
171
+ * - In the `local` directory under the server's root directory: two files, `start.json` and `testStart.json`, may exist. `start.json` is used when `npm start` is executed; `testStart.json` is used when `npm test` is executed.
172
+ * If these files don't exist, `example-start.json` is used to create `start.json` and `testStart.json`. Additionally, `example-testStart.json` is used to create `testStart.json`; values in `example-testStart.json` take precedence over values in `example-start.json`.
173
+ * The configuration of these files depends on the server's configuration parameters.
172
174
  *
173
175
  * Example `start.json` for `mIT`:
174
176
  * ```javascript
@@ -274,7 +276,7 @@ const mITInit = (confType) => {
274
276
  start = updatedStart;
275
277
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
276
278
  .then((adminType) => {
277
- const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
279
+ const adminAudience = adminType.audiences.find(audienceItem => audienceItem.type === type);
278
280
  if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
279
281
  return undefined;
280
282
  })
@@ -345,7 +347,7 @@ const serverInit = (confType) => {
345
347
  start = updatedStart;
346
348
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
347
349
  .then((adminType) => {
348
- const adminAudience = find(adminType.audiences, audienceItem => audienceItem.type === type);
350
+ const adminAudience = adminType.audiences.find(audienceItem => audienceItem.type === type);
349
351
  if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
350
352
  return undefined;
351
353
  })
@@ -360,7 +362,7 @@ const serverInit = (confType) => {
360
362
 
361
363
  if (startConfig.oauthImplicitNeeded === 'yes') {
362
364
  return settingUpAdminClient('mID', `admin_${customer.name}_${start.NODE_ENV}_mID`, customer, start.MST_TOKEN, mSTBaseUrl)
363
- .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))
364
366
  .then((mIDAdminToken) => {
365
367
  start.MID_TOKEN = mIDAdminToken;
366
368
  testResponse.content = JSON.stringify(start2env(start), null, TAB);
@@ -634,7 +636,7 @@ export const testSetup = () => serverInit(TEST);
634
636
  *
635
637
  * | Filename | Description |
636
638
  * | -------- | ----------- |
637
- * | `../sumo.json` | Sumo Logic endpoints and code
639
+ * | `../sumoLog.json` | Sumo Logic endpoints and code
638
640
  * | `../kinesisLog.json` | Kinesis configuration
639
641
  * | `../s3Log.json` | S3 configuration
640
642
  * | `../mSTConfig.json` | mST configuration
@@ -659,27 +661,30 @@ export const setup = () => serverInit();
659
661
  * Creates the `rule files` for:
660
662
  *
661
663
  * - `eslint` -> `eslint.config.js`.
662
- * - `c8` -> `.nycrc`
663
664
  * - `github` -> `.gitignore`
665
+ * - `husky` -> `.husky/pre-commit`, `.husky/pre-push`, `.husky/commit-msg`
664
666
  *
665
667
  * If a file already exists, it will be overwritten.
666
668
  */
667
669
  export const dotFiles = () => {
668
670
  write('./eslint.config.js', read(join(localDirname, 'dotFiles', 'eslint.config.js'), INSTALL), INSTALL);
669
- write('./.nycrc', parse(read(join(localDirname, 'dotFiles', 'nycrc.json'), 'nycrc.json', INSTALL)), INSTALL, true);
670
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);
671
676
  };
672
677
 
673
678
  /**
674
679
  *
675
- * Utility to add `scripts` and `husky`.
680
+ * Utility to add `scripts` to `package.json`.
676
681
  *
677
682
  * @function scripts
678
683
  * @category sync
679
684
  *
680
685
  * @return `null`.
681
686
  *
682
- * 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.
683
688
  */
684
689
  export const scripts = () => {
685
690
  const scriptsContent = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
@@ -688,20 +693,19 @@ export const scripts = () => {
688
693
  Object.keys(scriptsContent.scripts).forEach((script) => {
689
694
  packageContent.scripts[script] = scriptsContent.scripts[script];
690
695
  });
691
- packageContent.husky = scriptsContent.husky;
692
696
  write(DEFAULT.FILE.packageFile, packageContent, DEFAULT.FILE.packageFile, INSTALL, true);
693
697
  };
694
698
 
695
699
  /**
696
700
  *
697
- * Utility to remove `scripts` and `husky`.
701
+ * Utility to remove `scripts` from `package.json`.
698
702
  *
699
703
  * @function unscripts
700
704
  * @category sync
701
705
  *
702
706
  * @return `null`.
703
707
  *
704
- * 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.
705
709
  */
706
710
  export const unScripts = () => {
707
711
  const scriptsContent = parse(read(join(localDirname, 'scripts.json'), INSTALL), 'scripts.json', INSTALL);
@@ -710,7 +714,6 @@ export const unScripts = () => {
710
714
  Object.keys(scriptsContent.scripts).forEach((script) => {
711
715
  delete packageContent.scripts[script];
712
716
  });
713
- delete packageContent.husky;
714
717
  write(DEFAULT.FILE.packageFile, packageContent, DEFAULT.FILE.packageFile, INSTALL, true);
715
718
  };
716
719
 
@@ -741,7 +744,7 @@ export { commitCheckMsg };
741
744
  * @function start2process
742
745
  * @category sync
743
746
  * @param {object} start - JSON object that is used to configure the environment variables. The comments (starting by //) are ignored.
744
- * @return `null`.
747
+ * @return {void}
745
748
  */
746
749
  export { start2process };
747
750
 
package/lib/common.js CHANGED
@@ -4,14 +4,23 @@ import process from 'node:process';
4
4
  const S3_MAX_EVENTS = 10;
5
5
  const S3_TIMEOUT = 1;
6
6
  const S3_MAX_SIZE = 5;
7
+ const KINESIS_MAX_EVENTS = 10;
8
+ const KINESIS_TIMEOUT = 1;
9
+ const KINESIS_MAX_SIZE = 5;
10
+ const KINESIS_MAX_RETRIES = 2;
11
+ const KINESIS_SOCKET_TIMEOUT = 5000;
12
+ const KINESIS_CONNECTION_TIMEOUT = 5000;
7
13
 
8
14
  const DEFAULT_MST_PORT = 8025;
9
15
  const DEFAULT_MIT_PORT = 8050;
10
16
  const DEFAULT_MID_PORT = 8015;
11
17
 
18
+ const STATUS_NOT_FOUND = 404;
19
+ const STATUS_SYSTEM = 500;
20
+
12
21
  const ERROR_CODE = {
13
- NOT_FOUND: 404,
14
- SYSTEM: 500,
22
+ NOT_FOUND: STATUS_NOT_FOUND,
23
+ SYSTEM: STATUS_SYSTEM,
15
24
  };
16
25
 
17
26
  const DEFAULT_ADMIN_EXTERNAL_ID_BASE = 'admin_default_local';
@@ -54,21 +63,31 @@ const DEFAULT = {
54
63
  },
55
64
 
56
65
  KINESISLOG: {
57
- region: '--- default region ---',
58
66
  accessKeyId: '--- default accessKey Id',
67
+ region: '--- default region ---',
59
68
  secretAccessKey: '--- default secret accessKey ---',
60
- streamNameInfo: '--- default streamName Info ---',
61
69
  streamNameError: '--- default streamName Error ---',
70
+ streamNameInfo: '--- default streamName Info ---',
62
71
  streamNameOther: '--- default streamName Other ---',
72
+
73
+ httpOptions: {
74
+ socketTimeout: KINESIS_SOCKET_TIMEOUT,
75
+ connectionTimeout: KINESIS_CONNECTION_TIMEOUT,
76
+ },
77
+ maxEvents: KINESIS_MAX_EVENTS,
78
+ maxRetries: KINESIS_MAX_RETRIES,
79
+ maxSize: KINESIS_MAX_SIZE,
80
+ timeout: KINESIS_TIMEOUT,
63
81
  },
64
82
  S3LOG: {
65
- region: '--- default region ---',
83
+ bucketname: '--- default bucketname ---',
66
84
  accessKeyId: '--- default accessKey Id',
85
+ region: '--- default region ---',
67
86
  secretAccessKey: '--- default secret accessKey ---',
68
- bucketname: '--- default bucketname ---',
87
+
69
88
  maxEvents: S3_MAX_EVENTS,
70
- timeout: S3_TIMEOUT,
71
89
  maxSize: S3_MAX_SIZE,
90
+ timeout: S3_TIMEOUT,
72
91
  },
73
92
  SUMOLOG: {
74
93
  default: {
@@ -133,7 +152,7 @@ const DUMMY = {
133
152
  },
134
153
  MST: {
135
154
  basePath: '/mST/v1',
136
- protocol: 'http',
155
+ protocol: 'http:',
137
156
  domainName: 'dummy-mST',
138
157
  port: DEFAULT_MST_PORT,
139
158
  admin: {
@@ -148,8 +167,7 @@ const API_PROVIDER_SWAGGERHUB = 'https://api.swaggerhub.com/apis';
148
167
  const API_SOURCE = '/src';
149
168
  const SWAGGER = 'swagger';
150
169
  const EXTENSION_YML = '.yml';
151
- const EXTENSION_JSON = '.json';
152
- const POSTFIX = `${SWAGGER}${EXTENSION_JSON}`;
170
+ const POSTFIX = `${SWAGGER}.json`;
153
171
  const SWAGGERHUB = 'swaggerhub';
154
172
  const BITBUCKET = 'bitbucket';
155
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,12 +121,12 @@ 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 excuted.
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
- * The options parameters has the folowing structure:
129
+ * The options parameters has the following structure:
132
130
  *``` javascript
133
131
  * {
134
132
  * sourceFilename: {PATH<string>}, // Source filename to use if altFilename does not retrieve any file.
@@ -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,39 +115,30 @@ 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
 
151
139
  if (!sumoLog) {
152
- if (!config.sumoLog.default) exitError(regType, Error(`missing sumologic default config in ${DEFAULT.FILE.sumoLogFile}`));
153
- console.log('- using ' + 'default value'.warn + ' for sumologic');
140
+ if (!config.sumoLog.default) exitError(regType, Error(`missing Sumologic default config in ${DEFAULT.FILE.sumoLogFile}`));
141
+ console.log('- using ' + 'default value'.warn + ' for Sumologic');
154
142
  sumoLog = config.sumoLog.default;
155
143
  }
156
144
  start.SUMO_LOGIC_ENDPOINT ||= sumoLog.url;
@@ -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
  };
@@ -245,8 +247,8 @@ const startSetup = (config, origStart) => {
245
247
  * @function getAPI
246
248
  * @category async
247
249
  * @param {PATH<string>} directory - Directory to store the API file.
248
- * @param {object} swaggerFile - Information from package.swaggeFile.
249
- * @param {string} key - `bitbucket` with username password to access the bitbucket account or string to access `swaggerhub`.
250
+ * @param {object} swaggerFile - Information from package.swaggerFile.
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.6",
3
+ "version": "7.2.0",
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,38 +27,29 @@
32
27
  "url": "https://bitbucket.org/mimiktech/local"
33
28
  },
34
29
  "dependencies": {
35
- "@eslint/js": "9.37.0",
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.4.0",
40
- "axios": "1.12.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.0",
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.37.0",
41
+ "comment-json": "4.6.2",
42
+ "eslint": "9.39.4",
47
43
  "eslint-plugin-import": "2.32.0",
44
+ "globals": "17.4.0",
48
45
  "husky": "9.1.7",
49
46
  "ip": "2.0.1",
50
47
  "js-base64": "3.7.8",
51
- "js-yaml": "4.1.0",
48
+ "js-yaml": "4.1.1",
52
49
  "jsdoc-to-markdown": "9.1.3",
53
- "lodash.difference": "4.5.0",
54
- "lodash.find": "4.6.0",
55
- "lodash.findindex": "4.6.0",
56
- "lodash.isempty": "4.4.0",
57
- "lodash.isnumber": "3.0.3",
58
- "lodash.isobject": "3.0.2",
59
- "lodash.split": "4.4.2",
60
- "lodash.union": "4.6.0",
61
- "mocha": "11.7.4",
50
+ "mocha": "11.7.5",
62
51
  "mochawesome": "7.1.4",
63
- "rewire": "9.0.1",
64
- "sinon": "21.0.0",
65
- "supertest": "7.1.4",
66
- "swagger-client": "3.35.7",
67
- "uuid": "11.1.0"
52
+ "sinon": "21.0.3",
53
+ "swagger-client": "3.37.1"
68
54
  }
69
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,71 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
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 = 45;
12
- const MIN_KEYS_IN_OBJECT = 10;
13
- const MAX_COMPLEXITY = 60;
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/**, coverage/**'],
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
- console: 'readonly',
33
- describe: 'readonly',
34
- it: 'readonly',
35
- structuredClone: 'readonly',
36
- },
37
- sourceType: 'module',
38
- },
39
- rules: {
40
- '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
41
- '@stylistic/line-comment-position': ['off'],
42
- '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
43
- '@stylistic/semi': ['error', 'always'],
44
- 'capitalized-comments': ['off'],
45
- 'complexity': ['error', MAX_COMPLEXITY],
46
- 'curly': ['off'],
47
- 'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
48
- 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
49
- 'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
50
- 'init-declarations': ['off'],
51
- 'linebreak-style': ['off'],
52
- 'max-depth': ['error', MAX_DEPTH],
53
- 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
54
- 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
55
- 'max-params': ['error', MAX_FUNCTION_PARAMETERS],
56
- 'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
57
- 'no-confusing-arrow': ['off'],
58
- 'no-inline-comments': ['off'],
59
- 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true }],
60
- 'no-process-env': ['error'],
61
- 'no-ternary': ['off'],
62
- 'no-undefined': ['off'],
63
- 'no-warning-comments': ['warn'],
64
- 'one-var': ['error', 'never'],
65
- 'processDoc/validate-document-env': ['error'],
66
- 'quotes': ['warn', 'single'],
67
- 'sort-imports': ['error', { allowSeparatedGroups: true }],
68
- 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
69
- },
70
- },
71
- ];
@@ -1,4 +0,0 @@
1
- {
2
- "exclude": ["gulpfile.js"],
3
- "reporter": ["lcov", "text"]
4
- }
package/eslint.config.js DELETED
@@ -1,70 +0,0 @@
1
- import importPlugin from 'eslint-plugin-import';
2
- import js from '@eslint/js';
3
- import processDoc from '@mimik/eslint-plugin-document-env';
4
- import stylistic from '@stylistic/eslint-plugin';
5
-
6
- const MAX_LENGTH_LINE = 180;
7
- const MAX_FUNCTION_PARAMETERS = 6;
8
- const MAX_LINES_IN_FILES = 600;
9
- const MAX_LINES_IN_FUNCTION = 150;
10
- const MAX_STATEMENTS_IN_FUNCTION = 80;
11
- const MIN_KEYS_IN_OBJECT = 10;
12
- const MAX_COMPLEXITY = 80;
13
- const ECMA_VERSION = 'latest';
14
- const MAX_DEPTH = 6;
15
- const ALLOWED_CONSTANTS = [0, 1, -1];
16
-
17
- export default [
18
- {
19
- ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
20
- },
21
- importPlugin.flatConfigs.recommended,
22
- stylistic.configs.recommended,
23
- js.configs.all,
24
- {
25
- plugins: {
26
- processDoc,
27
- },
28
- languageOptions: {
29
- ecmaVersion: ECMA_VERSION,
30
- globals: {
31
- console: 'readonly',
32
- describe: 'readonly',
33
- it: 'readonly',
34
- structuredClone: 'readonly',
35
- },
36
- sourceType: 'module',
37
- },
38
- rules: {
39
- '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
40
- '@stylistic/line-comment-position': ['off'],
41
- '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
42
- '@stylistic/semi': ['error', 'always'],
43
- 'capitalized-comments': ['off'],
44
- 'complexity': ['error', MAX_COMPLEXITY],
45
- 'curly': ['off'],
46
- 'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
47
- 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
48
- 'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
49
- 'init-declarations': ['off'],
50
- 'linebreak-style': ['off'],
51
- 'max-depth': ['error', MAX_DEPTH],
52
- 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
53
- 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
54
- 'max-params': ['error', MAX_FUNCTION_PARAMETERS],
55
- 'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
56
- 'no-confusing-arrow': ['off'],
57
- 'no-inline-comments': ['off'],
58
- 'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true }],
59
- 'no-process-env': ['error'],
60
- 'no-ternary': ['off'],
61
- 'no-undefined': ['off'],
62
- 'no-warning-comments': ['warn'],
63
- 'one-var': ['error', 'never'],
64
- 'processDoc/validate-document-env': ['error'],
65
- 'quotes': ['warn', 'single'],
66
- 'sort-imports': ['error', { allowSeparatedGroups: true }],
67
- 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
68
- },
69
- },
70
- ];
@@ -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
- }