@zh-moody/safe-env 0.4.2 → 0.4.3

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.
@@ -0,0 +1,9 @@
1
+ var F="development",k="serve",M="build",S="VITE_DEV_SERVER",R="VITE_";var C=typeof window<"u"&&typeof window.document<"u";function m(n,o=!0){if(C)return`SafeEnv Validation Failed: ${n.map(t=>`${t.key} (${t.error})`).join(", ")}`;let c={r:"\x1B[31m",g:"\x1B[32m",y:"\x1B[33m",b:"\x1B[1m",res:"\x1B[0m",d:"\x1B[2m",cy:"\x1B[36m"},e=(t,p)=>{let l=String(t),b=()=>{let s=0;for(let h of l){let u=h.codePointAt(0)??0;s+=u>255||u>=126976&&u<=131071?2:1}return s};for(;b()>p;)l=l.slice(0,-1);return l+" ".repeat(p-b())},i=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,x=Math.floor(i*.3),v=Math.floor(i*.5),r=o?c:{r:"",g:"",y:"",b:"",res:"",d:"",cy:""},d=`
2
+ ${r.r}${r.b}\u274C SafeEnv Validation Failed${r.res}
3
+ `;return d+=` ${r.b}${e("Key",x)} \u2502 ${e("Error",v)} \u2502 Value${r.res}
4
+ `,d+=r.d+"\u2500".repeat(i+5)+r.res+`
5
+ `,n.forEach(t=>{let p=t.value===void 0?"undefined":t.isSecret?"********":`"${t.value}"`,l=t.value===void 0?r.d:t.isSecret?r.y:r.cy;d+=` ${r.y}${e(t.key,x)}${r.res} \u2502 ${r.r}${e(t.error,v)}${r.res} \u2502 ${l}${p}${r.res}
6
+ `}),d+=r.d+"\u2500".repeat(i+5)+r.res+`
7
+ `,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
8
+ `,d}function _(n){if(C){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let o=n.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(o),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(m(n,!0))}var y={},T=new WeakMap;function P(n){let o=m(n,!1);return new Proxy({},{get(c,e){if(e==="__isSafeEnvError")return!0;if(e==="toJSON")return()=>({error:"SafeEnv Validation Failed"});throw new Error(`[safe-env] Cannot access "${String(e)}" because validation failed:
9
+ ${o}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}var w="[safe-env] Cannot modify read-only environment variables.";function O(n){if(T.has(n))return T.get(n);let o=new Proxy(n,{get(c,e){if(e==="__isSafeEnv")return!0;let i=Reflect.get(c,e);return i!==null&&typeof i=="object"&&!Object.isFrozen(i)?O(i):i},set(){throw new Error(w)},deleteProperty(){throw new Error(w)},defineProperty(){throw new Error(w)},setPrototypeOf(){throw new Error(w)}});return T.set(n,o),o}function I(n,o,c,e){return o||(c[n]!==void 0?n:e&&!n.startsWith(e)?e+n:n)}function W(n,o={}){let{loadProcessEnv:c=!0,prefix:e=R,cwd:i,useCache:x=!0,refreshCache:v=!1,envLoader:r}=o,d=o.mode||(typeof process<"u"?process.env.NODE_ENV:void 0)||F,t=`${e}|${i??""}|${d}`;v&&delete y[t];let p=typeof window<"u",l=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),b=p||l||"source"in o,s={},h=!1;if("source"in o)o.source===void 0?(h=!0,s={}):s=o.source;else if(x&&!v&&y[t]&&Object.keys(y[t]).length>0)s=y[t];else if(typeof process<"u"&&!p)try{let a={};if(r)for(let f of[".env",`.env.${d}`,".env.local",`.env.${d}.local`])a={...a,...r(f,i)};s={...a,...c?process.env:{}}}catch{s={}}x&&Object.keys(s).length>0&&(y[t]||(y[t]={}),Object.assign(y[t],s));let u={},E=[];for(let a in n){let f=n[a],V=I(a,f.sourceKey,s,e),g=s[V],$={source:s,parsed:u};try{let D=typeof f.required=="function"?f.required($):f.required;if(g===void 0||g===""&&f.default!==void 0){if(D&&g===void 0)throw new Error("Missing required field");u[a]=f.default}else u[a]=f.parse(g,$)}catch(D){E.push({key:V,error:D.message,value:g,isSecret:f.metadata?.isSecret})}}if(E.length>0){if(o.throwOnError){let a=new Error(m(E,!0));throw a.plainMessage=m(E,!1),a}return h||_(E),typeof process<"u"&&process.exit&&!b&&process.exit(1),P(E)}return O(u)}export{F as a,k as b,M as c,S as d,R as e,m as f,_ as g,W as h};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);var _path = require('path'); var _path2 = _interopRequireDefault(_path);function g(t,i){let n="",r=1;for(;r<t.length;){if(t[r]==="\\"&&r+1<t.length){n+=t[r+1],r+=2;continue}if(t[r]===i)return n;n+=t[r++]}return null}function m(t){let i={},n=t.split(/\r?\n/);for(let r of n){let o=r.trim();if(!o||o.startsWith("#"))continue;let s=o.indexOf("=");if(s===-1)continue;let c=o.slice(0,s).trim(),e=o.slice(s+1).trim();if(!e){i[c]="";continue}let f=e[0];if(f==='"'||f==="'"){let u=g(e,f);if(u!==null){i[c]=u;continue}}let l=e.indexOf("#");l!==-1&&(e=e.slice(0,l).trim()),i[c]=e}return i}function D(t=".env",i){try{let n=_path2.default.resolve(i||process.cwd(),t);if(_fs2.default.existsSync(n))return m(_fs2.default.readFileSync(n,"utf-8"))}catch (e2){}return{}}exports.a = m; exports.b = D;
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var F="development",k= exports.b ="serve",M= exports.c ="build",S= exports.d ="VITE_DEV_SERVER",R= exports.e ="VITE_";var C=typeof window<"u"&&typeof window.document<"u";function m(n,o=!0){if(C)return`SafeEnv Validation Failed: ${n.map(t=>`${t.key} (${t.error})`).join(", ")}`;let c={r:"\x1B[31m",g:"\x1B[32m",y:"\x1B[33m",b:"\x1B[1m",res:"\x1B[0m",d:"\x1B[2m",cy:"\x1B[36m"},e=(t,p)=>{let l=String(t),b=()=>{let s=0;for(let h of l){let u=_nullishCoalesce(h.codePointAt(0), () => (0));s+=u>255||u>=126976&&u<=131071?2:1}return s};for(;b()>p;)l=l.slice(0,-1);return l+" ".repeat(p-b())},i=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,x=Math.floor(i*.3),v=Math.floor(i*.5),r=o?c:{r:"",g:"",y:"",b:"",res:"",d:"",cy:""},d=`
2
+ ${r.r}${r.b}\u274C SafeEnv Validation Failed${r.res}
3
+ `;return d+=` ${r.b}${e("Key",x)} \u2502 ${e("Error",v)} \u2502 Value${r.res}
4
+ `,d+=r.d+"\u2500".repeat(i+5)+r.res+`
5
+ `,n.forEach(t=>{let p=t.value===void 0?"undefined":t.isSecret?"********":`"${t.value}"`,l=t.value===void 0?r.d:t.isSecret?r.y:r.cy;d+=` ${r.y}${e(t.key,x)}${r.res} \u2502 ${r.r}${e(t.error,v)}${r.res} \u2502 ${l}${p}${r.res}
6
+ `}),d+=r.d+"\u2500".repeat(i+5)+r.res+`
7
+ `,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
8
+ `,d}function _(n){if(C){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let o=n.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(o),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(m(n,!0))}var y={},T=new WeakMap;function P(n){let o=m(n,!1);return new Proxy({},{get(c,e){if(e==="__isSafeEnvError")return!0;if(e==="toJSON")return()=>({error:"SafeEnv Validation Failed"});throw new Error(`[safe-env] Cannot access "${String(e)}" because validation failed:
9
+ ${o}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}var w="[safe-env] Cannot modify read-only environment variables.";function O(n){if(T.has(n))return T.get(n);let o=new Proxy(n,{get(c,e){if(e==="__isSafeEnv")return!0;let i=Reflect.get(c,e);return i!==null&&typeof i=="object"&&!Object.isFrozen(i)?O(i):i},set(){throw new Error(w)},deleteProperty(){throw new Error(w)},defineProperty(){throw new Error(w)},setPrototypeOf(){throw new Error(w)}});return T.set(n,o),o}function I(n,o,c,e){return o||(c[n]!==void 0?n:e&&!n.startsWith(e)?e+n:n)}function W(n,o={}){let{loadProcessEnv:c=!0,prefix:e=R,cwd:i,useCache:x=!0,refreshCache:v=!1,envLoader:r}=o,d=o.mode||(typeof process<"u"?process.env.NODE_ENV:void 0)||F,t=`${e}|${_nullishCoalesce(i, () => (""))}|${d}`;v&&delete y[t];let p=typeof window<"u",l=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),b=p||l||"source"in o,s={},h=!1;if("source"in o)o.source===void 0?(h=!0,s={}):s=o.source;else if(x&&!v&&y[t]&&Object.keys(y[t]).length>0)s=y[t];else if(typeof process<"u"&&!p)try{let a={};if(r)for(let f of[".env",`.env.${d}`,".env.local",`.env.${d}.local`])a={...a,...r(f,i)};s={...a,...c?process.env:{}}}catch (e2){s={}}x&&Object.keys(s).length>0&&(y[t]||(y[t]={}),Object.assign(y[t],s));let u={},E=[];for(let a in n){let f=n[a],V=I(a,f.sourceKey,s,e),g=s[V],$={source:s,parsed:u};try{let D=typeof f.required=="function"?f.required($):f.required;if(g===void 0||g===""&&f.default!==void 0){if(D&&g===void 0)throw new Error("Missing required field");u[a]=f.default}else u[a]=f.parse(g,$)}catch(D){E.push({key:V,error:D.message,value:g,isSecret:_optionalChain([f, 'access', _2 => _2.metadata, 'optionalAccess', _3 => _3.isSecret])})}}if(E.length>0){if(o.throwOnError){let a=new Error(m(E,!0));throw a.plainMessage=m(E,!1),a}return h||_(E),typeof process<"u"&&process.exit&&!b&&process.exit(1),P(E)}return O(u)}exports.a = F; exports.b = k; exports.c = M; exports.d = S; exports.e = R; exports.f = m; exports.g = _; exports.h = W;
@@ -0,0 +1 @@
1
+ import d from"fs";import p from"path";function g(t,i){let n="",r=1;for(;r<t.length;){if(t[r]==="\\"&&r+1<t.length){n+=t[r+1],r+=2;continue}if(t[r]===i)return n;n+=t[r++]}return null}function m(t){let i={},n=t.split(/\r?\n/);for(let r of n){let o=r.trim();if(!o||o.startsWith("#"))continue;let s=o.indexOf("=");if(s===-1)continue;let c=o.slice(0,s).trim(),e=o.slice(s+1).trim();if(!e){i[c]="";continue}let f=e[0];if(f==='"'||f==="'"){let u=g(e,f);if(u!==null){i[c]=u;continue}}let l=e.indexOf("#");l!==-1&&(e=e.slice(0,l).trim()),i[c]=e}return i}function D(t=".env",i){try{let n=p.resolve(i||process.cwd(),t);if(d.existsSync(n))return m(d.readFileSync(n,"utf-8"))}catch{}return{}}export{m as a,D as b};
package/dist/fs-node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTR6KYAQIcjs = require('./chunk-TR6KYAQI.cjs');exports.loadDotEnv = _chunkTR6KYAQIcjs.b;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGHUSMNQTcjs = require('./chunk-GHUSMNQT.cjs');exports.loadDotEnv = _chunkGHUSMNQTcjs.b;
package/dist/fs-node.js CHANGED
@@ -1 +1 @@
1
- import{b as a}from"./chunk-5KPNMU6R.js";export{a as loadDotEnv};
1
+ import{b as a}from"./chunk-Z4SFK232.js";export{a as loadDotEnv};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkTR6KYAQIcjs = require('./chunk-TR6KYAQI.cjs');var _chunk6NHVLNFIcjs = require('./chunk-6NHVLNFI.cjs');var o=class{constructor(n,e,r,i=[]){this.type=n,this.default=e,this.required=e===void 0,this.parse=r,this.metadata=i.length?{options:i}:{}}from(n){return this.sourceKey=n,this}optional(){return this.required=!1,this}requiredIf(n){return this.required=n,this}validate(n,e="Custom validation failed"){let r=this.parse;return this.parse=(i,a)=>{let s=r(i,a);if(!n(s,a))throw new Error(e);return s},this}min(n){return this.metadata={...this.metadata,min:n},this}max(n){return this.metadata={...this.metadata,max:n},this}transform(n){let e=this.parse;return this.parse=(r,i)=>n(e(r,i),i),this}secret(){return this.metadata={...this.metadata,isSecret:!0},this}description(n){return this.metadata={...this.metadata,description:n},this}},m= exports.s ={string:t=>new o("string",t,n=>String(n)),number:t=>new o("number",t,n=>{let e=Number(n);if(isNaN(e))throw new Error(`Invalid number: ${n}`);return e}),boolean:t=>new o("boolean",t,n=>{if(typeof n=="boolean")return n;if(n===void 0||n==="")return!1;let e=String(n).toLowerCase().trim();if(["true","1","yes","on"].includes(e))return!0;if(["false","0","no","off"].includes(e))return!1;throw new Error(`Invalid boolean: ${n}`)}),enum:(t,n)=>new o("enum",n,e=>{if(!t.includes(e))throw new Error(`Value "${e}" is not one of: ${t.join(", ")}`);return e},t),array:(t,n=",")=>new o("array",t,e=>Array.isArray(e)?e:typeof e!="string"?[]:e.split(n).map(r=>r.trim()).filter(Boolean))};var b=t=>{try{return new URL(String(t)),!0}catch (e2){return!1}},D= exports.isEmail =t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),S= exports.matchesRegex =t=>n=>t.test(String(n)),T= exports.isIPv4 =t=>/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(String(t)),F= exports.isUUID =t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(t)),C= exports.isBase64 =t=>/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(String(t)),E= exports.isJSON =t=>{try{return JSON.parse(String(t)),!0}catch (e3){return!1}},N= exports.isHexColor =t=>/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(String(t)),$= exports.isObjectId =t=>/^[0-9a-fA-F]{24}$/.test(String(t)),k= exports.trim =t=>String(t).trim(),v= exports.toLowerCase =t=>String(t).toLowerCase(),I= exports.toUpperCase =t=>String(t).toUpperCase(),O= exports.toJSON =t=>{try{return JSON.parse(String(t))}catch (e4){throw new Error("Invalid JSON string")}};function q(t,n={}){let e=typeof process<"u"&&(_optionalChain([process, 'access', _ => _.release, 'optionalAccess', _2 => _2.name])==="node"||!!_optionalChain([process, 'access', _3 => _3.versions, 'optionalAccess', _4 => _4.node]));return _chunk6NHVLNFIcjs.h.call(void 0, t,{...n,envLoader:e?_chunkTR6KYAQIcjs.b:void 0})}exports.BUILD = _chunk6NHVLNFIcjs.c; exports.DEV = _chunk6NHVLNFIcjs.a; exports.SERVE = _chunk6NHVLNFIcjs.b; exports.VITE_DEV_FLAG = _chunk6NHVLNFIcjs.d; exports.VITE_PREFIX = _chunk6NHVLNFIcjs.e; exports.formatErrorReport = _chunk6NHVLNFIcjs.f; exports.isBase64 = C; exports.isEmail = D; exports.isHexColor = N; exports.isIPv4 = T; exports.isJSON = E; exports.isObjectId = $; exports.isUUID = F; exports.isUrl = b; exports.matchesRegex = S; exports.parseDotEnv = _chunkTR6KYAQIcjs.a; exports.reportErrors = _chunk6NHVLNFIcjs.g; exports.s = m; exports.safeEnv = q; exports.toJSON = O; exports.toLowerCase = v; exports.toUpperCase = I; exports.trim = k;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkGHUSMNQTcjs = require('./chunk-GHUSMNQT.cjs');var _chunkMTT5NLXMcjs = require('./chunk-MTT5NLXM.cjs');var a=class{constructor(e,n,r,i=[]){this.type=e,this.default=n,this.required=n===void 0,this.parse=r,this.metadata=i.length?{options:i}:{}}from(e){return this.sourceKey=e,this}optional(){return this.required=!1,this}requiredIf(e){return this.required=e,this}validate(e,n="Custom validation failed"){let r=this.parse;return this.parse=(i,o)=>{let s=r(i,o);if(!e(s,o))throw new Error(n);return s},this}min(e){let n=this.parse;return this.parse=(r,i)=>{let o=n(r,i);if(typeof o=="number"&&o<e)throw new Error(`Below min ${e}`);return o},this.metadata={...this.metadata,min:e},this}max(e){let n=this.parse;return this.parse=(r,i)=>{let o=n(r,i);if(typeof o=="number"&&o>e)throw new Error(`Above max ${e}`);return o},this.metadata={...this.metadata,max:e},this}transform(e){let n=this.parse;return this.parse=(r,i)=>e(n(r,i),i),this}secret(){return this.metadata={...this.metadata,isSecret:!0},this}description(e){return this.metadata={...this.metadata,description:e},this}},m= exports.s ={string:t=>new a("string",t,e=>String(e)),number:t=>new a("number",t,e=>{let n=Number(e);if(isNaN(n))throw new Error(`Invalid number value: "${e}"`);return n}),boolean:t=>new a("boolean",t,e=>{if(typeof e=="boolean")return e;if(e==="")return!1;let n=String(e).toLowerCase().trim();if(["true","1","yes","on"].includes(n))return!0;if(["false","0","no","off"].includes(n))return!1;throw new Error(`Invalid boolean value: "${e}"`)}),enum:(t,e)=>new a("enum",e,n=>{if(!t.includes(n))throw new Error(`Value "${n}" is not one of: ${t.join(", ")}`);return n},t),array:(t,e=",")=>new a("array",t,n=>{if(!e)throw new Error("[safe-env] array separator cannot be empty");return Array.isArray(n)?n:typeof n!="string"?[]:n.split(e).map(r=>r.trim()).filter(Boolean)})};var b=t=>{try{return new URL(String(t)),!0}catch (e2){return!1}},D= exports.isEmail =t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),S= exports.matchesRegex =t=>e=>t.test(String(e)),T= exports.isIPv4 =t=>/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(String(t)),E= exports.isUUID =t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(t)),F= exports.isBase64 =t=>/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(String(t)),C= exports.isJSON =t=>{try{return JSON.parse(String(t)),!0}catch (e3){return!1}},N= exports.isHexColor =t=>/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(String(t)),$= exports.isObjectId =t=>/^[0-9a-fA-F]{24}$/.test(String(t)),V= exports.trim =t=>String(t).trim(),v= exports.toLowerCase =t=>String(t).toLowerCase(),k= exports.toUpperCase =t=>String(t).toUpperCase(),A= exports.toJSON =t=>{try{return JSON.parse(String(t))}catch (e4){throw new Error("Invalid JSON string")}};function B(t,e={}){let n=typeof process<"u"&&(_optionalChain([process, 'access', _ => _.release, 'optionalAccess', _2 => _2.name])==="node"||!!_optionalChain([process, 'access', _3 => _3.versions, 'optionalAccess', _4 => _4.node]));return _chunkMTT5NLXMcjs.h.call(void 0, t,{...e,envLoader:n?_chunkGHUSMNQTcjs.b:void 0})}exports.BUILD = _chunkMTT5NLXMcjs.c; exports.DEV = _chunkMTT5NLXMcjs.a; exports.SERVE = _chunkMTT5NLXMcjs.b; exports.VITE_DEV_FLAG = _chunkMTT5NLXMcjs.d; exports.VITE_PREFIX = _chunkMTT5NLXMcjs.e; exports.formatErrorReport = _chunkMTT5NLXMcjs.f; exports.isBase64 = F; exports.isEmail = D; exports.isHexColor = N; exports.isIPv4 = T; exports.isJSON = C; exports.isObjectId = $; exports.isUUID = E; exports.isUrl = b; exports.matchesRegex = S; exports.parseDotEnv = _chunkGHUSMNQTcjs.a; exports.reportErrors = _chunkMTT5NLXMcjs.g; exports.s = m; exports.safeEnv = B; exports.toJSON = A; exports.toLowerCase = v; exports.toUpperCase = k; exports.trim = V;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, E as EnvError, S as Schema, a as SafeEnvOptions, I as InferSchema } from './types-BsDPVktI.cjs';
2
- export { B as BUILD, b as BaseType, D as DEV, c as SERVE, V as VITE_DEV_FLAG, d as VITE_PREFIX, e as ValidationContext } from './types-BsDPVktI.cjs';
1
+ import { F as FieldDefinition, E as EnvError, S as Schema, a as SafeEnvOptions, I as InferSchema } from './types-DaBhCHE2.cjs';
2
+ export { B as BUILD, b as BaseType, D as DEV, c as FieldMetadata, d as SERVE, V as VITE_DEV_FLAG, e as VITE_PREFIX, f as ValidationContext } from './types-DaBhCHE2.cjs';
3
3
 
