@mimik/local 1.6.1 → 4.4.3

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
@@ -8,29 +8,35 @@ const eslint = require('gulp-eslint');
8
8
  const git = require('gulp-git');
9
9
  const jsdoc2md = require('jsdoc-to-markdown');
10
10
  const mocha = require('gulp-spawn-mocha');
11
+ const _ = require('lodash');
12
+
13
+ const { commitCheckMsg } = require('@mimik/git-hooks');
11
14
 
12
15
  const {
13
16
  colors,
14
17
  exitError,
15
- retrieve,
16
18
  start2env,
17
19
  start2shell,
20
+ baseUrl,
18
21
  } = require('./lib/helpers');
19
22
  const {
20
- testStartFile,
21
- exampleStartFile,
22
- startFile,
23
23
  defaultDirectory,
24
24
  testJsonFile,
25
25
  shellFile,
26
26
  DUMMY_CUSTOMER_CODE,
27
+ LITERAL,
28
+ SYSTEM_NAME,
29
+ TEST,
30
+ IGNORE,
27
31
  } = require('./lib/common');
28
32
  const {
33
+ getStartParams,
29
34
  init,
30
35
  startSetup,
31
36
  getAPI,
32
37
  getAdminToken,
33
38
  settingUpDummyServer,
39
+ gettingSystemCustomer,
34
40
  settingUpServer,
35
41
  settingUpCustomer,
36
42
  settingUpAdminClient,
@@ -43,7 +49,6 @@ colors.setTheme({
43
49
  info: ['grey', 'bold'],
44
50
  });
45
51
 
46
- const system = 'System';
47
52
  /**
48
53
  * @module local
49
54
  * @example
@@ -52,7 +57,7 @@ const system = 'System';
52
57
  * @description Set of function for local deployment.
53
58
  *
54
59
  * The following files are expected to exist:
55
- * 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.
56
61
  * - for `mSTConfig.json`:
57
62
  * ``` javascript
58
63
  * {
@@ -93,7 +98,7 @@ const system = 'System';
93
98
  * }
94
99
  * ```
95
100
  * Similar properties than for mSTConfig on `domainName` and `port` apply.
96
- * - for `sumo.json`:
101
+ * - for `sumoLog.json`:
97
102
  * ``` javascript
98
103
  * {
99
104
  * "<serverType>": {
@@ -105,10 +110,50 @@ const system = 'System';
105
110
  * "code": "code for sumologic, everything after the last / in the sumologic URL"
106
111
  * }
107
112
  * ```
108
- * 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.
109
150
  * - for `customerConfig.json`:
110
151
  * See `mST` `README.md` file for an example of a customer configuration. This may have to be updated to reflect the new servers.
111
- * - 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`:
112
157
  * ``` javascript
113
158
  * {
114
159
  * "NODE_ENV": "local",
@@ -126,6 +171,7 @@ const system = 'System';
126
171
  * There are reserved environement variable used by the library for configuration:
127
172
  * - `oauthImplicitNeeded`: if the service handles user token the implicit configuration is needed
128
173
  * - `mIDNeeded`: if the service has mID as a target
174
+ * - `locationNeeded`: if location translation is needed
129
175
  * - `standAlone`: if the service need to be operated without other service. If the service has targets most likely 500 errors will be generated
130
176
  *
131
177
  * If SERVER_ID is not set in the start.json or testStart.json file, SERVER_ID will be assigned with a uuid.v4.
@@ -148,38 +194,84 @@ const system = 'System';
148
194
  */
149
195
 
150
196
  const mSTInit = (confType) => {
151
- let regType = 'Local configuration setup ';
152
- let startConfig;
153
-
154
- process.stdout.write(regType);
155
- if (confType === 'test') {
156
- const test = 'for ' + 'test '.info;
157
-
158
- process.stdout.write(test);
159
- regType += test;
160
- startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
161
- }
162
- else {
163
- startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
164
- }
197
+ const { regType, startConfig } = getStartParams(confType);
165
198
  const config = init(regType);
166
199
  const start = startSetup(config, startConfig);
167
200
 
168
- 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)
169
202
  .then((apiFile) => {
170
203
  console.log('- mST base url: ' + config.mSTBaseUrl.info);
171
204
  console.log('- mIT base url: ' + config.MITBaseUrl.info);
172
205
  console.log('- mST config: ' + JSON.stringify(config.mST, null, 2).info);
173
- if (confType === 'test') {
174
- start.CUSTOMER_NAME = system;
206
+ if (confType === TEST) {
207
+ start.CUSTOMER_NAME = SYSTEM_NAME;
175
208
  start.BASE_PATH = apiFile.basePath;
176
209
  return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
177
210
  }
178
- 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
+ };
179
219
 
180
- shell += start2shell(start);
181
- shell += 'node index\n';
182
- 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
+ }));
183
275
  })
