@stacksjs/env 0.70.44 → 0.70.53
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/index.js +23 -23
- package/dist/types.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import XJ from"process";import{projectPath as jJ}from"@stacksjs/path";import
|
|
3
|
-
`);for(let X of Z){let
|
|
4
|
-
`)}if(Q.privateKey&&(j.startsWith("encrypted:")||j.startsWith("enc:")))try{let
|
|
2
|
+
import XJ from"process";import{projectPath as jJ}from"@stacksjs/path";import l from"fs";var K={APP_ENV:["local","dev","development","staging","prod","production"],DB_CONNECTION:["mysql","sqlite","postgres","dynamodb"],MAIL_MAILER:["smtp","mailgun","ses","log","sendgrid","mailtrap"],SEARCH_ENGINE_DRIVER:["opensearch","meilisearch","algolia","typesense"],FRONTEND_APP_ENV:["development","staging","production"]};import{createCipheriv as p,createDecipheriv as i,createHash as f,randomBytes as m}from"crypto";function a(J,Q){let $=m(16),z=Q.length===32?Q:Buffer.from(Q.toString("hex").slice(0,64),"hex"),Z=p("aes-256-gcm",z,$),X=Buffer.concat([Z.update(J,"utf8"),Z.final()]),Y=Z.getAuthTag();return{ciphertext:X.toString("hex"),iv:$.toString("hex"),authTag:Y.toString("hex")}}function n(J,Q,$,z){let Z=Q.length===32?Q:Buffer.from(Q.toString("hex").slice(0,64),"hex");try{let X=i("aes-256-gcm",Z,Buffer.from($,"hex"));return X.setAuthTag(Buffer.from(z,"hex")),Buffer.concat([X.update(Buffer.from(J,"hex")),X.final()]).toString("utf8")}catch(X){throw Error(`Decryption failed (data may be corrupted or key is incorrect): ${X instanceof Error?X.message:String(X)}`)}}function b(){let J=m(32);return{publicKey:f("sha256").update(J).digest().toString("hex"),privateKey:J.toString("hex")}}function S(J,Q){let $=f("sha256").update(Buffer.from(Q,"hex")).digest(),{ciphertext:z,iv:Z,authTag:X}=a(J,$);return`encrypted:${Buffer.concat([Buffer.from(Z,"hex"),Buffer.from(X,"hex"),Buffer.from(z,"hex")]).toString("base64")}`}function x(J,Q){if(!J.startsWith("encrypted:"))return J;let $=J.slice(10),z=Buffer.from($,"base64");if(z.length<32)throw Error("Invalid encrypted data: payload too short (need at least iv + authTag = 32 bytes)");let Z=z.subarray(0,16).toString("hex"),X=z.subarray(16,32).toString("hex"),Y=z.subarray(32).toString("hex"),W=f("sha256").update(Buffer.from(Q,"hex")).digest(),G=f("sha256").update(W).digest();return n(Y,G,Z,X)}function AJ(J){let Q=J.match(/^DOTENV_PRIVATE_KEY_(.+)$/);return Q&&Q[1]?Q[1].toLowerCase():""}function h(J=""){if(!J)return process.env.DOTENV_PRIVATE_KEY;let Q=`DOTENV_PRIVATE_KEY_${J.toUpperCase()}`;return process.env[Q]}function T(J,Q={}){let $={},z=[],Z=J.split(`
|
|
3
|
+
`);for(let X of Z){let Y=X.trim();if(!Y||Y.startsWith("#"))continue;if(Y.startsWith("DOTENV_PUBLIC_KEY=")){let q=Y.match(/^DOTENV_PUBLIC_KEY=["']?([^"'\n]+)["']?/);if(q&&q[1]!==void 0)$.DOTENV_PUBLIC_KEY=q[1];continue}let W=Y.match(/^([^=]+)=(.*)$/);if(!W||W[1]===void 0||W[2]===void 0)continue;let G=W[1].trim(),j=W[2].trim();if(j.startsWith('"')&&j.endsWith('"')||j.startsWith("'")&&j.endsWith("'")){if(j=j.slice(1,-1),j.includes("\\n"))j=j.replace(/\\n/g,`
|
|
4
|
+
`)}if(Q.privateKey&&(j.startsWith("encrypted:")||j.startsWith("enc:")))try{let q=j.startsWith("enc:")?`encrypted:${j.slice(4)}`:j;j=x(q,Q.privateKey)}catch(q){z.push(`Failed to decrypt ${G}: ${q instanceof Error?q.message:"Unknown error"}`)}j=r(j,{...Q.processEnv||process.env,...$}),j=s(j),$[G]=j}return{parsed:$,errors:z}}function r(J,Q){return J.replace(/\$\{([^}]+)\}/g,($,z)=>{let Z=z.match(/^([^:\-+]+)(:-|-)(.+)$/);if(Z){let[,Y,W,G]=Z,j=Q[Y];if(W===":-")return j||G;else return j!==void 0?j:G}let X=z.match(/^([^:\-+]+)(:?\+)(.+)$/);if(X){let[,Y,W,G]=X,j=Q[Y];if(W===":+")return j?G:"";else return j!==void 0?G:""}return Q[z]||""})}var o=new Set(["date","hostname","whoami","uname","pwd","echo","printf","cat","basename","dirname"]);function s(J){return J.replace(/\$\(([^)]+)\)/g,(Q,$)=>{try{let z=$.trim().split(/\s+/),Z=z[0];if(!Z||!o.has(Z))return console.warn(`[env] Blocked command substitution for disallowed command: ${Z}`),"";let X=Bun.spawnSync(z,{stdout:"pipe",stderr:"pipe"});if(X.exitCode===0)return new TextDecoder().decode(X.stdout).trim();console.warn(`[env] Command substitution failed (exit code ${X.exitCode}): ${Z}`)}catch(z){console.warn(`[env] Command substitution error: ${z instanceof Error?z.message:String(z)}`)}return""})}async function _J(J,Q={}){let $={},z=[];for(let Z of J)try{let X=Bun.file(Z);if(!X.size)continue;let Y=await X.text(),{parsed:W,errors:G}=T(Y,Q);z.push(...G);for(let[j,q]of Object.entries(W)){if(!Q.overload&&$[j]!==void 0)continue;$[j]=q}}catch(X){if(X?.code==="ENOENT")continue;z.push(`Failed to read ${Z}: ${X instanceof Error?X.message:String(X)}`)}return{parsed:$,errors:z}}import{existsSync as F}from"fs";import{readFileSync as k}from"fs";import{resolve as w}from"path";function d(J={}){let{path:Q=[".env"],overload:$=!1,env:z,privateKey:Z,keysFile:X,quiet:Y=!1,cwd:W=process.cwd()}=J,G=Array.isArray(Q)?Q:[Q],j=[],q=0,D=Z;if(!D&&X){let H=w(W,X);if(F(H))try{let O=k(H,"utf-8"),{parsed:U}=T(O);if(z){let B=`DOTENV_PRIVATE_KEY_${z.toUpperCase()}`;D=U[B]}else D=U.DOTENV_PRIVATE_KEY}catch(O){j.push(`Failed to load keys file: ${O instanceof Error?O.message:"Unknown error"}`)}}if(!D)D=h(z||"");for(let H of G){let O=w(W,H);if(!F(O)){if(!Y)j.push(`File not found: ${O}`);continue}try{let U=k(O,"utf-8"),{parsed:B,errors:I}=T(U,{privateKey:D,processEnv:process.env});j.push(...I);for(let[A,M]of Object.entries(B)){if(A==="DOTENV_PUBLIC_KEY")continue;if($||process.env[A]===void 0)process.env[A]=M,q++}if(!Y&&!process.env.__ENV_LOADED__)console.log(`[env] loaded ${Object.keys(B).length} variables from ${H}`),process.env.__ENV_LOADED__="1"}catch(U){j.push(`Failed to load ${O}: ${U instanceof Error?U.message:"Unknown error"}`)}}return{loaded:q,errors:j}}function LJ(J={}){return{name:"env-plugin",setup(Q){d(J)}}}function CJ(J={}){let Q=J.env||"development",$=J.cwd||process.cwd(),z=[],Z=`.env.${Q}`,X=`.env.${Q}.local`;if(F(w($,X)))z.push(X);if(F(w($,Z)))z.push(Z);if(F(w($,".env.local")))z.push(".env.local");if(F(w($,".env")))z.push(".env");return d({...J,path:z,env:Q})}import{existsSync as g,readFileSync as L,writeFileSync as V}from"fs";import{resolve as C}from"path";function t(J={}){let Q=J.cwd||process.cwd(),$=C(Q,J.file||".env"),z=C(Q,J.keysFile||".env.keys");if(!g($))return{success:!1,error:`File not found: ${$}`};try{let Z,X;if(g(z)){let H=L(z,"utf-8"),{parsed:O}=T(H),I=((J.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),A=I?`DOTENV_PUBLIC_KEY_${I}`:"DOTENV_PUBLIC_KEY",M=I?`DOTENV_PRIVATE_KEY_${I}`:"DOTENV_PRIVATE_KEY";if(Z=O[A]||"",X=O[M]||"",!Z||!X){let R=b();Z=R.publicKey,X=R.privateKey;let E=`
|
|
5
|
+
${A}="${Z}"
|
|
6
|
+
${M}="${X}"
|
|
7
|
+
`;V(z,H+E,"utf-8")}}else{let H=b();Z=H.publicKey,X=H.privateKey;let B=((J.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),I=B?`DOTENV_PUBLIC_KEY_${B}`:"DOTENV_PUBLIC_KEY",A=B?`DOTENV_PRIVATE_KEY_${B}`:"DOTENV_PRIVATE_KEY",M=`# .env.keys - Keep this file secure and never commit to source control
|
|
5
8
|
${I}="${Z}"
|
|
6
|
-
${
|
|
7
|
-
`;
|
|
8
|
-
${q}="${Z}"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`),
|
|
12
|
-
`);if(J.stdout)return{success:!0,output:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
${
|
|
18
|
-
${
|
|
19
|
-
|
|
20
|
-
`)
|
|
21
|
-
`)
|
|
22
|
-
`)
|
|
23
|
-
`),"utf-8"),t({file:J.file,keysFile:J.keysFile,key:J.key,excludeKey:J.excludeKey,stdout:J.stdout,cwd:J.cwd})}import _ from"process";import{platform as JJ}from"os";var u=typeof Bun<"u",c=typeof _<"u"&&_.versions?.node!==void 0,QJ=u?"bun":c?"node":"unknown",mJ={name:QJ,version:u?Bun.version:c?_.version:void 0},P=JJ(),hJ=P==="win32",kJ=P==="darwin",dJ=P==="linux",v=Boolean(_.stdout?.isTTY),uJ=typeof globalThis.window<"u",ZJ=Boolean(_.env.CI||_.env.CONTINUOUS_INTEGRATION||_.env.BUILD_NUMBER||_.env.RUN_ID),cJ=Boolean(_.env.DEBUG||_.env.VERBOSE||_.argv.includes("--debug")||_.argv.includes("--verbose")),$J=ZJ||!v,vJ=Boolean(!$J&&(v||_.env.COLORTERM||_.env.FORCE_COLOR||_.env.TERM&&_.env.TERM!=="dumb")),N={github:{name:"GitHub Actions",detected:Boolean(_.env.GITHUB_ACTIONS)},gitlab:{name:"GitLab CI",detected:Boolean(_.env.GITLAB_CI)},circle:{name:"CircleCI",detected:Boolean(_.env.CIRCLECI)},travis:{name:"Travis CI",detected:Boolean(_.env.TRAVIS)},jenkins:{name:"Jenkins",detected:Boolean(_.env.JENKINS_URL)},vercel:{name:"Vercel",detected:Boolean(_.env.VERCEL)},netlify:{name:"Netlify",detected:Boolean(_.env.NETLIFY)},heroku:{name:"Heroku",detected:Boolean(_.env.DYNO)},aws:{name:"AWS",detected:Boolean(_.env.AWS_REGION||_.env.AWS_LAMBDA_FUNCTION_NAME)},azure:{name:"Azure",detected:Boolean(_.env.AZURE_HTTP_USER_AGENT)},cloudflare:{name:"Cloudflare",detected:Boolean(_.env.CF_PAGES)},railway:{name:"Railway",detected:Boolean(_.env.RAILWAY_ENVIRONMENT)},render:{name:"Render",detected:Boolean(_.env.RENDER)}},zJ=Object.keys(N).find((J)=>{let Q=N[J];return Q!==void 0&&Q.detected})||"unknown",yJ=N[zJ]||{name:"Unknown",detected:!1};var GJ={get:(J,Q)=>{let $=J[Q],z=["_PORT","_TIMEOUT","_TTL","_SIZE","_LIMIT","_MAX","_MIN","_INTERVAL","_RETRIES","_CONCURRENCY","_WORKERS","_CONNECTIONS"];if(typeof $==="string"&&/^\d+$/.test($)&&!$.startsWith("0")&&z.some((Z)=>Q.endsWith(Z)))return Number($);if(typeof $==="string"){let Z=$.toLowerCase();if(Z==="true")return!0;if(Z==="false")return!1}return $}};function WJ(){return typeof Bun<"u"?Bun.env:XJ.env}var l=new Proxy(WJ(),GJ);function rJ(J,Q,$){let z=$?.path||jJ(".env"),X=y.readFileSync(z,"utf-8").split(`
|
|
24
|
-
`),W=X.findIndex((j)=>j.startsWith(`${J}=`)),G=/[\s"'#$\\]/.test(Q)?`"${Q.replace(/"/g,"\\\"")}"`:Q;if(W!==-1)X[W]=`${J}=${G}`;else X.push(`${J}=${G}`);y.writeFileSync(z,X.join(`
|
|
25
|
-
`))}function oJ(J=l){let Q=[];for(let[$,z]of Object.entries(K)){let Z=J[$];if(Z!==void 0&&Z!==""&&!z.includes(String(Z)))Q.push(`${$}="${Z}" is not valid. Allowed values: ${z.join(", ")}`)}return Q}function sJ(J,Q=l){let $=[];for(let z of J){let Z=Q[z];if(Z===void 0||Z===""||Z===null)$.push(z)}if($.length>0)throw Error(`[env] Missing required environment variable(s): ${$.join(", ")}. Set them in .env or your process environment before booting.`);return Q}export{rJ as writeEnv,oJ as validateEnv,wJ as setEnv,mJ as runtimeInfo,QJ as runtime,SJ as rotateKeypair,sJ as requireEnv,yJ as providerInfo,zJ as provider,WJ as process,P as platform,AJ as parseEnvFromKey,C as parse,_J as loadEnvFiles,d as loadEnv,hJ as isWindows,c as isNode,$J as isMinimal,kJ as isMacOS,dJ as isLinux,cJ as isDebug,vJ as isColorSupported,ZJ as isCI,u as isBun,uJ as hasWindow,v as hasTTY,h as getPrivateKey,xJ as getKeypair,fJ as getEnv,b as generateKeypair,CJ as envPlugin,K as envEnum,l as env,S as encryptValue,t as encryptEnv,x as decryptValue,e as decryptEnv,LJ as autoLoadEnv,a as aesEncrypt,n as aesDecrypt};
|
|
9
|
+
${A}="${X}"
|
|
10
|
+
`;V(z,M,"utf-8")}let W=L($,"utf-8").split(`
|
|
11
|
+
`),G=[],j=J.file?J.file.replace(/^\.env\./,"").toUpperCase():"",q=j?`DOTENV_PUBLIC_KEY_${j}`:"DOTENV_PUBLIC_KEY";G.push("#/-------------------[DOTENV_PUBLIC_KEY]--------------------/"),G.push("#/ public-key encryption for .env files /"),G.push("#/ [how it works](https://stacksjs.com/encryption) /"),G.push("#/----------------------------------------------------------/"),G.push(`${q}="${Z}"`),G.push("");for(let H of W){let O=H.trim();if(!O||O.startsWith("#")){G.push(H);continue}if(O.startsWith("DOTENV_PUBLIC_KEY"))continue;let U=O.match(/^([^=]+)=(.*)$/);if(!U||U[1]===void 0||U[2]===void 0){G.push(H);continue}let B=U[1].trim(),I=U[2].trim();if(I.startsWith('"')&&I.endsWith('"')||I.startsWith("'")&&I.endsWith("'"))I=I.slice(1,-1);let A=!0;if(J.key&&!B.includes(J.key))A=!1;if(J.excludeKey&&B.includes(J.excludeKey))A=!1;if(I.startsWith("encrypted:"))A=!1;if(A)I=S(I,Z);G.push(`${B}="${I}"`)}let D=G.join(`
|
|
12
|
+
`);if(J.stdout)return{success:!0,output:D};return V($,D,"utf-8"),{success:!0,output:`\u2714 encrypted (${J.file||".env"})
|
|
13
|
+
\u2714 key added to ${J.keysFile||".env.keys"}`}}catch(Z){return{success:!1,error:`Failed to encrypt: ${Z instanceof Error?Z.message:"Unknown error"}`}}}function e(J={}){let Q=J.cwd||process.cwd(),$=C(Q,J.file||".env"),z=C(Q,J.keysFile||".env.keys");if(!g($))return{success:!1,error:`File not found: ${$}`};if(!g(z))return{success:!1,error:`Keys file not found: ${z}`};try{let Z=L(z,"utf-8"),{parsed:X}=T(Z),G=((J.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),j=G?`DOTENV_PRIVATE_KEY_${G}`:"DOTENV_PRIVATE_KEY",q=X[j];if(!q)return{success:!1,error:`Private key not found: ${j}`};let H=L($,"utf-8").split(`
|
|
14
|
+
`),O=[];for(let B of H){let I=B.trim();if(!I||I.startsWith("#")){O.push(B);continue}if(I.startsWith("DOTENV_PUBLIC_KEY"))continue;let A=I.match(/^([^=]+)=(.*)$/);if(!A||A[1]===void 0||A[2]===void 0){O.push(B);continue}let M=A[1].trim(),R=A[2].trim();if(R.startsWith('"')&&R.endsWith('"')||R.startsWith("'")&&R.endsWith("'"))R=R.slice(1,-1);let E=R.startsWith("encrypted:");if(J.key&&!M.includes(J.key))E=!1;if(E)R=x(R,q);O.push(`${M}="${R}"`)}let U=O.join(`
|
|
15
|
+
`);if(J.stdout)return{success:!0,output:U};return V($,U,"utf-8"),{success:!0,output:`\u2714 decrypted (${J.file||".env"})`}}catch(Z){return{success:!1,error:`Failed to decrypt: ${Z instanceof Error?Z.message:"Unknown error"}`}}}function bJ(J,Q,$={}){let z=$.cwd||process.cwd(),Z=C(z,$.file||".env"),X=C(z,$.keysFile||".env.keys");try{let Y="";if(g(Z))Y=L(Z,"utf-8");let W=Y.split(`
|
|
16
|
+
`),G=!1,j,H=(($.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),O=H?`DOTENV_PUBLIC_KEY_${H}`:"DOTENV_PUBLIC_KEY",U=H?`DOTENV_PRIVATE_KEY_${H}`:"DOTENV_PRIVATE_KEY";for(let A of W){let M=A.trim();if(M.startsWith(`${O}=`)){let R=M.match(/^[^=]+=["']?([^"'\n]+)["']?/);if(R)j=R[1];break}}if(j){let A=!1;if(g(X)){let M=L(X,"utf-8"),{parsed:R}=T(M);A=Boolean(R[U])}if(!A)j=void 0}if(!$.plain&&!j){let A=b();j=A.publicKey;let M="";if(g(X))M=L(X,"utf-8");M+=`
|
|
17
|
+
${O}="${A.publicKey}"
|
|
18
|
+
${U}="${A.privateKey}"
|
|
19
|
+
`,V(X,M,"utf-8");for(let R=W.length-1;R>=0;R--){let E=W[R];if(E!==void 0&&E.trim().startsWith(`${O}=`))W.splice(R,1)}W.unshift(`${O}="${j}"`)}let B=Q;if(!$.plain&&j)B=S(Q,j);for(let A=0;A<W.length;A++){let M=W[A];if(M===void 0)continue;if(M.trim().startsWith(`${J}=`)){W[A]=`${J}="${B}"`,G=!0;break}}if(!G)W.push(`${J}="${B}"`);let I=W.join(`
|
|
20
|
+
`);return V(Z,I,"utf-8"),{success:!0,output:`set ${J}${$.plain?"":" with encryption"} (${$.file||".env"})`}}catch(Y){return{success:!1,error:`Failed to set: ${Y instanceof Error?Y.message:"Unknown error"}`}}}function fJ(J,Q={}){let $=Q.cwd||process.cwd(),z=C($,Q.file||".env");if(!g(z))return{success:!1,error:`File not found: ${z}`};try{let Z,X=C($,Q.keysFile||".env.keys"),G=((Q.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),j=G?`DOTENV_PRIVATE_KEY_${G}`:"DOTENV_PRIVATE_KEY";if(g(X)){let U=L(X,"utf-8"),{parsed:B}=T(U);Z=B[j]}if(!Z)Z=process.env[j];let q=L(z,"utf-8"),{parsed:D}=T(q,{privateKey:Z});if(J&&!Q.all){let U=D[J];if(U===void 0)return{success:!1,error:`Key not found: ${J}`};return{success:!0,output:U}}let H=Q.all?{...process.env,...D}:D,O;switch(Q.format){case"shell":O=Object.entries(H).map(([U,B])=>`${U}=${B}`).join(" ");break;case"eval":O=Object.entries(H).map(([U,B])=>`${U}="${B}"`).join(`
|
|
21
|
+
`);break;case"json":default:O=Q.prettyPrint?JSON.stringify(H,null,2):JSON.stringify(H);break}return{success:!0,output:O}}catch(Z){return{success:!1,error:`Failed to get: ${Z instanceof Error?Z.message:"Unknown error"}`}}}function xJ(J,Q={}){let $=Q.cwd||process.cwd(),z=C($,Q.keysFile||".env.keys");if(!g(z))return{success:!1,error:`Keys file not found: ${z}`};try{let Z=L(z,"utf-8"),{parsed:X}=T(Z),G=((Q.file||".env").split("/").pop()||"").replace(/^\.env\./,"").replace(/^\.env$/,"").toUpperCase(),j=G?`DOTENV_PUBLIC_KEY_${G}`:"DOTENV_PUBLIC_KEY",q=G?`DOTENV_PRIVATE_KEY_${G}`:"DOTENV_PRIVATE_KEY";if(J){let O=X[J];if(!O)return{success:!1,error:`Key not found: ${J}`};return{success:!0,output:O}}let D={[j]:X[j],[q]:X[q]};return{success:!0,output:Q.format==="shell"?`${j}=${D[j]} ${q}=${D[q]}`:JSON.stringify(D)}}catch(Z){return{success:!1,error:`Failed to get keypair: ${Z instanceof Error?Z.message:"Unknown error"}`}}}function SJ(J={}){let Q=e({file:J.file,keysFile:J.keysFile,stdout:!0,cwd:J.cwd});if(!Q.success)return Q;let $=J.cwd||process.cwd(),z=C($,J.file||".env"),Z=C($,J.keysFile||".env.keys");if(Q.output)V(z,Q.output,"utf-8");let X=b(),W=L(Z,"utf-8").split(`
|
|
22
|
+
`),G=J.file?J.file.replace(/^\.env\./,"").toUpperCase():"",j=G?`DOTENV_PUBLIC_KEY_${G}`:"DOTENV_PUBLIC_KEY",q=G?`DOTENV_PRIVATE_KEY_${G}`:"DOTENV_PRIVATE_KEY";for(let D=0;D<W.length;D++){let H=W[D];if(H===void 0)continue;if(H.startsWith(`${j}=`))W[D]=`${j}="${X.publicKey}"`;else if(H.startsWith(`${q}=`))W[D]=`${q}="${X.privateKey}"`}return V(Z,W.join(`
|
|
23
|
+
`),"utf-8"),t({file:J.file,keysFile:J.keysFile,key:J.key,excludeKey:J.excludeKey,stdout:J.stdout,cwd:J.cwd})}import _ from"process";import{platform as JJ}from"os";var u=typeof Bun<"u",c=typeof _<"u"&&_.versions?.node!==void 0,QJ=u?"bun":c?"node":"unknown",mJ={name:QJ,version:u?Bun.version:c?_.version:void 0},P=JJ(),hJ=P==="win32",kJ=P==="darwin",dJ=P==="linux",v=Boolean(_.stdout?.isTTY),uJ=typeof globalThis.window<"u",ZJ=Boolean(_.env.CI||_.env.CONTINUOUS_INTEGRATION||_.env.BUILD_NUMBER||_.env.RUN_ID),cJ=Boolean(_.env.DEBUG||_.env.VERBOSE||_.argv.includes("--debug")||_.argv.includes("--verbose")),$J=ZJ||!v,vJ=Boolean(!$J&&(v||_.env.COLORTERM||_.env.FORCE_COLOR||_.env.TERM&&_.env.TERM!=="dumb")),N={github:{name:"GitHub Actions",detected:Boolean(_.env.GITHUB_ACTIONS)},gitlab:{name:"GitLab CI",detected:Boolean(_.env.GITLAB_CI)},circle:{name:"CircleCI",detected:Boolean(_.env.CIRCLECI)},travis:{name:"Travis CI",detected:Boolean(_.env.TRAVIS)},jenkins:{name:"Jenkins",detected:Boolean(_.env.JENKINS_URL)},vercel:{name:"Vercel",detected:Boolean(_.env.VERCEL)},netlify:{name:"Netlify",detected:Boolean(_.env.NETLIFY)},heroku:{name:"Heroku",detected:Boolean(_.env.DYNO)},aws:{name:"AWS",detected:Boolean(_.env.AWS_REGION||_.env.AWS_LAMBDA_FUNCTION_NAME)},azure:{name:"Azure",detected:Boolean(_.env.AZURE_HTTP_USER_AGENT)},cloudflare:{name:"Cloudflare",detected:Boolean(_.env.CF_PAGES)},railway:{name:"Railway",detected:Boolean(_.env.RAILWAY_ENVIRONMENT)},render:{name:"Render",detected:Boolean(_.env.RENDER)}},zJ=Object.keys(N).find((J)=>{let Q=N[J];return Q!==void 0&&Q.detected})||"unknown",lJ=N[zJ]||{name:"Unknown",detected:!1};var GJ={get:(J,Q)=>{let $=J[Q],z=["_PORT","_TIMEOUT","_TTL","_SIZE","_LIMIT","_MAX","_MIN","_INTERVAL","_RETRIES","_CONCURRENCY","_WORKERS","_CONNECTIONS"];if(typeof $==="string"&&/^\d+$/.test($)&&!$.startsWith("0")&&z.some((Z)=>Q.endsWith(Z)))return Number($);if(typeof $==="string"){let Z=$.toLowerCase();if(Z==="true")return!0;if(Z==="false")return!1}return $}};function WJ(){return typeof Bun<"u"?Bun.env:XJ.env}var y=new Proxy(WJ(),GJ);function rJ(J,Q,$){let z=$?.path||jJ(".env"),X=l.readFileSync(z,"utf-8").split(`
|
|
24
|
+
`),Y=X.findIndex((j)=>j.startsWith(`${J}=`)),G=/[\s"'#$\\]/.test(Q)?`"${Q.replace(/"/g,"\\\"")}"`:Q;if(Y!==-1)X[Y]=`${J}=${G}`;else X.push(`${J}=${G}`);l.writeFileSync(z,X.join(`
|
|
25
|
+
`))}function oJ(J=y){let Q=[];for(let[$,z]of Object.entries(K)){let Z=J[$];if(Z!==void 0&&Z!==""&&!z.includes(String(Z)))Q.push(`${$}="${Z}" is not valid. Allowed values: ${z.join(", ")}`)}return Q}function sJ(J,Q=y){let $=[];for(let z of J){let Z=Q[z];if(Z===void 0||Z===""||Z===null)$.push(z)}if($.length>0)throw Error(`[env] Missing required environment variable(s): ${$.join(", ")}. Set them in .env or your process environment before booting.`);return Q}export{rJ as writeEnv,oJ as validateEnv,bJ as setEnv,mJ as runtimeInfo,QJ as runtime,SJ as rotateKeypair,sJ as requireEnv,lJ as providerInfo,zJ as provider,WJ as process,P as platform,AJ as parseEnvFromKey,T as parse,_J as loadEnvFiles,d as loadEnv,hJ as isWindows,c as isNode,$J as isMinimal,kJ as isMacOS,dJ as isLinux,cJ as isDebug,vJ as isColorSupported,ZJ as isCI,u as isBun,uJ as hasWindow,v as hasTTY,h as getPrivateKey,xJ as getKeypair,fJ as getEnv,b as generateKeypair,LJ as envPlugin,K as envEnum,y as env,S as encryptValue,t as encryptEnv,x as decryptValue,e as decryptEnv,CJ as autoLoadEnv,a as aesEncrypt,n as aesDecrypt};
|
package/dist/types.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ export declare interface StacksEnv {
|
|
|
125
125
|
AUTH_USERNAME_FIELD: string | undefined
|
|
126
126
|
AUTH_PASSWORD_FIELD: string | undefined
|
|
127
127
|
AUTH_TOKEN_EXPIRY: number | undefined
|
|
128
|
+
AUTH_REFRESH_TOKEN_EXPIRY: number | undefined
|
|
128
129
|
AUTH_TOKEN_ROTATION: number | undefined
|
|
129
130
|
AUTH_PASSWORD_RESET_EXPIRE: number | undefined
|
|
130
131
|
AUTH_PASSWORD_RESET_THROTTLE: number | undefined
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/env",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.53",
|
|
5
5
|
"description": "Stacks env helper methods.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"better-dx": "^0.2.12",
|
|
49
|
-
"@stacksjs/path": "
|
|
50
|
-
"@stacksjs/validation": "
|
|
49
|
+
"@stacksjs/path": "0.70.52",
|
|
50
|
+
"@stacksjs/validation": "0.70.52"
|
|
51
51
|
}
|
|
52
52
|
}
|