4
4
  declare const s: {
5
5
  string: (d?: string) => FieldDefinition<string>;
@@ -25,7 +25,7 @@ declare const toJSON: (v: string) => any;
25
25
 
26
26
  /***
27
27
  * 将 .env 内容字符串解析为对象
28
- * 兼容带引号的值、多层引号内部的注释标识符以及行尾注释
28
+ * 兼容带引号的值、转义字符(\"、\')、以及行尾注释
29
29
  */
30
30
  declare function parseDotEnv(content: string): Record<string, string>;
31
31
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, E as EnvError, S as Schema, a as SafeEnvOptions, I as InferSchema } from './types-BsDPVktI.js';
2
- export { B as BUILD, b as BaseType, D as DEV, c as SERVE, V as VITE_DEV_FLAG, d as VITE_PREFIX, e as ValidationContext } from './types-BsDPVktI.js';
1
+ import { F as FieldDefinition, E as EnvError, S as Schema, a as SafeEnvOptions, I as InferSchema } from './types-DaBhCHE2.js';
2
+ export { B as BUILD, b as BaseType, D as DEV, c as FieldMetadata, d as SERVE, V as VITE_DEV_FLAG, e as VITE_PREFIX, f as ValidationContext } from './types-DaBhCHE2.js';
3
3
 
