"use strict";(()=>{var e={};e.id=3812,e.ids=[3812],e.modules={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")},70955:(e,s,a)=>{a.r(s),a.d(s,{config:()=>m,default:()=>p,routeModule:()=>v});var r={};a.r(r),a.d(r,{default:()=>_});var t=a(89947),i=a(2706),n=a(96762),d=a(96052),l=a(69842),u=a(98e3),c=a(48786),o=a(83919);async function _(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let a=await (0,l.A)(e,s,!0);if(!a)return s.json({success:!1,msg:"Unauthorized"});let r=e.body,t=r.paradigm;if(t?.match(/database/)){let e=await (0,u.A)({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(r),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=r[e])}),s.user_id=a.id,s.password=(0,o.A)({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:r.password}),s.user_type="database",s.email=r.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(a?.email===r.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await (0,c.A)("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[r.email_address,a.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await (0,u.A)({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:a.id,invited_user_email:r.email_address,database_access:r.database_access,priviledge:r.priviledge,db_tables_data:r.db_tables}});let t=await (0,d.default)({to:r.email_address,subject:`${a.first_name} ${a.last_name} Invited you`,text:`${a.first_name} ${a.last_name} has invited you to manage a datasquirel account`,html:`

${a.first_name} ${a.last_name} has invited you to manage a datasquirel account.

Accept Invitation `});s.json({success:!!t?.accepted,msg:"This is an invitation request"})}}let p=(0,n.M)(r,"default"),m=(0,n.M)(r,"config"),v=new t.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:r})},69842:(e,s,a)=>{a.d(s,{A:()=>l});var r=a(48786),t=a(95969),i=a(29021),n=a.n(i),d=a(89159);async function l(e,s,a){let{keyCookieName:i,csrfCookieName:l}=(0,d.A)();if(!e.cookies?.[i]?.match(/./))return null;let u=(0,t.A)({encryptedString:e.cookies[i]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||a&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let o=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!o)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(a&&!n().existsSync(`${o}/${c.csrf_k}`))return null;if(0==c.verification_status&&!a){let e=await (0,r.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}},89159:(e,s,a)=>{a.d(s,{A:()=>r});function r(e){let s=process.env.DSQL_COOKIES_PREFIX||"dsql_",a=process.env.DSQL_COOKIES_KEY_NAME||"key",r=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",t=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",i=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=s;e?.userId&&(n+=`user_${e.userId}_`),i&&(n+=`${i}_`),n+=a;let d=s;e?.userId&&(d+=`user_${e.userId}_`),i&&(d+=`${i}_`),d+=r;let l=s;return e?.userId&&(l+=`user_${e.userId}_`),i&&(l+=`${i}_`),{keyCookieName:n,csrfCookieName:d,oneTimeCodeName:l+=t}}},96052:(e,s,a)=>{a.r(s),a.d(s,{default:()=>d});var r=a(29021),t=a.n(r),i=a(21572);let n=a.n(i)().createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});async function d({to:e,subject:s,text:a,html:r,alias:i,senderName:d}){let l;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let u=(i?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!t().existsSync("./email/index.html"))return;let c=t().readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,r||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let r={};r.from=`"${d||"Datasquirel"}" <${u}>`,r.sender=u,i&&(r.replyTo=u),r.to=e,r.subject=s,r.text=a,r.html=c,l=await n.sendMail(r)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},95969:(e,s,a)=>{a.d(s,{A:()=>i});var r=a(55511),t=a(79428);function i({encryptedString:e,encryptionKey:s,encryptionSalt:a}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=s||process.env.DSQL_ENCRYPTION_PASSWORD,n=a||process.env.DSQL_ENCRYPTION_SALT,d=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!i?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!n?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,r.scryptSync)(i,n,d),u=t.Buffer.alloc(16,0),c=(0,r.createDecipheriv)("aes-192-cbc",l,u);try{let s=c.update(e,"hex","utf8");return s+=c.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}},83919:(e,s,a)=>{a.d(s,{A:()=>t});var r=a(55511);function t({password:e,encryptionKey:s}){let a=s||process.env.DSQL_ENCRYPTION_PASSWORD;if(!a?.match(/.{8,}/))throw Error("Encryption key is invalid");let t=(0,r.createHmac)("sha512",a);return t.update(e),t.digest("base64")}}};var s=require("../../webpack-api-runtime.js");s.C(e);var a=e=>s(s.s=e),r=s.X(0,[1251],()=>a(70955));module.exports=r})();