node-env-resolver 5.0.1 → 6.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 CHANGED
@@ -16,7 +16,7 @@ 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
+ import { string } from 'node-env-resolver/validators';
20
20
 
21
21
  const config = resolve({
22
22
  PORT: 3000,
@@ -25,7 +25,15 @@ const config = resolve({
25
25
  API_KEY: string({optional:true})
26
26
  });
27
27
 
28
- // config is fully typed
28
+ // Resulting type (fully inferred):
29
+ // type config = {
30
+ // PORT: number;
31
+ // NODE_ENV: 'development' | 'production' | 'test';
32
+ // DEBUG: boolean;
33
+ // API_KEY: string | undefined;
34
+ // }
35
+
36
+ // TypeScript knows the exact types:
29
37
  config.PORT; // number
30
38
  config.NODE_ENV; // 'development' | 'production' | 'test'
31
39
  config.DEBUG; // boolean
@@ -35,8 +43,9 @@ config.API_KEY; // string | undefined
35
43
  ## Quick start (with custom resolvers)
36
44
 
37
45
  ```ts
38
- import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
39
- import { dotenv, string, url, postgres, redis } from 'node-env-resolver/resolvers';
46
+ import { resolve, resolveAsync } from 'node-env-resolver';
47
+ import { processEnv, dotenv } from 'node-env-resolver/resolvers';
48
+ import { string, url, postgres, redis } from 'node-env-resolver/validators';
40
49
  import { awsSecrets, gcpSecrets, vaultSecrets } from 'node-env-resolver-aws';
41
50
 
42
51
  // Synchronous with custom resolver (object syntax)
@@ -64,6 +73,15 @@ const config = await resolveAsync({
64
73
  ]
65
74
  });
66
75
 
76
+ // Resulting type (fully inferred):
77
+ // type config = {
78
+ // PORT: number;
79
+ // NODE_ENV: 'development' | 'production' | 'test';
80
+ // DEBUG: boolean;
81
+ // API_KEY: string | undefined;
82
+ // DATABASE_URL: string;
83
+ // }
84
+
67
85
  // Multiple resolvers with options
68
86
  const config = await resolveAsync({
69
87
  resolvers: [
@@ -86,7 +104,7 @@ const config = await resolveAsync({
86
104
  - [Required values](#required-values)
87
105
  - [Default values](#default-values)
88
106
  - [Optional values](#optional-values)
89
- - [Enums](#enums)
107
+ - [OneOf](#oneOf)
90
108
  - [Variable Naming Conventions](#variable-naming-conventions)
91
109
  - [Performance & Bundle Size](#performance--bundle-size)
92
110
  - [Custom validators](#custom-validators)
@@ -110,7 +128,7 @@ If an environment variable is missing and has no default, validation fails:
110
128
 
111
129
  ```ts
112
130
  import { resolve } from 'node-env-resolver';
113
- import { postgres, string } from 'node-env-resolver/resolvers';
131
+ import { postgres, string } from 'node-env-resolver/validators';
114
132
 
115
133
  const config = resolve({
116
134
  DATABASE_URL: postgres(), // Required PostgreSQL URL
@@ -137,7 +155,7 @@ const config = resolve({
137
155
  Use the `{optional: true}` option to make a value optional:
138
156
 
139
157
  ```ts
140
- import { string, url, number } from 'node-env-resolver/resolvers';
158
+ import { string, url, number } from 'node-env-resolver/validators';
141
159
 
142
160
  const config = resolve({
143
161
  API_KEY: string({optional: true}), // string | undefined
@@ -146,7 +164,7 @@ const config = resolve({
146
164
  });
147
165
  ```
148
166
 
149
- ### Enums
167
+ ### OneOf
150
168
 
151
169
  Use arrays for enum validation:
152
170
 
@@ -178,7 +196,7 @@ Variable names can use:
178
196
 
179
197
  ```ts
180
198
  import { resolve } from 'node-env-resolver';
181
- import { string } from 'node-env-resolver/resolvers';
199
+ import { string } from 'node-env-resolver/validators';
182
200
 
183
201
  const config = resolve({
184
202
  PORT: 3000, // ✅ SCREAMING_SNAKE_CASE (traditional)
@@ -194,7 +212,7 @@ const config = resolve({
194
212
 
195
213
  ```ts
196
214
  import { resolve } from 'node-env-resolver';
197
- import { string } from 'node-env-resolver/resolvers';
215
+ import { string } from 'node-env-resolver/validators';
198
216
 
199
217
  const config = resolve({
200
218
  '123PORT': 3000, // ❌ Starts with number
@@ -214,8 +232,9 @@ const config = resolve({
214
232
  **Lightweight** The core library is **~4.3KB gzipped** with validation and resolver capabilities - **optimized for minimal bundle impact**.
215
233
 
216
234
  ```ts
217
- import { resolveAsync, processEnv } from 'node-env-resolver';
218
- import { dotenv, json, postgres, string, redis } from 'node-env-resolver/resolvers';
235
+ import { resolveAsync } from 'node-env-resolver';
236
+ import { processEnv, dotenv, json } from 'node-env-resolver/resolvers';
237
+ import { postgres, string, redis } from 'node-env-resolver/validators';
219
238
  import { awsSecrets } from 'node-env-resolver-aws';
220
239
 
221
240
  const config = await resolveAsync({
@@ -253,7 +272,7 @@ Advanced validators are lazy-loaded only when you use them, keeping the base bun
253
272
 
254
273
  ```ts
255
274
  import { resolve, resolveAsync } from 'node-env-resolver';
256
- import { postgres, url } from 'node-env-resolver/resolvers';
275
+ import { postgres, url } from 'node-env-resolver/validators';
257
276
  import { awsSecrets } from 'node-env-resolver-aws';
258
277
 
259
278
  // Synchronous - works with all types
@@ -308,16 +327,16 @@ Import only what you need for optimal bundle size:
308
327
 
309
328
  ```ts
310
329
  // Core (~3.6KB) - Main API
311
- import { resolve, safeResolve, processEnv } from 'node-env-resolver';
330
+ import { resolve, safeResolve } from 'node-env-resolver';
312
331
 
313
332
  // Resolvers (separate chunk) - .env file parsing
314
- import { dotenv } from 'node-env-resolver/resolvers';
333
+ import { processEnv, dotenv } from 'node-env-resolver/resolvers';
315
334
 
316
335
  // Utils (separate chunk) - caching & retry logic
317
336
  import { cached, retry, TTL, awsCache } from 'node-env-resolver/utils';
318
337
 
319
338
  // Validators (separate chunk) - reusable validation functions
320
- import { validateUrl, validateEmail } from 'node-env-resolver/validators';
339
+ import { url, email } from 'node-env-resolver/validators';
321
340
 
322
341
  // Integrations (separate packages)
323
342
  import { resolveZod } from 'node-env-resolver/zod';
@@ -361,11 +380,11 @@ For advanced use cases, you can import and compose the built-in validation funct
361
380
 
362
381
  ```ts
363
382
  import { resolve } from 'node-env-resolver';
364
- import { validateUrl, validateEmail } from 'node-env-resolver/validators';
383
+ import { url, email } from 'node-env-resolver/validators';
365
384
 
366
385
  const validateMarketingUrl = (value: string): string => {
367
386
  // Reuse built-in URL validator
368
- const result = validateUrl(value);
387
+ const result = url(value);
369
388
  if (!result.valid) {
370
389
  throw new Error(result.error || 'Invalid URL');
371
390
  }
@@ -383,14 +402,15 @@ const config = resolve({
383
402
  });
384
403
  ```
385
404
 
386
- Available validation functions: `validatePostgres`, `validateMysql`, `validateMongodb`, `validateRedis`, `validateHttp`, `validateHttps`, `validateUrl`, `validateEmail`, `validatePort`, `validateNumber`, `validateBoolean`, `validateJson`, `validateDate`, `validateTimestamp`.
405
+ Available validation functions: `validatePostgres`, `mysql`, `mongodb`, `redis`, `http`, `https`, `url`, `email`, `port`, `number`, `boolean`, `json`, `date`, `timestamp`.
387
406
 
388
407
  ## Multiple sources
389
408
 
390
409
  Load configuration from multiple sources. By default, later sources override earlier ones:
391
410
  ```ts
392
- import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
393
- import { dotenv, json, postgres, string, redis } from 'node-env-resolver/resolvers';
411
+ import { resolve, resolveAsync } from 'node-env-resolver';
412
+ import { processEnv, dotenv, json } from 'node-env-resolver/resolvers';
413
+ import { postgres, string, redis } from 'node-env-resolver/validators';
394
414
  import { awsSecrets } from 'node-env-resolver-aws';
395
415
 
396
416
  // Async mode - supports both sync and async resolvers
@@ -432,8 +452,9 @@ const config = await resolveAsync({
432
452
  Use `priority` to control how resolvers merge values (works with both sync and async modes):
433
453
 
434
454
  ```ts
435
- import { resolve, resolveAsync, processEnv } from 'node-env-resolver';
436
- import { dotenv, json, postgres } from 'node-env-resolver/resolvers';
455
+ import { resolve, resolveAsync } from 'node-env-resolver';
456
+ import { processEnv, dotenv, json } from 'node-env-resolver/resolvers';
457
+ import { postgres } from 'node-env-resolver/validators';
437
458
  import { awsSecrets } from 'node-env-resolver-aws';
438
459
 
439
460
  // priority: 'last' (default) - later resolvers override earlier ones
@@ -478,7 +499,8 @@ When using `priority: 'first'`, resolvers are called sequentially, but execution
478
499
 
479
500
  ```ts
480
501
  import { resolveAsync } from 'node-env-resolver';
481
- import { dotenv, postgres, string } from 'node-env-resolver/resolvers';
502
+ import { dotenv } from 'node-env-resolver/resolvers';
503
+ import { postgres, string } from 'node-env-resolver/validators';
482
504
  import { awsSecrets } from 'node-env-resolver-aws';
483
505
 
484
506
  const config = await resolveAsync({
@@ -508,7 +530,7 @@ When using `priority: 'last'` (the default), all resolvers are called **in paral
508
530
 
509
531
  ```ts
510
532
  import { resolveAsync } from 'node-env-resolver';
511
- import { postgres, string } from 'node-env-resolver/resolvers';
533
+ import { postgres, string } from 'node-env-resolver/validators';
512
534
  import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
513
535
 
514
536
  const config = await resolveAsync({
@@ -535,7 +557,7 @@ Like Zod's `safeParse()`, use `safeResolve()` to get a result object instead of
535
557
 
536
558
  ```ts
537
559
  import { safeResolve, safeResolveAsync } from 'node-env-resolver';
538
- import { number, postgres } from 'node-env-resolver/resolvers';
560
+ import { number, postgres } from 'node-env-resolver/validators';
539
561
 
540
562
  // Synchronous safe resolve
541
563
  const result = safeResolve({
@@ -572,7 +594,7 @@ All functions have safe variants:
572
594
 
573
595
  ```ts
574
596
  import { resolve } from 'node-env-resolver';
575
- import { string, url, postgres } from 'node-env-resolver/resolvers';
597
+ import { string, url, postgres } from 'node-env-resolver/validators';
576
598
 
577
599
  // Synchronous - no await needed, works with ALL types
578
600
  const config = resolve({
@@ -588,8 +610,9 @@ const config = resolve({
588
610
  `resolveAsync()` is **async** when using custom resolvers:
589
611
 
590
612
  ```ts
591
- import { resolveAsync, processEnv } from 'node-env-resolver';
592
- import { dotenv, postgres, url } from 'node-env-resolver/resolvers';
613
+ import { resolveAsync } from 'node-env-resolver';
614
+ import { processEnv, dotenv } from 'node-env-resolver/resolvers';
615
+ import { postgres, url } from 'node-env-resolver/validators';
593
616
 
594
617
  // Async - await required when using custom resolvers
595
618
  const config = await resolveAsync({
@@ -607,8 +630,9 @@ const config = await resolveAsync({
607
630
  Parse command-line arguments as environment variables - perfect for CLI tools:
608
631
 
609
632
  ```ts
610
- import { resolveAsync, processEnv } from 'node-env-resolver';
611
- import { postgres } from 'node-env-resolver/resolvers';
633
+ import { resolveAsync } from 'node-env-resolver';
634
+ import { processEnv } from 'node-env-resolver/resolvers';
635
+ import { postgres } from 'node-env-resolver/validators';
612
636
  import { cliArgs } from 'node-env-resolver/cli';
613
637
 
614
638
  // $ node app.js --port 8080 --database-url postgres://localhost --verbose
@@ -812,8 +836,9 @@ if (result.success) {
812
836
  Create resolvers to load configuration from any source:
813
837
 
814
838
  ```ts
815
- import { resolveAsync, processEnv, type Resolver } from 'node-env-resolver';
816
- import { string } from 'node-env-resolver/resolvers';
839
+ import { resolveAsync, type Resolver } from 'node-env-resolver';
840
+ import { processEnv } from 'node-env-resolver/resolvers';
841
+ import { string } from 'node-env-resolver/validators';
817
842
 
818
843
  const databaseResolver: Resolver = {
819
844
  name: 'database',
@@ -843,7 +868,7 @@ Single source:
843
868
 
844
869
  ```ts
845
870
  import { resolveSecrets } from 'node-env-resolver-aws';
846
- import { postgres, string } from 'node-env-resolver/resolvers';
871
+ import { postgres, string } from 'node-env-resolver/validators';
847
872
 
848
873
  const config = await resolveSecrets({
849
874
  secretId: 'myapp/secrets'
@@ -856,8 +881,9 @@ const config = await resolveSecrets({
856
881
  Multiple sources:
857
882
 
858
883
  ```ts
859
- import { resolveAsync, processEnv } from 'node-env-resolver';
860
- import { postgres, string } from 'node-env-resolver/resolvers';
884
+ import { resolveAsync } from 'node-env-resolver';
885
+ import { processEnv } from 'node-env-resolver/resolvers';
886
+ import { postgres, string } from 'node-env-resolver/validators';
861
887
  import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
862
888
 
863
889
  const config = await resolveAsync({
@@ -878,7 +904,7 @@ Cache expensive operations like AWS API calls:
878
904
  ```ts
879
905
  import { resolveAsync } from 'node-env-resolver';
880
906
  import { cached, TTL } from 'node-env-resolver/utils';
881
- import { postgres, string } from 'node-env-resolver/resolvers';
907
+ import { postgres, string } from 'node-env-resolver/validators';
882
908
  import { awsSecrets } from 'node-env-resolver-aws';
883
909
 
884
910
  export const getConfig = async () => {
@@ -948,7 +974,7 @@ import {
948
974
  string, number, boolean, url, email, port, json,
949
975
  postgres, mysql, mongodb, redis,
950
976
  http, https, date, timestamp, duration, file
951
- } from 'node-env-resolver/resolvers';
977
+ } from 'node-env-resolver/validators';
952
978
  ```
953
979
 
954
980
  | Syntax | Type | Description |
@@ -1022,7 +1048,7 @@ const config = await resolveAsync({
1022
1048
 
1023
1049
  ```ts
1024
1050
  import { resolve } from 'node-env-resolver';
1025
- import { url } from 'node-env-resolver/resolvers';
1051
+ import { url } from 'node-env-resolver/validators';
1026
1052
 
1027
1053
  // With interpolation
1028
1054
  process.env.BASE_URL = 'https://api.example.com';
@@ -1097,8 +1123,9 @@ await resolveAsync({
1097
1123
  **Default:** `'last'`
1098
1124
 
1099
1125
  ```ts
1100
- import { resolveAsync, processEnv } from 'node-env-resolver';
1101
- import { dotenv, postgres } from 'node-env-resolver/resolvers';
1126
+ import { resolveAsync } from 'node-env-resolver';
1127
+ import { processEnv, dotenv } from 'node-env-resolver/resolvers';
1128
+ import { postgres } from 'node-env-resolver/validators';
1102
1129
  import { awsSecrets } from 'node-env-resolver-aws';
1103
1130
 
1104
1131
  // Production: AWS secrets override process.env
@@ -1212,7 +1239,7 @@ interface PolicyOptions {
1212
1239
  ```ts
1213
1240
  import express from 'express';
1214
1241
  import { resolve } from 'node-env-resolver';
1215
- import { postgres, string } from 'node-env-resolver/resolvers';
1242
+ import { postgres, string } from 'node-env-resolver/validators';
1216
1243
 
1217
1244
  const config = resolve({
1218
1245
  PORT: 3000,
@@ -1229,7 +1256,7 @@ app.listen(config.PORT);
1229
1256
  ```ts
1230
1257
  // env.mjs
1231
1258
  import { resolve } from 'node-env-resolver/nextjs';
1232
- import { postgres, string, url } from 'node-env-resolver/resolvers';
1259
+ import { postgres, string, url } from 'node-env-resolver/validators';
1233
1260
 
1234
1261
  export const env = resolve({
1235
1262
  server: {
@@ -1247,7 +1274,7 @@ export const env = resolve({
1247
1274
  ```ts
1248
1275
  import { resolveAsync } from 'node-env-resolver';
1249
1276
  import { cached, TTL } from 'node-env-resolver/utils';
1250
- import { postgres } from 'node-env-resolver/resolvers';
1277
+ import { postgres } from 'node-env-resolver/validators';
1251
1278
  import { awsSecrets } from 'node-env-resolver-aws';
1252
1279
 
1253
1280
  const getConfig = async () => {
@@ -1281,7 +1308,8 @@ By default, `.env` files are **completely blocked in production** for security.
1281
1308
 
1282
1309
  ```ts
1283
1310
  import { resolveAsync } from 'node-env-resolver';
1284
- import { dotenv, postgres } from 'node-env-resolver/resolvers';
1311
+ import { dotenv } from 'node-env-resolver/resolvers';
1312
+ import { postgres } from 'node-env-resolver/validators';
1285
1313
 
1286
1314
  // In production (NODE_ENV=production)
1287
1315
  const config = await resolveAsync({
@@ -1298,7 +1326,8 @@ const config = await resolveAsync({
1298
1326
 
1299
1327
  ```ts
1300
1328
  import { resolveAsync } from 'node-env-resolver';
1301
- import { dotenv, postgres } from 'node-env-resolver/resolvers';
1329
+ import { dotenv } from 'node-env-resolver/resolvers';
1330
+ import { postgres } from 'node-env-resolver/validators';
1302
1331
 
1303
1332
  const config = await resolveAsync({
1304
1333
  resolvers: [
@@ -1318,7 +1347,8 @@ const config = await resolveAsync({
1318
1347
 
1319
1348
  ```ts
1320
1349
  import { resolveAsync } from 'node-env-resolver';
1321
- import { dotenv, postgres } from 'node-env-resolver/resolvers';
1350
+ import { dotenv } from 'node-env-resolver/resolvers';
1351
+ import { postgres } from 'node-env-resolver/validators';
1322
1352
 
1323
1353
  const config = await resolveAsync({
1324
1354
  resolvers: [
@@ -1341,8 +1371,9 @@ const config = await resolveAsync({
1341
1371
  Restrict sensitive variables to specific resolvers (e.g., force secrets to come from AWS):
1342
1372
 
1343
1373
  ```ts
1344
- import { resolveAsync, processEnv } from 'node-env-resolver';
1345
- import { string } from 'node-env-resolver/resolvers';
1374
+ import { resolveAsync } from 'node-env-resolver';
1375
+ import { processEnv } from 'node-env-resolver/resolvers';
1376
+ import { string } from 'node-env-resolver/validators';
1346
1377
  import { awsSecrets } from 'node-env-resolver-aws';
1347
1378
 
1348
1379
  const config = await resolveAsync({
@@ -1370,8 +1401,9 @@ const config = await resolveAsync({
1370
1401
  **Use case:** Ensure production secrets only come from AWS Secrets Manager, never from `.env` or `process.env`:
1371
1402
 
1372
1403
  ```ts
1373
- import { resolveAsync, processEnv } from 'node-env-resolver';
1374
- import { string } from 'node-env-resolver/resolvers';
1404
+ import { resolveAsync } from 'node-env-resolver';
1405
+ import { processEnv } from 'node-env-resolver/resolvers';
1406
+ import { string } from 'node-env-resolver/validators';
1375
1407
  import { awsSecrets } from 'node-env-resolver-aws';
1376
1408
 
1377
1409
  const config = await resolveAsync({
@@ -1430,7 +1462,7 @@ Track environment variable resolution for security and compliance monitoring.
1430
1462
 
1431
1463
  ```ts
1432
1464
  import { resolve, getAuditLog, clearAuditLog } from 'node-env-resolver';
1433
- import { postgres, string } from 'node-env-resolver/resolvers';
1465
+ import { postgres, string } from 'node-env-resolver/validators';
1434
1466
 
1435
1467
  // Option 1: Explicitly enable (works in any environment)
1436
1468
  const config = resolve({
@@ -1453,7 +1485,7 @@ clearAuditLog();
1453
1485
 
1454
1486
  ```ts
1455
1487
  import { resolve, getAuditLog } from 'node-env-resolver';
1456
- import { postgres } from 'node-env-resolver/resolvers';
1488
+ import { postgres } from 'node-env-resolver/validators';
1457
1489
 
1458
1490
  // Option 2: Automatic in production
1459
1491
  process.env.NODE_ENV = 'production';
@@ -1472,7 +1504,7 @@ When you have multiple `resolve()` calls, you can now get audit logs **specific
1472
1504
 
1473
1505
  ```ts
1474
1506
  import { resolve, getAuditLog } from 'node-env-resolver';
1475
- import { string, postgres } from 'node-env-resolver/resolvers';
1507
+ import { string, postgres } from 'node-env-resolver/validators';
1476
1508
 
1477
1509
  const appConfig = resolve({
1478
1510
  PORT: 3000,
@@ -1529,7 +1561,7 @@ Audit logs include cache metadata to help monitor performance:
1529
1561
  ```ts
1530
1562
  import { resolveAsync, getAuditLog } from 'node-env-resolver';
1531
1563
  import { cached, TTL } from 'node-env-resolver/utils';
1532
- import { postgres } from 'node-env-resolver/resolvers';
1564
+ import { postgres } from 'node-env-resolver/validators';
1533
1565
  import { awsSecrets } from 'node-env-resolver-aws';
1534
1566
 
1535
1567
  const config = await resolveAsync({
@@ -1558,8 +1590,9 @@ logs.forEach(log => {
1558
1590
  Use audit logs for compliance and security monitoring:
1559
1591
 
1560
1592
  ```ts
1561
- import { resolveAsync, processEnv, getAuditLog } from 'node-env-resolver';
1562
- import { string } from 'node-env-resolver/resolvers';
1593
+ import { resolveAsync, getAuditLog } from 'node-env-resolver';
1594
+ import { processEnv } from 'node-env-resolver/resolvers';
1595
+ import { string } from 'node-env-resolver/validators';
1563
1596
  import { awsSecrets } from 'node-env-resolver-aws';
1564
1597
 
1565
1598
  // In production
@@ -1592,6 +1625,35 @@ if (policyViolations.length > 0) {
1592
1625
  }
1593
1626
  ```
1594
1627
 
1628
+ ## Troubleshooting
1629
+
1630
+ ### TypeScript: Cannot find module 'node-env-resolver/validators'
1631
+
1632
+ If you're using `moduleResolution: "bundler"` in your `tsconfig.json` and TypeScript can't resolve subpath exports like `node-env-resolver/validators`, this is a known TypeScript limitation (see [TypeScript issue #55337](https://github.com/microsoft/TypeScript/issues/55337)).
1633
+
1634
+ **Workaround options:**
1635
+
1636
+ 1. **Use `moduleResolution: "NodeNext"`** (recommended for most projects):
1637
+ ```json
1638
+ {
1639
+ "compilerOptions": {
1640
+ "moduleResolution": "NodeNext",
1641
+ "module": "NodeNext"
1642
+ }
1643
+ }
1644
+ ```
1645
+
1646
+ 2. **Use `moduleResolution: "Node"`** (legacy but widely supported):
1647
+ ```json
1648
+ {
1649
+ "compilerOptions": {
1650
+ "moduleResolution": "Node"
1651
+ }
1652
+ }
1653
+ ```
1654
+
1655
+ **Note:** The runtime will work correctly regardless of TypeScript's resolution mode. This is purely a TypeScript type-checking issue, not a runtime problem.
1656
+
1595
1657
  ## Error messages
1596
1658
 
1597
1659
  The library provides clear, actionable error messages:
package/dist/audit.d.cts CHANGED
@@ -1,14 +1,27 @@
1
1
  /**
2
2
  * Audit logging for environment variable resolution
3
3
  */
4
+ /**
5
+ * Types of audit events that can be logged
6
+ */
4
7
  type AuditEventType = 'validation_success' | 'validation_failure' | 'policy_violation' | 'env_loaded' | 'provider_error' | 'resolver_error';
8
+ /**
9
+ * Individual audit event record
10
+ */
5
11
  interface AuditEvent {
12
+ /** Type of audit event */
6
13
  type: AuditEventType;
14
+ /** Timestamp when the event occurred */
7
15
  timestamp: number;
16
+ /** Environment variable key (if applicable) */
8
17
  key?: string;
18
+ /** Source resolver name (if applicable) */
9
19
  source?: string;
20
+ /** Error message (if applicable) */
10
21
  error?: string;
22
+ /** Additional metadata about the event */
11
23
  metadata?: Record<string, unknown>;
24
+ /** Session ID for tracking per-config audit logs */
12
25
  sessionId?: string;
13
26
  }
14
27
  /**
@@ -16,6 +29,12 @@ interface AuditEvent {
16
29
  * Returns the session ID for use in audit events
17
30
  */
18
31
  declare function attachAuditSession(config: object): string;
32
+ /**
33
+ * Log an audit event to the audit log
34
+ * Automatically manages log size to prevent memory leaks
35
+ *
36
+ * @param event - Audit event to log
37
+ */
19
38
  declare function logAuditEvent(event: AuditEvent): void;
20
39
  /**
21
40
  * Get audit log, optionally filtered by config object
@@ -24,6 +43,10 @@ declare function logAuditEvent(event: AuditEvent): void;
24
43
  * @returns Audit events (all events if no config provided, or filtered by config's session)
25
44
  */
26
45
  declare function getAuditLog(config?: object): readonly AuditEvent[];
46
+ /**
47
+ * Clear all audit events from the audit log
48
+ * Useful for testing or memory management
49
+ */
27
50
  declare function clearAuditLog(): void;
28
51
 
29
52
  export { type AuditEvent, type AuditEventType, attachAuditSession, clearAuditLog, getAuditLog, logAuditEvent };
package/dist/audit.d.ts CHANGED
@@ -1,14 +1,27 @@
1
1
  /**
2
2
  * Audit logging for environment variable resolution
3
3
  */
4
+ /**
5
+ * Types of audit events that can be logged
6
+ */
4
7
  type AuditEventType = 'validation_success' | 'validation_failure' | 'policy_violation' | 'env_loaded' | 'provider_error' | 'resolver_error';
8
+ /**
9
+ * Individual audit event record
10
+ */
5
11
  interface AuditEvent {
12
+ /** Type of audit event */
6
13
  type: AuditEventType;
14
+ /** Timestamp when the event occurred */
7
15
  timestamp: number;
16
+ /** Environment variable key (if applicable) */
8
17
  key?: string;
18
+ /** Source resolver name (if applicable) */
9
19
  source?: string;
20
+ /** Error message (if applicable) */
10
21
  error?: string;
22
+ /** Additional metadata about the event */
11
23
  metadata?: Record<string, unknown>;
24
+ /** Session ID for tracking per-config audit logs */
12
25
  sessionId?: string;
13
26
  }
14
27
  /**
@@ -16,6 +29,12 @@ interface AuditEvent {
16
29
  * Returns the session ID for use in audit events
17
30
  */
18
31
  declare function attachAuditSession(config: object): string;
32
+ /**
33
+ * Log an audit event to the audit log
34
+ * Automatically manages log size to prevent memory leaks
35
+ *
36
+ * @param event - Audit event to log
37
+ */
19
38
  declare function logAuditEvent(event: AuditEvent): void;
20
39
  /**
21
40
  * Get audit log, optionally filtered by config object
@@ -24,6 +43,10 @@ declare function logAuditEvent(event: AuditEvent): void;
24
43
  * @returns Audit events (all events if no config provided, or filtered by config's session)
25
44
  */
26
45
  declare function getAuditLog(config?: object): readonly AuditEvent[];
46
+ /**
47
+ * Clear all audit events from the audit log
48
+ * Useful for testing or memory management
49
+ */
27
50
  declare function clearAuditLog(): void;
28
51
 
29
52
  export { type AuditEvent, type AuditEventType, attachAuditSession, clearAuditLog, getAuditLog, logAuditEvent };
package/dist/builder.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkXPL5XLTA_cjs=require('./chunk-XPL5XLTA.cjs'),chunk4YVXFL3I_cjs=require('./chunk-4YVXFL3I.cjs');require('./chunk-4ZOF2PI4.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=chunk4YVXFL3I_cjs.a(this.localSchema);for(let l of this.layers){let m=chunk4YVXFL3I_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunk4YVXFL3I_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkXPL5XLTA_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=chunk4YVXFL3I_cjs.a(this.localSchema);for(let l of this.layers){let m=chunk4YVXFL3I_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunk4YVXFL3I_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkXPL5XLTA_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};exports.EnvBuilder=i;exports.EnvBuilderSync=n;exports.ResolvableBuilder=d;exports.ResolvableBuilderSync=S;exports.env=y;exports.envSync=b;
1
+ 'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),chunkOSMNJM5N_cjs=require('./chunk-OSMNJM5N.cjs');require('./chunk-4ZOF2PI4.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=chunkOSMNJM5N_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkOSMNJM5N_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkOSMNJM5N_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkPNUGGPRS_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=chunkOSMNJM5N_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkOSMNJM5N_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkOSMNJM5N_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkPNUGGPRS_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};exports.EnvBuilder=i;exports.EnvBuilderSync=n;exports.ResolvableBuilder=d;exports.ResolvableBuilderSync=S;exports.env=y;exports.envSync=b;
package/dist/builder.js CHANGED
@@ -1 +1 @@
1
- import {a as a$1}from'./chunk-TAX63ALN.js';import {a,c}from'./chunk-DIXI6MUB.js';import'./chunk-YOHHFBZN.js';import {a as a$2}from'./chunk-WKIPEKF6.js';import'./chunk-5PELJRUQ.js';var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};export{i as EnvBuilder,n as EnvBuilderSync,d as ResolvableBuilder,S as ResolvableBuilderSync,y as env,b as envSync};
1
+ import {a as a$1}from'./chunk-LCW5BDAW.js';import {a,c}from'./chunk-3KAHSFPX.js';import'./chunk-YOHHFBZN.js';import {a as a$2}from'./chunk-WKIPEKF6.js';import'./chunk-5PELJRUQ.js';var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};export{i as EnvBuilder,n as EnvBuilderSync,d as ResolvableBuilder,S as ResolvableBuilderSync,y as env,b as envSync};
@@ -0,0 +1,9 @@
1
+ import {f,e}from'./chunk-YOHHFBZN.js';import {d}from'./chunk-5PELJRUQ.js';import {join,resolve}from'path';import {readFileSync}from'fs';function C(s,c){try{let r=resolve(process.cwd(),s);return {valid:!0,value:readFileSync(r,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${c?` for ${c}`:""}: ${r instanceof Error?r.message:String(r)}`}}}var D=null,h=null;async function E(s){if(!D){let c=await import('./audit.js');D=c.logAuditEvent,h=c.attachAuditSession;}D(s);}function b(s){if(!D)try{let c=(f(),d(e));D=c.logAuditEvent,h=c.attachAuditSession;}catch{return}D&&D(s);}function U(s){let c={};for(let[r,o]of Object.entries(s))if(typeof o=="function"){let a=o,t=a.__isFileValidator===true;c[r]={type:t?"file":"custom",validator:o,...a.default!==void 0&&{default:a.default},...a.optional!==void 0&&{optional:a.optional},...a.secretsDir!==void 0&&{secretsDir:a.secretsDir}};}else if(typeof o=="string")c[r]={type:"string",default:o,validator:a=>{if(a===""&&!c[r].allowEmpty)throw new Error("String cannot be empty");return a}};else if(typeof o=="number")c[r]={type:"number",default:o,validator:a=>{let t=Number(a);if(isNaN(t))throw new Error(`Invalid number: "${a}"`);return t}};else if(typeof o=="boolean")c[r]={type:"boolean",default:o,validator:a=>{let t=a.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${a}"`)}};else if(Array.isArray(o)){let a=o.map(String);c[r]={type:"string",enum:a,validator:(t,m)=>{if(!a.includes(t)){let n=m||r;throw new Error(`${n} must be one of: ${a.join(", ")}`)}return t}};}else c[r]=o;return c}function L(s,c){return s.replace(/\$\{([^}]+)\}/g,(r,o)=>c[o]||r)}async function B(s,c,r,o="last",a){let t={},m={};if(o==="last"){let n=await Promise.allSettled(s.map(async i=>({resolver:i,env:i.load?await i.load():{}})));for(let i of n){if(i.status==="rejected"){let u=i.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),r)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=i.value;for(let[u,y]of Object.entries(f))y!==void 0&&(t[u]=y,m[u]={source:d.name||"unknown",timestamp:Date.now(),...d.metadata?.cached!==void 0&&{cached:!!d.metadata.cached}});}}else for(let n of s)try{let i=n.load?await n.load():{};for(let[d,f]of Object.entries(i))if(f!==void 0){if(t[d]!==void 0)continue;t[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(a&&a.size>0&&Array.from(a).every(f=>t[f]!==void 0))break}catch(i){if(await E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),r)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(c)for(let[n,i]of Object.entries(t))t[n]=L(i,t);return {mergedEnv:t,provenance:m}}function M(s,c,r,o="last",a){let t={},m={};for(let n of s)try{if(!n.loadSync){if(r)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let i=n.loadSync();for(let[d,f]of Object.entries(i))if(f!==void 0){if(o==="first"&&t[d]!==void 0)continue;t[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&a&&a.size>0&&Array.from(a).every(f=>t[f]!==void 0))break}catch(i){if(b({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),r)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(c)for(let[n,i]of Object.entries(t))t[n]=L(i,t);return {mergedEnv:t,provenance:m}}function T(s,c,r,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&r&&r.source.startsWith("dotenv(")){let t=o.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(s)?null:`${s} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${s}'] or set to true for all.`:`${s} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[s]&&r){let t=o.enforceAllowedSources[s];if(!t.includes(r.source))return `${s} must be sourced from one of: ${t.join(", ")} (actual: ${r.source})`}return null}function x(s){let c=[],r=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(s))r.test(o)||c.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return c}function z(s,c){let r={};for(let[o,a]of Object.entries(s)){if(!o.includes(c)){r[o]=a;continue}let t=o.split(c),m=r;for(let i=0;i<t.length-1;i++){let d=t[i].toLowerCase();d in m||(m[d]={}),m=m[d];}let n=t[t.length-1].toLowerCase();m[n]=a;}return r}async function G(s,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:t=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=r,f={},u;if(n){if(!h){let e=await import('./audit.js');D=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
2
+ ${y.map(e=>` - ${e}`).join(`
3
+ `)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=await B(c,a,t,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let l;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=join(v,j),R=C(P,e);R.valid?(l={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):l={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?l={success:!0,value:p.default}:p.optional?l={success:!0,value:void 0}:l={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{l={success:!0,value:p.validator($,e)};}catch(v){l={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else l={success:!0,value:$};l.success?(f[e]=l.value,n&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(l.error),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:l.error,sessionId:u}));}catch(l){let v=l instanceof Error?l.message:String(l);g.push(`${e}: ${v}`),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
4
+ ${g.map(e=>` - ${e}`).join(`
5
+ `)}`);return n&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),r.nestedDelimiter?z(f,r.nestedDelimiter):f}function H(s,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:t=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d$1}=r,f$1={},u;if(n){if(!h)try{let e$1=(f(),d(e));D=e$1.logAuditEvent,h=e$1.attachAuditSession;}catch{}h&&(u=h(f$1));}let y=x(s);if(y.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
6
+ ${y.map(e=>` - ${e}`).join(`
7
+ `)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=M(c,a,t,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&b({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let l;if($===void 0){let v=p.secretsDir??d$1;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=join(v,j),R=C(P,e);R.valid?(l={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):l={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?l={success:!0,value:p.default}:p.optional?l={success:!0,value:void 0}:l={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{l={success:!0,value:p.validator($,e)};}catch(v){l={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else l={success:!0,value:$};l.success?(f$1[e]=l.value,n&&b({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(l.error),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:l.error,sessionId:u}));}catch(l){let v=l instanceof Error?l.message:String(l);g.push(`${e}: ${v}`),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
8
+ ${g.map(e=>` - ${e}`).join(`
9
+ `)}`);return n&&b({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),r.nestedDelimiter?z(f$1,r.nestedDelimiter):f$1}export{U as a,G as b,H as c};