envsdk
v0.1.1
Published
Type-safe environment variable SDK — define, validate, deploy everywhere
Maintainers
Readme
import { env } from "envsdk"
const config = env.validate({
DATABASE_URL: env.string().url(),
PORT: env.number().default(3000),
NODE_ENV: env.enum(["dev", "staging", "prod"] as const),
API_KEY: env.string().secret(),
})
// ^? { DATABASE_URL: string; PORT: number; NODE_ENV: "dev" | "staging" | "prod"; API_KEY: string }Install
npm install envsdkQuick Start
# 1. Create a schema
echo 'export default { DATABASE_URL: env.string().url() }' > env.config.ts
# 2. Validate your environment
npx envsdk validate
# 3. Push to Vercel, GitHub, or Cloudflare
npx envsdk push vercel --project my-appDocs
| Topic | |
|-------|--|
| Getting started | docs/getting-started.md |
| API reference | docs/api-reference.md |
| CLI reference | docs/cli-reference.md |
| Platform adapters | docs/platform-adapters.md |
| Advanced | docs/advanced.md |
API Surface
Schema Builders
| Builder | Type | Description |
|---------|------|-------------|
| env.string() | string | Plain string |
| env.string().url() | string | URL-validated |
| env.string().email() | string | Email-validated |
| env.number() | number | Parsed from string |
| env.boolean() | boolean | true/1/yes or false/0/no |
| env.enum([...]) | literal union | Must match one value |
| env.json() | inferred | JSON.parse |
Modifiers
env.string().optional() // allow undefined
env.string().default("fallback") // default value
env.string().secret() // redact in CLI output
env.string().pattern(/^[a-z]+$/) // regex validation
env.string().transform(s.trim) // transform value
env.string().description("...") // human labelValidation
env.validate(schema) // throws on error
env.safeValidate(schema) // returns { success, data, errors }
env.validate(schema, { env }) // inject mock envCLI
npx envsdk validate [--schema env.config.ts] [--env .env]
npx envsdk push vercel --project my-app [--dry-run]
npx envsdk pull vercel --project my-app [--format json]
npx envsdk diff vercel --project my-appPlatform Adapters
| Import | Platform | Auth |
|--------|----------|------|
| envsdk/vercel | Vercel | VERCEL_TOKEN |
| envsdk/github | GitHub Actions | GITHUB_TOKEN |
| envsdk/cloudflare | Cloudflare Workers | CLOUDFLARE_API_TOKEN |
| envsdk/testing | In-memory | None |
import { vercel } from "envsdk/vercel"
await vercel.push(vars, { token: "...", project: "my-project" })
const remote = await vercel.pull({ token: "...", project: "my-project" })
const diffs = vercel.diff(local, remote)Development
npm install
npm run build
npm test