184
276
  .then((response) => {
185
277
  fs.writeFileSync(response.file, response.content);
@@ -189,60 +281,56 @@ const mSTInit = (confType) => {
189
281
  };
190
282
 
191
283
  const serverInit = (confType) => {
192
- let regType = 'Local configuration setup ';
193
- let startConfig;
284
+ const { regType, startConfig } = getStartParams(confType);
194
285
 
195
- process.stdout.write(regType);
196
- if (confType === 'test') {
197
- const test = 'for ' + 'test '.info;
286
+ const standAlone = startConfig.standAlone === 'yes';
287
+ const isMSTDisabled = startConfig.DISABLE_MST === 'yes';
198
288
 
199
- process.stdout.write(test);
200
- regType += test;
201
- startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
202
- }
203
- else {
204
- startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
205
- }
206
- const config = init(regType, startConfig.standAlone);
289
+ const config = init(regType, standAlone, isMSTDisabled);
207
290
  const { mSTBaseUrl, customer } = config;
208
- const { type } = config.pack;
291
+ const { type } = config.pack.mimik;
209
292
  let start = startSetup(config, startConfig);
210
293
  let authorization;
211
294
 
212
- 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)
213
296
  .then((apiFile) => {
214
297
  console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
215
298
  console.log('- mIT base url: ' + config.MITBaseUrl.info);
216
- if (startConfig.standAlone === 'yes') {
299
+ if (standAlone || isMSTDisabled) {
217
300
  console.log('- service ' + type.info + ' is in ' + 'stand alone'.warn + ' mode');
218
301
  start = settingUpDummyServer(type, start.SERVER_ID, customer, start);
219
- if (confType === 'test') {
302
+ if (confType === TEST) {
220
303
  start.CUSTOMER_NAME = customer.name;
221
304
  start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
222
305
  start.BASE_PATH = apiFile.basePath;
223
306
  return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
224
307
  }
225
- let shell = '#!/bin/sh\n';
226
-
227
- shell += start2shell(start);
228
- shell += 'node index\n';
229
- return { file: shellFile, content: shell, type: 'shell script' };
308
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
230
309
  }
231
- return getAdminToken('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
+ )
232
315
  .then((mSTAdminToken) => {
233
316
  authorization = mSTAdminToken;
234
317
  return settingUpCustomer(customer, authorization, mSTBaseUrl, config.mST.update);
235
318
  })
236
- .then((code) => {
237
- customer.code = code;
319
+ .then((updatedCustomer) => {
320
+ customer.code = updatedCustomer.code;
321
+ customer.config = updatedCustomer.config;
238
322
  return settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start);
239
323
  })
240
324
  .then((updatedStart) => {
241
325
  start = updatedStart;
242
326
  return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
243
- .then((admin) => getAdminToken(type, admin, 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
+ })
244
332
  .then((adminToken) => {
245
- if (confType === 'test') {
333
+ if (confType === TEST) {
246
334
  start.CUSTOMER_NAME = customer.name;
247
335
  start.CUSTOMER_CODE = customer.code;
248
336
  start.BASE_PATH = apiFile.basePath;
@@ -252,7 +340,7 @@ const serverInit = (confType) => {
252
340
 
253
341
  if (startConfig.oauthImplicitNeeded === 'yes') {
254
342
  return settingUpAdminClient('mID', `admin_${customer.name}_${start.NODE_ENV}_mID`, customer, start.MST_TOKEN, mSTBaseUrl)
255
- .then((admin) => getAdminToken('mID', admin, mSTBaseUrl))
343
+ .then((mIDAdminType) => getAdminToken(_.find(mIDAdminType.audiences, (audienceItem) => audienceItem.type === 'mID'), mIDAdminType.data, mSTBaseUrl))
256
344
  .then((mIDAdminToken) => {
257
345
  start.MID_TOKEN = mIDAdminToken;
258
346
  testResponse.content = JSON.stringify(start2env(start), null, 2);
@@ -261,13 +349,9 @@ const serverInit = (confType) => {
261
349
  }
262
350
  return testResponse;
263
351
  }
264
- console.log('- admin token for the service: ' + adminToken.info);
352
+ if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
265
353
  console.log('- mST token: ' + authorization.info);
266
- let shell = '#!/bin/sh\n';
267
-
268
- shell += start2shell(start);
269
- shell += 'node index\n';
270
- return { file: shellFile, content: shell, type: 'shell script' };
354
+ return { file: shellFile, content: start2shell(start), type: 'shell script' };
271
355
  });
272
356
  });
273
357
  })
@@ -298,14 +382,14 @@ const serverInit = (confType) => {
298
382
  *
299
383
  * | Filename | Description |
300
384
  * | -------- | ----------- |
301
- * | `../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
302
388
  * | `../mSTConfig.json` | The config for mST
303
389
  * | `../mITConfig.json` | The config for mIT
304
- * | `../mIDConfig.json` | The config for mID
305
- * | `../customerConfig.json` | The mST customer config
306
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
307
391
  */
308
- const mSTTestSetup = () => mSTInit('test');
392
+ const mSTTestSetup = () => mSTInit(TEST);
309
393
 
310
394
  /**
311
395
  *
@@ -327,18 +411,110 @@ const mSTTestSetup = () => mSTInit('test');
327
411
  *
328
412
  * | Filename | Description |
329
413
  * | -------- | ----------- |
330
- * | `../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
331
417
  * | `../mSTConfig.json` | The config for mST
332
418
  * | `../mITConfig.json` | The config for mIT
333
- * | `../mIDConfig.json` | The config for mID
334
- * | `../customerConfig.json` | The mST customer config
335
419
  * | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
336
420
  */
337
421
  const mSTSetup = () => mSTInit();
338
422
 
339
423
  /**
340
424
  *
341
- * 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.
342
518
  *
343
519
  * @function testSetup
344
520
  * @category sync
@@ -351,14 +527,14 @@ const mSTSetup = () => mSTInit();
351
527
  * 1. stand alone
352
528
  * 2. with mST, mID are other dependent servers
353
529
  *
354
- * The environment variable STAND_ALONE will select the the mode.
530
+ * The environment variable STAND_ALONE will select the mode.
355
531
  * When in stand alone, the following actions are being performed:
356
532
  *
357
533
  * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
358
534
  * 2. get an admin token for that service
359
535
  * 3. generate a json object store in a file under .
360
536
  *
361
- * 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
362
538
  *
363
539
  * When mST and other servers are present, the following actions are being performed:
364
540
  *
@@ -375,18 +551,20 @@ const mSTSetup = () => mSTInit();
375
551
  *
376
552
  * | Filename | Description |
377
553
  * | -------- | ----------- |
378
- * | `../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
379
557
  * | `../mSTConfig.json` | The config for mST
380
558
  * | `../mITConfig.json` | The config for mIT
381
559
  * | `../mIDConfig.json` | The config for mID
382
560
  * | `../customerConfig.json` | The mST customer config
383
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
384
562
  */
385
- const testSetup = () => serverInit('test');
563
+ const testSetup = () => serverInit(TEST);
386
564
 
387
565
  /**
388
566
  *
389
- * Setup a service (not mST).
567
+ * Setup a service (not mST, mIT).
390
568
  *
391
569
  * @function setup
392
570
  * @category sync
@@ -395,7 +573,21 @@ const testSetup = () => serverInit('test');
395
573
  *
396
574
  * Will exit 1 if there is an error.
397
575
  *
398
- * 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
+ *
399
591
  *
400
592
  * 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
401
593
  * 2. get an Admin token for mST
@@ -408,32 +600,33 @@ const testSetup = () => serverInit('test');
408
600
  * | Filename | Description |
409
601
  * | -------- | ----------- |
410
602
  * | `../sumo.json` | The sumologic endpoints and code
603
+ * | `../kinesisLog.json` | The Kinesis information
604
+ * | `../s3Log.json` | The S3 information
411
605
  * | `../mSTConfig.json` | The config for mST
412
606
  * | `../mITConfig.json` | The config for mIT
413
607
  * | `../mIDConfig.json` | The config for mID
414
608
  * | `../customerConfig.json` | The mST customer config
415
- * | `./config.json` | The config of the service
416
609
  * | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
417
610
  */
418
611
  const setup = () => serverInit();
419
612
 
420
- const rootPath = (pathName) => {
613
+ const rootPath = (pathName, ignore) => {
421
614
  const rootDir = path.join(__dirname, '..', '..', '..');
422
615
 
423
- 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}`;
424
621
  return rootDir;
425
622
  };
426
623
  const files = [
427
- rootPath('index.js'),
428
- rootPath('configuration/*.js'),
429
- rootPath('controllers/*.js'),
430
- rootPath('processors/*.js'),
431
- rootPath('models/*.js'),
432
- rootPath('lib/**.js'),
433
- rootPath('util/**.js'),
624
+ rootPath('src/**/*.js'),
434
625
  rootPath('Gulpfile.js'),
435
626
  rootPath('local/**.js'),
436
- rootPath('test/**.js'),
627
+ rootPath('test/**/*.js'),
628
+ rootPath('tools/**/*.js'),
629
+ rootPath('tools/**/{node_modules,node_modules/**}', true),
437
630
  ];
438
631
 
439
632
  /**
@@ -468,14 +661,13 @@ const test = () => {
468
661
  */
469
662
  const lint = () => gulp.src(files, { allowEmpty: true })
470
663
  .pipe(eslint({}))
471
- .pipe(eslint.format())
472
- .pipe(eslint.failOnError());
664
+ .pipe(eslint.format());
473
665
 
474
666
  const createDocs = (done) => {
475
- jsdoc2md.render({ files: rootPath('configuration/config.js') })
667
+ jsdoc2md.render({ files: rootPath('src/configuration/config.js') })
476
668
  .then((output) => fs.writeFileSync(rootPath('README.md'), output))
477
- .catch((err) => log.error('docs creation failed:', err.message));
478
- return done();
669
+ .catch((err) => log.error('docs creation failed:', err.message))
670
+ .finally(() => done());
479
671
  };
480
672
 
481
673
  const add = () => gulp.src(rootPath('README.md'))
@@ -492,13 +684,91 @@ const add = () => gulp.src(rootPath('README.md'))
492
684
  */
493
685
  const docs = gulp.series(createDocs, add);
494
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
+
495
761
  module.exports = {
496
762
  mSTTestSetup,
497
763
  mSTSetup,
764
+ mITTestSetup,
765
+ mITSetup,
498
766
  testSetup,
499
767
  setup,
500
768
  test,
501
769
  lint,
502
770
  docs,
503
771
  add,
772
+ dotFiles,
773
+ commitCheckMsg,
504
774
  };