"use strict";(()=>{vare={};e.id=8282,e.ids=[8282],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,t){returntinr?r[t]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,t)):"function"==typeofr&&"default"===t?r:void0}}})},94057:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>f,routeModule:()=>m});vars={};t.r(s),t.d(s,{default:()=>S});varn=t(89947),o=t(2706),a=t(96762),i=t(51348),l=t.n(i),c=t(20503),u=t.n(c),d=t(48225),_=t.n(d),p=t(6420),E=t.n(p);asyncfunctionS(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitE()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.rootUserId,n=e.body.priviledges,o=e.body.database;try{lete=awaitl()("SELECT * FROM user_users WHERE user_id=? AND invited_user_id=? AND MATCH(database_access) AGAINST(?)",[s,t.id,o]);if(!e||!e[0])throwError(`user with id ${t.id} has no access to ${o} database belonging to user ${s}`);leta=(awaitl()("SELECT * FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=?",[s,t.id,o])).map(e=>e.table),i=awaitl()("SELECT * FROM users WHERE id=?",[s]),c={rootUserId:s,rootUserName:`${i[0].first_name}${i[0].last_name}`,rootUserEmail:i[0].email,rootUserImage:i[0].image_thumbnail,delegatedUserId:t.id,databaseFullName:`datasquirel_user_${s}_${o}`,databaseSlug:o,allowedTables:a,priviledges:n,dateCreated:Date.now()},d=u()({data:JSON.stringify(c)}),_=`${process.env.DSQL_USER_DB_PREFIX}${c.rootUserId}_${o}`,p=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${_}`;r.setHeader("Set-Cookie",[`${p}=${d};path=/`]),r.json({success:!0,msg:"Processed Successfully"})}catch(e){returnconsole.log("ERROR:",e.message),_()({component:"/api/getDelegatedDatabaseToken/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Unauthorized"})}}letf=(0,a.M)(s,"default"),g=(0,a.M)(s,"config"),m=newn.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/getDelegatedDatabaseToken",pathname:"/api/getDelegatedDatabaseToken",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);lets=t(51348),n=t(72835),o=t(29021),a=t(31341);asyncfunctioni(e,r,t,i){let{keyCookieName:l,csrfCookieName:c}=a();if(!e.cookies?.[l]?.match(/./))returnnull;letu=n({encryptedString:e.cookies[l]});if(!u)returnnull;letd=JSON.parse(u);if(!d.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))returnnull;let_=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!o.existsSync(`${_}/${d.csrf_k}`))returnnull;if(0==d.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}returnd?.date&&Date.now()-d.date>6048e5?null:d}e.exports=i},31341:e=>{e.exports=function(){lete=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},48225:(e,r,t)=>{lets=t(29021),{IncomingMessage:n}=t(81630);e.exports=asyncfunction({user:e,message:r,component:t,noMail:n,req:o}){leta=newDate,i=(()=>{if(!o)returnnull;try{lete=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],t=o.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||s||r||o.socket.remoteAddress;if(!n)returnnull;returnString(n)}catch(e){returnnull}})();try{letn=`🚀 SERVER ERROR ===========================