"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")},33873:e=>{e.exports=require("path")},69653:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>b,routeModule:()=>g});vara={};t.r(a),t.d(a,{default:()=>m});vars=t(89947),o=t(2706),i=t(96762),n=t(67619),l=t(69842),d=t(27825),c=t.n(d),u=t(48786),p=t(33170);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=await(0,u.A)(`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!");leti=o[0];a||(a=i.root_user_id)}return{isPriviledged:!0,rootUserId:a}}catch(e){return{isPriviledged:!1,rootUserId:a,error:e.message}}}varf=t(4820);asyncfunctionm(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,l.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{paradigm:a,src:s,dst:o}=e.body;try{leti=await_({tbls:[{db:s.db,table:s.table},{db:o.db,table:o.table}],user:t,query:e.query});if(!i.rootUserId||!i.isPriviledged)throwError(i.error||"Unauthorized!");letn=(0,f.A)({userId:i.rootUserId});if(!n)throwError("User Schema Data not Found!");letl=`${process.env.DSQL_USER_DB_PREFIX}${i.rootUserId}_${o.db}`,d=`${process.env.DSQL_USER_DB_PREFIX}${i.rootUserId}_${s.db}`,m=n.find(e=>e.dbFullName==l),b=n.find(e=>e.dbFullName==d),S=m?.tables.find(e=>e.tableName==o.table),g=b?.tables.find(e=>e.tableName==s.table);if(!S||!g)throwError("Operation Failed! Tables Schemas not present.");if(!c().isEqual(g.fields,S.fields))throwError("Tables incompatible");switch(a){case"Push":leth=await(0,u.A)(`SELECT * FROM ${d}.${s.table}`),y=await(0,p.A)({dbName:o.db,paradigm:"import",payload:h,tableName:o.table,userId:i.rootUserId,payloadType:"object"});returnawaitE({dbName:o.db,tableName:o.table,data:h,userId:i.rootUserId}),r.json({success:!0,payload:y});case"Pull":let$=await(0,u.A)(`SELECT * FROM ${l}.${o.table}`),A=await(0,p.A)({dbName:s.db,paradigm:"import",payload:$,tableName:s.table,userId:i.rootUserId,payloadType:"object"});returnawaitE({dbName:s.db,tableName:s.table,data:$,userId:i.rootUserId}),r.json({success:!0,payload:A})}r.json({success:!1})}catch(e){console.log(e.message),(0,n.A)({component:"/api/sync-table-data",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}asyncfunctionE({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),i=`DELETE FROM ${s}.${r}`;o?.[0]&&(i+=` WHERE id NOT IN (${o.join(",")})`),await(0,u.A)(i)}letb=(0,i.M)(a,"default"),S=(0,i.M)(a,"config"),g=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/sync-table-data",pathname:"/api/sync-table-data",bundlePath:"",filename:""},userland:a})},33170:(e,r,t)=>{t.d(r,{A:()=>i});vara=t(98e3),s=t(67619),o=t(48786);asyncfunctioni({paradigm:e,userId:r,dbName:t,tableName:i,payload:n,payloadType:l}){letd={};try{lets=`${process.env.DSQL_USER_DB_PREFIX}${r}_${t.replace(/ /g,"")}`;switch(e){case"export":letc=await(0,o.A)(`SELECT * FROM \`${s}\`.\`${i}\``);d.tableData=c;break;case"import":letu="base64"==l?Buffer.from(n,"base64").toString():n,p="object"===l?n:JSON.parse(u);for(lete=0;e<p.length;e++){letr=p[e],t=await(0,a.A)({data:r,dbFullName:s,tableName:i,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){return(0,s.A)({component:"/functions/backend/importExportTableDataFn",message:e.message}),null}}},69842:(e,r,t)=>{t.d(r,{A:()=>l});vara=t(48786),s=t(95969),o=t(29021),i=t.n(o),n=t(89159);asyncfuncti