node-env-resolver 5.0.1 → 6.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.
- package/README.md +90 -57
- package/dist/audit.d.cts +23 -0
- package/dist/audit.d.ts +23 -0
- package/dist/builder.cjs +1 -1
- package/dist/builder.js +1 -1
- package/dist/chunk-LCW5BDAW.js +15 -0
- package/dist/chunk-PNUGGPRS.cjs +15 -0
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +44 -266
- package/dist/resolvers.d.ts +44 -266
- package/dist/resolvers.js +1 -1
- package/dist/utils.d.cts +60 -0
- package/dist/utils.d.ts +60 -0
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.js +1 -1
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.cts +771 -17
- package/dist/validators.d.ts +771 -17
- package/dist/validators.js +2 -2
- package/dist/web.cjs +2 -2
- package/dist/web.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-TAX63ALN.js +0 -16
- package/dist/chunk-XPL5XLTA.cjs +0 -16
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/
|
|
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
|
-
//
|
|
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
|
|
39
|
-
import {
|
|
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
|
-
- [
|
|
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/
|
|
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/
|
|
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
|
-
###
|
|
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/
|
|
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/
|
|
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
|
|
218
|
-
import { dotenv, json
|
|
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/
|
|
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
|
|
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 {
|
|
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 {
|
|
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 =
|
|
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`, `
|
|
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
|
|
393
|
-
import { dotenv, json
|
|
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
|
|
436
|
-
import { dotenv, json
|
|
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
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
592
|
-
import {
|
|
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
|
|
611
|
-
import {
|
|
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,
|
|
816
|
-
import {
|
|
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/
|
|
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
|
|
860
|
-
import {
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
1101
|
-
import {
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1345
|
-
import {
|
|
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
|
|
1374
|
-
import {
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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,
|
|
1562
|
-
import {
|
|
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
|
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
|
|
1
|
+
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.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(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=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(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-
|
|
1
|
+
import {a as a$1}from'./chunk-LCW5BDAW.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};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {a}from'./chunk-5PELJRUQ.js';import {existsSync,readFileSync}from'fs';import {resolve,join}from'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 O(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=resolve(process.cwd(),a.path);return existsSync(n)?h(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=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=resolve(process.cwd(),a.path);return existsSync(n)?h(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=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=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=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=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=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=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=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=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=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=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$1,statSync:e}=a("fs"),t=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a$1(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=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$1=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a$1.path})`,async load(){let e=join(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=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$1.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=join(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{load:t}=a("js-yaml"),i=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$1.path}: ${t instanceof Error?t.message:String(t)}`)}}}}function C(l){let a$1=typeof l=="string"?{path:l}:{path:l?.path??"config.toml"};return {name:`toml(${a$1.path})`,async load(){let e=resolve(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{parse:t}=await import('smol-toml'),i=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$1.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=resolve(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{parse:t}=a("smol-toml"),i=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$1.path}: ${t instanceof Error?t.message:String(t)}`)}}}}export{O as a,S as b,k as c,R as d,_ as e,U as f,C as g};
|
|
@@ -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 O(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 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=O;exports.b=S;exports.c=k;exports.d=R;exports.e=_;exports.f=U;exports.g=C;
|