@mimik/configuration 5.0.4 → 5.0.6

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
@@ -132,6 +132,12 @@ When `on` is used for `TOPIC_SET` the following environment variables are used f
132
132
  | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
133
133
  | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
134
134
 
135
+ When a database is involved
136
+ | Env variable name | Description | Default | Comments |
137
+ | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
138
+ | DATABASE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
139
+ | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
140
+
135
141
  When `mongodb` is used the following environment variables are used for the configuration:
136
142
 
137
143
  | Env variable name | Description | Default | Comments |
@@ -140,8 +146,6 @@ When `mongodb` is used the following environment variables are used for the conf
140
146
  | DATABASE_IP | ip address of the database | localhost |
141
147
  | DATABASE_USER | user to access the database | null | if missing no user/password will be used
142
148
  | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
143
- | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
144
- | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
145
149
  | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
146
150
  | MONGO_AUTH_DATABASE | the auth database where users exists | |
147
151
  | MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
@@ -195,9 +199,12 @@ When `redis` is used the following environement variables are used for the confi
195
199
 
196
200
  | Env variable name | Description | Default | Comments |
197
201
  | ----------------- | ----------- | ------- | -------- |
198
- | CACHE_IP | domain of the redis server to use | localhost:6379 |
199
- | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
200
- | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 20 | in seconds
202
+ | CACHE_IP | domain of the redis server to use with port | localhost:6379 |
203
+ | CACHE_USER | redis user if the redis service is auth protected | null |
204
+ | CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
205
+ | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 30 | in seconds
206
+ | CACHE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
207
+ | CACHE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
201
208
  | CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
202
209
  | CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
203
210
  | CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
@@ -205,8 +212,8 @@ When `redis` is used the following environement variables are used for the confi
205
212
  | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
206
213
  | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
207
214
  | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
208
- | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
209
- | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
215
+ | REDIS_SOCKET_KEEPALIVE | keep long running connections alive for x seconds | 5000 | in seconds
216
+ | REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
210
217
 
211
218
  **Requires**: <code>module:@mimik/sumologic-winston-logger</code>
212
219
 
