"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:()=>E,default:()=>m,routeModule:()=>g});vars={};t.r(s),t.d(s,{default:()=>S});vara=t(89947),n=t(2706),o=t(96762),i=t(51348),l=t.n(i),u=t(82703),c=t.n(u),d=t(77538),p=t.n(d),_=t(6420),f=t.n(_);asyncfunctionS(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitf()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.rootUserId,a=e.body.priviledges,n=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,n]);if(!e||!e[0])throwError(`user with id ${t.id} has no access to ${n} database belonging to user ${s}`);leto=(awaitl()("SELECT * FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=?",[s,t.id,n])).map(e=>e.table),i=awaitl()("SELECT * FROM users WHERE id=?",[s]),u={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}_${n}`,databaseSlug:n,allowedTables:o,priviledges:a,dateCreated:Date.now()},d=c()(JSON.stringify(u)),p=`${process.env.DSQL_USER_DB_PREFIX}${u.rootUserId}_${n}`,_=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${p}`;r.setHeader("Set-Cookie",[`${_}=${d};path=/`]),r.json({success:!0,msg:"Processed Successfully"})}catch(e){returnconsole.log("ERROR:",e.message),p()({component:"/api/getDelegatedDatabaseToken/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Unauthorized"})}}letm=(0,o.M)(s,"default"),E=(0,o.M)(s,"config"),g=newa.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/getDelegatedDatabaseToken",pathname:"/api/getDelegatedDatabaseToken",bundlePath:"",filename:""},userland:s})},77538:(e,r,t)=>{lets=t(29021),{IncomingMessage:a}=t(81630);e.exports=asyncfunction({user:e,message:r,component:t,noMail:a,req:n}){leto=newDate,i=(()=>{if(!n)returnnull;try{lete=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.socket.remoteAddress;if(!a)returnnull;returnString(a)}catch(e){returnnull}})();try{leta=`🚀 SERVER ERROR ===========================