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/CHANGELOG.md +206 -0
- package/README.md +29 -3
- package/dist/index.cjs +134 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -39
- package/dist/index.d.ts +63 -39
- package/dist/index.mjs +134 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -30
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# envapt
|
|
2
|
+
|
|
3
|
+
## 4.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1244fb1: bump deps
|
|
8
|
+
|
|
9
|
+
## 4.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- a87c8e5: allow passing a list of env as the first arg to Envapt or Envapter methods. envapt will look for the env left-to-right and pick the first available one. passing a string still works and everything that worked before will work the same right now
|
|
14
|
+
|
|
15
|
+
## 4.0.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 9c7b728: bump versions
|
|
20
|
+
- 9c7b728: add examples for each overload of the Envapt decorator
|
|
21
|
+
|
|
22
|
+
## 4.0.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- bump deps
|
|
27
|
+
|
|
28
|
+
## 4.0.0
|
|
29
|
+
|
|
30
|
+
### Major Changes
|
|
31
|
+
|
|
32
|
+
- **BREAKING:** Simplify exports and type definitions for ESM and CJS. Replaced the nested exports map with flat fields import, require, and default. Types are now only at ./dist/index.d.ts. Removed the build step that renamed index.d.cts to index.d.mts.
|
|
33
|
+
|
|
34
|
+
## 3.0.2
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 063703c: bump deps
|
|
39
|
+
|
|
40
|
+
## 3.0.1
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- bump deps and refactor regexes to use String.raw and RegExp obj in BuiltInConverters to avoid disabling eslint rules
|
|
45
|
+
|
|
46
|
+
## 3.0.0
|
|
47
|
+
|
|
48
|
+
### Major Changes
|
|
49
|
+
|
|
50
|
+
- 482eb6d: **BREAKING:** Custom Converters will now execute even if an env variable is not present in the source env file(s). This allows for using `@Envapt` to validate the existence of variables by throwing errors inside the user-defined Custom Converters
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 5d1df34: update README to include new things and better navigation
|
|
55
|
+
|
|
56
|
+
## 2.2.10
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- remove codecov config
|
|
61
|
+
|
|
62
|
+
## 2.2.9
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- b263044: Ensure expected behavior to reject non ISO strings for Date converters
|
|
67
|
+
- 953bcb2: Improve test coverage by ignoring unreachable defensive programming blocks
|
|
68
|
+
- 8f0722d: Linting for TSDoc
|
|
69
|
+
- bc945d4: Safety when attempting to coerce to Symbol
|
|
70
|
+
- a21de8c: Augment ImportMeta instead of exporting a method
|
|
71
|
+
- dbd99b9: Cleanup files and configure vitest extension
|
|
72
|
+
|
|
73
|
+
## 2.2.8
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- e9e359e: Port tests to vitest
|
|
78
|
+
|
|
79
|
+
## 2.2.7
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Fix readme badge for tests CI and make file ext consistent in workflows dir
|
|
84
|
+
|
|
85
|
+
## 2.2.6
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- 01b1ba0: Fix deno missing mocha types error by explicitly importing mocha types in test files
|
|
90
|
+
- 0be2af4: Better test names and some badge formatting in README. Also condensed NOTICE and the other license file into one NOTICE.md file.
|
|
91
|
+
|
|
92
|
+
## 2.2.5
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- 7bb1923: Fixing types and removing `Error.captureStackTrace` to follow ECMAScript specifications
|
|
97
|
+
|
|
98
|
+
## 2.2.4
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- 435a738: Add jsr publishing support and a test for the previous version's type-error patch
|
|
103
|
+
- f17ca67: Bump deps: @types/node
|
|
104
|
+
- 6d47364: Bump deps: @typescript-eslint/parser
|
|
105
|
+
- fe12794: Bump deps: typescript-eslint
|
|
106
|
+
|
|
107
|
+
## 2.2.3
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- 73162d8: `undefined` as fallback causing type errors when provided with a BuiltIn or Array Converter
|
|
112
|
+
- d56fe89: Fix incorrect example in the README for URL converter and add some comments for `@Envapt` overloads
|
|
113
|
+
|
|
114
|
+
## 2.2.2
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- 6c1caaa: Fix grammar mistake in README
|
|
119
|
+
|
|
120
|
+
## 2.2.1
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- f1c81cc: Make clear that Envapt can be used with JavaScript too
|
|
125
|
+
|
|
126
|
+
## 2.2.0
|
|
127
|
+
|
|
128
|
+
### Minor Changes
|
|
129
|
+
|
|
130
|
+
- a74e97d: Tagged Template resolver for a easily "one-lining" multiple parsed envs in a string literal. It also supports template variables like `${VAR}`! Check README for usage and examples.
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- c479505: Missing export for `EnvaptError`
|
|
135
|
+
- f15ddc9: Fix cache collisions on Envapt used on a static property in one class, and an instance property in another class with the property name being the same for both
|
|
136
|
+
- 447aaa4: Fix incorrect "main" export in package.json
|
|
137
|
+
|
|
138
|
+
## 2.1.1
|
|
139
|
+
|
|
140
|
+
### Patch Changes
|
|
141
|
+
|
|
142
|
+
- "boilerplate of parsing" → "boilerplate of transforming parsed" in README
|
|
143
|
+
|
|
144
|
+
## 2.1.0
|
|
145
|
+
|
|
146
|
+
### Minor Changes
|
|
147
|
+
|
|
148
|
+
- Fix missing `.mjs` build
|
|
149
|
+
|
|
150
|
+
## 2.0.0
|
|
151
|
+
|
|
152
|
+
### Major Changes
|
|
153
|
+
|
|
154
|
+
- 7e3a440: Strict Runtime Validation
|
|
155
|
+
- **BREAKING:** Runtime type validation between converter return types and fallback values exists now... and it's strict!
|
|
156
|
+
- But only for built-in and array converters. You are free to do what you want with custom converters.
|
|
157
|
+
- EnvaptError codes actually make sense now instead of the random numbers they were before
|
|
158
|
+
- Added primitive type coercion validation and better error handling
|
|
159
|
+
|
|
160
|
+
Since this didn't exist before, it will break existing code that was previously passing incorrect types.
|
|
161
|
+
|
|
162
|
+
- 7e3a440: Major Type Inference Improvements
|
|
163
|
+
- **BREAKING:** Improved type inference for `@Envapt` decorator with better type safety
|
|
164
|
+
- Fallbacks and Converters are also validated against each other
|
|
165
|
+
- Fallback always decides the type and converter has to match it, except when using a Primitive constructor.
|
|
166
|
+
- Fixed incorrect type inference in **many** cases
|
|
167
|
+
- **BREAKING:** `@Envapt` won't allow you to use its Classic API for any custom converters anymore. Please use the decorator's Modern API, or the Functional API instead.
|
|
168
|
+
- I updated the overloads for `@Envapt` which fixed most of the type inference issues and also the point above.
|
|
169
|
+
|
|
170
|
+
Improved type checking may break existing code that was previously passing incorrect types. Typecheck your files after you update pls.
|
|
171
|
+
|
|
172
|
+
Decorators don't exactly set the value they return to the property they decorate, so the inferred type you see on hover for `@Envapt` will be the type of the converter rather than the type of the property it'll set. Although, for the functional API, the type will be the type of the property it'll set.
|
|
173
|
+
|
|
174
|
+
### Minor Changes
|
|
175
|
+
|
|
176
|
+
- 7e3a440: Enums for Built-in Converters
|
|
177
|
+
- Added `Converters` enum because they look better than string literals and provide better DX
|
|
178
|
+
- Allows using `Converters.String`, `Converters.Number`, etc. instead of string literals
|
|
179
|
+
- Maintains backward compatibility with string literal converter names
|
|
180
|
+
|
|
181
|
+
- 7e3a440: Customize Dotenv Configs
|
|
182
|
+
- Change how dotenv loads your env files. (Excludes the `path` and `processEnv` options because Envapter handles those)
|
|
183
|
+
- `Envapter.dotenvConfig` property for setting encoding, debug, override, and other dotenv options
|
|
184
|
+
- Now validates the file paths you provide to ensure they exist
|
|
185
|
+
|
|
186
|
+
- 7e3a440: New Functional API Methods
|
|
187
|
+
- Added `getUsing()` method for using built-in converters functionally
|
|
188
|
+
- Type overrides in `getUsing<T>()` if you need to specify a different type than the converter's inferred return type
|
|
189
|
+
- Added `getWith()` method for using custom converter functions functionally
|
|
190
|
+
- Functional API actually knows that a value won't be undefined if you pass a fallback value now
|
|
191
|
+
|
|
192
|
+
### Patch Changes
|
|
193
|
+
|
|
194
|
+
- 7e3a440: Dev and Testing Improvements
|
|
195
|
+
- Coverage for codecov
|
|
196
|
+
- Tests for BigInt and Symbol types
|
|
197
|
+
- Tests for primitive type coercion and multi-line environment variables
|
|
198
|
+
- LOTS more tests I don't remember
|
|
199
|
+
|
|
200
|
+
- 7e3a440: Refactored Some Code
|
|
201
|
+
- Envapter went over 400 lines and eslint started crying. It was a sign.
|
|
202
|
+
- It's basically a mixin using inheritance now. Nothing changed for the user though.
|
|
203
|
+
- Some Types were removed from the public API because they didn't have any use outside of internal code.
|
|
204
|
+
|
|
205
|
+
- 7e3a440: Make README.md pretty 🙏🏻
|
|
206
|
+
- Also shorten some scripts in package.json and update files that use these scripts
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
|
|
2
|
+
<img src="https://raw.githubusercontent.com/materwelonDhruv/envapt/main/.github/assets/banner.png" alt="Envapt – The apt way to handle environment variables" width="100%" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<div align="center">
|
|
11
11
|
<a href="https://www.npmjs.com/package/envapt"><img alt="npm" src="https://img.shields.io/npm/v/envapt?logo=npm&logoColor=cb3838&label=%20&labelColor=103544&color=cb3838"></a>
|
|
12
12
|
<a href="https://jsr.io/@materwelon/envapt"><img alt="jsr" src="https://jsr.io/badges/@materwelon/envapt"></a>
|
|
13
|
-
<img alt="CI" src="https://img.shields.io/github/actions/workflow/status/materwelonDhruv/envapt/
|
|
13
|
+
<img alt="CI" src="https://img.shields.io/github/actions/workflow/status/materwelonDhruv/envapt/checks.yml?branch=main&label=tests&style=flat&logo=github&color=3fb950&labelColor=103544"></a>
|
|
14
14
|
<a href="https://codecov.io/github/materwelonDhruv/envapt"><img alt="codecov" src="https://img.shields.io/codecov/c/github/materwelonDhruv/envapt/main?token=IQ4GC645LO&logo=codecov&color=f01f7a&labelColor=103544"/></a>
|
|
15
15
|
<br>
|
|
16
16
|
<a href="LICENSE"><img alt="License" src="https://img.shields.io/npm/l/envapt?style=flat&color=e97826&logo=apache&label="></a>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<a href="https://nodejs.org/api/modules.html"><img alt="CJS" src="https://img.shields.io/badge/CJS-ff6b35?style=flat"></a>
|
|
20
20
|
<a href="https://nodejs.org/"><img alt="Node" src="https://img.shields.io/badge/node-%3E=22.0.0-339933?style=flat&logo=node.js&logoColor=white"></a>
|
|
21
21
|
<a href="https://bundlephobia.com/package/envapt"><img alt="Bundle Size" src="https://img.shields.io/bundlephobia/minzip/envapt?style=flat&color=212121"></a>
|
|
22
|
-
|
|
22
|
+
<a href="https://www.npmjs.com/package/envapt"><img alt="Downloads (total)" src="https://img.shields.io/npm/dt/envapt?style=flat&color=f7f6e8"></a>
|
|
23
23
|
<a href="https://github.com/materwelonDhruv/envapt/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/materwelondhruv/envapt?style=flat&color=e3b341"></a>
|
|
24
24
|
</div>
|
|
25
25
|
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
- 🔖 **Tagged Template Resolver** - Tagged template literals with environment variable resolution
|
|
35
35
|
- 🌍 **Environment Detection** - Built-in development/staging/production handling
|
|
36
36
|
- 💪 **Edge Case Handling** - Robust validation and parsing for all scenarios
|
|
37
|
+
- 🔑 **Multi-Key Lookups** - Provide ordered lists of env keys and Envapt will use the first value it finds
|
|
37
38
|
- 🛡️ **Type Safety** - Full TypeScript support with proper type inference _(TypeScript optional)_
|
|
38
39
|
- 📂 **Multiple .env Files** - Load from multiple sources
|
|
39
40
|
- ⚡ **Lightweight** - Minimal overhead with [`dotenv`](https://www.npmjs.com/package/dotenv) bundled
|
|
@@ -163,6 +164,10 @@ console.log(`URL: ${url}`); // "http://localhost:8443"
|
|
|
163
164
|
const corsOrigins = Envapter.getUsing('ALLOWED_ORIGINS', Converters.Array, []);
|
|
164
165
|
const dbConfig = Envapter.getUsing('DATABASE_CONFIG', Converters.Json, {});
|
|
165
166
|
|
|
167
|
+
// Multi-key lookup: try primary, then replica, then fall back
|
|
168
|
+
const dbUrl = Envapter.get(['PRIMARY_DB_URL', 'REPLICA_DB_URL'], 'sqlite://memory');
|
|
169
|
+
const httpPort = Envapter.getNumber(['APP_PORT', 'PORT'], 3000);
|
|
170
|
+
|
|
166
171
|
// Tagged template literals
|
|
167
172
|
const message = Envapter.resolve`Server ${'APP_URL'} is ready!`;
|
|
168
173
|
console.log(message); // "Server http://localhost:8443 is ready!"
|
|
@@ -182,6 +187,10 @@ class AppConfig extends Envapter {
|
|
|
182
187
|
@Envapt('APP_URL', { fallback: new URL('http://localhost:3000'), converter: Converters.Url })
|
|
183
188
|
static readonly url: URL;
|
|
184
189
|
|
|
190
|
+
// Prefer CLOUD_REDIS_URL but fall back to classic REDIS_URL when missing
|
|
191
|
+
@Envapt(['CLOUD_REDIS_URL', 'REDIS_URL'], 'redis://localhost:6379')
|
|
192
|
+
static readonly redisUrl: string;
|
|
193
|
+
|
|
185
194
|
@Envapt('ALLOWED_ORIGINS', {
|
|
186
195
|
fallback: ['http://localhost:3000'],
|
|
187
196
|
converter: Converters.Array
|
|
@@ -241,6 +250,11 @@ The `@Envapt` decorator can be used on both **static** and **instance** class pr
|
|
|
241
250
|
@Envapt('ENV_VAR', { fallback?: T, converter?: EnvConverter<T> })
|
|
242
251
|
```
|
|
243
252
|
|
|
253
|
+
> [!NOTE]
|
|
254
|
+
> The first argument can be a string **or** an ordered array of strings:
|
|
255
|
+
> `@Envapt(['PRIMARY_URL', 'SECONDARY_URL'], { fallback: 'https://example.com' })`.
|
|
256
|
+
> Envapt will resolve the first key that exists.
|
|
257
|
+
>
|
|
244
258
|
> [!TIP]
|
|
245
259
|
> **Generic Typing for Better IntelliSense**
|
|
246
260
|
>
|
|
@@ -261,6 +275,13 @@ The `@Envapt` decorator can be used on both **static** and **instance** class pr
|
|
|
261
275
|
@Envapt('ENV_VAR', fallback?, converter?)
|
|
262
276
|
```
|
|
263
277
|
|
|
278
|
+
Need to chain multiple keys with the classic API? Pass an array instead of a string:
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
@Envapt(['HOST_PRIMARY', 'HOST_SECONDARY'], 'localhost')
|
|
282
|
+
static readonly host: string;
|
|
283
|
+
```
|
|
284
|
+
|
|
264
285
|
#### Automatic Runtime Type Detection
|
|
265
286
|
|
|
266
287
|
Types are automatically inferred from fallback values.
|
|
@@ -557,6 +578,9 @@ const jsonData = Envapter.getUsing('CONFIG_JSON', Converters.Json);
|
|
|
557
578
|
const urlArray = Envapter.getUsing('API_URLS', { delimiter: ',', type: Converters.Url });
|
|
558
579
|
const customData = Envapter.getWith('RAW_DATA', (raw) => raw?.split('|').map((s) => s.trim()));
|
|
559
580
|
|
|
581
|
+
// Multi-key inputs work everywhere: Envapt will read left-to-right
|
|
582
|
+
const secretsHost = Envapter.get(['SECRETS_HOST', 'DEFAULT_HOST'], 'localhost');
|
|
583
|
+
|
|
560
584
|
// Instance methods (same API available)
|
|
561
585
|
const envapter = new Envapter();
|
|
562
586
|
const value = envapter.get('VAR', 'default');
|
|
@@ -571,6 +595,7 @@ import { Envapter, Converters } from 'envapt';
|
|
|
571
595
|
// Use built-in converters directly
|
|
572
596
|
const config = Envapter.getUsing('API_CONFIG', Converters.Json, { default: 'value' });
|
|
573
597
|
const urls = Envapter.getUsing('SERVICE_URLS', { delimiter: '|', type: Converters.Url });
|
|
598
|
+
const pgUrl = Envapter.getUsing(['PRIMARY_PG_URL', 'SECONDARY_PG_URL'], Converters.Url);
|
|
574
599
|
|
|
575
600
|
// TypeScript: Use type override for better type inference
|
|
576
601
|
const typedConfig = Envapter.getUsing<{ host: string; port: number; ssl: boolean }>('DATABASE_CONFIG', Converters.Json);
|
|
@@ -846,6 +871,7 @@ try {
|
|
|
846
871
|
| `MissingDelimiter` (301) | Delimiter is missing in array converter config |
|
|
847
872
|
| `InvalidUserDefinedConfig` (302) | Invalid user-defined configuration provided |
|
|
848
873
|
| `EnvFilesNotFound` (303) | Specified environment file doesn't exist |
|
|
874
|
+
| `InvalidKeyInput` (304) | Invalid key input (not string or string array) |
|
|
849
875
|
|
|
850
876
|
<div align="right">
|
|
851
877
|
|