envclinic 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release.
6
+
7
+ **Auditing**
8
+ - `envclinic audit` compares `.env` files with `.env.example` / `.env.sample`: missing, undocumented, empty and duplicate variables, invalid names, syntax problems
9
+ - Potentially unused variables and undeclared variables from static source scanning (`process.env`, `import.meta.env`, `Bun.env`, `Deno.env.get`, destructuring), with dynamic-access warnings
10
+ - Secret detection in env files and source code: provider tokens, private keys, URLs with credentials, weak secrets, secrets exposed through client prefixes, env files not covered by `.gitignore`; severity depends on whether a file is git-ignored
11
+ - Framework detection (Next.js, Vite, Astro, NestJS, Express, React, Node.js) from dependencies and config files, overridable in config
12
+
13
+ **Validation**
14
+ - Schema validation with `string`, `number`, `integer`, `boolean`, `url`, `email`, `enum` and `custom` types, required/optional/default, length and numeric ranges, patterns, URL protocols and custom validators
15
+ - Runtime API: `validateEnv`, `assertEnv`, `defineSchema` with typed results
16
+
17
+ **Generation**
18
+ - `generate` creates or merges `.env.example` (names only, grouped, with schema descriptions)
19
+ - `types` generates TypeScript declarations (`ProcessEnv`, and `ImportMetaEnv` for Vite and Astro) and `--check` for CI
20
+ - `init` interactive setup; `audit --fix` appends undocumented names to the example file
21
+ - Safe writes: dry-run, confirmation, atomic writes, never real env files, never outside the project
22
+
23
+ **CLI and CI**
24
+ - Commands: `init`, `audit`, `check`, `secrets`, `unused`, `generate`, `types`, `validate`, `framework`
25
+ - Terminal report, `--json`, `--format github` annotations, `--ci`, `--strict`, `--quiet`, `--verbose`, `--no-color`
26
+ - Exit codes: 0 ok, 1 problems found, 2 usage or runtime error
27
+
28
+ **Security**
29
+ - Values are never printed, written to generated files, or included in JSON; enforced by tests across every command
30
+ - Refuses files outside the project, unsafe symlinks and oversized files; project code and package scripts are never executed
31
+ - Optional config file (`json`, `mjs`, `js`, `cjs`, `ts`) with rule levels, ignores, secret allow-lists and custom patterns
32
+
33
+ **Windows**
34
+ - UTF-16 env files (what PowerShell `>` and `echo ... > .env` create) are decoded correctly and reported with a `non-utf8-file` warning
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 envclinic contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,164 @@
1
- # Temporary Holding Version
1
+ # envclinic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Audit, validate and secure your environment configuration, before it breaks your app.
4
+
5
+ `envclinic` is a CLI and Node.js library that compares your `.env` files with `.env.example`, finds variables your code needs but nobody documented, flags potentially unused and exposed ones, validates values against a schema, and generates `.env.example` and TypeScript declarations. It never prints, uploads or stores variable values.
6
+
7
+ ```text
8
+ ╭──────────────────────────────────────╮
9
+ │ ENV DOCTOR │
10
+ │ Environment Configuration │
11
+ ╰──────────────────────────────────────╯
12
+
13
+ ✔ Framework detected: Next.js
14
+
15
+ Missing variables (1)
16
+ ✘ REDIS_URL is declared in .env.example but missing from .env
17
+
18
+ Potentially unused variables (1)
19
+ ⚠ OLD_API_KEY is declared in .env but was not found in 12 scanned source files (potentially unused)
20
+
21
+ Undeclared variables (1)
22
+ ⚠ STRIPE_SECRET_KEY is used in app/page.ts but is not set in any env file or documented in .env.example
23
+
24
+ Security audit (2)
25
+ [WARNING] Weak secret (shorter than 12 characters)
26
+ File: .env:2
27
+ Variable: JWT_SECRET
28
+ Value: ********
29
+ [WARNING] NEXT_PUBLIC_API_SECRET looks like a secret but its NEXT_PUBLIC_ prefix exposes it to the browser bundle
30
+ File: .env:3
31
+ Variable: NEXT_PUBLIC_API_SECRET
32
+ Value: ********
33
+
34
+ Summary
35
+ 2 env files analyzed, 5 variables found, 12 source files scanned
36
+ 1 error, 4 warnings
37
+ ```
38
+
39
+ ## Features
40
+
41
+ - **Environment file audit**: missing, undocumented, empty and duplicate variables, invalid names, malformed lines; handles quotes, multiline values, `export`, comments and CRLF
42
+ - **Unused and undeclared variables**: static scan of your source (`process.env.X`, `process.env["X"]`, `import.meta.env.X`, destructuring...). Results say *potentially unused* and note when dynamic access makes them uncertain
43
+ - **Secret detection**: provider tokens, private keys, URLs with passwords, weak secrets, secrets exposed through `NEXT_PUBLIC_`/`VITE_` prefixes, env files missing from `.gitignore`
44
+ - **Schema validation**: `string`, `number`, `integer`, `boolean`, `url`, `email`, `enum`, `custom`; required, defaults, ranges, patterns. Also usable at app startup
45
+ - **`.env.example` generation**: names only, grouped and commented; merge into an existing file without losing your comments
46
+ - **TypeScript declarations** for `process.env` and `import.meta.env`, with a `--check` mode for CI
47
+ - **Framework detection**: Next.js, Vite, Astro, NestJS, Express, React, Node.js, overridable
48
+ - **CI friendly**: exit codes, `--json`, GitHub annotations
49
+ - **Safe by design**: see [Security](#security)
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ npm install --save-dev envclinic
55
+ # or run without installing
56
+ npx envclinic
57
+ ```
58
+
59
+ Requires Node.js 18+. Works on Linux, macOS and Windows. See [docs/installation.md](./docs/installation.md).
60
+
61
+ ## Quick start
62
+
63
+ ```bash
64
+ npx envclinic # full audit (same as `audit`)
65
+ npx envclinic init # optional: create a config file interactively
66
+ npx envclinic generate # create .env.example from what you already have
67
+ npx envclinic types # generate env.d.ts
68
+ npx envclinic audit --ci # for CI: no colors, exit code 1 on errors
69
+ ```
70
+
71
+ ## Commands
72
+
73
+ | Command | What it does |
74
+ |---|---|
75
+ | `audit` | The complete audit (default) |
76
+ | `check` | Missing, empty, duplicate, invalid variables and schema validation |
77
+ | `secrets` | Potentially exposed and weak secrets |
78
+ | `unused` | Potentially unused and undeclared variables |
79
+ | `validate` | Validate values against your schema |
80
+ | `generate` | Create or update `.env.example` |
81
+ | `types` | Generate TypeScript declarations |
82
+ | `framework` | Show the detected framework and its conventions |
83
+ | `init` | Create a config file |
84
+
85
+ Global options: `--cwd`, `--config`, `--json`, `--format <terminal\|json\|github>`, `--quiet`, `--verbose`, `--no-color`. Audit options include `--strict`, `--ci`, `--file`, `--example`, `--ignore`, `--no-scan`, `--process-env`, `--fix`. Everything is in the [CLI reference](./docs/cli-reference.md).
86
+
87
+ Exit codes: `0` ok, `1` problems found, `2` usage or runtime error.
88
+
89
+ ## Configuration
90
+
91
+ Optional. Create `envclinic.config.json` (or `.mjs`) in your project root, or run `npx envclinic init`.
92
+
93
+ ```js
94
+ // envclinic.config.mjs
95
+ import { defineConfig } from "envclinic";
96
+
97
+ export default defineConfig({
98
+ files: { source: [".env"], example: ".env.example" },
99
+ scan: { directories: ["src", "app"], ignore: ["generated"] },
100
+ rules: { missing: "error", unused: "warning", secrets: "error" },
101
+ ignore: { variables: ["NEXT_RUNTIME"] },
102
+ types: { enabled: true, output: "env.d.ts" },
103
+ schema: {
104
+ DATABASE_URL: { type: "url", required: true },
105
+ PORT: { type: "integer", required: false, default: 3000 },
106
+ NODE_ENV: { type: "enum", values: ["development", "production", "test"] },
107
+ JWT_SECRET: { type: "string", minLength: 32, secret: true },
108
+ },
109
+ });
110
+ ```
111
+
112
+ Unknown options are rejected with a clear message. Full reference: [docs/configuration.md](./docs/configuration.md).
113
+
114
+ ## Use it in CI
115
+
116
+ ```yaml
117
+ - run: npx envclinic audit --ci
118
+ - run: npx envclinic types --check
119
+ ```
120
+
121
+ In GitHub Actions, findings also appear as annotations on the pull request. More in [docs/integrations.md](./docs/integrations.md), including pre-commit hooks, monorepos and using it alongside Zod, Envalid or T3 Env.
122
+
123
+ ## Programmatic API
124
+
125
+ ```ts
126
+ import { audit, assertEnv, defineSchema } from "envclinic";
127
+
128
+ // Audit a project
129
+ const result = await audit({ cwd: process.cwd() });
130
+ if (!result.success) console.error(result.issues);
131
+
132
+ // Validate at startup, with typed results
133
+ const env = assertEnv(
134
+ defineSchema({
135
+ PORT: { type: "integer", required: false, default: 3000 },
136
+ DATABASE_URL: { type: "url" },
137
+ }),
138
+ );
139
+ env.PORT; // number
140
+ ```
141
+
142
+ `audit` returns `{ success, summary, files, issues, framework, configFile? }` where each issue has `code`, `severity`, `message` and optionally `file`, `variable`, `line`, `recommendation`. Issues have no field that can hold a value.
143
+
144
+ ## Security
145
+
146
+ - **Nothing is sent over the network.**
147
+ - **Values are never printed**: not in the terminal, JSON, annotations, errors or generated files. Verified by tests that run every command against planted marker values.
148
+ - **Your real env files are never modified.** `generate` and `--fix` only write template files such as `.env.example`, ask before replacing, and support `--dry-run`.
149
+ - **Your code is never executed.** Source is read as text. (Your own `envclinic.config.mjs` is JavaScript and runs when loaded; use JSON if you prefer.)
150
+ - Only files inside the project are read or written; unsafe symlinks are refused.
151
+
152
+ Detection is conservative and static: **a clean report does not prove there are no secrets, and "unused" means "potentially unused".** Pair envclinic with a dedicated secret scanner. Read the guarantees and limitations in [docs/security.md](./docs/security.md).
153
+
154
+ ## Examples
155
+
156
+ [`examples/`](./examples) contains small Next.js, Express and NestJS projects.
157
+
158
+ ## Contributing
159
+
160
+ Contributions are welcome. Start with [CONTRIBUTING.md](./CONTRIBUTING.md). Please report vulnerabilities privately, see [SECURITY.md](./SECURITY.md).
161
+
162
+ ## License
163
+
164
+ MIT