@mimik/configuration 6.0.5 → 6.0.7
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/.claude/settings.local.json +14 -0
- package/.husky/pre-commit +0 -2
- package/.husky/pre-push +0 -2
- package/README.md +26 -24
- package/eslint.config.js +31 -11
- package/index.js +127 -192
- package/lib/common.js +7 -142
- package/package.json +21 -23
- package/test/configuration.spec.js +1038 -0
- package/test/testEnv.js +46 -0
- package/.nycrc +0 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(npm run lint)",
|
|
5
|
+
"Bash(cat /Users/niburger/Projects/mimik/common/response-helper-145/test/*.js)",
|
|
6
|
+
"Bash(ls -d /Users/niburger/Projects/mimik/common/*/test/)",
|
|
7
|
+
"Bash(grep -rl \"esmock\" /Users/niburger/Projects/mimik/common/*/package.json)",
|
|
8
|
+
"Bash(npm install)",
|
|
9
|
+
"Bash(npm test)",
|
|
10
|
+
"Bash(npx eslint test/)",
|
|
11
|
+
"Bash(npx eslint test/ --fix)"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
package/.husky/pre-commit
CHANGED
package/.husky/pre-push
CHANGED
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ The following environment variables are used
|
|
|
24
24
|
|
|
25
25
|
| Env variable name | Description | Value | Comments |
|
|
26
26
|
| ----------------- | ----------- | ----- | -------- |
|
|
27
|
-
| NODE_ENV |
|
|
27
|
+
| NODE_ENV | environment of the microservice |
|
|
28
28
|
**Category**: sync
|
|
29
29
|
<a name="module_configuration..setConfig"></a>
|
|
30
30
|
|
|
@@ -36,7 +36,7 @@ Set the configuration of the micro-service.
|
|
|
36
36
|
**Category**: sync
|
|
37
37
|
**Throws**:
|
|
38
38
|
|
|
39
|
-
- <code>configuration.serverSettings.type</code> Will
|
|
39
|
+
- <code>configuration.serverSettings.type</code> Will throw an error if a mandatory value is missing.
|
|
40
40
|
|
|
41
41
|
The following environment variables are being setup:
|
|
42
42
|
|
|
@@ -55,7 +55,7 @@ The following environment variables are being setup:
|
|
|
55
55
|
| AWS_LOCAL_PROPERTIES | internal ip address to access aws instance properties | 169.254.169.254
|
|
56
56
|
| MST_SET | to setup configuration without mST and oauth token setup | on | on/off
|
|
57
57
|
|
|
58
|
-
The following
|
|
58
|
+
The following environment variables are being used for the configuration:
|
|
59
59
|
|
|
60
60
|
| Env variable name | Description | Default | Config property | Comments |
|
|
61
61
|
| ----------------- | ----------- | ------- | ----------------| -------- |
|
|
@@ -63,18 +63,18 @@ The following environement variables are being used for the configuration:
|
|
|
63
63
|
| LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
|
|
64
64
|
| LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
|
|
65
65
|
| CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
|
|
66
|
-
| SERVER_ID | service id |
|
|
66
|
+
| SERVER_ID | service id | crypto.randomUUID() | serverSettings.id |
|
|
67
67
|
| CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
|
|
68
|
-
| SWAGGER_FILE_DIRECTORY | directory where the api definition is located |
|
|
68
|
+
| SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ../api | serverSettings.api | [1]
|
|
69
69
|
| BITBUCKET_USERNAME | username to access bitbucket read access on the swagger repos | ' ' | serverSettings.apiBasicAuth.username
|
|
70
70
|
| BITBUCKET_PASSWORD | password to access bitbucket read access on the swagger repos | ' ' | serverSettings.apiBasicAuth.password
|
|
71
71
|
| SWAGGERHUB_API_KEY | apiKey to access swaggerhub | | serverSettings.apiApiKey
|
|
72
72
|
| SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
|
|
73
73
|
| INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
|
|
74
74
|
| SERVER_PORT | port of the server | | serverSettings.port |
|
|
75
|
-
| SERVER_PUBLIC_PROTOCOL | protocol used to
|
|
75
|
+
| SERVER_PUBLIC_PROTOCOL | protocol used to define the domain address of the service | http: | serverSettings.public.protocol |
|
|
76
76
|
| SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
|
|
77
|
-
| ADMIN_EXTERNAL_ID | external id of the admin role to be
|
|
77
|
+
| ADMIN_EXTERNAL_ID | external id of the admin role to be checked in the token | admin | security.admin.externalId |
|
|
78
78
|
| OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
|
|
79
79
|
| OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
|
|
80
80
|
| OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
|
|
@@ -84,8 +84,8 @@ The following environement variables are being used for the configuration:
|
|
|
84
84
|
| OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
85
85
|
| OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
86
86
|
| API_KEYS | list of API Keys which a test against in case of APIKey security | [] |
|
|
87
|
-
| LOG_MODE | collector
|
|
88
|
-
| NO_STACK | disable the inclusion of
|
|
87
|
+
| LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
|
|
88
|
+
| NO_STACK | disable the inclusion of the stack in all logs | yes | logInfo.noStack
|
|
89
89
|
| FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
90
90
|
| USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
|
|
91
91
|
| EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
|
|
@@ -98,9 +98,9 @@ The following environement variables are being used for the configuration:
|
|
|
98
98
|
| ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
|
|
99
99
|
| MIT_URL | url for reaching mIT | | dependencies.mIT.url |
|
|
100
100
|
| MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
101
|
-
| REGISTRATION_SET |
|
|
101
|
+
| REGISTRATION_SET | switch to enable use of registration | on | registration.set | can be `on` or `off`
|
|
102
102
|
| REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
103
|
-
| REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration of execution the postOps | off |
|
|
103
|
+
| REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration of execution the postOps | off | registration.afterPostOpsSet | can be `on` or `off`
|
|
104
104
|
| `$_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
105
105
|
| `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
106
106
|
|
|
@@ -108,13 +108,13 @@ The following environement variables are being used for the configuration:
|
|
|
108
108
|
|
|
109
109
|
[2]: defined when registering to mST
|
|
110
110
|
|
|
111
|
-
When MST_SET is `off`, registration and cluster should not be enabled, so configuration.cluster.management and configuration.registration.set will be set to `off
|
|
111
|
+
When MST_SET is `off`, registration and cluster should not be enabled, so configuration.cluster.management and configuration.registration.set will be set to `off`
|
|
112
112
|
|
|
113
113
|
When `sumologic` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
|
|
114
114
|
|
|
115
115
|
| Env variable name | Description | Default | Comments |
|
|
116
116
|
| ----------------- | ----------- | ------- | -------- |
|
|
117
|
-
| SUMO_LOGIC_ENDPOINT | endpoint of the sumologic collector
|
|
117
|
+
| SUMO_LOGIC_ENDPOINT | endpoint of the sumologic collector used for logs |
|
|
118
118
|
| SUMO_LOGIC_COLLECTOR_CODE | id of the collector in sumologic |
|
|
119
119
|
|
|
120
120
|
When `awsS3` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
|
|
@@ -138,7 +138,9 @@ When `on` is used for `TOPIC_SET` the following environment variables are used f
|
|
|
138
138
|
| SNS_AWS_REGION | region where the topic is | ----noRegion---- |
|
|
139
139
|
|
|
140
140
|
When a database is involved
|
|
141
|
+
|
|
141
142
|
| Env variable name | Description | Default | Comments |
|
|
143
|
+
| ----------------- | ----------- | ------- | -------- |
|
|
142
144
|
| DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
|
|
143
145
|
| DATABASE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
|
|
144
146
|
| DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
|
|
@@ -153,16 +155,16 @@ When `mongodb` is used the following environment variables are used for the conf
|
|
|
153
155
|
| DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
|
|
154
156
|
| MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
|
|
155
157
|
| MONGO_AUTH_DATABASE | the auth database where users exists | |
|
|
156
|
-
|
|
|
157
|
-
|
|
|
158
|
-
| MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed |
|
|
158
|
+
| MONGO_MIN_POOL_SIZE | the minimum number of connections in the connection pool | 0 |
|
|
159
|
+
| MONGO_MAX_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
|
|
160
|
+
| MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 30000 | in milliseconds
|
|
159
161
|
| MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
|
|
160
162
|
| MONGO_WRITE_CONCERN | accepts a number or `majority` | |
|
|
161
163
|
| MONGO_SSL | uses ssl connection if `yes` | `no` |
|
|
162
164
|
| MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
|
|
163
165
|
| MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allows invalid hostnames | |
|
|
164
166
|
| MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
|
|
165
|
-
| MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver
|
|
167
|
+
| MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiplies the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | not mandatory
|
|
166
168
|
| MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
|
|
167
169
|
| MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
|
|
168
170
|
| MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
|
|
@@ -182,7 +184,7 @@ When `on` is used for `ENCRYPTION_SET` the following environment variables are u
|
|
|
182
184
|
| ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
|
|
183
185
|
| LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
|
|
184
186
|
|
|
185
|
-
When `dynamodb` is used the following
|
|
187
|
+
When `dynamodb` is used the following environment variables are used for the configuration:
|
|
186
188
|
|
|
187
189
|
| Env variable name | Description | Default | Comments |
|
|
188
190
|
| ----------------- | ----------- | ------- | -------- |
|
|
@@ -196,13 +198,13 @@ When `dynamodb` is used the following environement variables are used for the co
|
|
|
196
198
|
| DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
|
|
197
199
|
| DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
|
|
198
200
|
|
|
199
|
-
`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
|
|
201
|
+
`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 won't apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
|
|
200
202
|
|
|
201
|
-
When `redis` is used the following
|
|
203
|
+
When `redis` is used the following environment variables are used for the configuration:
|
|
202
204
|
|
|
203
205
|
| Env variable name | Description | Default | Comments |
|
|
204
206
|
| ----------------- | ----------- | ------- | -------- |
|
|
205
|
-
| CACHE_IP | domain of the redis server to use with port, a comma
|
|
207
|
+
| CACHE_IP | domain of the redis server to use with port, a comma separated list if using cluster | localhost:6379 |
|
|
206
208
|
| CACHE_USER | redis user if the redis service is auth protected | null |
|
|
207
209
|
| CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
|
|
208
210
|
| CACHE_CLUSTER_SET | set on, when using redis in a cluster. | off |
|
|
@@ -214,9 +216,9 @@ When `redis` is used the following environement variables are used for the confi
|
|
|
214
216
|
| CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
|
|
215
217
|
| CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
|
|
216
218
|
| CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
|
|
217
|
-
| REDIS_RECONNECT_TRIES | number of tries to
|
|
219
|
+
| REDIS_RECONNECT_TRIES | number of tries to reestablish a connection | 100 |
|
|
218
220
|
| REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
|
|
219
|
-
| REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache |
|
|
221
|
+
| REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10mb | in megabytes
|
|
220
222
|
| REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
|
|
221
223
|
| REDIS_SOCKET_KEEPALIVE | keep long running connections alive for x seconds | 5000 | in seconds
|
|
222
224
|
| REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
|
|
@@ -225,6 +227,6 @@ When `redis` is used the following environement variables are used for the confi
|
|
|
225
227
|
|
|
226
228
|
| Param | Type | Description |
|
|
227
229
|
| --- | --- | --- |
|
|
228
|
-
| pack | <code>
|
|
230
|
+
| pack | <code>object</code> | `Package.json` object to use for the configuration. |
|
|
229
231
|
| options | <code>object</code> | Options to add to the config. |
|
|
230
232
|
|
package/eslint.config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
1
2
|
import importPlugin from 'eslint-plugin-import';
|
|
2
3
|
import js from '@eslint/js';
|
|
3
4
|
import processDoc from '@mimik/eslint-plugin-document-env';
|
|
@@ -10,6 +11,9 @@ const MAX_LINES_IN_FUNCTION = 150;
|
|
|
10
11
|
const MAX_STATEMENTS_IN_FUNCTION = 45;
|
|
11
12
|
const MIN_KEYS_IN_OBJECT = 10;
|
|
12
13
|
const MAX_COMPLEXITY = 30;
|
|
14
|
+
const ECMA_VERSION = 'latest';
|
|
15
|
+
const MAX_DEPTH = 6;
|
|
16
|
+
const ALLOWED_CONSTANTS = [0, 1, -1];
|
|
13
17
|
|
|
14
18
|
export default [
|
|
15
19
|
{
|
|
@@ -23,18 +27,18 @@ export default [
|
|
|
23
27
|
processDoc,
|
|
24
28
|
},
|
|
25
29
|
languageOptions: {
|
|
26
|
-
ecmaVersion:
|
|
30
|
+
ecmaVersion: ECMA_VERSION,
|
|
27
31
|
globals: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
it: 'readonly',
|
|
31
|
-
require: 'readonly',
|
|
32
|
+
...globals.mocha,
|
|
33
|
+
...globals.nodeBuiltin,
|
|
32
34
|
},
|
|
33
35
|
sourceType: 'module',
|
|
34
36
|
},
|
|
35
37
|
rules: {
|
|
36
38
|
'@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
|
|
37
39
|
'@stylistic/line-comment-position': ['off'],
|
|
40
|
+
'@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
|
|
41
|
+
'@stylistic/quotes': ['warn', 'single'],
|
|
38
42
|
'@stylistic/semi': ['error', 'always'],
|
|
39
43
|
'capitalized-comments': ['off'],
|
|
40
44
|
'complexity': ['error', MAX_COMPLEXITY],
|
|
@@ -44,20 +48,36 @@ export default [
|
|
|
44
48
|
'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
|
|
45
49
|
'init-declarations': ['off'],
|
|
46
50
|
'linebreak-style': ['off'],
|
|
47
|
-
'max-
|
|
48
|
-
'max-
|
|
49
|
-
'max-lines
|
|
51
|
+
'max-depth': ['error', MAX_DEPTH],
|
|
52
|
+
'max-len': ['off'],
|
|
53
|
+
'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
|
|
54
|
+
'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
|
|
50
55
|
'max-params': ['error', MAX_FUNCTION_PARAMETERS],
|
|
51
56
|
'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
|
|
52
|
-
'no-confusing-arrow': ['off'],
|
|
57
|
+
'no-confusing-arrow': ['off'],
|
|
53
58
|
'no-inline-comments': ['off'],
|
|
59
|
+
'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: true }],
|
|
54
60
|
'no-process-env': ['error'],
|
|
55
61
|
'no-ternary': ['off'],
|
|
56
62
|
'no-undefined': ['off'],
|
|
57
63
|
'one-var': ['error', 'never'],
|
|
58
64
|
'processDoc/validate-document-env': ['error'],
|
|
59
|
-
'quotes': ['
|
|
60
|
-
'sort-
|
|
65
|
+
'quotes': ['off'],
|
|
66
|
+
'sort-imports': ['error', { allowSeparatedGroups: true }],
|
|
67
|
+
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
files: ['test/**/*.js'],
|
|
72
|
+
rules: {
|
|
73
|
+
'class-methods-use-this': ['off'],
|
|
74
|
+
'max-classes-per-file': ['off'],
|
|
75
|
+
'max-lines': ['off'],
|
|
76
|
+
'max-lines-per-function': ['off'],
|
|
77
|
+
'max-statements': ['off'],
|
|
78
|
+
'no-empty-function': ['off'],
|
|
79
|
+
'no-magic-numbers': ['off'],
|
|
80
|
+
'processDoc/validate-document-env': ['off'],
|
|
61
81
|
},
|
|
62
82
|
},
|
|
63
83
|
];
|