"use strict";exports.id=3496,exports.ids=[3496],exports.modules={96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},69842:(e,r,s)=>{s.d(r,{A:()=>l});var t=s(48786),n=s(95969),a=s(29021),o=s.n(a),i=s(89159);async function l(e,r,s){try{let{keyCookieName:a,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))throw Error("Request Cookies not Found!");let c=(0,n.A)({encryptedString:e.cookies[a]});if(!c)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(c);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");let E=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!E)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(s&&!o().existsSync(`${E}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,s)=>{s.d(r,{A:()=>t});function t(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=s;let i=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=t;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:l+=n}}},67619:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(29021),n=s.n(t);async function a({user:e,message:r,component:s,noMail:t,req:a}){let o=new Date,i=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],s=a.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],n=s||t||r||a.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${s}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),a?.url&&(t+=` URL: ${a.url}`),a?.body&&(t+=` Request Body: ${JSON.stringify(a.body,null,4)}`),i&&(t+=` IP: ${i}`),t+=` Date: ${o.toDateString()} ========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let l=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",t),n().appendFileSync("./.tmp/error.log",` ${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511),n=s(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,i=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,t.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,t.createDecipheriv)("aes-192-cbc",l,c);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511),n=s(79428);function a({data:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,i=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let l=(0,t.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,t.createCipheriv)("aes-192-cbc",l,c);try{let r=u.update(e,"utf8","hex");return r+=u.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},5437:(e,r,s)=>{s.d(r,{A:()=>_});var t=s(33873),n=s.n(t),a=s(47795),o=s.n(a),i=s(66866),l=s(41864);async function c({username:e,host:r,grants:s,userId:t}){let n=!1;if(console.log("Handling Grants for User =>",e,r),!e)return console.log("No username provided."),n;if(!r)return console.log(`No Host provided. \x1b[35m\`--host\`\x1b[0m flag is required`),n;if(!s)return console.log("No grants Array provided."),n;try{let a=await (0,i.A)(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(a?.[0]?.User){let n=await (0,i.A)(`SHOW GRANTS FOR '${e}'@'${r}'`);for(let e=0;e",e.message)}return n}var u=s(68829),E=s(95969);s(60818).config({path:n().resolve(__dirname,"../../../.env")});let d=process.env.DSQL_DB_HOST||"127.0.0.1";async function _({userId:e,mariadbUserHost:r,mariadbUsername:s,sqlUserID:t}){let n=await (0,l.A)({query:"SELECT * FROM mariadb_users"});if(!n?.[0])return;let a=!!e&&e==Number(process.env.DSQL_SU_USER_ID);for(let _=0;_",e.message)}}}},41864:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(29021),n=s.n(t),a=s(33873),o=s.n(a);async function i({query:e,values:r}){let s,t=global.DSQL_DB_CONN;try{s=e&&r?await t.query(e,r):await t.query(e)}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(t.config()),n().appendFileSync(o().resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),s=null}finally{await t?.end()}return s?JSON.parse(JSON.stringify(s)):null}},66866:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(41864);async function n(e){let r;try{r=await (0,t.A)({query:e})}catch(e){console.log("ERROR in noDatabaseDbHandler =>",e.message)}return r||null}},48786:(e,r,s)=>{s.d(r,{A:()=>t});async function t(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,s)=>{e.exports=s(75600)}};