"use strict";(()=>{vare={};e.id=4065,e.ids=[4065],e.modules={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")},33873:e=>{e.exports=require("path")},79551:e=>{e.exports=require("url")},28354:e=>{e.exports=require("util")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){returnfunctione(t,r){returnrint?t[r]:"then"int&&"function"==typeoft.then?t.then(t=>e(t,r)):"function"==typeoft&&"default"===r?t:void0}}})},63177:(e,t,r)=>{r.r(t),r.d(t,{config:()=>y,default:()=>E,routeModule:()=>D});varn={};r.r(n),r.d(n,{default:()=>h});vars=r(89947),a=r(2706),o=r(96762),i=r(76856),l=r(29021),u=r.n(l),c=r(33873),d=r.n(c);let_=async({userId:e,dbSchema:t,targetDb:r})=>(await(0,i.A)({userId:e,targetDatabase:r}),`User ${e} Db Schema Updated`),f=async({userId:e,dbSchema:t,database:r})=>{letn=d().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),s=JSON.parse(u().readFileSync(n,"utf-8")),a=s.findIndex(e=>e.dbFullName==r.db_full_name);if(a<0)throwError("Target Database not found in user schema data");leto={...s[a]};returns[a]=t,s[a].dbName=o.dbName,s[a].dbFullName=o.dbFullName,s[a].dbSlug=o.dbSlug,s[a].dbImage=o.dbImage,await_({dbSchema:s,userId:e,targetDb:r.db_full_name})};varp=r(67619),S=r(69842),g=r(30802);r(29021),r(28354);let{URL:m}=r(79551);asyncfunctionh(e,t){if("POST"!==e.method)returnt.json({msg:"Failed!"});letr=await(0,S.A)(e,t,!0);if(!r)returnt.json({success:!1,msg:"Unauthorized"});let{url:n,key:s,database:a,dbSchema:o,type:i,remoteDbs:l,targetDb:u}=e.body;try{if(!u?.tables)throwError("No Target Database");await(0,g.A)({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:n,remote_connection_key:s,remote_connection_type:i,remote_db_full_name:u.dbFullName},identifierColumnName:"db_full_name",identifierValue:a.db_full_name}),awaitf({dbSchema:u,database:a,userId:r.id}),t.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),(0,p.default)({component:"/api/connect/verify/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Operation Failed!"})}}letE=(0,o.M)(n,"default"),y=(0,o.M)(n,"config"),D=news.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:n})},69842:(e,t,r)=>{r.d(t,{A:()=>l});varn=r(48786),s=r(95969),a=r(29021),o=r.n(a),i=r(89159);asyncfunctionl(e,t,r){let{keyCookieName:a,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))returnnull;letu=(0,s.A)({encryptedString:e.cookies[a]});if(!u)returnnull;letc=JSON.parse(u);if(!c.csrf_k||r&&!Object.keys(e.headers).find(e=>e.includes(c.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(r&&!o().existsSync(`${d}/${c.csrf_k}`))returnnull;if(0==c.verification_status&&!r){lete=await(0,n.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}returnc?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,t,r)=>{r.d(t,{A:()=>n});functionn(e){lett=process.env.DSQL_COOKIES_PREFIX||"dsql_",r=process.env.DSQL_COOKIES_KEY_NAME||"key",n=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=t;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=r;leti=t;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=n;letl=t;returne?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:l+=s}}},30802:(e,t,r)=>{r.d(t,{A:()=>c});varn=r(72583),s=r.n(n),a=r(92652),o=r(48786),i=r(37275),l=r(6