@mimik/configuration 5.0.11 → 5.0.12

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
@@ -161,8 +161,6 @@ When `mongodb` is used the following environment variables are used for the conf
161
161
  | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
162
162
  | MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | no mandatory
163
163
  | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
164
- | MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
165
- | MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
166
164
  | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
167
165
  | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
168
166
  | MONGO_SERVER_SELECTION_TIMEOUT | the MongoDB driver will try to find a server to send any given operation to, and keep retrying for serverSelectionTimeoutMS milliseconds | 30000 | in milliseconds
package/index.js CHANGED
@@ -1,5 +1,11 @@
1
1
  /* eslint no-process-env: "off" */
2
- const _ = require('lodash');
2
+ const includes = require('lodash.includes');
3
+ const isNaN = require('lodash.isnan');
4
+ const isNil = require('lodash.isnil');
5
+ const isString = require('lodash.isstring');
6
+ const isUndefined = require('lodash.isundefined');
7
+ const split = require('lodash.split');
8
+ const trim = require('lodash.trim');
3
9
  const fs = require('fs');
4
10
  const ip = require('ip');
5
11
  const uuid = require('uuid');
@@ -56,8 +62,6 @@ const {
56
62
  DEFAULT_MONGO_MAX_POOL_SIZE,
57
63
  DEFAULT_MONGO_MIN_POOL_SIZE,
58
64
  DEFAULT_MONGO_MAX_IDLE_TIME,
59
- DEFAULT_MONGO_KEEP_ALIVE,
60
- DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
61
65
  DEFAULT_MONGO_SOCKET_TIMEOUT,
62
66
  DEFAULT_MONGO_FAMILY,
63
67
  DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
@@ -94,6 +98,8 @@ const {
94
98
  DEFAULT_INTERCEPT_ERROR,
95
99
  DEFAULT_BITBUCKET_USERNAME,
96
100
  DEFAULT_BITBUCKET_PASSWORD,
101
+ YES,
102
+ NO,
97
103
  } = require('./lib/common');
98
104
 
99
105
  let display = true;
@@ -145,7 +151,7 @@ const setupRedis = () => {
145
151
  }
146
152
  return undefined;
147
153
  },
148
- disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === 'yes') || DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
154
+ disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === YES) || DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
149
155
  },
150
156
  maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || DEFAULT_REDIS_REQUEST_MAX_MEMORY,
151
157
  maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
@@ -181,17 +187,17 @@ const setupDynamo = (dbOpts) => {
181
187
  },
182
188
  tableName: dbOpts.table,
183
189
  };
184
- if (!_.isNil(process.env.DYNAMODB_AWS_ACCESS_KEY_ID)) dbConfig.accessKeyId = process.env.DYNAMODB_AWS_ACCESS_KEY_ID;
185
- if (!_.isNil(process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY)) dbConfig.secretAccessKey = process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY;
190
+ if (!isNil(process.env.DYNAMODB_AWS_ACCESS_KEY_ID)) dbConfig.accessKeyId = process.env.DYNAMODB_AWS_ACCESS_KEY_ID;
191
+ if (!isNil(process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY)) dbConfig.secretAccessKey = process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY;
186
192
 
187
193
  if (process.env.DYNAMO_SCHEMA_THROUGHPUT === 'ON_DEMAND') {
188
194
  dbConfig.schemaThroughput = process.env.DYNAMO_SCHEMA_THROUGHPUT;
189
195
  delete dbConfig.throughput;
190
196
  }
191
- else if (!_.isNil(process.env.DYNAMO_SCHEMA_THROUGHPUT)) {
197
+ else if (!isNil(process.env.DYNAMO_SCHEMA_THROUGHPUT)) {
192
198
  const throughput = parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT, 10);
193
199
 
194
- if (_.isNil(throughput) || _.isNaN(throughput)) dbConfig.schemaThroughput = DEFAULT_DYNAMO_THROUGHPUT;
200
+ if (isNil(throughput) || isNaN(throughput)) dbConfig.schemaThroughput = DEFAULT_DYNAMO_THROUGHPUT;
195
201
  else dbConfig.schemaThroughput = throughput;
196
202
  }
