Skip to content

lum2008/envwise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🌿 envwise

Environment Contracts for Node.js
Deterministic runtime validation powered by statically generated schema manifests.

CI npm License: MIT

envwise gives you code-first env declarations (builder + decorators), AST extraction at build time, and a strict runtime that validates from a committed manifest (envwise.schema.json) with zero runtime scanning.

✨ Why envwise?

  • 🎯 Deterministic by design: runtime only reads schema + configured sources.
  • 🧩 Hybrid workflow: author in code, ship generated artifacts.
  • πŸ§ͺ Strict parsing: bool, int, float, json, list<T>, url, duration, bytes.
  • πŸ”— Serializable rule DSL: cross-field rules that survive extraction.
  • πŸ” Security-first diagnostics: secrets masked by default.
  • βœ… CI drift enforcement: ensure schema/docs/templates stay in sync.

🧠 How it works

Code (builder / decorators)
          |
          | envwise generate  (AST extraction)
          v
envwise.schema.json + outputs
(.env.example, markdown, html, k8s, json-schema)
          |
          | loadEnv({ schema, sources })
          v
Deterministic runtime validation

πŸ“Œ Feature matrix

Capability envwise
Builder API (TS + JS) βœ…
Decorator API (TS) βœ…
Runtime file/module scanning ❌
Startup / Lazy / Manual modes βœ…
Strict typed parsing βœ…
Serializable cross-field rules βœ…
.env.example / docs / html / k8s / json-schema outputs βœ…
CI schema drift checks βœ…

πŸš€ Quickstart

1) Install

pnpm add @envwise/core
pnpm add -D @envwise/cli

2) Define environment contract (builder)

import { defineEnv, rule } from '@envwise/core';

export const schema = defineEnv({ projectName: 'my-app' })
  .string('NODE_ENV').oneOf(['development', 'production']).default('development')
  .int('PORT').default(3000).min(1).max(65535)
  .bool('USE_DB').default(false)
  .string('DB_URL').optional().secret().mode('lazy')
  .rule(rule('db-required', (r) => r.when('USE_DB').equals(true).thenRequire(['DB_URL'])))
  .build();

3) Generate manifest + outputs

envwise generate \
  --entry ./src/env.ts \
  --out ./envwise.schema.json \
  --formats dotenv,markdown,html,json-schema,k8s,table

4) Validate at runtime

import manifest from './envwise.schema.json';
import { loadEnv, processEnvSource, dotenvSource, argvSource } from '@envwise/core';

const env = loadEnv({
  schema: manifest,
  sources: [dotenvSource({ optional: true }), processEnvSource(), argvSource()],
});

console.log(env.get('PORT'));

🧱 Authoring styles

Builder API (TS/JS)

Use fluent, chainable declarations with type-safe runtime access.

Decorator API (TS)

import { EnvSchema, EnvVar, Rule } from '@envwise/decorators';
import { rule } from '@envwise/core';

@EnvSchema({ projectName: 'my-app' })
@Rule(rule('db-required', (r) => r.when('USE_DB').equals(true).thenRequire(['DB_URL'])))
class AppEnv {
  @EnvVar({ key: 'PORT', type: 'int', default: 3000 })
  port!: number;

  @EnvVar({ key: 'USE_DB', type: 'bool', default: false })
  useDb!: boolean;

  @EnvVar({ key: 'DB_URL', type: 'string', required: false, mode: 'lazy', secret: true })
  dbUrl!: string;
}

πŸ› οΈ CLI

envwise generate --entry ./src/schema.ts --out ./envwise.schema.json
envwise check --entry ./src/schema.ts --out ./envwise.schema.json

Config file support: envwise.config.ts | envwise.config.js | envwise.config.json.

πŸ“¦ Generated outputs

  • πŸ“„ Contract manifest (envwise.schema.json)
  • πŸ”§ .env.example
  • πŸ“ Markdown docs
  • 🌐 HTML docs
  • πŸ“š JSON schema for manifest
  • ☸️ Kubernetes templates (ConfigMap + Secret placeholders)

πŸ” Security model

  • Diagnostics levels: safe | verbose | off
  • Secret values are masked by default
  • Secret values require explicit nuclear opt-in (allowSecretValueLogging: true)

πŸ§ͺ CI enforcement

envwise check fails if generated files drift from source declarations.

Recommended CI steps:

pnpm install
pnpm lint
pnpm test
pnpm build
pnpm envwise:generate
pnpm envwise:check

βš–οΈ Comparison

envwise vs Zod

Zod is excellent for runtime object validation; envwise focuses on env contracts + static extraction + deterministic startup/runtime env validation + generated infra/docs artifacts.

envwise vs envalid

envalid focuses on runtime env parsing; envwise adds extraction, manifest versioning, richer outputs, decorator support, and CI schema drift checks.

πŸ” Migration & guides

πŸ—‚οΈ Monorepo packages

  • @envwise/schema: shared manifest types + JSON schema
  • @envwise/core: runtime, parser, rule engine, outputs, sources
  • @envwise/decorators: decorator authoring API
  • @envwise/cli: AST extraction + generators + drift checks

πŸ’» Local development

pnpm install
pnpm lint
pnpm test
pnpm build
pnpm envwise:generate
pnpm envwise:check

🚒 Publishing

Local publish (no provenance, required outside GitHub Actions OIDC):

npm login
pnpm npm:whoami
pnpm changeset:publish:local

CI publish (with provenance):

  • Uses .github/workflows/release.yml
  • Sets NPM_CONFIG_PROVENANCE=true
  • Uses npm trusted publishing (OIDC) or NPM_TOKEN

If publish fails with 404 for @envwise/*, ensure your npm account/org owns the @envwise scope and has publish permission.

πŸ“„ License

MIT.

About

Deterministic environment contracts for Node.js: code-first env schemas, strict validation, static extraction, docs/templates, and CI drift checks.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors