"use strict";(()=>{vare={};e.id=538,e.ids=[538],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")},41848:(e,r,t)=>{t.r(r),t.d(r,{config:()=>N,default:()=>h,routeModule:()=>I});vara={};t.r(a),t.d(a,{default:()=>y});vars=t(89947),o=t(2706),l=t(96762),n=t(48225),i=t.n(n),d=t(6420),u=t.n(d),c=t(27825),p=t.n(c),_=t(51348),m=t.n(_),b=t(27444);t(81630),t(48225);letf=t(51348);asyncfunctionE({tbls:e,user:r,query:t}){leta;if(!t?.delegated)return{isPriviledged:!0,rootUserId:r.id};try{for(lett=0;t<e.length;t++){lets=e[t],o=awaitf(`SELECT * FROM delegated_user_tables WHERE delegated_user_id='${r.id}' AND \`database\`='${s.db}' AND \`table\`='${s.table}'`);if(!o?.[0]?.root_user_id)throwError("Unauthorized!");letl=o[0];a||(a=l.root_user_id)}return{isPriviledged:!0,rootUserId:a}}catch(e){return{isPriviledged:!1,rootUserId:a,error:e.message}}}varS=t(2258),g=t.n(S);asyncfunctiony(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitu()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{paradigm:a,src:s,dst:o}=e.body;try{letl=awaitE({tbls:[{db:s.db,table:s.table},{db:o.db,table:o.table}],user:t,query:e.query});if(!l.rootUserId||!l.isPriviledged)throwError(l.error||"Unauthorized!");letn=g()({userId:l.rootUserId});if(!n)throwError("User Schema Data not Found!");leti=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${o.db}`,d=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${s.db}`,u=n.find(e=>e.dbFullName==i),c=n.find(e=>e.dbFullName==d),_=u?.tables.find(e=>e.tableName==o.table),f=c?.tables.find(e=>e.tableName==s.table);if(!_||!f)throwError("Operation Failed! Tables Schemas not present.");if(!p().isEqual(f.fields,_.fields))throwError("Tables incompatible");switch(a){case"Push":letS=awaitm()(`SELECT * FROM ${d}.${s.table}`),y=await(0,b.A)({dbName:o.db,paradigm:"import",payload:S,tableName:o.table,userId:l.rootUserId,payloadType:"object"});returnawait$({dbName:o.db,tableName:o.table,data:S,userId:l.rootUserId}),r.json({success:!0,payload:y});case"Pull":leth=awaitm()(`SELECT * FROM ${i}.${o.table}`),N=await(0,b.A)({dbName:s.db,paradigm:"import",payload:h,tableName:s.table,userId:l.rootUserId,payloadType:"object"});returnawait$({dbName:s.db,tableName:s.table,data:h,userId:l.rootUserId}),r.json({success:!0,payload:N})}r.json({success:!1})}catch(e){console.log(e.message),i()({component:"/api/sync-table-data",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}asyncfunction$({dbName:e,tableName:r,data:t,userId:a}){lets=`${process.env.DSQL_USER_DB_PREFIX}${a}_${e.replace(/ /g,"")}`,o=t.map(e=>e.id),l=`DELETE FROM ${s}.${r}`;o?.[0]&&(l+=` WHERE id NOT IN (${o.join(",")})`),awaitm()(l)}leth=(0,l.M)(a,"default"),N=(0,l.M)(a,"config"),I=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/sync-table-data",pathname:"/api/sync-table-data",bundlePath:"",filename:""},userland:a})},27444:(e,r,t)=>{t.d(r,{A:()=>n});vara=t(47670),s=t.n(a);leto=t(48225),l=t(51348);asyncfunctionn({paradigm:e,userId:r,dbName:t,tableName:a,payload:n,payloadType:i}){letd={};try{leto=`${process.env.DSQL_USER_DB_PREFIX}${r}_${t.replace(/ /g,"")}`;switch(e){case"export":letu=awaitl(`SELECT * FROM \`${o}\`.\`${a}\``);d.tableData=u;break;case"import":letc="base64"==i?Buffer.from(n,"base64").toString():n,p="object"===i?n:JSON.parse(c);for(lete=0;e<p.length;e++){letr=p[e],t=awaits()({data:r,dbFullName:o,tableName:a,dbContext:"Dsql User",paradigm:"Full Access",duplicateColumnName:"id",duplicateColumnValue:r?.id,update:!0});if(t.error)throwError(t.error)}break;default:returnnull}returnd}catch(e){returno({component:"/functions/backend/importExportTableDataFn",message:e.message}),null}}},6420:(e,r,t)=>{t(81630);let