@subramanyaks/env-drift 1.1.0 → 1.2.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/dist/index.d.cts CHANGED
@@ -49,10 +49,31 @@ interface EnvDriftConfig {
49
49
  ignoreDirs?: string[];
50
50
  publicPrefixes?: string[];
51
51
  sensitiveKeywords?: string[];
52
+ strict?: boolean;
52
53
  }
53
54
  interface AuditOptions extends EnvDriftConfig {
54
55
  rootDir?: string;
55
56
  }
57
+ interface EnvDiffResult {
58
+ fileA: string;
59
+ fileB: string;
60
+ fileAExists: boolean;
61
+ fileBExists: boolean;
62
+ onlyInA: string[];
63
+ onlyInB: string[];
64
+ inBoth: string[];
65
+ emptyInA: string[];
66
+ emptyInB: string[];
67
+ }
68
+ interface WorkspaceAuditItem {
69
+ name: string;
70
+ path: string;
71
+ result: AuditResult;
72
+ }
73
+ interface WorkspaceAuditResult {
74
+ rootDir: string;
75
+ workspaces: WorkspaceAuditItem[];
76
+ }
56
77
 
57
78
  declare const BUILTIN_ENV_VARS: Set<string>;
58
79
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
@@ -84,8 +105,24 @@ declare function auditEnv(options?: AuditOptions): AuditResult;
84
105
  */
85
106
  declare function loadConfig(rootDir: string): EnvDriftConfig;
86
107
 
108
+ /**
109
+ * Compares keys across two `.env` files (e.g. `.env.staging` vs `.env.production`)
110
+ * without ever exposing secret values.
111
+ */
112
+ declare function diffEnvFiles(fileA: string, fileB: string, options?: {
113
+ rootDir?: string;
114
+ ignore?: string[];
115
+ }): EnvDiffResult;
116
+ /**
117
+ * Returns true if the diff found blocking drift between the two env files.
118
+ */
119
+ declare function hasDiffIssues(diff: EnvDiffResult, options?: {
120
+ strict?: boolean;
121
+ }): boolean;
122
+
87
123
  /**
88
124
  * Parses the text contents of a .env file without external dependencies.
125
+ * Supports multiline double-quoted values (e.g. PEM private keys).
89
126
  */
90
127
  declare function parseEnvContent(content: string): {
91
128
  keys: string[];
@@ -124,6 +161,22 @@ declare function scanFiles(rootDir: string, options?: ScanOptions): {
124
161
  references: EnvReference[];
125
162
  };
126
163
 
164
+ /**
165
+ * Infers a sensible starter Zod validator expression from an env variable name.
166
+ */
167
+ declare function inferZodRule(key: string): string;
168
+ /**
169
+ * Generates a starter Zod runtime validation schema (`env.schema.ts`) from an AuditResult.
170
+ */
171
+ declare function generateZodSchema(result: AuditResult): string;
172
+ /**
173
+ * Writes the generated Zod schema file to disk.
174
+ */
175
+ declare function writeZodSchema(outputPath: string, result: AuditResult): {
176
+ outputPath: string;
177
+ count: number;
178
+ };
179
+
127
180
  /**
128
181
  * Generates TypeScript ambient declarations (`env.d.ts`) from an AuditResult.
129
182
  */
@@ -141,9 +194,11 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
141
194
  * or real secrets committed in `.env.example`).
142
195
  * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
143
196
  * is skipped by default unless `requireEnvFile` is true.
197
+ * When `strict` is true, empty values, unused keys, and duplicate keys are also blocking.
144
198
  */
145
199
  declare function hasBlockingIssues(result: AuditResult, options?: {
146
200
  requireEnvFile?: boolean;
201
+ strict?: boolean;
147
202
  }): boolean;
148
203
  /**
149
204
  * Formats an AuditResult into a colorized terminal report.
@@ -162,5 +217,30 @@ declare function formatGitHubAnnotations(result: AuditResult, options?: {
162
217
  exampleFile?: string;
163
218
  ci?: boolean;
164
219
  }): string;
220
+ /**
221
+ * Formats an EnvDiffResult into a colorized terminal report without ever printing secret values.
222
+ */
223
+ declare function formatDiffReport(diff: EnvDiffResult): string;
224
+ /**
225
+ * Formats a multi-workspace audit report.
226
+ */
227
+ declare function formatWorkspaceReport(wsResult: WorkspaceAuditResult, options?: {
228
+ envFile?: string;
229
+ exampleFile?: string;
230
+ ci?: boolean;
231
+ }): string;
232
+
233
+ /**
234
+ * Discovers workspace package directories from `package.json` (`workspaces`)
235
+ * or `pnpm-workspace.yaml`.
236
+ */
237
+ declare function discoverWorkspaces(rootDir: string): Array<{
238
+ name: string;
239
+ path: string;
240
+ }>;
241
+ /**
242
+ * Audits every discovered workspace package in a monorepo.
243
+ */
244
+ declare function auditWorkspaces(rootDir: string, options?: Omit<AuditOptions, "rootDir">): WorkspaceAuditResult;
165
245
 
166
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectExampleSecretLeak, detectSecretExposure, extractEnvReferences, formatAuditReport, formatGitHubAnnotations, generateEnvTypes, hasBlockingIssues, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
246
+ export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDiffResult, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, type WorkspaceAuditItem, type WorkspaceAuditResult, auditEnv, auditWorkspaces, detectExampleSecretLeak, detectSecretExposure, diffEnvFiles, discoverWorkspaces, extractEnvReferences, formatAuditReport, formatDiffReport, formatGitHubAnnotations, formatWorkspaceReport, generateEnvTypes, generateZodSchema, hasBlockingIssues, hasDiffIssues, inferZodRule, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes, writeZodSchema };
package/dist/index.d.ts CHANGED
@@ -49,10 +49,31 @@ interface EnvDriftConfig {
49
49
  ignoreDirs?: string[];
50
50
  publicPrefixes?: string[];
51
51
  sensitiveKeywords?: string[];
52
+ strict?: boolean;
52
53
  }
