"use strict";(()=>{var e={};e.id=3812,e.ids=[3812],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},21572:e=>{e.exports=require("nodemailer")},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")},21110:(e,s,t)=>{t.r(s),t.d(s,{config:()=>h,default:()=>g,routeModule:()=>E});var a={};t.r(a),t.d(a,{default:()=>S});var r=t(89947),i=t(2706),n=t(96762),l=t(59474),o=t.n(l),d=t(6420),u=t.n(d),c=t(47670),_=t.n(c),p=t(51348),m=t.n(p),f=t(14533),v=t.n(f);async function S(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let t=await u()(e,s,!0);if(!t)return s.json({success:!1,msg:"Unauthorized"});let a=e.body,r=a.paradigm;if(r?.match(/database/)){let e=await _()({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(a),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=a[e])}),s.user_id=t.id,s.password=v()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:a.password}),s.user_type="database",s.email=a.email_address,s.image="/images/user-preset.png",s.image_thumbnail="/images/user-preset-thumbnail.png",delete s.email_address,s})()});s.json({success:!!e?.insertId,msg:"New User User Added",newUserId:e.insertId})}else{if(t?.email===a.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await m()("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[a.email_address,t.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await _()({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:t.id,invited_user_email:a.email_address,database_access:a.database_access,priviledge:a.priviledge,db_tables_data:a.db_tables}});let r=await o()({to:a.email_address,subject:`${t.first_name} ${t.last_name} Invited you`,text:`${t.first_name} ${t.last_name} has invited you to manage a datasquirel account`,html:`
${t.first_name} ${t.last_name} has invited you to manage a datasquirel account.
Accept Invitation
`});s.json({success:!!r?.accepted,msg:"This is an invitation request"})}}let g=(0,n.M)(a,"default"),h=(0,n.M)(a,"config"),E=new r.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:a})},6420:(e,s,t)=>{t(81630);let a=t(51348),r=t(72835),i=t(29021),n=t(31341);async function l(e,s,t,l){let{keyCookieName:o,csrfCookieName:d}=n();if(!e.cookies?.[o]?.match(/./))return null;let u=r({encryptedString:e.cookies[o]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!i.existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await a(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=l},31341:e=>{e.exports=function(e){let s=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",r=s;e?.userId&&(r+=`user_${e.userId}_`),e?.database&&(r+=`${e.database}_`),r+=t;let i=s;return e?.userId&&(i+=`user_${e.userId}_`),e?.database&&(i+=`${e.database}_`),{keyCookieName:r,csrfCookieName:i+=a}}},59474:(e,s,t)=>{let a=t(29021),r=t(21572).createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});e.exports=async function({to:e,subject:s,text:t,html:i,alias:n}){let l;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let o=(n?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!a.existsSync("./email/index.html"))return;let d=a.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let a={};a.from=`"Datasquirel" <${o}>`,a.sender=o,n&&(a["replyTo "]=o),a.to=e,a.subject=s,a.text=t,a.html=d,l=await r.sendMail(a)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},72835:(e,s,t)=>{let{scryptSync:a,createDecipheriv:r}=t(55511),{Buffer:i}=t(79428);e.exports=({encryptedString:e,encryptionKey:s,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=s||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=r("aes-192-cbc",a(n,l,o),i.alloc(16,0));try{let s=d.update(e,"hex","utf8");return s+=d.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}},14533:(e,s,t)=>{let{createHmac:a}=t(55511);e.exports=function({password:e,encryptionKey:s}){let t=s||process.env.DSQL_ENCRYPTION_PASSWORD;if(!t?.match(/.{8,}/))throw Error("Encryption key is invalid");let r=a("sha512",t);return r.update(e),r.digest("base64")}}};var s=require("../../webpack-api-runtime.js");s.C(e);var t=e=>s(s.s=e),a=s.X(0,[4050],()=>t(21110));module.exports=a})();