@subramanyaks/env-drift 1.0.1 → 1.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/dist/index.d.cts CHANGED
@@ -2,13 +2,14 @@ interface EnvReference {
2
2
  name: string;
3
3
  file: string;
4
4
  line: number;
5
- source: "process.env" | "import.meta.env";
5
+ source: "process.env" | "import.meta.env" | "Bun.env" | "Deno.env";
6
6
  }
7
7
  interface ParsedEnvFile {
8
8
  filePath: string;
9
9
  exists: boolean;
10
10
  keys: string[];
11
11
  values: Record<string, string>;
12
+ lines: Record<string, number>;
12
13
  duplicates: string[];
13
14
  }
14
15
  interface SecretExposureWarning {
@@ -17,6 +18,12 @@ interface SecretExposureWarning {
17
18
  matchedKeyword: string;
18
19
  references: EnvReference[];
19
20
  }
21
+ interface ExampleSecretLeak {
22
+ name: string;
23
+ reason: string;
24
+ file: string;
25
+ line: number;
26
+ }
20
27
  interface AuditResult {
21
28
  rootDir: string;
22
29
  scannedFiles: number;
@@ -25,29 +32,44 @@ interface AuditResult {
25
32
  usedInCode: Record<string, EnvReference[]>;
26
33
  missingInEnv: string[];
27
34
  missingInExample: string[];
35
+ emptyInEnv: string[];
28
36
  unusedInEnv: string[];
29
37
  unusedInExample: string[];
30
38
  secretExposures: SecretExposureWarning[];
39
+ exampleSecretLeaks: ExampleSecretLeak[];
31
40
  duplicateKeys: {
32
41
  env: string[];
33
42
  example: string[];
34
43
  };
35
44
  }
36
- interface AuditOptions {
37
- rootDir?: string;
45
+ interface EnvDriftConfig {
38
46
  envFile?: string;
39
47
  exampleFile?: string;
40
48
  ignore?: string[];
49
+ ignoreDirs?: string[];
50
+ publicPrefixes?: string[];
51
+ sensitiveKeywords?: string[];
52
+ }
53
+ interface AuditOptions extends EnvDriftConfig {
54
+ rootDir?: string;
41
55
  }
42
56
 
43
57
  declare const BUILTIN_ENV_VARS: Set<string>;
44
58
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
45
59
  declare const SENSITIVE_KEYWORDS: readonly ["SECRET", "PASSWORD", "PASSWD", "PRIVATE_KEY", "PRIVATE", "DATABASE_URL", "DB_URL", "DB_PASS", "JWT_SECRET", "AUTH_TOKEN", "ACCESS_KEY", "API_SECRET", "SERVICE_ROLE", "CREDENTIALS"];
60
+ /**
61
+ * Detects whether an `.env.example` value looks like a real committed secret
62
+ * rather than an empty or placeholder value.
63
+ */
64
+ declare function detectExampleSecretLeak(_name: string, value: string): string | null;
46
65
  /**
47
66
  * Detects whether an environment variable name combines a client-exposed prefix
48
67
  * with a sensitive keyword (e.g. `NEXT_PUBLIC_DB_PASSWORD`).
49
68
  */
50
- declare function detectSecretExposure(name: string): {
69
+ declare function detectSecretExposure(name: string, options?: {
70
+ publicPrefixes?: readonly string[];
71
+ sensitiveKeywords?: readonly string[];
72
+ }): {
51
73
  prefix: string;
52
74
  matchedKeyword: string;
53
75
  } | null;
@@ -56,12 +78,19 @@ declare function detectSecretExposure(name: string): {
56
78
  */
57
79
  declare function auditEnv(options?: AuditOptions): AuditResult;
58
80
 
81
+ /**
82
+ * Loads optional project configuration from `.envdriftrc.json` or the `"env-drift"`
83
+ * field in `package.json`.
84
+ */
85
+ declare function loadConfig(rootDir: string): EnvDriftConfig;
86
+
59
87
  /**
60
88
  * Parses the text contents of a .env file without external dependencies.
61
89
  */
62
90
  declare function parseEnvContent(content: string): {
63
91
  keys: string[];
64
92
  values: Record<string, string>;
93
+ lines: Record<string, number>;
65
94
  duplicates: string[];
66
95
  };
67
96
  /**
@@ -79,7 +108,8 @@ declare function syncEnvExample(examplePath: string, missingKeys: string[]): {
79
108
  declare const DEFAULT_IGNORE_DIRS: Set<string>;
80
109
  declare const DEFAULT_EXTENSIONS: Set<string>;
81
110
  /**
82
- * Extracts all `process.env` and `import.meta.env` references from a source string.
111
+ * Extracts all `process.env`, `import.meta.env`, `Bun.env`, and `Deno.env.get()`
112
+ * references from a source string.
83
113
  */
84
114
  declare function extractEnvReferences(content: string, filePath: string): EnvReference[];
85
115
  interface ScanOptions {
@@ -107,7 +137,8 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
107
137
  };
108
138
 
109
139
  /**
110
- * Returns true if the audit found blocking issues (missing vars or exposed public secrets).
140
+ * Returns true if the audit found blocking issues (missing vars, exposed public secrets,
141
+ * or real secrets committed in `.env.example`).
111
142
  * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
112
143
  * is skipped by default unless `requireEnvFile` is true.
113
144
  */
@@ -122,5 +153,14 @@ declare function formatAuditReport(result: AuditResult, options?: {
122
153
  exampleFile?: string;
123
154
  ci?: boolean;
124
155
  }): string;
156
+ /**
157
+ * Formats an AuditResult as GitHub Actions workflow commands (`::error` / `::warning`)
158
+ * so findings render inline on Pull Request diffs.
159
+ */
160
+ declare function formatGitHubAnnotations(result: AuditResult, options?: {
161
+ envFile?: string;
162
+ exampleFile?: string;
163
+ ci?: boolean;
164
+ }): string;
125
165
 
126
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvReference, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectSecretExposure, extractEnvReferences, formatAuditReport, generateEnvTypes, hasBlockingIssues, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
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 };
package/dist/index.d.ts CHANGED
@@ -2,13 +2,14 @@ interface EnvReference {
2
2
  name: string;
3
3
  file: string;
4
4
  line: number;
5
- source: "process.env" | "import.meta.env";
5
+ source: "process.env" | "import.meta.env" | "Bun.env" | "Deno.env";
6
6
  }
7
7
  interface ParsedEnvFile {
8
8
  filePath: string;
9
9
  exists: boolean;
10
10
  keys: string[];
11
11
  values: Record<string, string>;
12
+ lines: Record<string, number>;
12
13
  duplicates: string[];
13
14
  }
14
15
  interface SecretExposureWarning {
@@ -17,6 +18,12 @@ interface SecretExposureWarning {
17
18
  matchedKeyword: string;
18
19
  references: EnvReference[];
19
20
  }
21
+ interface ExampleSecretLeak {
22
+ name: string;
23
+ reason: string;
24
+ file: string;
25
+ line: number;
26
+ }
20
27
  interface AuditResult {
21
28
  rootDir: string;
22
29
  scannedFiles: number;
@@ -25,29 +32,44 @@ interface AuditResult {
25
32
  usedInCode: Record<string, EnvReference[]>;
26
33
  missingInEnv: string[];
27
34
  missingInExample: string[];
35
+ emptyInEnv: string[];
28
36
  unusedInEnv: string[];
29
37
  unusedInExample: string[];
30
38
  secretExposures: SecretExposureWarning[];
39
+ exampleSecretLeaks: ExampleSecretLeak[];
31
40
  duplicateKeys: {
32
41
  env: string[];
33
42
  example: string[];
34
43
  };
35
44
  }
36
- interface AuditOptions {
37
- rootDir?: string;
45
+ interface EnvDriftConfig {
38
46
  envFile?: string;
39
47
  exampleFile?: string;
40
48
  ignore?: string[];
49
+ ignoreDirs?: string[];
50
+ publicPrefixes?: string[];
51
+ sensitiveKeywords?: string[];
52
+ }
53
+ interface AuditOptions extends EnvDriftConfig {
54
+ rootDir?: string;
41
55
  }
42
56
 
43
57
  declare const BUILTIN_ENV_VARS: Set<string>;
44
58
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
45
59
  declare const SENSITIVE_KEYWORDS: readonly ["SECRET", "PASSWORD", "PASSWD", "PRIVATE_KEY", "PRIVATE", "DATABASE_URL", "DB_URL", "DB_PASS", "JWT_SECRET", "AUTH_TOKEN", "ACCESS_KEY", "API_SECRET", "SERVICE_ROLE", "CREDENTIALS"];
60
+ /**
61
+ * Detects whether an `.env.example` value looks like a real committed secret
62
+ * rather than an empty or placeholder value.
63
+ */
64
+ declare function detectExampleSecretLeak(_name: string, value: string): string | null;
46
65
  /**
47
66
  * Detects whether an environment variable name combines a client-exposed prefix
48
67
  * with a sensitive keyword (e.g. `NEXT_PUBLIC_DB_PASSWORD`).
49
68
  */
50
- declare function detectSecretExposure(name: string): {
69
+ declare function detectSecretExposure(name: string, options?: {
70
+ publicPrefixes?: readonly string[];
71
+ sensitiveKeywords?: readonly string[];
72
+ }): {
51
73
  prefix: string;
52
74
  matchedKeyword: string;
53
75
  } | null;
@@ -56,12 +78,19 @@ declare function detectSecretExposure(name: string): {
56
78
  */
57
79
  declare function auditEnv(options?: AuditOptions): AuditResult;
58
80
 
81
+ /**
82
+ * Loads optional project configuration from `.envdriftrc.json` or the `"env-drift"`
83
+ * field in `package.json`.
84
+ */
85
+ declare function loadConfig(rootDir: string): EnvDriftConfig;
86
+
59
87
  /**
60
88
  * Parses the text contents of a .env file without external dependencies.
61
89
  */
62
90
  declare function parseEnvContent(content: string): {
63
91
  keys: string[];
64
92
  values: Record<string, string>;
93
+ lines: Record<string, number>;
65
94
  duplicates: string[];
66
95
  };
67
96
  /**
@@ -79,7 +108,8 @@ declare function syncEnvExample(examplePath: string, missingKeys: string[]): {
79
108
  declare const DEFAULT_IGNORE_DIRS: Set<string>;
80
109
  declare const DEFAULT_EXTENSIONS: Set<string>;
81
110
  /**
82
- * Extracts all `process.env` and `import.meta.env` references from a source string.
111
+ * Extracts all `process.env`, `import.meta.env`, `Bun.env`, and `Deno.env.get()`
112
+ * references from a source string.
83
113
  */
84
114
  declare function extractEnvReferences(content: string, filePath: string): EnvReference[];
85
115
  interface ScanOptions {
@@ -107,7 +137,8 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
107
137
  };
108
138
 
109
139
  /**
110
- * Returns true if the audit found blocking issues (missing vars or exposed public secrets).
140
+ * Returns true if the audit found blocking issues (missing vars, exposed public secrets,
141
+ * or real secrets committed in `.env.example`).
111
142
  * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
112
143
  * is skipped by default unless `requireEnvFile` is true.
113
144
  */
@@ -122,5 +153,14 @@ declare function formatAuditReport(result: AuditResult, options?: {
122
153
  exampleFile?: string;
123
154
  ci?: boolean;
124
155
  }): string;
156
+ /**
157
+ * Formats an AuditResult as GitHub Actions workflow commands (`::error` / `::warning`)
158
+ * so findings render inline on Pull Request diffs.
159
+ */
160
+ declare function formatGitHubAnnotations(result: AuditResult, options?: {
161
+ envFile?: string;
162
+ exampleFile?: string;
163
+ ci?: boolean;
164
+ }): string;
125
165
 
126
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvReference, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectSecretExposure, extractEnvReferences, formatAuditReport, generateEnvTypes, hasBlockingIssues, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
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 };