node-env-resolver 6.0.0 → 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 +29 -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-OSMNJM5N.cjs +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/web.cjs +3 -3
- package/dist/web.js +1 -1
- package/package.json +25 -13
- package/dist/chunk-4YVXFL3I.cjs +0 -9
- package/dist/chunk-DIXI6MUB.js +0 -9
package/README.md
CHANGED
|
@@ -1625,6 +1625,35 @@ if (policyViolations.length > 0) {
|
|
|
1625
1625
|
}
|
|
1626
1626
|
```
|
|
1627
1627
|
|
|
1628
|
+
## Troubleshooting
|
|
1629
|
+
|
|
1630
|
+
### TypeScript: Cannot find module 'node-env-resolver/validators'
|
|
1631
|
+
|
|
1632
|
+
If you're using `moduleResolution: "bundler"` in your `tsconfig.json` and TypeScript can't resolve subpath exports like `node-env-resolver/validators`, this is a known TypeScript limitation (see [TypeScript issue #55337](https://github.com/microsoft/TypeScript/issues/55337)).
|
|
1633
|
+
|
|
1634
|
+
**Workaround options:**
|
|
1635
|
+
|
|
1636
|
+
1. **Use `moduleResolution: "NodeNext"`** (recommended for most projects):
|
|
1637
|
+
```json
|
|
1638
|
+
{
|
|
1639
|
+
"compilerOptions": {
|
|
1640
|
+
"moduleResolution": "NodeNext",
|
|
1641
|
+
"module": "NodeNext"
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
```
|
|
1645
|
+
|
|
1646
|
+
2. **Use `moduleResolution: "Node"`** (legacy but widely supported):
|
|
1647
|
+
```json
|
|
1648
|
+
{
|
|
1649
|
+
"compilerOptions": {
|
|
1650
|
+
"moduleResolution": "Node"
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
```
|
|
1654
|
+
|
|
1655
|
+
**Note:** The runtime will work correctly regardless of TypeScript's resolution mode. This is purely a TypeScript type-checking issue, not a runtime problem.
|
|
1656
|
+
|
|
1628
1657
|
## Error messages
|
|
1629
1658
|
|
|
1630
1659
|
The library provides clear, actionable error messages:
|
package/dist/builder.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),
|
|
1
|
+
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),chunkOSMNJM5N_cjs=require('./chunk-OSMNJM5N.cjs');require('./chunk-4ZOF2PI4.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=chunkOSMNJM5N_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkOSMNJM5N_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkOSMNJM5N_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkPNUGGPRS_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=chunkOSMNJM5N_cjs.a(this.localSchema);for(let l of this.layers){let m=chunkOSMNJM5N_cjs.a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a=this.options.extend||[],c=[...s,...r,...a],u=this.options.policies??{};return chunkOSMNJM5N_cjs.c(e,c,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(chunkPNUGGPRS_cjs.a({expand:true})),s.push(chunk4QOKRJ3F_cjs.a()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};exports.EnvBuilder=i;exports.EnvBuilderSync=n;exports.ResolvableBuilder=d;exports.ResolvableBuilderSync=S;exports.env=y;exports.envSync=b;
|
package/dist/builder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-LCW5BDAW.js';import {a,c}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-LCW5BDAW.js';import {a,c}from'./chunk-3KAHSFPX.js';import'./chunk-YOHHFBZN.js';import {a as a$2}from'./chunk-WKIPEKF6.js';import'./chunk-5PELJRUQ.js';var i=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolve(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}},n=class{constructor(e,s={}){this.localSchema=e;this.options=s;}layers=[];from(e,s){return this.layers.push({resolver:e,schema:s}),this}resolveSync(){let e=a(this.localSchema);for(let l of this.layers){let m=a(l.schema);Object.assign(e,m);}let s=this.buildDefaultResolvers(),r=this.layers.map(l=>l.resolver),a$1=this.options.extend||[],c$1=[...s,...r,...a$1],u=this.options.policies??{};return c(e,c$1,{...this.options,policies:u,interpolate:this.options.interpolate??true,strict:this.options.strict??true})}buildDefaultResolvers(){let e=process.env.NODE_ENV==="production",s=[];return e||s.push(a$1({expand:true})),s.push(a$2()),s}};function y(t,e){return new i(t,e)}function b(t,e){return new n(t,e)}var d=class{builder;simpleResolve=null;constructor(e,s={}){this.builder=new i(e,s);}from(e,s){return this.builder.from(e,s),this}async compose(){return this.builder.resolve()}then(e,s){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.then(e,s)}catch(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.catch(e)}finally(e){return this.simpleResolve||(this.simpleResolve=Promise.resolve(this.builder.resolve())),this.simpleResolve.finally(e)}},S=class{builder;_resolved=null;_hasComposition=false;constructor(e,s={}){Object.defineProperty(this,"builder",{value:new n(e,s),enumerable:false,writable:true}),Object.defineProperty(this,"_hasComposition",{value:false,enumerable:false,writable:true});let r=this.builder.resolveSync();Object.defineProperty(this,"_resolved",{value:r,enumerable:false,writable:true}),Object.assign(this,r);}from(e,s){return Object.defineProperty(this,"_hasComposition",{value:true,enumerable:false,writable:true}),this.builder.from(e,s),this}compose(){return this._hasComposition&&(this._resolved=this.builder.resolveSync(),Object.assign(this,this._resolved)),this._resolved}valueOf(){return this._resolved}toJSON(){return this._resolved}};export{i as EnvBuilder,n as EnvBuilderSync,d as ResolvableBuilder,S as ResolvableBuilderSync,y as env,b as envSync};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {f,e}from'./chunk-YOHHFBZN.js';import {d}from'./chunk-5PELJRUQ.js';import {join,resolve}from'path';import {readFileSync}from'fs';function C(s,c){try{let r=resolve(process.cwd(),s);return {valid:!0,value: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.js');D=c.logAuditEvent,h=c.attachAuditSession;}D(s);}function b(s){if(!D)try{let c=(f(),d(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.js');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=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$1}=r,f$1={},u;if(n){if(!h)try{let e$1=(f(),d(e));D=e$1.logAuditEvent,h=e$1.attachAuditSession;}catch{}h&&(u=h(f$1));}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$1;if(p.type==="file"&&v){let j=e.toLowerCase().replace(/_/g,"-"),P=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$1[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$1,r.nestedDelimiter):f$1}export{U as a,G as b,H as c};
|
|
@@ -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,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;
|
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.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/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk5E2SZR3V_cjs=require('./chunk-5E2SZR3V.cjs');require('./chunk-OSMNJM5N.cjs'),require('./chunk-4ZOF2PI4.cjs'),require('./chunk-4QOKRJ3F.cjs'),require('./chunk-6D5APQIG.cjs');var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs');function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a=null,i=[],d=async()=>{try{return await import('./index.cjs'),t=await chunk5E2SZR3V_cjs.b(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a&&clearTimeout(a),a=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=chunkKIQXH265_cjs.a("fs"),{join:y}=chunkKIQXH265_cjs.a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a&&clearTimeout(a);for(let c of i)c.close();}}}exports.TTL=p;exports.awsCache=C;exports.cached=T;exports.retry=b;exports.watch=v;exports.withAliases=$;exports.withComputed=P;exports.withNamespace=k;exports.withPrefix=x;exports.withTransform=S;
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b as b$1}from'./chunk-
|
|
1
|
+
import {b as b$1}from'./chunk-GMQOMCGI.js';import'./chunk-3KAHSFPX.js';import'./chunk-YOHHFBZN.js';import'./chunk-WKIPEKF6.js';import'./chunk-HHOS5S5T.js';import {a}from'./chunk-5PELJRUQ.js';function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a$1=null,i=[],d=async()=>{try{return await import('./index.js'),t=await b$1(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a$1&&clearTimeout(a$1),a$1=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=a("fs"),{join:y}=a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a$1&&clearTimeout(a$1);for(let c of i)c.close();}}}export{p as TTL,C as awsCache,T as cached,b as retry,v as watch,$ as withAliases,P as withComputed,k as withNamespace,x as withPrefix,S as withTransform};
|
package/dist/web.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),
|
|
2
|
-
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await
|
|
1
|
+
'use strict';var chunkPNUGGPRS_cjs=require('./chunk-PNUGGPRS.cjs'),chunk5E2SZR3V_cjs=require('./chunk-5E2SZR3V.cjs');require('./chunk-OSMNJM5N.cjs'),require('./chunk-4ZOF2PI4.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-6D5APQIG.cjs'),require('./chunk-KIQXH265.cjs');var h=()=>typeof globalThis.window<"u";async function u(r,v={}){let{resolvers:o=[chunk4QOKRJ3F_cjs.a()],clientPrefix:e="PUBLIC_",strict:m=true}=v,l=Object.keys(r).filter(n=>!n.startsWith(e));if(h()&&l.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${l.join(", ")}
|
|
2
|
+
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await chunk5E2SZR3V_cjs.b({resolvers:f,options:{strict:m}})}async function E(r,v={}){let{resolvers:o=[chunkPNUGGPRS_cjs.a({expand:true}),chunk4QOKRJ3F_cjs.a()],clientPrefix:e="PUBLIC_",policies:m,interpolate:l,strict:i}=v,s=Object.keys(r.client).filter(t=>!t.startsWith(e));if(s.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${s.join(", ")}
|
|
3
3
|
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);let c=Object.keys(r.server).filter(t=>t.startsWith(e));if(c.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${c.join(", ")}
|
|
4
|
-
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await
|
|
4
|
+
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await chunk5E2SZR3V_cjs.b({resolvers:x,options:{policies:m,interpolate:l,strict:i}}),d=o.map(t=>[t,r.client]),y=await chunk5E2SZR3V_cjs.b({resolvers:d,options:{strict:i}});return {server:T,client:y}}h()&&process.env.NODE_ENV==="development"&&console.warn(`\u{1F310} node-env-resolver/web: Running in browser context
|
|
5
5
|
Only variables with your configured prefix will be accessible
|
|
6
6
|
Server-only variables are blocked for security`);exports.resolveClientEnv=u;exports.resolveEnvSplit=E;
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-LCW5BDAW.js';import {b}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-LCW5BDAW.js';import {b}from'./chunk-GMQOMCGI.js';import'./chunk-3KAHSFPX.js';import'./chunk-YOHHFBZN.js';import {a}from'./chunk-WKIPEKF6.js';import'./chunk-HHOS5S5T.js';import'./chunk-5PELJRUQ.js';var h=()=>typeof globalThis.window<"u";async function u(r,v={}){let{resolvers:o=[a()],clientPrefix:e="PUBLIC_",strict:m=true}=v,l=Object.keys(r).filter(n=>!n.startsWith(e));if(h()&&l.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${l.join(", ")}
|
|
2
2
|
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(r))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await b({resolvers:f,options:{strict:m}})}async function E(r,v={}){let{resolvers:o=[a$1({expand:true}),a()],clientPrefix:e="PUBLIC_",policies:m,interpolate:l,strict:i}=v,s=Object.keys(r.client).filter(t=>!t.startsWith(e));if(s.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${s.join(", ")}
|
|
3
3
|
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);let c=Object.keys(r.server).filter(t=>t.startsWith(e));if(c.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${c.join(", ")}
|
|
4
4
|
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(t=>[t,r.server]),T=await b({resolvers:x,options:{policies:m,interpolate:l,strict:i}}),d=o.map(t=>[t,r.client]),y=await b({resolvers:d,options:{strict:i}});return {server:T,client:y}}h()&&process.env.NODE_ENV==="development"&&console.warn(`\u{1F310} node-env-resolver/web: Running in browser context
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-env-resolver",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Type-safe environment variable resolver with async resolvers - lightweight, tree-shakeable, no dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,62 +9,74 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.js"
|
|
13
14
|
},
|
|
14
15
|
"./builder": {
|
|
15
16
|
"types": "./dist/builder.d.ts",
|
|
16
17
|
"import": "./dist/builder.js",
|
|
17
|
-
"require": "./dist/builder.cjs"
|
|
18
|
+
"require": "./dist/builder.cjs",
|
|
19
|
+
"default": "./dist/builder.js"
|
|
18
20
|
},
|
|
19
21
|
"./zod": {
|
|
20
22
|
"types": "./dist/zod.d.ts",
|
|
21
23
|
"import": "./dist/zod.js",
|
|
22
|
-
"require": "./dist/zod.cjs"
|
|
24
|
+
"require": "./dist/zod.cjs",
|
|
25
|
+
"default": "./dist/zod.js"
|
|
23
26
|
},
|
|
24
27
|
"./valibot": {
|
|
25
28
|
"types": "./dist/valibot.d.ts",
|
|
26
29
|
"import": "./dist/valibot.js",
|
|
27
|
-
"require": "./dist/valibot.cjs"
|
|
30
|
+
"require": "./dist/valibot.cjs",
|
|
31
|
+
"default": "./dist/valibot.js"
|
|
28
32
|
},
|
|
29
33
|
"./web": {
|
|
30
34
|
"types": "./dist/web.d.ts",
|
|
31
35
|
"import": "./dist/web.js",
|
|
32
|
-
"require": "./dist/web.cjs"
|
|
36
|
+
"require": "./dist/web.cjs",
|
|
37
|
+
"default": "./dist/web.js"
|
|
33
38
|
},
|
|
34
39
|
"./resolvers": {
|
|
35
40
|
"types": "./dist/resolvers.d.ts",
|
|
36
41
|
"import": "./dist/resolvers.js",
|
|
37
|
-
"require": "./dist/resolvers.cjs"
|
|
42
|
+
"require": "./dist/resolvers.cjs",
|
|
43
|
+
"default": "./dist/resolvers.js"
|
|
38
44
|
},
|
|
39
45
|
"./validators": {
|
|
40
46
|
"types": "./dist/validators.d.ts",
|
|
41
47
|
"import": "./dist/validators.js",
|
|
42
|
-
"require": "./dist/validators.cjs"
|
|
48
|
+
"require": "./dist/validators.cjs",
|
|
49
|
+
"default": "./dist/validators.js"
|
|
43
50
|
},
|
|
44
51
|
"./utils": {
|
|
45
52
|
"types": "./dist/utils.d.ts",
|
|
46
53
|
"import": "./dist/utils.js",
|
|
47
|
-
"require": "./dist/utils.cjs"
|
|
54
|
+
"require": "./dist/utils.cjs",
|
|
55
|
+
"default": "./dist/utils.js"
|
|
48
56
|
},
|
|
49
57
|
"./cli": {
|
|
50
58
|
"types": "./dist/cli.d.ts",
|
|
51
59
|
"import": "./dist/cli.js",
|
|
52
|
-
"require": "./dist/cli.cjs"
|
|
60
|
+
"require": "./dist/cli.cjs",
|
|
61
|
+
"default": "./dist/cli.js"
|
|
53
62
|
},
|
|
54
63
|
"./audit": {
|
|
55
64
|
"types": "./dist/audit.d.ts",
|
|
56
65
|
"import": "./dist/audit.js",
|
|
57
|
-
"require": "./dist/audit.cjs"
|
|
66
|
+
"require": "./dist/audit.cjs",
|
|
67
|
+
"default": "./dist/audit.js"
|
|
58
68
|
},
|
|
59
69
|
"./resolver": {
|
|
60
70
|
"types": "./dist/resolver.d.ts",
|
|
61
71
|
"import": "./dist/resolver.js",
|
|
62
|
-
"require": "./dist/resolver.cjs"
|
|
72
|
+
"require": "./dist/resolver.cjs",
|
|
73
|
+
"default": "./dist/resolver.js"
|
|
63
74
|
},
|
|
64
75
|
"./types": {
|
|
65
76
|
"types": "./dist/types.d.ts",
|
|
66
77
|
"import": "./dist/types.js",
|
|
67
|
-
"require": "./dist/types.cjs"
|
|
78
|
+
"require": "./dist/types.cjs",
|
|
79
|
+
"default": "./dist/types.js"
|
|
68
80
|
}
|
|
69
81
|
},
|
|
70
82
|
"files": [
|
package/dist/chunk-4YVXFL3I.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use strict';var chunk4ZOF2PI4_cjs=require('./chunk-4ZOF2PI4.cjs'),chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs'),path=require('path'),fs=require('fs');function C(a,i){try{let n=path.resolve(process.cwd(),a);return {valid:!0,value:fs.readFileSync(n,"utf8").trim()}}catch(n){return {valid:false,error:`Failed to read file${i?` for ${i}`:""}: ${n instanceof Error?n.message:String(n)}`}}}var b=null,h=null;async function E(a){if(!b){let i=await import('./audit.cjs');b=i.logAuditEvent,h=i.attachAuditSession;}b(a);}function D(a){if(!b)try{let i=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));b=i.logAuditEvent,h=i.attachAuditSession;}catch{return}b&&b(a);}function U(a){let i={};for(let[n,r]of Object.entries(a))if(typeof r=="function"){let l=r,t=l.__isFileValidator===true;i[n]={type:t?"file":"custom",validator:r,...l.default!==void 0&&{default:l.default},...l.optional!==void 0&&{optional:l.optional},...l.secretsDir!==void 0&&{secretsDir:l.secretsDir}};}else if(typeof r=="string"){let l=["string","number","boolean","port","url","email","postgres","mysql","mongodb","redis","http","https","json","date","timestamp","duration","file"];if(r.endsWith("?")){let t=r.slice(0,-1);l.includes(t)?i[n]={type:t,optional:true}:i[n]={type:"string",optional:true};}else if(r.includes(":")){let[t,m]=r.split(":",2);i[n]={type:t,default:m};}else l.includes(r)?i[n]={type:r}:i[n]={type:"string",default:r,validator:t=>{if(t===""&&!i[n].allowEmpty)throw new Error("String cannot be empty");return t}};}else if(typeof r=="number")i[n]={type:"number",default:r,validator:l=>{let t=Number(l);if(isNaN(t))throw new Error(`Invalid number: "${l}"`);return t}};else if(typeof r=="boolean")i[n]={type:"boolean",default:r,validator:l=>{let t=l.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${l}"`)}};else if(Array.isArray(r)){let l=r.map(String);i[n]={type:"string",enum:l,validator:(t,m)=>{if(!l.includes(t)){let o=m||n;throw new Error(`${o} must be one of: ${l.join(", ")}`)}return t}};}else i[n]=r;return i}function T(a,i){return a.replace(/\$\{([^}]+)\}/g,(n,r)=>i[r]||n)}async function B(a,i,n,r="last",l){let t={},m={};if(r==="last"){let o=await Promise.allSettled(a.map(async s=>({resolver:s,env:s.load?await s.load():{}})));for(let s of o){if(s.status==="rejected"){let u=s.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),n)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=s.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 o of a)try{let s=o.load?await o.load():{};for(let[d,f]of Object.entries(s))if(f!==void 0){if(t[d]!==void 0)continue;t[d]=f,m[d]={source:o.name||"unknown",timestamp:Date.now(),...o.metadata?.cached!==void 0&&{cached:!!o.metadata.cached}};}if(l&&l.size>0&&Array.from(l).every(f=>t[f]!==void 0))break}catch(s){if(await E({type:"resolver_error",timestamp:Date.now(),source:o.name,error:s instanceof Error?s.message:String(s)}),n)throw new Error(`Resolver ${o.name} failed: ${s instanceof Error?s.message:s}`)}if(i)for(let[o,s]of Object.entries(t))t[o]=T(s,t);return {mergedEnv:t,provenance:m}}function W(a,i,n,r="last",l){let t={},m={};for(let o of a)try{if(!o.loadSync){if(n)throw new Error(`Resolver ${o.name} has no loadSync() method`);continue}let s=o.loadSync();for(let[d,f]of Object.entries(s))if(f!==void 0){if(r==="first"&&t[d]!==void 0)continue;t[d]=f,m[d]={source:o.name||"unknown",timestamp:Date.now(),...o.metadata?.cached!==void 0&&{cached:!!o.metadata.cached}};}if(r==="first"&&l&&l.size>0&&Array.from(l).every(f=>t[f]!==void 0))break}catch(s){if(D({type:"resolver_error",timestamp:Date.now(),source:o.name,error:s instanceof Error?s.message:String(s)}),n)throw new Error(`Resolver ${o.name} failed: ${s instanceof Error?s.message:s}`)}if(i)for(let[o,s]of Object.entries(t))t[o]=T(s,t);return {mergedEnv:t,provenance:m}}function L(a,i,n,r){if(!r)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&n&&n.source.startsWith("dotenv(")){let t=r.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(a)?null:`${a} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${a}'] or set to true for all.`:`${a} 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(r.enforceAllowedSources&&r.enforceAllowedSources[a]&&n){let t=r.enforceAllowedSources[a];if(!t.includes(n.source))return `${a} must be sourced from one of: ${t.join(", ")} (actual: ${n.source})`}return null}function x(a){let i=[],n=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let r of Object.keys(a))n.test(r)||i.push(`Invalid environment variable name: "${r}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return i}function z(a,i){let n={};for(let[r,l]of Object.entries(a)){if(!r.includes(i)){n[r]=l;continue}let t=r.split(i),m=n;for(let s=0;s<t.length-1;s++){let d=t[s].toLowerCase();d in m||(m[d]={}),m=m[d];}let o=t[t.length-1].toLowerCase();m[o]=l;}return n}async function G(a,i,n){let r=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:l=false,strict:t=true,policies:m,enableAudit:o=r,priority:s="last",secretsDir:d}=n,f={},u;if(o){if(!h){let e=await import('./audit.cjs');b=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(a);if(y.length>0)throw o&&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(a)),{mergedEnv:A,provenance:w}=await B(i,l,t,s,k),g=[];for(let[e,j]of Object.entries(a)){let p=j,$=A[e],S=L(e,p,w[e],m);if(S){g.push(S),o&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,_),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,o&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),o&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),o&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw o&&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 o&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(a).length},sessionId:u}),n.nestedDelimiter?z(f,n.nestedDelimiter):f}function H(a,i,n){let r=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:l=false,strict:t=true,policies:m,enableAudit:o=r,priority:s="last",secretsDir:d}=n,f={},u;if(o){if(!h)try{let e=(chunk4ZOF2PI4_cjs.f(),chunkKIQXH265_cjs.d(chunk4ZOF2PI4_cjs.e));b=e.logAuditEvent,h=e.attachAuditSession;}catch{}h&&(u=h(f));}let y=x(a);if(y.length>0)throw o&&D({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(a)),{mergedEnv:A,provenance:w}=W(i,l,t,s,k),g=[];for(let[e,j]of Object.entries(a)){let p=j,$=A[e],S=L(e,p,w[e],m);if(S){g.push(S),o&&D({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),P=path.join(v,_),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,o&&D({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),o&&D({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),o&&D({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw o&&D({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 o&&D({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(a).length},sessionId:u}),n.nestedDelimiter?z(f,n.nestedDelimiter):f}exports.a=U;exports.b=G;exports.c=H;
|
package/dist/chunk-DIXI6MUB.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {f,e}from'./chunk-YOHHFBZN.js';import {d}from'./chunk-5PELJRUQ.js';import {join,resolve}from'path';import {readFileSync}from'fs';function C(a,i){try{let n=resolve(process.cwd(),a);return {valid:!0,value:readFileSync(n,"utf8").trim()}}catch(n){return {valid:false,error:`Failed to read file${i?` for ${i}`:""}: ${n instanceof Error?n.message:String(n)}`}}}var b=null,h=null;async function E(a){if(!b){let i=await import('./audit.js');b=i.logAuditEvent,h=i.attachAuditSession;}b(a);}function D(a){if(!b)try{let i=(f(),d(e));b=i.logAuditEvent,h=i.attachAuditSession;}catch{return}b&&b(a);}function U(a){let i={};for(let[n,r]of Object.entries(a))if(typeof r=="function"){let l=r,t=l.__isFileValidator===true;i[n]={type:t?"file":"custom",validator:r,...l.default!==void 0&&{default:l.default},...l.optional!==void 0&&{optional:l.optional},...l.secretsDir!==void 0&&{secretsDir:l.secretsDir}};}else if(typeof r=="string"){let l=["string","number","boolean","port","url","email","postgres","mysql","mongodb","redis","http","https","json","date","timestamp","duration","file"];if(r.endsWith("?")){let t=r.slice(0,-1);l.includes(t)?i[n]={type:t,optional:true}:i[n]={type:"string",optional:true};}else if(r.includes(":")){let[t,m]=r.split(":",2);i[n]={type:t,default:m};}else l.includes(r)?i[n]={type:r}:i[n]={type:"string",default:r,validator:t=>{if(t===""&&!i[n].allowEmpty)throw new Error("String cannot be empty");return t}};}else if(typeof r=="number")i[n]={type:"number",default:r,validator:l=>{let t=Number(l);if(isNaN(t))throw new Error(`Invalid number: "${l}"`);return t}};else if(typeof r=="boolean")i[n]={type:"boolean",default:r,validator:l=>{let t=l.toLowerCase();if(["true","1","yes","on"].includes(t))return true;if(["false","0","no","off",""].includes(t))return false;throw new Error(`Invalid boolean: "${l}"`)}};else if(Array.isArray(r)){let l=r.map(String);i[n]={type:"string",enum:l,validator:(t,m)=>{if(!l.includes(t)){let o=m||n;throw new Error(`${o} must be one of: ${l.join(", ")}`)}return t}};}else i[n]=r;return i}function T(a,i){return a.replace(/\$\{([^}]+)\}/g,(n,r)=>i[r]||n)}async function B(a,i,n,r="last",l){let t={},m={};if(r==="last"){let o=await Promise.allSettled(a.map(async s=>({resolver:s,env:s.load?await s.load():{}})));for(let s of o){if(s.status==="rejected"){let u=s.reason;if(await E({type:"resolver_error",timestamp:Date.now(),source:"unknown",error:u instanceof Error?u.message:String(u)}),n)throw new Error(`Resolver failed: ${u instanceof Error?u.message:u}`);continue}let{resolver:d,env:f}=s.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 o of a)try{let s=o.load?await o.load():{};for(let[d,f]of Object.entries(s))if(f!==void 0){if(t[d]!==void 0)continue;t[d]=f,m[d]={source:o.name||"unknown",timestamp:Date.now(),...o.metadata?.cached!==void 0&&{cached:!!o.metadata.cached}};}if(l&&l.size>0&&Array.from(l).every(f=>t[f]!==void 0))break}catch(s){if(await E({type:"resolver_error",timestamp:Date.now(),source:o.name,error:s instanceof Error?s.message:String(s)}),n)throw new Error(`Resolver ${o.name} failed: ${s instanceof Error?s.message:s}`)}if(i)for(let[o,s]of Object.entries(t))t[o]=T(s,t);return {mergedEnv:t,provenance:m}}function W(a,i,n,r="last",l){let t={},m={};for(let o of a)try{if(!o.loadSync){if(n)throw new Error(`Resolver ${o.name} has no loadSync() method`);continue}let s=o.loadSync();for(let[d,f]of Object.entries(s))if(f!==void 0){if(r==="first"&&t[d]!==void 0)continue;t[d]=f,m[d]={source:o.name||"unknown",timestamp:Date.now(),...o.metadata?.cached!==void 0&&{cached:!!o.metadata.cached}};}if(r==="first"&&l&&l.size>0&&Array.from(l).every(f=>t[f]!==void 0))break}catch(s){if(D({type:"resolver_error",timestamp:Date.now(),source:o.name,error:s instanceof Error?s.message:String(s)}),n)throw new Error(`Resolver ${o.name} failed: ${s instanceof Error?s.message:s}`)}if(i)for(let[o,s]of Object.entries(t))t[o]=T(s,t);return {mergedEnv:t,provenance:m}}function L(a,i,n,r){if(!r)return null;if((process.env.NODE_ENV||"").toLowerCase()==="production"&&n&&n.source.startsWith("dotenv(")){let t=r.allowDotenvInProduction;return t===true?null:Array.isArray(t)?t.includes(a)?null:`${a} cannot be sourced from .env files in production. Use process.env or cloud resolvers. To allow: policies.allowDotenvInProduction: ['${a}'] or set to true for all.`:`${a} 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(r.enforceAllowedSources&&r.enforceAllowedSources[a]&&n){let t=r.enforceAllowedSources[a];if(!t.includes(n.source))return `${a} must be sourced from one of: ${t.join(", ")} (actual: ${n.source})`}return null}function x(a){let i=[],n=/^[A-Za-z_][A-Za-z0-9_]*$/;for(let r of Object.keys(a))n.test(r)||i.push(`Invalid environment variable name: "${r}". Environment variable names must contain only letters, numbers, and underscores, and cannot start with a number.`);return i}function z(a,i){let n={};for(let[r,l]of Object.entries(a)){if(!r.includes(i)){n[r]=l;continue}let t=r.split(i),m=n;for(let s=0;s<t.length-1;s++){let d=t[s].toLowerCase();d in m||(m[d]={}),m=m[d];}let o=t[t.length-1].toLowerCase();m[o]=l;}return n}async function G(a,i,n){let r=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:l=false,strict:t=true,policies:m,enableAudit:o=r,priority:s="last",secretsDir:d}=n,f={},u;if(o){if(!h){let e=await import('./audit.js');b=e.logAuditEvent,h=e.attachAuditSession;}h&&(u=h(f));}let y=x(a);if(y.length>0)throw o&&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(a)),{mergedEnv:A,provenance:w}=await B(i,l,t,s,k),g=[];for(let[e,j]of Object.entries(a)){let p=j,$=A[e],S=L(e,p,w[e],m);if(S){g.push(S),o&&E({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),P=join(v,_),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f[e]=c.value,o&&await E({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),o&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),o&&await E({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw o&&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 o&&await E({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(a).length},sessionId:u}),n.nestedDelimiter?z(f,n.nestedDelimiter):f}function H(a,i,n){let r=(process.env.NODE_ENV||"").toLowerCase()==="production",{interpolate:l=false,strict:t=true,policies:m,enableAudit:o=r,priority:s="last",secretsDir:d$1}=n,f$1={},u;if(o){if(!h)try{let e$1=(f(),d(e));b=e$1.logAuditEvent,h=e$1.attachAuditSession;}catch{}h&&(u=h(f$1));}let y=x(a);if(y.length>0)throw o&&D({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(a)),{mergedEnv:A,provenance:w}=W(i,l,t,s,k),g=[];for(let[e,j]of Object.entries(a)){let p=j,$=A[e],S=L(e,p,w[e],m);if(S){g.push(S),o&&D({type:"policy_violation",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",error:S,sessionId:u});continue}try{let c;if($===void 0){let v=p.secretsDir??d$1;if(p.type==="file"&&v){let _=e.toLowerCase().replace(/_/g,"-"),P=join(v,_),R=C(P,e);R.valid?(c={success:!0,value:R.value},w[e]={source:`secretsDir(${v})`,timestamp:Date.now()}):c={success:!1,error:R.error??`Failed to read secret for ${e}`};}else p.default!==void 0?c={success:!0,value:p.default}:p.optional?c={success:!0,value:void 0}:c={success:!1,error:`Missing required environment variable: ${e}`};}else if(p.validator)try{c={success:!0,value:p.validator($,e)};}catch(v){c={success:!1,error:v instanceof Error?v.message:`Validation failed for ${e}`};}else c={success:!0,value:$};c.success?(f$1[e]=c.value,o&&D({type:"env_loaded",timestamp:Date.now(),key:e,source:w[e]?.source??"unknown",metadata:{cached:w[e]?.cached},sessionId:u})):(g.push(c.error),o&&D({type:"validation_failure",timestamp:Date.now(),key:e,error:c.error,sessionId:u}));}catch(c){let v=c instanceof Error?c.message:String(c);g.push(`${e}: ${v}`),o&&D({type:"validation_failure",timestamp:Date.now(),key:e,error:v,sessionId:u});}}if(g.length>0)throw o&&D({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 o&&D({type:"validation_success",timestamp:Date.now(),metadata:{variableCount:Object.keys(a).length},sessionId:u}),n.nestedDelimiter?z(f$1,n.nestedDelimiter):f$1}export{U as a,G as b,H as c};
|