"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:()=>h,default:()=>$,routeModule:()=>N});vara={};t.r(a),t.d(a,{default:()=>g});vars=t(89947),l=t(2706),o=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),b=t.n(m),f=t(27444);t(81630),t(48225);let_=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],l=await_(`SELECT * FROM delegated_user_tables WHERE delegated_user_id='${r.id}' AND \`database\`='${s.db}' AND \`table\`='${s.table}'`);if(!l?.[0]?.root_user_id)throwError("Unauthorized!");leto=l[0];a||(a=o.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:l}=e.body;try{leto=awaitE({tbls:[{db:s.db,table:s.table},{db:l.db,table:l.table}],user:t,query:e.query});if(!o.rootUserId||!o.isPriviledged)throwError(o.error||"Unauthorized!");letn=(0,S.default)({userId:o.rootUserId});if(!n)throwError("User Schema Data not Found!");leti=`${process.env.DSQL_USER_DB_PREFIX}${o.rootUserId}_${l.db}`,d=`${process.env.DSQL_USER_DB_PREFIX}${o.rootUserId}_${s.db}`,u=n.find(e=>e.dbFullName==i),c=n.find(e=>e.dbFullName==d),m=u?.tables.find(e=>e.tableName==l.table),_=c?.tables.find(e=>e.tableName==s.table);if(!m||!_)throwError("Operation Failed! Tables Schemas not present.");if(!p().isEqual(_.fields,m.fields))throwError("Tables incompatible");switch(a){case"Push":letg=awaitb()(`SELECT * FROM ${d}.${s.table}`),$=await(0,f.A)({dbName:l.db,paradigm:"import",payload:g,tableName:l.table,userId:o.rootUserId,payloadType:"object"});returnawaity({dbName:l.db,tableName:l.table,data:g,userId:o.rootUserId}),r.json({success:!0,payload:$});case"Pull":leth=awaitb()(`SELECT * FROM ${i}.${l.table}`),N=await(0,f.A)({dbName:s.db,paradigm:"import",payload:h,tableName:s.table,userId:o.rootUserId,payloadType:"object"});returnawaity({dbName:s.db,tableName:s.table,data:h,userId:o.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})}}asyncfunctiony({dbName:e,tableName:r,data:t,userId:a}){lets=`${process.env.DSQL_USER_DB_PREFIX}${a}_${e.replace(/ /g,"")}`,l=t.map(e=>e.id),o=`DELETE FROM ${s}.${r}`;l?.[0]&&(o+=` WHERE id NOT IN (${l.join(",")})`),awaitb()(o)}let$=(0,o.M)(a,"default"),h=(0,o.M)(a,"config"),N=news.PagesAPIRouteModule({definition:{kind:l.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);letl=t(48225),o=t(51348);asyncfunctionn({paradigm:e,userId:r,dbName:t,tableName:a,payload:n,payloadType:i}){letd={};try{letl=`${process.env.DSQL_USER_DB_PREFIX}${r}_${t.replace(/ /g,"")}`;switch(e){case"export":letu=awaito(`SELECT * FROM \`${l}\`.\`${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:l,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){returnl({component:"/functions/backend/importExportTableDataFn",message:e.message}),null}}},6420:(e,r,t)=>{t(81630);let