envapt 4.0.2 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -76,6 +76,11 @@ interface ArrayConverter {
76
76
  * @public
77
77
  */
78
78
  type BaseInput = string | undefined;
79
+ /**
80
+ * Accepted shape for environment variable lookups. Either a single key or an ordered list of keys.
81
+ * @public
82
+ */
83
+ type EnvKeyInput = string | readonly [string, ...string[]];
79
84
  /**
80
85
  * Custom parser function type for environment variables
81
86
  * @param raw - Raw string value from environment
@@ -189,7 +194,7 @@ type InferPrimitiveFallbackType<TFallback extends string | number | boolean | bi
189
194
  /**
190
195
  * Usage 1: Custom converter function with fallback provided
191
196
  *
192
- * @param key - Environment variable name to load
197
+ * @param key - Environment variable name to load (string or ordered array of strings)
193
198
  * @param options - Configuration options with custom converter and required fallback
194
199
  * @public
195
200
  * @example
@@ -207,14 +212,14 @@ type InferPrimitiveFallbackType<TFallback extends string | number | boolean | bi
207
212
  * }
208
213
  * ```
209
214
  */
210
- declare function Envapt<TFallback>(key: string, options: {
215
+ declare function Envapt<TFallback>(key: EnvKeyInput, options: {
211
216
  converter: (raw: string | undefined, fallback: TFallback) => TFallback;
212
217
  fallback: TFallback;
213
218
  }): PropertyDecorator;
214
219
  /**
215
220
  * Usage 2: Custom converter function without fallback
216
221
  *
217
- * @param key - Environment variable name to load
222
+ * @param key - Environment variable name(s) to load
218
223
  * @param options - Configuration options with custom converter only
219
224
  * @public
220
225
  * @example
@@ -229,13 +234,13 @@ declare function Envapt<TFallback>(key: string, options: {
229
234
  * }
230
235
  * ```
231
236
  */
232
- declare function Envapt<TReturnType>(key: string, options: {
237
+ declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
233
238
  converter: ConverterFunction<TReturnType>;
234
239
  }): PropertyDecorator;
235
240
  /**
236
241
  * Usage 3: Built-in converter with optional fallback
237
242
  *
238
- * @param key - Environment variable name to load
243
+ * @param key - Environment variable name(s) to load
239
244
  * @param options - Configuration options with built-in converter
240
245
  * @public
241
246
  * @example
@@ -250,17 +255,21 @@ declare function Envapt<TReturnType>(key: string, options: {
250
255
  * // Use Url converter with a string fallback (must match converter type)
251
256
  * \@Envapt('APP_URL', { converter: Converters.Url, fallback: 'http://localhost:3000' })
252
257
  * static readonly url: URL;
258
+ *
259
+ * // Prefer CANARY_URL when present, otherwise fall back to APP_URL
260
+ * \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
261
+ * static readonly canaryUrl: URL | null;
253
262
  * }
254
263
  * ```
255
264
  */
256
- declare function Envapt<TConverter extends BuiltInConverter>(key: string, options: {
265
+ declare function Envapt<TConverter extends BuiltInConverter>(key: EnvKeyInput, options: {
257
266
  converter: TConverter;
258
267
  fallback?: InferConverterReturnType<TConverter> | undefined;
259
268
  }): PropertyDecorator;
260
269
  /**
261
270
  * Usage 4: Array converter with optional fallback
262
271
  *
263
- * @param key - Environment variable name to load
272
+ * @param key - Environment variable name(s) to load
264
273
  * @param options - Configuration options with array converter
265
274
  * @public
266
275
  * @example
@@ -284,14 +293,14 @@ declare function Envapt<TConverter extends BuiltInConverter>(key: string, option
284
293
  * }
285
294
  * ```
286
295
  */
287
- declare function Envapt<TConverter extends ArrayConverter>(key: string, options: {
296
+ declare function Envapt<TConverter extends ArrayConverter>(key: EnvKeyInput, options: {
288
297
  converter: TConverter;
289
298
  fallback?: InferConverterReturnType<TConverter> | undefined;
290
299
  }): PropertyDecorator;
291
300
  /**
292
301
  * Usage 5: Primitive constructor with optional fallback
293
302
  *
294
- * @param key - Environment variable name to load
303
+ * @param key - Environment variable name(s) to load
295
304
  * @param options - Configuration options with primitive constructor
296
305
  * @public
297
306
  * @example
@@ -306,14 +315,14 @@ declare function Envapt<TConverter extends ArrayConverter>(key: string, options:
306
315
  * }
307
316
  * ```
308
317
  */
309
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: string, options: {
318
+ declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
310
319
  converter: TConstructor;
311
320
  fallback?: InferPrimitiveReturnType<TConstructor>;
312
321
  }): PropertyDecorator;
313
322
  /**
314
323
  * Usage 6: Fallback only (no converter)
315
324
  *
316
- * @param key - Environment variable name to load
325
+ * @param key - Environment variable name(s) to load
317
326
  * @param options - Configuration options with fallback only
318
327
  * @public
319
328
  * @example
@@ -328,14 +337,14 @@ declare function Envapt<TConstructor extends PrimitiveConstructor>(key: string,
328
337
  * }
329
338
  * ```
330
339
  */
331
- declare function Envapt<TFallback>(key: string, options: {
340
+ declare function Envapt<TFallback>(key: EnvKeyInput, options: {
332
341
  fallback: TFallback;
333
342
  converter?: undefined;
334
343
  }): PropertyDecorator;
335
344
  /**
336
345
  * Classic API: No fallback
337
346
  *
338
- * @param key - Environment variable name to load
347
+ * @param key - Environment variable name(s) to load
339
348
  * @example
340
349
  * ```ts
341
350
  * // Classic API: no fallback — property will resolve from env or be null
@@ -345,11 +354,11 @@ declare function Envapt<TFallback>(key: string, options: {
345
354
  * }
346
355
  * ```
347
356
  */
348
- declare function Envapt<_TReturnType = string | null>(key: string): PropertyDecorator;
357
+ declare function Envapt<_TReturnType = string | null>(key: EnvKeyInput): PropertyDecorator;
349
358
  /**
350
359
  * Classic API: Primitive fallback only
351
360
  *
352
- * @param key - Environment variable name to load
361
+ * @param key - Environment variable name(s) to load
353
362
  * @param fallback - Default primitive value
354
363
  * @param converter - Optional primitive constructor (String, Number, etc.)
355
364
  * @public
@@ -367,14 +376,14 @@ declare function Envapt<_TReturnType = string | null>(key: string): PropertyDeco
367
376
  * }
368
377
  * ```
369
378
  */
370
- declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: string, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
379
+ declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: EnvKeyInput, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
371
380
 
372
381
  /**
373
382
  * @internal
374
383
  */
375
384
  interface EnvapterService {
376
- getRaw(key: string): string | undefined;
377
- get(key: string, def?: string): string | undefined;
385
+ getRaw(key: EnvKeyInput): string | undefined;
386
+ get(key: EnvKeyInput, def?: string): string | undefined;
378
387
  }
379
388
  /**
380
389
  * Parser class for handling environment variable template resolution and type conversion
@@ -389,7 +398,7 @@ declare class Parser {
389
398
  * @internal
390
399
  */
391
400
  resolveTemplate(key: string, value: string, stack?: Set<string>): string;
392
- convertValue<TFallback>(key: string, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
401
+ convertValue<TFallback>(key: EnvKeyInput, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
393
402
  private processFallbackForConverter;
394
403
  private convertPrimitiveToString;
395
404
  private processBuiltInConverter;
@@ -424,11 +433,15 @@ declare abstract class EnvapterBase {
424
433
  */
425
434
  static get dotenvConfig(): PermittedDotenvConfig;
426
435
  protected static refreshCache(): void;
436
+ protected static resolveKeyInput(keyInput: EnvKeyInput): {
437
+ key: string;
438
+ value: string | undefined;
439
+ };
427
440
  protected static get config(): Map<string, unknown>;
428
441
  /**
429
442
  * Get raw environment variable value without parsing or conversion.
430
443
  */
431
- getRaw(key: string): string | undefined;
444
+ getRaw(key: EnvKeyInput): string | undefined;
432
445
  }
433
446
 
434
447
  /**
@@ -500,49 +513,54 @@ declare class PrimitiveMethods extends EnvironmentMethods implements EnvapterSer
500
513
  private static _get;
501
514
  /**
502
515
  * Get a string environment variable with optional fallback.
503
- * Supports template variable resolution using $\{VAR\} syntax.
516
+ * Supports template variable resolution using `${VAR}` syntax.
517
+ * Accepts a single key or an ordered array of keys (first match wins).
504
518
  */
505
- static get<Default extends string | undefined = undefined>(key: string, def?: Default): ConditionalReturn<string, Default>;
519
+ static get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
506
520
  /**
507
521
  * @see {@link PrimitiveMethods.get}
508
522
  */
509
- get<Default extends string | undefined = undefined>(key: string, def?: Default): ConditionalReturn<string, Default>;
523
+ get(key: EnvKeyInput, def?: string): string | undefined;
510
524
  /**
511
525
  * Get a number environment variable with optional fallback.
512
526
  * Automatically converts string values to numbers.
527
+ * Accepts a single key or an ordered array of keys (first match wins).
513
528
  */
514
- static getNumber<Default extends number | undefined = undefined>(key: string, def?: Default): ConditionalReturn<number, Default>;
529
+ static getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
515
530
  /**
516
531
  * @see {@link PrimitiveMethods.getNumber}
517
532
  */
518
- getNumber<Default extends number | undefined = undefined>(key: string, def?: Default): ConditionalReturn<number, Default>;
533
+ getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
519
534
  /**
520
535
  * Get a boolean environment variable with optional fallback.
521
536
  * Recognizes: `1`, `yes`, `true`, 'on' as **true**; `0`, `no`, `false`, 'off' as **false** (case-insensitive).
537
+ * Accepts a single key or an ordered array of keys (first match wins).
522
538
  */
523
- static getBoolean<Default extends boolean | undefined = undefined>(key: string, def?: Default): ConditionalReturn<boolean, Default>;
539
+ static getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
524
540
  /**
525
541
  * @see {@link PrimitiveMethods.getBoolean}
526
542
  */
527
- getBoolean<Default extends boolean | undefined = undefined>(key: string, def?: Default): ConditionalReturn<boolean, Default>;
543
+ getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
528
544
  /**
529
545
  * Get a bigint environment variable with optional fallback.
530
546
  * Automatically converts string values to bigint.
547
+ * Accepts a single key or an ordered array of keys (first match wins).
531
548
  */
532
- static getBigInt<Default extends bigint | undefined = undefined>(key: string, def?: Default): ConditionalReturn<bigint, Default>;
549
+ static getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
533
550
  /**
534
551
  * @see {@link PrimitiveMethods.getBigInt}
535
552
  */
536
- getBigInt<Default extends bigint | undefined = undefined>(key: string, def?: Default): ConditionalReturn<bigint, Default>;
553
+ getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
537
554
  /**
538
555
  * Get a symbol environment variable with optional fallback.
539
556
  * Creates a symbol from the string value.
557
+ * Accepts a single key or an ordered array of keys (first match wins).
540
558
  */
541
- static getSymbol<Default extends symbol | undefined = undefined>(key: string, def?: Default): ConditionalReturn<symbol, Default>;
559
+ static getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
542
560
  /**
543
561
  * @see {@link PrimitiveMethods.getSymbol}
544
562
  */
545
- getSymbol<Default extends symbol | undefined = undefined>(key: string, def?: Default): ConditionalReturn<symbol, Default>;
563
+ getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
546
564
  }
547
565
 
548
566
  /**
@@ -553,22 +571,24 @@ declare class AdvancedMethods extends PrimitiveMethods {
553
571
  /**
554
572
  * Get an environment variable using a built-in converter.
555
573
  * Supports both Converter enum values and array converter configurations.
574
+ * The key can be a single name or an ordered list; the first defined value wins.
556
575
  */
557
- static getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: string, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
558
- static getUsing<TReturn>(key: string, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
576
+ static getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
577
+ static getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
559
578
  /**
560
579
  * @see {@link AdvancedMethods.getUsing}
561
580
  */
562
- getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: string, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
563
- getUsing<TReturn>(key: string, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
581
+ getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
582
+ getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
564
583
  /**
565
584
  * Get an environment variable using a custom converter function.
585
+ * Accepts a single key or an ordered list for automatic fallback.
566
586
  */
567
- static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: string, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
587
+ static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
568
588
  /**
569
589
  * @see {@link AdvancedMethods.getWith}
570
590
  */
571
- getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: string, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
591
+ getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
572
592
  }
573
593
 
574
594
  /**
@@ -584,10 +604,12 @@ declare class AdvancedMethods extends PrimitiveMethods {
584
604
  * // Static usage
585
605
  * const port = Envapter.getNumber('PORT', 3000);
586
606
  * const url = Envapter.get('API_URL', 'http://localhost');
607
+ * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
587
608
  *
588
609
  * // Instance usage
589
610
  * const env = new Envapter();
590
611
  * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
612
+ * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
591
613
  * ```
592
614
  *
593
615
  * @public
@@ -639,7 +661,9 @@ declare enum EnvaptErrorCodes {
639
661
  /** Thrown when invalid user-defined configuration is provided */
640
662
  InvalidUserDefinedConfig = 302,
641
663
  /** Thrown when specified environment files don't exist */
642
- EnvFilesNotFound = 303
664
+ EnvFilesNotFound = 303,
665
+ /** Thrown when no valid environment key is provided */
666
+ InvalidKeyInput = 304
643
667
  }
644
668
  /**
645
669
  * Custom error for better DX and debugging when using Envapt.
@@ -654,4 +678,4 @@ declare class EnvaptError extends Error {
654
678
  constructor(code: EnvaptErrorCodes, message: string);
655
679
  }
656
680
 
657
- export { type AdvancedConverterReturn, type ArrayConverter, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, Converters, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type JsonValue, type MapOfConverterFunctions, type PermittedDotenvConfig, type PrimitiveConstructor, type TimeUnit, type ValidArrayConverterBuiltInType };
681
+ export { type AdvancedConverterReturn, type ArrayConverter, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, Converters, type EnvKeyInput, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type JsonValue, type MapOfConverterFunctions, type PermittedDotenvConfig, type PrimitiveConstructor, type TimeUnit, type ValidArrayConverterBuiltInType };
package/dist/index.d.ts CHANGED
@@ -76,6 +76,11 @@ interface ArrayConverter {
76
76
  * @public
77
77
  */
78
78
  type BaseInput = string | undefined;
79
+ /**
80
+ * Accepted shape for environment variable lookups. Either a single key or an ordered list of keys.
81
+ * @public
82
+ */
83
+ type EnvKeyInput = string | readonly [string, ...string[]];
79
84
  /**
80
85
  * Custom parser function type for environment variables
81
86
  * @param raw - Raw string value from environment
@@ -189,7 +194,7 @@ type InferPrimitiveFallbackType<TFallback extends string | number | boolean | bi
189
194
  /**
190
195
  * Usage 1: Custom converter function with fallback provided
191
196
  *
192
- * @param key - Environment variable name to load
197
+ * @param key - Environment variable name to load (string or ordered array of strings)
193
198
  * @param options - Configuration options with custom converter and required fallback
194
199
  * @public
195
200
  * @example
@@ -207,14 +212,14 @@ type InferPrimitiveFallbackType<TFallback extends string | number | boolean | bi
207
212
  * }
208
213
  * ```
209
214
  */
210
- declare function Envapt<TFallback>(key: string, options: {
215
+ declare function Envapt<TFallback>(key: EnvKeyInput, options: {
211
216
  converter: (raw: string | undefined, fallback: TFallback) => TFallback;
212
217
  fallback: TFallback;
213
218
  }): PropertyDecorator;
214
219
  /**
215
220
  * Usage 2: Custom converter function without fallback
216
221
  *
217
- * @param key - Environment variable name to load
222
+ * @param key - Environment variable name(s) to load
218
223
  * @param options - Configuration options with custom converter only
219
224
  * @public
220
225
  * @example
@@ -229,13 +234,13 @@ declare function Envapt<TFallback>(key: string, options: {
229
234
  * }
230
235
  * ```
231
236
  */
232
- declare function Envapt<TReturnType>(key: string, options: {
237
+ declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
233
238
  converter: ConverterFunction<TReturnType>;
234
239
  }): PropertyDecorator;
235
240
  /**
236
241
  * Usage 3: Built-in converter with optional fallback
237
242
  *
238
- * @param key - Environment variable name to load
243
+ * @param key - Environment variable name(s) to load
239
244
  * @param options - Configuration options with built-in converter
240
245
  * @public
241
246
  * @example
@@ -250,17 +255,21 @@ declare function Envapt<TReturnType>(key: string, options: {
250
255
  * // Use Url converter with a string fallback (must match converter type)
251
256
  * \@Envapt('APP_URL', { converter: Converters.Url, fallback: 'http://localhost:3000' })
252
257
  * static readonly url: URL;
258
+ *
259
+ * // Prefer CANARY_URL when present, otherwise fall back to APP_URL
260
+ * \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
261
+ * static readonly canaryUrl: URL | null;
253
262
  * }
254
263
  * ```
255
264
  */
256
- declare function Envapt<TConverter extends BuiltInConverter>(key: string, options: {
265
+ declare function Envapt<TConverter extends BuiltInConverter>(key: EnvKeyInput, options: {
257
266
  converter: TConverter;
258
267
  fallback?: InferConverterReturnType<TConverter> | undefined;
259
268
  }): PropertyDecorator;
260
269
  /**
261
270
  * Usage 4: Array converter with optional fallback
262
271
  *
263
- * @param key - Environment variable name to load
272
+ * @param key - Environment variable name(s) to load
264
273
  * @param options - Configuration options with array converter
265
274
  * @public
266
275
  * @example
@@ -284,14 +293,14 @@ declare function Envapt<TConverter extends BuiltInConverter>(key: string, option
284
293
  * }
285
294
  * ```
286
295
  */
287
- declare function Envapt<TConverter extends ArrayConverter>(key: string, options: {
296
+ declare function Envapt<TConverter extends ArrayConverter>(key: EnvKeyInput, options: {
288
297
  converter: TConverter;
289
298
  fallback?: InferConverterReturnType<TConverter> | undefined;
290
299
  }): PropertyDecorator;
291
300
  /**
292
301
  * Usage 5: Primitive constructor with optional fallback
293
302
  *
294
- * @param key - Environment variable name to load
303
+ * @param key - Environment variable name(s) to load
295
304
  * @param options - Configuration options with primitive constructor
296
305
  * @public
297
306
  * @example
@@ -306,14 +315,14 @@ declare function Envapt<TConverter extends ArrayConverter>(key: string, options:
306
315
  * }
307
316
  * ```
308
317
  */
309
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: string, options: {
318
+ declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
310
319
  converter: TConstructor;
311
320
  fallback?: InferPrimitiveReturnType<TConstructor>;
312
321
  }): PropertyDecorator;
313
322
  /**
314
323
  * Usage 6: Fallback only (no converter)
315
324
  *
316
- * @param key - Environment variable name to load
325
+ * @param key - Environment variable name(s) to load
317
326
  * @param options - Configuration options with fallback only
318
327
  * @public
319
328
  * @example
@@ -328,14 +337,14 @@ declare function Envapt<TConstructor extends PrimitiveConstructor>(key: string,
328
337
  * }
329
338
  * ```
330
339
  */
331
- declare function Envapt<TFallback>(key: string, options: {
340
+ declare function Envapt<TFallback>(key: EnvKeyInput, options: {
332
341
  fallback: TFallback;
333
342
  converter?: undefined;
334
343
  }): PropertyDecorator;
335
344
  /**
336
345
  * Classic API: No fallback
337
346
  *
338
- * @param key - Environment variable name to load
347
+ * @param key - Environment variable name(s) to load
339
348
  * @example
340
349
  * ```ts
341
350
  * // Classic API: no fallback — property will resolve from env or be null
@@ -345,11 +354,11 @@ declare function Envapt<TFallback>(key: string, options: {
345
354
  * }
346
355
  * ```
347
356
  */
348
- declare function Envapt<_TReturnType = string | null>(key: string): PropertyDecorator;
357
+ declare function Envapt<_TReturnType = string | null>(key: EnvKeyInput): PropertyDecorator;
349
358
  /**
350
359
  * Classic API: Primitive fallback only
351
360
  *
352
- * @param key - Environment variable name to load
361
+ * @param key - Environment variable name(s) to load
353
362
  * @param fallback - Default primitive value
354
363
  * @param converter - Optional primitive constructor (String, Number, etc.)
355
364
  * @public
@@ -367,14 +376,14 @@ declare function Envapt<_TReturnType = string | null>(key: string): PropertyDeco
367
376
  * }
368
377
  * ```
369
378
  */
370
- declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: string, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
379
+ declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: EnvKeyInput, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
371
380
 
372
381
  /**
373
382
  * @internal
374
383
  */
375
384
  interface EnvapterService {
376
- getRaw(key: string): string | undefined;
377
- get(key: string, def?: string): string | undefined;
385
+ getRaw(key: EnvKeyInput): string | undefined;
386
+ get(key: EnvKeyInput, def?: string): string | undefined;
378
387
  }
379
388
  /**
380
389
  * Parser class for handling environment variable template resolution and type conversion
@@ -389,7 +398,7 @@ declare class Parser {
389
398
  * @internal
390
399
  */
391
400
  resolveTemplate(key: string, value: string, stack?: Set<string>): string;
392
- convertValue<TFallback>(key: string, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
401
+ convertValue<TFallback>(key: EnvKeyInput, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
393
402
  private processFallbackForConverter;
394
403
  private convertPrimitiveToString;
395
404
  private processBuiltInConverter;
@@ -424,11 +433,15 @@ declare abstract class EnvapterBase {
424
433
  */
425
434
  static get dotenvConfig(): PermittedDotenvConfig;
426
435
  protected static refreshCache(): void;
436
+ protected static resolveKeyInput(keyInput: EnvKeyInput): {
437
+ key: string;
438
+ value: string | undefined;
439
+ };
427
440
  protected static get config(): Map<string, unknown>;
428
441
  /**
429
442
  * Get raw environment variable value without parsing or conversion.
430
443
  */
431
- getRaw(key: string): string | undefined;
444
+ getRaw(key: EnvKeyInput): string | undefined;
432
445
  }
433
446
 
434
447
  /**
@@ -500,49 +513,54 @@ declare class PrimitiveMethods extends EnvironmentMethods implements EnvapterSer
500
513
  private static _get;
501
514
  /**
502
515
  * Get a string environment variable with optional fallback.
503
- * Supports template variable resolution using $\{VAR\} syntax.
516
+ * Supports template variable resolution using `${VAR}` syntax.
517
+ * Accepts a single key or an ordered array of keys (first match wins).
504
518
  */
505
- static get<Default extends string | undefined = undefined>(key: string, def?: Default): ConditionalReturn<string, Default>;
519
+ static get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
506
520
  /**
507
521
  * @see {@link PrimitiveMethods.get}
508
522
  */
509
- get<Default extends string | undefined = undefined>(key: string, def?: Default): ConditionalReturn<string, Default>;
523
+ get(key: EnvKeyInput, def?: string): string | undefined;
510
524
  /**
511
525
  * Get a number environment variable with optional fallback.
512
526
  * Automatically converts string values to numbers.
527
+ * Accepts a single key or an ordered array of keys (first match wins).
513
528
  */
514
- static getNumber<Default extends number | undefined = undefined>(key: string, def?: Default): ConditionalReturn<number, Default>;
529
+ static getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
515
530
  /**
516
531
  * @see {@link PrimitiveMethods.getNumber}
517
532
  */
518
- getNumber<Default extends number | undefined = undefined>(key: string, def?: Default): ConditionalReturn<number, Default>;
533
+ getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
519
534
  /**
520
535
  * Get a boolean environment variable with optional fallback.
521
536
  * Recognizes: `1`, `yes`, `true`, 'on' as **true**; `0`, `no`, `false`, 'off' as **false** (case-insensitive).
537
+ * Accepts a single key or an ordered array of keys (first match wins).
522
538
  */
523
- static getBoolean<Default extends boolean | undefined = undefined>(key: string, def?: Default): ConditionalReturn<boolean, Default>;
539
+ static getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
524
540
  /**
525
541
  * @see {@link PrimitiveMethods.getBoolean}
526
542
  */
527
- getBoolean<Default extends boolean | undefined = undefined>(key: string, def?: Default): ConditionalReturn<boolean, Default>;
543
+ getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
528
544
  /**
529
545
  * Get a bigint environment variable with optional fallback.
530
546
  * Automatically converts string values to bigint.
547
+ * Accepts a single key or an ordered array of keys (first match wins).
531
548
  */
532
- static getBigInt<Default extends bigint | undefined = undefined>(key: string, def?: Default): ConditionalReturn<bigint, Default>;
549
+ static getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
533
550
  /**
534
551
  * @see {@link PrimitiveMethods.getBigInt}
535
552
  */
536
- getBigInt<Default extends bigint | undefined = undefined>(key: string, def?: Default): ConditionalReturn<bigint, Default>;
553
+ getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
537
554
  /**
538
555
  * Get a symbol environment variable with optional fallback.
539
556
  * Creates a symbol from the string value.
557
+ * Accepts a single key or an ordered array of keys (first match wins).
540
558
  */
541
- static getSymbol<Default extends symbol | undefined = undefined>(key: string, def?: Default): ConditionalReturn<symbol, Default>;
559
+ static getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
542
560
  /**
543
561
  * @see {@link PrimitiveMethods.getSymbol}
544
562
  */
545
- getSymbol<Default extends symbol | undefined = undefined>(key: string, def?: Default): ConditionalReturn<symbol, Default>;
563
+ getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
546
564
  }
547
565
 
548
566
  /**
@@ -553,22 +571,24 @@ declare class AdvancedMethods extends PrimitiveMethods {
553
571
  /**
554
572
  * Get an environment variable using a built-in converter.
555
573
  * Supports both Converter enum values and array converter configurations.
574
+ * The key can be a single name or an ordered list; the first defined value wins.
556
575
  */
557
- static getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: string, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
558
- static getUsing<TReturn>(key: string, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
576
+ static getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
577
+ static getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
559
578
  /**
560
579
  * @see {@link AdvancedMethods.getUsing}
561
580
  */
562
- getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: string, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
563
- getUsing<TReturn>(key: string, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
581
+ getUsing<TConverter extends BuiltInConverter | ArrayConverter, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
582
+ getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayConverter, fallback?: TReturn): TReturn;
564
583
  /**
565
584
  * Get an environment variable using a custom converter function.
585
+ * Accepts a single key or an ordered list for automatic fallback.
566
586
  */
567
- static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: string, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
587
+ static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
568
588
  /**
569
589
  * @see {@link AdvancedMethods.getWith}
570
590
  */
571
- getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: string, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
591
+ getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
572
592
  }
573
593
 
574
594
  /**
@@ -584,10 +604,12 @@ declare class AdvancedMethods extends PrimitiveMethods {
584
604
  * // Static usage
585
605
  * const port = Envapter.getNumber('PORT', 3000);
586
606
  * const url = Envapter.get('API_URL', 'http://localhost');
607
+ * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
587
608
  *
588
609
  * // Instance usage
589
610
  * const env = new Envapter();
590
611
  * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
612
+ * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
591
613
  * ```
592
614
  *
593
615
  * @public
@@ -639,7 +661,9 @@ declare enum EnvaptErrorCodes {
639
661
  /** Thrown when invalid user-defined configuration is provided */
640
662
  InvalidUserDefinedConfig = 302,
641
663
  /** Thrown when specified environment files don't exist */
642
- EnvFilesNotFound = 303
664
+ EnvFilesNotFound = 303,
665
+ /** Thrown when no valid environment key is provided */
666
+ InvalidKeyInput = 304
643
667
  }
644
668
  /**
645
669
  * Custom error for better DX and debugging when using Envapt.
@@ -654,4 +678,4 @@ declare class EnvaptError extends Error {
654
678
  constructor(code: EnvaptErrorCodes, message: string);
655
679
  }
656
680
 
657
- export { type AdvancedConverterReturn, type ArrayConverter, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, Converters, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type JsonValue, type MapOfConverterFunctions, type PermittedDotenvConfig, type PrimitiveConstructor, type TimeUnit, type ValidArrayConverterBuiltInType };
681
+ export { type AdvancedConverterReturn, type ArrayConverter, type BuiltInConverter, type BuiltInConverterFunction, type ConditionalReturn, type ConverterFunction, Converters, type EnvKeyInput, Envapt, type EnvaptConverter, EnvaptError, EnvaptErrorCodes, type EnvaptOptions, Envapter, Environment, type InferConverterReturnType, type InferPrimitiveFallbackType, type InferPrimitiveReturnType, type JsonValue, type MapOfConverterFunctions, type PermittedDotenvConfig, type PrimitiveConstructor, type TimeUnit, type ValidArrayConverterBuiltInType };