env-drift-check 0.1.3 → 0.1.5

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 CHANGED
@@ -11,23 +11,29 @@
11
11
 
12
12
  ## Why use this?
13
13
 
14
- | Feature | Other Tools (dotenv-safe, etc.) | **env-drift-check** |
14
+ | Feature | Other Tools | **env-drift-check** |
15
15
  | :--- | :--- | :--- |
16
16
  | **Missing Keys** | Crash & Exit | **Interactive Setup Wizard** |
17
17
  | **Validation** | Basic Existence Check | **Rich Types** (Email, URL, Regex, Number) |
18
18
  | **Onboarding** | Manual (Read docs → Copy → Paste) | **Automated** (Run command → Fill prompts) |
19
19
  | **Drift Detection** | Static | **Real-time** comparison with `.env.example` |
20
20
 
21
- ## Features
21
+ ### Features
22
22
 
23
23
  - **Interactive Mode**: Automatically detects missing keys and prompts you to fill them in via CLI.
24
24
  - **Smart Schema Validation**: Enforce types like `email`, `url`, `number`, `boolean`, `enum`, and custom `regex`.
25
25
  - **Drift Detection**: Instantly compare your local environment against the team's `.env.example`.
26
- - **CI/CD Ready**: Use strict mode to fail builds if environment variables are missing or invalid.
27
26
  - **Zero Config**: Works out of the box, or add `envwise.config.json` for advanced validation rules.
28
27
 
28
+ ## 📖 Documentation
29
+
30
+ - [CLI Usage](./docs/CLI-Usage.md) - Command line flags and examples.
31
+ - [Configuration](./docs/Configuration.md) - Advanced validation rules and `envwise.config.json`.
32
+ - [Programmatic API](./docs/API-Reference.md) - Using the package in your code.
33
+
29
34
  ## Installation
30
35
 
36
+
31
37
  Install globally or as a dev dependency:
32
38
 
33
39
  ```bash
@@ -36,7 +42,7 @@ npm install -g env-drift-check
36
42
  npm install --save-dev env-drift-check
37
43
  ```
38
44
 
39
- ## 🛠 Usage
45
+ ## Usage
40
46
 
41
47
  ### 1. Basic Check
42
48
  Check if your `.env` is missing any keys defined in `.env.example`. This is great for a quick status check.
@@ -1,2 +1,8 @@
1
1
  import { Config } from "../types";
2
+ /**
3
+ * Loads the project configuration from 'envwise.config.json' if it exists.
4
+ * Falls back to default configuration if no file is found.
5
+ *
6
+ * @returns The consolidated configuration object
7
+ */
2
8
  export declare function loadConfig(): Config;
@@ -10,6 +10,12 @@ const DEFAULT_CONFIG = {
10
10
  baseEnv: ".env.example",
11
11
  rules: {}
12
12
  };