197
203
  return dbConfig;
@@ -206,9 +212,9 @@ const setupMongo = (dbOpts) => {
206
212
  maxIdleTimeMS: parseInt(process.env.MONGO_MAX_IDLE_TIME, 10) || DEFAULT_MONGO_MAX_IDLE_TIME,
207
213
  };
208
214
  // string variables without default
209
- if (process.env.MONGO_SSL === 'yes') stringOptions.ssl = true; // default value of mongo driver is false
210
- if (process.env.MONGO_SSL_VALIDATE === 'no') stringOptions.sslValidate = false; // default value of mongo driver is true, if ssl is true
211
- if (process.env.MONGO_SSL_ALLOW_INVALID_HOSTNAMES === 'yes') stringOptions.allowInvalidHostnames = true;
215
+ if (process.env.MONGO_SSL === YES) stringOptions.ssl = true; // default value of mongo driver is false
216
+ if (process.env.MONGO_SSL_VALIDATE === NO) stringOptions.sslValidate = false; // default value of mongo driver is true, if ssl is true
217
+ if (process.env.MONGO_SSL_ALLOW_INVALID_HOSTNAMES === YES) stringOptions.allowInvalidHostnames = true;
212
218
  // if (process.env.MONGO_SSL_CA) stringOptions.sslCA = process.env.MONGO_SSL_CA; // commented out for now as we're not using a pem file at the moment
213
219
  if (process.env.MONGO_REPLICAT_SET) stringOptions.replicaSet = process.env.MONGO_REPLICAT_SET;
214
220
  if (process.env.MONGO_AUTH_DATABASE) stringOptions.authSource = process.env.MONGO_AUTH_DATABASE;