53
54
  interface AuditOptions extends EnvDriftConfig {
54
55
  rootDir?: string;
55
56
  }
57
+ interface EnvDiffResult {
58
+ fileA: string;
59
+ fileB: string;
60
+ fileAExists: boolean;
61
+ fileBExists: boolean;
62
+ onlyInA: string[];
63
+ onlyInB: string[];
64
+ inBoth: string[];
65
+ emptyInA: string[];
66
+ emptyInB: string[];
67
+ }
68
+ interface WorkspaceAuditItem {
69
+ name: string;
70
+ path: string;
71
+ result: AuditResult;
72
+ }
73
+ interface WorkspaceAuditResult {
74
+ rootDir: string;
75
+ workspaces: WorkspaceAuditItem[];
76
+ }
56
77
 
57
78
  declare const BUILTIN_ENV_VARS: Set<string>;
58
79
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
@@ -84,8 +105,24 @@ declare function auditEnv(options?: AuditOptions): AuditResult;
84
105
  */
85
106
  declare function loadConfig(rootDir: string): EnvDriftConfig;
86
107
 
108
+ /**
109
+ * Compares keys across two `.env` files (e.g. `.env.staging` vs `.env.production`)
110
+ * without ever exposing secret values.
111
+ */
112
+ declare function diffEnvFiles(fileA: string, fileB: string, options?: {
113
+ rootDir?: string;
114
+ ignore?: string[];
115
+ }): EnvDiffResult;
116
+ /**
117
+ * Returns true if the diff found blocking drift between the two env files.
118
+ */
119
+ declare function hasDiffIssues(diff: EnvDiffResult, options?: {
120
+ strict?: boolean;
121
+ }): boolean;
122
+
87
123
  /**
88
124
  * Parses the text contents of a .env file without external dependencies.
125
+ * Supports multiline double-quoted values (e.g. PEM private keys).
89
126
  */
90
127
  declare function parseEnvContent(content: string): {
91
128
  keys: string[];
@@ -124,6 +161,22 @@ declare function scanFiles(rootDir: string, options?: ScanOptions): {
124
161
  references: EnvReference[];
125
162
  };
126
163
 
164
+ /**
165
+ * Infers a sensible starter Zod validator expression from an env variable name.
166
+ */
167
+ declare function inferZodRule(key: string): string;
168
+ /**
169
+ * Generates a starter Zod runtime validation schema (`env.schema.ts`) from an AuditResult.
170
+ */
171
+ declare function generateZodSchema(result: AuditResult): string;
172
+ /**
173
+ * Writes the generated Zod schema file to disk.
174
+ */
175
+ declare function writeZodSchema(outputPath: string, result: AuditResult): {
176
+ outputPath: string;
177
+ count: number;
178
+ };
179
+
127
180
  /**
128
181
  * Generates TypeScript ambient declarations (`env.d.ts`) from an AuditResult.
129
182
  */
@@ -141,9 +194,11 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
141
194
  * or real secrets committed in `.env.example`).
142
195
  * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
143
196
  * is skipped by default unless `requireEnvFile` is true.
197
+ * When `strict` is true, empty values, unused keys, and duplicate keys are also blocking.
144
198
  */
145
199
  declare function hasBlockingIssues(result: AuditResult, options?: {
146
200
  requireEnvFile?: boolean;
201
+ strict?: boolean;
147
202
  }): boolean;
148
203
  /**
149
204
  * Formats an AuditResult into a colorized terminal report.
@@ -162,5 +217,30 @@ declare function formatGitHubAnnotations(result: AuditResult, options?: {
162
217
  exampleFile?: string;
163
218
  ci?: boolean;
164
219
  }): string;
220
+ /**
221
+ * Formats an EnvDiffResult into a colorized terminal report without ever printing secret values.
222
+ */
223
+ declare function formatDiffReport(diff: EnvDiffResult): string;
224
+ /**
225
+ * Formats a multi-workspace audit report.
226
+ */
227
+ declare function formatWorkspaceReport(wsResult: WorkspaceAuditResult, options?: {
228
+ envFile?: string;
229
+ exampleFile?: string;
230
+ ci?: boolean;
231
+ }): string;
232
+
233
+ /**
234
+ * Discovers workspace package directories from `package.json` (`workspaces`)
235
+ * or `pnpm-workspace.yaml`.
236
+ */
237
+ declare function discoverWorkspaces(rootDir: string): Array<{
238
+ name: string;
239
+ path: string;
240
+ }>;
241
+ /**
242
+ * Audits every discovered workspace package in a monorepo.
243
+ */
244
+ declare function auditWorkspaces(rootDir: string, options?: Omit<AuditOptions, "rootDir">): WorkspaceAuditResult;
165
245
 
166
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectExampleSecretLeak, detectSecretExposure, extractEnvReferences, formatAuditReport, formatGitHubAnnotations, generateEnvTypes, hasBlockingIssues, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
246
+ export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDiffResult, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, type WorkspaceAuditItem, type WorkspaceAuditResult, auditEnv, auditWorkspaces, detectExampleSecretLeak, detectSecretExposure, diffEnvFiles, discoverWorkspaces, extractEnvReferences, formatAuditReport, formatDiffReport, formatGitHubAnnotations, formatWorkspaceReport, generateEnvTypes, generateZodSchema, hasBlockingIssues, hasDiffIssues, inferZodRule, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes, writeZodSchema };