@mimik/local 1.6.2 → 4.4.4

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/index.js CHANGED
@@ -10,30 +10,33 @@ const jsdoc2md = require('jsdoc-to-markdown');
10
10
  const mocha = require('gulp-spawn-mocha');
11
11
  const _ = require('lodash');
12
12
 
13
+ const { commitCheckMsg } = require('@mimik/git-hooks');
14
+
13
15
  const {
14
16
  colors,
15
17
  exitError,
16
- retrieve,
17
18
  start2env,
18
19
  start2shell,
19
20
  baseUrl,
20
21
  } = require('./lib/helpers');
21
22
  const {
22
- testStartFile,
23
- exampleStartFile,
24
- startFile,
25
23
  defaultDirectory,
26
24
  testJsonFile,
27
25
  shellFile,
28
26
  DUMMY_CUSTOMER_CODE,
29
27
  LITERAL,
28
+ SYSTEM_NAME,
29
+ TEST,
30
+ IGNORE,
30
31
  } = require('./lib/common');
31
32
  const {
33
+ getStartParams,
32
34
  init,
33
35
  startSetup,
34
36
  getAPI,
35
37
  getAdminToken,
36
38
  settingUpDummyServer,
39
+ gettingSystemCustomer,
37
40
  settingUpServer,
38
41
  settingUpCustomer,
39
42
  settingUpAdminClient,
@@ -46,7 +49,6 @@ colors.setTheme({
46
49
  info: ['grey', 'bold'],
47
50
  });
48
51
 
49
- const system = 'System';
50
52
  /**
51
53
  * @module local
52
54
  * @example
@@ -55,7 +57,7 @@ const system = 'System';
55
57
  * @description Set of function for local deployment.
56
58
  *
57
59
  * The following files are expected to exist:
58
- * In the directory above the server root directory: five files `mSTConfig.json`, `mIDConfig.json`, `mITConfig.json`,`sumo.json`, `customerConfig.json` are being set. If the don't exist at the launch of the script, default will be setup.
60
+ * In the directory above the server root directory: `mSTConfig.json`, `mIDConfig.json`, `mITConfig.json`,`sumoLog.json`, `kinesisLog.json`, ``s3Log.json`, `customerConfig.json`, 'key.json`, `locationConfig.json` are being set. If they don't exist at the launch of the script, default will be setup.
59
61
  * - for `mSTConfig.json`:
60
62
  * ``` javascript
61
63
  * {
@@ -96,7 +98,7 @@ const system = 'System';
96
98
  * }
97
99
  * ```
98
100
  * Similar properties than for mSTConfig on `domainName` and `port` apply.
99
- * - for `sumo.json`:
101
+ * - for `sumoLog.json`:
100
102
  * ``` javascript
101
103
  * {
102
104
  * "<serverType>": {
@@ -108,10 +110,50 @@ const system = 'System';
108
110
  * "code": "code for sumologic, everything after the last / in the sumologic URL"
109
111
  * }
110
112
  * ```
111
- * A property may be define for each `serverType` involved. If the serverType does not exist the default will be picked.
113
+ * - for `kinesisLog.json`:
114
+ * ``` javascript
115
+ * {
116
+ * "region": "region of the Kinesis implementation",
117
+ * "accessKeyId": "access key id of Kinesis",
118
+ * "secretAccessKey": "secret access key for Kinesis",
119
+ * "streamNameInfo": "name of the kiniesis stream for info",
120
+ * "streamNameError": "name of the kiniesis stream for error",
121
+ * "streamNameOther": "name of the kiniesis stream for all the other levels"
122
+ * }
123
+ * ```
124
+ * - for `s3Log.json`:
125
+ * ``` javascript
126
+ * {
127
+ * "region": "region of the S3 implementation",
128
+ * "accessKeyId": "Access key id for S3",
129
+ * "secretAccessKey": "secret access key for S3",
130
+ * "bucketname": "name of the S3 bucket used to store the information",
131
+ * "maxEvents": "number of events buffered before sending to S3 (integer)",
132
+ * "timeout": "number of seconds before timeout to send to S3 (integer)",
133
+ * "maxSize": "max size in Bytes before sending to S3 (integer)"
134
+ * }
135
+ * ```
136
+ * - for `key.json`:
137
+ * ``` javascript
138
+ * {
139
+ * "apiKey": "key to access API definition on the API provider"
140
+ * }
141
+ * ```
142
+ * - for `locationConfig.json`:
143
+ * ``` javascript
144
+ * {
145
+ * "url": "url of the location provider"
146
+ * "key": "key to make request to the location provider"
147
+ * }
148
+ * ```
149
+ * A property may be defined for each `serverType` involved. If the serverType does not exist the default will be picked.
112
150
  * - for `customerConfig.json`:
113
151
  * See `mST` `README.md` file for an example of a customer configuration. This may have to be updated to reflect the new servers.
114
- * - in the `local` directory of the server root directory: two files `start.json` and `testStart.json` may exit, if `testStart.json` is missing, `start.json` will be used as testStart.json. The configuration of these files depends on the configuration parameters of the server. The following is an example of start.json file for `mIT`:
152
+ * - in the `local` directory of the server root directory: two files `start.json` and `testStart.json` may exit. `start.json` is used when `npm start` is executed, `testStart.json` is used when `npm test` is executed.
153
+ * If the files don't exist `exampe-start.json` is used to create `start.json` and `testStart.json`.
154
+ * Additionally `example-testStart.json` is used when to create `testStart.json`. The values in `example-testStart.json` take precedence over the values in `example-start.json`.
155
+ * The configuration of these files depends on the configuration parameters of the server. If the files
156
+ * The following is an example of start.json file for `mIT`:
115
157
  * ``` javascript
116
158
  * {
117
159
  * "NODE_ENV": "local",
@@ -129,6 +171,7 @@ const system = 'System';
129
171
  * There are reserved environement variable used by the library for configuration:
130
172
  * - `oauthImplicitNeeded`: if the service handles user token the implicit configuration is needed
131
173
  * - `mIDNeeded`: if the service has mID as a target
174
+ * - `locationNeeded`: if location translation is needed
132
175
  * - `standAlone`: if the service need to be operated without other service. If the service has targets most likely 500 errors will be generated
133
176
  *
134
177
  * If SERVER_ID is not set in the start.json or testStart.json file, SERVER_ID will be assigned with a uuid.v4.
@@ -151,38 +194,84 @@ const system = 'System';
151
194
  */
152
195
 
153
196
  const mSTInit = (confType) => {
154
- let regType = 'Local configuration setup ';
155
- let startConfig;
156
-
157
- process.stdout.write(regType);
158
- if (confType === 'test') {
159
- const test = 'for ' + 'test '.info;
160
-
161
- process.stdout.write(test);
162
- regType += test;
163
- startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
164
- }
165
- else {
166
- startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
167
- }
197
+ const { regType, startConfig } = getStartParams(confType);
168
198
  const config = init(regType);
169
199
  const start = startSetup(config, startConfig);
170
200
 
171
- getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.name, config.pack.swaggerFile.version)
201
+ getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
172
202
  .then((apiFile) => {
173
203
  console.log('- mST base url: ' + config.mSTBaseUrl.info);
174
204
  console.log('- mIT base url: ' + config.MITBaseUrl.info);
175
205
  console.log('- mST config: ' + JSON.stringify(config.mST, null, 2).info);
176
- if (confType === 'test') {
177
- start.CUSTOMER_NAME = system;
206
+ if (confType === TEST) {
207
+ start.CUSTOMER_NAME = SYSTEM_NAME;
178
208
  start.BASE_PATH = apiFile.basePath;
179
209
  return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
180
210
  }
181
- let shell = '#!/bin/sh\n';
211
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
212
+ })
213
+ .then((response) => {
214
+ fs.writeFileSync(response.file, response.content);
215
+ console.log(`${regType}status: ` + 'completed'.success + ', ' + response.type.info + ' created at (' + response.file.info + ')');
216
+ })
217
+ .catch((err) => exitError(regType, err));
218
+ };
182
219
 
183
- shell += start2shell(start);
184
- shell += 'node index\n';
185
- return { file: shellFile, content: shell, type: 'shell script' };
220
+ const mITInit = (confType) => {
221
+ const { regType, startConfig } = getStartParams(confType);
222
+ const config = init(regType, startConfig.standAlone);
223
+ const { mSTBaseUrl } = config;
224
+ const { type } = config.pack.mimik;
225
+ let start = startSetup(config, startConfig);
226
+ let authorization;
227
+
228
+ getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
229
+ .then((apiFile) => {
230
+ console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
231
+ console.log('- mIT base url: ' + config.MITBaseUrl.info);
232
+ if (startConfig.standAlone === 'yes') {
233
+ console.log('- service ' + type.info + ' is in ' + 'stand alone'.warn + ' mode');
234
+ start = settingUpDummyServer(type, start.SERVER_ID, null, start);
235
+ if (confType === TEST) {
236
+ start.CUSTOMER_NAME = SYSTEM_NAME;
237
+ start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
238
+ start.BASE_PATH = apiFile.basePath;
239
+ return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
240
+ }
241
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
242
+ }
243
+ return getAdminToken(
244
+ { type: 'mST', audience: `${baseUrl('mST', regType, config.mST, LITERAL)}/clients/Generic-mST` },
245
+ { id: config.mST.admin.clientId, secret: config.mST.admin.clientSecret },
246
+ mSTBaseUrl,
247
+ )
248
+ .then((mSTAdminToken) => {
249
+ authorization = mSTAdminToken;
250
+ return gettingSystemCustomer(authorization, mSTBaseUrl);
251
+ })
252
+ .then((customer) => settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start)
253
+ .then((updatedStart) => {
254
+ start = updatedStart;
255
+ return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
256
+ .then((adminType) => {
257
+ const adminAudience = _.find(adminType.audiences, (audienceItem) => audienceItem.type === type);
258
+ if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
259
+ return undefined;
260
+ })
261
+ .then((adminToken) => {
262
+ if (confType === TEST) {
263
+ start.CUSTOMER_NAME = customer.name;
264
+ start.CUSTOMER_CODE = customer.code;
265
+ start.BASE_PATH = apiFile.basePath;
266
+ start.MST_TOKEN = authorization;
267
+ start.ADMIN_TOKEN = adminToken;
268
+ return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
269
+ }
270
+ if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
271
+ console.log('- mST token: ' + authorization.info);
272
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
273
+ });
274
+ }));
186
275
  })
187
276
  .then((response) => {
188
277
  fs.writeFileSync(response.file, response.content);
@@ -192,60 +281,56 @@ const mSTInit = (confType) => {
192
281
  };
193
282
 
194
283
  const serverInit = (confType) => {
195
- let regType = 'Local configuration setup ';
196
- let startConfig;
284
+ const { regType, startConfig } = getStartParams(confType);
197
285
 
198
- process.stdout.write(regType);
199
- if (confType === 'test') {
200
- const test = 'for ' + 'test '.info;
286
+ const standAlone = startConfig.standAlone === 'yes';
287
+ const isMSTSet = startConfig.MST_SET !== 'off';
201
288
 
202
- process.stdout.write(test);
203
- regType += test;
204
- startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
205
- }
206
- else {
207
- startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
208
- }
209
- const config = init(regType, startConfig.standAlone);
289
+ const config = init(regType, standAlone, isMSTSet);
210
290
  const { mSTBaseUrl, customer } = config;
211
- const { type } = config.pack;
291
+ const { type } = config.pack.mimik;
212
292
  let start = startSetup(config, startConfig);
213
293
  let authorization;
214
294
 
215
- getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.name, config.pack.swaggerFile.version)
295
+ getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
216
296
  .then((apiFile) => {
217
297
  console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
218
298
  console.log('- mIT base url: ' + config.MITBaseUrl.info);
219
- if (startConfig.standAlone === 'yes') {
299
+ if (standAlone || !isMSTSet) {
220
300
  console.log('- service ' + type.info + ' is in ' + 'stand alone'.warn + ' mode');
221
301
  start = settingUpDummyServer(type, start.SERVER_ID, customer, start);
222
- if (confType === 'test') {
302
+ if (confType === TEST) {
223
303
  start.CUSTOMER_NAME = customer.name;
224
304
  start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
225
305
  start.BASE_PATH = apiFile.basePath;
226
306
  return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
227
307
  }
228
- let shell = '#!/bin/sh\n';
229
-
230
- shell += start2shell(start);
231
- shell += 'node index\n';
232
- return { file: shellFile, content: shell, type: 'shell script' };
308
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
233
309
  }
234
- return getAdminToken({ type: 'mST', audience: `${baseUrl('mST', regType, config.mST, LITERAL)}/clients/Generic-mST` }, { id: config.mST.admin.clientId, secret: config.mST.admin.clientSecret }, mSTBaseUrl)
310
+ return getAdminToken(
311
+ { type: 'mST', audience: `${baseUrl('mST', regType, config.mST, LITERAL)}/clients/Generic-mST` },
312
+ { id: config.mST.admin.clientId, secret: config.mST.admin.clientSecret },
313
+ mSTBaseUrl,
314
+ )
235
315
  .then((mSTAdminToken) => {
236
316
  authorization = mSTAdminToken;
237
317
  return settingUpCustomer(customer, authorization, mSTBaseUrl, config.mST.update);
238
318
  })
239
- .then((code) => {
240
- customer.code = code;
319
+ .then((updatedCustomer) => {
320
+ customer.code = updatedCustomer.code;
321
+ customer.config = updatedCustomer.config;
241
322
  return settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start);
242
323
  })
243
324
  .then((updatedStart) => {
244
325
  start = updatedStart;
245
326
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
246
- .then((adminType) => getAdminToken(_.find(adminType.audiences, (audienceItem) => audienceItem.type === type), adminType.data, mSTBaseUrl))
327
+ .then((adminType) => {
328
+ const adminAudience = _.find(adminType.audiences, (audienceItem) => audienceItem.type === type);
329
+ if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
330
+ return undefined;
331
+ })
247
332
  .then((adminToken) => {
248
- if (confType === 'test') {
333
+ if (confType === TEST) {
249
334
  start.CUSTOMER_NAME = customer.name;
250
335
  start.CUSTOMER_CODE = customer.code;
251
336
  start.BASE_PATH = apiFile.basePath;
@@ -264,13 +349,9 @@ const serverInit = (confType) => {
264
349
  }
265
350
  return testResponse;
266
351
  }
267
- console.log('- admin token for the service: ' + adminToken.info);
352
+ if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
268
353
  console.log('- mST token: ' + authorization.info);
269
- let shell = '#!/bin/sh\n';
270
-
271
- shell += start2shell(start);
272
- shell += 'node index\n';
273
- return { file: shellFile, content: shell, type: 'shell script' };
354
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
274
355
  });
275
356
  });
276
357
  })
@@ -301,14 +382,14 @@ const serverInit = (confType) => {
301
382
  *
302
383
  * | Filename | Description |
303
384
  * | -------- | ----------- |
304
- * | `../sumo.json` | The sumologic endpoints and code
385
+ * | `../sumoLog.json` | The sumologic endpoints and code
386
+ * | `../kinesisLog.json` | The Kinesis information
387
+ * | `../s3Log.json` | The S3 information
305
388
  * | `../mSTConfig.json` | The config for mST
306
389
  * | `../mITConfig.json` | The config for mIT
307
- * | `../mIDConfig.json` | The config for mID
308
- * | `../customerConfig.json` | The mST customer config
309
390
  * | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
310
391
  */
311
- const mSTTestSetup = () => mSTInit('test');
392
+ const mSTTestSetup = () => mSTInit(TEST);
312
393
 
313
394
  /**
314
395
  *
@@ -330,18 +411,110 @@ const mSTTestSetup = () => mSTInit('test');
330
411
  *
331
412
  * | Filename | Description |
332
413
  * | -------- | ----------- |
333
- * | `../sumo.json` | The sumologic endpoints and code
414
+ * | `../sumoLog.json` | The sumologic endpoints and code
415
+ * | `../kinesisLog.json` | The Kinesis information
416
+ * | `../s3Log.json` | The S3 information
334
417
  * | `../mSTConfig.json` | The config for mST
335
418
  * | `../mITConfig.json` | The config for mIT
336
- * | `../mIDConfig.json` | The config for mID
337
- * | `../customerConfig.json` | The mST customer config
338
419
  * | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
339
420
  */
340
421
  const mSTSetup = () => mSTInit();
341
422
 
342
423
  /**
343
424
  *
344
- * Setup a service (not mST) for test.
425
+ * Setup mIT for test.
426
+ *
427
+ * @function testSetup
428
+ * @category sync
429
+ *
430
+ * @return `null`.
431
+ *
432
+ * Will exit 1 if there is an error.
433
+ *
434
+ * Two modes are available:
435
+ * 1. stand alone
436
+ * 2. with mST
437
+ *
438
+ * The environment variable STAND_ALONE will select the mode.
439
+ * When in stand alone, the following actions are being performed:
440
+ *
441
+ * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
442
+ * 2. get an admin token for that service
443
+ * 3. generate a json object store in a file under .
444
+ *
445
+ * In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
446
+ *
447
+ * When mST and other servers are present, the following actions are being performed:
448
+ *
449
+ * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
450
+ * 2. get an admin token for mST
451
+ * 3. register the service in mST
452
+ * 4. register an admin client for that service in mST
453
+ * 5. get an admin token for that service
454
+ * 6. get an admin token for mID if needed
455
+ * 7. generate a json object store in a file under .
456
+ *
457
+ * The following files are needed to perform these actions:
458
+ *
459
+ * | Filename | Description |
460
+ * | -------- | ----------- |
461
+ * | `../sumoLog.json` | The sumologic endpoints and code
462
+ * | `../kinesisLog.json` | The Kinesis information
463
+ * | `../s3Log.json` | The S3 information
464
+ * | `../mSTConfig.json` | The config for mST
465
+ * | `../mITConfig.json` | The config for mIT
466
+ * | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
467
+ */
468
+ const mITTestSetup = () => mITInit(TEST);
469
+
470
+ /**
471
+ *
472
+ * Setup mIT.
473
+ *
474
+ * @function setup
475
+ * @category sync
476
+ *
477
+ * @return `null`.
478
+ *
479
+ * Will exit 1 if there is an error.
480
+ *
481
+ * Two modes are available:
482
+ * 1. stand alone
483
+ * 2. with mST
484
+ *
485
+ * The environment variable STAND_ALONE will select the mode.
486
+ * When in stand alone, the following actions are being performed:
487
+ *
488
+ * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
489
+ * 2. get an admin token for that service
490
+ * 3. generate a shell script to start the server
491
+ *
492
+ * In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
493
+ *
494
+ * When mST is present, the following actions are being performed:
495
+ *
496
+ *
497
+ * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
498
+ * 2. get an Admin token for mST
499
+ * 3. register the service in mST
500
+ * 4. generate a shell script to start the server
501
+ *
502
+ * The following files are needed to perform these actions:
503
+ *
504
+ * | Filename | Description |
505
+ * | -------- | ----------- |
506
+ * | `../sumoLog.json` | The sumologic endpoints and code
507
+ * | `../kinesisLog.json` | The Kinesis information
508
+ * | `../s3Log.json` | The S3 information
509
+ * | `../mSTConfig.json` | The config for mST
510
+ * | `../mITConfig.json` | The config for mIT
511
+ * | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
512
+ */
513
+ const mITSetup = () => mITInit();
514
+
515
+ /**
516
+ *
517
+ * Setup a service (not mST, mIT) for test.
345
518
  *
346
519
  * @function testSetup
347
520
  * @category sync
@@ -354,14 +527,14 @@ const mSTSetup = () => mSTInit();
354
527
  * 1. stand alone
355
528
  * 2. with mST, mID are other dependent servers
356
529
  *
357
- * The environment variable STAND_ALONE will select the the mode.
530
+ * The environment variable STAND_ALONE will select the mode.
358
531
  * When in stand alone, the following actions are being performed:
359
532
  *
360
533
  * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
361
534
  * 2. get an admin token for that service
362
535
  * 3. generate a json object store in a file under .
363
536
  *
364
- * In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most like generate a 500 error
537
+ * In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
365
538
  *
366
539
  * When mST and other servers are present, the following actions are being performed:
367
540
  *
@@ -378,18 +551,20 @@ const mSTSetup = () => mSTInit();
378
551
  *
379
552
  * | Filename | Description |
380
553
  * | -------- | ----------- |
381
- * | `../sumo.json` | The sumologic endpoints and code
554
+ * | `../sumoLog.json` | The sumologic endpoints and code
555
+ * | `../kinesisLog.json` | The Kinesis information
556
+ * | `../s3Log.json` | The S3 information
382
557
  * | `../mSTConfig.json` | The config for mST
383
558
  * | `../mITConfig.json` | The config for mIT
384
559
  * | `../mIDConfig.json` | The config for mID
385
560
  * | `../customerConfig.json` | The mST customer config
386
561
  * | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
387
562
  */
388
- const testSetup = () => serverInit('test');
563
+ const testSetup = () => serverInit(TEST);
389
564
 
390
565
  /**
391
566
  *
392
- * Setup a service (not mST).
567
+ * Setup a service (not mST, mIT).
393
568
  *
394
569
  * @function setup
395
570
  * @category sync
@@ -398,7 +573,21 @@ const testSetup = () => serverInit('test');
398
573
  *
399
574
  * Will exit 1 if there is an error.
400
575
  *
401
- * The following actions are being performed:
576
+ * Two modes are available:
577
+ * 1. stand alone
578
+ * 2. with mST, mID are other dependent servers
579
+ *
580
+ * The environment variable STAND_ALONE will select the mode.
581
+ * When in stand alone, the following actions are being performed:
582
+ *
583
+ * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
584
+ * 2. get an admin token for that service
585
+ * 3. generate a shell script to start the server
586
+ *
587
+ * In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
588
+ *
589
+ * When mST and other servers are present, the following actions are being performed:
590
+ *
402
591
  *
403
592
  * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
404
593
  * 2. get an Admin token for mST
@@ -411,33 +600,33 @@ const testSetup = () => serverInit('test');
411
600
  * | Filename | Description |
412
601
  * | -------- | ----------- |
413
602
  * | `../sumo.json` | The sumologic endpoints and code
603
+ * | `../kinesisLog.json` | The Kinesis information
604
+ * | `../s3Log.json` | The S3 information
414
605
  * | `../mSTConfig.json` | The config for mST
415
606
  * | `../mITConfig.json` | The config for mIT
416
607
  * | `../mIDConfig.json` | The config for mID
417
608
  * | `../customerConfig.json` | The mST customer config
418
- * | `./config.json` | The config of the service
419
609
  * | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
420
610
  */
421
611
  const setup = () => serverInit();
422
612
 
423
- const rootPath = (pathName) => {
613
+ const rootPath = (pathName, ignore) => {
424
614
  const rootDir = path.join(__dirname, '..', '..', '..');
425
615
 
426
- if (pathName) return path.join(rootDir, pathName);
616
+ if (pathName) {
617
+ if (ignore) return `${IGNORE}${path.join(rootDir, pathName)}`;
618
+ return path.join(rootDir, pathName);
619
+ }
620
+ if (ignore) return `${IGNORE}${rootDir}`;
427
621
  return rootDir;
428
622
  };
429
623
  const files = [
430
- rootPath('index.js'),
431
- rootPath('configuration/*.js'),
432
- rootPath('controllers/*.js'),
433
- rootPath('processors/*.js'),
434
- rootPath('models/*.js'),
435
- rootPath('lib/**/*.js'),
436
- rootPath('util/**/*.js'),
624
+ rootPath('src/**/*.js'),
437
625
  rootPath('Gulpfile.js'),
438
626
  rootPath('local/**.js'),
439
627
  rootPath('test/**/*.js'),
440
628
  rootPath('tools/**/*.js'),
629
+ rootPath('tools/**/{node_modules,node_modules/**}', true),
441
630
  ];
442
631
 
443
632
  /**
@@ -472,14 +661,13 @@ const test = () => {
472
661
  */
473
662
  const lint = () => gulp.src(files, { allowEmpty: true })
474
663
  .pipe(eslint({}))
475
- .pipe(eslint.format())
476
- .pipe(eslint.failOnError());
664
+ .pipe(eslint.format());
477
665
 
478
666
  const createDocs = (done) => {
479
- jsdoc2md.render({ files: rootPath('configuration/config.js') })
667
+ jsdoc2md.render({ files: rootPath('src/configuration/config.js') })
480
668
  .then((output) => fs.writeFileSync(rootPath('README.md'), output))
481
- .catch((err) => log.error('docs creation failed:', err.message));
482
- return done();
669
+ .catch((err) => log.error('docs creation failed:', err.message))
670
+ .finally(() => done());
483
671
  };
484
672
 
485
673
  const add = () => gulp.src(rootPath('README.md'))
@@ -496,13 +684,91 @@ const add = () => gulp.src(rootPath('README.md'))
496
684
  */
497
685
  const docs = gulp.series(createDocs, add);
498
686
 
687
+ const dotFiles = () => {
688
+ const eslintrc = {
689
+ env: {
690
+ node: true,
691
+ },
692
+ plugins: [
693
+ '@mimik/document-env',
694
+ '@mimik/dependencies',
695
+ ],
696
+ extends: 'airbnb',
697
+ parserOptions: {
698
+ ecmaVersion: 2020,
699
+ },
700
+ rules: {
701
+ 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
702
+ 'brace-style': [1, 'stroustrup', { allowSingleLine: true }],
703
+ 'no-confusing-arrow': [0], // arrow isnt confusing
704
+ 'max-len': [1, 180, { ignoreComments: true }],
705
+ 'linebreak-style': 0,
706
+ quotes: [1, 'single'],
707
+ semi: [1, 'always'],
708
+ 'no-process-env': ['error'],
709
+ '@mimik/document-env/validate-document-env': 2,
710
+ '@mimik/dependencies/case-sensitive': 2,
711
+ '@mimik/dependencies/no-cycles': 2,
712
+ '@mimik/dependencies/no-unresolved': 2,
713
+ '@mimik/dependencies/require-json-ext': 2,
714
+ },
715
+ overrides: [
716
+ {
717
+ files: [
718
+ 'src/configuration/config.js',
719
+ 'test/**/*.js',
720
+ 'tools/**/*.js',
721
+ ],
722
+ rules: {
723
+ 'no-process-env': 'off',
724
+ },
725
+ },
726
+ {
727
+ files: [
728
+ 'test/**/*.js',
729
+ 'tools/**/*.js',
730
+ ],
731
+ rules: {
732
+ '@mimik/document-env/validate-document-env': 'off',
733
+ },
734
+ },
735
+ ],
736
+ settings: {
737
+ react: {
738
+ version: 'latest',
739
+ },
740
+ },
741
+ globals: {
742
+ module: true,
743
+ require: true,
744
+ const: false,
745
+ it: false,
746
+ describe: false,
747
+ before: true,
748
+ after: true,
749
+ JSON: true,
750
+ },
751
+ };
752
+ const nycrc = {
753
+ exclude: ['gulpfile.js'],
754
+ reporter: ['lcov', 'text'],
755
+ };
756
+
757
+ fs.writeFileSync(rootPath('.eslintrc'), JSON.stringify(eslintrc, null, 2));
758
+ fs.writeFileSync(rootPath('.nycrc'), JSON.stringify(nycrc, null, 2));
759
+ };
760
+
499
761
  module.exports = {
500
762
  mSTTestSetup,
501
763
  mSTSetup,
764
+ mITTestSetup,
765
+ mITSetup,
502
766
  testSetup,
503
767
  setup,
504
768
  test,
505
769
  lint,
506
770
  docs,
507
771
  add,
772
+ dotFiles,
773
+ commitCheckMsg,
508
774
  };