node-env-resolver 6.6.0 → 6.7.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/README.md +186 -11
- package/dist/audit.d.ts +7 -8
- package/dist/audit.d.ts.map +1 -0
- package/dist/builder.cjs +1 -1
- package/dist/builder.d.ts +9 -12
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +1 -1
- package/dist/chunk-3TXO5AOZ.cjs +3 -0
- package/dist/chunk-4CLWNKB5.js +1 -0
- package/dist/chunk-4DUWYBNJ.cjs +6 -0
- package/dist/chunk-6NSX37SO.js +6 -0
- package/dist/chunk-BITH5LSH.js +3 -0
- package/dist/{chunk-DIJNUFGZ.cjs → chunk-G5HNCCR6.cjs} +3 -3
- package/dist/chunk-IP6POQCY.cjs +1 -0
- package/dist/{chunk-ZSM2NDX5.js → chunk-JVRRDD3Y.js} +3 -3
- package/dist/chunk-KHEBSYFP.js +9 -0
- package/dist/chunk-NHXSZY2U.cjs +9 -0
- package/dist/chunk-NKISCWWB.js +1 -0
- package/dist/chunk-UZ7HKTYL.cjs +1 -0
- package/dist/cli/bin.cjs +67 -27
- package/dist/cli/bin.d.ts +11 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +67 -27
- package/dist/cli/scan.d.ts +24 -0
- package/dist/cli/scan.d.ts.map +1 -0
- package/dist/cli.d.ts +4 -7
- package/dist/cli.d.ts.map +1 -0
- package/dist/debug.d.ts +142 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +19 -61
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/process-env.d.ts +32 -0
- package/dist/process-env.d.ts.map +1 -0
- package/dist/provider-kit.d.ts +7 -8
- package/dist/provider-kit.d.ts.map +1 -0
- package/dist/providers.d.ts +49 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/references.d.ts +5 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.d.ts +16 -8
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.ts +13 -31
- package/dist/resolvers.d.ts.map +1 -0
- package/dist/resolvers.js +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.d.ts +8 -108
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/patch-console.d.ts +23 -0
- package/dist/runtime/patch-console.d.ts.map +1 -0
- package/dist/runtime/redactor.d.ts +22 -0
- package/dist/runtime/redactor.d.ts.map +1 -0
- package/dist/runtime/response.d.ts +59 -0
- package/dist/runtime/response.d.ts.map +1 -0
- package/dist/security.d.ts +49 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/sensitivity.d.ts +34 -0
- package/dist/sensitivity.d.ts.map +1 -0
- package/dist/types.d.ts +150 -1
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.ts +19 -21
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.ts +9 -11
- package/dist/valibot.d.ts.map +1 -0
- package/dist/valibot.js +1 -1
- package/dist/validation-types.d.ts +3 -4
- package/dist/validation-types.d.ts.map +1 -0
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.ts +59 -44
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +2 -2
- package/dist/web.cjs +3 -3
- package/dist/web.d.ts +8 -10
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +3 -3
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.ts +9 -11
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +1 -1
- package/package.json +15 -23
- package/dist/audit.d.cts +0 -52
- package/dist/builder.d.cts +0 -149
- package/dist/chunk-3EWCMDFP.js +0 -9
- package/dist/chunk-4QOKRJ3F.cjs +0 -1
- package/dist/chunk-DYFRO3NM.cjs +0 -9
- package/dist/chunk-K4NIC5T3.js +0 -9
- package/dist/chunk-WKIPEKF6.js +0 -1
- package/dist/chunk-WVMDTD6J.cjs +0 -9
- package/dist/cli/bin.d.cts +0 -1
- package/dist/cli.d.cts +0 -52
- package/dist/index.d.cts +0 -220
- package/dist/provider-kit.d.cts +0 -50
- package/dist/resolver.d.cts +0 -20
- package/dist/resolvers.d.cts +0 -190
- package/dist/runtime/index.d.cts +0 -161
- package/dist/types--RcOnfdl.d.cts +0 -284
- package/dist/types--RcOnfdl.d.ts +0 -284
- package/dist/types.d.cts +0 -1
- package/dist/utils.d.cts +0 -327
- package/dist/valibot.d.cts +0 -143
- package/dist/validation-types.d.cts +0 -29
- package/dist/validators.d.cts +0 -933
- package/dist/web.d.cts +0 -71
- package/dist/zod.d.cts +0 -122
package/dist/index.d.cts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { e as ReferenceHandler, P as PolicyOptions, R as ResolveOptions, S as SimpleEnvSchema, f as ResolveAsyncConfig, g as InferSimpleValue, h as ResolveAsyncConfigWithSchema, a as Resolver, b as ReferenceOptions, i as InferMergedSchemaResult, j as ResolveConfigWithSchema, d as SyncResolver, k as ResolveConfig } from './types--RcOnfdl.cjs';
|
|
2
|
-
export { A as AsyncResolver, F as DEFAULT_DEBUG_OPTIONS, G as DEFAULT_SENSITIVE_PATTERNS, v as DebugEntry, u as DebugOptions, D as DebugValueMode, c as EnvDefinition, E as EnvSchema, r as InferResolveResult, q as InferSchema, I as InferSimpleSchema, p as InferType, n as Provenance, l as ReferenceContext, m as ReferenceResolution, y as SecuritySnapshotEntry, x as SecuritySnapshotOptions, o as SimpleEnvValue, V as Validator, w as VisibilityLevel, z as createDebugView, C as createRedactedObject, B as createSecuritySnapshot, t as isAsyncOnlyResolver, s as isSyncResolver } from './types--RcOnfdl.cjs';
|
|
3
|
-
export { SafeResolveResult as SafeResolveResultWithIssues, ValidationIssue } from './validation-types.cjs';
|
|
4
|
-
export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.cjs';
|
|
5
|
-
|
|
6
|
-
declare const processEnvReferenceHandler: ReferenceHandler;
|
|
7
|
-
|
|
8
|
-
interface StrictReferencePoliciesOptions {
|
|
9
|
-
/**
|
|
10
|
-
* Variables that must come from secret managers (not dotenv/process.env fallbacks).
|
|
11
|
-
* Example: ['STRIPE_KEY', 'DATABASE_URL']
|
|
12
|
-
*/
|
|
13
|
-
sensitiveKeys: readonly string[];
|
|
14
|
-
/**
|
|
15
|
-
* Allowed resolver source(s) for sensitive keys.
|
|
16
|
-
* Matching accepts:
|
|
17
|
-
* - exact resolver/source name
|
|
18
|
-
* - source prefix before `(` (e.g. `aws-secrets(prod/app)` -> `aws-secrets`)
|
|
19
|
-
* - reference handler `resolvedVia` value
|
|
20
|
-
* Default: ['aws-secrets']
|
|
21
|
-
*/
|
|
22
|
-
secretSources?: readonly string[] | string;
|
|
23
|
-
/**
|
|
24
|
-
* Keep secure default in production: false blocks dotenv values.
|
|
25
|
-
* You can pass a whitelist array to allow specific non-secret vars from dotenv.
|
|
26
|
-
* Default: false
|
|
27
|
-
*/
|
|
28
|
-
allowDotenvInProduction?: PolicyOptions['allowDotenvInProduction'];
|
|
29
|
-
/**
|
|
30
|
-
* Optional base policy object to merge into.
|
|
31
|
-
*/
|
|
32
|
-
basePolicies?: PolicyOptions;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Build a strict production policy preset for reference-first deployments:
|
|
36
|
-
* - Blocks dotenv in production by default
|
|
37
|
-
* - Forces sensitive keys to come from reference-backed resolvers (e.g. aws-secrets)
|
|
38
|
-
*/
|
|
39
|
-
declare function strictReferencePolicies(options: StrictReferencePoliciesOptions): PolicyOptions;
|
|
40
|
-
interface StrictReferenceResolveOptions extends Omit<StrictReferencePoliciesOptions, 'basePolicies'> {
|
|
41
|
-
/**
|
|
42
|
-
* Optional extra resolve options to merge with this preset.
|
|
43
|
-
*/
|
|
44
|
-
baseOptions?: Partial<ResolveOptions>;
|
|
45
|
-
/**
|
|
46
|
-
* Audit should be enabled for incident response reconstruction.
|
|
47
|
-
* Default: true
|
|
48
|
-
*/
|
|
49
|
-
enableAudit?: boolean;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Resolve options preset for strict reference-first hardening.
|
|
53
|
-
*/
|
|
54
|
-
declare function strictReferenceResolveOptions(options: StrictReferenceResolveOptions): Partial<ResolveOptions>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Type-safe environment variable resolver
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* import { resolve } from 'node-env-resolver';
|
|
62
|
-
* import { postgres, string } from 'node-env-resolver/validators';
|
|
63
|
-
*
|
|
64
|
-
* const config = resolve({
|
|
65
|
-
* PORT: 3000, // number with default
|
|
66
|
-
* DATABASE_URL: postgres(), // required PostgreSQL URL
|
|
67
|
-
* NODE_ENV: ['development', 'production'], // enum
|
|
68
|
-
* DEBUG: false, // boolean with default
|
|
69
|
-
* API_KEY: string({optional: true}), // optional string
|
|
70
|
-
* });
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
interface SafeResolveResult<T> {
|
|
75
|
-
success: true;
|
|
76
|
-
data: T;
|
|
77
|
-
}
|
|
78
|
-
interface SafeResolveError {
|
|
79
|
-
success: false;
|
|
80
|
-
error: string;
|
|
81
|
-
errors?: string[];
|
|
82
|
-
}
|
|
83
|
-
type SafeResolveResultType<T> = SafeResolveResult<T> | SafeResolveError;
|
|
84
|
-
declare function resolve<T extends SimpleEnvSchema>(schema: T, options?: Partial<ResolveOptions>): {
|
|
85
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
86
|
-
};
|
|
87
|
-
declare function resolve<T extends SimpleEnvSchema>(config: ResolveConfigWithSchema<T>): {
|
|
88
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
89
|
-
};
|
|
90
|
-
declare function resolve<T extends SimpleEnvSchema>(config: {
|
|
91
|
-
resolvers: readonly [[SyncResolver, T]];
|
|
92
|
-
options?: Partial<ResolveOptions>;
|
|
93
|
-
references?: ReferenceOptions;
|
|
94
|
-
}): {
|
|
95
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
96
|
-
};
|
|
97
|
-
declare function resolve<T extends SimpleEnvSchema>(config: {
|
|
98
|
-
resolvers: readonly [SyncResolver, T][];
|
|
99
|
-
options?: Partial<ResolveOptions>;
|
|
100
|
-
references?: ReferenceOptions;
|
|
101
|
-
}): {
|
|
102
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
103
|
-
};
|
|
104
|
-
declare function resolve<T extends readonly [SyncResolver, SimpleEnvSchema][]>(config: {
|
|
105
|
-
resolvers: T;
|
|
106
|
-
options?: Partial<ResolveOptions>;
|
|
107
|
-
references?: ReferenceOptions;
|
|
108
|
-
}): InferMergedSchemaResult<T>;
|
|
109
|
-
/**
|
|
110
|
-
* Resolve environment variables asynchronously (supports all resolver types - both sync and async)
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* import { resolveAsync } from 'node-env-resolver';
|
|
115
|
-
* import { postgres, string } from 'node-env-resolver/validators';
|
|
116
|
-
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
117
|
-
*
|
|
118
|
-
* // Works with async-only resolvers
|
|
119
|
-
* const config = await resolveAsync({
|
|
120
|
-
* resolvers: [
|
|
121
|
-
* [awsSecrets(), { PORT: 3000, DATABASE_URL: postgres(), API_KEY: string() }]
|
|
122
|
-
* ]
|
|
123
|
-
* });
|
|
124
|
-
*
|
|
125
|
-
* // Also works with sync resolvers (automatically wrapped in Promise)
|
|
126
|
-
* const config = await resolveAsync({
|
|
127
|
-
* resolvers: [
|
|
128
|
-
* [processEnv(), { DATABASE_URL: postgres() }]
|
|
129
|
-
* ],
|
|
130
|
-
* options: { strict: true }
|
|
131
|
-
* });
|
|
132
|
-
*
|
|
133
|
-
* // Multiple resolvers - supports unlimited tuples!
|
|
134
|
-
* const config = await resolveAsync({
|
|
135
|
-
* resolvers: [
|
|
136
|
-
* [dotenv(), { PORT: 3000 }],
|
|
137
|
-
* [awsSecrets(), { DATABASE_URL: postgres() }]
|
|
138
|
-
* ],
|
|
139
|
-
* options: { strict: true }
|
|
140
|
-
* });
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
declare function resolveAsync<T extends SimpleEnvSchema>(config: ResolveAsyncConfigWithSchema<T>): Promise<{
|
|
144
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
145
|
-
}>;
|
|
146
|
-
declare function resolveAsync<T extends SimpleEnvSchema>(config: {
|
|
147
|
-
resolvers: readonly [[Resolver, T]];
|
|
148
|
-
options?: Partial<ResolveOptions>;
|
|
149
|
-
references?: ReferenceOptions;
|
|
150
|
-
}): Promise<{
|
|
151
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
152
|
-
}>;
|
|
153
|
-
declare function resolveAsync<T extends SimpleEnvSchema>(config: {
|
|
154
|
-
resolvers: readonly [Resolver, T][];
|
|
155
|
-
options?: Partial<ResolveOptions>;
|
|
156
|
-
references?: ReferenceOptions;
|
|
157
|
-
}): Promise<{
|
|
158
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
159
|
-
}>;
|
|
160
|
-
declare function resolveAsync<T extends readonly [Resolver, SimpleEnvSchema][]>(config: {
|
|
161
|
-
resolvers: T;
|
|
162
|
-
options?: Partial<ResolveOptions>;
|
|
163
|
-
references?: ReferenceOptions;
|
|
164
|
-
}): Promise<InferMergedSchemaResult<T>>;
|
|
165
|
-
/**
|
|
166
|
-
* Safe resolve implementation (doesn't throw, returns result object)
|
|
167
|
-
*
|
|
168
|
-
* @param arg1 - Schema object or config object
|
|
169
|
-
* @param arg2 - Optional resolve options
|
|
170
|
-
* @returns Safe resolve result with success/error information
|
|
171
|
-
* @private
|
|
172
|
-
*/
|
|
173
|
-
declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
|
|
174
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
175
|
-
}>;
|
|
176
|
-
/**
|
|
177
|
-
* Safe async resolve (doesn't throw, returns result object)
|
|
178
|
-
* Supports both sync and async resolvers
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```typescript
|
|
182
|
-
* import { safeResolveAsync } from 'node-env-resolver';
|
|
183
|
-
* import { postgres } from 'node-env-resolver/validators';
|
|
184
|
-
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
185
|
-
*
|
|
186
|
-
* // Works with async resolvers
|
|
187
|
-
* const result = await safeResolveAsync({
|
|
188
|
-
* resolvers: [
|
|
189
|
-
* [awsSecrets({ region: 'us-east-1' }), { PORT: 3000, DATABASE_URL: postgres() }]
|
|
190
|
-
* ]
|
|
191
|
-
* });
|
|
192
|
-
*
|
|
193
|
-
* // Also works with sync resolvers
|
|
194
|
-
* const result = await safeResolveAsync({
|
|
195
|
-
* resolvers: [
|
|
196
|
-
* [processEnv(), { PORT: 3000 }]
|
|
197
|
-
* ]
|
|
198
|
-
* });
|
|
199
|
-
*
|
|
200
|
-
* // Multiple resolvers - supports unlimited tuples!
|
|
201
|
-
* const result = await safeResolveAsync({
|
|
202
|
-
* resolvers: [
|
|
203
|
-
* [dotenv(), { PORT: 3000 }],
|
|
204
|
-
* [awsSecrets(), { DATABASE_URL: postgres() }]
|
|
205
|
-
* ],
|
|
206
|
-
* options: { strict: true }
|
|
207
|
-
* });
|
|
208
|
-
*
|
|
209
|
-
* if (result.success) {
|
|
210
|
-
* console.log(result.data.PORT); // Type-safe access
|
|
211
|
-
* } else {
|
|
212
|
-
* console.error(result.error); // Detailed error message
|
|
213
|
-
* }
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
declare function safeResolveAsync<T extends SimpleEnvSchema>(config: ResolveAsyncConfig<T>): Promise<SafeResolveResultType<{
|
|
217
|
-
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
218
|
-
}>>;
|
|
219
|
-
|
|
220
|
-
export { PolicyOptions, ReferenceHandler, ReferenceOptions, ResolveAsyncConfig, ResolveConfig, ResolveOptions, Resolver, type SafeResolveError, type SafeResolveResult, type SafeResolveResultType, SimpleEnvSchema, type StrictReferencePoliciesOptions, type StrictReferenceResolveOptions, SyncResolver, processEnvReferenceHandler, resolve, resolveAsync, safeResolve, safeResolveAsync, strictReferencePolicies, strictReferenceResolveOptions };
|
package/dist/provider-kit.d.cts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Toolkit for building remote-secret resolvers (Bitwarden, Infisical, Doppler,
|
|
3
|
-
* 1Password, and any third-party vault).
|
|
4
|
-
*
|
|
5
|
-
* It centralises the cross-cutting concerns every vault provider shares so each
|
|
6
|
-
* one is written — and audited — exactly once:
|
|
7
|
-
*
|
|
8
|
-
* - **Bootstrap-credential resolution** that accepts a lazy provider instead of
|
|
9
|
-
* forcing a plaintext environment string. The function form keeps the secret
|
|
10
|
-
* out of `process.env`/dotfiles (read it from the OS keychain, an STS/OIDC
|
|
11
|
-
* exchange, `op read`, …) so an environment harvest finds nothing.
|
|
12
|
-
* - **HTTPS transport enforcement** so a bootstrap credential is never sent in
|
|
13
|
-
* cleartext to an overridable (self-hosted) endpoint.
|
|
14
|
-
* - **A fetch wrapper** with an abort-based timeout.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* A bootstrap credential — a vault access token, client secret, service token, …
|
|
18
|
-
*
|
|
19
|
-
* Either a literal string, or a function that produces one on demand. Prefer the
|
|
20
|
-
* function form in hardened setups: it lets the credential come from the OS
|
|
21
|
-
* keychain, a short-lived token exchange, or workload identity rather than living
|
|
22
|
-
* in an environment variable a supply-chain harvester can read.
|
|
23
|
-
*/
|
|
24
|
-
type CredentialInput = string | (() => string | Promise<string>);
|
|
25
|
-
/**
|
|
26
|
-
* Validate a *required* credential at construction time.
|
|
27
|
-
*
|
|
28
|
-
* A literal string is checked eagerly so the familiar synchronous
|
|
29
|
-
* `"<label> is required"` error still fires the moment the resolver is built. A
|
|
30
|
-
* function provider is accepted as-is and validated when it is later resolved
|
|
31
|
-
* (its value isn't available yet).
|
|
32
|
-
*/
|
|
33
|
-
declare function requireCredential(input: CredentialInput | undefined, label: string): CredentialInput;
|
|
34
|
-
/** Resolve a credential to its string value at use time, asserting it is non-empty. */
|
|
35
|
-
declare function resolveCredential(input: CredentialInput, label: string): Promise<string>;
|
|
36
|
-
/** Resolve an *optional* credential: `undefined` passes through, anything else is validated. */
|
|
37
|
-
declare function resolveOptionalCredential(input: CredentialInput | undefined, label: string): Promise<string | undefined>;
|
|
38
|
-
/**
|
|
39
|
-
* Reject a non-`https:` endpoint so a bootstrap credential is never transmitted
|
|
40
|
-
* in cleartext.
|
|
41
|
-
*
|
|
42
|
-
* Loopback hosts (`localhost`, `127.0.0.1`, `::1`) are always allowed — they are
|
|
43
|
-
* not exposed to network interception. Any other `http://` URL requires an
|
|
44
|
-
* explicit `allowInsecureHttp` opt-in.
|
|
45
|
-
*/
|
|
46
|
-
declare function assertSecureUrl(rawUrl: string, label: string, allowInsecureHttp?: boolean): void;
|
|
47
|
-
/** `fetch()` with an abort-based timeout (default 30s), surfacing a clear timeout error. */
|
|
48
|
-
declare function fetchWithTimeout(url: string, init: RequestInit, service: string, timeoutMs?: number): Promise<Response>;
|
|
49
|
-
|
|
50
|
-
export { type CredentialInput, assertSecureUrl, fetchWithTimeout, requireCredential, resolveCredential, resolveOptionalCredential };
|
package/dist/resolver.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { S as SimpleEnvSchema, E as EnvSchema, a as Resolver, R as ResolveOptions } from './types--RcOnfdl.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Internal resolver functions - extracted for use by both old and new APIs
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Convert simplified schema to standard EnvSchema
|
|
9
|
-
*/
|
|
10
|
-
declare function normalizeSchema(schema: SimpleEnvSchema): EnvSchema;
|
|
11
|
-
/**
|
|
12
|
-
* Internal resolver - used by both old resolve() and new env() APIs
|
|
13
|
-
*/
|
|
14
|
-
declare function resolveEnvInternal<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Promise<Record<string, unknown>>;
|
|
15
|
-
/**
|
|
16
|
-
* Internal sync resolver
|
|
17
|
-
*/
|
|
18
|
-
declare function resolveEnvInternalSync<T extends EnvSchema>(schema: T, resolvers: Resolver[], options: ResolveOptions): Record<string, unknown>;
|
|
19
|
-
|
|
20
|
-
export { normalizeSchema, resolveEnvInternal, resolveEnvInternalSync };
|
package/dist/resolvers.d.cts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { d as SyncResolver, a as Resolver } from './types--RcOnfdl.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Resolver that reads from process.env
|
|
5
|
-
* This is the default resolver used when no custom resolvers are provided
|
|
6
|
-
*
|
|
7
|
-
* @returns SyncResolver that loads environment variables from process.env
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { processEnv } from 'node-env-resolver';
|
|
12
|
-
*
|
|
13
|
-
* const resolver = processEnv();
|
|
14
|
-
* const env = resolver.loadSync(); // { PORT: '3000', NODE_ENV: 'development', ... }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
declare function processEnv(): SyncResolver;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Built-in resolvers for environment variable resolution
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Options for the dotenv resolver
|
|
25
|
-
*/
|
|
26
|
-
interface DotenvOptions {
|
|
27
|
-
/** Path to the .env file (default: '.env') */
|
|
28
|
-
path?: string;
|
|
29
|
-
/** Enable environment-specific file loading (default: false) */
|
|
30
|
-
expand?: boolean;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Load configuration from .env files
|
|
34
|
-
* Supports environment-specific files when expand=true
|
|
35
|
-
*
|
|
36
|
-
* @param options Path string or options object
|
|
37
|
-
* @returns Resolver that loads from .env file(s)
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* import { dotenv } from 'node-env-resolver/resolvers';
|
|
42
|
-
*
|
|
43
|
-
* // Simple .env file
|
|
44
|
-
* const config = await resolveAsync([
|
|
45
|
-
* dotenv('.env'),
|
|
46
|
-
* { PORT: 3000, API_KEY: string() }
|
|
47
|
-
* ]);
|
|
48
|
-
*
|
|
49
|
-
* // Environment-specific files
|
|
50
|
-
* const config = await resolveAsync([
|
|
51
|
-
* dotenv({ path: '.env', expand: true }),
|
|
52
|
-
* { PORT: 3000 }
|
|
53
|
-
* ]);
|
|
54
|
-
* // Loads: .env.defaults, .env, .env.local, .env.development, .env.development.local
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
declare function dotenv(options?: string | DotenvOptions): SyncResolver;
|
|
58
|
-
/**
|
|
59
|
-
* Load configuration from package.json
|
|
60
|
-
* Reads version, name, and config fields by default
|
|
61
|
-
*
|
|
62
|
-
* @param options Optional configuration
|
|
63
|
-
* @returns Resolver that loads from package.json
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { packageJson } from 'node-env-resolver/resolvers';
|
|
68
|
-
*
|
|
69
|
-
* // Loads: VERSION, NAME, CONFIG_* from package.json
|
|
70
|
-
* const config = await resolveAsync([
|
|
71
|
-
* packageJson(),
|
|
72
|
-
* { VERSION: string(), NAME: string() }
|
|
73
|
-
* ]);
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
declare function packageJson(options?: {
|
|
77
|
-
path?: string;
|
|
78
|
-
fields?: string[];
|
|
79
|
-
}): Resolver;
|
|
80
|
-
/**
|
|
81
|
-
* Load configuration from a remote HTTP/HTTPS endpoint
|
|
82
|
-
* Expects JSON response
|
|
83
|
-
*
|
|
84
|
-
* @param url URL to fetch config from
|
|
85
|
-
* @param options Optional fetch options
|
|
86
|
-
* @returns Resolver that loads from HTTP
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* import { http } from 'node-env-resolver/resolvers';
|
|
91
|
-
*
|
|
92
|
-
* // Fetch config from remote endpoint
|
|
93
|
-
* const config = await resolveAsync([
|
|
94
|
-
* http('https://config.example.com/app.json'),
|
|
95
|
-
* { PORT: 3000, API_KEY: string() }
|
|
96
|
-
* ]);
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
declare function http(url: string, options?: RequestInit & {
|
|
100
|
-
timeout?: number;
|
|
101
|
-
}): Resolver;
|
|
102
|
-
/**
|
|
103
|
-
* Load configuration from a JSON file
|
|
104
|
-
*
|
|
105
|
-
* @param path Path to JSON file (relative to cwd)
|
|
106
|
-
* @returns Resolver that loads from JSON file
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* import { resolve } from 'node-env-resolver';
|
|
111
|
-
* import { json } from 'node-env-resolver/resolvers';
|
|
112
|
-
*
|
|
113
|
-
* const config = await resolveAsync(
|
|
114
|
-
* [json('config.json'), { PORT: 3000 }]
|
|
115
|
-
* );
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare function json(path?: string): Resolver;
|
|
119
|
-
/**
|
|
120
|
-
* Load secrets from a directory (Docker secrets / Kubernetes mounted secrets)
|
|
121
|
-
* Each file in the directory becomes an environment variable (filename = key, content = value)
|
|
122
|
-
*
|
|
123
|
-
* @param path Path to secrets directory (relative to cwd)
|
|
124
|
-
* @returns Resolver that loads from secrets directory
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```ts
|
|
128
|
-
* import { resolve } from 'node-env-resolver';
|
|
129
|
-
* import { secrets } from 'node-env-resolver/resolvers';
|
|
130
|
-
*
|
|
131
|
-
* const config = await resolveAsync(
|
|
132
|
-
* [secrets('/run/secrets'), { DB_PASSWORD: string() }]
|
|
133
|
-
* );
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
declare function secrets(path?: string): Resolver;
|
|
137
|
-
/**
|
|
138
|
-
* YAML configuration file resolver interface
|
|
139
|
-
* Requires 'js-yaml' as a peer dependency (install separately for tree-shaking)
|
|
140
|
-
*/
|
|
141
|
-
interface YamlOptions {
|
|
142
|
-
/** Path to the YAML file (default: 'config.yaml') */
|
|
143
|
-
path?: string;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Load configuration from a YAML file
|
|
147
|
-
* Requires 'js-yaml' package to be installed separately
|
|
148
|
-
*
|
|
149
|
-
* @param options Path string or options object
|
|
150
|
-
* @returns Resolver that loads from YAML file
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* import { resolve } from 'node-env-resolver';
|
|
155
|
-
* import { yaml } from 'node-env-resolver/resolvers';
|
|
156
|
-
*
|
|
157
|
-
* const config = await resolveAsync(
|
|
158
|
-
* [yaml('config.yaml'), { PORT: 3000 }]
|
|
159
|
-
* );
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
declare function yaml(options?: string | YamlOptions): Resolver;
|
|
163
|
-
/**
|
|
164
|
-
* TOML configuration file resolver interface
|
|
165
|
-
* Requires 'smol-toml' as a peer dependency (install separately for tree-shaking)
|
|
166
|
-
*/
|
|
167
|
-
interface TomlOptions {
|
|
168
|
-
/** Path to the TOML file (default: 'config.toml') */
|
|
169
|
-
path?: string;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Load configuration from a TOML file
|
|
173
|
-
* Requires 'smol-toml' package to be installed separately
|
|
174
|
-
*
|
|
175
|
-
* @param options Path string or options object
|
|
176
|
-
* @returns Resolver that loads from TOML file
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* import { resolve } from 'node-env-resolver';
|
|
181
|
-
* import { toml } from 'node-env-resolver/resolvers';
|
|
182
|
-
*
|
|
183
|
-
* const config = await resolveAsync(
|
|
184
|
-
* [toml('config.toml'), { PORT: 3000 }]
|
|
185
|
-
* );
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
declare function toml(options?: string | TomlOptions): Resolver;
|
|
189
|
-
|
|
190
|
-
export { type DotenvOptions, type TomlOptions, type YamlOptions, dotenv, http, json, packageJson, processEnv, secrets, toml, yaml };
|
package/dist/runtime/index.d.cts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
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 };
|