"use strict";(()=>{var e={};e.id=9187,e.ids=[9187],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")},49915:(e,r,s)=>{s.r(r),s.d(r,{config:()=>m,default:()=>f,routeModule:()=>S});var t={};s.r(t),s.d(t,{default:()=>_});var a=s(89947),i=s(2706),n=s(96762),o=s(14533),l=s.n(o),u=s(6420),d=s.n(u),c=s(47670),p=s.n(c);async function _(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});if(!await d()(e,r,!0))return r.json({success:!1,msg:"Unauthorized"});let{payload:s,dbFullName:t,dbId:a}=e.body,i=await p()({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:t,tableName:"users",data:(()=>{let e=Object.keys(s),r={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(r[e]=s[e])}),r.password=l()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:s.password}),r.email=s.email_address,r.image="/images/user-preset.png",r.image_thumbnail="/images/user-preset-thumbnail.png",delete r.email_address,r})()});r.json({success:!!i?.insertId,msg:"New User User Added",newUserId:i.insertId})}let f=(0,n.M)(t,"default"),m=(0,n.M)(t,"config"),S=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addDbUser",pathname:"/api/addDbUser",bundlePath:"",filename:""},userland:t})},6420:(e,r,s)=>{s(81630);let t=s(51348),a=s(72835),i=s(29021),n=s(31341);async function o(e,r,s,o){let{keyCookieName:l,csrfCookieName:u}=n();if(!e.cookies?.[l]?.match(/./))return null;let d=a({encryptedString:e.cookies[l]});if(!d)return null;let c=JSON.parse(d);if(!c.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let p=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!p)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!i.existsSync(`${p}/${c.csrf_k}`))return null;if(0==c.verification_status&&!s){let e=await t(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=o},31341:e=>{e.exports=function(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=r;e?.userId&&(a+=`user_${e.userId}_`),e?.database&&(a+=`${e.database}_`),a+=s;let i=r;return e?.userId&&(i+=`user_${e.userId}_`),e?.database&&(i+=`${e.database}_`),{keyCookieName:a,csrfCookieName:i+=t}}},72835:(e,r,s)=>{let{scryptSync:t,createDecipheriv:a}=s(55511),{Buffer:i}=s(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:s})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,l=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(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=a("aes-192-cbc",t(n,o,l),i.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},14533:(e,r,s)=>{let{createHmac:t}=s(55511);e.exports=function({password:e,encryptionKey:r}){let s=r||process.env.DSQL_ENCRYPTION_PASSWORD;if(!s?.match(/.{8,}/))throw Error("Encryption key is invalid");let a=t("sha512",s);return a.update(e),a.digest("base64")}}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[4050],()=>s(49915));module.exports=t})();