package/index.js CHANGED
@@ -35,8 +35,9 @@ const {
35
35
  DEFAULT_CLOUD_PROVIDER,
36
36
  DEFAULT_CUSTOMER_CODE,
37
37
  DEFAULT_CACHE_IP,
38
- DEFAULT_CACHE_PASSWORD,
39
38
  DEFAULT_CACHE_CONNECTION_TIMEOUT,
39
+ DEFAULT_CACHE_RECONNECTION_OFFSET,
40
+ DEFAULT_CACHE_VALIDATION_CHECK,
40
41
  DEFAULT_CACHE_REQUEST_TTL,
41
42
  DEFAULT_CACHE_API_ID_TTL,
42
43
  DEFAULT_CACHE_API_OPTION_TTL,
@@ -45,7 +46,7 @@ const {
45
46
  DEFAULT_REDIS_REQUEST_MAX_MEMORY,
46
47
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
47
48
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
48
- DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
49
+ DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
49
50
  DEFAULT_AWS_REGION,
50
51
  DEFAULT_AWS_LOCAL_PROPERTIES,
51
52
  DEFAULT_DYNAMODB_LOCAL_URL,
@@ -66,6 +67,7 @@ const {
66
67
  DEFAULT_DATABASE_PASSWORD,
67
68
  DEFAULT_DATABASE_CONNECTION_TIMEOUT,
68
69
  DEFAULT_DATABASE_RECONNECTION_OFFSET,
70
+ DEFAULT_DATABASE_VALIDATION_CHECK,
69
71
  DEFAULT_ENCRYPTION_SET,
70
72
  DEFAULT_KMS_PROVIDER,
71
73
  DEFAULT_LOG_LEVEL,
@@ -101,35 +103,42 @@ const isMSTSet = process.env.MST_SET !== SET_OFF;
101
103
 
102
104
  const setupRedis = () => {
103
105
  const domain = process.env.CACHE_IP || DEFAULT_CACHE_IP;
104
- const password = process.env.CACHE_PASSWORD || DEFAULT_CACHE_PASSWORD;
106
+ const username = process.env.CACHE_USER;
107
+ const password = process.env.CACHE_PASSWORD;
105
108
  const reconnectTries = parseInt(process.env.REDIS_RECONNECT_TRIES, 10) || DEFAULT_REDIS_RECONNECT_TRIES;
106
109
  const reconnectInterval = parseInt(process.env.REDIS_RECONNECT_INTERVAL, 10) || DEFAULT_REDIS_RECONNECT_INTERVAL;
107
- let url = `${REDIS_BASE_URL}${domain}`;
110
+ let url = REDIS_BASE_URL;
111
+ if (username && password) url += `${username}:${password}@`;
112
+ url += domain;
108
113
 
109
- if (password) url = `${url}?password=${password}`;
110
114
  return {
111
115
  domain,
116
+ username,
112
117
  password,
113
118
  connectTimeout: parseInt(process.env.CACHE_CONNECTION_TIMEOUT, 10) || DEFAULT_CACHE_CONNECTION_TIMEOUT,
119
+ validationCheck: parseInt(process.env.CACHE_VALIDATION_CHECK, 10) || DEFAULT_CACHE_VALIDATION_CHECK,
120
+ reconnectOffset: parseInt(process.env.CACHE_RECONNECTION_OFFSET, 10) || DEFAULT_CACHE_RECONNECTION_OFFSET,
114
121
  url,
115
122
  options: {
116
- maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || DEFAULT_REDIS_REQUEST_MAX_MEMORY,
117
- maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
118
- socket_keepalive: process.env.REDIS_SOCKET_KEEPALIVE || DEFAULT_REDIS_SOCKET_KEEPALIVE,
119
- enable_offline_queue: process.env.REDIS_ENABLE_OFFLINE_QUEUE || DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
120
- retry_strategy: function retryStrategy(opts) {
121
- if (opts.timesConnected > 0 && opts.attempt < reconnectTries) {
122
- return reconnectInterval;
123
- }
124
- if (opts.error && opts.error.code === 'ECONNREFUSED') {
125
- if (display) {
126
- logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
127
- logger.flushAndExit(1);
123
+ socket: {
124
+ keepAlive: process.env.REDIS_SOCKET_KEEPALIVE || DEFAULT_REDIS_SOCKET_KEEPALIVE,
125
+ reconnectStrategy: function retryStrategy(opts) {
126
+ if (opts.timesConnected > 0 && opts.attempt < reconnectTries) {
127
+ return reconnectInterval;
128
128
  }
129
- display = false;
130
- }
131
- return undefined;
129
+ if (opts.error && opts.error.code === 'ECONNREFUSED') {
130
+ if (display) {
131
+ logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
132
+ logger.flushAndExit(1);
133
+ }
134
+ display = false;
135
+ }
136
+ return undefined;
137
+ },
138
+ disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === 'yes') || DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
132
139
  },
140
+ maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || DEFAULT_REDIS_REQUEST_MAX_MEMORY,
141
+ maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
133
142
  },
134
143
  retryStrategyOptions: {
135
144
  reconnectTries,
@@ -147,6 +156,9 @@ const setupRedis = () => {
147
156
 
148
157
  const setupDynamo = (dbOpts) => {
149
158
  const dbConfig = {
159
+ connectTimeout: parseInt(process.env.DATABASE_CONNECTION_TIMEOUT, 10) || DEFAULT_DATABASE_CONNECTION_TIMEOUT,
160
+ validationCheck: parseInt(process.env.DATABASE_VALIDATION_CHECK, 10) || DEFAULT_DATABASE_VALIDATION_CHECK,
161
+ reconnectOffset: parseInt(process.env.DATABASE_RECONNECTION_OFFSET, 10) || DEFAULT_DATABASE_RECONNECTION_OFFSET,
150
162
  region: process.env.DYNAMODB_AWS_REGION || DEFAULT_AWS_REGION,
151
163
  url: process.env.DYNAMODB_LOCAL_URL || DEFAULT_DYNAMODB_LOCAL_URL,
152
164
  throughput: {
@@ -215,6 +227,7 @@ const setupMongo = (dbOpts) => {
215
227
  user,
216
228
  password,
217
229
  connectTimeout: parseInt(process.env.DATABASE_CONNECTION_TIMEOUT, 10) || DEFAULT_DATABASE_CONNECTION_TIMEOUT,
230
+ validationCheck: parseInt(process.env.DATABASE_VALIDATION_CHECK, 10) || DEFAULT_DATABASE_VALIDATION_CHECK,
218
231
  reconnectOffset: parseInt(process.env.DATABASE_RECONNECTION_OFFSET, 10) || DEFAULT_DATABASE_RECONNECTION_OFFSET,
219
232
  replicat: !!process.env.MONGO_REPLICAT_SET,
220
233
  stringOptions: qs,
@@ -566,6 +579,12 @@ configuration.locationProvider = setupLocationProvider();
566
579
  * | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
567
580
  * | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
568
581
  *
582
+ * When a database is involved
583
+ * | Env variable name | Description | Default | Comments |
584
+ * | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
585
+ * | DATABASE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
586
+ * | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
587
+ *
569
588
  * When `mongodb` is used the following environment variables are used for the configuration:
570
589
  *
571
590
  * | Env variable name | Description | Default | Comments |
@@ -574,8 +593,6 @@ configuration.locationProvider = setupLocationProvider();
574
593
  * | DATABASE_IP | ip address of the database | localhost |
575
594
  * | DATABASE_USER | user to access the database | null | if missing no user/password will be used
576
595
  * | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
577
- * | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
578
- * | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
579
596
  * | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
580
597
  * | MONGO_AUTH_DATABASE | the auth database where users exists | |
581
598
  * | MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
@@ -629,9 +646,12 @@ configuration.locationProvider = setupLocationProvider();
629
646
  *
630
647
  * | Env variable name | Description | Default | Comments |
631
648
  * | ----------------- | ----------- | ------- | -------- |
632
- * | CACHE_IP | domain of the redis server to use | localhost:6379 |
633
- * | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
634
- * | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 20 | in seconds
649
+ * | CACHE_IP | domain of the redis server to use with port | localhost:6379 |
650
+ * | CACHE_USER | redis user if the redis service is auth protected | null |
651
+ * | CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
652
+ * | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 30 | in seconds
653
+ * | CACHE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
654
+ * | CACHE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
635
655
  * | CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
636
656
  * | CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
637
657
  * | CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
@@ -639,8 +659,8 @@ configuration.locationProvider = setupLocationProvider();
639
659
  * | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
640
660
  * | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
641
661
  * | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
642
- * | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
643
- * | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
662
+ * | REDIS_SOCKET_KEEPALIVE | keep long running connections alive for x seconds | 5000 | in seconds
663
+ * | REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
644
664
  */
645
665
  const setConfig = (pack, options) => {
646
666
  process.env.SERVER_VERSION = pack.version;
package/lib/common.js CHANGED
@@ -21,8 +21,9 @@ const DEFAULT_CLOUD_PROVIDER = 'noCloud';
21
21
  const DEFAULT_CUSTOMER_CODE = '';
22
22
 
23
23
  const DEFAULT_CACHE_IP = 'localhost:6379';
24
- const DEFAULT_CACHE_PASSWORD = null;
25
- const DEFAULT_CACHE_CONNECTION_TIMEOUT = 20; // in seconds
24
+ const DEFAULT_CACHE_CONNECTION_TIMEOUT = 30; // in seconds
25
+ const DEFAULT_CACHE_RECONNECTION_OFFSET = 5; // in seconds
26
+ const DEFAULT_CACHE_VALIDATION_CHECK = 1000; // in ms
26
27
  const DEFAULT_CACHE_REQUEST_TTL = 10; // in seconds
27
28
  const DEFAULT_CACHE_API_ID_TTL = 20; // in seconds
28
29
  const DEFAULT_CACHE_API_OPTION_TTL = 5; // in seconds
@@ -31,8 +32,8 @@ const DEFAULT_REDIS_RECONNECT_TRIES = 100;
31
32
  const DEFAULT_REDIS_RECONNECT_INTERVAL = 500; // in ms
32
33
  const DEFAULT_REDIS_REQUEST_MAX_MEMORY = '10mb';
33
34
  const DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY = 'allkeys-lru';
34
- const DEFAULT_REDIS_SOCKET_KEEPALIVE = true;
35
- const DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE = true;
35
+ const DEFAULT_REDIS_SOCKET_KEEPALIVE = 5000;
36
+ const DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE = false;
36
37
 
37
38
  const DEFAULT_AWS_REGION = '---noRegion--';
38
39
  const DEFAULT_AWS_LOCAL_PROPERTIES = '169.254.169.254'; // to access properties of the instance on AWS
@@ -57,6 +58,7 @@ const DEFAULT_DATABASE_USER = null;
57
58
  const DEFAULT_DATABASE_PASSWORD = null;
58
59
  const DEFAULT_DATABASE_CONNECTION_TIMEOUT = 30; // in seconds
59
60
  const DEFAULT_DATABASE_RECONNECTION_OFFSET = 5; // in seconds
61
+ const DEFAULT_DATABASE_VALIDATION_CHECK = 1000; // in ms
60
62
 
61
63
  const DEFAULT_ENCRYPTION_SET = SET_OFF;
62
64
  const DEFAULT_KMS_PROVIDER = 'local';
@@ -115,8 +117,9 @@ module.exports = {
115
117
  DEFAULT_LOCATION_PROVIDER,
116
118
  DEFAULT_CLOUD_PROVIDER,
117
119
  DEFAULT_CACHE_IP,
118
- DEFAULT_CACHE_PASSWORD,
119
120
  DEFAULT_CACHE_CONNECTION_TIMEOUT,
121
+ DEFAULT_CACHE_RECONNECTION_OFFSET,
122
+ DEFAULT_CACHE_VALIDATION_CHECK,
120
123
  DEFAULT_CACHE_REQUEST_TTL,
121
124
  DEFAULT_CACHE_API_ID_TTL,
122
125
  DEFAULT_CACHE_API_OPTION_TTL,
@@ -125,7 +128,7 @@ module.exports = {
125
128
  DEFAULT_REDIS_REQUEST_MAX_MEMORY,
126
129
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
127
130
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
128
- DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
131
+ DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
129
132
  DEFAULT_AWS_REGION,
130
133
  DEFAULT_AWS_LOCAL_PROPERTIES,
131
134
  DEFAULT_DYNAMODB_LOCAL_URL,
@@ -146,6 +149,7 @@ module.exports = {
146
149
  DEFAULT_DATABASE_PASSWORD,
147
150
  DEFAULT_DATABASE_CONNECTION_TIMEOUT,
148
151
  DEFAULT_DATABASE_RECONNECTION_OFFSET,
152
+ DEFAULT_DATABASE_VALIDATION_CHECK,
149
153
  DEFAULT_ENCRYPTION_SET,
150
154
  DEFAULT_KMS_PROVIDER,
151
155
  DEFAULT_LOG_LEVEL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "5.0.4",
3
+ "version": "5.0.6",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,8 +30,8 @@
30
30
  "url": "https://bitbucket.org/mimiktech/configuration"
31
31
  },
32
32
  "dependencies": {
33
- "@mimik/request-helper": "^1.7.8",
34
- "@mimik/sumologic-winston-logger": "^1.6.15",
33
+ "@mimik/request-helper": "^1.7.9",
34
+ "@mimik/sumologic-winston-logger": "^1.6.19",
35
35
  "@mimik/user-filters": "1.3.6",
36
36
  "ip": "2.0.0",
37
37
  "lodash": "4.17.21",
@@ -40,11 +40,11 @@
40
40
  "devDependencies": {
41
41
  "@mimik/eslint-plugin-dependencies": "^2.4.5",
42
42
  "@mimik/eslint-plugin-document-env": "^1.0.5",
43
- "eslint": "8.39.0",
43
+ "eslint": "8.48.0",
44
44
  "eslint-config-airbnb": "19.0.4",
45
- "eslint-plugin-import": "2.27.5",
45
+ "eslint-plugin-import": "2.28.1",
46
46
  "eslint-plugin-jsx-a11y": "6.7.1",
47
- "eslint-plugin-react": "7.32.2",
47
+ "eslint-plugin-react": "7.33.2",
48
48
  "eslint-plugin-react-hooks": "4.6.0",
49
49
  "husky": "8.0.3",
50
50
  "jsdoc-to-markdown": "8.0.0"