node-env-resolver 5.0.1 → 6.0.1
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 +119 -57
- package/dist/audit.d.cts +23 -0
- package/dist/audit.d.ts +23 -0
- package/dist/builder.cjs +1 -1
- package/dist/builder.js +1 -1
- package/dist/chunk-3KAHSFPX.js +9 -0
- package/dist/{chunk-FH54ESWI.cjs → chunk-5E2SZR3V.cjs} +3 -3
- package/dist/{chunk-XJLMVSPN.js → chunk-GMQOMCGI.js} +1 -1
- package/dist/chunk-LCW5BDAW.js +15 -0
- package/dist/chunk-OSMNJM5N.cjs +9 -0
- package/dist/chunk-PNUGGPRS.cjs +15 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +44 -266
- package/dist/resolvers.d.ts +44 -266
- package/dist/resolvers.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +60 -0
- package/dist/utils.d.ts +60 -0
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.js +1 -1
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.cts +771 -17
- package/dist/validators.d.ts +771 -17
- package/dist/validators.js +2 -2
- package/dist/web.cjs +3 -3
- package/dist/web.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +25 -13
- package/dist/chunk-4YVXFL3I.cjs +0 -9
- package/dist/chunk-DIXI6MUB.js +0 -9
- package/dist/chunk-TAX63ALN.js +0 -16
- package/dist/chunk-XPL5XLTA.cjs +0 -16
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkOSMNJM5N_cjs=require('./chunk-OSMNJM5N.cjs'),chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');chunk4ZOF2PI4_cjs.f();function v(){return [chunk4QOKRJ3F_cjs.a()]}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&("resolvers"in e||"schema"in e||"options"in e)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!("resolvers"in e)&&!("schema"in e)&&!("options"in e)}function P(e,t){let o,l,i;if(y(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else throw new Error('resolve() config object must have either a "schema" property or "resolvers" array');l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else throw new Error('resolve() expects either a schema object or a config object with "schema" or "resolvers" property');for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)throw new Error(`\u274C resolve() cannot be used with async validators.
|
|
2
2
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
3
3
|
\u{1F4A1} Use resolveAsync() instead, or use shorthand syntax for sync validation.`);for(let s of l)if(!s.loadSync)throw new Error(`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
4
4
|
All resolvers passed to resolve() must have a loadSync() method.
|
|
5
|
-
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a,policies:r,...i},c=
|
|
5
|
+
\u{1F4A1} Use resolveAsync() for async resolvers, or use a sync-compatible resolver.`);let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:true,strict:true,enableAudit:a,policies:r,...i},c=chunkOSMNJM5N_cjs.a(o);return chunkOSMNJM5N_cjs.c(c,l,p)}async function k(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,c]of e.resolvers)Object.assign(t,c);}else throw new Error('resolveAsync() config object must have either a "schema" property or "resolvers" array');let o=e.resolvers?e.resolvers.map(([c])=>c):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options},r=chunkOSMNJM5N_cjs.a(t);return await chunkOSMNJM5N_cjs.b(r,o,a)}function V(e,t){let o,l,i;try{if(y(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else return {success:!1,error:'safeResolve() config object must have either a "schema" property or "resolvers" array'};l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else return {success:!1,error:'safeResolve() expects either a schema object or a config object with "schema" or "resolvers" property'};for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)return {success:!1,error:`\u274C safeResolve() cannot be used with async validators.
|
|
6
6
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
7
7
|
\u{1F4A1} Use safeResolveAsync() instead, or use shorthand syntax for sync validation.`};for(let s of l)if(!s.loadSync)return {success:!1,error:`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
8
8
|
All resolvers passed to safeResolve() must have a loadSync() method.
|
|
9
|
-
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a,policies:r,...i},c=
|
|
9
|
+
\u{1F4A1} Use safeResolveAsync() for async resolvers.`};let a=(process.env.NODE_ENV||"").toLowerCase()==="production",r=i?.policies??{},p={interpolate:!0,strict:!0,enableAudit:a,policies:r,...i},c=chunkOSMNJM5N_cjs.a(o);return {success:!0,data:chunkOSMNJM5N_cjs.c(c,l,p)}}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}async function g(e){let t;if(e.schema)t=e.schema;else if(e.resolvers&&e.resolvers.length>0){t={};for(let[,r]of e.resolvers)Object.assign(t,r);}else return {success:false,error:'safeResolveAsync() config object must have either a "schema" property or "resolvers" array'};let o=e.resolvers?e.resolvers.map(([r])=>r):v(),l=(process.env.NODE_ENV||"").toLowerCase()==="production",i=e.options?.policies??{},a={interpolate:true,strict:true,enableAudit:l,policies:i,...e.options};try{let r=chunkOSMNJM5N_cjs.a(t);return {success:!0,data:await chunkOSMNJM5N_cjs.b(r,o,a)}}catch(r){return {success:false,error:r instanceof Error?r.message:String(r)}}}exports.a=P;exports.b=k;exports.c=V;exports.d=g;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a,c,b}from'./chunk-
|
|
1
|
+
import {a,c,b}from'./chunk-3KAHSFPX.js';import {f}from'./chunk-YOHHFBZN.js';import {a as a$1}from'./chunk-WKIPEKF6.js';f();function v(){return [a$1()]}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&("resolvers"in e||"schema"in e||"options"in e)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!("resolvers"in e)&&!("schema"in e)&&!("options"in e)}function P(e,t){let o,l,i;if(y(e)){let s=e;if(s.schema)o=s.schema;else if(s.resolvers&&s.resolvers.length>0){o={};for(let[,n]of s.resolvers)Object.assign(o,n);}else throw new Error('resolve() config object must have either a "schema" property or "resolvers" array');l=s.resolvers?s.resolvers.map(([n])=>n):v(),i=s.options;}else if(S(e))o=e,l=v(),i=t;else throw new Error('resolve() expects either a schema object or a config object with "schema" or "resolvers" property');for(let[s,n]of Object.entries(o))if(n&&typeof n=="object"&&"~standard"in n)throw new Error(`\u274C resolve() cannot be used with async validators.
|
|
2
2
|
Variable '${s}' uses a Standard Schema validator (Zod, Valibot, etc.)
|
|
3
3
|
\u{1F4A1} Use resolveAsync() instead, or use shorthand syntax for sync validation.`);for(let s of l)if(!s.loadSync)throw new Error(`\u274C Resolver '${s.name}' does not support synchronous loading.
|
|
4
4
|
All resolvers passed to resolve() must have a loadSync() method.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {a}from'./chunk-5PELJRUQ.js';import {existsSync,readFileSync}from'fs';import {resolve,join}from'path';var h=l=>{let a={},e=l.split(`
|
|
2
|
+
`);for(let t=0;t<e.length;t++){let i=e[t]?.trim()??"";if(!i||i[0]==="#")continue;let o=i.indexOf("=");if(o<=0)continue;let n=i.slice(0,o).trim();if(!/^[A-Z_][A-Z0-9_]*$/i.test(n))continue;let r=i.slice(o+1).trim();if(r.length>=2){let s=r[0];(s==='"'||s==="'")&&r[r.length-1]===s&&(r=r.slice(1,-1),s==='"'&&(r=r.replace(/\\n/g,`
|
|
3
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function O(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=resolve(process.cwd(),a.path);return existsSync(n)?h(readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=resolve(process.cwd(),a.path);return existsSync(n)?h(readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=resolve(process.cwd(),n);if(existsSync(r))try{o={...o,...h(readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=resolve(process.cwd(),a.path);if(!existsSync(e))return {};try{let t=readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=resolve(process.cwd(),l);if(!existsSync(a))return {};try{let e=readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a$1,statSync:e}=a("fs"),t=resolve(process.cwd(),l);if(!existsSync(t))return {};try{let i=a$1(t),o={};for(let n of i){let r=join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}}}}function U(l){let a$1=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a$1.path})`,async load(){let e=join(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
4
|
+
npm install js-yaml
|
|
5
|
+
# or
|
|
6
|
+
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a$1.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=join(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{load:t}=a("js-yaml"),i=readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
7
|
+
npm install js-yaml
|
|
8
|
+
# or
|
|
9
|
+
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a$1.path}: ${t instanceof Error?t.message:String(t)}`)}}}}function C(l){let a$1=typeof l=="string"?{path:l}:{path:l?.path??"config.toml"};return {name:`toml(${a$1.path})`,async load(){let e=resolve(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{parse:t}=await import('smol-toml'),i=readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
10
|
+
npm install smol-toml
|
|
11
|
+
# or
|
|
12
|
+
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a$1.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=resolve(process.cwd(),a$1.path);if(!existsSync(e))return {};try{let{parse:t}=a("smol-toml"),i=readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
13
|
+
npm install smol-toml
|
|
14
|
+
# or
|
|
15
|
+
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a$1.path}: ${t instanceof Error?t.message:String(t)}`)}}}}export{O as a,S as b,k as c,R as d,_ as e,U as f,C as g};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs'),chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs'),path=require('path'),fs=require('fs');function C(s,c){try{let r=path.resolve(process.cwd(),s);return {valid:!0,value:fs.readFileSync(r,"utf8").trim()}}catch(r){return {valid:false,error:`Failed to read file${c?` for ${c}`:""}: ${r instanceof Error?r.message:String(r)}`}}}var D=null,h=null;async function E(s){if(!D){let c=await import('./audit.cjs');D=c.logAuditEvent,h=c.attachAuditSession;}D(s);}function b(s){if(!D)try{let c=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));D=c.logAuditEvent,h=c.attachAuditSession;}catch{return}D&&D(s);}function U(s){let c={};for(let[r,o]of Object.entries(s))if(typeof o=="function"){let a=o,t=a.__isFileValidator===true;c[r]={type:t?"file":"custom",validator:o,...a.default!==void 0&&{default:a.default},...a.optional!==void 0&&{optional:a.optional},...a.secretsDir!==void 0&&{secretsDir:a.secretsDir}};}else if(typeof o=="string")c[r]={type:"string",default:o,validator:a=>{if(a===""&&!c[r].allowEmpty)throw new Error("String cannot be empty");return a}};else if(typeof o=="number")c[r]={type:"number",default:o,validator:a=>{let t=Number(a);if(isNaN(t))throw new Error(`Invalid number: "${a}"`);return t}};else if(typeof o=="boolean")c[r]={type:"boolean",default:o,validator:a=>{let t=a.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${a}"`)}};else if(Array.isArray(o)){let a=o.map(String);c[r]={type:"string",enum:a,validator:(t,m)=>{if(!a.includes(t)){let n=m||r;throw new Error(`${n} must be one of: ${a.join(", ")}`)}return t}};}else c[r]=o;return c}function L(s,c){return s.replace(/\$\{([^}]+)\}/g,(r,o)=>c[o]||r)}async function B(s,c,r,o="last",a){let t={},m={};if(o==="last"){let n=await Promise.allSettled(s.map(async i=>({resolver:i,env:i.load?await i.load():{}})));for(let i of n){if(i.status==="rejected"){let u=i.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),r)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=i.value;for(let[u,y]of Object.entries(f))y!==void 0&&(t[u]=y,m[u]={source:d.name||"unknown",timestamp:Date.now(),...d.metadata?.cached!==void 0&&{cached:!!d.metadata.cached}});}}else for(let n of s)try{let i=n.load?await n.load():{};for(let[d,f]of Object.entries(i))if(f!==void 0){if(t[d]!==void 0)continue;t[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(a&&a.size>0&&Array.from(a).every(f=>t[f]!==void 0))break}catch(i){if(await E({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),r)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(c)for(let[n,i]of Object.entries(t))t[n]=L(i,t);return {mergedEnv:t,provenance:m}}function M(s,c,r,o="last",a){let t={},m={};for(let n of s)try{if(!n.loadSync){if(r)throw new Error(`Resolver ${n.name} has no loadSync() method`);continue}let i=n.loadSync();for(let[d,f]of Object.entries(i))if(f!==void 0){if(o==="first"&&t[d]!==void 0)continue;t[d]=f,m[d]={source:n.name||"unknown",timestamp:Date.now(),...n.metadata?.cached!==void 0&&{cached:!!n.metadata.cached}};}if(o==="first"&&a&&a.size>0&&Array.from(a).every(f=>t[f]!==void 0))break}catch(i){if(b({type:"resolver_error",timestamp:Date.now(),source:n.name,error:i instanceof Error?i.message:String(i)}),r)throw new Error(`Resolver ${n.name} failed: ${i instanceof Error?i.message:i}`)}if(c)for(let[n,i]of Object.entries(t))t[n]=L(i,t);return {mergedEnv:t,provenance:m}}function T(s,c,r,o){if(!o)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&r&&r.source.startsWith("dotenv(")){let t=o.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(s)?null:`${s} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${s}'] or set to true for all.`:`${s} cannot be sourced from .env files in production (secure default). Production platforms (Vercel, AWS, etc.) use process.env. To allow .env in production: policies.allowDotenvInProduction: true`}if(o.enforceAllowedSources&&o.enforceAllowedSources[s]&&r){let t=o.enforceAllowedSources[s];if(!t.includes(r.source))return `${s} must be sourced from one of: ${t.join(", ")} (actual: ${r.source})`}return null}function x(s){let c=[],r=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let o of Object.keys(s))r.test(o)||c.push(`Invalid environment variable name: "${o}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return c}function z(s,c){let r={};for(let[o,a]of Object.entries(s)){if(!o.includes(c)){r[o]=a;continue}let t=o.split(c),m=r;for(let i=0;i<t.length-1;i++){let d=t[i].toLowerCase();d in m||(m[d]={}),m=m[d];}let n=t[t.length-1].toLowerCase();m[n]=a;}return r}async function G(s,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:t=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=r,f={},u;if(n){if(!h){let e=await import('./audit.cjs');D=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
2
|
+
${y.map(e=>` - ${e}`).join(`
|
|
3
|
+
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=await B(c,a,t,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let l;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,j),R=C(P,e);R.valid?(l={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):l={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?l={success:!0,value:p.default}:p.optional?l={success:!0,value:void 0}:l={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{l={success:!0,value:p.validator($,e)};}catch(v){l={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else l={success:!0,value:$};l.success?(f[e]=l.value,n&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(l.error),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:l.error,sessionId:u}));}catch(l){let v=l instanceof Error?l.message:String(l);g.push(`${e}: ${v}`),n&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&await E({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
4
|
+
${g.map(e=>` - ${e}`).join(`
|
|
5
|
+
`)}`);return n&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),r.nestedDelimiter?z(f,r.nestedDelimiter):f}function H(s,c,r){let o=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:a=false,strict:t=true,policies:m,enableAudit:n=o,priority:i="last",secretsDir:d}=r,f={},u;if(n){if(!h)try{let e=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));D=e.logAuditEvent,h=e.attachAuditSession;}catch{}h&&(u=h(f));}let y=x(s);if(y.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`Invalid environment variable names: ${y.join(", ")}`,sessionId:u}),new Error(`Environment validation failed:
|
|
6
|
+
${y.map(e=>` - ${e}`).join(`
|
|
7
|
+
`)}`);let k=new Set(Object.keys(s)),{mergedEnv:A,provenance:w}=M(c,a,t,i,k),g=[];for(let[e,_]of Object.entries(s)){let p=_,$=A[e],S=T(e,p,w[e],m);if(S){g.push(S),n&&b({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let l;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,j),R=C(P,e);R.valid?(l={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):l={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?l={success:!0,value:p.default}:p.optional?l={success:!0,value:void 0}:l={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{l={success:!0,value:p.validator($,e)};}catch(v){l={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else l={success:!0,value:$};l.success?(f[e]=l.value,n&&b({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(l.error),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:l.error,sessionId:u}));}catch(l){let v=l instanceof Error?l.message:String(l);g.push(`${e}: ${v}`),n&&b({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw n&&b({type:"validation_failure",timestamp:Date.now(),error:`${g.length} validation error(s)`,metadata:{errorCount:g.length},sessionId:u}),new Error(`Environment validation failed:
|
|
8
|
+
${g.map(e=>` - ${e}`).join(`
|
|
9
|
+
`)}`);return n&&b({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(s).length},sessionId:u}),r.nestedDelimiter?z(f,r.nestedDelimiter):f}exports.a=U;exports.b=G;exports.c=H;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs'),fs=require('fs'),path=require('path');var h=l=>{let a={},e=l.split(`
|
|
2
|
+
`);for(let t=0;t<e.length;t++){let i=e[t]?.trim()??"";if(!i||i[0]==="#")continue;let o=i.indexOf("=");if(o<=0)continue;let n=i.slice(0,o).trim();if(!/^[A-Z_][A-Z0-9_]*$/i.test(n))continue;let r=i.slice(o+1).trim();if(r.length>=2){let s=r[0];(s==='"'||s==="'")&&r[r.length-1]===s&&(r=r.slice(1,-1),s==='"'&&(r=r.replace(/\\n/g,`
|
|
3
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'")));}else {let s=r.indexOf("#");s>=0&&(r=r.slice(0,s).trim());}a[n]=r;}return a};function O(l){let a=typeof l=="string"?{path:l,expand:false}:{path:l?.path??".env",expand:l?.expand??false};return {name:a.expand?`dotenv-expand(${a.path})`:`dotenv(${a.path})`,async load(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o},loadSync(){if(!a.expand){let n=path.resolve(process.cwd(),a.path);return fs.existsSync(n)?h(fs.readFileSync(n,"utf8")):{}}let e=a.path,t=process.env.NODE_ENV||"development",i=[`${e}.defaults`,e,`${e}.local`,`${e}.${t}`,`${e}.${t}.local`],o={};for(let n of i){let r=path.resolve(process.cwd(),n);if(fs.existsSync(r))try{o={...o,...h(fs.readFileSync(r,"utf8"))};}catch{}}return o}}}function S(l){let a={path:l?.path??"package.json",fields:l?.fields??["version","name","config"]};return {name:"package.json",async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let t=fs.readFileSync(e,"utf8"),i=JSON.parse(t),o={};for(let n of a.fields){let r=i[n];if(r!==void 0)if(n==="config"&&typeof r=="object"){let s=(c,d)=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=`${d}_${f.toUpperCase()}`;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):o[m]=String(p);}};s(r,"CONFIG");}else o[n.toUpperCase()]=String(r);}return o}catch(t){throw new Error(`Failed to read package.json: ${t instanceof Error?t.message:String(t)}`)}}}}function k(l,a){return {name:`http(${l})`,async load(){try{let e=new AbortController,t=a?.timeout??5e3,i=setTimeout(()=>e.abort(),t),o=await fetch(l,{...a,signal:e.signal});if(clearTimeout(i),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);let n=await o.json(),r={},s=(c,d="")=>{if(c&&typeof c=="object"&&!Array.isArray(c))for(let[f,p]of Object.entries(c)){let m=d?`${d}_${f}`:f;p&&typeof p=="object"&&!Array.isArray(p)?s(p,m):r[m.toUpperCase()]=String(p);}};return s(n),r}catch(e){throw e.name==="AbortError"?new Error(`HTTP request timeout after ${a?.timeout??5e3}ms`):new Error(`Failed to fetch config from ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function R(l="config.json"){return {name:`json(${l})`,async load(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}},loadSync(){let a=path.resolve(process.cwd(),l);if(!fs.existsSync(a))return {};try{let e=fs.readFileSync(a,"utf8"),t=JSON.parse(e),i={},o=(n,r="")=>{if(n&&typeof n=="object"&&!Array.isArray(n))for(let[s,c]of Object.entries(n)){let d=r?`${r}_${s}`:s;c&&typeof c=="object"&&!Array.isArray(c)?o(c,d):i[d.toUpperCase()]=String(c);}};return o(t),i}catch(e){throw new Error(`Failed to parse JSON file ${l}: ${e instanceof Error?e.message:String(e)}`)}}}}function _(l="/run/secrets"){return {name:`secrets(${l})`,async load(){let{readdirSync:a,statSync:e}=await import('fs'),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}},loadSync(){let{readdirSync:a,statSync:e}=chunkKIQXH265_cjs.a("fs"),t=path.resolve(process.cwd(),l);if(!fs.existsSync(t))return {};try{let i=a(t),o={};for(let n of i){let r=path.join(t,n);if(!e(r).isFile())continue;let c=n.toUpperCase().replace(/[.-]/g,"_"),d=fs.readFileSync(r,"utf8").trim();o[c]=d;}return o}catch(i){throw new Error(`Failed to read secrets from ${l}: ${i instanceof Error?i.message:String(i)}`)}}}}function U(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.yaml"};return {name:`yaml(${a.path})`,async load(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=await import('js-yaml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
4
|
+
npm install js-yaml
|
|
5
|
+
# or
|
|
6
|
+
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.join(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{load:t}=chunkKIQXH265_cjs.a("js-yaml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`YAML resolver requires 'js-yaml' package. Install it with:
|
|
7
|
+
npm install js-yaml
|
|
8
|
+
# or
|
|
9
|
+
pnpm add js-yaml`):new Error(`Failed to parse YAML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}function C(l){let a=typeof l=="string"?{path:l}:{path:l?.path??"config.toml"};return {name:`toml(${a.path})`,async load(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=await import('smol-toml'),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
10
|
+
npm install smol-toml
|
|
11
|
+
# or
|
|
12
|
+
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}},loadSync(){let e=path.resolve(process.cwd(),a.path);if(!fs.existsSync(e))return {};try{let{parse:t}=chunkKIQXH265_cjs.a("smol-toml"),i=fs.readFileSync(e,"utf8"),o=t(i),n={},r=(s,c="")=>{if(s&&typeof s=="object"&&!Array.isArray(s))for(let[d,f]of Object.entries(s)){let p=c?`${c}_${d}`:d;f&&typeof f=="object"&&!Array.isArray(f)?r(f,p):n[p.toUpperCase()]=String(f);}};return r(o),n}catch(t){throw t.code==="MODULE_NOT_FOUND"||t.message?.includes("Cannot find package")?new Error(`TOML resolver requires 'smol-toml' package. Install it with:
|
|
13
|
+
npm install smol-toml
|
|
14
|
+
# or
|
|
15
|
+
pnpm add smol-toml`):new Error(`Failed to parse TOML file ${a.path}: ${t instanceof Error?t.message:String(t)}`)}}}}exports.a=O;exports.b=S;exports.c=k;exports.d=R;exports.e=_;exports.f=U;exports.g=C;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk5E2SZR3V_cjs=require('./chunk-5E2SZR3V.cjs');require('./chunk-OSMNJM5N.cjs');var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs');require('./chunk-4QOKRJ3F.cjs');var chunk6D5APQIG_cjs=require('./chunk-6D5APQIG.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"resolve",{enumerable:true,get:function(){return chunk5E2SZR3V_cjs.a}});Object.defineProperty(exports,"resolveAsync",{enumerable:true,get:function(){return chunk5E2SZR3V_cjs.b}});Object.defineProperty(exports,"safeResolve",{enumerable:true,get:function(){return chunk5E2SZR3V_cjs.c}});Object.defineProperty(exports,"safeResolveAsync",{enumerable:true,get:function(){return chunk5E2SZR3V_cjs.d}});Object.defineProperty(exports,"clearAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.d}});Object.defineProperty(exports,"getAuditLog",{enumerable:true,get:function(){return chunk4ZOF2PI4_cjs.c}});Object.defineProperty(exports,"isAsyncOnlyResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.b}});Object.defineProperty(exports,"isSyncResolver",{enumerable:true,get:function(){return chunk6D5APQIG_cjs.a}});
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.
|
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { resolve } from 'node-env-resolver';
|
|
12
|
-
* import { postgres, string } from 'node-env-resolver/
|
|
12
|
+
* import { postgres, string } from 'node-env-resolver/validators';
|
|
13
13
|
*
|
|
14
14
|
* const config = resolve({
|
|
15
15
|
* PORT: 3000, // number with default
|
|
@@ -55,7 +55,7 @@ declare function resolve<T extends SimpleEnvSchema>(config: {
|
|
|
55
55
|
* @example
|
|
56
56
|
* ```typescript
|
|
57
57
|
* import { resolveAsync } from 'node-env-resolver';
|
|
58
|
-
* import { postgres, string } from 'node-env-resolver/
|
|
58
|
+
* import { postgres, string } from 'node-env-resolver/validators';
|
|
59
59
|
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
60
60
|
*
|
|
61
61
|
* // Works with async-only resolvers
|
|
@@ -98,6 +98,14 @@ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
|
|
|
98
98
|
}): Promise<{
|
|
99
99
|
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
100
100
|
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Safe resolve implementation (doesn't throw, returns result object)
|
|
103
|
+
*
|
|
104
|
+
* @param arg1 - Schema object or config object
|
|
105
|
+
* @param arg2 - Optional resolve options
|
|
106
|
+
* @returns Safe resolve result with success/error information
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
101
109
|
declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
|
|
102
110
|
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
103
111
|
}>;
|
|
@@ -108,7 +116,7 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<
|
|
|
108
116
|
* @example
|
|
109
117
|
* ```typescript
|
|
110
118
|
* import { safeResolveAsync } from 'node-env-resolver';
|
|
111
|
-
* import { postgres } from 'node-env-resolver/
|
|
119
|
+
* import { postgres } from 'node-env-resolver/validators';
|
|
112
120
|
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
113
121
|
*
|
|
114
122
|
* // Works with async resolvers
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { AuditEvent, AuditEventType, clearAuditLog, getAuditLog } from './audit.
|
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { resolve } from 'node-env-resolver';
|
|
12
|
-
* import { postgres, string } from 'node-env-resolver/
|
|
12
|
+
* import { postgres, string } from 'node-env-resolver/validators';
|
|
13
13
|
*
|
|
14
14
|
* const config = resolve({
|
|
15
15
|
* PORT: 3000, // number with default
|
|
@@ -55,7 +55,7 @@ declare function resolve<T extends SimpleEnvSchema>(config: {
|
|
|
55
55
|
* @example
|
|
56
56
|
* ```typescript
|
|
57
57
|
* import { resolveAsync } from 'node-env-resolver';
|
|
58
|
-
* import { postgres, string } from 'node-env-resolver/
|
|
58
|
+
* import { postgres, string } from 'node-env-resolver/validators';
|
|
59
59
|
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
60
60
|
*
|
|
61
61
|
* // Works with async-only resolvers
|
|
@@ -98,6 +98,14 @@ declare function resolveAsync<T extends SimpleEnvSchema>(config: {
|
|
|
98
98
|
}): Promise<{
|
|
99
99
|
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
100
100
|
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Safe resolve implementation (doesn't throw, returns result object)
|
|
103
|
+
*
|
|
104
|
+
* @param arg1 - Schema object or config object
|
|
105
|
+
* @param arg2 - Optional resolve options
|
|
106
|
+
* @returns Safe resolve result with success/error information
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
101
109
|
declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<T>, arg2?: Partial<ResolveOptions>): SafeResolveResultType<{
|
|
102
110
|
[K in keyof T]: InferSimpleValue<T[K]>;
|
|
103
111
|
}>;
|
|
@@ -108,7 +116,7 @@ declare function safeResolve<T extends SimpleEnvSchema>(arg1: T | ResolveConfig<
|
|
|
108
116
|
* @example
|
|
109
117
|
* ```typescript
|
|
110
118
|
* import { safeResolveAsync } from 'node-env-resolver';
|
|
111
|
-
* import { postgres } from 'node-env-resolver/
|
|
119
|
+
* import { postgres } from 'node-env-resolver/validators';
|
|
112
120
|
* import { awsSecrets, dotenv } from 'node-env-resolver/resolvers';
|
|
113
121
|
*
|
|
114
122
|
* // Works with async resolvers
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as resolve,b as resolveAsync,c as safeResolve,d as safeResolveAsync}from'./chunk-
|
|
1
|
+
export{a as resolve,b as resolveAsync,c as safeResolve,d as safeResolveAsync}from'./chunk-GMQOMCGI.js';import'./chunk-3KAHSFPX.js';export{d as clearAuditLog,c as getAuditLog}from'./chunk-YOHHFBZN.js';import'./chunk-WKIPEKF6.js';export{b as isAsyncOnlyResolver,a as isSyncResolver}from'./chunk-HHOS5S5T.js';import'./chunk-5PELJRUQ.js';
|
package/dist/resolver.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkOSMNJM5N_cjs=require('./chunk-OSMNJM5N.cjs');require('./chunk-4ZOF2PI4.cjs'),require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"normalizeSchema",{enumerable:true,get:function(){return chunkOSMNJM5N_cjs.a}});Object.defineProperty(exports,"resolveEnvInternal",{enumerable:true,get:function(){return chunkOSMNJM5N_cjs.b}});Object.defineProperty(exports,"resolveEnvInternalSync",{enumerable:true,get:function(){return chunkOSMNJM5N_cjs.c}});
|
package/dist/resolver.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-
|
|
1
|
+
export{a as normalizeSchema,b as resolveEnvInternal,c as resolveEnvInternalSync}from'./chunk-3KAHSFPX.js';import'./chunk-YOHHFBZN.js';import'./chunk-5PELJRUQ.js';
|
package/dist/resolvers.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');Object.defineProperty(exports,"dotenv",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.a}});Object.defineProperty(exports,"http",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.c}});Object.defineProperty(exports,"json",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.d}});Object.defineProperty(exports,"packageJson",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.b}});Object.defineProperty(exports,"secrets",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.e}});Object.defineProperty(exports,"toml",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.g}});Object.defineProperty(exports,"yaml",{enumerable:true,get:function(){return chunkPNUGGPRS_cjs.f}});Object.defineProperty(exports,"processEnv",{enumerable:true,get:function(){return chunk4QOKRJ3F_cjs.a}});
|
package/dist/resolvers.d.cts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { SyncResolver, Resolver
|
|
1
|
+
import { SyncResolver, Resolver } from './types.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Resolver that reads from process.env
|
|
5
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
|
+
* ```
|
|
6
16
|
*/
|
|
7
17
|
declare function processEnv(): SyncResolver;
|
|
8
18
|
|
|
@@ -10,10 +20,40 @@ declare function processEnv(): SyncResolver;
|
|
|
10
20
|
* Built-in resolvers for environment variable resolution
|
|
11
21
|
*/
|
|
12
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Options for the dotenv resolver
|
|
25
|
+
*/
|
|
13
26
|
interface DotenvOptions {
|
|
27
|
+
/** Path to the .env file (default: '.env') */
|
|
14
28
|
path?: string;
|
|
29
|
+
/** Enable environment-specific file loading (default: false) */
|
|
15
30
|
expand?: boolean;
|
|
16
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
|
+
*/
|
|
17
57
|
declare function dotenv(options?: string | DotenvOptions): Resolver;
|
|
18
58
|
/**
|
|
19
59
|
* Load configuration from package.json
|
|
@@ -99,6 +139,7 @@ declare function secrets(path?: string): Resolver;
|
|
|
99
139
|
* Requires 'js-yaml' as a peer dependency (install separately for tree-shaking)
|
|
100
140
|
*/
|
|
101
141
|
interface YamlOptions {
|
|
142
|
+
/** Path to the YAML file (default: 'config.yaml') */
|
|
102
143
|
path?: string;
|
|
103
144
|
}
|
|
104
145
|
/**
|
|
@@ -124,6 +165,7 @@ declare function yaml(options?: string | YamlOptions): Resolver;
|
|
|
124
165
|
* Requires 'smol-toml' as a peer dependency (install separately for tree-shaking)
|
|
125
166
|
*/
|
|
126
167
|
interface TomlOptions {
|
|
168
|
+
/** Path to the TOML file (default: 'config.toml') */
|
|
127
169
|
path?: string;
|
|
128
170
|
}
|
|
129
171
|
/**
|
|
@@ -144,269 +186,5 @@ interface TomlOptions {
|
|
|
144
186
|
* ```
|
|
145
187
|
*/
|
|
146
188
|
declare function toml(options?: string | TomlOptions): Resolver;
|
|
147
|
-
declare function string<Opts extends {
|
|
148
|
-
default?: string;
|
|
149
|
-
optional?: boolean;
|
|
150
|
-
min?: number;
|
|
151
|
-
max?: number;
|
|
152
|
-
allowEmpty?: boolean;
|
|
153
|
-
pattern?: string;
|
|
154
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
155
|
-
optional: true;
|
|
156
|
-
} ? Validator<string> & {
|
|
157
|
-
optional: true;
|
|
158
|
-
default?: Opts['default'];
|
|
159
|
-
} : Validator<string> & {
|
|
160
|
-
optional?: Opts['optional'];
|
|
161
|
-
default?: Opts['default'];
|
|
162
|
-
};
|
|
163
|
-
declare function number<Opts extends {
|
|
164
|
-
default?: number;
|
|
165
|
-
optional?: boolean;
|
|
166
|
-
min?: number;
|
|
167
|
-
max?: number;
|
|
168
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
169
|
-
optional: true;
|
|
170
|
-
} ? Validator<number> & {
|
|
171
|
-
optional: true;
|
|
172
|
-
default?: Opts['default'];
|
|
173
|
-
} : Validator<number> & {
|
|
174
|
-
optional?: Opts['optional'];
|
|
175
|
-
default?: Opts['default'];
|
|
176
|
-
};
|
|
177
|
-
declare function boolean<Opts extends {
|
|
178
|
-
default?: boolean;
|
|
179
|
-
optional?: boolean;
|
|
180
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
181
|
-
optional: true;
|
|
182
|
-
} ? Validator<boolean> & {
|
|
183
|
-
optional: true;
|
|
184
|
-
default?: Opts['default'];
|
|
185
|
-
} : Validator<boolean> & {
|
|
186
|
-
optional?: Opts['optional'];
|
|
187
|
-
default?: Opts['default'];
|
|
188
|
-
};
|
|
189
|
-
declare function url<Opts extends {
|
|
190
|
-
default?: string;
|
|
191
|
-
optional?: boolean;
|
|
192
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
193
|
-
optional: true;
|
|
194
|
-
} ? Validator<string> & {
|
|
195
|
-
optional: true;
|
|
196
|
-
default?: Opts['default'];
|
|
197
|
-
} : Validator<string> & {
|
|
198
|
-
optional?: Opts['optional'];
|
|
199
|
-
default?: Opts['default'];
|
|
200
|
-
};
|
|
201
|
-
declare function email<Opts extends {
|
|
202
|
-
default?: string;
|
|
203
|
-
optional?: boolean;
|
|
204
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
205
|
-
optional: true;
|
|
206
|
-
} ? Validator<string> & {
|
|
207
|
-
optional: true;
|
|
208
|
-
default?: Opts['default'];
|
|
209
|
-
} : Validator<string> & {
|
|
210
|
-
optional?: Opts['optional'];
|
|
211
|
-
default?: Opts['default'];
|
|
212
|
-
};
|
|
213
|
-
declare function port<Opts extends {
|
|
214
|
-
default?: number;
|
|
215
|
-
optional?: boolean;
|
|
216
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
217
|
-
optional: true;
|
|
218
|
-
} ? Validator<number> & {
|
|
219
|
-
optional: true;
|
|
220
|
-
default?: Opts['default'];
|
|
221
|
-
} : Validator<number> & {
|
|
222
|
-
optional?: Opts['optional'];
|
|
223
|
-
default?: Opts['default'];
|
|
224
|
-
};
|
|
225
|
-
declare function postgres<Opts extends {
|
|
226
|
-
default?: string;
|
|
227
|
-
optional?: boolean;
|
|
228
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
229
|
-
optional: true;
|
|
230
|
-
} ? Validator<string> & {
|
|
231
|
-
optional: true;
|
|
232
|
-
default?: Opts['default'];
|
|
233
|
-
} : Validator<string> & {
|
|
234
|
-
optional?: Opts['optional'];
|
|
235
|
-
default?: Opts['default'];
|
|
236
|
-
};
|
|
237
|
-
declare function mysql<Opts extends {
|
|
238
|
-
default?: string;
|
|
239
|
-
optional?: boolean;
|
|
240
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
241
|
-
optional: true;
|
|
242
|
-
} ? Validator<string> & {
|
|
243
|
-
optional: true;
|
|
244
|
-
default?: Opts['default'];
|
|
245
|
-
} : Validator<string> & {
|
|
246
|
-
optional?: Opts['optional'];
|
|
247
|
-
default?: Opts['default'];
|
|
248
|
-
};
|
|
249
|
-
declare function mongodb<Opts extends {
|
|
250
|
-
default?: string;
|
|
251
|
-
optional?: boolean;
|
|
252
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
253
|
-
optional: true;
|
|
254
|
-
} ? Validator<string> & {
|
|
255
|
-
optional: true;
|
|
256
|
-
default?: Opts['default'];
|
|
257
|
-
} : Validator<string> & {
|
|
258
|
-
optional?: Opts['optional'];
|
|
259
|
-
default?: Opts['default'];
|
|
260
|
-
};
|
|
261
|
-
declare function redis<Opts extends {
|
|
262
|
-
default?: string;
|
|
263
|
-
optional?: boolean;
|
|
264
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
265
|
-
optional: true;
|
|
266
|
-
} ? Validator<string> & {
|
|
267
|
-
optional: true;
|
|
268
|
-
default?: Opts['default'];
|
|
269
|
-
} : Validator<string> & {
|
|
270
|
-
optional?: Opts['optional'];
|
|
271
|
-
default?: Opts['default'];
|
|
272
|
-
};
|
|
273
|
-
declare function https<Opts extends {
|
|
274
|
-
default?: string;
|
|
275
|
-
optional?: boolean;
|
|
276
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
277
|
-
optional: true;
|
|
278
|
-
} ? Validator<string> & {
|
|
279
|
-
optional: true;
|
|
280
|
-
default?: Opts['default'];
|
|
281
|
-
} : Validator<string> & {
|
|
282
|
-
optional?: Opts['optional'];
|
|
283
|
-
default?: Opts['default'];
|
|
284
|
-
};
|
|
285
|
-
declare function stringArray<Opts extends {
|
|
286
|
-
default?: string[];
|
|
287
|
-
optional?: boolean;
|
|
288
|
-
separator?: string;
|
|
289
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
290
|
-
optional: true;
|
|
291
|
-
} ? Validator<string[]> & {
|
|
292
|
-
optional: true;
|
|
293
|
-
default?: Opts['default'];
|
|
294
|
-
} : Validator<string[]> & {
|
|
295
|
-
optional?: Opts['optional'];
|
|
296
|
-
default?: Opts['default'];
|
|
297
|
-
};
|
|
298
|
-
declare function numberArray<Opts extends {
|
|
299
|
-
default?: number[];
|
|
300
|
-
optional?: boolean;
|
|
301
|
-
separator?: string;
|
|
302
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
303
|
-
optional: true;
|
|
304
|
-
} ? Validator<number[]> & {
|
|
305
|
-
optional: true;
|
|
306
|
-
default?: Opts['default'];
|
|
307
|
-
} : Validator<number[]> & {
|
|
308
|
-
optional?: Opts['optional'];
|
|
309
|
-
default?: Opts['default'];
|
|
310
|
-
};
|
|
311
|
-
declare function urlArray<Opts extends {
|
|
312
|
-
default?: string[];
|
|
313
|
-
optional?: boolean;
|
|
314
|
-
separator?: string;
|
|
315
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
316
|
-
optional: true;
|
|
317
|
-
} ? Validator<string[]> & {
|
|
318
|
-
optional: true;
|
|
319
|
-
default?: Opts['default'];
|
|
320
|
-
} : Validator<string[]> & {
|
|
321
|
-
optional?: Opts['optional'];
|
|
322
|
-
default?: Opts['default'];
|
|
323
|
-
};
|
|
324
|
-
declare function enums<T extends readonly (string | number)[], Opts extends {
|
|
325
|
-
default?: T[number];
|
|
326
|
-
optional?: boolean;
|
|
327
|
-
} = Record<string, never>>(values: T, opts?: Opts): Opts extends {
|
|
328
|
-
optional: true;
|
|
329
|
-
} ? Validator<T[number]> & {
|
|
330
|
-
optional: true;
|
|
331
|
-
default?: Opts['default'];
|
|
332
|
-
} : Validator<T[number]> & {
|
|
333
|
-
optional?: Opts['optional'];
|
|
334
|
-
default?: Opts['default'];
|
|
335
|
-
};
|
|
336
|
-
declare function duration<Opts extends {
|
|
337
|
-
default?: number;
|
|
338
|
-
optional?: boolean;
|
|
339
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
340
|
-
optional: true;
|
|
341
|
-
} ? Validator<number> & {
|
|
342
|
-
optional: true;
|
|
343
|
-
default?: Opts['default'];
|
|
344
|
-
} : Validator<number> & {
|
|
345
|
-
optional?: Opts['optional'];
|
|
346
|
-
default?: Opts['default'];
|
|
347
|
-
};
|
|
348
|
-
declare function file<Opts extends {
|
|
349
|
-
default?: string;
|
|
350
|
-
optional?: boolean;
|
|
351
|
-
secretsDir?: string;
|
|
352
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
353
|
-
optional: true;
|
|
354
|
-
} ? Validator<string> & {
|
|
355
|
-
optional: true;
|
|
356
|
-
default?: Opts['default'];
|
|
357
|
-
secretsDir?: Opts['secretsDir'];
|
|
358
|
-
} : Validator<string> & {
|
|
359
|
-
optional?: Opts['optional'];
|
|
360
|
-
default?: Opts['default'];
|
|
361
|
-
secretsDir?: Opts['secretsDir'];
|
|
362
|
-
};
|
|
363
|
-
declare function secret<Opts extends {
|
|
364
|
-
default?: string;
|
|
365
|
-
optional?: boolean;
|
|
366
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
367
|
-
optional: true;
|
|
368
|
-
} ? Validator<string> & {
|
|
369
|
-
optional: true;
|
|
370
|
-
default?: Opts['default'];
|
|
371
|
-
} : Validator<string> & {
|
|
372
|
-
optional?: Opts['optional'];
|
|
373
|
-
default?: Opts['default'];
|
|
374
|
-
};
|
|
375
|
-
declare function custom<T = unknown, Opts extends {
|
|
376
|
-
default?: T;
|
|
377
|
-
optional?: boolean;
|
|
378
|
-
} = Record<string, never>>(validator: (value: string) => T, opts?: Opts): Opts extends {
|
|
379
|
-
optional: true;
|
|
380
|
-
} ? Validator<T> & {
|
|
381
|
-
optional: true;
|
|
382
|
-
default?: Opts['default'];
|
|
383
|
-
} : Validator<T> & {
|
|
384
|
-
optional?: Opts['optional'];
|
|
385
|
-
default?: Opts['default'];
|
|
386
|
-
};
|
|
387
|
-
declare function date<Opts extends {
|
|
388
|
-
default?: string;
|
|
389
|
-
optional?: boolean;
|
|
390
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
391
|
-
optional: true;
|
|
392
|
-
} ? Validator<string> & {
|
|
393
|
-
optional: true;
|
|
394
|
-
default?: Opts['default'];
|
|
395
|
-
} : Validator<string> & {
|
|
396
|
-
optional?: Opts['optional'];
|
|
397
|
-
default?: Opts['default'];
|
|
398
|
-
};
|
|
399
|
-
declare function timestamp<Opts extends {
|
|
400
|
-
default?: number;
|
|
401
|
-
optional?: boolean;
|
|
402
|
-
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
403
|
-
optional: true;
|
|
404
|
-
} ? Validator<number> & {
|
|
405
|
-
optional: true;
|
|
406
|
-
default?: Opts['default'];
|
|
407
|
-
} : Validator<number> & {
|
|
408
|
-
optional?: Opts['optional'];
|
|
409
|
-
default?: Opts['default'];
|
|
410
|
-
};
|
|
411
189
|
|
|
412
|
-
export { type DotenvOptions, type TomlOptions, type YamlOptions,
|
|
190
|
+
export { type DotenvOptions, type TomlOptions, type YamlOptions, dotenv, http, json, packageJson, processEnv, secrets, toml, yaml };
|