"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,r)=>{r.r(s),r.d(s,{config:()=>m,default:()=>p,routeModule:()=>f});var t={};r.r(t),r.d(t,{default:()=>_});var a=r(89947),i=r(2706),n=r(96762),o=r(96052),d=r(69842),c=r(98e3),l=r(48786),u=r(83919);async function _(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let r=await (0,d.A)(e,s,!0);if(!r)return s.json({success:!1,msg:"Unauthorized"});let t=e.body,a=t.paradigm;if(a?.match(/database/)){let e=await (0,c.A)({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(t),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=t[e])}),s.user_id=r.id,s.password=(0,u.A)({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:t.password}),s.user_type="database",s.email=t.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(r?.email===t.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await (0,l.A)("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[t.email_address,r.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await (0,c.A)({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:r.id,invited_user_email:t.email_address,database_access:t.database_access,priviledge:t.priviledge,db_tables_data:t.db_tables}});let a=await (0,o.A)({to:t.email_address,subject:`${r.first_name} ${r.last_name} Invited you`,text:`${r.first_name} ${r.last_name} has invited you to manage a datasquirel account`,html:`
${r.first_name} ${r.last_name} has invited you to manage a datasquirel account.
Accept Invitation
`});s.json({success:!!a?.accepted,msg:"This is an invitation request"})}}let p=(0,n.M)(t,"default"),m=(0,n.M)(t,"config"),f=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:t})},69842:(e,s,r)=>{r.d(s,{A:()=>d});var t=r(48786),a=r(95969),i=r(29021),n=r.n(i),o=r(89159);async function d(e,s,r){try{let{keyCookieName:i,csrfCookieName:d}=(0,o.A)();if(!e.cookies?.[i]?.match(/./))throw Error("Request Cookies not Found!");let c=(0,a.A)({encryptedString:e.cookies[i]});if(!c)throw Error("Couldn't decrypt auth cookie!");let l=JSON.parse(c);if(!l.csrf_k)throw Error("No `csrf_k` present in user Object!");if(r&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",l),Error("Deep Auth Failed. `csrf` key not found in request headers!");let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(r&&!n().existsSync(`${u}/${l.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==l.verification_status&&!r){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}if(l?.date&&Date.now()-l.date>6048e5)throw Error("Key expired!");return l}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,s,r)=>{r.d(s,{A:()=>t});function t(e){let s=process.env.DSQL_COOKIES_PREFIX||"dsql_",r=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=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+=r;let o=s;e?.userId&&(o+=`user_${e.userId}_`),i&&(o+=`${i}_`),o+=t;let d=s;return e?.userId&&(d+=`user_${e.userId}_`),i&&(d+=`${i}_`),{keyCookieName:n,csrfCookieName:o,oneTimeCodeName:d+=a}}},96052:(e,s,r)=>{r.d(s,{A:()=>o});var t=r(29021),a=r.n(t),i=r(21572);let n=r.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 o({to:e,subject:s,text:r,html:t,alias:i,senderName:o}){let d;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let c=(i?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!a().existsSync("./email/index.html"))return;let l=a().readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,t||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let t={};t.from=`"${o||"Datasquirel"}" <${c}>`,t.sender=c,i&&(t.replyTo=c),t.to=e,t.subject=s,t.text=r,t.html=l,d=await n.sendMail(t)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return d}},95969:(e,s,r)=>{r.d(s,{A:()=>i});var t=r(55511),a=r(79428);function i({encryptedString:e,encryptionKey:s,encryptionSalt:r}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=s||process.env.DSQL_ENCRYPTION_PASSWORD,n=r||process.env.DSQL_ENCRYPTION_SALT,o=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 d=(0,t.scryptSync)(i,n,o),c=a.Buffer.alloc(16,0),l=(0,t.createDecipheriv)("aes-192-cbc",d,c);try{let s=l.update(e,"hex","utf8");return s+=l.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}},83919:(e,s,r)=>{r.d(s,{A:()=>a});var t=r(55511);function a({password:e,encryptionKey:s}){let r=s||process.env.DSQL_ENCRYPTION_PASSWORD;if(!r?.match(/.{8,}/))throw Error("Encryption key is invalid");let a=(0,t.createHmac)("sha512",r);return a.update(e),a.digest("base64")}}};var s=require("../../webpack-api-runtime.js");s.C(e);var r=e=>s(s.s=e),t=s.X(0,[1251],()=>r(70955));module.exports=t})();