node-env-resolver 3.0.1 → 4.0.0

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.
Files changed (59) hide show
  1. package/README.md +166 -54
  2. package/dist/audit.cjs +1 -0
  3. package/dist/audit.d.ts +13 -1
  4. package/dist/audit.d.ts.map +1 -1
  5. package/dist/audit.js +1 -1
  6. package/dist/builder.cjs +1 -0
  7. package/dist/builder.js +1 -1
  8. package/dist/chunk-4ZOF2PI4.cjs +1 -0
  9. package/dist/chunk-54OHKWZJ.js +1 -0
  10. package/dist/chunk-5PELJRUQ.js +1 -0
  11. package/dist/chunk-FCFDGYTF.cjs +15 -0
  12. package/dist/chunk-HCVTYYLE.js +9 -0
  13. package/dist/{chunk-QWDK3BUB.js → chunk-IU5TG3HL.js} +1 -1
  14. package/dist/chunk-J7ZHEMRP.js +9 -0
  15. package/dist/chunk-KIQXH265.cjs +1 -0
  16. package/dist/{chunk-VJZZNSRI.js → chunk-NKPXKLF7.js} +1 -1
  17. package/dist/chunk-P3ZWKKKW.cjs +1 -0
  18. package/dist/chunk-THFGEKYL.cjs +9 -0
  19. package/dist/chunk-ULL4WKTV.cjs +9 -0
  20. package/dist/chunk-XPGSWVRT.cjs +1 -0
  21. package/dist/chunk-YOHHFBZN.js +1 -0
  22. package/dist/cli.cjs +1 -0
  23. package/dist/cli.d.ts +1 -1
  24. package/dist/cli.js +1 -1
  25. package/dist/index.cjs +1 -0
  26. package/dist/index.d.ts +93 -20
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/resolver.cjs +1 -0
  30. package/dist/resolver.d.ts.map +1 -1
  31. package/dist/resolver.js +1 -1
  32. package/dist/resolvers.cjs +1 -0
  33. package/dist/resolvers.d.ts +8 -8
  34. package/dist/resolvers.d.ts.map +1 -1
  35. package/dist/resolvers.js +1 -1
  36. package/dist/sync-resolvers.test.d.ts +2 -0
  37. package/dist/sync-resolvers.test.d.ts.map +1 -0
  38. package/dist/types.cjs +1 -0
  39. package/dist/types.d.ts +10 -2
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +1 -0
  42. package/dist/utils.cjs +1 -0
  43. package/dist/utils.d.ts +15 -13
  44. package/dist/utils.d.ts.map +1 -1
  45. package/dist/utils.js +1 -1
  46. package/dist/valibot.cjs +1 -0
  47. package/dist/valibot.js +1 -1
  48. package/dist/validation-types.cjs +1 -0
  49. package/dist/validators.cjs +1 -0
  50. package/dist/validators.js +1 -1
  51. package/dist/web.cjs +6 -0
  52. package/dist/web.js +4 -4
  53. package/dist/zod.cjs +1 -0
  54. package/dist/zod.js +1 -1
  55. package/package.json +27 -15
  56. package/dist/chunk-476ZUILE.js +0 -1
  57. package/dist/chunk-DAGPFV3V.js +0 -1
  58. package/dist/chunk-MGTYH57K.js +0 -9
  59. package/dist/chunk-MWG7FWHN.js +0 -5
package/README.md CHANGED
@@ -31,34 +31,45 @@ config.DEBUG; // boolean
31
31
  config.API_KEY; // string | undefined
32
32
  ```
33
33
 
34
- ## Quick start (async)
34
+ ## Quick start (with custom resolvers)
35
35
 
36
36
  ```ts
37
37
  import { resolve, processEnv } from 'node-env-resolver';
38
+ import { dotenv } from 'node-env-resolver/resolvers';
38
39
 
39
- const config = await resolve.with([processEnv(), {
40
- PORT: 3000,
41
- NODE_ENV: ['development', 'production', 'test'] as const,
42
- DEBUG: false,
43
- API_KEY: 'string?'
44
- }]);
40
+ // Synchronous with custom resolver (array syntax)
41
+ const config = resolve([
42
+ dotenv(), // Resolver must support loadSync()
43
+ {
44
+ PORT: 3000,
45
+ NODE_ENV: ['development', 'production', 'test'] as const,
46
+ DEBUG: false,
47
+ API_KEY: 'string?'
48
+ }
49
+ ]);
45
50
 
