@mimik/configuration 1.4.0 → 4.4.2

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/.eslintrc CHANGED
@@ -1,17 +1,29 @@
1
- // Use this file as a starting point for your project's .eslintrc.
2
- // Copy this file, and add rule overrides as needed.
3
1
  {
2
+ "plugins": [
3
+ "@mimik/document-env",
4
+ "@mimik/dependencies"
5
+ ],
4
6
  "env": {
5
7
  "node": true
6
8
  },
9
+ "parserOptions": {
10
+ "ecmaVersion": 2020
11
+ },
7
12
  "extends": "airbnb",
8
13
  "rules": {
14
+ "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
9
15
  "brace-style": [1, "stroustrup", {"allowSingleLine": true}],
10
16
  "no-confusing-arrow": [0], // arrow isnt confusing
11
17
  "max-len": [1, 180, { "ignoreComments": true }],
12
18
  "linebreak-style": 0,
13
19
  "quotes": [1, "single"],
14
- "semi": [1, "always"]
20
+ "semi": [1, "always"],
21
+ "no-process-env": ["error"],
22
+ "@mimik/document-env/validate-document-env": 2,
23
+ "@mimik/dependencies/case-sensitive": 2,
24
+ "@mimik/dependencies/no-cycles": 2,
25
+ "@mimik/dependencies/no-unresolved": 2,
26
+ "@mimik/dependencies/require-json-ext": 2
15
27
  },
16
28
  "settings":{
17
29
  "react": {
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run commit-ready
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run test
package/Gulpfile.js CHANGED
@@ -16,14 +16,13 @@ const files = [
16
16
  const createDocs = (done) => {
17
17
  jsdoc2md.render({ files: 'index.js' })
18
18
  .then((output) => fs.writeFileSync('README.md', output))
19
- .catch((err) => log.error('docs creation failed:', err.message));
20
- return done();
19
+ .catch((err) => log.error('docs creation failed:', err.message))
20
+ .finally(() => done());
21
21
  };
22
22
 
23
23
  const lint = () => gulp.src(files)
24
24
  .pipe(eslint({}))
25
- .pipe(eslint.format())
26
- .pipe(eslint.failOnError());
25
+ .pipe(eslint.format());
27
26
 
28
27
  const add = () => gulp.src('README.md')
29
28
  .pipe(git.add({ quiet: true }));
package/README.md CHANGED
@@ -5,6 +5,25 @@
5
5
  ```js
6
6
  const config = require('@mimik/configuration');
7
7
  ```
8
+
9
+ * [configuration](#module_configuration)
10
+ * [~isProd()](#module_configuration..isProd) ⇒ <code>boolean</code>
11
+ * [~setConfig(pack, options)](#module_configuration..setConfig) ⇒ <code>object</code>
12
+
13
+ <a name="module_configuration..isProd"></a>
14
+
15
+ ### configuration~isProd() ⇒ <code>boolean</code>
16
+ Indicates if the environment is prod
17
+
18
+ **Kind**: inner method of [<code>configuration</code>](#module_configuration)
19
+ **Returns**: <code>boolean</code> - `true` if the environment is `prod` or `production`.
20
+
21
+ The following environment variables are used
22
+
23
+ | Env variable name | Description | Value | Comments |
24
+ | ----------------- | ----------- | ----- | -------- |
25
+ | NODE_ENV | environnment of the microservice |
26
+ **Category**: sync
8
27
  <a name="module_configuration..setConfig"></a>
9
28
 
10
29
  ### configuration~setConfig(pack, options) ⇒ <code>object</code>
@@ -15,19 +34,22 @@ Set the configuration of the micro-service.
15
34
  **Category**: sync
16
35
  **Throws**:
17
36
 
18
- - Will trow an error if a mandatory value is missing.
37
+ - <code>configuration.serverSettings.type</code> Will trow an error if a mandatory value is missing.
19
38
 
20
39
  The following environment variables are being setup:
21
40
 
22
41
  | Env variable name | Description | Value | Comments |
23
42
  | ----------------- | ----------- | ----- | -------- |
24
- | SERVER_VERSION | version of the software for the micro-service| package.version |
25
- | SERVER_NAME | name of the micro-service | package.[]()name |
26
- | SERVER_TYPE | type of the micro-service | package.type |
27
- | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version |
28
- | SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() |
29
- | CONSOLE_LEVEL | log level for console output | debug | if not already set
30
- | LOG_LEVEL | log level for the logger service | debug | if not already set
43
+ | SERVER_VERSION | version of the software for the micro-service | package.version | serverSettings.version
44
+ | SERVER_NAME | name of the micro-service | package.name | serverSettings.name
45
+ | SERVER_TYPE | type of the micro-service | package.mimik.type | serverSettings.type
46
+ | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version | serverSettings.swaggerFileVersion
47
+ | SWAGGER_FILE_ACCOUNT | account associated with the API | package.swaggerFile.account |
48
+ | SWAGGER_FILE_NAME | name of the API | package.swaggerFile.name |
49
+ | SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() | serverSettings.ip.local
50
+ | CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel
51
+ | LOG_LEVEL | log level for console output | debug | logInfo.logLevel
52
+ | AWS_LOCAL_PROPERTIES | internal ip address to access aws insrance properties | 169.254.169.254
31
53
 
32
54
  The following environement variables are being used for the configuration:
33
55
 
@@ -37,46 +59,42 @@ The following environement variables are being used for the configuration:
37
59
  | LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
38
60
  | LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
39
61
  | CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
40
- | AWS_ACCESS_KEY_ID | aws access key id for the account | ----noAccessKeyId---- | aws.accessKeyId |
41
- | AWS_SECRET_ACCESS_KEY | secret for the aws access key id for the account | ----noAccessKey---- | aws.secretAccessKey |
42
- | AWS_REGION | aws region for the account | ----noRegion---- | aws.region |
43
62
  | SERVER_ID | service id | uuid.v4() | serverSettings.id |
63
+ | CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
44
64
  | SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ./api | serverSettings.api | [1]
65
+ | SWAGGER_API_KEY | key on swagger hub for provate api access | | serverSettings.apiKey
45
66
  | SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
46
67
  | INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
47
68
  | SERVER_PORT | port of the server | | serverSettings.port |
48
- | SERVER_NAME | name of the micro-service | | serverSettings.[]()name | see setup environment variable
49
- | SERVER_TYPE | type of the micro-service | | serverSettings.type | see setup environment variable
50
- | SERVER_VERSION | version of the software for the micro-service | | serverSettings.version | see setup environment variable
51
- | SWAGGER_FILE_VERSION | version of the swagger file for the API | | serverSettings.swaggerFileVersion | see setup environment variable
52
- | SERVER_LOCAL_IPV4 | ip address of the server | | serverSettings.ip.local | see setup environment variable
53
69
  | SERVER_PUBLIC_PROTOCOL | protocol used to defined the domain address of the sevice | http: | serverSettings.public.protocol |
54
70
  | SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
55
71
  | ADMIN_EXTERNAL_ID | external id of the admin role to be chacked in the token | admin | security.admin.externalId |
56
- | OAUTH_CLIENT_ID | security id of the service | | security.server.[]()id | [2]
72
+ | OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
57
73
  | OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
58
74
  | OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
59
75
  | OAUTH_CLIENT_AUDIENCE | url representing the server to mST | | security.server.audience | [2]
60
76
  | OAUTH_ISSUER | token url of mST | | security.server.issuer | [2]
61
77
  | OAUTH_GENERIC_KEY | key for token signature provided when a generic for this service type is defined | noGeneric | security.generic.key | [2]
78
+ | OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
62
79
  | OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
63
- | CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel | see setup environment variable
64
- | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`
65
- | LOG_LEVEL | log level for console output | debug | logInfo.logLevel | see setup environment variable
80
+ | API_KEYS | list of API Keys which a test against in case of APIKey security | [] |
81
+ | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
82
+ | NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
66
83
  | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
67
84
  | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
68
85
  | CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
69
86
  | REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
70
87
  | CACHE_SET | switch to enable use of cache | off | cache.set | can be `on`, `off`
71
88
  | TOPIC_SET | switch to enable use of event topic | off | topic.set | can be `on`, `off`, `mock`
89
+ | ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
72
90
  | MIT_URL | url for reaching mIT | | dependencies.mIT.url |
73
91
  | MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
74
92
  | REGISTRATION_SET | swicht to enable user of registration | on | registration.set | can be `on` or `off`
75
93
  | REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
76
- | `(SERVER_TYPE)`_URL | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
77
- | `(SERVER_TYPE)`_AUDIENCE | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
94
+ | `$_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
95
+ | `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
78
96
 
79
- [1]: `/(SERVER_NAME)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
97
+ [1]: `/(SWAGGER_FILE_ACCOUNT)_(SERVER_TYPE)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
80
98
 
81
99
  [2]: defined when registering to mST
82
100
 
@@ -103,8 +121,8 @@ When `on` is used for `TOPIC_SET` the following environment variables are used f
103
121
 
104
122
  | Env variable name | Description | Default | Comments |
105
123
  | ----------------- | ----------- | ------- | -------- |
106
- | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | ----noAccessKeyId---- |
107
- | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | ----noAccessKey---- |
124
+ | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | |
125
+ | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
108
126
  | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
109
127
 
110
128
  When `mongodb` is used the following environment variables are used for the configuration:
@@ -116,32 +134,55 @@ When `mongodb` is used the following environment variables are used for the conf
116
134
  | DATABASE_USER | user to access the database | null | if missing no user/password will be used
117
135
  | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
118
136
  | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
137
+ | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
138
+ | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
139
+ | MONGO_AUTH_DATABASE | the auth database where users exists | |
119
140
  | MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
120
141
  | MONGO_MIN_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
121
142
  | MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 3000 | in milliseconds
122
- | MONGO_SSL | uses ssl connection if true | false |
123
- | MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to true | true | true if MONGO_SSL is also true
143
+ | MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
144
+ | MONGO_WRITE_CONCERN | accepts a number or `majority` | |
145
+ | MONGO_SSL | uses ssl connection if `yes` | `no` |
146
+ | MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
147
+ | MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allows invalid hostnames | |
124
148
  | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
125
149
  | 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
126
150
  | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
127
- | MONGO_AUTO_RECONNECT | enable the ability to reconnect when connection is lost | true |
128
- | MONGO_RECONNECT_TRIES | number of tries before generating an error | 100 |
129
- | MONGO_RECONNECT_INTERVAL | time between reconnect tries | 500 | in milliseconds
130
- | MONGO_KEEP_ALIVE | | true |
131
- | MONGO_BUFFER_MAX_ENTRIES | | 0 |
132
- | MONGO_BUFFER_COMMANDS | | false |
133
- | MONGO_CONNECT_TIMEOUT | the time in milliseconds to attempt a connection before timing out | null | in milliseconds
134
- | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | null | in milliseconds
151
+ | MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
152
+ | MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
153
+ | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
154
+ | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
155
+ | 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
156
+ | MONGO_HEARTBEAT_FREQUENCY | the MongoDB driver sends a heartbeat every heartbeatFrequencyMS to check on the status of the connection | 10000 | in milliseconds
157
+
158
+ When `on` is used for `ENCRYPTION_SET` the following environment variables are used for the configuration:
159
+
160
+ | Env variable name | Description | Default | Comments |
161
+ | ----------------- | ----------- | ------- | -------- |
162
+ | ENCRYPTION_DATABASE | database name where data encryption keyvault exists | admin |
163
+ | KEY_VAULT_TABLE | collection name which has data encryption keys | keystore |
164
+ | KMS_PROVIDER | Key Management service provider for master key | local |
165
+ | MASTER_KEY_AWS_REGION | if KMS is aws region where master key exists | ----noRegion---- |
166
+ | MASTER_KEY_ARN | if KMS is aws ARN of master key | |
167
+ | ENCRYPTION_ACCESS_KEY_ID | if KMS is aws, accessKeyId to connect KMS | |
168
+ | ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
169
+ | LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
170
+
135
171
  When `dynamodb` is used the following environement variables are used for the configuration:
136
172
 
137
173
  | Env variable name | Description | Default | Comments |
138
174
  | ----------------- | ----------- | ------- | -------- |
139
- | DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | ----noAccessKeyId---- |
140
- | DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | ----noSecretAccessKey---- |
175
+ | DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | |
176
+ | DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | |
141
177
  | DYNAMODB_AWS_REGION | region where dynamodb is | ----noRegion---- |
142
178
  | DYNAMODB_LOCAL_URL | url access the locally deploy dynamodb | http://localhost:8000 |
143
179
  | DYNAMO_THROUGHPUT_READ | throughput read for dynamodb index | 1 |
144
180
  | DYNAMO_THROUGHPUT_WRITE | throughput write for dynamodb index | 1 |
181
+ | DYNAMO_SCHEMA_THROUGHPUT_READ | throughput read for dynamodb schema | 1 |
182
+ | DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
183
+ | DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
184
+
185
+ `DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput wont apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
145
186
 
146
187
  When `redis` is used the following environement variables are used for the configuration:
147
188
 
package/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ /* eslint no-process-env: "off" */
1
2
  const _ = require('lodash');
2
3
  const ip = require('ip');
3
4
  const uuid = require('uuid');
4
5
  const querystring = require('querystring');
5
6
 
6
7
  const logger = require('@mimik/sumologic-winston-logger');
8
+ const { getCorrelationId } = require('@mimik/request-helper');
7
9
  /**
8
10
  * @module configuration
9
11
  * @example
@@ -20,11 +22,15 @@ const {
20
22
  ENV_VARIABLE,
21
23
  REDIS_BASE_URL,
22
24
  MONGO_BASE_URL,
25
+ MONGO_BASE_URL_SRV,
23
26
  SWAGGER_EXT,
24
27
  SWAGGER_SEP,
28
+ CUSTOMER_CODE_SEP,
25
29
  DEFAULT_ENV,
30
+ PRODUCTIONS,
26
31
  DEFAULT_LOCATION_PROVIDER,
27
32
  DEFAULT_CLOUD_PROVIDER,
33
+ DEFAULT_CUSTOMER_CODE,
28
34
  DEFAULT_CACHE_IP,
29
35
  DEFAULT_CACHE_PASSWORD,
30
36
  DEFAULT_CACHE_CONNECTION_TIMEOUT,
@@ -37,28 +43,28 @@ const {
37
43
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
38
44
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
39
45
  DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
40
- DEFAULT_AWS_ACCESS_KEY_ID,
41
- DEFAULT_AWS_SECRET_ACCESS_KEY,
42
46
  DEFAULT_AWS_REGION,
43
47
  DEFAULT_AWS_LOCAL_PROPERTIES,
44
48
  DEFAULT_DYNAMODB_LOCAL_URL,
45
49
  DEFAULT_DYNAMO_THROUGHPUT_READ,
46
50
  DEFAULT_DYNAMO_THROUGHPUT_WRITE,
51
+ DEFAULT_DYNAMO_THROUGHPUT,
47
52
  DEFAULT_MONGO_MAX_POOL_SIZE,
48
53
  DEFAULT_MONGO_MIN_POOL_SIZE,
49
54
  DEFAULT_MONGO_MAX_IDLE_TIME,
50
- DEFAULT_MONGO_AUTO_RECONNECT,
51
- DEFAULT_MONGO_RECONNECT_TRIES,
52
- DEFAULT_MONGO_RECONNECT_INTERVAL,
53
55
  DEFAULT_MONGO_KEEP_ALIVE,
54
- DEFAULT_MONGO_BUFFER_MAX_ENTRIES,
55
- DEFAULT_MONGO_BUFFER_COMMANDS,
56
- DEFAULT_MONGO_CONNECT_TIMEOUT,
56
+ DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
57
57
  DEFAULT_MONGO_SOCKET_TIMEOUT,
58
+ DEFAULT_MONGO_FAMILY,
59
+ DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
60
+ DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
58
61
  DEFAULT_DATABASE_IP,
59
62
  DEFAULT_DATABASE_USER,
60
63
  DEFAULT_DATABASE_PASSWORD,
61
64
  DEFAULT_DATABASE_CONNECTION_TIMEOUT,
65
+ DEFAULT_DATABASE_RECONNECTION_OFFSET,
66
+ DEFAULT_ENCRYPTION_SET,
67
+ DEFAULT_KMS_PROVIDER,
62
68
  DEFAULT_LOG_LEVEL,
63
69
  DEFAULT_FILTER_FILE,
64
70
  DEFAULT_EXIT_DELAY,
@@ -80,7 +86,7 @@ const {
80
86
  DEFAULT_INTERCEPT_ERROR,
81
87
  } = require('./lib/common');
82
88
 
83
- const correlationId = 'config-start';
89
+ const correlationIdStart = getCorrelationId('config-start');
84
90
  let display = true;
85
91
  const locParams = [NO_PUBLIC_PROVIDER, ENV_VARIABLE];
86
92
 
@@ -108,8 +114,8 @@ const setupRedis = () => {
108
114
  }
109
115
  if (opts.error && opts.error.code === 'ECONNREFUSED') {
110
116
  if (display) {
111
- logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, 'cache-start');
112
- logger.flushAndExit(0);
117
+ logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
118
+ logger.flushAndExit(1);
113
119
  }
114
120
  display = false;
115
121
  }
@@ -132,17 +138,31 @@ const setupRedis = () => {
132
138
 
133
139
  const setupDynamo = (dbOpts) => {
134
140
  const dbConfig = {
135
- accessKeyId: process.env.DYNAMODB_AWS_ACCESS_KEY_ID || DEFAULT_AWS_ACCESS_KEY_ID,
136
- secretAccessKey: process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY || DEFAULT_AWS_SECRET_ACCESS_KEY,
137
141
  region: process.env.DYNAMODB_AWS_REGION || DEFAULT_AWS_REGION,
138
142
  url: process.env.DYNAMODB_LOCAL_URL || DEFAULT_DYNAMODB_LOCAL_URL,
139
143
  throughput: {
140
144
  read: parseInt(process.env.DYNAMO_THROUGHPUT_READ, 10) || DEFAULT_DYNAMO_THROUGHPUT_READ,
141
145
  write: parseInt(process.env.DYNAMO_THROUGHPUT_WRITE, 10) || DEFAULT_DYNAMO_THROUGHPUT_WRITE,
142
146
  },
147
+ schemaThroughput: {
148
+ read: parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_READ, 10) || DEFAULT_DYNAMO_THROUGHPUT_READ,
149
+ write: parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_WRITE, 10) || DEFAULT_DYNAMO_THROUGHPUT_WRITE,
150
+ },
143
151
  tableName: dbOpts.table,
144
152
  };
153
+ if (!_.isNil(process.env.DYNAMODB_AWS_ACCESS_KEY_ID)) dbConfig.accessKeyId = process.env.DYNAMODB_AWS_ACCESS_KEY_ID;
154
+ if (!_.isNil(process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY)) dbConfig.secretAccessKey = process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY;
155
+
156
+ if (process.env.DYNAMO_SCHEMA_THROUGHPUT === 'ON_DEMAND') {
157
+ dbConfig.schemaThroughput = process.env.DYNAMO_SCHEMA_THROUGHPUT;
158
+ delete dbConfig.throughput;
159
+ }
160
+ else if (!_.isNil(process.env.DYNAMO_SCHEMA_THROUGHPUT)) {
161
+ const throughput = parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT, 10);
145
162
 
163
+ if (_.isNil(throughput) || _.isNaN(throughput)) dbConfig.schemaThroughput = DEFAULT_DYNAMO_THROUGHPUT;
164
+ else dbConfig.schemaThroughput = throughput;
165
+ }
146
166
  return dbConfig;
147
167
  };
148
168
 
@@ -157,8 +177,12 @@ const setupMongo = (dbOpts) => {
157
177
  // string variables without default
158
178
  if (process.env.MONGO_SSL === 'yes') stringOptions.ssl = true; // default value of mongo driver is false
159
179
  if (process.env.MONGO_SSL_VALIDATE === 'no') stringOptions.sslValidate = false; // default value of mongo driver is true, if ssl is true
180
+ if (process.env.MONGO_SSL_ALLOW_INVALID_HOSTNAMES === 'yes') stringOptions.allowInvalidHostnames = true;
160
181
  // 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
161
182
  if (process.env.MONGO_REPLICAT_SET) stringOptions.replicaSet = process.env.MONGO_REPLICAT_SET;
183
+ if (process.env.MONGO_AUTH_DATABASE) stringOptions.authSource = process.env.MONGO_AUTH_DATABASE;
184
+ if (process.env.MONGO_WRITE_CONCERN) stringOptions.w = process.env.MONGO_WRITE_CONCERN;
185
+ if (process.env.MONGO_RETRY_WRITES) stringOptions.retryWrites = process.env.MONGO_RETRY_WRITES;
162
186
  if (process.env.MONGO_WAIT_QUEUE_MULTIPLE) stringOptions.waitQueueMultiple = parseInt(process.env.MONGO_WAIT_QUEUE_MULTIPLE, 10);
163
187
  if (process.env.MONGO_WAIT_QUEUE_TIMEOUT) stringOptions.waitQueueTimeoutMS = parseInt(process.env.MONGO_WAIT_QUEUE_TIMEOUT, 10); // in ms
164
188
  return stringOptions ? querystring.stringify(stringOptions) : null;
@@ -171,7 +195,7 @@ const setupMongo = (dbOpts) => {
171
195
  const user = process.env.DATABASE_USER || DEFAULT_DATABASE_USER;
172
196
  const password = process.env.DATABASE_PASSWORD || DEFAULT_DATABASE_PASSWORD;
173
197
  const qs = processStringOptions();
174
- let url = MONGO_BASE_URL;
198
+ let url = (process.env.MONGO_USE_SRV === 'yes') ? MONGO_BASE_URL_SRV : MONGO_BASE_URL;
175
199
 
176
200
  if (user && password) url = `${url}${user}:${password}@`;
177
201
  url = `${url}${domain}/${database}`;
@@ -182,21 +206,18 @@ const setupMongo = (dbOpts) => {
182
206
  user,
183
207
  password,
184
208
  connectTimeout: parseInt(process.env.DATABASE_CONNECTION_TIMEOUT, 10) || DEFAULT_DATABASE_CONNECTION_TIMEOUT,
209
+ reconnectOffset: parseInt(process.env.DATABASE_RECONNECTION_OFFSET, 10) || DEFAULT_DATABASE_RECONNECTION_OFFSET,
185
210
  replicat: !!process.env.MONGO_REPLICAT_SET,
186
211
  stringOptions: qs,
187
212
  table: dbOpts.table,
188
213
  url,
189
214
  options: {
190
- useNewUrlParser: true,
191
- useCreateIndex: true,
192
- autoReconnect: process.env.MONGO_AUTO_RECONNECT || DEFAULT_MONGO_AUTO_RECONNECT,
193
- reconnectTries: parseInt(process.env.MONGO_RECONNECT_TRIES, 10) || DEFAULT_MONGO_RECONNECT_TRIES,
194
- reconnectInterval: parseInt(process.env.MONGO_RECONNECT_INTERVAL, 10) || DEFAULT_MONGO_RECONNECT_INTERVAL,
215
+ family: parseInt(process.env.MONGO_FAMILY, 10) || DEFAULT_MONGO_FAMILY,
195
216
  keepAlive: process.env.MONGO_KEEP_ALIVE || DEFAULT_MONGO_KEEP_ALIVE,
196
- bufferMaxEntries: parseInt(process.env.MONGO_BUFFER_MAX_ENTRIES, 10) || DEFAULT_MONGO_BUFFER_MAX_ENTRIES,
197
- bufferCommands: process.env.MONGO_BUFFER_COMMANDS || DEFAULT_MONGO_BUFFER_COMMANDS,
198
- connectTimeoutMS: parseInt(process.env.MONGO_CONNECT_TIMEOUT, 10) || DEFAULT_MONGO_CONNECT_TIMEOUT,
217
+ keepAliveInitialDelay: parseInt(process.env.MONGO_KEEP_ALIVE_INITIAL_DELAY, 10) || DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
199
218
  socketTimeoutMS: parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || DEFAULT_MONGO_SOCKET_TIMEOUT,
219
+ serverSelectionTimeoutMS: parseInt(process.env.MONGO_SERVER_SELECTION_TIMEOUT, 10) || DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
220
+ heartbeatFrequencyMS: parseInt(process.env.MONGO_HEARTBEAT_FREQUENCY, 10) || DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
200
221
  },
201
222
  };
202
223
  };
@@ -232,29 +253,53 @@ const setupLog = () => {
232
253
  }
233
254
  if (logInfo.mode === AWS_S3 || logInfo.mode === ALL) {
234
255
  logInfo[AWS_S3] = {
235
- accessKeyId: process.env.S3_AWS_ACCESS_KEY_ID,
236
- secretAccessKey: process.env.S3_AWS_SECRET_ACCESS_KEY,
237
256
  region: process.env.S3_AWS_REGION,
238
257
  bucketname: process.env.S3_AWS_BUCKET_NAME,
239
258
  timeout: parseInt(process.env.S3_AWS_TIMEOUT, 10) || DEFAULT_S3_AWS_TIMEOUT,
240
259
  maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) || DEFAULT_S3_AWS_MAX_SIZE,
241
260
  maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) || DEFAULT_S3_AWS_MAX_EVENTS,
242
261
  };
262
+ if (!_.isNil(process.env.S3_AWS_ACCESS_KEY_ID)) logInfo[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
263
+ if (!_.isNil(process.env.S3_AWS_SECRET_ACCESS_KEY)) logInfo[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
243
264
  }
244
265
  return logInfo;
245
266
  };
246
267
 
247
268
  const setupTopic = (topicOpts) => {
248
269
  const topicConfig = {
249
- accessKeyId: process.env.SNS_AWS_ACCESS_KEY_ID || DEFAULT_AWS_ACCESS_KEY_ID,
250
- secretAccessKey: process.env.SNS_AWS_SECRET_ACCESS_KEY || DEFAULT_AWS_SECRET_ACCESS_KEY,
251
270
  region: process.env.SNS_AWS_REGION || DEFAULT_AWS_REGION,
252
271
  name: topicOpts.name,
253
272
  };
254
273
 
274
+ if (!_.isNil(process.env.SNS_AWS_ACCESS_KEY_ID)) topicConfig.accessKeyId = process.env.SNS_AWS_ACCESS_KEY_ID;
275
+ if (!_.isNil(process.env.SNS_AWS_SECRET_ACCESS_KEY)) topicConfig.secretAccessKey = process.env.SNS_AWS_SECRET_ACCESS_KEY;
276
+
255
277
  return topicConfig;
256
278
  };
257
279
 
280
+ const setupEncryption = (encryptionOpts) => {
281
+ const encryptionConfig = {
282
+ set: encryptionOpts.set,
283
+ database: process.env.ENCRYPTION_DATABASE,
284
+ keyVaultTable: process.env.KEY_VAULT_TABLE,
285
+ kmsProvider: process.env.KMS_PROVIDER || DEFAULT_KMS_PROVIDER,
286
+ };
287
+
288
+ if (encryptionConfig.kmsProvider.toLowerCase() === 'aws') {
289
+ encryptionConfig.aws = {};
290
+ encryptionConfig.region = process.env.MASTER_KEY_AWS_REGION || DEFAULT_AWS_REGION;
291
+ encryptionConfig.masterKeyARN = process.env.MASTER_KEY_ARN;
292
+
293
+ if (!_.isNil(process.env.ENCRYPTION_ACCESS_KEY_ID)) encryptionConfig.aws.accessKeyId = process.env.ENCRYPTION_ACCESS_KEY_ID;
294
+ if (!_.isNil(process.env.ENCRYPTION_SECRET_ACCESS_KEY)) encryptionConfig.aws.secretAccessKey = process.env.ENCRYPTION_SECRET_ACCESS_KEY;
295
+ }
296
+ else encryptionConfig.localMasterKey = process.env.LOCAL_MASTER_KEY;
297
+
298
+ if (Object.keys(encryptionOpts.keys).length > 0) encryptionConfig.keys = encryptionOpts.keys;
299
+
300
+ return encryptionConfig;
301
+ };
302
+
258
303
  const checkConfig = (config) => {
259
304
  const errs = [];
260
305
 
@@ -271,11 +316,101 @@ const checkConfig = (config) => {
271
316
  if (errs.length > 0) {
272
317
  const error = new Error('Missing values');
273
318
 
274
- logger.error(error, { values: errs }, correlationId);
319
+ logger.error(error, { values: errs }, correlationIdStart);
275
320
  throw error;
276
321
  }
277
322
  };
278
323
 
324
+ /**
325
+ * Indicates if the environment is prod
326
+ *
327
+ * @function isProd
328
+ * @category sync
329
+ * @return {boolean} `true` if the environment is `prod` or `production`.
330
+ *
331
+ * The following environment variables are used
332
+ *
333
+ * | Env variable name | Description | Value | Comments |
334
+ * | ----------------- | ----------- | ----- | -------- |
335
+ * | NODE_ENV | environnment of the microservice |
336
+ */
337
+ const isProd = () => {
338
+ if (_.isString(process.env.NODE_ENV)) return _.includes(PRODUCTIONS, process.env.NODE_ENV.toLowerCase());
339
+ return false;
340
+ };
341
+
342
+ process.env.SERVER_LOCAL_IPV4 = ip.address();
343
+ process.env.AWS_LOCAL_PROPERTIES = DEFAULT_AWS_LOCAL_PROPERTIES;
344
+ process.env.CONSOLE_LEVEL = process.env.CONSOLE_LEVEL || DEFAULT_LOG_LEVEL;
345
+ process.env.LOG_LEVEL = process.env.LOG_LEVEL || DEFAULT_LOG_LEVEL;
346
+ process.env.SERVER_ID = process.env.SERVER_ID || uuid.v4();
347
+
348
+ const configuration = {
349
+ nodeEnvironment: process.env.NODE_ENV || DEFAULT_ENV,
350
+ locationProvider: process.env.LOCATION_PROVIDER || DEFAULT_LOCATION_PROVIDER,
351
+ cloudProvider: process.env.CLOUD_PROVIDER || DEFAULT_CLOUD_PROVIDER,
352
+ serverSettings: {
353
+ id: process.env.SERVER_ID,
354
+ customerCode: process.env.CUSTOMER_CODE || DEFAULT_CUSTOMER_CODE,
355
+ customerCodeSep: process.env.CUSTOMER_CODE ? CUSTOMER_CODE_SEP : '',
356
+ securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
357
+ port: process.env.SERVER_PORT,
358
+ interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
359
+ ip: {
360
+ local: process.env.SERVER_LOCAL_IPV4,
361
+ },
362
+ public: {
363
+ protocol: process.env.SERVER_PUBLIC_PROTOCOL || DEFAULT_SERVER_PUBLIC_PROTOCOL,
364
+ domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME || DEFAULT_SERVER_PUBLIC_DOMAIN_NAME,
365
+ },
366
+ },
367
+ security: {
368
+ admin: {
369
+ externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
370
+ },
371
+ server: {
372
+ id: process.env.OAUTH_CLIENT_ID,
373
+ secret: process.env.OAUTH_CLIENT_SECRET,
374
+ accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
375
+ audience: process.env.OAUTH_CLIENT_AUDIENCE,
376
+ issuer: process.env.OAUTH_ISSUER,
377
+ },
378
+ generic: {
379
+ key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
380
+ audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
381
+ },
382
+ apiKeys: process.env.API_KEYS ? _.split(_.trim(process.env.API_KEYS), /\s*,\s*/) : [],
383
+ },
384
+ cluster: {
385
+ management: process.env.CLUSTER_MANAGEMENT || DEFAULT_CLUSTER_MANAGEMENT,
386
+ timeout: parseInt(process.env.REQUEST_TIMEOUT, 10) || DEFAULT_REQUEST_TIMEOUT,
387
+ },
388
+ cache: {
389
+ set: process.env.CACHE_SET || DEFAULT_CACHE_SET,
390
+ },
391
+ encryption: {
392
+ set: process.env.ENCRYPTION_SET || DEFAULT_ENCRYPTION_SET,
393
+ },
394
+ topic: {
395
+ set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
396
+ },
397
+ dependencies: { // everyserver will resport to mIT
398
+ mIT: {
399
+ url: process.env.MIT_URL,
400
+ audience: process.env.MIT_AUDIENCE,
401
+ },
402
+ },
403
+ registration: {
404
+ set: process.env.REGISTRATION_SET || DEFAULT_REGISTRATION_SET,
405
+ retry: parseInt(process.env.REGISTRATION_RETRY, 10) || DEFAULT_REGISTRATION_RETRY,
406
+ },
407
+ };
408
+
409
+ if (process.env.OAUTH_GENERIC_PREVIOUS_KEY) configuration.security.generic.previousKey = process.env.OAUTH_GENERIC_PREVIOUS_KEY;
410
+ if (process.env.SWAGGER_API_KEY) configuration.serverSettings.apiKey = process.env.SWAGGER_API_KEY;
411
+ configuration.logInfo = setupLog();
412
+ configuration.locationProvider = setupLocationProvider();
413
+
279
414
  /**
280
415
  * Set the configuration of the micro-service.
281
416
  *
@@ -292,13 +427,16 @@ const checkConfig = (config) => {
292
427
  *
293
428
  * | Env variable name | Description | Value | Comments |
294
429
  * | ----------------- | ----------- | ----- | -------- |
295
- * | SERVER_VERSION | version of the software for the micro-service| package.version |
296
- * | SERVER_NAME | name of the micro-service | package.[]()name |
297
- * | SERVER_TYPE | type of the micro-service | package.type |
298
- * | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version |
299
- * | SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() |
300
- * | CONSOLE_LEVEL | log level for console output | debug | if not already set
301
- * | LOG_LEVEL | log level for the logger service | debug | if not already set
430
+ * | SERVER_VERSION | version of the software for the micro-service | package.version | serverSettings.version
431
+ * | SERVER_NAME | name of the micro-service | package.name | serverSettings.name
432
+ * | SERVER_TYPE | type of the micro-service | package.mimik.type | serverSettings.type
433
+ * | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version | serverSettings.swaggerFileVersion
434
+ * | SWAGGER_FILE_ACCOUNT | account associated with the API | package.swaggerFile.account |
435
+ * | SWAGGER_FILE_NAME | name of the API | package.swaggerFile.name |
436
+ * | SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() | serverSettings.ip.local
437
+ * | CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel
438
+ * | LOG_LEVEL | log level for console output | debug | logInfo.logLevel
439
+ * | AWS_LOCAL_PROPERTIES | internal ip address to access aws insrance properties | 169.254.169.254
302
440
  *
303
441
  * The following environement variables are being used for the configuration:
304
442
  *
@@ -308,46 +446,42 @@ const checkConfig = (config) => {
308
446
  * | LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
309
447
  * | LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
310
448
  * | CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
311
- * | AWS_ACCESS_KEY_ID | aws access key id for the account | ----noAccessKeyId---- | aws.accessKeyId |
312
- * | AWS_SECRET_ACCESS_KEY | secret for the aws access key id for the account | ----noAccessKey---- | aws.secretAccessKey |
313
- * | AWS_REGION | aws region for the account | ----noRegion---- | aws.region |
314
449
  * | SERVER_ID | service id | uuid.v4() | serverSettings.id |
450
+ * | CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
315
451
  * | SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ./api | serverSettings.api | [1]
452
+ * | SWAGGER_API_KEY | key on swagger hub for provate api access | | serverSettings.apiKey
316
453
  * | SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
317
454
  * | INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
318
455
  * | SERVER_PORT | port of the server | | serverSettings.port |
319
- * | SERVER_NAME | name of the micro-service | | serverSettings.[]()name | see setup environment variable
320
- * | SERVER_TYPE | type of the micro-service | | serverSettings.type | see setup environment variable
321
- * | SERVER_VERSION | version of the software for the micro-service | | serverSettings.version | see setup environment variable
322
- * | SWAGGER_FILE_VERSION | version of the swagger file for the API | | serverSettings.swaggerFileVersion | see setup environment variable
323
- * | SERVER_LOCAL_IPV4 | ip address of the server | | serverSettings.ip.local | see setup environment variable
324
456
  * | SERVER_PUBLIC_PROTOCOL | protocol used to defined the domain address of the sevice | http: | serverSettings.public.protocol |
325
457
  * | SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
326
458
  * | ADMIN_EXTERNAL_ID | external id of the admin role to be chacked in the token | admin | security.admin.externalId |
327
- * | OAUTH_CLIENT_ID | security id of the service | | security.server.[]()id | [2]
459
+ * | OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
328
460
  * | OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
329
461
  * | OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
330
462
  * | OAUTH_CLIENT_AUDIENCE | url representing the server to mST | | security.server.audience | [2]
331
463
  * | OAUTH_ISSUER | token url of mST | | security.server.issuer | [2]
332
464
  * | OAUTH_GENERIC_KEY | key for token signature provided when a generic for this service type is defined | noGeneric | security.generic.key | [2]
465
+ * | OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
333
466
  * | OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
334
- * | CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel | see setup environment variable
335
- * | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`
336
- * | LOG_LEVEL | log level for console output | debug | logInfo.logLevel | see setup environment variable
467
+ * | API_KEYS | list of API Keys which a test against in case of APIKey security | [] |
468
+ * | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
469
+ * | NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
337
470
  * | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
338
471
  * | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
339
472
  * | CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
340
473
  * | REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
341
474
  * | CACHE_SET | switch to enable use of cache | off | cache.set | can be `on`, `off`
342
475
  * | TOPIC_SET | switch to enable use of event topic | off | topic.set | can be `on`, `off`, `mock`
476
+ * | ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
343
477
  * | MIT_URL | url for reaching mIT | | dependencies.mIT.url |
344
478
  * | MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
345
479
  * | REGISTRATION_SET | swicht to enable user of registration | on | registration.set | can be `on` or `off`
346
480
  * | REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
347
- * | `(SERVER_TYPE)`_URL | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
348
- * | `(SERVER_TYPE)`_AUDIENCE | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
481
+ * | `${configuration.serverSettings.type}_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
482
+ * | `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
349
483
  *
350
- * [1]: `/(SERVER_NAME)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
484
+ * [1]: `/(SWAGGER_FILE_ACCOUNT)_(SERVER_TYPE)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
351
485
  *
352
486
  * [2]: defined when registering to mST
353
487
  *
@@ -374,149 +508,110 @@ const checkConfig = (config) => {
374
508
  *
375
509
  * | Env variable name | Description | Default | Comments |
376
510
  * | ----------------- | ----------- | ------- | -------- |
377
- * | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | ----noAccessKeyId---- |
378
- * | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | ----noAccessKey---- |
511
+ * | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | |
512
+ * | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
379
513
  * | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
380
514
  *
381
515
  * When `mongodb` is used the following environment variables are used for the configuration:
382
516
  *
383
- *| Env variable name | Description | Default | Comments |
384
- *| ----------------- | ----------- | ------- | -------- |
385
- *| DATABASE_NAME | name of the database to store the information | |
386
- *| DATABASE_IP | ip address of the database | localhost |
387
- *| DATABASE_USER | user to access the database | null | if missing no user/password will be used
388
- *| DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
389
- *| DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
390
- *| MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
391
- *| MONGO_MIN_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
392
- *| MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 3000 | in milliseconds
393
- *| MONGO_SSL | uses ssl connection if true | false |
394
- *| MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to true | true | true if MONGO_SSL is also true
395
- *| MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
396
- *| 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
397
- *| MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
398
- *| MONGO_AUTO_RECONNECT | enable the ability to reconnect when connection is lost | true |
399
- *| MONGO_RECONNECT_TRIES | number of tries before generating an error | 100 |
400
- *| MONGO_RECONNECT_INTERVAL | time between reconnect tries | 500 | in milliseconds
401
- *| MONGO_KEEP_ALIVE | | true |
402
- *| MONGO_BUFFER_MAX_ENTRIES | | 0 |
403
- *| MONGO_BUFFER_COMMANDS | | false |
404
- *| MONGO_CONNECT_TIMEOUT | the time in milliseconds to attempt a connection before timing out | null | in milliseconds
405
- *| MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | null | in milliseconds
406
-
517
+ * | Env variable name | Description | Default | Comments |
518
+ * | ----------------- | ----------- | ------- | -------- |
519
+ * | DATABASE_NAME | name of the database to store the information | |
520
+ * | DATABASE_IP | ip address of the database | localhost |
521
+ * | DATABASE_USER | user to access the database | null | if missing no user/password will be used
522
+ * | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
523
+ * | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
524
+ * | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
525
+ * | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
526
+ * | MONGO_AUTH_DATABASE | the auth database where users exists | |
527
+ * | MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
528
+ * | MONGO_MIN_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
529
+ * | MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 3000 | in milliseconds
530
+ * | MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
531
+ * | MONGO_WRITE_CONCERN | accepts a number or `majority` | |
532
+ * | MONGO_SSL | uses ssl connection if `yes` | `no` |
533
+ * | MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
534
+ * | MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allows invalid hostnames | |
535
+ * | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
536
+ * | 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
537
+ * | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
538
+ * | MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
539
+ * | MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
540
+ * | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
541
+ * | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
542
+ * | 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
543
+ * | MONGO_HEARTBEAT_FREQUENCY | the MongoDB driver sends a heartbeat every heartbeatFrequencyMS to check on the status of the connection | 10000 | in milliseconds
544
+ *
545
+ * When `on` is used for `ENCRYPTION_SET` the following environment variables are used for the configuration:
546
+ *
547
+ * | Env variable name | Description | Default | Comments |
548
+ * | ----------------- | ----------- | ------- | -------- |
549
+ * | ENCRYPTION_DATABASE | database name where data encryption keyvault exists | admin |
550
+ * | KEY_VAULT_TABLE | collection name which has data encryption keys | keystore |
551
+ * | KMS_PROVIDER | Key Management service provider for master key | local |
552
+ * | MASTER_KEY_AWS_REGION | if KMS is aws region where master key exists | ----noRegion---- |
553
+ * | MASTER_KEY_ARN | if KMS is aws ARN of master key | |
554
+ * | ENCRYPTION_ACCESS_KEY_ID | if KMS is aws, accessKeyId to connect KMS | |
555
+ * | ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
556
+ * | LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
557
+ *
407
558
  * When `dynamodb` is used the following environement variables are used for the configuration:
408
559
  *
409
- *| Env variable name | Description | Default | Comments |
410
- *| ----------------- | ----------- | ------- | -------- |
411
- *| DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | ----noAccessKeyId---- |
412
- *| DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | ----noSecretAccessKey---- |
413
- *| DYNAMODB_AWS_REGION | region where dynamodb is | ----noRegion---- |
414
- *| DYNAMODB_LOCAL_URL | url access the locally deploy dynamodb | http://localhost:8000 |
415
- *| DYNAMO_THROUGHPUT_READ | throughput read for dynamodb index | 1 |
416
- *| DYNAMO_THROUGHPUT_WRITE | throughput write for dynamodb index | 1 |
560
+ * | Env variable name | Description | Default | Comments |
561
+ * | ----------------- | ----------- | ------- | -------- |
562
+ * | DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | |
563
+ * | DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | |
564
+ * | DYNAMODB_AWS_REGION | region where dynamodb is | ----noRegion---- |
565
+ * | DYNAMODB_LOCAL_URL | url access the locally deploy dynamodb | http://localhost:8000 |
566
+ * | DYNAMO_THROUGHPUT_READ | throughput read for dynamodb index | 1 |
567
+ * | DYNAMO_THROUGHPUT_WRITE | throughput write for dynamodb index | 1 |
568
+ * | DYNAMO_SCHEMA_THROUGHPUT_READ | throughput read for dynamodb schema | 1 |
569
+ * | DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
570
+ * | DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
571
+ *
572
+ * `DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput wont apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
417
573
  *
418
574
  * When `redis` is used the following environement variables are used for the configuration:
419
575
  *
420
- *| Env variable name | Description | Default | Comments |
421
- *| ----------------- | ----------- | ------- | -------- |
422
- *| CACHE_IP | domain of the redis server to use | localhost:6379 |
423
- *| CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
424
- *| CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 20 | in seconds
425
- *| CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
426
- *| CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
427
- *| CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
428
- *| REDIS_RECONNECT_TRIES | number of tries to restablish a connection | 100 |
429
- *| REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
430
- *| REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
431
- *| REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
432
- *| REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
433
- *| REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
576
+ * | Env variable name | Description | Default | Comments |
577
+ * | ----------------- | ----------- | ------- | -------- |
578
+ * | CACHE_IP | domain of the redis server to use | localhost:6379 |
579
+ * | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
580
+ * | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 20 | in seconds
581
+ * | CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
582
+ * | CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
583
+ * | CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
584
+ * | REDIS_RECONNECT_TRIES | number of tries to restablish a connection | 100 |
585
+ * | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
586
+ * | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
587
+ * | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
588
+ * | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
589
+ * | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
434
590
  */
435
591
  const setConfig = (pack, options) => {
436
592
  process.env.SERVER_VERSION = pack.version;
437
593
  process.env.SERVER_NAME = pack.name;
438
- process.env.SERVER_TYPE = pack.type;
439
- process.env.SWAGGER_FILE_VERSION = pack.swaggerFile.version;
440
- process.env.SERVER_LOCAL_IPV4 = ip.address();
441
- process.env.AWS_LOCAL_PROPERTIES = DEFAULT_AWS_LOCAL_PROPERTIES;
442
-
443
- // we need to setup the env variables for the logger
444
- process.env.CONSOLE_LEVEL = process.env.CONSOLE_LEVEL || DEFAULT_LOG_LEVEL;
445
- process.env.LOG_LEVEL = process.env.LOG_LEVEL || DEFAULT_LOG_LEVEL;
446
-
447
- const configuration = {
448
- nodeEnvironment: process.env.NODE_ENV || DEFAULT_ENV,
449
- locationProvider: process.env.LOCATION_PROVIDER || DEFAULT_LOCATION_PROVIDER,
450
- cloudProvider: process.env.CLOUD_PROVIDER || DEFAULT_CLOUD_PROVIDER,
451
- aws: {
452
- accessKeyId: process.env.AWS_ACCESS_KEY_ID || DEFAULT_AWS_ACCESS_KEY_ID,
453
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || DEFAULT_AWS_SECRET_ACCESS_KEY,
454
- region: process.env.AWS_REGION || DEFAULT_AWS_REGION,
455
- },
456
- serverSettings: {
457
- id: process.env.SERVER_ID || uuid.v4(),
458
- api: `${process.env.SWAGGER_FILE_DIRECTORY || DEFAULT_SWAGGER_DIR}/${process.env.SERVER_NAME}${SWAGGER_SEP}${process.env.SWAGGER_FILE_VERSION}${SWAGGER_SEP}${SWAGGER_EXT}`,
459
- securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
460
- port: process.env.SERVER_PORT,
461
- name: process.env.SERVER_NAME,
462
- type: process.env.SERVER_TYPE,
463
- version: process.env.SERVER_VERSION,
464
- swaggerFileVersion: process.env.SWAGGER_FILE_VERSION,
465
- interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
466
- ip: {
467
- local: process.env.SERVER_LOCAL_IPV4,
468
- },
469
- public: {
470
- protocol: process.env.SERVER_PUBLIC_PROTOCOL || DEFAULT_SERVER_PUBLIC_PROTOCOL,
471
- domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME || DEFAULT_SERVER_PUBLIC_DOMAIN_NAME,
472
- },
473
- },
474
- security: {
475
- admin: {
476
- externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
477
- },
478
- server: {
479
- id: process.env.OAUTH_CLIENT_ID,
480
- secret: process.env.OAUTH_CLIENT_SECRET,
481
- accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
482
- audience: process.env.OAUTH_CLIENT_AUDIENCE,
483
- issuer: process.env.OAUTH_ISSUER,
484
- },
485
- generic: {
486
- key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
487
- audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
488
- },
489
- },
490
- cluster: {
491
- management: process.env.CLUSTER_MANAGEMENT || DEFAULT_CLUSTER_MANAGEMENT,
492
- timeout: parseInt(process.env.REQUEST_TIMEOUT, 10) || DEFAULT_REQUEST_TIMEOUT,
493
- },
494
- cache: {
495
- set: process.env.CACHE_SET || DEFAULT_CACHE_SET,
496
- },
497
- topic: {
498
- set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
499
- },
500
- dependencies: { // everyserver will resport to mIT
501
- mIT: {
502
- url: process.env.MIT_URL,
503
- audience: process.env.MIT_AUDIENCE,
504
- },
505
- },
506
- registration: {
507
- set: process.env.REGISTRATION_SET || DEFAULT_REGISTRATION_SET,
508
- retry: parseInt(process.env.REGISTRATION_RETRY, 10) || DEFAULT_REGISTRATION_RETRY,
509
- },
510
- };
511
- // setup the log configuration
512
- configuration.logInfo = setupLog();
594
+ if (pack.mimik) process.env.SERVER_TYPE = pack.mimik.type;
595
+ if (pack.swaggerFile) {
596
+ process.env.SWAGGER_FILE_VERSION = pack.swaggerFile.version;
597
+ process.env.SWAGGER_FILE_ACCOUNT = pack.swaggerFile.account;
598
+ process.env.SWAGGER_FILE_NAME = pack.swaggerFile.name;
599
+ }
600
+
601
+ const apiFilename = `${process.env.SWAGGER_FILE_ACCOUNT}${SWAGGER_SEP}${process.env.SWAGGER_FILE_NAME}${SWAGGER_SEP}${process.env.SWAGGER_FILE_VERSION}${SWAGGER_SEP}${SWAGGER_EXT}`;
602
+
603
+ configuration.serverSettings.name = process.env.SERVER_NAME;
604
+ configuration.serverSettings.type = process.env.SERVER_TYPE;
605
+ configuration.serverSettings.version = process.env.SERVER_VERSION;
606
+ configuration.serverSettings.api = `${process.env.SWAGGER_FILE_DIRECTORY || DEFAULT_SWAGGER_DIR}/${apiFilename}`;
607
+ configuration.serverSettings.swaggerFileVersion = process.env.SWAGGER_FILE_VERSION;
608
+
513
609
  // default for every server for cluster management
514
610
  configuration.dependencies[configuration.serverSettings.type] = {
515
611
  url: process.env[`${configuration.serverSettings.type}_URL`.toUpperCase()] || 'self', // this url should never be needed
516
612
  audience: process.env[`${configuration.serverSettings.type}_AUDIENCE`.toUpperCase()],
517
613
  };
518
614
 
519
- configuration.locationProvider = setupLocationProvider();
520
615
  if (options.database) {
521
616
  if (options.database.type === 'mongodb') {
522
617
  configuration.mongoSettings = setupMongo(options.database);
@@ -545,6 +640,9 @@ const setConfig = (pack, options) => {
545
640
  if (options.topic && configuration.topic.set === SET_ON) {
546
641
  configuration.topicSettings = setupTopic(options.topic);
547
642
  }
643
+ if (options.encryption && configuration.encryption.set === SET_ON) {
644
+ configuration.encryption = setupEncryption(options.encryption);
645
+ }
548
646
  if (options.dependencies) {
549
647
  Object.keys(options.dependencies).forEach((dependency) => {
550
648
  configuration.dependencies[dependency] = options.dependencies[dependency];
@@ -573,4 +671,5 @@ const setConfig = (pack, options) => {
573
671
 
574
672
  module.exports = {
575
673
  setConfig,
674
+ isProd,
576
675
  };
package/lib/common.js CHANGED
@@ -8,12 +8,16 @@ const NO_PUBLIC_PROVIDER = 'noPublic';
8
8
  const ENV_VARIABLE = 'environment';
9
9
  const REDIS_BASE_URL = 'redis://';
10
10
  const MONGO_BASE_URL = 'mongodb://';
11
+ const MONGO_BASE_URL_SRV = 'mongodb+srv://';
11
12
  const SWAGGER_EXT = 'swagger.json';
12
13
  const SWAGGER_SEP = '_';
14
+ const CUSTOMER_CODE_SEP = '__';
15
+ const PRODUCTIONS = ['prod', 'production'];
13
16
 
14
17
  const DEFAULT_ENV = 'local';
15
18
  const DEFAULT_LOCATION_PROVIDER = NO_PUBLIC_PROVIDER;
16
19
  const DEFAULT_CLOUD_PROVIDER = 'noCloud';
20
+ const DEFAULT_CUSTOMER_CODE = '';
17
21
 
18
22
  const DEFAULT_CACHE_IP = 'localhost:6379';
19
23
  const DEFAULT_CACHE_PASSWORD = null;
@@ -29,31 +33,32 @@ const DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY = 'allkeys-lru';
29
33
  const DEFAULT_REDIS_SOCKET_KEEPALIVE = true;
30
34
  const DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE = true;
31
35
 
32
- const DEFAULT_AWS_ACCESS_KEY_ID = '---noAccessKeyId---';
33
- const DEFAULT_AWS_SECRET_ACCESS_KEY = '---noSecretAccessKey---';
34
36
  const DEFAULT_AWS_REGION = '---noRegion--';
35
37
  const DEFAULT_AWS_LOCAL_PROPERTIES = '169.254.169.254'; // to access properties of the instance on AWS
36
38
 
37
39
  const DEFAULT_DYNAMODB_LOCAL_URL = 'http://localhost:8000';
38
40
  const DEFAULT_DYNAMO_THROUGHPUT_READ = 1;
39
41
  const DEFAULT_DYNAMO_THROUGHPUT_WRITE = 1;
42
+ const DEFAULT_DYNAMO_THROUGHPUT = 1;
40
43
 
41
44
  const DEFAULT_MONGO_MAX_POOL_SIZE = 10;
42
45
  const DEFAULT_MONGO_MIN_POOL_SIZE = 5;
43
46
  const DEFAULT_MONGO_MAX_IDLE_TIME = 3000; // in ms
44
- const DEFAULT_MONGO_AUTO_RECONNECT = true;
45
- const DEFAULT_MONGO_RECONNECT_TRIES = 100;
46
- const DEFAULT_MONGO_RECONNECT_INTERVAL = 500; // in ms
47
47
  const DEFAULT_MONGO_KEEP_ALIVE = true;
48
- const DEFAULT_MONGO_BUFFER_MAX_ENTRIES = 0;
49
- const DEFAULT_MONGO_BUFFER_COMMANDS = false;
50
- const DEFAULT_MONGO_CONNECT_TIMEOUT = null; // in ms
51
- const DEFAULT_MONGO_SOCKET_TIMEOUT = null; // in ms
48
+ const DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY = 300000; // in ms
49
+ const DEFAULT_MONGO_SOCKET_TIMEOUT = 20000; // in ms
50
+ const DEFAULT_MONGO_FAMILY = 4; // 4 -> ipv4, 6 -> ipv6
51
+ const DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT = 30000; // in ms
52
+ const DEFAULT_MONGO_HEARTBEAT_FREQUENCY = 10000; // in ms
52
53
 
53
54
  const DEFAULT_DATABASE_IP = 'localhost';
54
55
  const DEFAULT_DATABASE_USER = null;
55
56
  const DEFAULT_DATABASE_PASSWORD = null;
56
57
  const DEFAULT_DATABASE_CONNECTION_TIMEOUT = 30; // in seconds
58
+ const DEFAULT_DATABASE_RECONNECTION_OFFSET = 5; // in seconds
59
+
60
+ const DEFAULT_ENCRYPTION_SET = SET_OFF;
61
+ const DEFAULT_KMS_PROVIDER = 'local';
57
62
 
58
63
  const DEFAULT_LOG_LEVEL = 'debug';
59
64
  const DEFAULT_FILTER_FILE = 'not set';
@@ -79,20 +84,24 @@ const DEFAULT_SERVER_PUBLIC_DOMAIN_NAME = null;
79
84
 
80
85
  const DEFAULT_ADMIN_EXTERNAL_ID = 'admin';
81
86
 
82
- const DEFAULT_SWAGGER_DIR = './api';
87
+ const DEFAULT_SWAGGER_DIR = '../api';
83
88
 
84
89
  module.exports = {
85
90
  SUMOLOGIC,
86
91
  AWS_S3,
87
92
  ALL,
88
93
  SET_ON,
94
+ CUSTOMER_CODE_SEP,
89
95
  NO_PUBLIC_PROVIDER,
90
96
  NO_GENERIC,
91
97
  ENV_VARIABLE,
98
+ DEFAULT_CUSTOMER_CODE,
92
99
  REDIS_BASE_URL,
93
100
  MONGO_BASE_URL,
101
+ MONGO_BASE_URL_SRV,
94
102
  SWAGGER_EXT,
95
103
  SWAGGER_SEP,
104
+ PRODUCTIONS,
96
105
  DEFAULT_ENV,
97
106
  DEFAULT_LOCATION_PROVIDER,
98
107
  DEFAULT_CLOUD_PROVIDER,
@@ -108,28 +117,28 @@ module.exports = {
108
117
  DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
109
118
  DEFAULT_REDIS_SOCKET_KEEPALIVE,
110
119
  DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
111
- DEFAULT_AWS_ACCESS_KEY_ID,
112
- DEFAULT_AWS_SECRET_ACCESS_KEY,
113
120
  DEFAULT_AWS_REGION,
114
121
  DEFAULT_AWS_LOCAL_PROPERTIES,
115
122
  DEFAULT_DYNAMODB_LOCAL_URL,
116
123
  DEFAULT_DYNAMO_THROUGHPUT_READ,
117
124
  DEFAULT_DYNAMO_THROUGHPUT_WRITE,
125
+ DEFAULT_DYNAMO_THROUGHPUT,
118
126
  DEFAULT_MONGO_MAX_POOL_SIZE,
119
127
  DEFAULT_MONGO_MIN_POOL_SIZE,
120
128
  DEFAULT_MONGO_MAX_IDLE_TIME,
121
- DEFAULT_MONGO_AUTO_RECONNECT,
122
- DEFAULT_MONGO_RECONNECT_TRIES,
123
- DEFAULT_MONGO_RECONNECT_INTERVAL,
124
129
  DEFAULT_MONGO_KEEP_ALIVE,
125
- DEFAULT_MONGO_BUFFER_MAX_ENTRIES,
126
- DEFAULT_MONGO_BUFFER_COMMANDS,
127
- DEFAULT_MONGO_CONNECT_TIMEOUT,
130
+ DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
128
131
  DEFAULT_MONGO_SOCKET_TIMEOUT,
132
+ DEFAULT_MONGO_FAMILY,
133
+ DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
134
+ DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
129
135
  DEFAULT_DATABASE_IP,
130
136
  DEFAULT_DATABASE_USER,
131
137
  DEFAULT_DATABASE_PASSWORD,
132
138
  DEFAULT_DATABASE_CONNECTION_TIMEOUT,
139
+ DEFAULT_DATABASE_RECONNECTION_OFFSET,
140
+ DEFAULT_ENCRYPTION_SET,
141
+ DEFAULT_KMS_PROVIDER,
133
142
  DEFAULT_LOG_LEVEL,
134
143
  DEFAULT_FILTER_FILE,
135
144
  DEFAULT_EXIT_DELAY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "1.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,8 @@
8
8
  "docs": "gulp docs",
9
9
  "test": "exit 0",
10
10
  "prepublishOnly": "gulp docs; gulp lint; npm run test",
11
- "commit-ready": "gulp docs; gulp lint; npm run test"
11
+ "commit-ready": "gulp docs; gulp lint; npm run test",
12
+ "prepare": "husky install"
12
13
  },
13
14
  "husky": {
14
15
  "hooks": {
@@ -21,30 +22,33 @@
21
22
  "microservice",
22
23
  "config"
23
24
  ],
24
- "author": "mimik",
25
+ "author": "mimik technology inc <support@mimik.com> (https://developer.mimik.com/)",
25
26
  "license": "Apache-2.0",
26
27
  "repository": {
27
28
  "type": "git",
28
29
  "url": "https://bitbucket.org/mimiktech/configuration"
29
30
  },
30
31
  "dependencies": {
31
- "@mimik/sumologic-winston-logger": "1.2.0",
32
+ "@mimik/request-helper": "^1.7.3",
33
+ "@mimik/sumologic-winston-logger": "^1.6.6",
32
34
  "ip": "1.1.5",
33
- "lodash": "4.17.15",
34
- "uuid": "3.3.3"
35
+ "lodash": "4.17.21",
36
+ "uuid": "8.3.2"
35
37
  },
36
38
  "devDependencies": {
37
- "eslint": "6.3.0",
38
- "eslint-config-airbnb": "18.0.1",
39
- "eslint-plugin-import": "2.18.2",
40
- "eslint-plugin-jsx-a11y": "6.2.3",
41
- "eslint-plugin-react": "7.14.3",
42
- "eslint-plugin-react-hooks": "2.0.1",
39
+ "@mimik/eslint-plugin-dependencies": "^2.4.1",
40
+ "@mimik/eslint-plugin-document-env": "^1.0.0",
41
+ "eslint": "8.4.1",
42
+ "eslint-config-airbnb": "18.2.1",
43
+ "eslint-plugin-import": "2.25.3",
44
+ "eslint-plugin-jsx-a11y": "6.5.1",
45
+ "eslint-plugin-react": "7.27.1",
46
+ "eslint-plugin-react-hooks": "4.3.0",
43
47
  "fancy-log": "1.3.3",
44
48
  "gulp": "4.0.2",
45
49
  "gulp-eslint": "6.0.0",
46
- "gulp-git": "2.9.0",
47
- "husky": "3.0.5",
48
- "jsdoc-to-markdown": "5.0.1"
50
+ "gulp-git": "2.10.1",
51
+ "husky": "7.0.4",
52
+ "jsdoc-to-markdown": "7.1.0"
49
53
  }
50
54
  }