4
4
  declare const s: {
5
5
  string: (d?: string) => FieldDefinition<string>;
@@ -25,7 +25,7 @@ declare const toJSON: (v: string) => any;
25
25
 
26
26
  /***
27
27
  * 将 .env 内容字符串解析为对象
28
- * 兼容带引号的值、多层引号内部的注释标识符以及行尾注释
28
+ * 兼容带引号的值、转义字符(\"、\')、以及行尾注释
29
29
  */
30
30
  declare function parseDotEnv(content: string): Record<string, string>;
31
31
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as f,b as l}from"./chunk-5KPNMU6R.js";import{a as c,b as g,c as h,d as x,e as w,f as u,g as p,h as d}from"./chunk-JBML47XC.js";var o=class{type;default;required;sourceKey;metadata;parse;constructor(n,e,r,i=[]){this.type=n,this.default=e,this.required=e===void 0,this.parse=r,this.metadata=i.length?{options:i}:{}}from(n){return this.sourceKey=n,this}optional(){return this.required=!1,this}requiredIf(n){return this.required=n,this}validate(n,e="Custom validation failed"){let r=this.parse;return this.parse=(i,a)=>{let s=r(i,a);if(!n(s,a))throw new Error(e);return s},this}min(n){return this.metadata={...this.metadata,min:n},this}max(n){return this.metadata={...this.metadata,max:n},this}transform(n){let e=this.parse;return this.parse=(r,i)=>n(e(r,i),i),this}secret(){return this.metadata={...this.metadata,isSecret:!0},this}description(n){return this.metadata={...this.metadata,description:n},this}},m={string:t=>new o("string",t,n=>String(n)),number:t=>new o("number",t,n=>{let e=Number(n);if(isNaN(e))throw new Error(`Invalid number: ${n}`);return e}),boolean:t=>new o("boolean",t,n=>{if(typeof n=="boolean")return n;if(n===void 0||n==="")return!1;let e=String(n).toLowerCase().trim();if(["true","1","yes","on"].includes(e))return!0;if(["false","0","no","off"].includes(e))return!1;throw new Error(`Invalid boolean: ${n}`)}),enum:(t,n)=>new o("enum",n,e=>{if(!t.includes(e))throw new Error(`Value "${e}" is not one of: ${t.join(", ")}`);return e},t),array:(t,n=",")=>new o("array",t,e=>Array.isArray(e)?e:typeof e!="string"?[]:e.split(n).map(r=>r.trim()).filter(Boolean))};var b=t=>{try{return new URL(String(t)),!0}catch{return!1}},D=t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),S=t=>n=>t.test(String(n)),T=t=>/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(String(t)),F=t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(t)),C=t=>/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(String(t)),E=t=>{try{return JSON.parse(String(t)),!0}catch{return!1}},N=t=>/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(String(t)),$=t=>/^[0-9a-fA-F]{24}$/.test(String(t)),k=t=>String(t).trim(),v=t=>String(t).toLowerCase(),I=t=>String(t).toUpperCase(),O=t=>{try{return JSON.parse(String(t))}catch{throw new Error("Invalid JSON string")}};function q(t,n={}){let e=typeof process<"u"&&(process.release?.name==="node"||!!process.versions?.node);return d(t,{...n,envLoader:e?l:void 0})}export{h as BUILD,c as DEV,g as SERVE,x as VITE_DEV_FLAG,w as VITE_PREFIX,u as formatErrorReport,C as isBase64,D as isEmail,N as isHexColor,T as isIPv4,E as isJSON,$ as isObjectId,F as isUUID,b as isUrl,S as matchesRegex,f as parseDotEnv,p as reportErrors,m as s,q as safeEnv,O as toJSON,v as toLowerCase,I as toUpperCase,k as trim};
1
+ import{a as d,b as l}from"./chunk-Z4SFK232.js";import{a as c,b as h,c as g,d as x,e as w,f as u,g as p,h as f}from"./chunk-3IILV4AU.js";var a=class{type;default;required;sourceKey;metadata;parse;constructor(e,n,r,i=[]){this.type=e,this.default=n,this.required=n===void 0,this.parse=r,this.metadata=i.length?{options:i}:{}}from(e){return this.sourceKey=e,this}optional(){return this.required=!1,this}requiredIf(e){return this.required=e,this}validate(e,n="Custom validation failed"){let r=this.parse;return this.parse=(i,o)=>{let s=r(i,o);if(!e(s,o))throw new Error(n);return s},this}min(e){let n=this.parse;return this.parse=(r,i)=>{let o=n(r,i);if(typeof o=="number"&&o<e)throw new Error(`Below min ${e}`);return o},this.metadata={...this.metadata,min:e},this}max(e){let n=this.parse;return this.parse=(r,i)=>{let o=n(r,i);if(typeof o=="number"&&o>e)throw new Error(`Above max ${e}`);return o},this.metadata={...this.metadata,max:e},this}transform(e){let n=this.parse;return this.parse=(r,i)=>e(n(r,i),i),this}secret(){return this.metadata={...this.metadata,isSecret:!0},this}description(e){return this.metadata={...this.metadata,description:e},this}},m={string:t=>new a("string",t,e=>String(e)),number:t=>new a("number",t,e=>{let n=Number(e);if(isNaN(n))throw new Error(`Invalid number value: "${e}"`);return n}),boolean:t=>new a("boolean",t,e=>{if(typeof e=="boolean")return e;if(e==="")return!1;let n=String(e).toLowerCase().trim();if(["true","1","yes","on"].includes(n))return!0;if(["false","0","no","off"].includes(n))return!1;throw new Error(`Invalid boolean value: "${e}"`)}),enum:(t,e)=>new a("enum",e,n=>{if(!t.includes(n))throw new Error(`Value "${n}" is not one of: ${t.join(", ")}`);return n},t),array:(t,e=",")=>new a("array",t,n=>{if(!e)throw new Error("[safe-env] array separator cannot be empty");return Array.isArray(n)?n:typeof n!="string"?[]:n.split(e).map(r=>r.trim()).filter(Boolean)})};var b=t=>{try{return new URL(String(t)),!0}catch{return!1}},D=t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),S=t=>e=>t.test(String(e)),T=t=>/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(String(t)),E=t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(t)),F=t=>/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(String(t)),C=t=>{try{return JSON.parse(String(t)),!0}catch{return!1}},N=t=>/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(String(t)),$=t=>/^[0-9a-fA-F]{24}$/.test(String(t)),V=t=>String(t).trim(),v=t=>String(t).toLowerCase(),k=t=>String(t).toUpperCase(),A=t=>{try{return JSON.parse(String(t))}catch{throw new Error("Invalid JSON string")}};function B(t,e={}){let n=typeof process<"u"&&(process.release?.name==="node"||!!process.versions?.node);return f(t,{...e,envLoader:n?l:void 0})}export{g as BUILD,c as DEV,h as SERVE,x as VITE_DEV_FLAG,w as VITE_PREFIX,u as formatErrorReport,F as isBase64,D as isEmail,N as isHexColor,T as isIPv4,C as isJSON,$ as isObjectId,E as isUUID,b as isUrl,S as matchesRegex,d as parseDotEnv,p as reportErrors,m as s,B as safeEnv,A as toJSON,v as toLowerCase,k as toUpperCase,V as trim};
@@ -8,12 +8,19 @@ interface ValidationContext {
8
8
  source: Record<string, any>;
9
9
  parsed: Record<string, any>;
10
10
  }
