bini-env 1.1.1 → 1.1.2
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 +87 -28
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|

|
|
6
6
|

|
|
7
7
|

|
|
8
|
-

|
|
9
9
|

|
|
10
10
|
|
|
11
|
-
**
|
|
11
|
+
**Environment variable system + Vite plugin for Bini.js**
|
|
12
12
|
|
|
13
13
|
Powered by [Hono](https://hono.dev) — reads env vars from the Hono request context so variables are always resolved from the correct runtime binding, whether you're on Node.js, Bun, Deno, Vercel Edge, Netlify Edge, or Cloudflare Workers.
|
|
14
14
|
|
|
@@ -130,53 +130,73 @@ app.post('/example', async (c) => {
|
|
|
130
130
|
|
|
131
131
|
## Environment Prefixes
|
|
132
132
|
|
|
133
|
-
###
|
|
133
|
+
### The Truth About Prefixes
|
|
134
134
|
|
|
135
|
-
`BINI_`
|
|
135
|
+
**Both `BINI_` and `VITE_` work exactly the same way.** Neither is special.
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
| Prefix | Exposed to Browser? | Default Behavior |
|
|
138
|
+
|--------|--------------------|------------------|
|
|
139
|
+
| `BINI_` | **Yes** | Included in `envPrefix` by default |
|
|
140
|
+
| `VITE_` | **Yes** | Vite's default prefix (always included) |
|
|
141
|
+
| Any prefix you add | **Yes** | If you add it to `envPrefix` |
|
|
142
|
+
| No prefix | **No** | Not exposed to browser |
|
|
143
|
+
|
|
144
|
+
### What `biniEnv()` Actually Does
|
|
138
145
|
|
|
139
146
|
```ts
|
|
140
|
-
biniEnv(
|
|
147
|
+
// biniEnv() sets envPrefix to:
|
|
148
|
+
envPrefix: ['BINI_', 'VITE_']
|
|
149
|
+
|
|
150
|
+
// This tells Vite: "Expose ALL variables starting with BINI_ or VITE_ to import.meta.env"
|
|
141
151
|
```
|
|
142
152
|
|
|
143
|
-
|
|
153
|
+
**This means:**
|
|
154
|
+
- ✅ `BINI_API_KEY` → available in browser via `import.meta.env.BINI_API_KEY`
|
|
155
|
+
- ✅ `VITE_API_URL` → available in browser via `import.meta.env.VITE_API_URL`
|
|
156
|
+
- ❌ `DATABASE_URL` → NOT available in browser (no prefix)
|
|
144
157
|
|
|
145
|
-
|
|
158
|
+
### How to Keep Secrets Secret
|
|
159
|
+
|
|
160
|
+
**Use no prefix for secrets:**
|
|
146
161
|
|
|
147
162
|
```env
|
|
148
|
-
|
|
149
|
-
|
|
163
|
+
# ✅ NOT exposed to browser
|
|
164
|
+
DATABASE_URL=postgres://...
|
|
165
|
+
STRIPE_SECRET_KEY=sk_live_...
|
|
166
|
+
AWS_SECRET_KEY=...
|
|
150
167
|
```
|
|
151
168
|
|
|
169
|
+
**If you want `BINI_` to be private, remove it from `envPrefix`:**
|
|
170
|
+
|
|
152
171
|
```ts
|
|
153
|
-
//
|
|
154
|
-
|
|
172
|
+
// vite.config.ts
|
|
173
|
+
biniEnv({ envPrefix: ['VITE_'] }) // Only VITE_ exposed
|
|
174
|
+
// BINI_ is no longer exposed to the browser
|
|
155
175
|
```
|
|
156
176
|
|
|
157
|
-
### Choosing the
|
|
158
|
-
|
|
159
|
-
```env
|
|
160
|
-
# ✓ use VITE_ for anything the browser needs
|
|
161
|
-
VITE_API_URL=https://api.example.com
|
|
177
|
+
### Choosing the Right Prefix
|
|
162
178
|
|
|
163
|
-
|
|
164
|
-
BINI_FEATURE_FLAG=true
|
|
179
|
+
Since `BINI_` and `VITE_` are both exposed by default:
|
|
165
180
|
|
|
166
|
-
|
|
181
|
+
```env
|
|
182
|
+
# ✅ Use no prefix for secrets
|
|
167
183
|
DATABASE_URL=postgres://...
|
|
168
184
|
STRIPE_SECRET_KEY=sk_live_...
|
|
169
|
-
```
|
|
170
185
|
|
|
171
|
-
|
|
186
|
+
# ✅ Use any prefix for public config
|
|
187
|
+
BINI_API_URL=https://api.example.com
|
|
188
|
+
VITE_ANALYTICS_ID=UA-XXXX
|
|
189
|
+
PUBLIC_APP_NAME=MyApp # If you add PUBLIC_ to envPrefix
|
|
190
|
+
```
|
|
172
191
|
|
|
173
|
-
### Prefix
|
|
192
|
+
### Prefix Summary
|
|
174
193
|
|
|
175
|
-
| Prefix | Exposed to
|
|
194
|
+
| Prefix | Exposed to Browser? | Use For |
|
|
176
195
|
|--------|--------------------|---------|
|
|
177
|
-
|
|
|
178
|
-
| `
|
|
179
|
-
|
|
|
196
|
+
| No prefix | ❌ Never | **SECRETS** — API keys, database URLs, tokens |
|
|
197
|
+
| `BINI_` | ✅ Yes (by default) | Public config (same as VITE_) |
|
|
198
|
+
| `VITE_` | ✅ Yes (always) | Public config (Vite's default) |
|
|
199
|
+
| Custom prefix | ✅ If in `envPrefix` | Public config you want to control |
|
|
180
200
|
|
|
181
201
|
---
|
|
182
202
|
|
|
@@ -325,6 +345,41 @@ function readDbConfig(c: HonoContext) {
|
|
|
325
345
|
|
|
326
346
|
---
|
|
327
347
|
|
|
348
|
+
## Security Best Practices
|
|
349
|
+
|
|
350
|
+
### Rule 1: Never Prefix Secrets
|
|
351
|
+
```env
|
|
352
|
+
# ❌ BAD - This will be exposed to the browser!
|
|
353
|
+
BINI_DATABASE_URL=postgres://...
|
|
354
|
+
|
|
355
|
+
# ✅ GOOD - Not exposed to browser
|
|
356
|
+
DATABASE_URL=postgres://...
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Rule 2: Use No Prefix for Anything Secret
|
|
360
|
+
```env
|
|
361
|
+
# ✅ Safe - Not exposed
|
|
362
|
+
DATABASE_URL=postgres://...
|
|
363
|
+
STRIPE_SECRET=sk_live_...
|
|
364
|
+
AWS_SECRET_KEY=...
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Rule 3: Use Any Prefix for Public Data
|
|
368
|
+
```env
|
|
369
|
+
# ✅ Safe - Public data
|
|
370
|
+
BINI_API_URL=https://api.example.com
|
|
371
|
+
VITE_GA_ID=UA-XXXXX
|
|
372
|
+
PUBLIC_APP_NAME=MyApp
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Rule 4: Remove `BINI_` from envPrefix if You Want It Private
|
|
376
|
+
```ts
|
|
377
|
+
// To make BINI_ private, remove it from envPrefix
|
|
378
|
+
biniEnv({ envPrefix: ['VITE_'] })
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
328
383
|
## Performance
|
|
329
384
|
|
|
330
385
|
| Metric | Dev | Prod |
|
|
@@ -339,6 +394,10 @@ No dotenv. No disk reads. No caching layer. `getEnv` is a direct call to Hono's
|
|
|
339
394
|
|
|
340
395
|
## Troubleshooting
|
|
341
396
|
|
|
397
|
+
### "My BINI_ var is exposed to the browser!"
|
|
398
|
+
|
|
399
|
+
Yes — by design. `BINI_` is included in `envPrefix` by default. Use no prefix for secrets.
|
|
400
|
+
|
|
342
401
|
### "Env var is undefined in production"
|
|
343
402
|
|
|
344
403
|
Vars set in `.env` files are only loaded by Vite during local development. In production, set your variables in your hosting platform's environment dashboard (Vercel, Netlify, Cloudflare, etc.).
|
|
@@ -388,4 +447,4 @@ PRs are welcome. The goal of this library is to stay minimal and runtime-cost-fr
|
|
|
388
447
|
|
|
389
448
|
## License
|
|
390
449
|
|
|
391
|
-
MIT © Bini.js Team
|
|
450
|
+
MIT © Bini.js Team
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bini-env",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Universal environment variable loader and Vite plugin for Bini.js — powered by Hono, works across Node.js, Bun, Deno, Vercel Edge, Netlify Edge, and Cloudflare Workers",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@types/node": "
|
|
72
|
+
"@types/node": "26.1.2",
|
|
73
73
|
"hono": "^4.8.4",
|
|
74
74
|
"tsup": "^8.5.1",
|
|
75
|
-
"typescript": "^5.
|
|
75
|
+
"typescript": "^5.8.3",
|
|
76
76
|
"vite": "^8.0.8"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|