node-env-resolver 6.5.1 → 6.6.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.
Files changed (92) hide show
  1. package/README.md +708 -400
  2. package/dist/builder.cjs +1 -1
  3. package/dist/builder.d.cts +1 -1
  4. package/dist/builder.d.ts +1 -1
  5. package/dist/builder.js +1 -1
  6. package/dist/chunk-3EWCMDFP.js +9 -0
  7. package/dist/chunk-BFLXBLZ3.cjs +1 -0
  8. package/dist/chunk-CDXO2XX3.cjs +2 -0
  9. package/dist/chunk-CTJYBBOB.js +2 -0
  10. package/dist/chunk-DIJNUFGZ.cjs +15 -0
  11. package/dist/chunk-DYFRO3NM.cjs +9 -0
  12. package/dist/chunk-K4NIC5T3.js +9 -0
  13. package/dist/chunk-WVMDTD6J.cjs +9 -0
  14. package/dist/chunk-ZMRT37K3.js +1 -0
  15. package/dist/chunk-ZSM2NDX5.js +15 -0
  16. package/dist/cli/bin.cjs +74 -0
  17. package/dist/cli/bin.js +74 -0
  18. package/dist/cli.d.cts +1 -1
  19. package/dist/cli.d.ts +1 -1
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.cts +59 -3
  22. package/dist/index.d.ts +59 -3
  23. package/dist/index.js +1 -1
  24. package/dist/provider-kit.cjs +2 -0
  25. package/dist/provider-kit.d.cts +50 -0
  26. package/dist/provider-kit.d.ts +50 -0
  27. package/dist/provider-kit.js +2 -0
  28. package/dist/resolver.cjs +1 -1
  29. package/dist/resolver.d.cts +1 -1
  30. package/dist/resolver.d.ts +1 -1
  31. package/dist/resolver.js +1 -1
  32. package/dist/resolvers.cjs +1 -1
  33. package/dist/resolvers.d.cts +2 -27
  34. package/dist/resolvers.d.ts +2 -27
  35. package/dist/resolvers.js +1 -1
  36. package/dist/runtime/index.cjs +1 -0
  37. package/dist/runtime/index.d.cts +161 -0
  38. package/dist/runtime/index.d.ts +161 -0
  39. package/dist/runtime/index.js +1 -0
  40. package/dist/types--RcOnfdl.d.cts +284 -0
  41. package/dist/types--RcOnfdl.d.ts +284 -0
  42. package/dist/types.cjs +1 -1
  43. package/dist/types.d.cts +1 -129
  44. package/dist/types.d.ts +1 -129
  45. package/dist/types.js +1 -1
  46. package/dist/utils.cjs +1 -1
  47. package/dist/utils.d.cts +56 -12
  48. package/dist/utils.d.ts +56 -12
  49. package/dist/utils.js +1 -1
  50. package/dist/valibot.cjs +1 -1
  51. package/dist/valibot.d.cts +12 -25
  52. package/dist/valibot.d.ts +12 -25
  53. package/dist/valibot.js +1 -1
  54. package/dist/validators.cjs +2 -2
  55. package/dist/validators.d.cts +25 -48
  56. package/dist/validators.d.ts +25 -48
  57. package/dist/validators.js +2 -2
  58. package/dist/web.cjs +5 -5
  59. package/dist/web.d.cts +3 -1
  60. package/dist/web.d.ts +3 -1
  61. package/dist/web.js +5 -5
  62. package/dist/zod.cjs +1 -1
  63. package/dist/zod.d.cts +12 -25
  64. package/dist/zod.d.ts +12 -25
  65. package/dist/zod.js +1 -1
  66. package/package.json +26 -31
  67. package/binding.gyp +0 -9
  68. package/dist/chunk-2IQQVAXA.cjs +0 -9
  69. package/dist/chunk-46CBATKM.js +0 -1
  70. package/dist/chunk-C34FGZOG.js +0 -9
  71. package/dist/chunk-FNF55TN4.cjs +0 -1
  72. package/dist/chunk-G36OESVW.cjs +0 -1
  73. package/dist/chunk-I5UKYTX6.js +0 -1
  74. package/dist/chunk-MFFH2ZXS.js +0 -17
  75. package/dist/chunk-QCKMQEJP.cjs +0 -17
  76. package/dist/chunk-S7AB6UX7.cjs +0 -9
  77. package/dist/chunk-TGIYWWDY.js +0 -9
  78. package/dist/chunk-VUUPIWFJ.js +0 -9
  79. package/dist/chunk-ZDRU3RSU.cjs +0 -9
  80. package/dist/cli-main.cjs +0 -4
  81. package/dist/cli-main.js +0 -4
  82. package/dist/redaction.cjs +0 -1
  83. package/dist/redaction.d.cts +0 -54
  84. package/dist/redaction.d.ts +0 -54
  85. package/dist/redaction.js +0 -1
  86. package/dist/typegen.cjs +0 -1
  87. package/dist/typegen.d.cts +0 -52
  88. package/dist/typegen.d.ts +0 -52
  89. package/dist/typegen.js +0 -1
  90. package/index.js +0 -1
  91. /package/dist/{cli-main.d.cts → cli/bin.d.cts} +0 -0
  92. /package/dist/{cli-main.d.ts → cli/bin.d.ts} +0 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Redaction utilities for protecting secrets in logs and responses
