node-env-resolver 6.5.1 → 6.5.2
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 +708 -400
- package/dist/builder.cjs +1 -1
- package/dist/builder.d.cts +1 -1
- package/dist/builder.d.ts +1 -1
- package/dist/builder.js +1 -1
- package/dist/chunk-3EWCMDFP.js +9 -0
- package/dist/chunk-BFLXBLZ3.cjs +1 -0
- package/dist/chunk-CDXO2XX3.cjs +2 -0
- package/dist/chunk-CTJYBBOB.js +2 -0
- package/dist/chunk-DIJNUFGZ.cjs +15 -0
- package/dist/chunk-DYFRO3NM.cjs +9 -0
- package/dist/chunk-K4NIC5T3.js +9 -0
- package/dist/chunk-WVMDTD6J.cjs +9 -0
- package/dist/chunk-ZMRT37K3.js +1 -0
- package/dist/chunk-ZSM2NDX5.js +15 -0
- package/dist/cli/bin.cjs +74 -0
- package/dist/cli/bin.js +74 -0
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.d.cts +1 -1
- package/dist/resolver.d.ts +1 -1
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +2 -27
- package/dist/resolvers.d.ts +2 -27
- package/dist/resolvers.js +1 -1
- package/dist/runtime/index.cjs +1 -0
- package/dist/runtime/index.d.cts +161 -0
- package/dist/runtime/index.d.ts +161 -0
- package/dist/runtime/index.js +1 -0
- package/dist/types--RcOnfdl.d.cts +284 -0
- package/dist/types--RcOnfdl.d.ts +284 -0
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +1 -129
- package/dist/types.d.ts +1 -129
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +56 -12
- package/dist/utils.d.ts +56 -12
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.cts +12 -25
- package/dist/valibot.d.ts +12 -25
- package/dist/valibot.js +1 -1
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.cts +25 -48
- package/dist/validators.d.ts +25 -48
- package/dist/validators.js +2 -2
- package/dist/web.cjs +5 -5
- package/dist/web.d.cts +3 -1
- package/dist/web.d.ts +3 -1
- package/dist/web.js +5 -5
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.cts +12 -25
- package/dist/zod.d.ts +12 -25
- package/dist/zod.js +1 -1
- package/package.json +28 -40
- package/binding.gyp +0 -9
- package/dist/chunk-2IQQVAXA.cjs +0 -9
- package/dist/chunk-46CBATKM.js +0 -1
- package/dist/chunk-C34FGZOG.js +0 -9
- package/dist/chunk-FNF55TN4.cjs +0 -1
- package/dist/chunk-G36OESVW.cjs +0 -1
- package/dist/chunk-I5UKYTX6.js +0 -1
- package/dist/chunk-MFFH2ZXS.js +0 -17
- package/dist/chunk-QCKMQEJP.cjs +0 -17
- package/dist/chunk-S7AB6UX7.cjs +0 -9
- package/dist/chunk-TGIYWWDY.js +0 -9
- package/dist/chunk-VUUPIWFJ.js +0 -9
- package/dist/chunk-ZDRU3RSU.cjs +0 -9
- package/dist/cli-main.cjs +0 -4
- package/dist/cli-main.js +0 -4
- package/dist/redaction.cjs +0 -1
- package/dist/redaction.d.cts +0 -54
- package/dist/redaction.d.ts +0 -54
- package/dist/redaction.js +0 -1
- package/dist/typegen.cjs +0 -1
- package/dist/typegen.d.cts +0 -52
- package/dist/typegen.d.ts +0 -52
- package/dist/typegen.js +0 -1
- package/index.js +0 -1
- /package/dist/{cli-main.d.cts → cli/bin.d.cts} +0 -0
- /package/dist/{cli-main.d.ts → cli/bin.d.ts} +0 -0
|
@@ -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 };
|
|
@@ -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 };
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkBFLXBLZ3_cjs=require('./chunk-BFLXBLZ3.cjs');require('./chunk-D6WM53FN.cjs');Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunkBFLXBLZ3_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunkBFLXBLZ3_cjs.a}});
|