11
+ interface FieldMetadata {
12
+ isSecret?: boolean;
13
+ description?: string;
14
+ min?: number;
15
+ max?: number;
16
+ options?: string[];
17
+ }
11
18
  interface FieldDefinition<T = any, D extends string = string> {
12
19
  type: BaseType;
13
20
  default?: T;
14
21
  required: boolean | ((ctx: ValidationContext) => boolean);
15
22
  sourceKey?: string;
16
- metadata?: any;
23
+ metadata?: FieldMetadata;
17
24
  parse: (val: any, ctx: ValidationContext) => T;
18
25
  from: (key: string) => FieldDefinition<T, D>;
19
26
  optional: () => FieldDefinition<T | undefined, D>;
@@ -47,4 +54,4 @@ interface SafeEnvOptions {
47
54
  /** @internal */ devMode?: boolean;
48
55
  }
49
56
 
50
- export { BUILD as B, DEV as D, type EnvError as E, type FieldDefinition as F, type InferSchema as I, type Schema as S, VITE_DEV_FLAG as V, type SafeEnvOptions as a, type BaseType as b, SERVE as c, VITE_PREFIX as d, type ValidationContext as e };
57
+ export { BUILD as B, DEV as D, type EnvError as E, type FieldDefinition as F, type InferSchema as I, type Schema as S, VITE_DEV_FLAG as V, type SafeEnvOptions as a, type BaseType as b, type FieldMetadata as c, SERVE as d, VITE_PREFIX as e, type ValidationContext as f };
@@ -8,12 +8,19 @@ interface ValidationContext {
8
8
  source: Record<string, any>;
9
9
  parsed: Record<string, any>;
10
10
  }
11
+ interface FieldMetadata {
12
+ isSecret?: boolean;
13
+ description?: string;
14
+ min?: number;
15
+ max?: number;
16
+ options?: string[];
17
+ }
11
18
  interface FieldDefinition<T = any, D extends string = string> {
12
19
  type: BaseType;
13
20
  default?: T;
14
21
  required: boolean | ((ctx: ValidationContext) => boolean);
15
22
  sourceKey?: string;
16
- metadata?: any;
23
+ metadata?: FieldMetadata;
17
24
  parse: (val: any, ctx: ValidationContext) => T;
18
25
  from: (key: string) => FieldDefinition<T, D>;
19
26
  optional: () => FieldDefinition<T | undefined, D>;
@@ -47,4 +54,4 @@ interface SafeEnvOptions {
47
54
  /** @internal */ devMode?: boolean;
48
55
  }
49
56
 
50
- export { BUILD as B, DEV as D, type EnvError as E, type FieldDefinition as F, type InferSchema as I, type Schema as S, VITE_DEV_FLAG as V, type SafeEnvOptions as a, type BaseType as b, SERVE as c, VITE_PREFIX as d, type ValidationContext as e };
57
+ export { BUILD as B, DEV as D, type EnvError as E, type FieldDefinition as F, type InferSchema as I, type Schema as S, VITE_DEV_FLAG as V, type SafeEnvOptions as a, type BaseType as b, type FieldMetadata as c, SERVE as d, VITE_PREFIX as e, type ValidationContext as f };
package/dist/vite.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6NHVLNFIcjs = require('./chunk-6NHVLNFI.cjs');var _vite = require('vite');function g(v,f={}){let n=null,o=!1;return{name:"vite-plugin-safe-env",configResolved(e){o=e.command===_chunk6NHVLNFIcjs.b,process.env[_chunk6NHVLNFIcjs.d]=o?"true":"";let{envDir:t=e.root,prefix:r=e.envPrefix||_chunk6NHVLNFIcjs.e}=f,p=_vite.loadEnv.call(void 0, e.mode,t,r);try{_chunk6NHVLNFIcjs.h.call(void 0, v,{source:p,prefix:Array.isArray(r)?r[0]:r,loadProcessEnv:!1,throwOnError:!0}),n=null}catch(s){n=s,o?e.logger.error(s.message):(console.error(s.message),console.error(`\x1B[31m[safe-env] Fatal: Environment validation failed during build. Exiting...\x1B[0m
2
- `),process.exit(1))}},transform(e,t){if(o&&n&&(e.includes("import.meta.env")||e.includes("safeEnv"))){let r=new Error(n.plainMessage||n.message);throw r.stack="",r}return null}}}exports.viteSafeEnv = g;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkMTT5NLXMcjs = require('./chunk-MTT5NLXM.cjs');var _vite = require('vite');function g(v,c={}){let n=null,s=!1;return{name:"vite-plugin-safe-env",configResolved(e){s=e.command===_chunkMTT5NLXMcjs.b,process.env[_chunkMTT5NLXMcjs.d]=s?"true":"";let{envDir:o=e.root,prefix:r=e.envPrefix||_chunkMTT5NLXMcjs.e}=c,t=_vite.loadEnv.call(void 0, e.mode,o,r);try{_chunkMTT5NLXMcjs.h.call(void 0, v,{source:t,prefix:Array.isArray(r)?r[0]:r,loadProcessEnv:!1,throwOnError:!0}),n=null}catch(l){n=l,s?e.logger.error(l.message):(console.error(l.message),console.error(`\x1B[31m[safe-env] Fatal: Environment validation failed during build. Exiting...\x1B[0m
2
+ `),process.exit(1))}},transform(e,o){if(!s||!n||o.includes("node_modules")||o.endsWith(".d.ts"))return null;let r=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,"");if(r.includes("import.meta.env")||r.includes("safeEnv")){let t=new Error(n.plainMessage||n.message);throw t.stack="",t}return null}}}exports.viteSafeEnv = g;
package/dist/vite.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { S as Schema } from './types-BsDPVktI.cjs';
2
+ import { S as Schema } from './types-DaBhCHE2.cjs';
3
3
 
4
4
  /**
5
5
  * Vite 插件:在构建或开发启动时校验环境变量
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { S as Schema } from './types-BsDPVktI.js';
2
+ import { S as Schema } from './types-DaBhCHE2.js';
3
3
 
4
4
  /**
5
5
  * Vite 插件:在构建或开发启动时校验环境变量
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import{b as a,d as i,e as l,h as m}from"./chunk-JBML47XC.js";import{loadEnv as u}from"vite";function g(v,f={}){let n=null,o=!1;return{name:"vite-plugin-safe-env",configResolved(e){o=e.command===a,process.env[i]=o?"true":"";let{envDir:t=e.root,prefix:r=e.envPrefix||l}=f,p=u(e.mode,t,r);try{m(v,{source:p,prefix:Array.isArray(r)?r[0]:r,loadProcessEnv:!1,throwOnError:!0}),n=null}catch(s){n=s,o?e.logger.error(s.message):(console.error(s.message),console.error(`\x1B[31m[safe-env] Fatal: Environment validation failed during build. Exiting...\x1B[0m
2
- `),process.exit(1))}},transform(e,t){if(o&&n&&(e.includes("import.meta.env")||e.includes("safeEnv"))){let r=new Error(n.plainMessage||n.message);throw r.stack="",r}return null}}}export{g as viteSafeEnv};
1
+ import{b as a,d as i,e as m,h as u}from"./chunk-3IILV4AU.js";import{loadEnv as f}from"vite";function g(v,c={}){let n=null,s=!1;return{name:"vite-plugin-safe-env",configResolved(e){s=e.command===a,process.env[i]=s?"true":"";let{envDir:o=e.root,prefix:r=e.envPrefix||m}=c,t=f(e.mode,o,r);try{u(v,{source:t,prefix:Array.isArray(r)?r[0]:r,loadProcessEnv:!1,throwOnError:!0}),n=null}catch(l){n=l,s?e.logger.error(l.message):(console.error(l.message),console.error(`\x1B[31m[safe-env] Fatal: Environment validation failed during build. Exiting...\x1B[0m
2
+ `),process.exit(1))}},transform(e,o){if(!s||!n||o.includes("node_modules")||o.endsWith(".d.ts"))return null;let r=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,"");if(r.includes("import.meta.env")||r.includes("safeEnv")){let t=new Error(n.plainMessage||n.message);throw t.stack="",t}return null}}}export{g as viteSafeEnv};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zh-moody/safe-env",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Type-safe environment variables for Node.js and Browser with schema validation.",
5
5
  "author": "Moody",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- import u from"fs";import a from"path";function m(r){let n={},i=r.split(/\r?\n/);for(let d of i){let e=d.trim();if(!e||e.startsWith("#"))continue;let o=e.indexOf("=");if(o===-1)continue;let s=e.slice(0,o).trim(),t=e.slice(o+1).trim();if(!t){n[s]="";continue}let c=t[0];if(c==='"'||c==="'"){let l=t.indexOf(c,1);if(l!==-1){n[s]=t.slice(1,l);continue}}let f=t.indexOf("#");f!==-1&&(t=t.slice(0,f).trim()),n[s]=t}return n}function h(r=".env",n){try{let i=a.resolve(n||process.cwd(),r);if(u.existsSync(i))return m(u.readFileSync(i,"utf-8"))}catch{}return{}}export{m as a,h as b};
@@ -1,9 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var F="development",j= exports.b ="serve",K= exports.c ="build",C= exports.d ="VITE_DEV_SERVER",k= exports.e ="VITE_";var O=typeof window<"u"&&typeof window.document<"u";function b(i,o=!0){if(O)return`SafeEnv Validation Failed: ${i.map(s=>`${s.key} (${s.error})`).join(", ")}`;let d={r:"\x1B[31m",g:"\x1B[32m",y:"\x1B[33m",b:"\x1B[1m",res:"\x1B[0m",d:"\x1B[2m",cy:"\x1B[36m"},n=(s,p)=>{let r=String(s),x=()=>r.length+(r.match(/[^\x00-\xff]/g)||[]).length;for(;x()>p;)r=r.slice(0,-1);return r+" ".repeat(p-x())},c=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,u=Math.floor(c*.3),y=Math.floor(c*.5),e=o?d:{r:"",g:"",y:"",b:"",res:"",d:"",cy:""},f=`
2
- ${e.r}${e.b}\u274C SafeEnv Validation Failed${e.res}
3
- `;return f+=` ${e.b}${n("Key",u)} \u2502 ${n("Error",y)} \u2502 Value${e.res}
4
- `,f+=e.d+"\u2500".repeat(c+5)+e.res+`
5
- `,i.forEach(s=>{let p=s.value===void 0?"undefined":s.isSecret?"********":`"${s.value}"`,r=s.value===void 0?e.d:s.isSecret?e.y:e.cy;f+=` ${e.y}${n(s.key,u)}${e.res} \u2502 ${e.r}${n(s.error,y)}${e.res} \u2502 ${r}${p}${e.res}
6
- `}),f+=e.d+"\u2500".repeat(c+5)+e.res+`
7
- `,f+=` ${e.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${e.res}
8
- `,f}function _(i){if(O){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let o=i.reduce((d,n)=>(d[n.key]={"Error Message":n.error,"Current Value":n.value===void 0?"undefined":n.isSecret?"********":n.value},d),{});console.table(o),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(b(i,!0))}var l={},$=new WeakMap;function P(i){let o=b(i,!1);return new Proxy({},{get(d,n){if(n==="__isSafeEnvError")return!0;if(n==="toJSON")return()=>({error:"SafeEnv Validation Failed"});throw new Error(`[safe-env] Cannot access "${String(n)}" because validation failed:
9
- ${o}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}var w="[safe-env] Cannot modify read-only environment variables.";function I(i){if($.has(i))return $.get(i);let o=new Proxy(i,{get(d,n){if(n==="__isSafeEnv")return!0;let c=Reflect.get(d,n);return c!==null&&typeof c=="object"&&!Object.isFrozen(c)?I(c):c},set(){throw new Error(w)},deleteProperty(){throw new Error(w)},defineProperty(){throw new Error(w)},setPrototypeOf(){throw new Error(w)}});return $.set(i,o),o}function X(i,o={}){let{loadProcessEnv:d=!0,prefix:n=k,cwd:c,useCache:u=!0,refreshCache:y=!1,envLoader:e}=o;if(y)for(let t in l)delete l[t];let f=typeof window<"u",s=typeof process<"u"&&(!!process.env.VITE||!!process.env[C]),p=f||s||"source"in o,r={},x=!1;if("source"in o)o.source===void 0?(x=!0,r={}):r=o.source;else if(u&&!y&&Object.keys(l).length>0)r=l;else if(typeof process<"u"&&!f)try{let t=o.mode||process.env.NODE_ENV||F,a={};if(e)for(let v of[".env",`.env.${t}`,".env.local",`.env.${t}.local`])a={...a,...e(v,c)};r={...a,...d?process.env:{}}}catch (e2){r={}}u&&!y&&Object.keys(l).length>0?Object.keys(r).length===0?r=l:Object.assign(l,r):u&&Object.keys(r).length>0&&Object.assign(l,r);let h={},E=[];for(let t in i){let a=i[t],v=n&&!t.startsWith(n)?n+t:t,S=a.sourceKey||(r[v]!==void 0?v:r[t]!==void 0?t:v),m=r[S],R={source:r,parsed:h};try{let D=typeof a.required=="function"?a.required(R):a.required;if(m===void 0||m===""&&a.default!==void 0){if(D&&m===void 0)throw new Error("Missing required field");h[t]=a.default}else{let g=a.parse(m,R);if(g!==void 0&&a.metadata){let{min:T,max:V}=a.metadata;if(typeof g=="number"){if(T!==void 0&&g<T)throw new Error(`Below min ${T}`);if(V!==void 0&&g>V)throw new Error(`Above max ${V}`)}}h[t]=g}}catch(D){E.push({key:S,error:D.message,value:m,isSecret:_optionalChain([a, 'access', _2 => _2.metadata, 'optionalAccess', _3 => _3.isSecret])})}}if(E.length>0){if(o.throwOnError){let t=new Error(b(E,!0));throw t.plainMessage=b(E,!1),t}return x||_(E),typeof process<"u"&&process.exit&&!p&&process.exit(1),P(E)}return I(h)}exports.a = F; exports.b = j; exports.c = K; exports.d = C; exports.e = k; exports.f = b; exports.g = _; exports.h = X;
@@ -1,9 +0,0 @@
1
- var F="development",j="serve",K="build",C="VITE_DEV_SERVER",k="VITE_";var O=typeof window<"u"&&typeof window.document<"u";function b(i,o=!0){if(O)return`SafeEnv Validation Failed: ${i.map(s=>`${s.key} (${s.error})`).join(", ")}`;let d={r:"\x1B[31m",g:"\x1B[32m",y:"\x1B[33m",b:"\x1B[1m",res:"\x1B[0m",d:"\x1B[2m",cy:"\x1B[36m"},n=(s,p)=>{let r=String(s),x=()=>r.length+(r.match(/[^\x00-\xff]/g)||[]).length;for(;x()>p;)r=r.slice(0,-1);return r+" ".repeat(p-x())},c=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,u=Math.floor(c*.3),y=Math.floor(c*.5),e=o?d:{r:"",g:"",y:"",b:"",res:"",d:"",cy:""},f=`
2
- ${e.r}${e.b}\u274C SafeEnv Validation Failed${e.res}
3
- `;return f+=` ${e.b}${n("Key",u)} \u2502 ${n("Error",y)} \u2502 Value${e.res}
4
- `,f+=e.d+"\u2500".repeat(c+5)+e.res+`
5
- `,i.forEach(s=>{let p=s.value===void 0?"undefined":s.isSecret?"********":`"${s.value}"`,r=s.value===void 0?e.d:s.isSecret?e.y:e.cy;f+=` ${e.y}${n(s.key,u)}${e.res} \u2502 ${e.r}${n(s.error,y)}${e.res} \u2502 ${r}${p}${e.res}
6
- `}),f+=e.d+"\u2500".repeat(c+5)+e.res+`
7
- `,f+=` ${e.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${e.res}
8
- `,f}function _(i){if(O){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let o=i.reduce((d,n)=>(d[n.key]={"Error Message":n.error,"Current Value":n.value===void 0?"undefined":n.isSecret?"********":n.value},d),{});console.table(o),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(b(i,!0))}var l={},$=new WeakMap;function P(i){let o=b(i,!1);return new Proxy({},{get(d,n){if(n==="__isSafeEnvError")return!0;if(n==="toJSON")return()=>({error:"SafeEnv Validation Failed"});throw new Error(`[safe-env] Cannot access "${String(n)}" because validation failed:
9
- ${o}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}var w="[safe-env] Cannot modify read-only environment variables.";function I(i){if($.has(i))return $.get(i);let o=new Proxy(i,{get(d,n){if(n==="__isSafeEnv")return!0;let c=Reflect.get(d,n);return c!==null&&typeof c=="object"&&!Object.isFrozen(c)?I(c):c},set(){throw new Error(w)},deleteProperty(){throw new Error(w)},defineProperty(){throw new Error(w)},setPrototypeOf(){throw new Error(w)}});return $.set(i,o),o}function X(i,o={}){let{loadProcessEnv:d=!0,prefix:n=k,cwd:c,useCache:u=!0,refreshCache:y=!1,envLoader:e}=o;if(y)for(let t in l)delete l[t];let f=typeof window<"u",s=typeof process<"u"&&(!!process.env.VITE||!!process.env[C]),p=f||s||"source"in o,r={},x=!1;if("source"in o)o.source===void 0?(x=!0,r={}):r=o.source;else if(u&&!y&&Object.keys(l).length>0)r=l;else if(typeof process<"u"&&!f)try{let t=o.mode||process.env.NODE_ENV||F,a={};if(e)for(let v of[".env",`.env.${t}`,".env.local",`.env.${t}.local`])a={...a,...e(v,c)};r={...a,...d?process.env:{}}}catch{r={}}u&&!y&&Object.keys(l).length>0?Object.keys(r).length===0?r=l:Object.assign(l,r):u&&Object.keys(r).length>0&&Object.assign(l,r);let h={},E=[];for(let t in i){let a=i[t],v=n&&!t.startsWith(n)?n+t:t,S=a.sourceKey||(r[v]!==void 0?v:r[t]!==void 0?t:v),m=r[S],R={source:r,parsed:h};try{let D=typeof a.required=="function"?a.required(R):a.required;if(m===void 0||m===""&&a.default!==void 0){if(D&&m===void 0)throw new Error("Missing required field");h[t]=a.default}else{let g=a.parse(m,R);if(g!==void 0&&a.metadata){let{min:T,max:V}=a.metadata;if(typeof g=="number"){if(T!==void 0&&g<T)throw new Error(`Below min ${T}`);if(V!==void 0&&g>V)throw new Error(`Above max ${V}`)}}h[t]=g}}catch(D){E.push({key:S,error:D.message,value:m,isSecret:a.metadata?.isSecret})}}if(E.length>0){if(o.throwOnError){let t=new Error(b(E,!0));throw t.plainMessage=b(E,!1),t}return x||_(E),typeof process<"u"&&process.exit&&!p&&process.exit(1),P(E)}return I(h)}export{F as a,j as b,K as c,C as d,k as e,b as f,_ as g,X as h};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);var _path = require('path'); var _path2 = _interopRequireDefault(_path);function m(r){let n={},i=r.split(/\r?\n/);for(let d of i){let e=d.trim();if(!e||e.startsWith("#"))continue;let o=e.indexOf("=");if(o===-1)continue;let s=e.slice(0,o).trim(),t=e.slice(o+1).trim();if(!t){n[s]="";continue}let c=t[0];if(c==='"'||c==="'"){let l=t.indexOf(c,1);if(l!==-1){n[s]=t.slice(1,l);continue}}let f=t.indexOf("#");f!==-1&&(t=t.slice(0,f).trim()),n[s]=t}return n}function h(r=".env",n){try{let i=_path2.default.resolve(n||process.cwd(),r);if(_fs2.default.existsSync(i))return m(_fs2.default.readFileSync(i,"utf-8"))}catch (e2){}return{}}exports.a = m; exports.b = h;