"use strict";(()=>{vare={};e.id=538,e.ids=[538],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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:()=>E,default:()=>y,routeModule:()=>$});vara={};t.r(a),t.d(a,{default:()=>f});vars=t(89947),o=t(2706),l=t(96762),i=t(67619),d=t(69842),n=t(27825),u=t.n(n),c=t(48786),p=t(33170);asyncfunctionm({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,c.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!");letl=o[0];a||(a=l.root_user_id)}return{isPriviledged:!0,rootUserId:a}}catch(e){return{isPriviledged:!1,rootUserId:a,error:e.message}}}varb=t(4820);asyncfunctionf(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,d.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{paradigm:a,src:s,dst:o}=e.body;try{letl=awaitm({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!");leti=(0,b.A)({userId:l.rootUserId});if(!i)throwError("User Schema Data not Found!");letd=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${o.db}`,n=`${process.env.DSQL_USER_DB_PREFIX}${l.rootUserId}_${s.db}`,f=i.find(e=>e.dbFullName==d),y=i.find(e=>e.dbFullName==n),E=f?.tables.find(e=>e.tableName==o.table),$=y?.tables.find(e=>e.tableName==s.table);if(!E||!$)throwError("Operation Failed! Tables Schemas not present.");if(!u().isEqual($.fields,E.fields))throwError("Tables incompatible");switch(a){case"Push":letS=await(0,c.A)(`SELECT * FROM ${n}.${s.table}`),h=await(0,p.A)({dbName:o.db,paradigm:"import",payload:S,tableName:o.table,userId:l.rootUserId,payloadType:"object"});returnawaitg({dbName:o.db,tableName:o.table,data:S,userId:l.rootUserId}),r.json({success:!0,payload:h});case"Pull":let_=await(0,c.A)(`SELECT * FROM ${d}.${o.table}`),A=await(0,p.A)({dbName:s.db,paradigm:"import",payload:_,tableName:s.table,userId:l.rootUserId,payloadType:"object"});returnawaitg({dbName:s.db,tableName:s.table,data:_,userId:l.rootUserId}),r.json({success:!0,payload:A})}r.json({success:!1})}catch(e){console.log(e.message),(0,i.A)({component:"/api/sync-table-data",message:e.message,user:t}),r.json({success:!1,msg:e.message})}}asyncfunctiong({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(",")})`),await(0,c.A)(l)}lety=(0,l.M)(a,"default"),E=(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})},33170:(e,r,t)=>{t.d(r,{A:()=>l});vara=t(98e3),s=t(67619),o=t(48786);asyncfunctionl({paradigm:e,userId:r,dbName:t,tableName:l,payload:i,payloadType:d}){letn={};try{lets=`${process.env.DSQL_USER_DB_PREFIX}${r}_${t.replace(/ /g,"")}`;switch(e){case"export":letu=await(0,o.A)(`SELECT * FROM \`${s}\`.\`${l}\``);n.tableData=u;break;case"import":letc="base64"==d?Buffer.from(i,"base64").toString():i,p="object"===d?i:JSON.parse(c);for(lete=0;e<p.length;e++){letr=p[e],t=await(0,a.A)({data:r,dbFullName:s,tableName:l,dbContext:"Dsql User",paradigm:"Full Access",duplicateColumnName:"id",duplicateColumnValue:r?.id,update:!0});if(t.error)throwError(t.error)}break;default:returnnull}returnn}catch(e){return(0,s.A)({component:"/functions/backend/importExportTableDataFn",message:e.message}),null}}},69842:(e,r,t)=>{t.d(r,{A