envlys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import * as zod from 'zod';
2
+ import { ZodType } from 'zod';
3
+
4
+ type EnvironmentOptions = {
5
+ path?: string;
6
+ fileName?: string;
7
+ generateExample?: boolean;
8
+ listEnvironment?: string[];
9
+ };
10
+
11
+ declare const createEnvironment: <T extends ZodType>(schema: T, options?: EnvironmentOptions) => zod.infer<T>;
12
+
13
+ export { createEnvironment };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ var se=Object.create;var G=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var T=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ue=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of le(t))!ce.call(e,n)&&n!==r&&G(e,n,{get:()=>t[n],enumerable:!(o=ie(t,n))||o.enumerable});return e};var O=(e,t,r)=>(r=e!=null?se(ae(e)):{},ue(t||!e||!e.__esModule?G(r,"default",{value:e,enumerable:!0}):r,e));var L=S((He,b)=>{"use strict";var R=T("fs"),k=T("path"),Be=T("os"),xe=T("crypto"),W=["\u25C8 encrypted .env [www.dotenvx.com]","\u25C8 secrets for agents [www.dotenvx.com]","\u2301 auth for agents [www.vestauth.com]","\u2318 custom filepath { path: '/custom/path/.env' }","\u2318 enable debugging { debug: true }","\u2318 override existing { override: true }","\u2318 suppress logs { quiet: true }","\u2318 multiple files { path: ['.env.local', '.env'] }"];function ye(){return W[Math.floor(Math.random()*W.length)]}function x(e){return typeof e=="string"?!["false","0","no","off",""].includes(e.toLowerCase()):!!e}function _e(){return process.stdout.isTTY}function De(e){return _e()?`\x1B[2m${e}\x1B[0m`:e}var Ne=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function Te(e){let t={},r=e.toString();r=r.replace(/\r\n?/mg,`
2
+ `);let o;for(;(o=Ne.exec(r))!=null;){let n=o[1],i=o[2]||"";i=i.trim();let s=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),s==='"'&&(i=i.replace(/\\n/g,`
3
+ `),i=i.replace(/\\r/g,"\r")),t[n]=i}return t}function Oe(e){e=e||{};let t=Z(e);e.path=t;let r=h.configDotenv(e);if(!r.parsed){let s=new Error(`MISSING_DATA: Cannot parse ${t} for an unknown reason`);throw s.code="MISSING_DATA",s}let o=Q(e).split(","),n=o.length,i;for(let s=0;s<n;s++)try{let l=o[s].trim(),c=Ie(r,l);i=h.decrypt(c.ciphertext,c.key);break}catch(l){if(s+1>=n)throw l}return h.parse(i)}function ke(e){console.error(`\u26A0 ${e}`)}function _(e){console.log(`\u2506 ${e}`)}function z(e){console.log(`\u25C7 ${e}`)}function Q(e){return e&&e.DOTENV_KEY&&e.DOTENV_KEY.length>0?e.DOTENV_KEY:process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0?process.env.DOTENV_KEY:""}function Ie(e,t){let r;try{r=new URL(t)}catch(l){if(l.code==="ERR_INVALID_URL"){let c=new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");throw c.code="INVALID_DOTENV_KEY",c}throw l}let o=r.password;if(!o){let l=new Error("INVALID_DOTENV_KEY: Missing key part");throw l.code="INVALID_DOTENV_KEY",l}let n=r.searchParams.get("environment");if(!n){let l=new Error("INVALID_DOTENV_KEY: Missing environment part");throw l.code="INVALID_DOTENV_KEY",l}let i=`DOTENV_VAULT_${n.toUpperCase()}`,s=e.parsed[i];if(!s){let l=new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${i} in your .env.vault file.`);throw l.code="NOT_FOUND_DOTENV_ENVIRONMENT",l}return{ciphertext:s,key:o}}function Z(e){let t=null;if(e&&e.path&&e.path.length>0)if(Array.isArray(e.path))for(let r of e.path)R.existsSync(r)&&(t=r.endsWith(".vault")?r:`${r}.vault`);else t=e.path.endsWith(".vault")?e.path:`${e.path}.vault`;else t=k.resolve(process.cwd(),".env.vault");return R.existsSync(t)?t:null}function q(e){return e[0]==="~"?k.join(Be.homedir(),e.slice(1)):e}function Ve(e){let t=x(process.env.DOTENV_CONFIG_DEBUG||e&&e.debug),r=x(process.env.DOTENV_CONFIG_QUIET||e&&e.quiet);(t||!r)&&z("loading env from encrypted .env.vault");let o=h._parseVault(e),n=process.env;return e&&e.processEnv!=null&&(n=e.processEnv),h.populate(n,o,e),{parsed:o}}function Fe(e){let t=k.resolve(process.cwd(),".env"),r="utf8",o=process.env;e&&e.processEnv!=null&&(o=e.processEnv);let n=x(o.DOTENV_CONFIG_DEBUG||e&&e.debug),i=x(o.DOTENV_CONFIG_QUIET||e&&e.quiet);e&&e.encoding?r=e.encoding:n&&_("no encoding is specified (UTF-8 is used by default)");let s=[t];if(e&&e.path)if(!Array.isArray(e.path))s=[q(e.path)];else{s=[];for(let g of e.path)s.push(q(g))}let l,c={};for(let g of s)try{let d=h.parse(R.readFileSync(g,{encoding:r}));h.populate(c,d,e)}catch(d){n&&_(`failed to load ${g} ${d.message}`),l=d}let p=h.populate(o,c,e);if(n=x(o.DOTENV_CONFIG_DEBUG||n),i=x(o.DOTENV_CONFIG_QUIET||i),n||!i){let g=Object.keys(p).length,d=[];for(let B of s)try{let w=k.relative(process.cwd(),B);d.push(w)}catch(w){n&&_(`failed to load ${B} ${w.message}`),l=w}z(`injected env (${g}) from ${d.join(",")} ${De(`// tip: ${ye()}`)}`)}return l?{parsed:c,error:l}:{parsed:c}}function Ae(e){if(Q(e).length===0)return h.configDotenv(e);let t=Z(e);return t?h._configVault(e):(ke(`you set DOTENV_KEY but you are missing a .env.vault file at ${t}`),h.configDotenv(e))}function Ce(e,t){let r=Buffer.from(t.slice(-64),"hex"),o=Buffer.from(e,"base64"),n=o.subarray(0,12),i=o.subarray(-16);o=o.subarray(12,-16);try{let s=xe.createDecipheriv("aes-256-gcm",r,n);return s.setAuthTag(i),`${s.update(o)}${s.final()}`}catch(s){let l=s instanceof RangeError,c=s.message==="Invalid key length",p=s.message==="Unsupported state or unable to authenticate data";if(l||c){let g=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw g.code="INVALID_DOTENV_KEY",g}else if(p){let g=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw g.code="DECRYPTION_FAILED",g}else throw s}}function Re(e,t,r={}){let o=!!(r&&r.debug),n=!!(r&&r.override),i={};if(typeof t!="object"){let s=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw s.code="OBJECT_REQUIRED",s}for(let s of Object.keys(t))Object.prototype.hasOwnProperty.call(e,s)?(n===!0&&(e[s]=t[s],i[s]=t[s]),o&&_(n===!0?`"${s}" is already defined and WAS overwritten`:`"${s}" is already defined and was NOT overwritten`)):(e[s]=t[s],i[s]=t[s]);return i}var h={configDotenv:Fe,_configVault:Ve,_parseVault:Oe,config:Ae,decrypt:Ce,parse:Te,populate:Re};b.exports.configDotenv=h.configDotenv;b.exports._configVault=h._configVault;b.exports._parseVault=h._parseVault;b.exports.config=h.config;b.exports.decrypt=h.decrypt;b.exports.parse=h.parse;b.exports.populate=h.populate;b.exports=h});var j=S((Xe,H)=>{"use strict";function J(e){return e.replace(/\\\$/g,"$")}function Le(e,t,r){let o={...r,...t},n=/(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g,i=e,s,l=new Set;for(;(s=n.exec(i))!==null;){l.add(i);let[c,p,g]=s,d=p||g,B=/(:\+|\+|:-|-)/,w=d.match(B),D=w?w[0]:null,I=d.split(D),N,y,V=I.shift();if([":+","+"].includes(D)?(N=o[V]?I.join(D):"",y=null):(N=I.join(D),y=o[V]),y?l.has(y)?i=i.replace(c,N):i=i.replace(c,y):i=i.replace(c,N),i===r[V])break;n.lastIndex=0}return i}function je(e){let t={},r=process.env;e&&e.processEnv!=null&&(r=e.processEnv);for(let o in e.parsed){let n=e.parsed[o];r[o]&&r[o]!==n?n=r[o]:n=Le(n,r,t),e.parsed[o]=J(n),t[o]=J(n)}for(let o in e.parsed)r[o]=e.parsed[o];return e}H.exports.expand=je});var a={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",purple:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",blueBright:"\x1B[94m",redBright:"\x1B[91m",greenBright:"\x1B[92m",yellowBright:"\x1B[93m",cyanBright:"\x1B[96m",whiteBright:"\x1B[97m",gray:"\x1B[90m",reset:"\x1B[0m",bgBlack:"\x1B[40m",bgBlue:"\x1B[44m",bgGreen:"\x1B[42m",bgAzure:"\x1B[104m",bgCyan:"\x1B[46m",bgYellow:"\x1B[43m",bgRed:"\x1B[41m",bgPurple:"\x1B[45m",bgGray:"\x1B[100m",bgWhite:"\x1B[47m",bgBlueBright:"\x1B[104m",bgRedBright:"\x1B[101m",bgGreenBright:"\x1B[102m",bgYellowBright:"\x1B[103m",bgCyanBright:"\x1B[106m",bgWhiteBright:"\x1B[107m"},u={black:"#000000",blue:"#60a5fa",green:"#4ade80",yellow:"#facc15",red:"#f87171",purple:"#c084fc",cyan:"#06b6d4",white:"#ffffff",gray:"#a3a3a3",blueBright:"#38bdf8",redBright:"#f87171",greenBright:"#4ade80",yellowBright:"#facc15",cyanBright:"#06b6d4",whiteBright:"#ffffff",bgBlue:"#2563eb",bgGreen:"#16a34a",bgYellow:"#ca8a04",bgRed:"#dc2626",bgPurple:"#9333ea",bgCyan:"#0891b2",bgWhite:"#ffffff",bgGray:"#525252",bgBlack:"#000000",bgBlueBright:"#2563eb",bgGreenBright:"#16a34a",bgYellowBright:"#ca8a04",bgRedBright:"#dc2626",bgPurpleBright:"#9333ea",bgCyanBright:"#0891b2",bgWhiteBright:"#ffffff"},v={check:"\u2705",error:"\u274C",info:"\u2139\uFE0F",warning:"\u26A0\uFE0F",http:"\u{1F310}",debug:"\u{1FAB2}",log:"\u{1F4CB}",rocket:"\u{1F680}"},m={check:"\uF00C",error:"\uF00D",info:"\uF05A",warning:"\uF071",debug:"\uED7B",http:"\u{F059F}",log:"\uF03A",rocket:"\uF135"},ge={error:{level:"error",icon:m.error,emoji:v.error,showBadge:!0,ansi:{color:a.red,bg:a.bgRed},css:{color:u.red,bg:u.bgRed}},info:{level:"info",icon:m.info,emoji:v.info,showBadge:!0,ansi:{color:a.blue,bg:a.bgBlue},css:{color:u.blue,bg:u.bgBlue}},http:{level:"http",icon:m.http,emoji:v.http,showBadge:!0,ansi:{color:a.blueBright,bg:a.bgBlueBright},css:{color:u.bgBlueBright,bg:u.bgBlueBright}},warning:{level:"warning",icon:m.warning,emoji:v.warning,showBadge:!0,ansi:{color:a.yellow,bg:a.bgYellow},css:{color:u.yellow,bg:u.bgYellow}},success:{level:"success",icon:m.check,emoji:v.check,showBadge:!0,ansi:{color:a.green,bg:a.bgGreen},css:{color:u.green,bg:u.bgGreen}},debug:{level:"debug",icon:m.debug,emoji:v.debug,showBadge:!0,ansi:{color:a.purple,bg:a.bgPurple},css:{color:u.purple,bg:u.bgPurple}},log:{level:"log",icon:m.log,emoji:v.log,showBadge:!0,ansi:{color:a.gray,bg:a.bgGray},css:{color:u.gray,bg:u.bgGray}},setup:{level:"setup",icon:m.rocket,emoji:v.rocket,showBadge:!0,ansi:{color:a.cyan,bg:a.bgCyan},css:{color:u.cyan,bg:u.bgCyan}}},he={double:{border:"\u2550",topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",left:"\u2551",right:"\u2551"},simple:{border:"\u2500",topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",left:"\u2502",right:"\u2502"},rounded:{border:"\u2500",topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",left:"\u2502",right:"\u2502"},bold:{border:"\u2501",topLeft:"\u250F",topRight:"\u2513",bottomLeft:"\u2517",bottomRight:"\u251B",left:"\u2503",right:"\u2503"},dashed:{border:"\u2504",topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",left:"\u2502",right:"\u2502"}},pe=e=>Math.floor(e/2)*2,A=typeof process<"u"&&process.release.name==="node",K={height:5,ansi:{color:a.white,borderColor:a.white},css:{color:u.white,borderColor:u.white,bgColor:u.bgGray},blankAbove:!1,blankBelow:!1,width:12,boxStyle:"rounded"},de=(e,t)=>{let r=e.split(`
4
+ `),o=pe(t.width??0),n=he[t.boxStyle??"rounded"],i=n.border.repeat(e.length+4+o),s=`${t.ansi?.borderColor??""}${n.topLeft}${i}${n.topRight}`,l=" ".repeat(Math.floor((4+o)/2)),c="";for(let g of r){let d=" ".repeat(Math.floor((e.length-g.length)/2)),B=g===r.at(-1);c+=`${n.left}${l}${d}${t.ansi?.color??""}${g}${a.reset}${t.ansi?.borderColor}${d}${l}${n.right}${B?"":`
5
+ `}`}let p=`${n.bottomLeft}${i}${n.bottomRight}${a.reset}`;return{style:n,top:s,middle:c,bottom:p,space:l}},fe=(e,t)=>{let r={...K,...t},{style:o,top:n,middle:i,bottom:s,space:l}=de(e,r);if(r.blankAbove&&console.log(""),console.log(n),r.height&&r.height>1){let c=`${o.left}${l}${" ".repeat(e.length)}${l}${o.right}`;for(let p=0;p<r.height-2;p++)p===Math.floor((r.height-2)/2)?console.log(i):console.log(c)}console.log(s),r.blankBelow&&console.log("")},me=(e,t)=>{let r={...K,...t},o=`display: flex;
6
+ align-items: center;
7
+ justify-content: center;
8
+ color: ${r.css?.color};
9
+ background-color: ${r.css?.bgColor};
10
+ border: 2px solid ${r.css?.borderColor};
11
+ border-radius: 4px;
12
+ padding: ${r.css?.padding??"10px"};
13
+ `;return r.blankAbove&&console.log(""),console.log(`%c${e}`,o),r.blankBelow&&console.log(""),[`%c${e}`,o]},be=(e,t)=>{A?fe(e,t):me(e,t)},Y={dots:["\u28FE","\u28F7","\u28EF","\u28DF","\u28FB","\u28FD","\u28FE"],line:["-","\\","|","/"],bounce:["\u2801","\u2802","\u2804","\u2802"],circle:["\u25D0","\u25D3","\u25D1","\u25D2"],arrow:["\u2190","\u2196","\u2191","\u2197","\u2192","\u2198","\u2193","\u2199"],grow:[".","..","...","....",".....","......","......."]},E={reset:"\x1B[0m",underline:"\x1B[4m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",inverse:"\x1B[7m",hidden:"\x1B[8m",strikethrough:"\x1B[9m"},ve=(e,t)=>(t.bold&&e.push(E.bold),t.dim&&e.push(E.dim),t.italic&&e.push(E.italic),t.inverse&&e.push(E.inverse),t.hidden&&e.push(E.hidden),t.underline&&e.push(E.underline),t.strikethrough&&e.push(E.strikethrough),t.reset&&e.push(E.reset),e.join("")),f={ansi:(e,t)=>{let r=[];return t.color&&r.push(t.color),t.bg&&r.push(t.bg),ve(r,t),`${r.join("")}${e}${a.reset}`},css:(e,t)=>[`%c${e}`,t]},F=()=>new Date().toLocaleTimeString("en-GB",{hour12:!1}),Ee=class{color=a.blueBright;frameIndex=0;message="Loading...";position="right";showTimestamp=!1;timer=null;type="dots";constructor({message:e,position:t,color:r,showTimestamp:o,type:n}){this.message=e,this.position=t??this.position,this.color=r??this.color,this.showTimestamp=o??this.showTimestamp,this.type=n??this.type}start(){if(!A)return;let e=f.ansi(F(),{color:a.gray}),t=this.showTimestamp?`${e} `:"";process.stdout.write("\x1B[?25l"),this.timer=setInterval(()=>{let r=f.ansi(Y[this.type][this.frameIndex],{color:this.color}),o=f.ansi(this.message,{color:this.color});this.position==="left"?process.stdout.write(`\r${t}${r} ${o} `):process.stdout.write(`\r${t}${o} ${r}`),this.frameIndex=(this.frameIndex+1)%Y[this.type].length},80)}stop(e,t=m.check){this.timer&&(clearInterval(this.timer),this.timer=null),process.stdout.write("\r\x1B[2K");let r=f.ansi(F(),{color:a.gray}),o=this.showTimestamp?`${r} `:"",n=f.ansi(e??this.message,{color:this.color}),i=f.ansi(t,{color:a.greenBright});this.position==="left"?process.stdout.write(`\r\x1B[K${o}${i} ${n}
14
+ `):process.stdout.write(`\r\x1B[K${o}${n} ${i}
15
+ `),process.stdout.write("\x1B[?25h")}},M=e=>{let t=new URL(e);return t.pathname+t.search};var C=class{options;constructor(e={}){this.options={showTimestamp:!0,showBadge:!0,isDev:!0,prefix:"",...e}}formatAnsi(e,t,r,o){let n=f.ansi(e,{color:a.gray}),i=f.ansi(` ${o.icon} ${t.toUpperCase()} `,{color:o.ansi?.color,bg:o.ansi?.bg,bold:!0}),s=o.showBadge?` ${i} `:" ",l=f.ansi(r,{color:o.ansi?.color});return[`${n}${s}${l}`]}formatCss(e,t,r,o){let n=`background: ${o.css?.bg}; color: ${u.white}; font-weight: bold; padding: 2px 6px; border-radius: 3px;`,[i,s]=f.css(e,`color: ${u.gray};`),[l,c]=f.css(`${o.emoji} ${t.toUpperCase()}`,n),[p,g]=f.css(` ${r}`,`color: ${o.css?.color}; font-weight: bold;`);return[`${i} ${l} ${p}`,s,c,g]}formatMessage(e,t,r){let o={...ge[e],...this.options[e],...r},n=r?.showTimestamp??this.options.showTimestamp?F():"",i=r?.prefix??this.options.prefix,s=i?`${i} ${t}`:t;return A?this.formatAnsi(n,e,s,o):this.formatCss(n,e,s,o)}run(e,t,r){this.options.isDev&&this.runWithSpacing(()=>{console.log(...this.formatMessage(e,t,r))},r)}runWithSpacing(e,t){(t?.blankAbove||this.options.blankAbove)&&console.log(""),e(),(t?.blankBelow||this.options.blankBelow)&&console.log("")}blank(){console.log("")}box(e,t){be(e,t)}custom(e,t){this.run("debug",e,t)}debug(e,t){this.run("debug",e,t)}error(e,t){this.run("error",e,t)}http(e){let t=M(e?.url??"");this.run("http",`${e?.method} ${e?.status} - ${t} (${e?.time}ms)`,e)}httpError(e,t){let r=M(t?.url??"");this.run("error",`${t?.method} ${t?.status} - ${r} (${t?.time}ms) - ${e}`,t)}info(e,t){this.run("info",e,t)}loader(e){return new Ee({...e})}log(e,t){this.run("log",e,t)}setup(e,t){this.run("setup",e,t)}success(e,t){this.run("success",e,t)}warning(e,t){this.run("warning",e,t)}};var Me=new C;var $=new C;import we from"fs";import{resolve as $e}from"path";var P=(e,t)=>{let o=`${$e(process.cwd(),t?.path??"",t?.fileName??`.env.${t?.currentState}`)}.example`,n=Object.entries(e).map(([i,s])=>{let l=s===void 0?`<${i}>`:s;return`${i}=${l}`}).join(`
16
+ `);we.writeFileSync(o,n),$.success(`Example file generated: ${o}`)},U=(e,t)=>{if(t?.listEnvironment&&t.listEnvironment.length>0)for(let r of t.listEnvironment){let o=Object.fromEntries(Object.entries(e).filter(([n])=>n===r));P(o,t)}else P(e,t)};var X=O(L(),1),ee=O(j(),1);import{existsSync as Ge}from"fs";import{resolve as Se}from"path";var te=e=>{let t=process.env.NODE_ENV??"development",r=Se(process.cwd(),e?.path??"",e?.fileName??`.env.${t}`);if(Ge(r)){let o=X.default.config({path:r});return(0,ee.expand)(o),{path:r,state:t}}throw new Error(`No se encontr\xF3 el archivo de entorno en la ruta: ${r}`)};var re=e=>{$.error("Invalid environment configuration detected");let{fieldErrors:t}=e.flatten();Object.entries(t).forEach(([r,o])=>{let n=Array.isArray(o)?o:[o];n.length>0&&$.error(`Field [${r}]: ${n.join(", ")}`)}),process.exit(1)};var oe=O(L(),1),ne=O(j(),1),ct=(e,t)=>{let r=te(t);(0,ne.expand)(oe.default.config({path:r.path}));let o=e.safeParse(process.env);if(o.success)return $.success("Environment configuration loaded successfully"),t?.generateExample&&U(o.data,{...t,currentState:r.state,listEnvironment:t.listEnvironment}),o.data;throw re(o.error),new Error("Environment validation failed")};export{ct as createEnvironment};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "envlys",
3
+ "description": "📦️ A lightweight, type-safe environment variable validator for TypeScript and Bun, powered by Zod. Features auto-loading, variable expansion, and automatic .env.example generation",
4
+ "author": "Luis Monsalve",
5
+ "version": "1.0.0",
6
+ "homepage": "https://github.com/TheElegantCoding/envlys#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TheElegantCoding/envlys.git"
10
+ },
11
+ "keywords": [
12
+ "typescript",
13
+ "github",
14
+ "git",
15
+ "clean-code",
16
+ "environment-variables",
17
+ "env-validation"
18
+ ],
19
+ "bugs": {
20
+ "url": "https://github.com/TheElegantCoding/envlys/issues"
21
+ },
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ }
28
+ },
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "files": ["./dist"],
32
+ "engines": {
33
+ "node": ">=22.17.0",
34
+ "bun": ">=1.1.0"
35
+ },
36
+ "scripts": {
37
+ "postinstall": "bunx gitlys init",
38
+ "dev": "bunx tsup --watch playground/index.ts",
39
+ "build": "tsup",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "eslint --fix",
42
+ "release": "bunx gitlys release"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^25.6.0",
46
+ "dotenv": "^17.4.2",
47
+ "dotenv-expand": "^13.0.0",
48
+ "eslint-config-universal-code": "^1.0.15",
49
+ "gitlys": "^1.1.5",
50
+ "logginlys": "^3.0.2",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^5.9.3",
53
+ "zod": "^4.3.6"
54
+ }
55
+ }
package/readme.md ADDED
@@ -0,0 +1,189 @@
1
+ <img src="./.github/asset/illustration/wave_header.svg" width="100%" />
2
+
3
+ <h1 id="top" align="center">
4
+ <img src="./.github/asset/icon/setting.svg" width="28px" align="center" />
5
+ Envlys
6
+ </h1>
7
+
8
+ <br />
9
+
10
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" />
11
+
12
+ <pre align="center">
13
+ <a href="#installation">📦 SETUP</a> • <a href="#configuration">⚙️ CONFIGURATION</a> • <a href="#features">🛰️ FEATURES</a>
14
+ </pre>
15
+
16
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" />
17
+
18
+ <img src="./.github/asset/illustration/envlys_cover.svg" width="100%" />
19
+
20
+ <br />
21
+
22
+ <div align="center">
23
+ <img src="./.github/asset/illustration/eslint_badge.svg" height="34px" />&nbsp;&nbsp;&nbsp;
24
+ <img src="./.github/asset/illustration/bun_badge.svg" height="34px" />&nbsp;&nbsp;&nbsp;
25
+ <img src="./.github/asset/illustration/github_badge.svg" height="34px" />&nbsp;&nbsp;&nbsp;
26
+ <img src="./.github/asset/illustration/typescript_badge.svg" height="34px" />&nbsp;&nbsp;&nbsp;
27
+ </div>
28
+
29
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" />
30
+
31
+ <h2 id="about">
32
+ <img src="./.github/asset/icon/information.svg" width="24px" align="center"/>
33
+ About
34
+ </h2>
35
+
36
+ <table border="0">
37
+ <tr>
38
+ <td>
39
+ A lightweight, type-safe environment variable validator for TypeScript and Bun, powered by Zod. Features auto-loading, variable expansion, and automatic .env.example generation
40
+ </td>
41
+ </tr>
42
+ </table>
43
+
44
+ <br />
45
+
46
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" />
47
+
48
+ <h2 id="table-of-content">
49
+ <img src="./.github/asset/icon/book.svg" width="24px" align="center"/>
50
+ Table of content
51
+ </h2>
52
+
53
+ - [<img src="./.github/asset/icon/information.svg" width="20px" align="center" /> About](#about)
54
+ - [<img src="./.github/asset/icon/thunder.svg" width="20px" align="center" /> Requirements](#requirements)
55
+ - [<img src="./.github/asset/icon/package.svg" width="20px" align="center" /> Installation](#installation)
56
+ - [<img src="./.github/asset/icon/rocket.svg" width="20px" align="center" /> Usage](#usage)
57
+ - [<img src="./.github/asset/icon/gear.svg" width="20px" align="center" /> Configuration](#configuration)
58
+
59
+ <br />
60
+
61
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" />
62
+
63
+ <h2 id="requirements">
64
+ <img src="./.github/asset/icon/thunder.svg" width="24px" align="center" />
65
+ Requirements
66
+ </h2>
67
+
68
+ - <img src="./.github/asset/icon/node.svg" width="20px" align="center" /> node >= **22.17.0**
69
+ - <img src="./.github/asset/icon/bun.svg" width="20px" align="center" /> bun >= **1.1.0**
70
+
71
+ <br />
72
+
73
+ <img src="./.github/asset/illustration/divider.svg" alt="divider" width="100%" align="center" />
74
+
75
+ <h2 id="installation">
76
+ <img src="./.github/asset/icon/package.svg" width="24px" align="center" />
77
+ Installation
78
+ </h2>
79
+
80
+ <h3><img src="./.github/asset/icon/bun.svg" width="24px" align="center" /> Bun</h3>
81
+
82
+ ```bash
83
+ bun i -D envlys
84
+ ```
85
+
86
+ <h3><img src="./.github/asset/icon/npm.svg" width="24px" align="center" /> Npm</h3>
87
+
88
+ ```bash
89
+ npm i -D envlys
90
+ ```
91
+
92
+ <h3><img src="./.github/asset/icon/pnpm.svg" width="24px" align="center" /> Pnpm</h3>
93
+
94
+ ```bash
95
+ pnpm i -D envlys
96
+ ```
97
+
98
+ <h3><img src="./.github/asset/icon/yarn.svg" width="24px" align="center" /> Yarn</h3>
99
+
100
+ ```bash
101
+ yarn i -D envlys
102
+ ```
103
+
104
+ <br />
105
+
106
+ <img
107
+ src="./.github/asset/illustration/divider.svg"
108
+ alt="divider"
109
+ width="100%"
110
+ />
111
+
112
+ <h2 id="usage">
113
+ <img src="./.github/asset/icon/rocket.svg" width="24px" align="center" />
114
+ Usage
115
+ </h2>
116
+
117
+ In order to validate your environment variables, you can use the `createEnvironment` function from the `envlys` package. This function takes an object with the following properties:
118
+
119
+ ```ts
120
+ import { createEnvironment } from 'envlys';
121
+ import { z } from 'zod';
122
+
123
+ const environment = z.object({
124
+ NODE_ENV: z.enum([ 'development', 'production'], {
125
+ error: "NODE_ENV has to be either 'development' or 'production'"
126
+ }),
127
+ PORT: z.coerce.number({ error: 'PORT must be a number (e.g., 4321)' }),
128
+ BASE_URL: z.string({
129
+ error: 'Base URL is required and must be a string (e.g., http://localhost:4321)'
130
+ }).default('http://localhost:4321')
131
+ });
132
+
133
+ const { NODE_ENV, PORT, BASE_URL } = createEnvironment(environment, {
134
+ path: './',
135
+ generateExample: true,
136
+ listEnvironment: [
137
+ 'development',
138
+ 'production'
139
+ ]
140
+ });
141
+ ```
142
+
143
+ <br />
144
+
145
+ <img
146
+ src="./.github/asset/illustration/divider.svg"
147
+ alt="divider"
148
+ width="100%"
149
+ />
150
+
151
+ <h2 id="configuration">
152
+ <img src="./.github/asset/icon/gear.svg" width="24px" align="center" />
153
+ Configuration
154
+ </h2>
155
+
156
+ The `createEnvironment` function accepts a second parameter, which is an object with the following optional properties:
157
+
158
+ - `path`: A string that specifies the path to the directory where the `.env` file is located. Default is `./`.
159
+ - `generateExample`: A boolean that indicates whether to generate a `.env.example` file based on the provided Zod schema. Default is `false`.
160
+ - `listEnvironment`: An array of strings that specifies the valid values for the `NODE_ENV` variable. Default is `['development', 'production']` this help to generate examples for every environment.
161
+ - `filename`: A string that specifies the name of the `.env` file to load. Default is `.env`.
162
+
163
+ <br />
164
+
165
+ <img
166
+ src="./.github/asset/illustration/divider.svg"
167
+ alt="divider"
168
+ width="100%"
169
+ />
170
+
171
+ <pre align="center">
172
+ <a href="#top">BACK TO TOP</a>
173
+ </pre>
174
+
175
+ <img
176
+ src="./.github/asset/illustration/divider.svg"
177
+ alt="divider"
178
+ width="100%"
179
+ />
180
+
181
+ <pre align="center">
182
+ Copyright © All rights reserved,
183
+ developed by LuisdaByte and
184
+ </pre>
185
+ <div align="center">
186
+ <img src="./.github/asset/illustration/astralys_logo.svg" width="120px" align="center" />
187
+ </div>
188
+
189
+ <img src="./.github/asset/illustration/wave_footer.svg" width="100%" />