@mimik/local 6.0.12 → 7.0.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/lib/helpers.js CHANGED
@@ -1,10 +1,12 @@
1
- /* eslint-disable prefer-template, no-console, no-process-env, @mimik/document-env/validate-document-env */
2
- const colors = require('colors');
3
- const fs = require('fs');
4
- const ip = require('ip');
5
- const json = require('comment-json');
6
- const net = require('net');
7
- const _ = require('lodash');
1
+ /* eslint-disable prefer-template, no-console, no-process-env, processDoc/validate-document-env */
2
+ import colors from 'colors';
3
+ import fs from 'fs';
4
+ import ip from 'ip';
5
+ import isNumber from 'lodash.isnumber';
6
+ import isObject from 'lodash.isobject';
7
+ import json from 'comment-json';
8
+ import net from 'net';
9
+ import process from 'process';
8
10
 
9
11
  colors.setTheme({
10
12
  success: 'green',
@@ -13,19 +15,30 @@ colors.setTheme({
13
15
  info: ['grey', 'bold'],
14
16
  });
15
17
 
18
+ const SYSTEM_ERROR = 500;
19
+ const EXIT_ERROR = 1;
20
+ const TAB = 2;
21
+ const FIRST = 0;
22
+ const SECOND = 1;
23
+ const START = 0;
24
+ const EXT = 2;
25
+ const SUB = 1;
26
+
16
27
  const exitError = (regType, error, filename) => {
17
- let details = `{ statusCode: ${error.statusCode || 500}, message: ${error.message || error}`;
28
+ let details = `{ statusCode: ${error.statusCode || SYSTEM_ERROR}, message: ${error.message || error}`;
18
29
 
19
30
  if (filename) details = `${details}, filename: ${filename}`;
20
31
  details = `${details} }`;
21
32
  console.error(`${regType}status: ` + 'error'.error + ', ' + details.info);
22
- process.exit(1);
33
+ process.exit(EXIT_ERROR);
23
34
  };
24
35
 
25
36
  const read = (filename, regType) => {
26
37
  let readFile;
27
38
 
28
- try { readFile = fs.readFileSync(filename).toString(); }
39
+ try {
40
+ readFile = fs.readFileSync(filename).toString();
41
+ }
29
42
  catch (err) {
30
43
  if (err.code !== 'ENOENT') return exitError(regType, err, filename);
31
44
  throw err;
@@ -35,15 +48,17 @@ const read = (filename, regType) => {
35
48
 
36
49
  const write = (fname, content, regType, withJSON) => {
37
50
  try {
38
- if (withJSON) fs.writeFileSync(fname, json.stringify(content, null, 2));
39
- else fs.writeFileSync(fname, content, null, 2);
51
+ if (withJSON) fs.writeFileSync(fname, json.stringify(content, null, TAB));
52
+ else fs.writeFileSync(fname, content, null, TAB);
40
53
  }
41
54
  catch (err) { exitError(regType, err, fname); }
42
55
  return content;
43
56
  };
44
57
 
45
58
  const parse = (rawFile, rawFilename, regType) => {
46
- try { return json.parse(rawFile); }
59
+ try {
60
+ return json.parse(rawFile);
61
+ }
47
62
  catch (errParse) { return exitError(regType, errParse, rawFilename); }
48
63
  };
49
64
 
@@ -51,9 +66,9 @@ const start2shell = (start) => {
51
66
  let result = '#!/bin/sh\n';
52
67
 
53
68
  Object.keys(start).forEach((key) => {
54
- if (key[0] !== '/' && key[1] !== '/') {
55
- if (_.isNumber(start[key])) result = `${result}export ${key}=${start[key]}\n`;
56
- else if (_.isObject(start[key])) result = `${result}export ${key}='${JSON.stringify(start[key])}'\n`;
69
+ if (key[FIRST] !== '/' && key[SECOND] !== '/') {
70
+ if (isNumber(start[key])) result = `${result}export ${key}=${start[key]}\n`;
71
+ else if (isObject(start[key])) result = `${result}export ${key}='${JSON.stringify(start[key])}'\n`;
57
72
  else result = `${result}export ${key}="${start[key]}"\n`;
58
73
  }
59
74
  });
@@ -65,7 +80,7 @@ const start2env = (start) => {
65
80
  const result = {};
66
81
 
67
82
  Object.keys(start).forEach((key) => {
68
- if (key[0] !== '/' && key[1] !== '/') {
83
+ if (key[FIRST] !== '/' && key[SECOND] !== '/') {
69
84
  result[key] = start[key];
70
85
  }
71
86
  });
@@ -74,7 +89,7 @@ const start2env = (start) => {
74
89
 
75
90
  /**
76
91
  *
77
- * Setup environment variables based on a json object.
92
+ * Setup environment variables based on a JSON object.
78
93
  *
79
94
  * @function start2process
80
95
  * @category sync
@@ -83,7 +98,7 @@ const start2env = (start) => {
83
98
  */
84
99
  const start2process = (start) => {
85
100
  Object.keys(start).forEach((key) => {
86
- if (key[0] !== '/' && key[1] !== '/') {
101
+ if (key[FIRST] !== '/' && key[SECOND] !== '/') {
87
102
  process.env[key] = start[key];
88
103
  }
89
104
  });
@@ -109,20 +124,21 @@ const baseUrl = (serverType, regType, config, literal) => {
109
124
  * @category sync
110
125
  * @params {string} regType - Type of registration to be excuted.
111
126
  * @params {PATH<string>} filename - Filename to retrieve. If the filename does not retrieve any file altFilename will be used.
112
- * @params options {object} - options to be added for the retrieval
127
+ * @params options {object} - Options to be added for the retrieval
113
128
  * @return {object} The JSON object contained in the file.
114
129
  *
115
- * The options paramters has the folowing structure:
130
+ * The options parameters has the folowing structure:
116
131
  *``` javascript
117
132
  * {
118
133
  * sourceFilename: {PATH<string>}, // Source filename to use if altFilename does not retrieve any file.
119
- * sourceFilenameSupp: {PATH<string}, // Source filename supplementatry to by use with source filename.
134
+ * sourceFilenameSupp: {PATH<string}, // Source filename supplementary to use with source filename.
120
135
  * altFilename: {PATH<string>}, // Alternate filename to use if filename does not retrieve any file.
121
136
  * default: {object}, // default content if no file exist
122
137
  * }
123
138
  *````
124
139
  * Will exit 1 if there is an error.
125
- * Source filename supp is only used when source filename exist. If environement variables between source filename and source filename supplementatry exist the environement variable in source filename will be commented out.
140
+ * sourceFilenameSupp is only used when sourceFilename exists.
141
+ * If an environment variables exists in sourceFilename and sourceFilenameSupp, the environment variable in sourceFilename will be commented out.
126
142
  *
127
143
  */
128
144
  const retrieve = (regType, filename, options) => {
@@ -136,13 +152,13 @@ const retrieve = (regType, filename, options) => {
136
152
 
137
153
  Object.keys(parsedFileSupp).forEach((key) => {
138
154
  if (keysParsedFile.includes(key)) {
139
- const regex = new RegExp(`\n[ \t]+"${key}"`);
155
+ const regex = new RegExp(`\n[ \t]+"${key}"`, 'u');
140
156
 
141
157
  rawFile = rawFile.replace(regex, `\n// "${key}"`);
142
158
  }
143
159
  });
144
- rawFile = rawFile.substring(0, rawFile.length - 2);
145
- rawFileSupp = rawFileSupp.substring(1);
160
+ rawFile = rawFile.substring(START, rawFile.length - EXT);
161
+ rawFileSupp = rawFileSupp.substring(SUB);
146
162
  return `${rawFile},\n//-- test\n${rawFileSupp}`;
147
163
  };
148
164
 
@@ -151,8 +167,11 @@ const retrieve = (regType, filename, options) => {
151
167
  const readFile = parse(readFileRaw, fname, regType);
152
168
 
153
169
  if (!fnameSupp) return readFile;
154
- try { readFileSuppRaw = read(fnameSupp, regType); }
170
+ try {
171
+ readFileSuppRaw = read(fnameSupp, regType);
172
+ }
155
173
  catch (errFnameSupp) {
174
+ console.log('- no supplementary: ' + errFnameSupp.info);
156
175
  return readFile;
157
176
  }
158
177
 
@@ -163,8 +182,8 @@ const retrieve = (regType, filename, options) => {
163
182
  try {
164
183
  const readFile = readMerge(fSource, fSourceSupp);
165
184
 
166
- if (!fSourceSupp) console.log('- using ' + fSource.warn + ' for ' + fname.info);
167
- else console.log('- using ' + fSource.warn + ' + ' + fSourceSupp.warn + ' for ' + fname.info);
185
+ if (fSourceSupp) console.log('- using ' + fSource.warn + ' + ' + fSourceSupp.warn + ' for ' + fname.info);
186
+ else console.log('- using ' + fSource.warn + ' for ' + fname.info);
168
187
  return readFile;
169
188
  }
170
189
  catch (err) {
@@ -205,7 +224,7 @@ const retrieve = (regType, filename, options) => {
205
224
  }
206
225
  };
207
226
 
208
- module.exports = {
227
+ export {
209
228
  colors,
210
229
  start2shell,
211
230
  start2env,
@@ -1,7 +1,6 @@
1
- const axios = require('axios');
2
- const http = require('http');
3
-
4
- const { correlationId, userAgent } = require('./common');
1
+ import { correlationId, userAgent } from './common.js';
2
+ import axios from 'axios';
3
+ import http from 'http';
5
4
 
6
5
  const rp = (origOptions) => {
7
6
  const options = origOptions;
@@ -47,6 +46,6 @@ const rp = (origOptions) => {
47
46
  });
48
47
  };
49
48
 
50
- module.exports = {
49
+ export {
51
50
  rp,
52
51
  };
package/lib/tasks.js CHANGED
@@ -1,75 +1,86 @@
1
- /* eslint-disable prefer-template, no-console */
2
- const fs = require('fs');
3
- const json = require('comment-json');
4
- const path = require('path');
5
- const Promise = require('bluebird');
6
- const uuid = require('uuid');
7
- const _ = require('lodash');
8
- const yaml = require('js-yaml');
9
- const SwaggerClient = require('swagger-client');
10
- const { Base64 } = require('js-base64');
11
-
12
- const { rp } = require('./rp-axios-wrapper');
13
- const { getAllTargets } = require('./commonExt');
14
- const {
15
- sumoLogFile,
16
- s3LogFile,
17
- kinesisLogFile,
18
- locationFile,
19
- keyFile,
20
- packageFile,
21
- customerConfigFile,
22
- testStartFile,
23
- exampleStartFile,
24
- exampleTestStartFile,
25
- startFile,
26
- mSTConfigFile,
27
- mITConfigFile,
28
- mIDConfigFile,
29
- ERR_CHECK,
30
- SUCCESS_CHECK,
31
- POSTFIX,
32
- API_SOURCE,
33
- SWAGGER,
34
- API_PROVIDER_SWAGGERHUB,
1
+ /* eslint-disable prefer-template, no-console, camelcase */
2
+ import {
3
+ ALL,
4
+ ALL_MODES,
35
5
  API_PROVIDER_BITBUCKET,
36
- SWAGGERHUB,
6
+ API_PROVIDER_SWAGGERHUB,
7
+ API_SOURCE,
8
+ AWS_KINESIS,
9
+ AWS_S3,
37
10
  BITBUCKET,
38
- RESOLVED,
39
- EXTENSION_YML,
40
- LITERAL,
41
- DEFAULT_SUMOLOG,
42
- DEFAULT_S3LOG,
43
- DEFAULT_KINESISLOG,
11
+ DEFAULT_BITBUCKET_PASSWORD,
12
+ DEFAULT_BITBUCKET_USERNAME,
44
13
  DEFAULT_KEY,
14
+ DEFAULT_KINESISLOG,
45
15
  DEFAULT_LOCATION,
46
- DEFAULT_MST,
47
- DEFAULT_MIT,
48
16
  DEFAULT_MID,
49
- DUMMY_MST,
50
- DUMMY_MIT,
17
+ DEFAULT_MIT,
18
+ DEFAULT_MST,
19
+ DEFAULT_S3LOG,
20
+ DEFAULT_SUMOLOG,
51
21
  DUMMY_MID,
52
- AWS_S3,
53
- AWS_KINESIS,
54
- SUMOLOGIC,
55
- ALL,
22
+ DUMMY_MIT,
23
+ DUMMY_MST,
24
+ ERR_CHECK,
25
+ EXTENSION_YML,
26
+ IDENTITY_SERVICE,
27
+ IT_REGISTRY,
28
+ LITERAL,
56
29
  NONE,
57
- ALL_MODES,
30
+ POSTFIX,
31
+ RESOLVED,
32
+ SUCCESS_CHECK,
33
+ SUMOLOGIC,
34
+ SWAGGER,
35
+ SWAGGERHUB,
58
36
  SWAGGER_SEP,
59
37
  SYSTEM_NAME,
60
- IT_REGISTRY,
61
- TOKEN_SERVICE,
62
- IDENTITY_SERVICE,
63
38
  TEST,
64
- DEFAULT_BITBUCKET_USERNAME,
65
- DEFAULT_BITBUCKET_PASSWORD,
66
- } = require('./common');
67
- const {
68
- exitError,
69
- setDomainName,
39
+ TOKEN_SERVICE,
40
+ customerConfigFile,
41
+ exampleStartFile,
42
+ exampleTestStartFile,
43
+ keyFile,
44
+ kinesisLogFile,
45
+ locationFile,
46
+ mIDConfigFile,
47
+ mITConfigFile,
48
+ mSTConfigFile,
49
+ packageFile,
50
+ s3LogFile,
51
+ startFile,
52
+ sumoLogFile,
53
+ testStartFile,
54
+ } from './common.js';
55
+ import {
70
56
  baseUrl,
57
+ exitError,
71
58
  retrieve,
72
- } = require('./helpers');
59
+ setDomainName,
60
+ } from './helpers.js';
61
+ import { Base64 } from 'js-base64';
62
+ import Promise from 'bluebird';
63
+ import SwaggerClient from 'swagger-client';
64
+ import clone from 'lodash.clone';
65
+ import difference from 'lodash.difference';
66
+ import fs from 'fs';
67
+ import { getAllTargets } from './commonExt.js';
68
+ import isEmpty from 'lodash.isempty';
69
+ import { join } from 'path';
70
+ import json from 'comment-json';
71
+ import { load } from 'js-yaml';
72
+ import process from 'process';
73
+ import { rp } from './rp-axios-wrapper.js';
74
+ import split from 'lodash.split';
75
+ import trim from 'lodash.trim';
76
+ import { v4 as uuidv4 } from 'uuid';
77
+
78
+ const EMPTY = 0;
79
+ const NOT_FOUND_ERROR = 404;
80
+ const CONFLICT_ERROR = 409;
81
+ const DUPLICATE = 1;
82
+ const TAB = 2;
83
+ const FIRST = 0;
73
84
 
74
85
  const getStartParams = (confType) => {
75
86
  let regType = 'Local configuration setup ';
@@ -135,7 +146,7 @@ const init = (regType, standAlone, isMSTSet) => {
135
146
  };
136
147
 
137
148
  const startSetup = (config, origStart) => {
138
- const start = _.clone(origStart);
149
+ const start = clone(origStart);
139
150
  const { regType } = config;
140
151
  const { type } = config.pack.mimik;
141
152
  // basic check
@@ -150,10 +161,10 @@ const startSetup = (config, origStart) => {
150
161
  let logMode = null;
151
162
 
152
163
  if (start.LOG_MODE) {
153
- logMode = _.split(_.trim(start.LOG_MODE), /\s*,\s*/);
154
- if (logMode.length === 0) exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
155
- if (_.difference(logMode, ALL_MODES).length !== 0) exitError(regType, `Invalid items in LOG_MODE: ${logMode}`);
156
- if (logMode.includes(NONE) && logMode.length !== 1) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
164
+ logMode = split(trim(start.LOG_MODE), /\s*,\s*/u);
165
+ if (logMode.length === EMPTY) exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
166
+ if (difference(logMode, ALL_MODES).length !== EMPTY) exitError(regType, `Invalid items in LOG_MODE: ${logMode}`);
167
+ if (logMode.includes(NONE) && logMode.length !== DUPLICATE) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
157
168
  if (logMode.includes(ALL)) logMode = [SUMOLOGIC, AWS_S3]; // legacy support
158
169
  }
159
170
  if (!logMode || logMode.includes(SUMOLOGIC)) {
@@ -164,33 +175,33 @@ const startSetup = (config, origStart) => {
164
175
  console.log('- using ' + 'default value'.warn + ' for sumologic');
165
176
  sumoLog = config.sumoLog.default;
166
177
  }
167
- start.SUMO_LOGIC_ENDPOINT = start.SUMO_LOGIC_ENDPOINT || sumoLog.url;
168
- start.SUMO_LOGIC_COLLECTOR_CODE = start.SUMO_LOGIC_COLLECTOR_CODE || sumoLog.code;
178
+ start.SUMO_LOGIC_ENDPOINT ||= sumoLog.url;
179
+ start.SUMO_LOGIC_COLLECTOR_CODE ||= sumoLog.code;
169
180
  }
170
181
  if (logMode && logMode.includes(AWS_S3)) {
171
182
  const { s3Log } = config;
172
183
 
173
- start.S3_AWS_ACCESS_KEY_ID = start.S3_AWS_ACCESS_KEY_ID || s3Log.accessKeyId;
174
- start.S3_AWS_REGION = start.S3_AWS_REGION || s3Log.region;
175
- start.S3_AWS_SECRET_ACCESS_KEY = start.S3_AWS_SECRET_ACCESS_KEY || s3Log.secretAccessKey;
176
- start.S3_AWS_BUCKET_NAME = start.S3_AWS_BUCKET_NAME || s3Log.bucketname;
177
- start.S3_AWS_MAX_EVENTS = start.S3_AWS_MAX_EVENTS || s3Log.maxEvents;
178
- start.S3_AWS_TIMEOUT = start.S3_AWS_TIMEOUT || s3Log.timeout;
179
- start.S3_AWS_MAX_SIZE = start.S3_AWS_MAX_SIZE || s3Log.maxSize;
184
+ start.S3_AWS_ACCESS_KEY_ID ||= s3Log.accessKeyId;
185
+ start.S3_AWS_REGION ||= s3Log.region;
186
+ start.S3_AWS_SECRET_ACCESS_KEY ||= s3Log.secretAccessKey;
187
+ start.S3_AWS_BUCKET_NAME ||= s3Log.bucketname;
188
+ start.S3_AWS_MAX_EVENTS ||= s3Log.maxEvents;
189
+ start.S3_AWS_TIMEOUT ||= s3Log.timeout;
190
+ start.S3_AWS_MAX_SIZE ||= s3Log.maxSize;
180
191
  }
181
192
  if (logMode && logMode.includes(AWS_KINESIS)) {
182
193
  const { kinesisLog } = config;
183
194
 
184
- start.KINESIS_AWS_ACCESS_KEY_ID = start.KINESIS_AWS_ACCESS_KEY_ID || kinesisLog.accessKeyId;
185
- start.KINESIS_AWS_REGION = start.KINESIS_AWS_REGION || kinesisLog.region;
186
- start.KINESIS_AWS_SECRET_ACCESS_KEY = start.KINESIS_AWS_SECRET_ACCESS_KEY || kinesisLog.secretAccessKey;
187
- start.KINESIS_AWS_STREAM_NAME_INFO = start.KINESIS_AWS_STREAM_NAME_INFO || kinesisLog.streamNameInfo;
188
- start.KINESIS_AWS_STREAM_NAME_ERROR = start.KINESIS_AWS_STREAM_NAME_ERROR || kinesisLog.streamNameError;
189
- start.KINESIS_AWS_STREAM_NAME_OTHER = start.KINESIS_AWS_STREAM_NAME_OTHER || kinesisLog.streamNameOther;
195
+ start.KINESIS_AWS_ACCESS_KEY_ID ||= kinesisLog.accessKeyId;
196
+ start.KINESIS_AWS_REGION ||= kinesisLog.region;
197
+ start.KINESIS_AWS_SECRET_ACCESS_KEY ||= kinesisLog.secretAccessKey;
198
+ start.KINESIS_AWS_STREAM_NAME_INFO ||= kinesisLog.streamNameInfo;
199
+ start.KINESIS_AWS_STREAM_NAME_ERROR ||= kinesisLog.streamNameError;
200
+ start.KINESIS_AWS_STREAM_NAME_OTHER ||= kinesisLog.streamNameOther;
190
201
  }
191
202
  // server basics
192
203
  start.SERVER_TYPE = type;
193
- start.SERVER_ID = start.SERVER_ID || uuid.v4();
204
+ start.SERVER_ID ||= uuidv4();
194
205
  // api access
195
206
  start.BITBUCKET_USERNAME = config.key.username;
196
207
  start.BITBUCKET_PASSWORD = config.key.password;
@@ -263,7 +274,7 @@ const startSetup = (config, origStart) => {
263
274
  * @fulfil {object} The API file itself.
264
275
  * @throws {Promise} An error containing the reason of the failure.
265
276
  *
266
- * The directory will be created if it does not exist.
277
+ * The directory will be created, if it does not exist.
267
278
  */
268
279
  const getAPI = (directory, swaggerFile, key) => {
269
280
  const {
@@ -272,7 +283,7 @@ const getAPI = (directory, swaggerFile, key) => {
272
283
  version,
273
284
  provider,
274
285
  } = swaggerFile;
275
- const swaggerOptions = (spec) => ({
286
+ const swaggerOptions = spec => ({
276
287
  spec,
277
288
  allowMetaPatches: false,
278
289
  skipNormalization: true,
@@ -280,7 +291,7 @@ const getAPI = (directory, swaggerFile, key) => {
280
291
  });
281
292
 
282
293
  process.stdout.write('- getting API definition in (' + directory.info + ')');
283
- const apiFilename = path.join(directory, `${account}${SWAGGER_SEP}${name}${SWAGGER_SEP}${version}${SWAGGER_SEP}${POSTFIX}`);
294
+ const apiFilename = join(directory, `${account}${SWAGGER_SEP}${name}${SWAGGER_SEP}${version}${SWAGGER_SEP}${POSTFIX}`);
284
295
  let apiDefinition;
285
296
 
286
297
  try {
@@ -294,7 +305,9 @@ const getAPI = (directory, swaggerFile, key) => {
294
305
  return Promise.reject(err);
295
306
  }
296
307
  if (apiDefinition) {
297
- try { apiDefinition = json.parse(apiDefinition); }
308
+ try {
309
+ apiDefinition = json.parse(apiDefinition);
310
+ }
298
311
  catch (err) {
299
312
  console.log(ERR_CHECK.error);
300
313
  return Promise.reject(err);
@@ -305,10 +318,10 @@ const getAPI = (directory, swaggerFile, key) => {
305
318
  throw err;
306
319
  })
307
320
  .then((apiDefinitionResult) => {
308
- if (apiDefinitionResult.errors.length !== 0) {
321
+ if (apiDefinitionResult.errors.length !== EMPTY) {
309
322
  throw new Error('Errors while resolving definition');
310
323
  }
311
- fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
324
+ fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, TAB));
312
325
  console.log(' ' + SUCCESS_CHECK.success);
313
326
  return apiDefinitionResult.spec;
314
327
  })
@@ -367,14 +380,14 @@ const getAPI = (directory, swaggerFile, key) => {
367
380
  .then((result) => {
368
381
  let resultJSON = result;
369
382
 
370
- if (typeof result !== 'object') resultJSON = yaml.load(result);
383
+ if (typeof result !== 'object') resultJSON = load(result);
371
384
  return SwaggerClient.resolve(swaggerOptions(resultJSON));
372
385
  })
373
386
  .then((apiDefinitionResult) => {
374
- if (apiDefinitionResult.errors.length !== 0) {
387
+ if (apiDefinitionResult.errors.length !== EMPTY) {
375
388
  throw new Error('errors while resolving definition');
376
389
  }
377
- fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
390
+ fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, TAB));
378
391
  console.log(SUCCESS_CHECK.success);
379
392
  return apiDefinitionResult.spec;
380
393
  })
@@ -415,7 +428,7 @@ const settingUpCustomer = (customer, authorization, mSTbaseUrl, update) => {
415
428
  url: `${mSTbaseUrl}/customers/${customer.name}`,
416
429
  })
417
430
  .catch((err) => {
418
- if (err.statusCode !== 404) {
431
+ if (err.statusCode !== NOT_FOUND_ERROR) {
419
432
  console.log(ERR_CHECK.error);
420
433
  throw err;
421
434
  }
@@ -481,7 +494,7 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
481
494
  // oauth
482
495
  updatedStart.OAUTH_CLIENT_ID = `${client.id}`;
483
496
  updatedStart.OAUTH_CLIENT_SECRET = `${client.secret}`;
484
- if (_.isEmpty(client.accessKeyPair) || !client.accessKeyPair.publicKey) updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKey}`;
497
+ if (isEmpty(client.accessKeyPair) || !client.accessKeyPair.publicKey) updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKey}`;
485
498
  else updatedStart.OAUTH_CLIENT_ACCESS_KEY = `${client.accessKeyPair.publicKey}`;
486
499
  updatedStart.OAUTH_CLIENT_AUDIENCE = `${client.audience}`;
487
500
  // generic
@@ -504,16 +517,16 @@ const settingUpDummyServer = (serverType, serverId, customer, origStart) => {
504
517
 
505
518
  updatedStart.OAUTH_GENERIC_KEY = 'a-secret-key-for-generic';
506
519
  updatedStart.OAUTH_GENERIC_AUDIENCE = `http://dummy-${serverType}-generic-audience`;
507
- if (!customer) { // mIT case
508
- updatedStart[`${serverType.toUpperCase()}_URL`] = `http://dummy-${serverType}/dummy`;
509
- updatedStart[`${serverType.toUpperCase()}_AUDIENCE`] = `http://dummy-${serverType}-audience`;
510
- }
511
- else {
520
+ if (customer) {
512
521
  getAllTargets(serverType, customer.config).forEach((target) => {
513
522
  updatedStart[`${target.type.toUpperCase()}_URL`] = `http://dummy-${target.type}/dummy`;
514
523
  updatedStart[`${target.type.toUpperCase()}_AUDIENCE`] = `http://dummy-${target.type}-audience`;
515
524
  });
516
525
  }
526
+ else { // mIT case
527
+ updatedStart[`${serverType.toUpperCase()}_URL`] = `http://dummy-${serverType}/dummy`;
528
+ updatedStart[`${serverType.toUpperCase()}_AUDIENCE`] = `http://dummy-${serverType}-audience`;
529
+ }
517
530
  console.log(SUCCESS_CHECK.success);
518
531
  return updatedStart;
519
532
  };
@@ -533,7 +546,7 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
533
546
  console.log(SUCCESS_CHECK.success);
534
547
  return resultPOST;
535
548
  }).catch((err) => {
536
- if (err.statusCode !== 409) {
549
+ if (err.statusCode !== CONFLICT_ERROR) {
537
550
  console.log(ERR_CHECK.error);
538
551
  throw err;
539
552
  }
@@ -567,7 +580,7 @@ const getAdminToken = (audienceType, admin, mSTbaseUrl) => {
567
580
  data: {
568
581
  client_id: admin.id,
569
582
  client_secret: admin.secret,
570
- audience: `${audienceType.audience.split('Generic-')[0]}Generic-${audienceType.type}`,
583
+ audience: `${audienceType.audience.split('Generic-')[FIRST]}Generic-${audienceType.type}`,
571
584
  grant_type: 'client_credentials',
572
585
  },
573
586
  }).catch((err) => {
@@ -579,7 +592,7 @@ const getAdminToken = (audienceType, admin, mSTbaseUrl) => {
579
592
  });
580
593
  };
581
594
 
582
- module.exports = {
595
+ export {
583
596
  getStartParams,
584
597
  init,
585
598
  startSetup,
@@ -1,3 +1,3 @@
1
- const start = require('../index');
1
+ import start from '../index.js';
2
2
 
3
3
  start.getAPI('./testing', 'mimik', 'mDS', '1.1.1');
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-console */
2
- const { retrieve } = require('../lib/helpers');
2
+ import { retrieve } from '../lib/helpers.js';
3
3
 
4
4
  // console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json', sourceFilenameSupp: 'startTest-example.json' } ));
5
5
 
@@ -1,7 +1,8 @@
1
- /* eslint-disable prefer-template, no-console, no-process-env */
2
- const colors = require('colors');
3
- const fs = require('fs');
4
- const json = require('comment-json');
1
+ /* eslint-disable prefer-template, no-console */
2
+ import colors from 'colors';
3
+ import fs from 'fs';
4
+ import json from 'comment-json';
5
+ import process from 'process';
5
6
 
6
7
  colors.setTheme({
7
8
  success: 'green',
@@ -10,20 +11,29 @@ colors.setTheme({
10
11
  info: ['grey', 'bold'],
11
12
  });
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
+
13
21
  const exitError = (regType, error, filename) => {
14
- let details = `{ statusCode: ${error.statusCode || 500}, message: ${error.message || error}`;
22
+ let details = `{ statusCode: ${error.statusCode || SYSTEM_ERROR}, message: ${error.message || error}`;
15
23
 
16
24
  if (filename) details = `, ${details}, filename: ${filename}`;
17
25
  details = `${details} }`;
18
26
  console.error(`${regType}status: ` + 'error'.error + ', ' + details.info);
19
- process.exit(1);
27
+ process.exit(EXIT_ERROR);
20
28
  };
21
29
 
22
30
  const regType = 'test';
23
31
 
24
32
  const readMerge = (fname, fnameSupp) => {
25
33
  const parse = (rawFile, rawFilename) => {
26
- try { return json.parse(rawFile); }
34
+ try {
35
+ return json.parse(rawFile);
36
+ }
27
37
  catch (errParse) {
28
38
  return exitError(regType, errParse, rawFilename);
29
39
  }
@@ -36,27 +46,31 @@ const readMerge = (fname, fnameSupp) => {
36
46
 
37
47
  Object.keys(parsedFileSupp).forEach((key) => {
38
48
  if (keysParsedFile.includes(key)) {
39
- const regex = new RegExp(`\n[ \t]+"${key}"`);
49
+ const regex = new RegExp(`\n[ \t]+"${key}"`, 'u');
40
50
 
41
51
  rawFile = rawFile.replace(regex, `\n// "${key}"`);
42
52
  }
43
53
  });
44
- rawFile = rawFile.substring(0, rawFile.length - 2);
45
- rawFileSupp = rawFileSupp.substring(1);
54
+ rawFile = rawFile.substring(START, rawFile.length - EXT);
55
+ rawFileSupp = rawFileSupp.substring(SUB);
46
56
  return `${rawFile},\n//-- test\n${rawFileSupp}`;
47
57
  };
48
58
 
49
59
  let readFileRaw;
50
60
  let readFileSuppRaw;
51
61
 
52
- try { readFileRaw = fs.readFileSync(fname).toString(); }
62
+ try {
63
+ readFileRaw = fs.readFileSync(fname).toString();
64
+ }
53
65
  catch (errFname) {
54
66
  if (errFname.code !== 'ENOENT') exitError(regType, errFname, fname);
55
67
  throw errFname;
56
68
  }
57
69
  const readFile = parse(readFileRaw, fname);
58
70
 
59
- try { readFileSuppRaw = fs.readFileSync(fnameSupp).toString(); }
71
+ try {
72
+ readFileSuppRaw = fs.readFileSync(fnameSupp).toString();
73
+ }
60
74
  catch (errFnameSupp) {
61
75
  if (errFnameSupp.code !== 'ENOENT') exitError(regType, errFnameSupp, fnameSupp);
62
76
  return readFile;
@@ -65,4 +79,4 @@ const readMerge = (fname, fnameSupp) => {
65
79
  return parse(merge(readFileRaw, readFile, readFileSuppRaw, parse(readFileSuppRaw, fnameSupp)), `${fname} + ${fnameSupp}`);
66
80
  };
67
81
 
68
- console.log(json.stringify(readMerge('../../../mst-2297/local/start-example.json', '../../../mst-2297/local/startTest-example.json'), null, 2));
82
+ console.log(json.stringify(readMerge('../../../mst-2297/local/start-example.json', '../../../mst-2297/local/startTest-example.json'), null, TAB));
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable no-console */
2
- const _ = require('lodash');
2
+ import split from 'lodash.split';
3
+ import trim from 'lodash.trim';
3
4
 
4
5
  const test = ' a, b ,c,d ';
5
6
  const allTest = 'all ';
6
7
 
7
- console.log(_.split(_.trim(test), /\s*,\s*/));
8
- console.log(_.split(_.trim(allTest), /\s*,\s*/));
8
+ console.log(split(trim(test), /\s*,\s*/u));
9
+ console.log(split(trim(allTest), /\s*,\s*/u));