"use strict";(()=>{vare={};e.id=4065,e.ids=[4065],e.modules={60818:e=>{e.exports=require("dotenv")},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")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},79551:e=>{e.exports=require("url")},28354:e=>{e.exports=require("util")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,t){returntinr?r[t]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,t)):"function"==typeofr&&"default"===t?r:void0}}})},83919:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>m,routeModule:()=>h});vars={};t.r(s),t.d(s,{default:()=>f});varn=t(89947),a=t(2706),o=t(96762),c=t(7753),i=t(48225),l=t.n(i),u=t(6420),_=t.n(u),d=t(33364),p=t.n(d);t(29021),t(28354);let{URL:S}=t(79551);asyncfunctionf(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await_()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{url:s,key:n,database:a,dbSchema:o,type:i,remoteDbs:u,targetDb:d}=e.body;try{if(!d?.tables)throwError("No Target Database");awaitp()({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:s,remote_connection_key:n,remote_connection_type:i,remote_db_full_name:d.dbFullName},identifierColumnName:"db_full_name",identifierValue:a.db_full_name}),await(0,c.e)({dbSchema:d,database:a,userId:t.id}),r.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),l()({component:"/api/connect/verify/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Operation Failed!"})}}letm=(0,o.M)(s,"default"),g=(0,o.M)(s,"config"),h=newn.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:s})},7753:(e,r,t)=>{lets=t(19261),{execSync:n}=t(79646),a=t(29021),o=t(33873),c=async({userId:e,dbSchema:r,targetDb:t})=>(awaits({userId:e,targetDatabase:t}),`User ${e} Db Schema Updated`),i=async({userId:e,dbSchema:r,database:t})=>{lets=o.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),n=JSON.parse(a.readFileSync(s,"utf-8")),i=n.findIndex(e=>e.dbFullName==t.db_full_name);if(i<0)throwError("Target Database not found in user schema data");letl={...n[i]};returnn[i]=r,n[i].dbName=l.dbName,n[i].dbFullName=l.dbFullName,n[i].dbSlug=l.dbSlug,n[i].dbImage=l.dbImage,awaitc({dbSchema:n,userId:e,targetDb:t.db_full_name})};r.e=i},6420:(e,r,t)=>{t(81630);lets=t(51348),n=t(72835),a=t(29021),o=t(31341);asyncfunctionc(e,r,t,c){let{keyCookieName:i,csrfCookieName:l}=o();if(!e.cookies?.[i]?.match(/./))returnnull;letu=n({encryptedString:e.cookies[i]});if(!u)returnnull;let_=JSON.parse(u);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))returnnull;letd=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${d}/${_.csrf_k}`))returnnull;if(0==_.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return_?.date&&Date.now()-_.date>6048e5?null:_}e.exports=c},31341:e=>{e.exports=function(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=r;e?.userId&&(n+=`user_${e.userId}_`),e?.database&&(n+=`${e.database}_`),n+=t;leta=r;returne?.userId&&(a+=`user_${e.userId}_`),e?.database&&(a+=`${e.database}_`),{keyCookieName:n,csrfCookieName:a+=s}}},33364:(e,r,t)=>{lets=t(72583),n=t(16570),a=t(51348),o=t(21339),c=t(20503),i=t(44900);asyncfunctionl({dbContext:e,paradigm:r,dbFullName:t,tableName:l,data:u,tableSchema:_,identifierColumnName:d,ide