"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:()=>$});vara={};t.r(a),t.d(a,{default:()=>g});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),m=t(51348),f=t.n(m),b=t(27444);t(81630),t(48225);letE=t(51348);asyncfunction_({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=awaitE(`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);asyncfunctiong(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=await_({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=(0,S.default)({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),m=u?.tables.find(e=>e.tableName==o.table),E=c?.tables.find(e=>e.tableName==s.table);if(!m||!E)throwError("Operation Failed! Tables Schemas not present.");if(!p().isEqual(E.fields,m.fields))throwError("Tables incompatible");switch(a){case"Push":letg=awaitf()(`SELECT * FROM ${d}.${s.table}`),h=await(0,b.A)({dbName:o.db,paradigm:"import",payload:g,tableName:o.table,userId:l.rootUserId,payloadType:"object"});returnawaity({dbName:o.db,tableName:o.table,data:g,userId:l.rootUserId}),r.json({success:!0,payload:h});case"Pull":letN=awaitf()(`SELECT * FROM ${i}.${o.table}`),$=await(0,b.A)({dbName:s.db,paradigm:"import",payload:N,tableName:s.table,userId:l.rootUserId,payloadType:"object"});returnawaity({dbName:s.db,tableName:s.table,data:N,userId:l.rootUserId}),r.json({success:!0,payload:$})}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})}}asyncfunctiony({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(",")})`),awaitf()(l)}leth=(0,l.M)(a,"default"),N=(0,l.M)(a,"config"),$=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