13
+ /**
14
+ * Loads the project configuration from 'envwise.config.json' if it exists.
15
+ * Falls back to default configuration if no file is found.
16
+ *
17
+ * @returns The consolidated configuration object
18
+ */
13
19
  function loadConfig() {
14
20
  const configPath = path_1.default.resolve("envwise.config.json");
15
21
  if (!fs_1.default.existsSync(configPath)) {
@@ -1,2 +1,11 @@
1
1
  import { DriftResult, Config } from "../types";
2
+ /**
3
+ * Compares a base environment (template) against a target environment (actual)
4
+ * and returns the differences including missing keys, extra keys, and value mismatches.
5
+ *
6
+ * @param base - The record representing the template environment (e.g., .env.example)
7
+ * @param target - The record representing the actual environment (e.g., .env)
8
+ * @param config - Configuration object containing validation rules
9
+ * @returns An object containing the results of the drift check
10
+ */
2
11
  export declare function checkDrift(base: Record<string, string>, target: Record<string, string>, config: Config): DriftResult;
@@ -2,6 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkDrift = checkDrift;
4
4
  const validator_1 = require("./validator");
5
+ /**
6
+ * Compares a base environment (template) against a target environment (actual)
7
+ * and returns the differences including missing keys, extra keys, and value mismatches.
8
+ *
9
+ * @param base - The record representing the template environment (e.g., .env.example)
10
+ * @param target - The record representing the actual environment (e.g., .env)
11
+ * @param config - Configuration object containing validation rules
12
+ * @returns An object containing the results of the drift check
13
+ */
5
14
  function checkDrift(base, target, config) {
6
15
  const result = {
7
16
  missing: [],
@@ -1 +1,9 @@
1
+ /**
2
+ * Parses a .env file from the given file system path.
3
+ * It handles comments, empty lines, and quoted values.
4
+ *
5
+ * @param path - The absolute or relative path to the .env file
6
+ * @returns A record containing key-value pairs of the environment variables
7
+ * @throws {Error} If the file does not exist
8
+ */
1
9
  export declare function parseEnv(path: string): Record<string, string>;
@@ -5,6 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseEnv = parseEnv;
7
7
  const fs_1 = __importDefault(require("fs"));
8
+ /**
9
+ * Parses a .env file from the given file system path.
10
+ * It handles comments, empty lines, and quoted values.
11
+ *
12
+ * @param path - The absolute or relative path to the .env file
13
+ * @returns A record containing key-value pairs of the environment variables
14
+ * @throws {Error} If the file does not exist
15
+ */
8
16
  function parseEnv(path) {
9
17
  if (!fs_1.default.existsSync(path)) {
10
18
  throw new Error(`Env file not found: ${path}`);
@@ -1,2 +1,11 @@
1
1
  import { Config } from "../types";
2
+ /**
3
+ * Launches an interactive CLI wizard to help users fill in missing environment variables.
4
+ * Uses the 'prompts' package to collect user input with validation.
5
+ *
6
+ * @param missingKeys - An array of environment variable keys that are missing
7
+ * @param baseEnv - The template environment mapping
8
+ * @param config - The tool configuration containing validation rules
9
+ * @returns A promise that resolves to a record of the newly filled key-value pairs
10
+ */
2
11
  export declare function interactiveSetup(missingKeys: string[], baseEnv: Record<string, string>, config: Config): Promise<Record<string, string>>;
@@ -6,6 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.interactiveSetup = interactiveSetup;
7
7
  const prompts_1 = __importDefault(require("prompts"));
8
8
  const validator_1 = require("./validator");
9
+ /**
10
+ * Launches an interactive CLI wizard to help users fill in missing environment variables.
11
+ * Uses the 'prompts' package to collect user input with validation.
12
+ *
13
+ * @param missingKeys - An array of environment variable keys that are missing
14
+ * @param baseEnv - The template environment mapping
15
+ * @param config - The tool configuration containing validation rules
16
+ * @returns A promise that resolves to a record of the newly filled key-value pairs
17
+ */
9
18
  async function interactiveSetup(missingKeys, baseEnv, config) {
10
19
  const newValues = {};
11
20
  console.log("\n🛠 Interactive Setup: Let's fill in the missing variables.\n");
@@ -1,2 +1,12 @@
1
1
  import { Rule } from "../types";
2
+ /**
3
+ * Validates a single environment variable value against a set of rules.
4
+ * Supports string length, number ranges, boolean flags, enums, emails, URLs, and custom regex.
5
+ *
6
+ * @param key - The name of the environment variable
7
+ * @param value - The value to validate
8
+ * @param rule - The validation rule configuration for this key
9
+ * @param env - The current environment (e.g., NODE_ENV) for conditional rules
10
+ * @returns A string containing the error message if validation fails, otherwise null
11
+ */
2
12
  export declare function validateValue(key: string, value: string, rule: Rule, env: string): string | null;
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateValue = validateValue;
4
+ /**
5
+ * Validates a single environment variable value against a set of rules.
6
+ * Supports string length, number ranges, boolean flags, enums, emails, URLs, and custom regex.
7
+ *
8
+ * @param key - The name of the environment variable
9
+ * @param value - The value to validate
10
+ * @param rule - The validation rule configuration for this key
11
+ * @param env - The current environment (e.g., NODE_ENV) for conditional rules
12
+ * @returns A string containing the error message if validation fails, otherwise null
13
+ */
4
14
  function validateValue(key, value, rule, env) {
5
15
  if (!value && rule.required !== false) {
6
16
  return `${key} is required`;
package/dist/types.d.ts CHANGED
@@ -1,29 +1,56 @@
1
+ /**
2
+ * Represents a validation rule for an environment variable.
3
+ */
1
4
  export interface Rule {
5
+ /** The data type of the variable. Used for validation and CLI input prompts. */
2
6
  type: "string" | "number" | "boolean" | "enum" | "email" | "url" | "regex";
7
+ /** Allowed values if the type is 'enum'. */
3
8
  values?: string[];
9
+ /** Custom regular expression string if the type is 'regex'. */
4
10
  regex?: string;
11
+ /** Minimum length (for strings) or minimum value (for numbers). */
5
12
  min?: number;
13
+ /** Maximum length (for strings) or maximum value (for numbers). */
6
14
  max?: number;
15
+ /** A helpful description displayed during interactive CLI setup. */
7
16
  description?: string;
17
+ /** Environment(s) where this boolean must be false (useful for safety flags). */
8
18
  mustBeFalseIn?: string;
19
+ /** Whether the variable is mandatory. Defaults to true. */
9
20
  required?: boolean;
10
21
  }
22
+ /**
23
+ * Global configuration for the env-drift-check tool.
24
+ */
11
25
  export interface Config {
26
+ /** The template environment file to compare against (e.g., .env.example). */
12
27
  baseEnv?: string;
28
+ /** A map of environment variable keys to their validation rules. */
13
29
  rules?: Record<string, Rule>;
14
30
  }
31
+ /**
32
+ * Details of a mismatch between the base and target environment values.
33
+ */
15
34
  export interface ValueMismatch {
16
35
  key: string;
17
36
  expected: string;
18
37
  actual: string;
19
38
  }
39
+ /**
40
+ * The consolidated result of an environment drift check.
41
+ */
20
42
  export interface DriftResult {
43
+ /** Keys present in the template but missing in the target. */
21
44
  missing: string[];
45
+ /** Keys present in the target but absent from the template. */
22
46
  extra: string[];
47
+ /** Validation errors based on the defined rules. */
23
48
  errors: {
24
49
  key: string;
25
50
  message: string;
26
51
  }[];
52
+ /** Non-critical warnings. */
27
53
  warnings: string[];
54
+ /** Values that differ between the template and target for the same key. */
28
55
  mismatches: ValueMismatch[];
29
56
  }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "env-drift-check",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Interactive environment variable checker and setup wizard. Sync .env files with validation (Email, URL, Regex) and prompts.",
5
5
  "keywords": [
6
6
  "env",
7
7
  "dotenv",
8
8
  "check-env",
9
9
  "dotenv-safe",
10
+ "env-drift-check",
10
11
  "environment-variables",
12
+ "env-validation",
11
13
  "config",
12
14
  "validation",
13
15
  "interactive",