3
+ */
4
+ interface RedactorOptions {
5
+ sensitiveKeys?: string[];
6
+ sensitivePatterns?: RegExp[];
7
+ customPatterns?: RegExp[];
8
+ fallbackValue?: string;
9
+ }
10
+ declare function maskValue(value: string): string;
11
+ declare function createRedactor(sensitiveValues: Map<string, string>, options?: RedactorOptions): {
12
+ redactString: (str: string) => string;
13
+ redactObject: (obj: unknown, depth?: number, seen?: WeakSet<WeakKey>) => unknown;
14
+ maskValue: typeof maskValue;
15
+ createFingerprint: (value: string) => string;
16
+ shouldRedactKey: (key: string) => boolean;
17
+ };
18
+ declare function extractSensitiveValues(config: Record<string, unknown>, options?: {
19
+ sensitiveKeys?: string[];
20
+ }): Map<string, string>;
21
+
22
+ /**
23
+ * Patch global console methods to redact sensitive values
24
+ *
25
+ * Prevents accidental logging of secrets by intercepting console methods
26
+ * and redacting values matching sensitive patterns.
27
+ */
28
+
29
+ interface ConsolePatchOptions extends RedactorOptions {
30
+ enabled?: boolean;
31
+ methods?: ('log' | 'debug' | 'info' | 'warn' | 'error' | 'trace')[];
32
+ redactStrings?: boolean;
33
+ redactObjects?: boolean;
34
+ }
35
+ declare function patchGlobalConsole(config: Record<string, unknown>, options?: ConsolePatchOptions): () => void;
36
+ declare function createConsoleRedactor(config: Record<string, unknown>, options?: ConsolePatchOptions): {
37
+ redactString: (str: string) => string;
38
+ redactObject: (obj: unknown, depth?: number, seen?: WeakSet<WeakKey>) => unknown;
39
+ maskValue: (value: string) => string;
40
+ createFingerprint: (value: string) => string;
41
+ shouldRedactKey: (key: string) => boolean;
42
+ redact: (...args: unknown[]) => unknown[];
43
+ };
44
+
45
+ /**
46
+ * Response protection utilities for preventing secret leakage in HTTP responses
47
+ *
48
+ * Provides middleware for Node.js (Express/Connect/Hono) and a utility for
49
+ * Edge runtimes (Cloudflare Workers, Vercel Edge, etc.).
50
+ *
51
+ * @example Node.js / Express
52
+ * ```ts
53
+ * import express from 'express';
54
+ * import { createResponseMiddleware } from 'node-env-resolver/runtime';
55
+ *
56
+ * const app = express();
57
+ * app.use(createResponseMiddleware(config, { mode: 'throw' }));
58
+ * ```
59
+ *
60
+ * @example Edge runtime
61
+ * ```ts
62
+ * import { wrapFetchResponse } from 'node-env-resolver/runtime';
63
+ *
64
+ * export default {
65
+ * async fetch(req, env) {
66
+ * const response = await handler(req);
67
+ * return wrapFetchResponse(response, config, { mode: 'redact' });
68
+ * }
69
+ * }
70
+ * ```
71
+ */
72
+
73
+ interface ResponsePatchOptions extends RedactorOptions {
74
+ mode?: 'throw' | 'redact' | 'warn';
75
+ ignoreContentTypes?: string[];
76
+ maxBodySize?: number;
77
+ }
78
+ /**
79
+ * Express / Connect / Hono middleware that scans outgoing response bodies
80
+ * for sensitive values and redacts, warns, or throws depending on `mode`.
81
+ *
82
+ * Default mode: 'warn' in production, 'throw' in development.
83
+ */
84
+ declare function createResponseMiddleware(config: Record<string, unknown>, options?: ResponsePatchOptions): (_req: unknown, res: {
85
+ end: (...args: unknown[]) => unknown;
86
+ write?: (...args: unknown[]) => unknown;
87
+ getHeader?: (name: string) => string | number | string[] | undefined;
88
+ }, next: () => void) => void;
89
+ /**
90
+ * Scan and optionally redact an Edge runtime `Response` object.
91
+ * Returns a new Response (original is consumed). Safe to use in
92
+ * Cloudflare Workers, Vercel Edge Functions, and Deno Deploy.
93
+ */
94
+ declare function wrapFetchResponse(response: Response, config: Record<string, unknown>, options?: ResponsePatchOptions): Promise<Response>;
95
+ /**
96
+ * Utility to imperatively scan a response body for secrets.
97
+ * Useful when you need to check manually rather than via middleware.
98
+ */
99
+ declare function scanBodyForSecrets(body: string | Buffer | unknown, config: Record<string, unknown>, options?: ResponsePatchOptions): {
100
+ safe: boolean;
101
+ redacted?: string;
102
+ };
103
+
104
+ /**
105
+ * Runtime protection utilities for preventing secret leaks
106
+ *
107
+ * Quick start — protect everything with one call:
108
+ * ```typescript
109
+ * import { protect } from 'node-env-resolver/runtime';
110
+ *
111
+ * const unprotect = protect(config);
112
+ * // console methods now redact secrets automatically
113
+ *
114
+ * // Optional: add response scanning in your server/edge handler
115
+ * app.use(createResponseMiddleware(config)); // Express / Hono
116
+ * return wrapFetchResponse(response, config); // Edge runtime
117
+ * ```
118
+ *
119
+ * Or compose individual primitives for fine-grained control:
120
+ * ```typescript
121
+ * import {
122
+ * patchGlobalConsole,
123
+ * createResponseMiddleware,
124
+ * wrapFetchResponse,
125
+ * } from 'node-env-resolver/runtime';
126
+ *
127
+ * const unpatch = patchGlobalConsole(config, { methods: ['error', 'warn'] });
128
+ * app.use(createResponseMiddleware(config, { mode: 'redact' }));
129
+ * ```
130
+ */
131
+
132
+ interface ProtectOptions {
133
+ /** Options forwarded to patchGlobalConsole. Pass false to disable console patching. */
134
+ console?: ConsolePatchOptions | false;
135
+ /** Options forwarded to createResponseMiddleware. Response protection must still be
136
+ * wired up separately — this just pre-configures the options. */
137
+ responses?: ResponsePatchOptions;
138
+ }
139
+ /**
140
+ * Enable runtime secret protection in one call.
141
+ *
142
+ * Patches global console methods to redact sensitive values.
143
+ * Returns an `unpatch` function that restores the originals.
144
+ *
145
+ * Response protection is intentionally explicit — use `createResponseMiddleware`
146
+ * or `wrapFetchResponse` to add it to your server/edge handler.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * import { protect } from 'node-env-resolver/runtime';
151
+ *
152
+ * const unprotect = protect(config);
153
+ * // console.log('key:', config.API_KEY) → console.log('key:', '[REDACTED]')
154
+ *
155
+ * // Restore originals when done (e.g. in tests)
156
+ * unprotect();
157
+ * ```
158
+ */
159
+ declare function protect(config: Record<string, unknown>, options?: ProtectOptions): () => void;
160
+
161
+ export { type ConsolePatchOptions, type ProtectOptions, type RedactorOptions, type ResponsePatchOptions, createConsoleRedactor, createRedactor, createResponseMiddleware, extractSensitiveValues, patchGlobalConsole, protect, scanBodyForSecrets, wrapFetchResponse };
@@ -0,0 +1 @@
1
+ import'../chunk-I7AUKTXE.js';var P=[/password/i,/secret/i,/token/i,/key/i,/credential/i,/auth/i,/api[_-]?key/i,/access[_-]?token/i,/refresh[_-]?token/i,/private[_-]?key/i,/database[_-]?url/i,/db[_-]?url/i,/connection[_-]?string/i,/conn[_-]?string/i,/dsn/i,/bearer/i],x=[/sk_live_[a-zA-Z0-9]{24,}/g,/sk_test_[a-zA-Z0-9]{24,}/g,/pk_live_[a-zA-Z0-9]{24,}/g,/pk_test_[a-zA-Z0-9]{24,}/g,/xox[baprs]-[a-zA-Z0-9-]+/g,/ghp_[a-zA-Z0-9]{36}/g,/gho_[a-zA-Z0-9]{36}/g,/ghu_[a-zA-Z0-9]{36}/g,/ghs_[a-zA-Z0-9]{36}/g,/ghr_[a-zA-Z0-9]{36}/g,/eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*/g,/postgres:\/\/[^@]+:[^@]+@/g,/mysql:\/\/[^@]+:[^@]+@/g,/mongodb(\+srv)?:\/\/[^@]+:[^@]+@/g,/redis:\/\/[^:]+:[^@]+@/g,/rediss:\/\/[^:]+:[^@]+@/g];function S(e){let o=e.length;return o<=4?"****":o<=8?`${e[0]}****${e[o-1]}`:o<=16?`${e.slice(0,2)}****${e.slice(-2)}`:`${e.slice(0,4)}...${e.slice(-4)}`}function h(e,o={}){let{sensitivePatterns:i=P,customPatterns:a=[],fallbackValue:u="[REDACTED]"}=o,c=[...x,...a];function p(t){return i.some(n=>n.test(t))}function f(t){let n=t;for(let[,r]of e)if(typeof r=="string"&&r.length>0){let l=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(l,"g"),u);}for(let r of c)n=n.replace(r,u);return n}function g(t,n=0,r=new WeakSet){if(n>10||t==null)return t;if(typeof t=="string")return f(t);if(typeof t!="object")return t;if(r.has(t))return "[Circular]";if(r.add(t),Array.isArray(t))return t.map(s=>g(s,n+1,r));if(t instanceof Error){let s=new Error(f(t.message));return s.name=t.name,s.stack=t.stack?f(t.stack):void 0,s}if(t instanceof Date||t instanceof RegExp)return t;if(t instanceof Map)return new Map(Array.from(t.entries()).map(([s,d])=>[g(s,n+1,r),g(d,n+1,r)]));if(t instanceof Set)return new Set(Array.from(t.values()).map(s=>g(s,n+1,r)));let l={};for(let[s,d]of Object.entries(t))p(s)?l[s]=typeof d=="string"?u:"[REDACTED]":typeof d=="string"?l[s]=f(d):l[s]=g(d,n+1,r);return l}return {redactString:f,redactObject:g,maskValue:S,createFingerprint:t=>{let n=0;for(let r=0;r<t.length;r++){let l=t.charCodeAt(r);n=(n<<5)-n+l,n=n&n;}return `sha256:${Math.abs(n).toString(16).slice(0,8)}`},shouldRedactKey:p}}function y(e,o={}){let i=new Map,a=o.sensitiveKeys?.map(u=>new RegExp(u,"i"))??P;for(let[u,c]of Object.entries(e))typeof c=="string"&&a.some(p=>p.test(u))&&i.set(u,c);return i}var m="__nodeEnvResolverPatched";function _(e,o={}){let{enabled:i=true,methods:a=["log","debug","info","warn","error","trace"],redactStrings:u=true,redactObjects:c=true,...p}=o;if(!i)return ()=>{};let f=console;if(f[m])return ()=>{};let g=y(e),t=h(g,p),n={};for(let r of a)if(typeof console[r]=="function"){n[r]=console[r].bind(console);let l=n[r];console[r]=(...s)=>{let d=s.map(w=>typeof w=="string"&&u?t.redactString(w):typeof w=="object"&&c&&w!==null?t.redactObject(w):w);l(...d);};}return Object.defineProperty(f,m,{value:true,writable:true,enumerable:false,configurable:true}),()=>{for(let r of a)if(n[r]){let s=n[r].bind(console);console[r]=s;}try{delete f[m];}catch{}f[m]=false;}}function E(e,o={}){let i=y(e),a=h(i,o);return {redact:(...u)=>u.map(c=>typeof c=="string"?a.redactString(c):typeof c=="object"&&c!==null?a.redactObject(c):c),...a}}var O=["image/","video/","audio/","application/octet-stream","application/pdf"];function v(e,o){let i=e.toLowerCase();return !o.some(a=>i.includes(a.toLowerCase()))}function T(e,o,i){if(o===e)return e;if(i==="throw")throw new Error('Secret leak detected in HTTP response body. A sensitive value was found before it could be sent. Use mode: "redact" to automatically scrub, or mode: "warn" to log and continue.');return i==="warn"?(console.warn('[node-env-resolver] Potential secret leak detected in HTTP response. Set mode: "redact" to scrub automatically.'),e):o}function A(e,o={}){let{mode:i=process.env.NODE_ENV==="production"?"warn":"throw",ignoreContentTypes:a=O,maxBodySize:u=1024*1024,...c}=o,p=y(e),f=h(p,c);return function(t,n,r){let l=n.end.bind(n);n.end=function(...s){let d=s[0];if(d!=null&&(typeof d=="string"||Buffer.isBuffer(d))){let w=String(n.getHeader?.("content-type")??"");if(v(w,a)){let k=typeof d=="string"?d:d.toString("utf8");if(Buffer.byteLength(k)<=u)try{let R=f.redactString(k);s[0]=T(k,R,i);}catch(R){if(i==="throw")throw R;console.error("[node-env-resolver] Response scan error:",R);}}}return l(...s)},r();}}async function C(e,o,i={}){let{mode:a="warn",ignoreContentTypes:u=O,maxBodySize:c=1024*1024,...p}=i,f=e.headers.get("content-type")??"";if(!v(f,u))return e;let t=await e.clone().arrayBuffer();if(t.byteLength>c)return e;let n=new TextDecoder().decode(t),r=y(o),s=h(r,p).redactString(n);if(s===n)return e;if(a==="throw")throw new Error('Secret leak detected in HTTP response. Use mode: "redact" to scrub automatically.');return a==="warn"?(console.warn("[node-env-resolver] Potential secret leak detected in HTTP response."),e):new Response(s,{status:e.status,statusText:e.statusText,headers:e.headers})}function b(e,o,i={}){if(typeof e!="string"&&!Buffer.isBuffer(e))return {safe:true};let a=y(o),u=h(a,i),c=typeof e=="string"?e:e.toString("utf8"),p=u.redactString(c);return p!==c?{safe:false,redacted:p}:{safe:true}}function F(e,o={}){return o.console===false?()=>{}:_(e,o.console)}export{E as createConsoleRedactor,h as createRedactor,A as createResponseMiddleware,y as extractSensitiveValues,_ as patchGlobalConsole,F as protect,b as scanBodyForSecrets,C as wrapFetchResponse};
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Debug view for environment variable resolution
3
+ *
4
+ * Provides a safe, operator-friendly inspection surface that:
5
+ * - Shows provenance/source without exposing values
6
+ * - Supports masked preview, fingerprint, or length-only modes
7
+ * - Marks sensitive values for special handling
8
+ * - Tracks consumed vs available
9
+ */
10
+
11
+ declare const DEFAULT_SENSITIVE_PATTERNS: readonly RegExp[];
12
+ /**
13
+ * Value display modes - from most to least safe
14
+ */
15
+ type DebugValueMode = 'none' | 'length' | 'fingerprint' | 'masked';
16
+ /**
17
+ * Security snapshot entry - for incident response
18
+ */
19
+ interface SecuritySnapshotEntry {
20
+ key: string;
21
+ resolved: boolean;
22
+ consumed: boolean;
23
+ source: string | null;
24
+ reference?: string | null;
25
+ resolvedVia?: string | null;
26
+ sensitive: boolean;
27
+ length: number;
28
+ fingerprint: string | null;
29
+ preview: string | null;
30
+ timestamp?: number;
31
+ }
32
+ /**
33
+ * Visibility levels for different use cases
34
+ *
35
+ * - provenance: key, resolved, source, sensitive (safe default for production)
36
+ * - fingerprint: adds fingerprint (best for incident response)
37
+ * - masked: adds preview (only with explicit opt-in)
38
+ */
39
+ type VisibilityLevel = 'provenance' | 'fingerprint' | 'masked';
40
+ /**
41
+ * Security snapshot options
42
+ */
43
+ interface SecuritySnapshotOptions {
44
+ /** Visibility level (default: 'provenance') */
45
+ visibility?: VisibilityLevel;
46
+ /** Include source in output (default: true) */
47
+ includeSource?: boolean;
48
+ /** Include consumed vs available (default: true) */
49
+ includeConsumed?: boolean;
50
+ /** Include timestamp (default: false) */
51
+ includeTimestamp?: boolean;
52
+ /** Custom sensitive key patterns */
53
+ sensitiveKeys?: readonly string[];
54
+ /** Custom sensitive key matcher */
55
+ isSensitive?: (key: string, value: string) => boolean;
56
+ }
57
+ /**
58
+ * Individual debug entry for a single env var
59
+ */
60
+ interface DebugEntry {
61
+ key: string;
62
+ resolved: boolean;
63
+ source: string | null;
64
+ reference: string | null;
65
+ resolvedVia: string | null;
66
+ sensitive: boolean;
67
+ length: number;
68
+ fingerprint: string | null;
69
+ preview: string | null;
70
+ }
71
+ /**
72
+ * Debug view options
73
+ */
74
+ interface DebugOptions {
75
+ /** Enable debug view generation (default: false) */
76
+ enabled?: boolean;
77
+ /** Value display mode */
78
+ valueMode?: DebugValueMode;
79
+ /** Include source in debug output (default: true) */
80
+ includeSource?: boolean;
81
+ /** Custom sensitive key patterns */
82
+ sensitiveKeys?: readonly string[];
83
+ /** Custom sensitive key matcher */
84
+ isSensitive?: (key: string, value: string) => boolean;
85
+ /** Callback called for each debug entry as it's resolved (default: none) */
86
+ onDebugEntry?: (entry: DebugEntry) => void;
87
+ }
88
+ /**
89
+ * Generate debug view for resolved config
90
+ */
91
+ declare function createDebugView(resolved: Record<string, unknown>, provenance: Record<string, Provenance>, options: DebugOptions): DebugEntry[];
92
+ /**
93
+ * Default debug options - safe defaults
94
+ */
95
+ declare const DEFAULT_DEBUG_OPTIONS: DebugOptions;
96
+ /**
97
+ * Generate security snapshot for incident response
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const snapshot = createSecuritySnapshot(
102
+ * resolvedConfig,
103
+ * provenanceMap,
104
+ * consumedMap,
105
+ * { visibility: 'fingerprint', includeConsumed: true }
106
+ * );
107
+ *
108
+ * // Output:
109
+ * // [
110
+ * // { key: "PORT", resolved: true, consumed: true, source: "processEnv", sensitive: false, length: 4, preview: "3000" },
111
+ * // { key: "STRIPE_SECRET_KEY", resolved: true, consumed: true, source: "awsSecrets", sensitive: true, fingerprint: "sha256:ab12cd34", length: 51 }
112
+ * // ]
113
+ * ```
114
+ */
115
+ declare function createSecuritySnapshot(resolved: Record<string, unknown>, provenance: Record<string, Provenance>, consumed: Record<string, boolean>, options: SecuritySnapshotOptions): SecuritySnapshotEntry[];
116
+ /**
117
+ * Generate a redacted object for human-readable debugging
118
+ *
119
+ * Non-sensitive values: shown as-is or masked
120
+ * Sensitive values: [sha256:xxxx] or [redacted]
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const redacted = createRedactedObject(
125
+ * resolvedConfig,
126
+ * provenanceMap,
127
+ * { valueMode: 'fingerprint' }
128
+ * );
129
+ *
130
+ * // Output:
131
+ * // { PORT: "3000", STRIPE_SECRET_KEY: "[sha256:ab12cd34]", DATABASE_URL: "[sha256:94e1b7aa]" }
132
+ * ```
133
+ */
134
+ declare function createRedactedObject(resolved: Record<string, unknown>, provenance: Record<string, Provenance>, options: DebugOptions): Record<string, string>;
135
+
136
+ type Validator<T> = ((value: string) => T) & {
137
+ optional?: boolean;
138
+ default?: T;
139
+ };
140
+ type SimpleEnvSchema = Record<string, Validator<unknown> | string | number | boolean | readonly string[]>;
141
+ type InferSimpleValue<V> = V extends Validator<infer R> ? V extends {
142
+ optional: true;
143
+ } ? R | undefined : R : V extends number ? number : V extends boolean ? boolean : V extends readonly (infer U)[] ? V extends {
144
+ __optional: true;
145
+ } ? U | undefined : U : V extends string ? string : never;
146
+ type InferSimpleSchema<T extends SimpleEnvSchema> = {
147
+ [K in keyof T]: InferSimpleValue<T[K]>;
148
+ };
149
+ type InferNestedSchema<T extends SimpleEnvSchema> = InferSimpleSchema<T>;
150
+ type InferResolveResult<T extends SimpleEnvSchema, O extends ResolveOptions | undefined> = O extends {
151
+ nestedDelimiter: string;
152
+ } ? InferNestedSchema<T> : InferSimpleSchema<T>;
153
+ interface SyncResolver {
154
+ loadSync(): Record<string, string>;
155
+ load?(): Promise<Record<string, string>>;
156
+ name?: string;
157
+ metadata?: Record<string, unknown>;
158
+ }
159
+ interface AsyncResolver {
160
+ load(): Promise<Record<string, string>>;
161
+ loadSync?(): Record<string, string>;
162
+ name?: string;
163
+ metadata?: Record<string, unknown>;
164
+ }
165
+ type Resolver = SyncResolver | AsyncResolver;
166
+ interface ReferenceResolution {
167
+ value: string;
168
+ resolvedVia?: string;
169
+ metadata?: Record<string, unknown>;
170
+ }
171
+ interface ReferenceContext {
172
+ key: string;
173
+ source: string | null;
174
+ reference: string;
175
+ }
176
+ interface ReferenceHandler {
177
+ name?: string;
178
+ resolve(reference: string, context: ReferenceContext): string | ReferenceResolution | Promise<string | ReferenceResolution>;
179
+ resolveSync?(reference: string, context: ReferenceContext): string | ReferenceResolution;
180
+ }
181
+ interface ReferenceOptions {
182
+ handlers: Record<string, ReferenceHandler>;
183
+ onUnresolved?: 'error' | 'ignore';
184
+ }
185
+ declare const isSyncResolver: (resolver: Resolver) => resolver is SyncResolver;
186
+ declare const isAsyncOnlyResolver: (resolver: Resolver) => resolver is AsyncResolver;
187
+ interface ResolveOptions {
188
+ priority?: 'first' | 'last';
189
+ nestedDelimiter?: string;
190
+ validateDefaults?: boolean;
191
+ secretsDir?: string;
192
+ arraySeparator?: string;
193
+ interpolate?: boolean;
194
+ strict?: boolean;
195
+ policies?: Record<string, unknown>;
196
+ enableAudit?: boolean;
197
+ /**
198
+ * Prevent writing resolved values back into process.env.
199
+ * Default: true (secure-by-default)
200
+ *
201
+ * Set to false only if you explicitly need legacy write-back behavior.
202
+ */
203
+ preventProcessEnvWrite?: boolean;
204
+ /** Debug view options for safe inspection */
205
+ debug?: DebugOptions;
206
+ /** Optional secret/reference dereferencing */
207
+ references?: ReferenceOptions;
208
+ }
209
+ type SafeResolveResultType<T> = {
210
+ success: true;
211
+ data: T;
212
+ } | {
213
+ success: false;
214
+ error: string;
215
+ details?: unknown;
216
+ };
217
+ type ExtractSchema<T> = T extends readonly [unknown, infer S] ? S : never;
218
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
219
+ type ExtractSchemasUnion<T> = T extends readonly (infer E)[] ? E extends readonly [unknown, infer S] ? S extends SimpleEnvSchema ? S : never : never : never;
220
+ type MergedSchema<T> = UnionToIntersection<ExtractSchemasUnion<T>>;
221
+ type InferMergedSchemaResult<T extends readonly [unknown, SimpleEnvSchema][]> = MergedSchema<T> extends SimpleEnvSchema ? {
222
+ [K in keyof MergedSchema<T>]: InferSimpleValue<MergedSchema<T>[K]>;
223
+ } : Record<string, unknown>;
224
+ type InferMergedSchema<T extends readonly [unknown, SimpleEnvSchema][]> = T extends readonly [unknown, infer S1, ...infer Rest] ? Rest extends readonly [unknown, SimpleEnvSchema][] ? S1 & InferMergedSchema<Rest> : S1 : T extends readonly [unknown, infer S] ? S : Record<string, never>;
225
+
226
+ interface ResolveConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
227
+ schema?: T;
228
+ resolvers?: readonly [SyncResolver, SimpleEnvSchema][];
229
+ options?: Partial<ResolveOptions>;
230
+ references?: ReferenceOptions;
231
+ }
232
+ interface ResolveAsyncConfig<T extends SimpleEnvSchema = SimpleEnvSchema> {
233
+ schema?: T;
234
+ resolvers?: readonly [Resolver, SimpleEnvSchema][];
235
+ options?: Partial<ResolveOptions>;
236
+ references?: ReferenceOptions;
237
+ }
238
+ interface ResolveConfigWithSchema<T extends SimpleEnvSchema> {
239
+ schema: T;
240
+ options?: Partial<ResolveOptions>;
241
+ references?: ReferenceOptions;
242
+ }
243
+ interface ResolveConfigWithResolvers<T extends readonly [SyncResolver, SimpleEnvSchema][]> {
244
+ resolvers: T;
245
+ options?: Partial<ResolveOptions>;
246
+ references?: ReferenceOptions;
247
+ }
248
+ interface ResolveAsyncConfigWithSchema<T extends SimpleEnvSchema> {
249
+ schema: T;
250
+ options?: Partial<ResolveOptions>;
251
+ references?: ReferenceOptions;
252
+ }
253
+ interface ResolveAsyncConfigWithResolvers<T extends readonly [Resolver, SimpleEnvSchema][]> {
254
+ resolvers: T;
255
+ options?: Partial<ResolveOptions>;
256
+ references?: ReferenceOptions;
257
+ }
258
+ type Provenance = {
259
+ source: string;
260
+ timestamp: number;
261
+ metadata?: Record<string, unknown>;
262
+ cached?: boolean;
263
+ reference?: string;
264
+ resolvedVia?: string;
265
+ };
266
+ type PolicyOptions = {
267
+ allowDotenvInProduction?: boolean;
268
+ requireSecretsForSensitive?: boolean;
269
+ blockInsecureProtocols?: boolean;
270
+ enforceAllowedSources?: Record<string, string[]>;
271
+ };
272
+ type SimpleEnvValue = Validator<unknown> | string | number | boolean | readonly string[];
273
+ type EnvSchema = Record<string, unknown>;
274
+ interface EnvDefinition {
275
+ type?: string;
276
+ validator?: (value: string, key?: string) => unknown;
277
+ default?: unknown;
278
+ optional?: boolean;
279
+ secretsDir?: string;
280
+ }
281
+ type InferType = unknown;
282
+ type InferSchema = unknown;
283
+
284
+ export { type AsyncResolver as A, createSecuritySnapshot as B, createRedactedObject as C, type DebugValueMode as D, type EnvSchema as E, DEFAULT_DEBUG_OPTIONS as F, DEFAULT_SENSITIVE_PATTERNS as G, type InferMergedSchema as H, type InferSimpleSchema as I, type ExtractSchema as J, type InferNestedSchema as K, type SafeResolveResultType as L, type MergedSchema as M, type ResolveConfigWithResolvers as N, type ResolveAsyncConfigWithResolvers as O, type PolicyOptions as P, type ResolveOptions as R, type SimpleEnvSchema as S, type UnionToIntersection as U, type Validator as V, type Resolver as a, type ReferenceOptions as b, type EnvDefinition as c, type SyncResolver as d, type ReferenceHandler as e, type ResolveAsyncConfig as f, type InferSimpleValue as g, type ResolveAsyncConfigWithSchema as h, type InferMergedSchemaResult as i, type ResolveConfigWithSchema as j, type ResolveConfig as k, type ReferenceContext as l, type ReferenceResolution as m, type Provenance as n, type SimpleEnvValue as o, type InferType as p, type InferSchema as q, type InferResolveResult as r, isSyncResolver as s, isAsyncOnlyResolver as t, type DebugOptions as u, type DebugEntry as v, type VisibilityLevel as w, type SecuritySnapshotOptions as x, type SecuritySnapshotEntry as y, createDebugView as z };