46
- // config is fully typed
47
- config.PORT; // number
48
- config.NODE_ENV; // 'development' | 'production' | 'test'
49
- config.DEBUG; // boolean
50
- config.API_KEY; // string | undefined
51
+ // Asynchronous with any resolvers (both sync and async work!)
52
+ const config = await resolve.async([
53
+ dotenv(), {
54
+ PORT: 3000,
55
+ NODE_ENV: ['development', 'production', 'test'] as const,
56
+ DEBUG: false,
57
+ API_KEY: 'string?'
58
+ }],
59
+ [awsSecrets(), { DATABASE_URL: 'url' }]);
51
60
  ```
52
61
 
53
62
  ## Table of Contents
54
63
 
55
64
  - [Install](#install)
56
65
  - [Quick start](#quick-start-uses-processenv)
66
+ - [Quick start (with custom resolvers)](#quick-start-with-custom-resolvers)
57
67
  - [Basic usage](#basic-usage)
58
68
  - [Required values](#required-values)
59
69
  - [Default values](#default-values)
60
70
  - [Optional values](#optional-values)
61
71
  - [Enums](#enums)
72
+ - [Variable Naming Conventions](#variable-naming-conventions)
62
73
  - [Performance & Bundle Size](#performance--bundle-size)
63
74
  - [Built-in validators](#built-in-validators)
64
75
  - [Custom validators](#custom-validators)
@@ -126,9 +137,49 @@ config.NODE_ENV; // 'development' | 'production' | 'test'
126
137
  config.LOG_LEVEL; // 'debug' | 'info' | 'warn' | 'error'
127
138
  ```
128
139
 
140
+ ## Variable Naming Conventions
141
+
142
+ The library validates environment variable names to prevent shell errors and ensure cross-platform compatibility.
143
+
144
+ ### Supported Name Formats
145
+
146
+ Variable names can use:
147
+ - **Letters** (both uppercase and lowercase): `A-Z`, `a-z`
148
+ - **Numbers** (not as first character): `0-9`
149
+ - **Underscores**: `_`
150
+
151
+ ### Valid Examples
152
+
153
+ ```ts
154
+ const config = resolve({
155
+ PORT: 3000, // ✅ SCREAMING_SNAKE_CASE (traditional)
156
+ port: 3000, // ✅ lowercase
157
+ myApiKey: 'string', // ✅ camelCase
158
+ my_api_key: 'string', // ✅ snake_case
159
+ API_KEY_V2: 'string', // ✅ with numbers (not first char)
160
+ _PRIVATE: 'string' // ✅ starting with underscore
161
+ });
162
+ ```
163
+
164
+ ### Invalid Examples
165
+
166
+ ```ts
167
+ const config = resolve({
168
+ '123PORT': 3000, // ❌ Starts with number
169
+ 'API-KEY': 'string', // ❌ Contains hyphen
170
+ 'API.KEY': 'string', // ❌ Contains dot
171
+ 'API KEY': 'string', // ❌ Contains space
172
+ 'API@KEY': 'string' // ❌ Special characters
173
+ });
174
+ ```
175
+
176
+ **Recommendation:** While all formats are supported, **SCREAMING_SNAKE_CASE** (e.g., `DATABASE_URL`, `API_KEY`) is the most common convention for environment variables and ensures maximum compatibility with legacy systems.
177
+
178
+ **Validation pattern:** `/^[A-Za-z_][A-Za-z0-9_]*$/`
179
+
129
180
  ## Performance & Bundle Size
130
181
 
131
- **Lightweight with powerful features.** The core library is **~3.6KB gzipped** with comprehensive validation and resolver capabilities - **38% smaller** than previous versions while maintaining all features.
182
+ **Lightweight** The core library is **~3.6KB gzipped** with validation and resolver capabilities.
132
183
 
133
184
  ### Efficient validation architecture
134
185
 
@@ -157,7 +208,7 @@ const config = resolve({
157
208
  });
158
209
 
159
210
  // Also works with async resolvers
