"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});vari={};t.r(i),t.d(i,{default:()=>o});vars=t(89947),a=t(2706),n=t(96762),l=t(69842),d=t(49941);asyncfunctiono(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,l.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 ...");leti=await(0,d.A)({query:e.body.query,user:t});r.json({success:!0,result:i})}letu=(0,n.M)(i,"default"),_=(0,n.M)(i,"config"),c=news.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:i})},69842:(e,r,t)=>{t.d(r,{A:()=>d});vari=t(48786),s=t(95969),a=t(29021),n=t.n(a),l=t(89159);asyncfunctiond(e,r,t){let{keyCookieName:a,csrfCookieName:d}=(0,l.A)();if(!e.cookies?.[a]?.match(/./))returnnull;leto=(0,s.A)({encryptedString:e.cookies[a]});if(!o)returnnull;letu=JSON.parse(o);if(!u.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(u.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&&!n().existsSync(`${_}/${u.csrf_k}`))returnnull;if(0==u.verification_status&&!t){lete=await(0,i.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"])}returnu?.date&&Date.now()-u.date>6048e5?null:u}},49941:(e,r,t)=>{t.d(r,{A:()=>l});vari=t(67619),s=t(48786),a=t(98e3),n=t(7971);asyncfunctionl({query:e,user:r,useLocal:t}){try{leti=t?n.A:s.A,{invite:l,database_access:d,priviledge:o,email:u}=e,_=[l,u],c=awaiti("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",_);if(!c||!c[0])throwError("No Invitation Found");letm=[l],E=awaiti("SELECT first_name,last_name,email FROM users WHERE id=?",m);if(E?.[0]){lete=awaiti("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[l,r.id,u]);if(e?.[0])console.log("User already added");else{(0,a.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:l,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:o,image:r.image,image_thumbnail:r.image_thumbnail},useLocal:t});lete=awaiti("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[l,u]);if(awaiti("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[l,r.id]),e&&e[0]){leti=e[0].db_tables_data.split("|");for(lete=0;e<i.length;e++){let[s,n]=i[e].split("-");await(0,a.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:l,database:s,table:n,priviledge:o},useLocal:t})}}}awaiti("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[l,u])}}catch(e){(0,i.default)({component:"addAdminUserOnLogin",message:e.message,user:r})}}},89159:(e,r,t)=>{t.d(r,{A:()=>i});functioni(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",i=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=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+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),n+=t;letl=r;e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),l+=i;letd=r;returne?.userId&&(d+=`user_${e.userId}_`),a&&(d+=`${a}_`),{keyCookieName:n,csrfCookieName:l,o