@@ -226,7 +232,7 @@ const setupMongo = (dbOpts) => {
226
232
  const user = process.env.DATABASE_USER || DEFAULT_DATABASE_USER;
227
233
  const password = process.env.DATABASE_PASSWORD || DEFAULT_DATABASE_PASSWORD;
228
234
  const qs = processStringOptions();
229
- let url = (process.env.MONGO_USE_SRV === 'yes') ? MONGO_BASE_URL_SRV : MONGO_BASE_URL;
235
+ let url = (process.env.MONGO_USE_SRV === YES) ? MONGO_BASE_URL_SRV : MONGO_BASE_URL;
230
236
  let noAuthUrl = url;
231
237
 
232
238
  if (user && password) url = `${url}${user}:${password}@`;
@@ -251,8 +257,6 @@ const setupMongo = (dbOpts) => {
251
257
  noAuthUrl,
252
258
  options: {
253
259
  family: parseInt(process.env.MONGO_FAMILY, 10) || DEFAULT_MONGO_FAMILY,
254
- keepAlive: process.env.MONGO_KEEP_ALIVE || DEFAULT_MONGO_KEEP_ALIVE,
255
- keepAliveInitialDelay: parseInt(process.env.MONGO_KEEP_ALIVE_INITIAL_DELAY, 10) || DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
256
260
  socketTimeoutMS: parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || DEFAULT_MONGO_SOCKET_TIMEOUT,
257
261
  serverSelectionTimeoutMS: parseInt(process.env.MONGO_SERVER_SELECTION_TIMEOUT, 10) || DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
258
262
  heartbeatFrequencyMS: parseInt(process.env.MONGO_HEARTBEAT_FREQUENCY, 10) || DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
@@ -264,7 +268,7 @@ const setupLocationProvider = () => {
264
268
  const url = process.env.LOCATION_PROVIDER;
265
269
 
266
270
  if (!url) return NO_PUBLIC_PROVIDER;
267
- if (_.includes(locParams, url)) return url;
271
+ if (includes(locParams, url)) return url;
268
272
  const locationProvider = { url };
269
273
 
270
274
  if (process.env.LOCATION_PROVIDER_KEY) locationProvider.key = process.env.LOCATION_PROVIDER_KEY;
@@ -297,8 +301,8 @@ const setupLog = () => {
297
301
  maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) || DEFAULT_S3_AWS_MAX_SIZE,
298
302
  maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) || DEFAULT_S3_AWS_MAX_EVENTS,
299
303
  };
300
- if (!_.isNil(process.env.S3_AWS_ACCESS_KEY_ID)) logInfo[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
301
- if (!_.isNil(process.env.S3_AWS_SECRET_ACCESS_KEY)) logInfo[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
304
+ if (!isNil(process.env.S3_AWS_ACCESS_KEY_ID)) logInfo[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
305
+ if (!isNil(process.env.S3_AWS_SECRET_ACCESS_KEY)) logInfo[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
302
306
  }
303
307
  return logInfo;
304
308
  };
@@ -307,13 +311,13 @@ const setupTopic = (topicOpts) => {
307
311
  const topicConfig = {
308
312
  region: process.env.SNS_AWS_REGION || DEFAULT_AWS_REGION,
309
313
  name: topicOpts.name,
310
- isFifoTopic: process.env.SET_SNS_TOPIC_FIFO === 'yes',
314
+ isFifoTopic: process.env.SET_SNS_TOPIC_FIFO === YES,
311
315
  contentBasedDeduplication: false,
312
316
  };
313
317
 
314
- if (topicConfig.isFifoTopic) topicConfig.contentBasedDeduplication = process.env.SET_SNS_CONTENT_DEDUPLICATION === 'yes';
315
- if (!_.isNil(process.env.SNS_AWS_ACCESS_KEY_ID)) topicConfig.accessKeyId = process.env.SNS_AWS_ACCESS_KEY_ID;
316
- if (!_.isNil(process.env.SNS_AWS_SECRET_ACCESS_KEY)) topicConfig.secretAccessKey = process.env.SNS_AWS_SECRET_ACCESS_KEY;
318
+ if (topicConfig.isFifoTopic) topicConfig.contentBasedDeduplication = process.env.SET_SNS_CONTENT_DEDUPLICATION === YES;
319
+ if (!isNil(process.env.SNS_AWS_ACCESS_KEY_ID)) topicConfig.accessKeyId = process.env.SNS_AWS_ACCESS_KEY_ID;
320
+ if (!isNil(process.env.SNS_AWS_SECRET_ACCESS_KEY)) topicConfig.secretAccessKey = process.env.SNS_AWS_SECRET_ACCESS_KEY;
317
321
 
318
322
  return topicConfig;
319
323
  };
@@ -331,8 +335,8 @@ const setupEncryption = (encryptionOpts) => {
331
335
  encryptionConfig.region = process.env.MASTER_KEY_AWS_REGION || DEFAULT_AWS_REGION;
332
336
  encryptionConfig.masterKeyARN = process.env.MASTER_KEY_ARN;
333
337
 
334
- if (!_.isNil(process.env.ENCRYPTION_ACCESS_KEY_ID)) encryptionConfig.aws.accessKeyId = process.env.ENCRYPTION_ACCESS_KEY_ID;
335
- if (!_.isNil(process.env.ENCRYPTION_SECRET_ACCESS_KEY)) encryptionConfig.aws.secretAccessKey = process.env.ENCRYPTION_SECRET_ACCESS_KEY;
338
+ if (!isNil(process.env.ENCRYPTION_ACCESS_KEY_ID)) encryptionConfig.aws.accessKeyId = process.env.ENCRYPTION_ACCESS_KEY_ID;
339
+ if (!isNil(process.env.ENCRYPTION_SECRET_ACCESS_KEY)) encryptionConfig.aws.secretAccessKey = process.env.ENCRYPTION_SECRET_ACCESS_KEY;
336
340
  }
337
341
  else encryptionConfig.localMasterKey = process.env.LOCAL_MASTER_KEY;
338
342
 
@@ -365,7 +369,7 @@ const checkConfig = (config) => {
365
369
  if (typeof node[prop] === 'object' && node[prop]) {
366
370
  traverseNodeSync(node[prop], `${path}.${prop}`);
367
371
  }
368
- else if (_.isUndefined(node[prop])) errors.push({ reason: 'missing', value: `${path}.${prop}` });
372
+ else if (isUndefined(node[prop])) errors.push({ reason: 'missing', value: `${path}.${prop}` });
369
373
  });
370
374
  }
371
375
 
@@ -395,7 +399,7 @@ const checkConfig = (config) => {
395
399
  * | NODE_ENV | environnment of the microservice |
396
400
  */
397
401
  const isProd = () => {
398
- if (_.isString(process.env.NODE_ENV)) return _.includes(PRODUCTIONS, process.env.NODE_ENV.toLowerCase());
402
+ if (isString(process.env.NODE_ENV)) return includes(PRODUCTIONS, process.env.NODE_ENV.toLowerCase());
399
403
  return false;
400
404
  };
401
405
 
@@ -415,7 +419,7 @@ const configuration = {
415
419
  customerCodeSep: process.env.CUSTOMER_CODE ? CUSTOMER_CODE_SEP : '',
416
420
  securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
417
421
  isMSTSet,
418
- port: process.env.SERVER_PORT,
422
+ port: parseInt(process.env.SERVER_PORT, 10),
419
423
  interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
420
424
  ip: {
421
425
  local: process.env.SERVER_LOCAL_IPV4,
@@ -440,7 +444,7 @@ const configuration = {
440
444
  key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
441
445
  audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
442
446
  },
443
- apiKeys: process.env.API_KEYS ? _.split(_.trim(process.env.API_KEYS), /\s*,\s*/) : [],
447
+ apiKeys: process.env.API_KEYS ? split(trim(process.env.API_KEYS), /\s*,\s*/) : [],
444
448
  },
445
449
  cluster: {
446
450
  management: process.env.CLUSTER_MANAGEMENT || DEFAULT_CLUSTER_MANAGEMENT,
@@ -627,8 +631,6 @@ configuration.locationProvider = setupLocationProvider();
627
631
  * | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
628
632
  * | MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | no mandatory
629
633
  * | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
630
- * | MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
631
- * | MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
632
634
  * | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
633
635
  * | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
634
636
  * | MONGO_SERVER_SELECTION_TIMEOUT | the MongoDB driver will try to find a server to send any given operation to, and keep retrying for serverSelectionTimeoutMS milliseconds | 30000 | in milliseconds
package/lib/common.js CHANGED
@@ -1,3 +1,7 @@
1
+ const YES = 'yes';
2
+ const NO = 'no';
3
+ const LOCAL = 'local';
4
+
1
5
  const SUMOLOGIC = 'sumologic';
2
6
  const AWS_S3 = 'awsS3';
3
7
  const ALL = 'all';
@@ -15,7 +19,7 @@ const SWAGGER_SEP = '_';
15
19
  const CUSTOMER_CODE_SEP = '__';
16
20
  const PRODUCTIONS = ['prod', 'production'];
17
21
 
18
- const DEFAULT_ENV = 'local';
22
+ const DEFAULT_ENV = LOCAL;
19
23
  const DEFAULT_LOCATION_PROVIDER = NO_PUBLIC_PROVIDER;
20
24
  const DEFAULT_CLOUD_PROVIDER = 'noCloud';
21
25
  const DEFAULT_CUSTOMER_CODE = '';
@@ -46,8 +50,6 @@ const DEFAULT_DYNAMO_THROUGHPUT = 1;
46
50
  const DEFAULT_MONGO_MAX_POOL_SIZE = 10;
47
51
  const DEFAULT_MONGO_MIN_POOL_SIZE = 0;
48
52
  const DEFAULT_MONGO_MAX_IDLE_TIME = 30000; // in ms
49
- const DEFAULT_MONGO_KEEP_ALIVE = true;
50
- const DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY = 300000; // in ms
51
53
  const DEFAULT_MONGO_SOCKET_TIMEOUT = 20000; // in ms
52
54
  const DEFAULT_MONGO_FAMILY = 4; // 4 -> ipv4, 6 -> ipv6
53
55
  const DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT = 30000; // in ms
@@ -61,12 +63,12 @@ const DEFAULT_DATABASE_RECONNECTION_OFFSET = 5; // in seconds
61
63
  const DEFAULT_DATABASE_VALIDATION_CHECK = 1000; // in ms
62
64
 
63
65
  const DEFAULT_ENCRYPTION_SET = SET_OFF;
64
- const DEFAULT_KMS_PROVIDER = 'local';
66
+ const DEFAULT_KMS_PROVIDER = LOCAL;
65
67
 
66
68
  const DEFAULT_LOG_LEVEL = 'debug';
67
69
  const DEFAULT_FILTER_FILE = NOT_SET;
68
70
  const DEFAULT_EXIT_DELAY = 2000; // in ms
69
- const DEFAULT_NO_STACK = 'yes';
71
+ const DEFAULT_NO_STACK = YES;
70
72
 
71
73
  const DEFAULT_USER_DEFINITIONS_FILE = NOT_SET;
72
74
 
@@ -102,6 +104,8 @@ module.exports = {
102
104
  ALL,
103
105
  SET_ON,
104
106
  SET_OFF,
107
+ YES,
108
+ NO,
105
109
  CUSTOMER_CODE_SEP,
106
110
  NO_PUBLIC_PROVIDER,
107
111
  NO_GENERIC,
@@ -138,8 +142,6 @@ module.exports = {
138
142
  DEFAULT_MONGO_MAX_POOL_SIZE,
139
143
  DEFAULT_MONGO_MIN_POOL_SIZE,
140
144
  DEFAULT_MONGO_MAX_IDLE_TIME,
141
- DEFAULT_MONGO_KEEP_ALIVE,
142
- DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
143
145
  DEFAULT_MONGO_SOCKET_TIMEOUT,
144
146
  DEFAULT_MONGO_FAMILY,
145
147
  DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "5.0.11",
3
+ "version": "5.0.12",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,8 +9,7 @@
9
9
  "test": "echo \"Error: no test specified\" && exit 0",
10
10
  "test-ci": "echo \"Error: no test specified\" && exit 0",
11
11
  "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
12
- "commit-ready": "npm run docs && npm run lint && npm run test-ci",
13
- "prepare": "husky install"
12
+ "commit-ready": "npm run docs && npm run lint && npm run test-ci"
14
13
  },
15
14
  "husky": {
16
15
  "hooks": {
@@ -33,20 +32,26 @@
33
32
  "@mimik/request-helper": "^1.7.10",
34
33
  "@mimik/sumologic-winston-logger": "^1.6.20",
35
34
  "@mimik/user-filters": "^1.3.7",
36
- "ip": "2.0.0",
37
- "lodash": "4.17.21",
35
+ "ip": "2.0.1",
36
+ "lodash.includes": "4.3.0",
37
+ "lodash.isnan": "3.0.2",
38
+ "lodash.isnil": "4.0.0",
39
+ "lodash.isstring": "4.0.1",
40
+ "lodash.isundefined": "3.0.1",
41
+ "lodash.split": "4.4.2",
42
+ "lodash.trim": "4.5.1",
38
43
  "uuid": "9.0.1"
39
44
  },
40
45
  "devDependencies": {
41
46
  "@mimik/eslint-plugin-dependencies": "^2.4.6",
42
47
  "@mimik/eslint-plugin-document-env": "^1.0.6",
43
- "eslint": "8.56.0",
48
+ "eslint": "8.57.0",
44
49
  "eslint-config-airbnb": "19.0.4",
45
50
  "eslint-plugin-import": "2.29.1",
46
51
  "eslint-plugin-jsx-a11y": "6.8.0",
47
- "eslint-plugin-react": "7.33.2",
52
+ "eslint-plugin-react": "7.34.0",
48
53
  "eslint-plugin-react-hooks": "4.6.0",
49
- "husky": "8.0.3",
50
- "jsdoc-to-markdown": "8.0.0"
54
+ "husky": "9.0.11",
55
+ "jsdoc-to-markdown": "8.0.1"
51
56
  }
52
57
  }