160
- const config = await resolve.with([
211
+ const config = await resolve.async([
161
212
  awsSecrets(),
162
213
  { DATABASE_URL: 'postgres', API_URL: 'url' }
163
214
  ]);
@@ -286,7 +337,7 @@ process.env.TIMEOUT = '30s';
286
337
  process.env.CACHE_TTL = '5m';
287
338
  process.env.SESSION_DURATION = '24h';
288
339
 
289
- const config = await resolve.with([processEnv(), {
340
+ const config = await resolve.async([processEnv(), {
290
341
  TIMEOUT: 'duration', // 30000 (milliseconds)
291
342
  CACHE_TTL: 'duration', // 300000
292
343
  SESSION_DURATION: 'duration' // 86400000
@@ -295,18 +346,18 @@ const config = await resolve.with([processEnv(), {
295
346
  // File reading (useful for Docker/Kubernetes secrets)
296
347
  // Method 1: Explicit path in env var
297
348
  process.env.DB_PASSWORD_FILE = '/run/secrets/db_password';
298
- const config = await resolve.with([processEnv(), {
349
+ const config = await resolve.async([processEnv(), {
299
350
  DB_PASSWORD_FILE: 'file' // 'my-secret-password' (file content, trimmed)
300
351
  }]);
301
352
 
302
353
  // Method 2: Using secretsDir (cleaner for Docker/K8s)
303
354
  // Reads from /run/secrets/db_password automatically (key name lowercased)
304
- const config = await resolve.with([processEnv(), {
355
+ const config = await resolve.async([processEnv(), {
305
356
  DB_PASSWORD: 'file' // Reads /run/secrets/db_password
306
357
  }], { secretsDir: '/run/secrets' });
307
358
 
308
359
  // Per-field secretsDir (overrides global)
309
- const config = await resolve.with([processEnv(), {
360
+ const config = await resolve.async([processEnv(), {
310
361
  DB_PASSWORD: { type: 'file', secretsDir: '/custom/secrets' },
311
362
  API_KEY: 'file' // Uses global secretsDir
312
363
  }], { secretsDir: '/run/secrets' });
@@ -376,9 +427,10 @@ Load configuration from multiple sources. By default, later sources override ear
376
427
 
377
428
  ```ts
378
429
  import { resolve, processEnv } from 'node-env-resolver';
379
- import { dotenv } from 'node-env-resolver/resolvers';
430
+ import { dotenv, json } from 'node-env-resolver/resolvers';
380
431
 
381
- const config = await resolve.with(
432
+ // Async mode - supports both sync and async resolvers
433
+ const config = await resolve.async(
382
434
  [processEnv(), {
383
435
  PORT: 3000,
384
436
  NODE_ENV: ['development', 'production'] as const,
@@ -388,27 +440,42 @@ const config = await resolve.with(
388
440
  API_KEY: 'string',
389
441
  }]
390
442
  );
443
+
444
+ // Sync mode - supports multiple SYNC resolvers (NEW!)
445
+ const config = resolve(
446
+ [dotenv(), { PORT: 3000 }],
447
+ [json('config.json'), { DATABASE_URL: 'postgres' }]
448
+ // Both resolvers must have loadSync() method
449
+ );
391
450
  ```
392
451
 
393
452
  ### Controlling merge behaviour
394
453
 
395
- Use `priority` to control how resolvers merge values:
454
+ Use `priority` to control how resolvers merge values (works with both sync and async modes):
396
455
 
397
456
  ```ts
398
457
  // priority: 'last' (default) - later resolvers override earlier ones
399
- const config = await resolve.with(
458
+ const config = await resolve.async(
400
459
  [processEnv(), { DATABASE_URL: 'postgres' }],
401
460
  [awsSecrets(), { DATABASE_URL: 'postgres' }]
402
461
  // AWS wins
403
462
  );
404
463
 
405
464
  // priority: 'first' - earlier resolvers take precedence
406
- const config = await resolve.with(
465
+ const config = await resolve.async(
407
466
  [dotenv(), { DATABASE_URL: 'postgres' }],
408
467
  [awsSecrets(), { DATABASE_URL: 'postgres' }],
409
468
  { priority: 'first' }
410
469
  // dotenv wins
411
470
  );
471
+
472
+ // Also works with sync resolve() (NEW!)
473
+ const config = resolve(
474
+ [dotenv(), { DATABASE_URL: 'postgres' }],
475
+ [json('config.json'), { DATABASE_URL: 'postgres' }],
476
+ { priority: 'first' }
477
+ // dotenv wins
478
+ );
412
479
  ```
413
480
 
414
481
  This is useful for development workflows where local overrides should take precedence over cloud secrets.
@@ -422,7 +489,7 @@ The library includes two automatic performance optimizations:
422
489
  When using `priority: 'first'`, resolvers are called sequentially, but execution **stops early** once all required environment variables are satisfied:
423
490
 
424
491
  ```ts
425
- const config = await resolve.with(
492
+ const config = await resolve.async(
426
493
  [dotenv(), { DATABASE_URL: 'postgres', API_KEY: 'string', PORT: 3000 }],
427
494
  [awsSecrets(), { DATABASE_URL: 'postgres', API_KEY: 'string', PORT: 3000 }],
428
495
  [gcpSecrets(), { DATABASE_URL: 'postgres', API_KEY: 'string', PORT: 3000 }],
@@ -447,7 +514,7 @@ This is particularly valuable in development where:
447
514
  When using `priority: 'last'` (the default), all resolvers are called **in parallel** for maximum performance:
448
515
 
449
516
  ```ts
450
- const config = await resolve.with(
517
+ const config = await resolve.async(
451
518
  [awsSecrets(), { DATABASE_URL: 'postgres' }], // 100ms
452
519
  [awsParameterStore(), { API_KEY: 'string' }], // 100ms
453
520
  [gcpSecrets(), { JWT_SECRET: 'string' }] // 100ms
@@ -489,7 +556,7 @@ if (result.success) {
489
556
  All functions have safe variants:
490
557
 
491
558
  - `resolve()` → `safeResolve()` (both synchronous)
492
- - `resolve.with()` → `safeResolve.with()` (both async)
559
+ - `resolve.async()` → `safeResolve.async()` (both async)
493
560
 
494
561
  ## Synchronous resolution
495
562
 
@@ -509,11 +576,11 @@ const config = resolve({
509
576
  });
510
577
  ```
511
578
 
512
- `resolve.with()` is **async** when using custom resolvers:
579
+ `resolve.async()` is **async** when using custom resolvers:
513
580
 
514
581
  ```ts
515
582
  // Async - await required when using custom resolvers
516
- const config = await resolve.with(
583
+ const config = await resolve.async(
517
584
  [processEnv(), { PORT: 3000 }],
518
585
  [dotenv(), { DATABASE_URL: 'postgres', API_URL: 'url' }]
519
586
  );
@@ -531,7 +598,7 @@ import { cliArgs } from 'node-env-resolver/cli';
531
598
 
532
599
  // $ node app.js --port 8080 --database-url postgres://localhost --verbose
533
600
 
534
- const config = await resolve.with(
601
+ const config = await resolve.async(
535
602
  [processEnv(), {
536
603
  PORT: 3000,
537
604
  DATABASE_URL: 'postgres',
@@ -738,7 +805,7 @@ const databaseResolver: Resolver = {
738
805
  }
739
806
  };
740
807
 
741
- const config = await resolve.with(
808
+ const config = await resolve.async(
742
809
  [processEnv(), { PORT: 3000 }],
743
810
  [databaseResolver, { API_KEY: 'string' }]
744
811
  );
@@ -771,7 +838,7 @@ Multiple sources:
771
838
  import { resolve } from 'node-env-resolver';
772
839
  import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
773
840
 
774
- const config = await resolve.with(
841
+ const config = await resolve.async(
775
842
  [processEnv(), { PORT: 3000 }],
776
843
  [awsSecrets({ secretId: 'app/secrets' }), { DATABASE_URL: 'postgres' }],
777
844
  [awsSsm({ path: '/app/config' }), { API_KEY: 'string' }]
@@ -790,7 +857,7 @@ import { cached, TTL } from 'node-env-resolver/utils';
790
857
  import { awsSecrets } from 'node-env-resolver-aws';
791
858
 
792
859
  export const getConfig = async () => {
793
- return await resolve.with(
860
+ return await resolve.async(
794
861
  [cached(
795
862
  awsSecrets({ secretId: 'app/secrets' }),
796
863
  { ttl: TTL.minutes5 }
@@ -823,8 +890,8 @@ Performance:
823
890
  |----------|-----------|----------|
824
891
  | `resolve()` | Sync, throws on error | Most applications (reading from process.env) |
825
892
  | `safeResolve()` | Sync, returns result object | Graceful error handling |
826
- | `resolve.with()` | Async, throws on error | Multiple sources (dotenv, AWS, etc.) |
827
- | `safeResolve.with()` | Async, returns result object | Multiple sources with error handling |
893
+ | `resolve.async()` | Async, throws on error | Multiple sources (dotenv, AWS, etc.) |
894
+ | `safeResolve.async()` | Async, returns result object | Multiple sources with error handling |
828
895
 
829
896
  ### Shorthand syntax
830
897
 
@@ -865,8 +932,8 @@ const config = resolve(schema, {
865
932
  enableAudit: true
866
933
  });
867
934
 
868
- // Multiple sources - options as last parameter to resolve.with()
869
- const config = await resolve.with(
935
+ // Multiple sources - options as last parameter to resolve.async()
936
+ const config = await resolve.async(
870
937
  [resolver1, schema],
871
938
  [resolver2, schema],
872
939
  {
@@ -879,7 +946,7 @@ const config = await resolve.with(
879
946
  );
880
947
  ```
881
948
 
882
- **Note:** The `resolvers` option has been removed. For single source resolution, use `resolve()` directly (defaults to `process.env`). For multiple sources, use `resolve.with()` syntax.
949
+ **Note:** The `resolvers` option has been removed. For single source resolution, use `resolve()` directly (defaults to `process.env`). For multiple sources, use `resolve.async()` syntax.
883
950
 
884
951
  ### `interpolate`
885
952
 
@@ -889,7 +956,7 @@ const config = await resolve.with(
889
956
 
890
957
  **Why:** Keeps configuration DRY and maintainable.
891
958
 
892
- **Default:** `true` in `resolve.with()`, `false` in `resolve()`
959
+ **Default:** `true` in `resolve.async()`, `false` in `resolve()`
893
960
 
894
961
  ```ts
895
962
  // With interpolation
@@ -931,14 +998,14 @@ const flakyResolver = {
931
998
  };
932
999
 
933
1000
  // ❌ Throws immediately
934
- await resolve.with(
1001
+ await resolve.async(
935
1002
  [flakyResolver, schema],
936
1003
  [processEnv(), schema],
937
1004
  { strict: true } // default
938
1005
  );
939
1006
 
940
1007
  // ✅ Continues with processEnv()
941
- await resolve.with(
1008
+ await resolve.async(
942
1009
  [flakyResolver, schema],
943
1010
  [processEnv(), schema],
944
1011
  { strict: false } // graceful degradation
@@ -962,14 +1029,14 @@ await resolve.with(
962
1029
 
963
1030
  ```ts
964
1031
  // Production: AWS secrets override process.env
965
- await resolve.with(
1032
+ await resolve.async(
966
1033
  [processEnv(), { DATABASE_URL: 'postgres' }],
967
1034
  [awsSecrets(), { DATABASE_URL: 'postgres' }]
968
1035
  // priority: 'last' (default) - AWS wins
969
1036
  );
970
1037
 
971
1038
  // Development: Local .env overrides cloud
972
- await resolve.with(
1039
+ await resolve.async(
973
1040
  [dotenv(), { DATABASE_URL: 'postgres' }],
974
1041
  [awsSecrets(), { DATABASE_URL: 'postgres' }],
975
1042
  { priority: 'first' } // dotenv wins
@@ -989,7 +1056,7 @@ await resolve.with(
989
1056
  **Default:** `undefined` (no policies enforced)
990
1057
 
991
1058
  ```ts
992
- await resolve.with(
1059
+ await resolve.async(
993
1060
  [processEnv(), schema],
994
1061
  [awsSecrets(), schema],
995
1062
  {
@@ -1024,7 +1091,7 @@ await resolve.with(
1024
1091
  **Default:** `false` (disabled in development), automatically `true` in production (`NODE_ENV === 'production'`)
1025
1092
 
1026
1093
  ```ts
1027
- await resolve.with(
1094
+ await resolve.async(
1028
1095
  [processEnv(), schema],
1029
1096
  [awsSecrets(), schema],
1030
1097
  { enableAudit: true } // Explicitly enable in development
@@ -1043,7 +1110,7 @@ const logs = getAuditLog();
1043
1110
 
1044
1111
  ```ts
1045
1112
  interface ResolveOptions {
1046
- interpolate?: boolean; // Variable interpolation (default: true in .with())
1113
+ interpolate?: boolean; // Variable interpolation (default: true in .async())
1047
1114
  strict?: boolean; // Fail-fast behaviour (default: true)
1048
1115
  priority?: 'first' | 'last'; // Merge strategy (default: 'last')
1049
1116
  policies?: PolicyOptions; // Security policies (default: undefined)
@@ -1100,7 +1167,7 @@ import { cached, TTL } from 'node-env-resolver/utils';
1100
1167
  import { awsSecrets } from 'node-env-resolver-aws';
1101
1168
 
1102
1169
  const getConfig = async () => {
1103
- return await resolve.with(
1170
+ return await resolve.async(
1104
1171
  [cached(
1105
1172
  awsSecrets({ secretId: 'lambda/config' }),
1106
1173
  { ttl: TTL.minutes5 }
@@ -1128,7 +1195,7 @@ By default, `.env` files are **completely blocked in production** for security.
1128
1195
 
1129
1196
  ```ts
1130
1197
  // In production (NODE_ENV=production)
1131
- const config = await resolve.with(
1198
+ const config = await resolve.async(
1132
1199
  [dotenv(), {
1133
1200
  DATABASE_URL: 'postgres',
1134
1201
  }]
@@ -1139,7 +1206,7 @@ const config = await resolve.with(
1139
1206
  **Allow all .env variables (NOT recommended):**
1140
1207
 
1141
1208
  ```ts
1142
- const config = await resolve.with(
1209
+ const config = await resolve.async(
1143
1210
  [dotenv(), {
1144
1211
  DATABASE_URL: 'postgres',
1145
1212
  }],
@@ -1154,7 +1221,7 @@ const config = await resolve.with(
1154
1221
  **Allow specific variables only (recommended if needed):**
1155
1222
 
1156
1223
  ```ts
1157
- const config = await resolve.with(
1224
+ const config = await resolve.async(
1158
1225
  [dotenv(), {
1159
1226
  PORT: 3000,
1160
1227
  DATABASE_URL: 'postgres',
@@ -1176,7 +1243,7 @@ Restrict sensitive variables to specific resolvers (e.g., force secrets to come
1176
1243
  import { resolve, processEnv } from 'node-env-resolver';
1177
1244
  import { awsSecrets } from 'node-env-resolver-aws';
1178
1245
 
1179
- const config = await resolve.with(
1246
+ const config = await resolve.async(
1180
1247
  [processEnv(), {
1181
1248
  PORT: 3000,
1182
1249
  }],
@@ -1203,7 +1270,7 @@ import { resolve, processEnv } from 'node-env-resolver';
1203
1270
  import { cached, TTL } from 'node-env-resolver/utils';
1204
1271
  import { awsSecrets } from 'node-env-resolver-aws';
1205
1272
 
1206
- const config = await resolve.with(
1273
+ const config = await resolve.async(
1207
1274
  [processEnv(), {}],
1208
1275
  [cached(awsSecrets({ secretId: 'prod/db' }), { ttl: TTL.minutes5 }), {
1209
1276
  DATABASE_PASSWORD: 'string',
@@ -1269,7 +1336,7 @@ const config = resolve({
1269
1336
  console.log(getAuditLog());
1270
1337
  // [
1271
1338
  // { type: 'env_loaded', key: 'DATABASE_URL', source: 'process.env', timestamp: ... },
1272
- // { type: 'env_loaded', key: 'API_KEY', source: 'aws-secrets', timestamp: ... },
1339
+ // { type: 'env_loaded', key: 'API_KEY', source: 'process.env', timestamp: ... },
1273
1340
  // { type: 'validation_success', metadata: { variableCount: 2 }, timestamp: ... }
1274
1341
  // ]
1275
1342
 
@@ -1289,6 +1356,51 @@ const config = resolve({
1289
1356
  console.log(getAuditLog());
1290
1357
  ```
1291
1358
 
1359
+ ### Per-Config Audit Tracking
1360
+
1361
+ When you have multiple `resolve()` calls, you can now get audit logs **specific to each config object**:
1362
+
1363
+ ```ts
1364
+ import { resolve, getAuditLog } from 'node-env-resolver';
1365
+
1366
+ const appConfig = resolve({
1367
+ PORT: 3000,
1368
+ API_KEY: 'string'
1369
+ }, { enableAudit: true });
1370
+
1371
+ const dbConfig = resolve({
1372
+ DATABASE_URL: 'postgres',
1373
+ DB_POOL_SIZE: 10
1374
+ }, { enableAudit: true });
1375
+
1376
+ // Get audit logs for specific config (NEW!)
1377
+ const appAudit = getAuditLog(appConfig); // Only PORT and API_KEY events
1378
+ const dbAudit = getAuditLog(dbConfig); // Only DATABASE_URL and DB_POOL_SIZE events
1379
+
1380
+ // Still works: get ALL audit events (backward compatible)
1381
+ const allAudit = getAuditLog(); // All events from both configs
1382
+
1383
+ console.log('App config audit:', appAudit);
1384
+ // [
1385
+ // { type: 'env_loaded', key: 'PORT', source: 'process.env', ... },
1386
+ // { type: 'env_loaded', key: 'API_KEY', source: 'process.env', ... },
1387
+ // { type: 'validation_success', ... }
1388
+ // ]
1389
+
1390
+ console.log('DB config audit:', dbAudit);
1391
+ // [
1392
+ // { type: 'env_loaded', key: 'DATABASE_URL', source: 'process.env', ... },
1393
+ // { type: 'env_loaded', key: 'DB_POOL_SIZE', source: 'process.env', ... },
1394
+ // { type: 'validation_success', ... }
1395
+ // ]
1396
+ ```
1397
+
1398
+ **Use cases:**
1399
+ - Multi-tenant applications with separate configs per tenant
1400
+ - Microservices with different config sources
1401
+ - Testing/debugging specific configuration loads
1402
+ - Isolating audit trails in complex applications
1403
+
1292
1404
  ### Audit Event Types
1293
1405
 
1294
1406
  | Event Type | When It Occurs |
@@ -1308,7 +1420,7 @@ import { resolve, getAuditLog } from 'node-env-resolver';
1308
1420
  import { cached } from 'node-env-resolver/utils';
1309
1421
  import { awsSecrets } from 'node-env-resolver-aws';
1310
1422
 
1311
- const config = await resolve.with(
1423
+ const config = await resolve.async(
1312
1424
  [cached(awsSecrets({ secretId: 'prod/db' }), { ttl: 300000 }), {
1313
1425
  DATABASE_URL: 'postgres',
1314
1426
  }],
@@ -1336,7 +1448,7 @@ import { resolve, processEnv, getAuditLog } from 'node-env-resolver';
1336
1448
  import { awsSecrets } from 'node-env-resolver-aws';
1337
1449
 
1338
1450
  // In production
1339
- const config = await resolve.with(
1451
+ const config = await resolve.async(
1340
1452
  [processEnv(), {}],
1341
1453
  [awsSecrets(), {
1342
1454
  DATABASE_PASSWORD: 'string',
package/dist/audit.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs');require('./chunk-KIQXH265.cjs');chunk4ZOF2PI4_cjs.f();Object.defineProperty(exports,"attachAuditSession",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.a}});Object.defineProperty(exports,"clearAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.d}});Object.defineProperty(exports,"getAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.c}});Object.defineProperty(exports,"logAuditEvent",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.b}});
package/dist/audit.d.ts CHANGED
@@ -9,8 +9,20 @@ export interface AuditEvent {
9
9
  source?: string;
10
10
  error?: string;
11
11
  metadata?: Record<string, unknown>;
12
+ sessionId?: string;
12
13
  }
14
+ /**
15
+ * Attach an audit session ID to a config object
16
+ * Returns the session ID for use in audit events
17
+ */
18
+ export declare function attachAuditSession(config: object): string;
13
19
  export declare function logAuditEvent(event: AuditEvent): void;
14
- export declare function getAuditLog(): readonly AuditEvent[];
20
+ /**
21
+ * Get audit log, optionally filtered by config object
22
+ *
23
+ * @param config - Optional config object to filter audit events for
24
+ * @returns Audit events (all events if no config provided, or filtered by config's session)
25
+ */
26
+ export declare function getAuditLog(config?: object): readonly AuditEvent[];
15
27
  export declare function clearAuditLog(): void;
16
28
  //# sourceMappingURL=audit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GACtB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,YAAY,GACZ,gBAAgB,GAChB,gBAAgB,CAAC;AAErB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAKD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAMrD;AAED,wBAAgB,WAAW,IAAI,SAAS,UAAU,EAAE,CAEnD;AAED,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GACtB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,YAAY,GACZ,gBAAgB,GAChB,gBAAgB,CAAC;AAErB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AASD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAMrD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,CAelE;AAED,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
package/dist/audit.js CHANGED
@@ -1 +1 @@
1
- export{c as clearAuditLog,b as getAuditLog,a as logAuditEvent}from'./chunk-DAGPFV3V.js';import'./chunk-476ZUILE.js';
1
+ import {f}from'./chunk-YOHHFBZN.js';export{a as attachAuditSession,d as clearAuditLog,c as getAuditLog,b as logAuditEvent}from'./chunk-YOHHFBZN.js';import'./chunk-5PELJRUQ.js';f();
@@ -0,0 +1 @@
1
+ 'use strict';var chunkULL4WKTV_cjs=require('./chunk-ULL4WKTV.cjs');require('./chunk-XPGSWVRT.cjs'),require('./chunk-4ZOF2PI4.cjs');var chunkFCFDGYTF_cjs=require('./chunk-FCFDGYTF.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=chunkULL4WKTV_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkULL4WKTV_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 chunkULL4WKTV_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(chunkFCFDGYTF_cjs.a({expand:true})),s.push(chunkFCFDGYTF_cjs.b()),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=chunkULL4WKTV_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkULL4WKTV_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 chunkULL4WKTV_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(chunkFCFDGYTF_cjs.a({expand:true})),s.push(chunkFCFDGYTF_cjs.b()),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,c}from'./chunk-MGTYH57K.js';import'./chunk-VJZZNSRI.js';import {a as a$1,b as b$1}from'./chunk-QWDK3BUB.js';import'./chunk-476ZUILE.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(b$1()),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(b$1()),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,c}from'./chunk-J7ZHEMRP.js';import'./chunk-NKPXKLF7.js';import'./chunk-YOHHFBZN.js';import {a as a$1,b as b$1}from'./chunk-IU5TG3HL.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(b$1()),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(b$1()),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 @@
1
+ 'use strict';var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs');var g={};chunkKIQXH265_cjs.c(g,{attachAuditSession:()=>d,clearAuditLog:()=>c,getAuditLog:()=>a,logAuditEvent:()=>u});function d(t){let n=Date.now().toString(36)+Math.random().toString(36).substring(2,9);return o.set(t,n),n}function u(t){e.push(t),e.length>1e3&&e.shift();}function a(t){if(!t)return [...e];let n=o.get(t);return n?e.filter(i=>i.sessionId===n):[]}function c(){e.length=0;}var e,o,p=chunkKIQXH265_cjs.b(()=>{e=[],o=new WeakMap;});exports.a=d;exports.b=u;exports.c=a;exports.d=c;exports.e=g;exports.f=p;
@@ -0,0 +1 @@
1
+ function n(e){return typeof e.loadSync=="function"}function t(e){return !e.loadSync}export{n as a,t as b};
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var k=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var l=(a,b)=>()=>(a&&(b=a(a=0)),b);var m=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:true});},j=(a,b,c,f)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of h(b))!i.call(a,d)&&d!==c&&e(a,d,{get:()=>b[d],enumerable:!(f=g(b,d))||f.enumerable});return a};var n=a=>j(e({},"__esModule",{value:true}),a);export{k as a,l as b,m as c,n as d};
@@ -0,0 +1,15 @@
1
+ 'use strict';var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs'),fs=require('fs'),path=require('path');var h=l=>{let a={},e=l.split(`
2
+ `);for(let t=0;t<e.length;t++){let i=e[t]?.trim()??"";if(!i||i[0]==="#")continue;let o=i.indexOf("=");if(o<=0)continue;let n=i.slice(0,o).trim();if(!/^[A-Z_][A-Z0-9_]*$/i.test(n))continue;let r=i.slice(o+1).trim();if(r.length>=2){let s=r[0];(s==='"'||s==="'")&&r[r.length-1]===s&&(r=r.slice(1,-1),s==='"'&&(r=r.replace(/\\n/g,`
3
+ `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function E(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o}}}function O(){return {name:"process.env",async load(){return {...process.env}},loadSync(){return {...process.env}}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a,statSync:e}=chunkKIQXH265_cjs.a("fs"),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}}}}function U(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a.path})`,async load(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
4
+ npm install js-yaml
5
+ # or
6
+ pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=chunkKIQXH265_cjs.a("js-yaml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
7
+ npm install js-yaml
8
+ # or
9
+ pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}function C(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.toml"};return {name:`toml(${a.path})`,async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=await import('smol-toml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
10
+ npm install smol-toml
11
+ # or
12
+ pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=chunkKIQXH265_cjs.a("smol-toml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
13
+ npm install smol-toml
14
+ # or
15
+ pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}exports.a=E;exports.b=O;exports.c=S;exports.d=k;exports.e=R;exports.f=_;exports.g=U;exports.h=C;
@@ -0,0 +1,9 @@
1
+ import {a,c,b}from'./chunk-J7ZHEMRP.js';import {f}from'./chunk-YOHHFBZN.js';f();function T(){return {name:"process.env",async load(){return {...process.env}},loadSync(){return {...process.env}}}}function m(){return [T()]}function S(a$1,...l){let i=[a$1,...l],r,t,n;if(!Array.isArray(a$1))r=a$1,t=m(),n=l[0];else {let o=[];for(let s of i)Array.isArray(s)&&s.length===2&&typeof s[0]=="object"&&"load"in s[0]?o.push(s):typeof s=="object"&&!Array.isArray(s)&&(n=s);if(o.length===0)throw new Error("resolve() requires at least one [resolver, schema] tuple when using array syntax");r={};for(let[,s]of o)Object.assign(r,s);t=o.map(([s])=>s);}for(let[o,s]of Object.entries(r))if(s&&typeof s=="object"&&"~standard"in s)throw new Error(`\u274C resolve() cannot be used with async validators.
2
+ Variable '${o}' uses a Standard Schema validator (Zod, Valibot, etc.)
3
+ \u{1F4A1} Use resolve.async() instead, or use shorthand syntax for sync validation.`);for(let o of t)if(!o.loadSync)throw new Error(`\u274C Resolver '${o.name}' does not support synchronous loading.
4
+ All resolvers passed to resolve() must have a loadSync() method.
5
+ \u{1F4A1} Use resolve.async() for async resolvers, or use a sync-compatible resolver.`);let c$1=(process.env.NODE_ENV||"").toLowerCase()==="production",p=n?.policies??{},v={interpolate:true,strict:true,enableAudit:c$1,policies:p,...n},u=a(r);return c(u,t,v)}async function O(a$1,...l){let i=[a$1,...l],r=[],t;for(let s of i)Array.isArray(s)&&s.length===2&&typeof s[0]=="object"&&"load"in s[0]?r.push(s):typeof s=="object"&&!Array.isArray(s)&&(t=s);if(r.length===0)throw new Error("resolve.async() requires at least one [resolver, schema] tuple");let n={};for(let[,s]of r)Object.assign(n,s);let c=r.map(([s])=>s),p=(process.env.NODE_ENV||"").toLowerCase()==="production",v=t?.policies??{},u={interpolate:true,strict:true,enableAudit:p,policies:v,...t},e=a(n);return await b(e,c,u)}S.async=O;function R(a$1,...l){let i=[a$1,...l],r,t,n;if(!Array.isArray(a$1))r=a$1,t=m(),n=l[0];else {let e=[];for(let o of i)Array.isArray(o)&&o.length===2&&typeof o[0]=="object"&&"load"in o[0]?e.push(o):typeof o=="object"&&!Array.isArray(o)&&(n=o);if(e.length===0)return {success:false,error:"safeResolve() requires at least one [resolver, schema] tuple when using array syntax"};r={};for(let[,o]of e)Object.assign(r,o);t=e.map(([o])=>o);}for(let[e,o]of Object.entries(r))if(o&&typeof o=="object"&&"~standard"in o)return {success:false,error:`\u274C safeResolve() cannot be used with async validators.
6
+ Variable '${e}' uses a Standard Schema validator (Zod, Valibot, etc.)
7
+ \u{1F4A1} Use safeResolve.async() instead, or use shorthand syntax for sync validation.`};for(let e of t)if(!e.loadSync)return {success:false,error:`\u274C Resolver '${e.name}' does not support synchronous loading.
8
+ All resolvers passed to safeResolve() must have a loadSync() method.
9
+ \u{1F4A1} Use safeResolve.async() for async resolvers.`};let c$1=(process.env.NODE_ENV||"").toLowerCase()==="production",p=n?.policies??{},v={interpolate:true,strict:true,enableAudit:c$1,policies:p,...n},u=a(r);try{return {success:!0,data:c(u,t,v)}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e)}}}async function A(a$1,...l){let i=[a$1,...l],r=[],t;for(let e of i)Array.isArray(e)&&e.length===2&&typeof e[0]=="object"&&"load"in e[0]?r.push(e):typeof e=="object"&&!Array.isArray(e)&&(t=e);if(r.length===0)return {success:false,error:"safeResolve.async() requires at least one [resolver, schema] tuple"};let n={};for(let[,e]of r)Object.assign(n,e);let c=r.map(([e])=>e),p=(process.env.NODE_ENV||"").toLowerCase()==="production",v=t?.policies??{},u={interpolate:true,strict:true,enableAudit:p,policies:v,...t};try{let e=a(n);return {success:!0,data:await b(e,c,u)}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e)}}}R.async=A;var x=S,I=R;export{T as a,x as b,I as c};