@smythos/cli
Version:
SmythOS SRE Command Line Interface
5 lines (4 loc) • 10.1 kB
JavaScript
;var K=Object.defineProperty;var c=(b,l)=>K(b,"name",{value:l,configurable:!0});var index=require("./index2.cjs"),P=require("fs"),sysPath=require("path"),require$$0=require("os"),se=require("crypto"),require$$0$1=require("buffer"),main={exports:{}},version="16.5.0",require$$4={version},hasRequiredMain;function requireMain(){if(hasRequiredMain)return main.exports;hasRequiredMain=1;const b=P,l=sysPath,E=require$$0,x=se,v=require$$4.version,f=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function u(e){const a={};let t=e.toString();t=t.replace(/\r\n?/mg,`
`);let d;for(;(d=f.exec(t))!=null;){const i=d[1];let r=d[2]||"";r=r.trim();const n=r[0];r=r.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),n==='"'&&(r=r.replace(/\\n/g,`
`),r=r.replace(/\\r/g,"\r")),a[i]=r}return a}c(u,"parse");function g(e){const a=I(e),t=s.configDotenv({path:a});if(!t.parsed){const n=new Error(`MISSING_DATA: Cannot parse ${a} for an unknown reason`);throw n.code="MISSING_DATA",n}const d=w(e).split(","),i=d.length;let r;for(let n=0;n<i;n++)try{const o=d[n].trim(),p=T(t,o);r=s.decrypt(p.ciphertext,p.key);break}catch(o){if(n+1>=i)throw o}return s.parse(r)}c(g,"_parseVault");function _(e){console.log(`[dotenv@${v}][WARN] ${e}`)}c(_,"_warn");function m(e){console.log(`[dotenv@${v}][DEBUG] ${e}`)}c(m,"_debug");function w(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:""}c(w,"_dotenvKey");function T(e,a){let t;try{t=new URL(a)}catch(o){if(o.code==="ERR_INVALID_URL"){const p=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 p.code="INVALID_DOTENV_KEY",p}throw o}const d=t.password;if(!d){const o=new Error("INVALID_DOTENV_KEY: Missing key part");throw o.code="INVALID_DOTENV_KEY",o}const i=t.searchParams.get("environment");if(!i){const o=new Error("INVALID_DOTENV_KEY: Missing environment part");throw o.code="INVALID_DOTENV_KEY",o}const r=`DOTENV_VAULT_${i.toUpperCase()}`,n=e.parsed[r];if(!n){const o=new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${r} in your .env.vault file.`);throw o.code="NOT_FOUND_DOTENV_ENVIRONMENT",o}return{ciphertext:n,key:d}}c(T,"_instructions");function I(e){let a=null;if(e&&e.path&&e.path.length>0)if(Array.isArray(e.path))for(const t of e.path)b.existsSync(t)&&(a=t.endsWith(".vault")?t:`${t}.vault`);else a=e.path.endsWith(".vault")?e.path:`${e.path}.vault`;else a=l.resolve(process.cwd(),".env.vault");return b.existsSync(a)?a:null}c(I,"_vaultPath");function V(e){return e[0]==="~"?l.join(E.homedir(),e.slice(1)):e}c(V,"_resolveHome");function O(e){!!(e&&e.debug)&&m("Loading env from encrypted .env.vault");const t=s._parseVault(e);let d=process.env;return e&&e.processEnv!=null&&(d=e.processEnv),s.populate(d,t,e),{parsed:t}}c(O,"_configVault");function A(e){const a=l.resolve(process.cwd(),".env");let t="utf8";const d=!!(e&&e.debug);e&&e.encoding?t=e.encoding:d&&m("No encoding is specified. UTF-8 is used by default");let i=[a];if(e&&e.path)if(!Array.isArray(e.path))i=[V(e.path)];else{i=[];for(const p of e.path)i.push(V(p))}let r;const n={};for(const p of i)try{const y=s.parse(b.readFileSync(p,{encoding:t}));s.populate(n,y,e)}catch(y){d&&m(`Failed to load ${p} ${y.message}`),r=y}let o=process.env;return e&&e.processEnv!=null&&(o=e.processEnv),s.populate(o,n,e),r?{parsed:n,error:r}:{parsed:n}}c(A,"configDotenv");function $(e){if(w(e).length===0)return s.configDotenv(e);const a=I(e);return a?s._configVault(e):(_(`You set DOTENV_KEY but you are missing a .env.vault file at ${a}. Did you forget to build it?`),s.configDotenv(e))}c($,"config");function B(e,a){const t=Buffer.from(a.slice(-64),"hex");let d=Buffer.from(e,"base64");const i=d.subarray(0,12),r=d.subarray(-16);d=d.subarray(12,-16);try{const n=x.createDecipheriv("aes-256-gcm",t,i);return n.setAuthTag(r),`${n.update(d)}${n.final()}`}catch(n){const o=n instanceof RangeError,p=n.message==="Invalid key length",y=n.message==="Unsupported state or unable to authenticate data";if(o||p){const N=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw N.code="INVALID_DOTENV_KEY",N}else if(y){const N=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw N.code="DECRYPTION_FAILED",N}else throw n}}c(B,"decrypt");function k(e,a,t={}){const d=!!(t&&t.debug),i=!!(t&&t.override);if(typeof a!="object"){const r=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw r.code="OBJECT_REQUIRED",r}for(const r of Object.keys(a))Object.prototype.hasOwnProperty.call(e,r)?(i===!0&&(e[r]=a[r]),d&&m(i===!0?`"${r}" is already defined and WAS overwritten`:`"${r}" is already defined and was NOT overwritten`)):e[r]=a[r]}c(k,"populate");const s={configDotenv:A,_configVault:O,_parseVault:g,config:$,decrypt:B,parse:u,populate:k};return main.exports.configDotenv=s.configDotenv,main.exports._configVault=s._configVault,main.exports._parseVault=s._parseVault,main.exports.config=s.config,main.exports.decrypt=s.decrypt,main.exports.parse=s.parse,main.exports.populate=s.populate,main.exports=s,main.exports}c(requireMain,"requireMain");var mainExports=requireMain(),D=index.getDefaultExportFromCjs(mainExports),pend,hasRequiredPend;function requirePend(){if(hasRequiredPend)return pend;hasRequiredPend=1,pend=b;function b(){this.pending=0,this.max=1/0,this.listeners=[],this.waiting=[],this.error=null}c(b,"Pend"),b.prototype.go=function(x){this.pending<this.max?E(this,x):this.waiting.push(x)},b.prototype.wait=function(x){this.pending===0?x(this.error):this.listeners.push(x)},b.prototype.hold=function(){return l(this)};function l(x){x.pending+=1;var h=!1;return v;function v(u){if(h)throw new Error("callback called twice");if(h=!0,x.error=x.error||u,x.pending-=1,x.waiting.length>0&&x.pending<x.max)E(x,x.waiting.shift());else if(x.pending===0){var g=x.listeners;x.listeners=[],g.forEach(f)}}function f(u){u(x.error)}}c(l,"pendHold");function E(x,h){h(l(x))}return c(E,"pendGo"),pend}c(requirePend,"requirePend");var bufferCrc32,hasRequiredBufferCrc32;function requireBufferCrc32(){if(hasRequiredBufferCrc32)return bufferCrc32;hasRequiredBufferCrc32=1;var b=require$$0$1.Buffer,l=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];typeof Int32Array<"u"&&(l=new Int32Array(l));function E(f){if(b.isBuffer(f))return f;var u=typeof b.alloc=="function"&&typeof b.from=="function";if(typeof f=="number")return u?b.alloc(f):new b(f);if(typeof f=="string")return u?b.from(f):new b(f);throw new Error("input must be buffer, number, or string, received "+typeof f)}c(E,"ensureBuffer");function x(f){var u=E(4);return u.writeInt32BE(f,0),u}c(x,"bufferizeInt");function h(f,u){f=E(f),b.isBuffer(u)&&(u=u.readUInt32BE(0));for(var g=~~u^-1,_=0;_<f.length;_++)g=l[(g^f[_])&255]^g>>>8;return g^-1}c(h,"_crc32");function v(){return x(h.apply(null,arguments))}return c(v,"crc32"),v.signed=function(){return h.apply(null,arguments)},v.unsigned=function(){return h.apply(null,arguments)>>>0},bufferCrc32=v,bufferCrc32}c(requireBufferCrc32,"requireBufferCrc32");exports.D=D;exports.requireBufferCrc32=requireBufferCrc32;exports.requireMain=requireMain;exports.requirePend=requirePend;