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

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

Accept Invitation `});a.json({success:!!r?.accepted,msg:"This is an invitation request"})}}let p=(0,n.M)(t,"default"),_=(0,n.M)(t,"config"),v=new r.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:t})},69842:(e,a,s)=>{s.d(a,{A:()=>i});var t=s(39908),r=s.n(t);async function i(e,a,s){let t=r()({req:e,level:s?"deep":void 0});return console.log(t),t.payload}},96052:(e,a,s)=>{s.d(a,{A:()=>d});var t=s(29021),r=s.n(t),i=s(21572);let n=s.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:a,text:s,html:t,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(!r().existsSync("./email/index.html"))return;let o=r().readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,t||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let t={};t.from=`"${d||"Datasquirel"}" <${u}>`,t.sender=u,i&&(t.replyTo=u),t.to=e,t.subject=a,t.text=s,t.html=o,l=await n.sendMail(t)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},83919:(e,a,s)=>{s.d(a,{A:()=>i});var t=s(55511),r=s(32443);function i({password:e,encryptionKey:a}){let{key:s}=(0,r.A)({encryptionKey:a});if(!s?.match(/.{8,}/))throw Error("Encryption key is invalid");let i=(0,t.createHmac)("sha512",s);return i.update(e),i.digest("base64")}}};var a=require("../../webpack-api-runtime.js");a.C(e);var s=e=>a(a.s=e),t=a.X(0,[1251],()=>s(70955));module.exports=t})();