node-env-resolver 4.0.0 → 5.0.1
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 +493 -376
- package/dist/audit.d.cts +29 -0
- package/dist/audit.d.ts +8 -7
- package/dist/builder.cjs +1 -1
- package/dist/builder.d.cts +149 -0
- package/dist/builder.d.ts +17 -14
- package/dist/builder.js +1 -1
- package/dist/chunk-4QOKRJ3F.cjs +1 -0
- package/dist/chunk-4YVXFL3I.cjs +9 -0
- package/dist/chunk-6D5APQIG.cjs +1 -0
- package/dist/chunk-DIXI6MUB.js +9 -0
- package/dist/chunk-FH54ESWI.cjs +9 -0
- package/dist/chunk-HHOS5S5T.js +1 -0
- package/dist/chunk-TAX63ALN.js +16 -0
- package/dist/chunk-WKIPEKF6.js +1 -0
- package/dist/chunk-XJLMVSPN.js +9 -0
- package/dist/chunk-XPL5XLTA.cjs +16 -0
- package/dist/cli.d.cts +52 -0
- package/dist/cli.d.ts +9 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +99 -92
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.d.cts +20 -0
- package/dist/resolver.d.ts +8 -5
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +412 -0
- package/dist/resolvers.d.ts +294 -22
- package/dist/resolvers.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +106 -0
- package/dist/types.d.ts +90 -172
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +213 -0
- package/dist/utils.d.ts +28 -26
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.cts +156 -0
- package/dist/valibot.d.ts +11 -8
- package/dist/valibot.js +1 -1
- package/dist/validation-types.d.cts +29 -0
- package/dist/validation-types.d.ts +4 -3
- package/dist/validators.cjs +2 -1
- package/dist/validators.d.cts +116 -0
- package/dist/validators.d.ts +46 -18
- package/dist/validators.js +2 -1
- package/dist/web.cjs +3 -3
- package/dist/web.d.cts +69 -0
- package/dist/web.d.ts +28 -10
- package/dist/web.js +3 -3
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.cts +135 -0
- package/dist/zod.d.ts +11 -8
- package/dist/zod.js +1 -1
- package/package.json +7 -7
- package/dist/advanced-features.test.d.ts +0 -2
- package/dist/advanced-features.test.d.ts.map +0 -1
- package/dist/audit.d.ts.map +0 -1
- package/dist/audit.test.d.ts +0 -2
- package/dist/audit.test.d.ts.map +0 -1
- package/dist/builder.d.ts.map +0 -1
- package/dist/chunk-54OHKWZJ.js +0 -1
- package/dist/chunk-FCFDGYTF.cjs +0 -15
- package/dist/chunk-HCVTYYLE.js +0 -9
- package/dist/chunk-IU5TG3HL.js +0 -15
- package/dist/chunk-J7ZHEMRP.js +0 -9
- package/dist/chunk-NKPXKLF7.js +0 -1
- package/dist/chunk-P3ZWKKKW.cjs +0 -1
- package/dist/chunk-THFGEKYL.cjs +0 -9
- package/dist/chunk-ULL4WKTV.cjs +0 -9
- package/dist/chunk-XPGSWVRT.cjs +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.test.d.ts +0 -2
- package/dist/cli.test.d.ts.map +0 -1
- package/dist/composition.test.d.ts +0 -7
- package/dist/composition.test.d.ts.map +0 -1
- package/dist/computed.test.d.ts +0 -2
- package/dist/computed.test.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/nested.test.d.ts +0 -2
- package/dist/nested.test.d.ts.map +0 -1
- package/dist/performance.test.d.ts +0 -7
- package/dist/performance.test.d.ts.map +0 -1
- package/dist/priority.test.d.ts +0 -6
- package/dist/priority.test.d.ts.map +0 -1
- package/dist/providers.d.ts +0 -11
- package/dist/providers.d.ts.map +0 -1
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolvers.d.ts.map +0 -1
- package/dist/resolvers.test.d.ts +0 -2
- package/dist/resolvers.test.d.ts.map +0 -1
- package/dist/sync-resolvers.test.d.ts +0 -2
- package/dist/sync-resolvers.test.d.ts.map +0 -1
- package/dist/type-inference.test.d.ts +0 -2
- package/dist/type-inference.test.d.ts.map +0 -1
- package/dist/type-override.test.d.ts +0 -2
- package/dist/type-override.test.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/valibot.d.ts.map +0 -1
- package/dist/validation-types.d.ts.map +0 -1
- package/dist/validators.d.ts.map +0 -1
- package/dist/web.d.ts.map +0 -1
- package/dist/zod.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Type-safe environment variable resolution with zero dependencies and ultra-small
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/node-env-resolver)
|
|
6
6
|
|
|
7
|
-
**Bundle Size:** ~
|
|
7
|
+
**Bundle Size:** ~4.3KB gzipped
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -16,12 +16,13 @@ npm install node-env-resolver
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import { resolve } from 'node-env-resolver';
|
|
19
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
19
20
|
|
|
20
21
|
const config = resolve({
|
|
21
22
|
PORT: 3000,
|
|
22
23
|
NODE_ENV: ['development', 'production', 'test'] as const,
|
|
23
24
|
DEBUG: false,
|
|
24
|
-
API_KEY:
|
|
25
|
+
API_KEY: string({optional:true})
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
// config is fully typed
|
|
@@ -34,29 +35,46 @@ config.API_KEY; // string | undefined
|
|
|
34
35
|
## Quick start (with custom resolvers)
|
|
35
36
|
|
|
36
37
|
```ts
|
|
37
|
-
import { resolve, processEnv } from 'node-env-resolver';
|
|
38
|
-
import { dotenv } from 'node-env-resolver/resolvers';
|
|
38
|
+
import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
|
|
39
|
+
import { dotenv, string, url, postgres, redis } from 'node-env-resolver/resolvers';
|
|
40
|
+
import { awsSecrets, gcpSecrets, vaultSecrets } from 'node-env-resolver-aws';
|
|
39
41
|
|
|
40
|
-
// Synchronous with custom resolver (
|
|
41
|
-
const config = resolve(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
]
|
|
42
|
+
// Synchronous with custom resolver (object syntax)
|
|
43
|
+
const config = resolve({
|
|
44
|
+
resolvers: [
|
|
45
|
+
[dotenv(), {
|
|
46
|
+
PORT: 3000,
|
|
47
|
+
NODE_ENV: ['development', 'production', 'test'] as const,
|
|
48
|
+
DEBUG: false,
|
|
49
|
+
API_KEY: string({optional:true})
|
|
50
|
+
}]
|
|
51
|
+
]
|
|
52
|
+
});
|
|
50
53
|
|
|
51
54
|
// Asynchronous with any resolvers (both sync and async work!)
|
|
52
|
-
const config = await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const config = await resolveAsync({
|
|
56
|
+
resolvers: [
|
|
57
|
+
[dotenv(), {
|
|
58
|
+
PORT: 3000,
|
|
59
|
+
NODE_ENV: ['development', 'production', 'test'] as const,
|
|
60
|
+
DEBUG: false,
|
|
61
|
+
API_KEY: string({optional:true})
|
|
62
|
+
}],
|
|
63
|
+
[awsSecrets(), { DATABASE_URL: url() }]
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Multiple resolvers with options
|
|
68
|
+
const config = await resolveAsync({
|
|
69
|
+
resolvers: [
|
|
70
|
+
[processEnv(), { PORT: 3000 }],
|
|
71
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
72
|
+
[awsSecrets(), { API_KEY: string() }],
|
|
73
|
+
[gcpSecrets(), { JWT_SECRET: string() }],
|
|
74
|
+
[vaultSecrets(), { REDIS_URL: redis() }]
|
|
75
|
+
],
|
|
76
|
+
options: { priority: 'last' }
|
|
77
|
+
});
|
|
60
78
|
```
|
|
61
79
|
|
|
62
80
|
## Table of Contents
|
|
@@ -71,7 +89,6 @@ const config = await resolve.async([
|
|
|
71
89
|
- [Enums](#enums)
|
|
72
90
|
- [Variable Naming Conventions](#variable-naming-conventions)
|
|
73
91
|
- [Performance & Bundle Size](#performance--bundle-size)
|
|
74
|
-
- [Built-in validators](#built-in-validators)
|
|
75
92
|
- [Custom validators](#custom-validators)
|
|
76
93
|
- [Multiple sources](#multiple-sources)
|
|
77
94
|
- [Safe error handling](#safe-error-handling)
|
|
@@ -92,9 +109,12 @@ const config = await resolve.async([
|
|
|
92
109
|
If an environment variable is missing and has no default, validation fails:
|
|
93
110
|
|
|
94
111
|
```ts
|
|
112
|
+
import { resolve } from 'node-env-resolver';
|
|
113
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
114
|
+
|
|
95
115
|
const config = resolve({
|
|
96
|
-
DATABASE_URL:
|
|
97
|
-
API_KEY:
|
|
116
|
+
DATABASE_URL: postgres(), // Required PostgreSQL URL
|
|
117
|
+
API_KEY: string() // Required
|
|
98
118
|
});
|
|
99
119
|
```
|
|
100
120
|
|
|
@@ -103,6 +123,8 @@ const config = resolve({
|
|
|
103
123
|
Provide a default value to use when the environment variable is not set:
|
|
104
124
|
|
|
105
125
|
```ts
|
|
126
|
+
import { resolve } from 'node-env-resolver';
|
|
127
|
+
|
|
106
128
|
const config = resolve({
|
|
107
129
|
PORT: 3000, // Defaults to 3000
|
|
108
130
|
DEBUG: false, // Defaults to false
|
|
@@ -112,13 +134,15 @@ const config = resolve({
|
|
|
112
134
|
|
|
113
135
|
### Optional values
|
|
114
136
|
|
|
115
|
-
|
|
137
|
+
Use the `{optional: true}` option to make a value optional:
|
|
116
138
|
|
|
117
139
|
```ts
|
|
140
|
+
import { string, url, number } from 'node-env-resolver/resolvers';
|
|
141
|
+
|
|
118
142
|
const config = resolve({
|
|
119
|
-
API_KEY:
|
|
120
|
-
REDIS_URL:
|
|
121
|
-
MAX_RETRIES:
|
|
143
|
+
API_KEY: string({optional: true}), // string | undefined
|
|
144
|
+
REDIS_URL: url({optional: true}), // string | undefined
|
|
145
|
+
MAX_RETRIES: number({optional: true}) // number | undefined
|
|
122
146
|
});
|
|
123
147
|
```
|
|
124
148
|
|
|
@@ -127,6 +151,8 @@ const config = resolve({
|
|
|
127
151
|
Use arrays for enum validation:
|
|
128
152
|
|
|
129
153
|
```ts
|
|
154
|
+
import { resolve } from 'node-env-resolver';
|
|
155
|
+
|
|
130
156
|
const config = resolve({
|
|
131
157
|
NODE_ENV: ['development', 'production', 'test'] as const,
|
|
132
158
|
LOG_LEVEL: ['debug', 'info', 'warn', 'error'] as const
|
|
@@ -151,25 +177,31 @@ Variable names can use:
|
|
|
151
177
|
### Valid Examples
|
|
152
178
|
|
|
153
179
|
```ts
|
|
180
|
+
import { resolve } from 'node-env-resolver';
|
|
181
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
182
|
+
|
|
154
183
|
const config = resolve({
|
|
155
184
|
PORT: 3000, // ✅ SCREAMING_SNAKE_CASE (traditional)
|
|
156
185
|
port: 3000, // ✅ lowercase
|
|
157
|
-
myApiKey:
|
|
158
|
-
my_api_key:
|
|
159
|
-
API_KEY_V2:
|
|
160
|
-
_PRIVATE:
|
|
186
|
+
myApiKey: string(), // ✅ camelCase
|
|
187
|
+
my_api_key: string(), // ✅ snake_case
|
|
188
|
+
API_KEY_V2: string(), // ✅ with numbers (not first char)
|
|
189
|
+
_PRIVATE: string() // ✅ starting with underscore
|
|
161
190
|
});
|
|
162
191
|
```
|
|
163
192
|
|
|
164
193
|
### Invalid Examples
|
|
165
194
|
|
|
166
195
|
```ts
|
|
196
|
+
import { resolve } from 'node-env-resolver';
|
|
197
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
198
|
+
|
|
167
199
|
const config = resolve({
|
|
168
200
|
'123PORT': 3000, // ❌ Starts with number
|
|
169
|
-
'API-KEY':
|
|
170
|
-
'API.KEY':
|
|
171
|
-
'API KEY':
|
|
172
|
-
'API@KEY':
|
|
201
|
+
'API-KEY': string(), // ❌ Contains hyphen
|
|
202
|
+
'API.KEY': string(), // ❌ Contains dot
|
|
203
|
+
'API KEY': string(), // ❌ Contains space
|
|
204
|
+
'API@KEY': string() // ❌ Special characters
|
|
173
205
|
});
|
|
174
206
|
```
|
|
175
207
|
|
|
@@ -179,7 +211,28 @@ const config = resolve({
|
|
|
179
211
|
|
|
180
212
|
## Performance & Bundle Size
|
|
181
213
|
|
|
182
|
-
**Lightweight** The core library is **~
|
|
214
|
+
**Lightweight** The core library is **~4.3KB gzipped** with validation and resolver capabilities - **optimized for minimal bundle impact**.
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
218
|
+
import { dotenv, json, postgres, string, redis } from 'node-env-resolver/resolvers';
|
|
219
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
220
|
+
|
|
221
|
+
const config = await resolveAsync({
|
|
222
|
+
resolvers: [
|
|
223
|
+
[processEnv(), { PORT: 3000 }],
|
|
224
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
225
|
+
[awsSecrets(), { API_KEY: string() }]
|
|
226
|
+
]
|
|
227
|
+
// Perfect for complex microservice architectures!
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Benefits:**
|
|
232
|
+
- **No artificial limits** - use as many resolvers as needed
|
|
233
|
+
- **Better type inference** - proper schema merging with full TypeScript support
|
|
234
|
+
- **Cleaner code** - single implementation instead of multiple overloads
|
|
235
|
+
- **Future-proof** - automatically supports new resolver types
|
|
183
236
|
|
|
184
237
|
### Efficient validation architecture
|
|
185
238
|
|
|
@@ -199,19 +252,24 @@ The library uses a two-tier validation strategy with lazy-loaded validators:
|
|
|
199
252
|
Advanced validators are lazy-loaded only when you use them, keeping the base bundle minimal. All types work both synchronously and asynchronously:
|
|
200
253
|
|
|
201
254
|
```ts
|
|
255
|
+
import { resolve, resolveAsync } from 'node-env-resolver';
|
|
256
|
+
import { postgres, url } from 'node-env-resolver/resolvers';
|
|
257
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
258
|
+
|
|
202
259
|
// Synchronous - works with all types
|
|
203
260
|
const config = resolve({
|
|
204
261
|
PORT: 3000,
|
|
205
|
-
DATABASE_URL:
|
|
206
|
-
API_URL:
|
|
262
|
+
DATABASE_URL: postgres(),
|
|
263
|
+
API_URL: url(),
|
|
207
264
|
NODE_ENV: ['development', 'production'] as const
|
|
208
265
|
});
|
|
209
266
|
|
|
210
267
|
// Also works with async resolvers
|
|
211
|
-
const config = await
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
]
|
|
268
|
+
const config = await resolveAsync({
|
|
269
|
+
resolvers: [
|
|
270
|
+
[awsSecrets(), { DATABASE_URL: postgres(), API_URL: url() }]
|
|
271
|
+
]
|
|
272
|
+
});
|
|
215
273
|
```
|
|
216
274
|
|
|
217
275
|
### What's in the 3.6KB core?
|
|
@@ -235,6 +293,8 @@ Only the code you actually use gets loaded!
|
|
|
235
293
|
Audit logging is lazy-loaded only when enabled, keeping the base bundle minimal:
|
|
236
294
|
|
|
237
295
|
```ts
|
|
296
|
+
import { resolve } from 'node-env-resolver';
|
|
297
|
+
|
|
238
298
|
// Base bundle
|
|
239
299
|
const config = resolve({ PORT: 3000 });
|
|
240
300
|
|
|
@@ -267,109 +327,13 @@ import { awsSecrets } from 'node-env-resolver-aws';
|
|
|
267
327
|
|
|
268
328
|
**Most apps only need the core (~3.6KB)!**
|
|
269
329
|
|
|
270
|
-
## Built-in validators
|
|
271
|
-
|
|
272
|
-
All validator types work synchronously and asynchronously.
|
|
273
|
-
|
|
274
|
-
### Basic types
|
|
275
|
-
|
|
276
|
-
These types use inline validation:
|
|
277
|
-
|
|
278
|
-
- `'string'` - Any string value (with optional `min`/`max` length)
|
|
279
|
-
- `'number'` - Numeric value (coerced from string, with optional `min`/`max`)
|
|
280
|
-
- `'boolean'` - Boolean value (`'true'`/`'false'` coerced to boolean)
|
|
281
|
-
- `'enum'` - Array of allowed values
|
|
282
|
-
- `'pattern'` - Regex pattern validation
|
|
283
|
-
- `'custom'` - Custom validator function
|
|
284
|
-
|
|
285
|
-
### Advanced types
|
|
286
|
-
|
|
287
|
-
Advanced validators provide specialized validation and parsing:
|
|
288
|
-
|
|
289
|
-
**Network types:**
|
|
290
|
-
|
|
291
|
-
- `'url'` - Valid URL (returns string)
|
|
292
|
-
- `'http'` - HTTP or HTTPS URL (returns string)
|
|
293
|
-
- `'https'` - HTTPS-only URL (returns string)
|
|
294
|
-
- `'email'` - Email address (returns string)
|
|
295
|
-
|
|
296
|
-
**Database connection strings:**
|
|
297
|
-
|
|
298
|
-
- `'postgres'` or `'postgresql'` - PostgreSQL connection string (returns string)
|
|
299
|
-
- `'mysql'` - MySQL connection string (returns string)
|
|
300
|
-
- `'mongodb'` - MongoDB connection string (returns string)
|
|
301
|
-
- `'redis'` - Redis connection string (returns string)
|
|
302
|
-
|
|
303
|
-
**Format types:**
|
|
304
|
-
|
|
305
|
-
- `'json'` - JSON value (returns parsed object/array)
|
|
306
|
-
- `'port'` - Port number (returns number, 1-65535)
|
|
307
|
-
- `'date'` - ISO 8601 date string (returns string)
|
|
308
|
-
- `'timestamp'` - Unix timestamp (returns number)
|
|
309
|
-
- `'duration'` - Time duration like `'5s'`, `'2m'`, `'1h'` (returns milliseconds as number)
|
|
310
|
-
- `'file'` - Read content from file path (returns trimmed file content as string)
|
|
311
|
-
|
|
312
|
-
**Array types:**
|
|
313
|
-
|
|
314
|
-
- `'string[]'` - Array of strings from comma-separated values (returns `string[]`)
|
|
315
|
-
- `'number[]'` - Array of numbers from comma-separated values (returns `number[]`)
|
|
316
|
-
- `'url[]'` - Array of validated URLs from comma-separated values (returns `string[]`)
|
|
317
|
-
|
|
318
|
-
```ts
|
|
319
|
-
// Array examples
|
|
320
|
-
process.env.TAGS = 'frontend,backend,mobile';
|
|
321
|
-
process.env.PORTS = '3000,8080,9000';
|
|
322
|
-
process.env.ALLOWED_ORIGINS = 'https://app.com,https://api.com';
|
|
323
|
-
|
|
324
|
-
const config = resolve({
|
|
325
|
-
TAGS: 'string[]', // ['frontend', 'backend', 'mobile']
|
|
326
|
-
PORTS: 'number[]', // [3000, 8080, 9000]
|
|
327
|
-
ALLOWED_ORIGINS: 'url[]' // ['https://app.com', 'https://api.com']
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// Custom separator
|
|
331
|
-
const config = resolve({
|
|
332
|
-
TAGS: { type: 'string[]', separator: '|' } // Use pipe instead of comma
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
// Duration parsing
|
|
336
|
-
process.env.TIMEOUT = '30s';
|
|
337
|
-
process.env.CACHE_TTL = '5m';
|
|
338
|
-
process.env.SESSION_DURATION = '24h';
|
|
339
|
-
|
|
340
|
-
const config = await resolve.async([processEnv(), {
|
|
341
|
-
TIMEOUT: 'duration', // 30000 (milliseconds)
|
|
342
|
-
CACHE_TTL: 'duration', // 300000
|
|
343
|
-
SESSION_DURATION: 'duration' // 86400000
|
|
344
|
-
}]);
|
|
345
|
-
|
|
346
|
-
// File reading (useful for Docker/Kubernetes secrets)
|
|
347
|
-
// Method 1: Explicit path in env var
|
|
348
|
-
process.env.DB_PASSWORD_FILE = '/run/secrets/db_password';
|
|
349
|
-
const config = await resolve.async([processEnv(), {
|
|
350
|
-
DB_PASSWORD_FILE: 'file' // 'my-secret-password' (file content, trimmed)
|
|
351
|
-
}]);
|
|
352
|
-
|
|
353
|
-
// Method 2: Using secretsDir (cleaner for Docker/K8s)
|
|
354
|
-
// Reads from /run/secrets/db_password automatically (key name lowercased)
|
|
355
|
-
const config = await resolve.async([processEnv(), {
|
|
356
|
-
DB_PASSWORD: 'file' // Reads /run/secrets/db_password
|
|
357
|
-
}], { secretsDir: '/run/secrets' });
|
|
358
|
-
|
|
359
|
-
// Per-field secretsDir (overrides global)
|
|
360
|
-
const config = await resolve.async([processEnv(), {
|
|
361
|
-
DB_PASSWORD: { type: 'file', secretsDir: '/custom/secrets' },
|
|
362
|
-
API_KEY: 'file' // Uses global secretsDir
|
|
363
|
-
}], { secretsDir: '/run/secrets' });
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
All validators automatically handle type coercion from environment variable strings.
|
|
367
|
-
|
|
368
330
|
## Custom validators
|
|
369
331
|
|
|
370
332
|
Write your own validation functions:
|
|
371
333
|
|
|
372
334
|
```ts
|
|
335
|
+
import { resolve } from 'node-env-resolver';
|
|
336
|
+
|
|
373
337
|
const isValidPort = (value: string): number => {
|
|
374
338
|
const port = parseInt(value, 10);
|
|
375
339
|
if (isNaN(port) || port < 1 || port > 65535) {
|
|
@@ -424,29 +388,43 @@ Available validation functions: `validatePostgres`, `validateMysql`, `validateMo
|
|
|
424
388
|
## Multiple sources
|
|
425
389
|
|
|
426
390
|
Load configuration from multiple sources. By default, later sources override earlier ones:
|
|
427
|
-
|
|
428
391
|
```ts
|
|
429
|
-
import { resolve, processEnv } from 'node-env-resolver';
|
|
430
|
-
import { dotenv, json } from 'node-env-resolver/resolvers';
|
|
392
|
+
import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
|
|
393
|
+
import { dotenv, json, postgres, string, redis } from 'node-env-resolver/resolvers';
|
|
394
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
431
395
|
|
|
432
396
|
// Async mode - supports both sync and async resolvers
|
|
433
|
-
const config = await
|
|
434
|
-
[
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
397
|
+
const config = await resolveAsync({
|
|
398
|
+
resolvers: [
|
|
399
|
+
[processEnv(), {
|
|
400
|
+
PORT: 3000,
|
|
401
|
+
NODE_ENV: ['development', 'production'] as const,
|
|
402
|
+
}],
|
|
403
|
+
[dotenv(), {
|
|
404
|
+
DATABASE_URL: postgres(),
|
|
405
|
+
API_KEY: string(),
|
|
406
|
+
}]
|
|
407
|
+
]
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// Sync mode - supports multiple SYNC resolvers
|
|
411
|
+
const config = resolve({
|
|
412
|
+
resolvers: [
|
|
413
|
+
[dotenv(), { PORT: 3000 }],
|
|
414
|
+
[json('config.json'), { DATABASE_URL: postgres() }]
|
|
415
|
+
]
|
|
448
416
|
// Both resolvers must have loadSync() method
|
|
449
|
-
);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// Support for ANY number of resolvers (3, 4, 5, 10+ resolvers!)
|
|
420
|
+
const config = await resolveAsync({
|
|
421
|
+
resolvers: [
|
|
422
|
+
[processEnv(), { PORT: 3000 }],
|
|
423
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
424
|
+
[awsSecrets(), { API_KEY: string() }]
|
|
425
|
+
],
|
|
426
|
+
options: { priority: 'last' }
|
|
427
|
+
});
|
|
450
428
|
```
|
|
451
429
|
|
|
452
430
|
### Controlling merge behaviour
|
|
@@ -454,28 +432,38 @@ const config = resolve(
|
|
|
454
432
|
Use `priority` to control how resolvers merge values (works with both sync and async modes):
|
|
455
433
|
|
|
456
434
|
```ts
|
|
435
|
+
import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
|
|
436
|
+
import { dotenv, json, postgres } from 'node-env-resolver/resolvers';
|
|
437
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
438
|
+
|
|
457
439
|
// priority: 'last' (default) - later resolvers override earlier ones
|
|
458
|
-
const config = await
|
|
459
|
-
|
|
460
|
-
|
|
440
|
+
const config = await resolveAsync({
|
|
441
|
+
resolvers: [
|
|
442
|
+
[processEnv(), { DATABASE_URL: postgres() }],
|
|
443
|
+
[awsSecrets(), { DATABASE_URL: postgres() }]
|
|
444
|
+
]
|
|
461
445
|
// AWS wins
|
|
462
|
-
);
|
|
446
|
+
});
|
|
463
447
|
|
|
464
448
|
// priority: 'first' - earlier resolvers take precedence
|
|
465
|
-
const config = await
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
449
|
+
const config = await resolveAsync({
|
|
450
|
+
resolvers: [
|
|
451
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
452
|
+
[awsSecrets(), { DATABASE_URL: postgres() }]
|
|
453
|
+
],
|
|
454
|
+
options: { priority: 'first' }
|
|
469
455
|
// dotenv wins
|
|
470
|
-
);
|
|
456
|
+
});
|
|
471
457
|
|
|
472
|
-
// Also works with sync resolve()
|
|
473
|
-
const config = resolve(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
458
|
+
// Also works with sync resolve()
|
|
459
|
+
const config = resolve({
|
|
460
|
+
resolvers: [
|
|
461
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
462
|
+
[json('config.json'), { DATABASE_URL: postgres() }]
|
|
463
|
+
],
|
|
464
|
+
options: { priority: 'first' }
|
|
477
465
|
// dotenv wins
|
|
478
|
-
);
|
|
466
|
+
});
|
|
479
467
|
```
|
|
480
468
|
|
|
481
469
|
This is useful for development workflows where local overrides should take precedence over cloud secrets.
|
|
@@ -489,13 +477,18 @@ The library includes two automatic performance optimizations:
|
|
|
489
477
|
When using `priority: 'first'`, resolvers are called sequentially, but execution **stops early** once all required environment variables are satisfied:
|
|
490
478
|
|
|
491
479
|
```ts
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
480
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
481
|
+
import { dotenv, postgres, string } from 'node-env-resolver/resolvers';
|
|
482
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
483
|
+
|
|
484
|
+
const config = await resolveAsync({
|
|
485
|
+
resolvers: [
|
|
486
|
+
[dotenv(), { DATABASE_URL: postgres(), API_KEY: string(), PORT: 3000 }],
|
|
487
|
+
[awsSecrets(), { DATABASE_URL: postgres(), API_KEY: string(), PORT: 3000 }]
|
|
488
|
+
],
|
|
489
|
+
options: { priority: 'first' }
|
|
490
|
+
});
|
|
491
|
+
// If dotenv() provides all required keys, awsSecrets() is never called!
|
|
499
492
|
```
|
|
500
493
|
|
|
501
494
|
This is particularly valuable in development where:
|
|
@@ -514,12 +507,17 @@ This is particularly valuable in development where:
|
|
|
514
507
|
When using `priority: 'last'` (the default), all resolvers are called **in parallel** for maximum performance:
|
|
515
508
|
|
|
516
509
|
```ts
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
510
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
511
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
512
|
+
import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
|
|
513
|
+
|
|
514
|
+
const config = await resolveAsync({
|
|
515
|
+
resolvers: [
|
|
516
|
+
[awsSecrets(), { DATABASE_URL: postgres() }], // 100ms
|
|
517
|
+
[awsSsm(), { API_KEY: string() }], // 100ms
|
|
518
|
+
]
|
|
521
519
|
// Default: priority: 'last'
|
|
522
|
-
);
|
|
520
|
+
});
|
|
523
521
|
// Total time: ~100ms (parallel) instead of ~300ms (sequential)
|
|
524
522
|
```
|
|
525
523
|
|
|
@@ -536,11 +534,21 @@ Since `priority: 'last'` means "last write wins", the order doesn't matter for c
|
|
|
536
534
|
Like Zod's `safeParse()`, use `safeResolve()` to get a result object instead of throwing:
|
|
537
535
|
|
|
538
536
|
```ts
|
|
539
|
-
import { safeResolve } from 'node-env-resolver';
|
|
537
|
+
import { safeResolve, safeResolveAsync } from 'node-env-resolver';
|
|
538
|
+
import { number, postgres } from 'node-env-resolver/resolvers';
|
|
540
539
|
|
|
540
|
+
// Synchronous safe resolve
|
|
541
541
|
const result = safeResolve({
|
|
542
|
-
PORT:
|
|
543
|
-
DATABASE_URL:
|
|
542
|
+
PORT: number(),
|
|
543
|
+
DATABASE_URL: postgres()
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// Asynchronous safe resolve
|
|
547
|
+
const result = await safeResolveAsync({
|
|
548
|
+
resolvers: [
|
|
549
|
+
[processEnv(), { PORT: number() }],
|
|
550
|
+
[awsSecrets(), { DATABASE_URL: postgres() }]
|
|
551
|
+
]
|
|
544
552
|
});
|
|
545
553
|
|
|
546
554
|
if (result.success) {
|
|
@@ -556,7 +564,7 @@ if (result.success) {
|
|
|
556
564
|
All functions have safe variants:
|
|
557
565
|
|
|
558
566
|
- `resolve()` → `safeResolve()` (both synchronous)
|
|
559
|
-
- `
|
|
567
|
+
- `resolveAsync()` → `safeResolveAsync()` (both async)
|
|
560
568
|
|
|
561
569
|
## Synchronous resolution
|
|
562
570
|
|
|
@@ -564,26 +572,32 @@ All functions have safe variants:
|
|
|
564
572
|
|
|
565
573
|
```ts
|
|
566
574
|
import { resolve } from 'node-env-resolver';
|
|
575
|
+
import { string, url, postgres } from 'node-env-resolver/resolvers';
|
|
567
576
|
|
|
568
577
|
// Synchronous - no await needed, works with ALL types
|
|
569
578
|
const config = resolve({
|
|
570
579
|
PORT: 3000,
|
|
571
580
|
NODE_ENV: ['development', 'production'] as const,
|
|
572
|
-
API_KEY:
|
|
573
|
-
API_URL:
|
|
574
|
-
DATABASE_URL:
|
|
581
|
+
API_KEY: string(),
|
|
582
|
+
API_URL: url(), // Advanced types work synchronously!
|
|
583
|
+
DATABASE_URL: postgres(),
|
|
575
584
|
DEBUG: false
|
|
576
585
|
});
|
|
577
586
|
```
|
|
578
587
|
|
|
579
|
-
`
|
|
588
|
+
`resolveAsync()` is **async** when using custom resolvers:
|
|
580
589
|
|
|
581
590
|
```ts
|
|
591
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
592
|
+
import { dotenv, postgres, url } from 'node-env-resolver/resolvers';
|
|
593
|
+
|
|
582
594
|
// Async - await required when using custom resolvers
|
|
583
|
-
const config = await
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
)
|
|
595
|
+
const config = await resolveAsync({
|
|
596
|
+
resolvers: [
|
|
597
|
+
[processEnv(), { PORT: 3000 }],
|
|
598
|
+
[dotenv(), { DATABASE_URL: postgres(), API_URL: url() }]
|
|
599
|
+
]
|
|
600
|
+
});
|
|
587
601
|
```
|
|
588
602
|
|
|
589
603
|
## Advanced features
|
|
@@ -593,23 +607,26 @@ const config = await resolve.async(
|
|
|
593
607
|
Parse command-line arguments as environment variables - perfect for CLI tools:
|
|
594
608
|
|
|
595
609
|
```ts
|
|
596
|
-
import {
|
|
610
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
611
|
+
import { postgres } from 'node-env-resolver/resolvers';
|
|
597
612
|
import { cliArgs } from 'node-env-resolver/cli';
|
|
598
613
|
|
|
599
614
|
// $ node app.js --port 8080 --database-url postgres://localhost --verbose
|
|
600
615
|
|
|
601
|
-
const config = await
|
|
602
|
-
[
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
616
|
+
const config = await resolveAsync({
|
|
617
|
+
resolvers: [
|
|
618
|
+
[processEnv(), {
|
|
619
|
+
PORT: 3000,
|
|
620
|
+
DATABASE_URL: postgres(),
|
|
621
|
+
VERBOSE: false
|
|
622
|
+
}],
|
|
623
|
+
[cliArgs(), {
|
|
624
|
+
PORT: 3000,
|
|
625
|
+
DATABASE_URL: postgres(),
|
|
626
|
+
VERBOSE: false
|
|
627
|
+
}]
|
|
628
|
+
]
|
|
629
|
+
});
|
|
613
630
|
|
|
614
631
|
// config.PORT === 8080 (from CLI)
|
|
615
632
|
// config.DATABASE_URL === 'postgres://localhost' (from CLI)
|
|
@@ -795,7 +812,8 @@ if (result.success) {
|
|
|
795
812
|
Create resolvers to load configuration from any source:
|
|
796
813
|
|
|
797
814
|
```ts
|
|
798
|
-
import {
|
|
815
|
+
import { resolveAsync, processEnv, type Resolver } from 'node-env-resolver';
|
|
816
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
799
817
|
|
|
800
818
|
const databaseResolver: Resolver = {
|
|
801
819
|
name: 'database',
|
|
@@ -805,10 +823,12 @@ const databaseResolver: Resolver = {
|
|
|
805
823
|
}
|
|
806
824
|
};
|
|
807
825
|
|
|
808
|
-
const config = await
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
)
|
|
826
|
+
const config = await resolveAsync({
|
|
827
|
+
resolvers: [
|
|
828
|
+
[processEnv(), { PORT: 3000 }],
|
|
829
|
+
[databaseResolver, { API_KEY: string() }]
|
|
830
|
+
]
|
|
831
|
+
});
|
|
812
832
|
```
|
|
813
833
|
|
|
814
834
|
### AWS Secrets Manager
|
|
@@ -823,26 +843,30 @@ Single source:
|
|
|
823
843
|
|
|
824
844
|
```ts
|
|
825
845
|
import { resolveSecrets } from 'node-env-resolver-aws';
|
|
846
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
826
847
|
|
|
827
848
|
const config = await resolveSecrets({
|
|
828
849
|
secretId: 'myapp/secrets'
|
|
829
850
|
}, {
|
|
830
|
-
DATABASE_URL:
|
|
831
|
-
API_KEY:
|
|
851
|
+
DATABASE_URL: postgres(),
|
|
852
|
+
API_KEY: string()
|
|
832
853
|
});
|
|
833
854
|
```
|
|
834
855
|
|
|
835
856
|
Multiple sources:
|
|
836
857
|
|
|
837
858
|
```ts
|
|
838
|
-
import {
|
|
859
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
860
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
839
861
|
import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
|
|
840
862
|
|
|
841
|
-
const config = await
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
)
|
|
863
|
+
const config = await resolveAsync({
|
|
864
|
+
resolvers: [
|
|
865
|
+
[processEnv(), { PORT: 3000 }],
|
|
866
|
+
[awsSecrets({ secretId: 'app/secrets' }), { DATABASE_URL: postgres() }],
|
|
867
|
+
[awsSsm({ path: '/app/config' }), { API_KEY: string() }]
|
|
868
|
+
]
|
|
869
|
+
});
|
|
846
870
|
```
|
|
847
871
|
|
|
848
872
|
See the [AWS package documentation](../node-env-resolver-aws/README.md) for details on credentials, caching, and best practices.
|
|
@@ -852,20 +876,23 @@ See the [AWS package documentation](../node-env-resolver-aws/README.md) for deta
|
|
|
852
876
|
Cache expensive operations like AWS API calls:
|
|
853
877
|
|
|
854
878
|
```ts
|
|
855
|
-
import {
|
|
879
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
856
880
|
import { cached, TTL } from 'node-env-resolver/utils';
|
|
881
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
857
882
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
858
883
|
|
|
859
884
|
export const getConfig = async () => {
|
|
860
|
-
return await
|
|
861
|
-
[
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
885
|
+
return await resolveAsync({
|
|
886
|
+
resolvers: [
|
|
887
|
+
[cached(
|
|
888
|
+
awsSecrets({ secretId: 'app/secrets' }),
|
|
889
|
+
{ ttl: TTL.minutes5 }
|
|
890
|
+
), {
|
|
891
|
+
DATABASE_URL: postgres(),
|
|
892
|
+
API_KEY: string(),
|
|
893
|
+
}]
|
|
894
|
+
]
|
|
895
|
+
});
|
|
869
896
|
};
|
|
870
897
|
|
|
871
898
|
// Call getConfig() in your handlers
|
|
@@ -882,6 +909,25 @@ Performance:
|
|
|
882
909
|
|
|
883
910
|
**Important:** Call `resolve()` every time. The `cached()` wrapper handles the caching.
|
|
884
911
|
|
|
912
|
+
**Advanced caching options:**
|
|
913
|
+
|
|
914
|
+
```ts
|
|
915
|
+
import { cached, TTL } from 'node-env-resolver/utils';
|
|
916
|
+
|
|
917
|
+
// Stale-while-revalidate: serve stale data while refreshing in background
|
|
918
|
+
const resolver = cached(awsSecrets(), {
|
|
919
|
+
ttl: TTL.minutes5, // Fresh for 5 minutes
|
|
920
|
+
maxAge: TTL.hour, // Force refresh after 1 hour
|
|
921
|
+
staleWhileRevalidate: true // Serve stale data during refresh
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
// Custom cache key for debugging
|
|
925
|
+
const resolver = cached(awsSecrets(), {
|
|
926
|
+
ttl: TTL.minutes15,
|
|
927
|
+
key: 'prod-secrets-v2'
|
|
928
|
+
});
|
|
929
|
+
```
|
|
930
|
+
|
|
885
931
|
## API Reference
|
|
886
932
|
|
|
887
933
|
### Function variants
|
|
@@ -890,34 +936,48 @@ Performance:
|
|
|
890
936
|
|----------|-----------|----------|
|
|
891
937
|
| `resolve()` | Sync, throws on error | Most applications (reading from process.env) |
|
|
892
938
|
| `safeResolve()` | Sync, returns result object | Graceful error handling |
|
|
893
|
-
| `
|
|
894
|
-
| `
|
|
939
|
+
| `resolveAsync()` | Async, throws on error | Multiple sources (dotenv, AWS, etc.) |
|
|
940
|
+
| `safeResolveAsync()` | Async, returns result object | Multiple sources with error handling |
|
|
941
|
+
|
|
942
|
+
### Resolver API Reference
|
|
895
943
|
|
|
896
|
-
|
|
944
|
+
Import resolver functions from `'node-env-resolver/resolvers'`:
|
|
945
|
+
|
|
946
|
+
```ts
|
|
947
|
+
import {
|
|
948
|
+
string, number, boolean, url, email, port, json,
|
|
949
|
+
postgres, mysql, mongodb, redis,
|
|
950
|
+
http, https, date, timestamp, duration, file
|
|
951
|
+
} from 'node-env-resolver/resolvers';
|
|
952
|
+
```
|
|
897
953
|
|
|
898
954
|
| Syntax | Type | Description |
|
|
899
955
|
|--------|------|-------------|
|
|
900
|
-
| `
|
|
901
|
-
| `
|
|
902
|
-
| `
|
|
903
|
-
| `
|
|
904
|
-
| `
|
|
905
|
-
| `
|
|
906
|
-
| `
|
|
907
|
-
| `
|
|
908
|
-
| `
|
|
909
|
-
| `
|
|
910
|
-
| `
|
|
911
|
-
| `
|
|
912
|
-
| `
|
|
913
|
-
| `
|
|
914
|
-
| `
|
|
915
|
-
| `
|
|
916
|
-
| `
|
|
917
|
-
| `
|
|
918
|
-
| `
|
|
919
|
-
| `
|
|
920
|
-
| `
|
|
956
|
+
| `string()` | `string` | Required string (empty strings rejected by default) |
|
|
957
|
+
| `string({optional: true})` | `string \| undefined` | Optional string |
|
|
958
|
+
| `number()` | `number` | Required number (coerced from string) |
|
|
959
|
+
| `number({optional: true})` | `number \| undefined` | Optional number |
|
|
960
|
+
| `boolean()` | `boolean` | Required boolean (coerced from string) |
|
|
961
|
+
| `boolean({optional: true})` | `boolean \| undefined` | Optional boolean |
|
|
962
|
+
| `url()` | `string` | Validated URL (returns string) |
|
|
963
|
+
| `url({optional: true})` | `string \| undefined` | Optional URL |
|
|
964
|
+
| `email()` | `string` | Validated email address |
|
|
965
|
+
| `port()` | `number` | Validated port number (1-65535) |
|
|
966
|
+
| `json()` | `unknown` | Parsed JSON (returns object/array) |
|
|
967
|
+
| `postgres()` or `postgresql()` | `string` | Validated PostgreSQL URL |
|
|
968
|
+
| `mysql()` | `string` | Validated MySQL connection string |
|
|
969
|
+
| `mongodb()` | `string` | Validated MongoDB connection string |
|
|
970
|
+
| `redis()` | `string` | Validated Redis connection string |
|
|
971
|
+
| `http()` | `string` | HTTP or HTTPS URL |
|
|
972
|
+
| `https()` | `string` | HTTPS-only URL |
|
|
973
|
+
| `date()` | `string` | Validated ISO 8601 date |
|
|
974
|
+
| `timestamp()` | `number` | Validated Unix timestamp |
|
|
975
|
+
| `duration()` | `number` | Time duration (`5s`, `2m`, `1h` → milliseconds) |
|
|
976
|
+
| `file()` | `string` | Read content from file path |
|
|
977
|
+
| `3000` | `number` | Number with default value |
|
|
978
|
+
| `false` | `boolean` | Boolean with default value |
|
|
979
|
+
| `'defaultValue'` | `string` | String with default value |
|
|
980
|
+
| `['a', 'b'] as const` | `'a' \| 'b'` | Enum (requires `as const`) |
|
|
921
981
|
|
|
922
982
|
## Configuration Options
|
|
923
983
|
|
|
@@ -932,21 +992,23 @@ const config = resolve(schema, {
|
|
|
932
992
|
enableAudit: true
|
|
933
993
|
});
|
|
934
994
|
|
|
935
|
-
// Multiple sources - options
|
|
936
|
-
const config = await
|
|
937
|
-
[
|
|
938
|
-
|
|
939
|
-
|
|
995
|
+
// Multiple sources - options in config object
|
|
996
|
+
const config = await resolveAsync({
|
|
997
|
+
resolvers: [
|
|
998
|
+
[resolver1, schema],
|
|
999
|
+
[resolver2, schema]
|
|
1000
|
+
],
|
|
1001
|
+
options: {
|
|
940
1002
|
interpolate: false,
|
|
941
1003
|
strict: true,
|
|
942
1004
|
policies: {...},
|
|
943
1005
|
enableAudit: true,
|
|
944
1006
|
priority: 'last'
|
|
945
1007
|
}
|
|
946
|
-
);
|
|
1008
|
+
});
|
|
947
1009
|
```
|
|
948
1010
|
|
|
949
|
-
**Note:** The `resolvers` option has been removed. For single source resolution, use `resolve()` directly (defaults to `process.env`). For multiple sources, use `
|
|
1011
|
+
**Note:** The `resolvers` option has been removed. For single source resolution, use `resolve()` directly (defaults to `process.env`). For multiple sources, use `resolveAsync()` syntax.
|
|
950
1012
|
|
|
951
1013
|
### `interpolate`
|
|
952
1014
|
|
|
@@ -956,16 +1018,19 @@ const config = await resolve.async(
|
|
|
956
1018
|
|
|
957
1019
|
**Why:** Keeps configuration DRY and maintainable.
|
|
958
1020
|
|
|
959
|
-
**Default:** `true` in `
|
|
1021
|
+
**Default:** `true` in `resolveAsync()`, `false` in `resolve()`
|
|
960
1022
|
|
|
961
1023
|
```ts
|
|
1024
|
+
import { resolve } from 'node-env-resolver';
|
|
1025
|
+
import { url } from 'node-env-resolver/resolvers';
|
|
1026
|
+
|
|
962
1027
|
// With interpolation
|
|
963
1028
|
process.env.BASE_URL = 'https://api.example.com';
|
|
964
1029
|
process.env.API_ENDPOINT = '${BASE_URL}/v1';
|
|
965
1030
|
|
|
966
1031
|
const config = resolve({
|
|
967
|
-
BASE_URL:
|
|
968
|
-
API_ENDPOINT:
|
|
1032
|
+
BASE_URL: url(),
|
|
1033
|
+
API_ENDPOINT: url()
|
|
969
1034
|
}, {
|
|
970
1035
|
interpolate: true
|
|
971
1036
|
});
|
|
@@ -998,18 +1063,22 @@ const flakyResolver = {
|
|
|
998
1063
|
};
|
|
999
1064
|
|
|
1000
1065
|
// ❌ Throws immediately
|
|
1001
|
-
await
|
|
1002
|
-
[
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1066
|
+
await resolveAsync({
|
|
1067
|
+
resolvers: [
|
|
1068
|
+
[flakyResolver, schema],
|
|
1069
|
+
[processEnv(), schema]
|
|
1070
|
+
],
|
|
1071
|
+
options: { strict: true } // default
|
|
1072
|
+
});
|
|
1006
1073
|
|
|
1007
1074
|
// ✅ Continues with processEnv()
|
|
1008
|
-
await
|
|
1009
|
-
[
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1075
|
+
await resolveAsync({
|
|
1076
|
+
resolvers: [
|
|
1077
|
+
[flakyResolver, schema],
|
|
1078
|
+
[processEnv(), schema]
|
|
1079
|
+
],
|
|
1080
|
+
options: { strict: false } // graceful degradation
|
|
1081
|
+
});
|
|
1013
1082
|
```
|
|
1014
1083
|
|
|
1015
1084
|
**Note:** In sync mode with `strict: true`, resolvers without `loadSync()` method will throw errors.
|
|
@@ -1028,19 +1097,27 @@ await resolve.async(
|
|
|
1028
1097
|
**Default:** `'last'`
|
|
1029
1098
|
|
|
1030
1099
|
```ts
|
|
1100
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
1101
|
+
import { dotenv, postgres } from 'node-env-resolver/resolvers';
|
|
1102
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1103
|
+
|
|
1031
1104
|
// Production: AWS secrets override process.env
|
|
1032
|
-
await
|
|
1033
|
-
|
|
1034
|
-
|
|
1105
|
+
await resolveAsync({
|
|
1106
|
+
resolvers: [
|
|
1107
|
+
[processEnv(), { DATABASE_URL: postgres() }],
|
|
1108
|
+
[awsSecrets(), { DATABASE_URL: postgres() }]
|
|
1109
|
+
]
|
|
1035
1110
|
// priority: 'last' (default) - AWS wins
|
|
1036
|
-
);
|
|
1111
|
+
});
|
|
1037
1112
|
|
|
1038
1113
|
// Development: Local .env overrides cloud
|
|
1039
|
-
await
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1114
|
+
await resolveAsync({
|
|
1115
|
+
resolvers: [
|
|
1116
|
+
[dotenv(), { DATABASE_URL: postgres() }],
|
|
1117
|
+
[awsSecrets(), { DATABASE_URL: postgres() }]
|
|
1118
|
+
],
|
|
1119
|
+
options: { priority: 'first' } // dotenv wins
|
|
1120
|
+
});
|
|
1044
1121
|
```
|
|
1045
1122
|
|
|
1046
1123
|
**See:** "Controlling merge behaviour" section above for details.
|
|
@@ -1056,10 +1133,12 @@ await resolve.async(
|
|
|
1056
1133
|
**Default:** `undefined` (no policies enforced)
|
|
1057
1134
|
|
|
1058
1135
|
```ts
|
|
1059
|
-
await
|
|
1060
|
-
[
|
|
1061
|
-
|
|
1062
|
-
|
|
1136
|
+
await resolveAsync({
|
|
1137
|
+
resolvers: [
|
|
1138
|
+
[processEnv(), schema],
|
|
1139
|
+
[awsSecrets(), schema]
|
|
1140
|
+
],
|
|
1141
|
+
options: {
|
|
1063
1142
|
policies: {
|
|
1064
1143
|
// Block .env in production (default behaviour)
|
|
1065
1144
|
allowDotenvInProduction: false,
|
|
@@ -1071,7 +1150,7 @@ await resolve.async(
|
|
|
1071
1150
|
}
|
|
1072
1151
|
}
|
|
1073
1152
|
}
|
|
1074
|
-
);
|
|
1153
|
+
});
|
|
1075
1154
|
```
|
|
1076
1155
|
|
|
1077
1156
|
**See:** "Security Policies" section below for complete documentation.
|
|
@@ -1091,11 +1170,13 @@ await resolve.async(
|
|
|
1091
1170
|
**Default:** `false` (disabled in development), automatically `true` in production (`NODE_ENV === 'production'`)
|
|
1092
1171
|
|
|
1093
1172
|
```ts
|
|
1094
|
-
await
|
|
1095
|
-
[
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1173
|
+
await resolveAsync({
|
|
1174
|
+
resolvers: [
|
|
1175
|
+
[processEnv(), schema],
|
|
1176
|
+
[awsSecrets(), schema]
|
|
1177
|
+
],
|
|
1178
|
+
options: { enableAudit: true } // Explicitly enable in development
|
|
1179
|
+
});
|
|
1099
1180
|
|
|
1100
1181
|
const logs = getAuditLog();
|
|
1101
1182
|
// [
|
|
@@ -1131,11 +1212,12 @@ interface PolicyOptions {
|
|
|
1131
1212
|
```ts
|
|
1132
1213
|
import express from 'express';
|
|
1133
1214
|
import { resolve } from 'node-env-resolver';
|
|
1215
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
1134
1216
|
|
|
1135
1217
|
const config = resolve({
|
|
1136
1218
|
PORT: 3000,
|
|
1137
|
-
DATABASE_URL:
|
|
1138
|
-
SESSION_SECRET:
|
|
1219
|
+
DATABASE_URL: postgres(),
|
|
1220
|
+
SESSION_SECRET: string()
|
|
1139
1221
|
});
|
|
1140
1222
|
|
|
1141
1223
|
const app = express();
|
|
@@ -1147,14 +1229,15 @@ app.listen(config.PORT);
|
|
|
1147
1229
|
```ts
|
|
1148
1230
|
// env.mjs
|
|
1149
1231
|
import { resolve } from 'node-env-resolver/nextjs';
|
|
1232
|
+
import { postgres, string, url } from 'node-env-resolver/resolvers';
|
|
1150
1233
|
|
|
1151
1234
|
export const env = resolve({
|
|
1152
1235
|
server: {
|
|
1153
|
-
DATABASE_URL:
|
|
1154
|
-
API_SECRET:
|
|
1236
|
+
DATABASE_URL: postgres(),
|
|
1237
|
+
API_SECRET: string(),
|
|
1155
1238
|
},
|
|
1156
1239
|
client: {
|
|
1157
|
-
NEXT_PUBLIC_APP_URL:
|
|
1240
|
+
NEXT_PUBLIC_APP_URL: url(),
|
|
1158
1241
|
}
|
|
1159
1242
|
});
|
|
1160
1243
|
```
|
|
@@ -1162,19 +1245,22 @@ export const env = resolve({
|
|
|
1162
1245
|
### AWS Lambda
|
|
1163
1246
|
|
|
1164
1247
|
```ts
|
|
1165
|
-
import {
|
|
1248
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
1166
1249
|
import { cached, TTL } from 'node-env-resolver/utils';
|
|
1250
|
+
import { postgres } from 'node-env-resolver/resolvers';
|
|
1167
1251
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1168
1252
|
|
|
1169
1253
|
const getConfig = async () => {
|
|
1170
|
-
return await
|
|
1171
|
-
[
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1254
|
+
return await resolveAsync({
|
|
1255
|
+
resolvers: [
|
|
1256
|
+
[cached(
|
|
1257
|
+
awsSecrets({ secretId: 'lambda/config' }),
|
|
1258
|
+
{ ttl: TTL.minutes5 }
|
|
1259
|
+
), {
|
|
1260
|
+
DATABASE_URL: postgres(),
|
|
1261
|
+
}]
|
|
1262
|
+
]
|
|
1263
|
+
});
|
|
1178
1264
|
};
|
|
1179
1265
|
|
|
1180
1266
|
export const handler = async (event) => {
|
|
@@ -1194,45 +1280,60 @@ By default, `.env` files are **completely blocked in production** for security.
|
|
|
1194
1280
|
**Default behavior (secure):**
|
|
1195
1281
|
|
|
1196
1282
|
```ts
|
|
1283
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
1284
|
+
import { dotenv, postgres } from 'node-env-resolver/resolvers';
|
|
1285
|
+
|
|
1197
1286
|
// In production (NODE_ENV=production)
|
|
1198
|
-
const config = await
|
|
1199
|
-
[
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1287
|
+
const config = await resolveAsync({
|
|
1288
|
+
resolvers: [
|
|
1289
|
+
[dotenv(), {
|
|
1290
|
+
DATABASE_URL: postgres(),
|
|
1291
|
+
}]
|
|
1292
|
+
]
|
|
1293
|
+
});
|
|
1203
1294
|
// ❌ Throws: "DATABASE_URL cannot be sourced from .env files in production"
|
|
1204
1295
|
```
|
|
1205
1296
|
|
|
1206
1297
|
**Allow all .env variables (NOT recommended):**
|
|
1207
1298
|
|
|
1208
1299
|
```ts
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1300
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
1301
|
+
import { dotenv, postgres } from 'node-env-resolver/resolvers';
|
|
1302
|
+
|
|
1303
|
+
const config = await resolveAsync({
|
|
1304
|
+
resolvers: [
|
|
1305
|
+
[dotenv(), {
|
|
1306
|
+
DATABASE_URL: postgres(),
|
|
1307
|
+
}]
|
|
1308
|
+
],
|
|
1309
|
+
options: {
|
|
1214
1310
|
policies: {
|
|
1215
1311
|
allowDotenvInProduction: true // Allow all (risky!)
|
|
1216
1312
|
}
|
|
1217
1313
|
}
|
|
1218
|
-
);
|
|
1314
|
+
});
|
|
1219
1315
|
```
|
|
1220
1316
|
|
|
1221
1317
|
**Allow specific variables only (recommended if needed):**
|
|
1222
1318
|
|
|
1223
1319
|
```ts
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1320
|
+
import { resolveAsync } from 'node-env-resolver';
|
|
1321
|
+
import { dotenv, postgres } from 'node-env-resolver/resolvers';
|
|
1322
|
+
|
|
1323
|
+
const config = await resolveAsync({
|
|
1324
|
+
resolvers: [
|
|
1325
|
+
[dotenv(), {
|
|
1326
|
+
PORT: 3000,
|
|
1327
|
+
DATABASE_URL: postgres(),
|
|
1328
|
+
}]
|
|
1329
|
+
],
|
|
1330
|
+
options: {
|
|
1230
1331
|
policies: {
|
|
1231
1332
|
allowDotenvInProduction: ['PORT'] // Only PORT allowed from .env
|
|
1232
1333
|
// DATABASE_URL must come from process.env or cloud resolvers
|
|
1233
1334
|
}
|
|
1234
1335
|
}
|
|
1235
|
-
);
|
|
1336
|
+
});
|
|
1236
1337
|
```
|
|
1237
1338
|
|
|
1238
1339
|
### Policy: `enforceAllowedSources`
|
|
@@ -1240,18 +1341,21 @@ const config = await resolve.async(
|
|
|
1240
1341
|
Restrict sensitive variables to specific resolvers (e.g., force secrets to come from AWS):
|
|
1241
1342
|
|
|
1242
1343
|
```ts
|
|
1243
|
-
import {
|
|
1344
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
1345
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
1244
1346
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1245
1347
|
|
|
1246
|
-
const config = await
|
|
1247
|
-
[
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1348
|
+
const config = await resolveAsync({
|
|
1349
|
+
resolvers: [
|
|
1350
|
+
[processEnv(), {
|
|
1351
|
+
PORT: 3000,
|
|
1352
|
+
}],
|
|
1353
|
+
[awsSecrets({ secretId: 'prod/secrets' }), {
|
|
1354
|
+
DATABASE_PASSWORD: string(),
|
|
1355
|
+
API_KEY: string(),
|
|
1356
|
+
}]
|
|
1357
|
+
],
|
|
1358
|
+
options: {
|
|
1255
1359
|
policies: {
|
|
1256
1360
|
enforceAllowedSources: {
|
|
1257
1361
|
DATABASE_PASSWORD: ['aws-secrets'], // Must come from AWS
|
|
@@ -1260,31 +1364,33 @@ const config = await resolve.async(
|
|
|
1260
1364
|
}
|
|
1261
1365
|
}
|
|
1262
1366
|
}
|
|
1263
|
-
);
|
|
1367
|
+
});
|
|
1264
1368
|
```
|
|
1265
1369
|
|
|
1266
1370
|
**Use case:** Ensure production secrets only come from AWS Secrets Manager, never from `.env` or `process.env`:
|
|
1267
1371
|
|
|
1268
1372
|
```ts
|
|
1269
|
-
import {
|
|
1270
|
-
import {
|
|
1373
|
+
import { resolveAsync, processEnv } from 'node-env-resolver';
|
|
1374
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
1271
1375
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1272
1376
|
|
|
1273
|
-
const config = await
|
|
1274
|
-
[
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1377
|
+
const config = await resolveAsync({
|
|
1378
|
+
resolvers: [
|
|
1379
|
+
[processEnv(), {}],
|
|
1380
|
+
[awsSecrets({ secretId: 'prod/db' }), {
|
|
1381
|
+
DATABASE_PASSWORD: string(),
|
|
1382
|
+
STRIPE_SECRET: string(),
|
|
1383
|
+
}]
|
|
1384
|
+
],
|
|
1385
|
+
options: {
|
|
1280
1386
|
policies: {
|
|
1281
1387
|
enforceAllowedSources: {
|
|
1282
|
-
DATABASE_PASSWORD: ['
|
|
1283
|
-
STRIPE_SECRET: ['
|
|
1388
|
+
DATABASE_PASSWORD: ['aws-secrets'],
|
|
1389
|
+
STRIPE_SECRET: ['aws-secrets']
|
|
1284
1390
|
}
|
|
1285
1391
|
}
|
|
1286
1392
|
}
|
|
1287
|
-
);
|
|
1393
|
+
});
|
|
1288
1394
|
|
|
1289
1395
|
// ✅ If secrets come from AWS → Success
|
|
1290
1396
|
// ❌ If secrets come from process.env → Throws policy violation error
|
|
@@ -1324,11 +1430,12 @@ Track environment variable resolution for security and compliance monitoring.
|
|
|
1324
1430
|
|
|
1325
1431
|
```ts
|
|
1326
1432
|
import { resolve, getAuditLog, clearAuditLog } from 'node-env-resolver';
|
|
1433
|
+
import { postgres, string } from 'node-env-resolver/resolvers';
|
|
1327
1434
|
|
|
1328
1435
|
// Option 1: Explicitly enable (works in any environment)
|
|
1329
1436
|
const config = resolve({
|
|
1330
|
-
DATABASE_URL:
|
|
1331
|
-
API_KEY:
|
|
1437
|
+
DATABASE_URL: postgres(),
|
|
1438
|
+
API_KEY: string(),
|
|
1332
1439
|
}, {
|
|
1333
1440
|
enableAudit: true // ← Enable audit logging
|
|
1334
1441
|
});
|
|
@@ -1345,11 +1452,14 @@ clearAuditLog();
|
|
|
1345
1452
|
```
|
|
1346
1453
|
|
|
1347
1454
|
```ts
|
|
1455
|
+
import { resolve, getAuditLog } from 'node-env-resolver';
|
|
1456
|
+
import { postgres } from 'node-env-resolver/resolvers';
|
|
1457
|
+
|
|
1348
1458
|
// Option 2: Automatic in production
|
|
1349
1459
|
process.env.NODE_ENV = 'production';
|
|
1350
1460
|
|
|
1351
1461
|
const config = resolve({
|
|
1352
|
-
DATABASE_URL:
|
|
1462
|
+
DATABASE_URL: postgres(),
|
|
1353
1463
|
});
|
|
1354
1464
|
|
|
1355
1465
|
// Audit automatically enabled in production
|
|
@@ -1362,14 +1472,15 @@ When you have multiple `resolve()` calls, you can now get audit logs **specific
|
|
|
1362
1472
|
|
|
1363
1473
|
```ts
|
|
1364
1474
|
import { resolve, getAuditLog } from 'node-env-resolver';
|
|
1475
|
+
import { string, postgres } from 'node-env-resolver/resolvers';
|
|
1365
1476
|
|
|
1366
1477
|
const appConfig = resolve({
|
|
1367
1478
|
PORT: 3000,
|
|
1368
|
-
API_KEY:
|
|
1479
|
+
API_KEY: string()
|
|
1369
1480
|
}, { enableAudit: true });
|
|
1370
1481
|
|
|
1371
1482
|
const dbConfig = resolve({
|
|
1372
|
-
DATABASE_URL:
|
|
1483
|
+
DATABASE_URL: postgres(),
|
|
1373
1484
|
DB_POOL_SIZE: 10
|
|
1374
1485
|
}, { enableAudit: true });
|
|
1375
1486
|
|
|
@@ -1416,16 +1527,19 @@ console.log('DB config audit:', dbAudit);
|
|
|
1416
1527
|
Audit logs include cache metadata to help monitor performance:
|
|
1417
1528
|
|
|
1418
1529
|
```ts
|
|
1419
|
-
import {
|
|
1420
|
-
import { cached } from 'node-env-resolver/utils';
|
|
1530
|
+
import { resolveAsync, getAuditLog } from 'node-env-resolver';
|
|
1531
|
+
import { cached, TTL } from 'node-env-resolver/utils';
|
|
1532
|
+
import { postgres } from 'node-env-resolver/resolvers';
|
|
1421
1533
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1422
1534
|
|
|
1423
|
-
const config = await
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1535
|
+
const config = await resolveAsync({
|
|
1536
|
+
resolvers: [
|
|
1537
|
+
[cached(awsSecrets({ secretId: 'prod/db' }), { ttl: TTL.minutes5 }), {
|
|
1538
|
+
DATABASE_URL: postgres(),
|
|
1539
|
+
}]
|
|
1540
|
+
],
|
|
1541
|
+
options: { enableAudit: true }
|
|
1542
|
+
});
|
|
1429
1543
|
|
|
1430
1544
|
const logs = getAuditLog();
|
|
1431
1545
|
logs.forEach(log => {
|
|
@@ -1444,17 +1558,20 @@ logs.forEach(log => {
|
|
|
1444
1558
|
Use audit logs for compliance and security monitoring:
|
|
1445
1559
|
|
|
1446
1560
|
```ts
|
|
1447
|
-
import {
|
|
1561
|
+
import { resolveAsync, processEnv, getAuditLog } from 'node-env-resolver';
|
|
1562
|
+
import { string } from 'node-env-resolver/resolvers';
|
|
1448
1563
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
1449
1564
|
|
|
1450
1565
|
// In production
|
|
1451
|
-
const config = await
|
|
1452
|
-
[
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1566
|
+
const config = await resolveAsync({
|
|
1567
|
+
resolvers: [
|
|
1568
|
+
[processEnv(), {}],
|
|
1569
|
+
[awsSecrets(), {
|
|
1570
|
+
DATABASE_PASSWORD: string(),
|
|
1571
|
+
API_KEY: string(),
|
|
1572
|
+
}]
|
|
1573
|
+
],
|
|
1574
|
+
options: {
|
|
1458
1575
|
policies: {
|
|
1459
1576
|
enforceAllowedSources: {
|
|
1460
1577
|
DATABASE_PASSWORD: ['aws-secrets'],
|
|
@@ -1463,7 +1580,7 @@ const config = await resolve.async(
|
|
|
1463
1580
|
}
|
|
1464
1581
|
// enableAudit: true automatically in production
|
|
1465
1582
|
}
|
|
1466
|
-
);
|
|
1583
|
+
});
|
|
1467
1584
|
|
|
1468
1585
|
// Send audit logs to your monitoring system
|
|
1469
1586
|
const logs = getAuditLog();
|