"use strict";(()=>{var e={};e.id=4065,e.ids=[4065],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},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")},63177:(e,a,r)=>{r.r(a),r.d(a,{config:()=>g,default:()=>D,routeModule:()=>h});var s={};r.r(s),r.d(s,{default:()=>f});var t=r(89947),n=r(2706),o=r(96762),d=r(10776),i=r(29021),u=r.n(i),l=r(33873),_=r.n(l);let c=async({userId:e,dbSchema:a,targetDb:r})=>(await (0,d.A)({userId:e,targetDatabase:r}),`User ${e} Db Schema Updated`),m=async({userId:e,dbSchema:a,database:r})=>{let s=_().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),t=JSON.parse(u().readFileSync(s,"utf-8")),n=t.findIndex(e=>e.dbFullName==r.db_full_name);if(n<0)throw Error("Target Database not found in user schema data");let o={...t[n]};return t[n]=a,t[n].dbName=o.dbName,t[n].dbFullName=o.dbFullName,t[n].dbSlug=o.dbSlug,t[n].dbImage=o.dbImage,await c({dbSchema:t,userId:e,targetDb:r.db_full_name})};var p=r(67619),S=r(69842),b=r(30802);async function f(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let{user:r}=await (0,S.A)(e,a,!0);if(!r)return a.json({success:!1,msg:"Unauthorized"});let{url:s,key:t,database:n,dbSchema:o,type:d,remoteDbs:i,targetDb:u}=e.body;try{if(!u?.tables)throw Error("No Target Database");await (0,b.A)({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:s,remote_connection_key:t,remote_connection_type:d,remote_db_full_name:u.dbFullName},identifierColumnName:"db_full_name",identifierValue:n.db_full_name}),await m({dbSchema:u,database:n,userId:r.id}),a.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),(0,p.A)({component:"/api/connect/verify/main-catch-error",message:e.message,user:r}),a.json({success:!1,msg:"Operation Failed!"})}}let D=(0,o.M)(s,"default"),g=(0,o.M)(s,"config"),h=new t.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:s})},55153:(e,a,r)=>{r.d(a,{On:()=>t.a,_n:()=>o}),r(76102);var s=r(65967),t=r.n(s);r(30889);var n=r(93726);let o=r.n(n)()},69842:(e,a,r)=>{r.d(a,{A:()=>o});var s=r(39383),t=r.n(s),n=r(55153);async function o(e,a,r,s){let o=t()({req:e,level:r?"deep":void 0}),d={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return s&&o.payload?.id&&(0,n._n)(process.env.DSQL_SU_USER_ID)!==o.payload.id?{user:null,appData:d}:{user:o.payload,appData:d}}}};var a=require("../../../webpack-api-runtime.js");a.C(e);var r=e=>a(a.s=e),s=a.X(0,[6060,776],()=>r(63177));module.exports=s})();