@zh-moody/safe-env 0.3.7 → 0.3.8
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/dist/chunk-5AAC43HE.js +9 -0
- package/dist/chunk-QKTQJTDS.cjs +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BX67JRJU.cjs +0 -9
- package/dist/chunk-IHZESWXY.js +0 -9
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{a as R}from"./chunk-I7AUKTXE.js";var $="development",_="serve",j="build",S="VITE_DEV_SERVER",F="VITE_";var V=typeof window<"u"&&typeof window.document<"u";function x(i,s=!0){if(V)return`SafeEnv Validation Failed: ${i.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,o)=>{let f=String(t),E=()=>f.length+(f.match(/[^\x00-\xff]/g)||[]).length;for(;E()>o;)f=f.slice(0,-1);return f+" ".repeat(o-E())},y=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,v=Math.floor(y*.3),g=Math.floor(y*.5),r=s?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",v)} \u2502 ${e("Error",g)} \u2502 Value${r.res}
|
|
4
|
+
`,d+=r.d+"\u2500".repeat(y+5)+r.res+`
|
|
5
|
+
`,i.forEach(t=>{let o=t.value===void 0?"undefined":t.isSecret?"********":`"${t.value}"`,f=t.value===void 0?r.d:t.isSecret?r.y:r.cy;d+=` ${r.y}${e(t.key,v)}${r.res} \u2502 ${r.r}${e(t.error,g)}${r.res} \u2502 ${f}${o}${r.res}
|
|
6
|
+
`}),d+=r.d+"\u2500".repeat(y+5)+r.res+`
|
|
7
|
+
`,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
|
|
8
|
+
`,d}function k(i){if(V){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let s=i.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(s),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(x(i,!0))}var p={};function I(i){let s=x(i,!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
|
+
${s}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}function O(i){let s=Object.getOwnPropertyNames(i);for(let c of s){let e=i[c];e&&typeof e=="object"&&!Object.isFrozen(e)&&O(e)}return Object.freeze(i)}function z(i,s={}){let{loadProcessEnv:c=!0,prefix:e=F,cwd:y,useCache:v=!0,refreshCache:g=!1}=s;if(g)for(let n in p)delete p[n];let r=typeof window<"u",d=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),t=r||d||"source"in s,o={};if("source"in s)o=s.source||{};else if(v&&!g&&Object.keys(p).length>0)o=p;else if(typeof process<"u"&&!r)try{let n=s.mode||process.env.NODE_ENV||$,{loadDotEnv:a}=R("./fs-node.cjs"),u={};for(let h of[".env",`.env.${n}`,".env.local",`.env.${n}.local`])u={...u,...a(h,y)};o={...u,...c?process.env:{}}}catch{o={}}let f=Object.keys(o).length;if(v&&(f>0?Object.assign(p,o):Object.keys(p).length>0&&(o=p)),t&&Object.keys(o).length===0)return{};let E={},m=[];for(let n in i){let a=i[n],u=e&&!n.startsWith(e)?e+n:n,h=a.sourceKey||(o[u]!==void 0?u:o[n]!==void 0?n:u),b=o[h];try{if(b===void 0||b===""&&a.default!==void 0){if(a.required&&b===void 0)throw new Error("Missing required field");E[n]=a.default}else{let l=a.parse(b);if(l!==void 0&&a.metadata){let{min:D,max:w,validate:T}=a.metadata;if(typeof l=="number"){if(D!==void 0&&l<D)throw new Error(`Below min ${D}`);if(w!==void 0&&l>w)throw new Error(`Above max ${w}`)}if(T&&!T.fn(l))throw new Error(T.message)}E[n]=l}}catch(l){m.push({key:h,error:l.message,value:b,isSecret:a.metadata?.isSecret})}}if(m.length>0){if(s.throwOnError){let n=new Error(x(m,!0));throw n.plainMessage=x(m,!1),n}return k(m),typeof process<"u"&&process.exit&&!t&&process.exit(1),I(m)}return O(E)}export{$ as a,_ as b,j as c,S as d,F as e,x as f,k as g,z as h};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 _chunkD6WM53FNcjs = require('./chunk-D6WM53FN.cjs');var $="development",_= exports.b ="serve",j= exports.c ="build",S= exports.d ="VITE_DEV_SERVER",F= exports.e ="VITE_";var V=typeof window<"u"&&typeof window.document<"u";function x(i,s=!0){if(V)return`SafeEnv Validation Failed: ${i.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,o)=>{let f=String(t),E=()=>f.length+(f.match(/[^\x00-\xff]/g)||[]).length;for(;E()>o;)f=f.slice(0,-1);return f+" ".repeat(o-E())},y=Math.max(80,(typeof process<"u"?process.stdout.columns:80)||80)-10,v=Math.floor(y*.3),g=Math.floor(y*.5),r=s?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",v)} \u2502 ${e("Error",g)} \u2502 Value${r.res}
|
|
4
|
+
`,d+=r.d+"\u2500".repeat(y+5)+r.res+`
|
|
5
|
+
`,i.forEach(t=>{let o=t.value===void 0?"undefined":t.isSecret?"********":`"${t.value}"`,f=t.value===void 0?r.d:t.isSecret?r.y:r.cy;d+=` ${r.y}${e(t.key,v)}${r.res} \u2502 ${r.r}${e(t.error,g)}${r.res} \u2502 ${f}${o}${r.res}
|
|
6
|
+
`}),d+=r.d+"\u2500".repeat(y+5)+r.res+`
|
|
7
|
+
`,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
|
|
8
|
+
`,d}function k(i){if(V){console.group("%c \u274C SafeEnv Validation Failed ","background: #fee2e2; color: #b91c1c; font-weight: bold; padding: 4px; border-radius: 2px;");let s=i.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(s),console.log("%c \u{1F4A1} Tip: Check your .env files or schema definitions. ","color: #059669; font-style: italic;"),console.groupEnd()}else console.error(x(i,!0))}var p={};function I(i){let s=x(i,!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
|
+
${s}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}function O(i){let s=Object.getOwnPropertyNames(i);for(let c of s){let e=i[c];e&&typeof e=="object"&&!Object.isFrozen(e)&&O(e)}return Object.freeze(i)}function z(i,s={}){let{loadProcessEnv:c=!0,prefix:e=F,cwd:y,useCache:v=!0,refreshCache:g=!1}=s;if(g)for(let n in p)delete p[n];let r=typeof window<"u",d=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),t=r||d||"source"in s,o={};if("source"in s)o=s.source||{};else if(v&&!g&&Object.keys(p).length>0)o=p;else if(typeof process<"u"&&!r)try{let n=s.mode||process.env.NODE_ENV||$,{loadDotEnv:a}=_chunkD6WM53FNcjs.a.call(void 0, "./fs-node.cjs"),u={};for(let h of[".env",`.env.${n}`,".env.local",`.env.${n}.local`])u={...u,...a(h,y)};o={...u,...c?process.env:{}}}catch (e2){o={}}let f=Object.keys(o).length;if(v&&(f>0?Object.assign(p,o):Object.keys(p).length>0&&(o=p)),t&&Object.keys(o).length===0)return{};let E={},m=[];for(let n in i){let a=i[n],u=e&&!n.startsWith(e)?e+n:n,h=a.sourceKey||(o[u]!==void 0?u:o[n]!==void 0?n:u),b=o[h];try{if(b===void 0||b===""&&a.default!==void 0){if(a.required&&b===void 0)throw new Error("Missing required field");E[n]=a.default}else{let l=a.parse(b);if(l!==void 0&&a.metadata){let{min:D,max:w,validate:T}=a.metadata;if(typeof l=="number"){if(D!==void 0&&l<D)throw new Error(`Below min ${D}`);if(w!==void 0&&l>w)throw new Error(`Above max ${w}`)}if(T&&!T.fn(l))throw new Error(T.message)}E[n]=l}}catch(l){m.push({key:h,error:l.message,value:b,isSecret:_optionalChain([a, 'access', _2 => _2.metadata, 'optionalAccess', _3 => _3.isSecret])})}}if(m.length>0){if(s.throwOnError){let n=new Error(x(m,!0));throw n.plainMessage=x(m,!1),n}return k(m),typeof process<"u"&&process.exit&&!t&&process.exit(1),I(m)}return O(E)}exports.a = $; exports.b = _; exports.c = j; exports.d = S; exports.e = F; exports.f = x; exports.g = k; exports.h = z;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkPLO26PP5cjs = require('./chunk-PLO26PP5.cjs');var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkPLO26PP5cjs = require('./chunk-PLO26PP5.cjs');var _chunkQKTQJTDScjs = require('./chunk-QKTQJTDS.cjs');require('./chunk-D6WM53FN.cjs');function a(r,e,n,s=[]){return{type:r,default:e,required:e===void 0,parse:n,metadata:s.length?{options:s}:{},from(t){return this.sourceKey=t,this},validate(t,i="Custom validation failed"){return this.metadata={...this.metadata,validate:{fn:t,message:i}},this},min(t){return this.metadata={...this.metadata,min:t},this},max(t){return this.metadata={...this.metadata,max:t},this},transform(t){let i=this.parse;return this.parse=o=>t(i(o)),this},secret(){return this.metadata={...this.metadata,isSecret:!0},this},url(){return this.validate(t=>{try{return new URL(String(t)),!0}catch (e2){return!1}},"Invalid URL format")},email(){return this.validate(t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),"Invalid email format")},regex(t,i="Value does not match pattern"){return this.validate(o=>t.test(String(o)),i)},description(t){return this.metadata={...this.metadata,description:t},this}}}var m={string:r=>a("string",r,e=>String(e)),number:r=>a("number",r,e=>{let n=Number(e);if(isNaN(n))throw new Error(`Invalid number: ${e}`);return n}),boolean:r=>a("boolean",r,e=>{if(typeof e=="boolean")return e;if(e===void 0||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: ${e}`)}),enum:(r,e)=>a("enum",e,n=>{if(!r.includes(n))throw new Error(`Value "${n}" is not one of: ${r.join(", ")}`);return n},r),array:(r,e=",")=>a("array",r,n=>Array.isArray(n)?n:typeof n!="string"?[]:n.split(e).map(s=>s.trim()).filter(Boolean))};exports.BUILD = _chunkQKTQJTDScjs.c; exports.DEV = _chunkQKTQJTDScjs.a; exports.SERVE = _chunkQKTQJTDScjs.b; exports.VITE_DEV_FLAG = _chunkQKTQJTDScjs.d; exports.VITE_PREFIX = _chunkQKTQJTDScjs.e; exports.formatErrorReport = _chunkQKTQJTDScjs.f; exports.parseDotEnv = _chunkPLO26PP5cjs.a; exports.reportErrors = _chunkQKTQJTDScjs.g; exports.s = m; exports.safeEnv = _chunkQKTQJTDScjs.h;
|
package/dist/index.d.cts
CHANGED
|
@@ -20,9 +20,6 @@ declare const s: {
|
|
|
20
20
|
*/
|
|
21
21
|
declare function parseDotEnv(content: string): Record<string, string>;
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* 格式化终端报错表格 (仅 Node 端/开发端使用)
|
|
25
|
-
*/
|
|
26
23
|
declare function formatErrorReport(errors: EnvError[], useColor?: boolean): string;
|
|
27
24
|
declare function reportErrors(errors: EnvError[]): void;
|
|
28
25
|
|
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,6 @@ declare const s: {
|
|
|
20
20
|
*/
|
|
21
21
|
declare function parseDotEnv(content: string): Record<string, string>;
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* 格式化终端报错表格 (仅 Node 端/开发端使用)
|
|
25
|
-
*/
|
|
26
23
|
declare function formatErrorReport(errors: EnvError[], useColor?: boolean): string;
|
|
27
24
|
declare function reportErrors(errors: EnvError[]): void;
|
|
28
25
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./chunk-7CVG4I6F.js";import{a as y,b as p,c as D,d as g,e as T,f,g as u,h as l}from"./chunk-
|
|
1
|
+
import{a as d}from"./chunk-7CVG4I6F.js";import{a as y,b as p,c as D,d as g,e as T,f,g as u,h as l}from"./chunk-5AAC43HE.js";import"./chunk-I7AUKTXE.js";function a(r,e,n,s=[]){return{type:r,default:e,required:e===void 0,parse:n,metadata:s.length?{options:s}:{},from(t){return this.sourceKey=t,this},validate(t,i="Custom validation failed"){return this.metadata={...this.metadata,validate:{fn:t,message:i}},this},min(t){return this.metadata={...this.metadata,min:t},this},max(t){return this.metadata={...this.metadata,max:t},this},transform(t){let i=this.parse;return this.parse=o=>t(i(o)),this},secret(){return this.metadata={...this.metadata,isSecret:!0},this},url(){return this.validate(t=>{try{return new URL(String(t)),!0}catch{return!1}},"Invalid URL format")},email(){return this.validate(t=>/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(String(t)),"Invalid email format")},regex(t,i="Value does not match pattern"){return this.validate(o=>t.test(String(o)),i)},description(t){return this.metadata={...this.metadata,description:t},this}}}var m={string:r=>a("string",r,e=>String(e)),number:r=>a("number",r,e=>{let n=Number(e);if(isNaN(n))throw new Error(`Invalid number: ${e}`);return n}),boolean:r=>a("boolean",r,e=>{if(typeof e=="boolean")return e;if(e===void 0||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: ${e}`)}),enum:(r,e)=>a("enum",e,n=>{if(!r.includes(n))throw new Error(`Value "${n}" is not one of: ${r.join(", ")}`);return n},r),array:(r,e=",")=>a("array",r,n=>Array.isArray(n)?n:typeof n!="string"?[]:n.split(e).map(s=>s.trim()).filter(Boolean))};export{D as BUILD,y as DEV,p as SERVE,g as VITE_DEV_FLAG,T as VITE_PREFIX,f as formatErrorReport,d as parseDotEnv,u as reportErrors,m as s,l as safeEnv};
|
package/dist/vite.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkQKTQJTDScjs = require('./chunk-QKTQJTDS.cjs');require('./chunk-D6WM53FN.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===_chunkQKTQJTDScjs.b,process.env[_chunkQKTQJTDScjs.d]=o?"true":"";let{envDir:t=e.root,prefix:r=e.envPrefix||_chunkQKTQJTDScjs.e}=f,p=_vite.loadEnv.call(void 0, e.mode,t,r);try{_chunkQKTQJTDScjs.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
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;
|
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-
|
|
1
|
+
import{b as a,d as i,e as l,h as m}from"./chunk-5AAC43HE.js";import"./chunk-I7AUKTXE.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
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};
|
package/package.json
CHANGED
package/dist/chunk-BX67JRJU.cjs
DELETED
|
@@ -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 _chunkD6WM53FNcjs = require('./chunk-D6WM53FN.cjs');var $="development",_= exports.b ="serve",j= exports.c ="build",S= exports.d ="VITE_DEV_SERVER",F= exports.e ="VITE_";var V=typeof window<"u"&&typeof window.document<"u";function x(i,s=!0){if(V)return`SafeEnv Validation Failed: ${i.map(o=>`${o.key} (${o.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=(o,t)=>{let f=String(o),p=()=>f.length+(f.match(/[^\x00-\xff]/g)||[]).length;for(;p()>t;)f=f.slice(0,-1);return f+" ".repeat(t-p())},E=80,v=Math.floor(E*.3),g=Math.floor(E*.5),r=s?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",v)} \u2502 ${e("Error",g)} \u2502 Value${r.res}
|
|
4
|
-
`,d+=r.d+"\u2500".repeat(E+5)+r.res+`
|
|
5
|
-
`,i.forEach(o=>{let t=o.value===void 0?"undefined":o.isSecret?"********":`"${o.value}"`,f=o.value===void 0?r.d:o.isSecret?r.y:r.cy;d+=` ${r.y}${e(o.key,v)}${r.res} \u2502 ${r.r}${e(o.error,g)}${r.res} \u2502 ${f}${t}${r.res}
|
|
6
|
-
`}),d+=r.d+"\u2500".repeat(E+5)+r.res+`
|
|
7
|
-
`,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
|
|
8
|
-
`,d}function O(i){if(V){let s=i.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(s)}else console.error(x(i,!0))}var y={};function I(i){let s=x(i,!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
|
-
${s}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}function k(i){let s=Object.getOwnPropertyNames(i);for(let c of s){let e=i[c];e&&typeof e=="object"&&!Object.isFrozen(e)&&k(e)}return Object.freeze(i)}function z(i,s={}){let{loadProcessEnv:c=!0,prefix:e=F,cwd:E,useCache:v=!0,refreshCache:g=!1}=s;if(g)for(let n in y)delete y[n];let r=typeof window<"u",d=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),o=r||d||"source"in s,t={};if("source"in s)t=s.source||{};else if(v&&!g&&Object.keys(y).length>0)t=y;else if(typeof process<"u"&&!r)try{let n=s.mode||process.env.NODE_ENV||$,{loadDotEnv:a}=_chunkD6WM53FNcjs.a.call(void 0, "./fs-node.cjs"),u={};for(let h of[".env",`.env.${n}`,".env.local",`.env.${n}.local`])u={...u,...a(h,E)};t={...u,...c?process.env:{}}}catch (e2){t={}}let f=Object.keys(t).length;if(v&&(f>0?Object.assign(y,t):Object.keys(y).length>0&&(t=y)),o&&Object.keys(t).length===0)return{};let p={},m=[];for(let n in i){let a=i[n],u=e&&!n.startsWith(e)?e+n:n,h=a.sourceKey||(t[u]!==void 0?u:t[n]!==void 0?n:u),b=t[h];try{if(b===void 0||b===""&&a.default!==void 0){if(a.required&&b===void 0)throw new Error("Missing required field");p[n]=a.default}else{let l=a.parse(b);if(l!==void 0&&a.metadata){let{min:D,max:w,validate:T}=a.metadata;if(typeof l=="number"){if(D!==void 0&&l<D)throw new Error(`Below min ${D}`);if(w!==void 0&&l>w)throw new Error(`Above max ${w}`)}if(T&&!T.fn(l))throw new Error(T.message)}p[n]=l}}catch(l){m.push({key:h,error:l.message,value:b,isSecret:_optionalChain([a, 'access', _2 => _2.metadata, 'optionalAccess', _3 => _3.isSecret])})}}if(m.length>0){if(s.throwOnError){let n=new Error(x(m,!0));throw n.plainMessage=x(m,!1),n}return O(m),typeof process<"u"&&process.exit&&!o&&process.exit(1),I(m)}return k(p)}exports.a = $; exports.b = _; exports.c = j; exports.d = S; exports.e = F; exports.f = x; exports.g = O; exports.h = z;
|
package/dist/chunk-IHZESWXY.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{a as R}from"./chunk-I7AUKTXE.js";var $="development",_="serve",j="build",S="VITE_DEV_SERVER",F="VITE_";var V=typeof window<"u"&&typeof window.document<"u";function x(i,s=!0){if(V)return`SafeEnv Validation Failed: ${i.map(o=>`${o.key} (${o.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=(o,t)=>{let f=String(o),p=()=>f.length+(f.match(/[^\x00-\xff]/g)||[]).length;for(;p()>t;)f=f.slice(0,-1);return f+" ".repeat(t-p())},E=80,v=Math.floor(E*.3),g=Math.floor(E*.5),r=s?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",v)} \u2502 ${e("Error",g)} \u2502 Value${r.res}
|
|
4
|
-
`,d+=r.d+"\u2500".repeat(E+5)+r.res+`
|
|
5
|
-
`,i.forEach(o=>{let t=o.value===void 0?"undefined":o.isSecret?"********":`"${o.value}"`,f=o.value===void 0?r.d:o.isSecret?r.y:r.cy;d+=` ${r.y}${e(o.key,v)}${r.res} \u2502 ${r.r}${e(o.error,g)}${r.res} \u2502 ${f}${t}${r.res}
|
|
6
|
-
`}),d+=r.d+"\u2500".repeat(E+5)+r.res+`
|
|
7
|
-
`,d+=` ${r.g}\u{1F4A1} Tip: Check your .env files or schema definitions.${r.res}
|
|
8
|
-
`,d}function O(i){if(V){let s=i.reduce((c,e)=>(c[e.key]={"Error Message":e.error,"Current Value":e.value===void 0?"undefined":e.isSecret?"********":e.value},c),{});console.table(s)}else console.error(x(i,!0))}var y={};function I(i){let s=x(i,!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
|
-
${s}`)},ownKeys(){return[]},getOwnPropertyDescriptor(){}})}function k(i){let s=Object.getOwnPropertyNames(i);for(let c of s){let e=i[c];e&&typeof e=="object"&&!Object.isFrozen(e)&&k(e)}return Object.freeze(i)}function z(i,s={}){let{loadProcessEnv:c=!0,prefix:e=F,cwd:E,useCache:v=!0,refreshCache:g=!1}=s;if(g)for(let n in y)delete y[n];let r=typeof window<"u",d=typeof process<"u"&&(!!process.env.VITE||!!process.env[S]),o=r||d||"source"in s,t={};if("source"in s)t=s.source||{};else if(v&&!g&&Object.keys(y).length>0)t=y;else if(typeof process<"u"&&!r)try{let n=s.mode||process.env.NODE_ENV||$,{loadDotEnv:a}=R("./fs-node.cjs"),u={};for(let h of[".env",`.env.${n}`,".env.local",`.env.${n}.local`])u={...u,...a(h,E)};t={...u,...c?process.env:{}}}catch{t={}}let f=Object.keys(t).length;if(v&&(f>0?Object.assign(y,t):Object.keys(y).length>0&&(t=y)),o&&Object.keys(t).length===0)return{};let p={},m=[];for(let n in i){let a=i[n],u=e&&!n.startsWith(e)?e+n:n,h=a.sourceKey||(t[u]!==void 0?u:t[n]!==void 0?n:u),b=t[h];try{if(b===void 0||b===""&&a.default!==void 0){if(a.required&&b===void 0)throw new Error("Missing required field");p[n]=a.default}else{let l=a.parse(b);if(l!==void 0&&a.metadata){let{min:D,max:w,validate:T}=a.metadata;if(typeof l=="number"){if(D!==void 0&&l<D)throw new Error(`Below min ${D}`);if(w!==void 0&&l>w)throw new Error(`Above max ${w}`)}if(T&&!T.fn(l))throw new Error(T.message)}p[n]=l}}catch(l){m.push({key:h,error:l.message,value:b,isSecret:a.metadata?.isSecret})}}if(m.length>0){if(s.throwOnError){let n=new Error(x(m,!0));throw n.plainMessage=x(m,!1),n}return O(m),typeof process<"u"&&process.exit&&!o&&process.exit(1),I(m)}return k(p)}export{$ as a,_ as b,j as c,S as d,F as e,x as f,O as g,z as h};
|