"use strict";(()=>{vare={};e.id=9785,e.ids=[9785],e.modules={27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},81764:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>c,routeModule:()=>p});vars={};t.r(s),t.d(s,{default:()=>_});vari=t(89947),a=t(2706),n=t(96762),l=t(6420),o=t.n(l),d=t(44767),u=t.n(d);asyncfunction_(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaito()(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=awaitu()({query:e.body.query,user:t});r.json({success:!0,result:s})}letc=(0,n.M)(s,"default"),m=(0,n.M)(s,"config"),p=newi.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);lets=t(51348),i=t(72835),a=t(29021),n=t(31341);asyncfunctionl(e,r,t,l){let{keyCookieName:o,csrfCookieName:d}=n();if(!e.cookies?.[o]?.match(/./))returnnull;letu=i({encryptedString:e.cookies[o]});if(!u)returnnull;let_=JSON.parse(u);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))returnnull;letc=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${_.csrf_k}`))returnnull;if(0==_.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return_?.date&&Date.now()-_.date>6048e5?null:_}e.exports=l},44767:(e,r,t)=>{lets=t(48225),i=t(51348),a=t(47670),n=t(44900);e.exports=asyncfunction({query:e,user:r,useLocal:t}){try{lets=t?n:i,{invite:l,database_access:o,priviledge:d,email:u}=e,_=[l,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");letm=[l],p=awaits("SELECT first_name,last_name,email FROM users WHERE id=?",m);if(p?.[0]){lete=awaits("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{a({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:l,invited_user_id:r.id,database_access:o,first_name:r.first_name,last_name:r.last_name,phone:r.phone,email:r.email,username:r.username,user_type:"admin",user_priviledge:d,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=?",[l,u]);if(awaits("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[l,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("-");awaita({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:l,database:i,table:n,priviledge:d},useLocal:t})}}}awaits("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[l,u])}}catch(e){s({component:"addAdminUserOnLogin",message:e.message,user:r})}}},31341:e=>{e.exports=function(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||"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+=s;leto=r;returne?.userId&&(o+=`user_${e.userId}_`),a&