"use strict";(()=>{vare={};e.id=9785,e.ids=[9785],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},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")},92145:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>u,routeModule:()=>c});vars={};t.r(s),t.d(s,{default:()=>l});vari=t(89947),a=t(2706),n=t(96762),o=t(69842),d=t(49941);asyncfunctionl(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,o.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});console.log("Invitation Received by current logged in user, Loggin in VIA API ...");lets=await(0,d.A)({query:e.body.query,user:t});r.json({success:!0,result:s})}letu=(0,n.M)(s,"default"),_=(0,n.M)(s,"config"),c=newi.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>d});vars=t(48786),i=t(95969),a=t(29021),n=t.n(a),o=t(89159);asyncfunctiond(e,r,t){try{let{keyCookieName:a,csrfCookieName:d}=(0,o.A)();if(!e.cookies?.[a]?.match(/./))throwError("Request Cookies not Found!");letl=(0,i.A)({encryptedString:e.cookies[a]});if(!l)throwError("Couldn't decrypt auth cookie!");letu=JSON.parse(l);if(!u.csrf_k)throwError("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throwconsole.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");let_=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)throwError("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!n().existsSync(`${_}/${u.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){lete=await(0,s.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)throwError("Key expired!");returnu}catch(e){returnconsole.log(`userAuth Error: ${e.message}`),null}}},49941:(e,r,t)=>{t.d(r,{A:()=>o});vars=t(67619),i=t(48786),a=t(98e3),n=t(7971);asyncfunctiono({query:e,user:r,useLocal:t}){try{lets=t?n.A:i.A,{invite:o,database_access:d,priviledge:l,email:u}=e,_=[o,u],c=awaits("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",_);if(!c||!c[0])throwError("No Invitation Found");letE=[o],m=awaits("SELECT first_name,last_name,email FROM users WHERE id=?",E);if(m?.[0]){lete=awaits("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[o,r.id,u]);if(e?.[0])console.log("User already added");else{(0,a.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:o,invited_user_id:r.id,database_access:d,first_name:r.first_name,last_name:r.last_name,phone:r.phone,email:r.email,username:r.username,user_type:"admin",user_priviledge:l,image:r.image,image_thumbnail:r.image_thumbnail},useLocal:t});lete=awaits("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[o,u]);if(awaits("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[o,r.id]),e&&e[0]){lets=e[0].db_tables_data.split("|");for(lete=0;e<s.length;e++){let[i,n]=s[e].split("-");await(0,a.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:o,database:i,table:n,priviledge:l},useLocal:t})}}}awaits("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[o,u])}}catch(e){(0,s.A)({component:"addAdminUserOnLogin",message:e.message,user:r})}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});functions(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"