"use strict";(()=>{vare={};e.id=861,e.ids=[861],e.modules={39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/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")},15679:(e,r,a)=>{a.r(r),a.d(r,{config:()=>D,default:()=>E,routeModule:()=>y});vart={};a.r(t),a.d(t,{default:()=>g});vars=a(89947),o=a(2706),l=a(96762),n=a(48786),i=a(60125),d=a(67619),u=a(69842),c=a(4820),m=a(29021),f=a.n(m),p=a(27825),b=a.n(p),h=a(10776);asyncfunctiong(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});leta=await(0,u.A)(e,r,!0);if(!a)returnr.json({success:!1,msg:"Unauthorized"});lett=e.body.schema,s=e.body.database,o=e.body.table;e.body.delegated;try{letl;letd=await(0,i.A)({request:e,user:a,databaseSlug:s,query:e.query}),u=d?.rootUserId?d.rootUserId:a.id,m=`datasquirel_user_${u}_${s}`.replace(/[^a-z\_0-9]/g,"");if(d?.delegated){lete=await(0,n.A)("SELECT * FROM user_users WHERE invited_user_id=? AND user_id=? AND user_priviledge LIKE '%Edit Tables%'",[a.id,d.rootUserId]);e&&e[0]&&(l=!0)}elsel=!0;if(!l)returnr.json({success:!1,msg:"Unauthorized"});letp=(0,c.A)({userId:u});if(!p)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:a,schema:t,table:s,userId:o}){letl=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/main.json`;try{if(!e)throwError("Database schema not found!");leto=b().cloneDeep(e),n=o.find(e=>e.dbFullName==a);if(!n)throwError("Old Database schema not found!");leti=o.findIndex(e=>e.dbFullName==a);if(i<0)throwError("Target Database index not found!");letd=t.find(e=>e.dbFullName===a);if(!d)throwError("New Database schema not found!");if(r?.delegated&&(r.priviledges?.match(/create.?table/i),!r.priviledges?.match(/edit.?table/i)))throwError("Unauthorized!");letu=d.tables.find(e=>e.tableName==s.tableName);if(!u)throwError("Table schema not found!");letc=n.tables.findIndex(e=>e.tableName==s.tableName);u&&(o[i].tables[c]=u);letm=n?.childrenDatabases;m?.forEach(e=>{letr=o.findIndex(r=>r.dbFullName===e.dbFullName);o[r]&&n&&(o[r].tables=n.tables.map(e=>{letr=b().cloneDeep(e);returndeleter.childrenTables,r}))});letp=o?.[i]?.tables?.[c]?.childrenTables;returnp&&p.forEach(e=>{letr=o.findIndex(r=>r.dbFullName==e.dbNameFull),a=o[r]?.tables?.findIndex(r=>r.tableName===e.tableName);o[r]?.tables[a]&&(o[r].tables[a].fields=b().cloneDeep(u.fields),o[r].tables[a].indexes=b().cloneDeep(u.indexes))}),f().writeFileSync(`${l}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.ts ERROR: ",e.message),!1}}({dbFullName:m,dbSchemaData:p,delegatedUser:d,schema:t,table:o,userId:u}))throwError("Update Failed!");returnawait(0,h.A)({userId:u,targetDatabase:m}),r.json({success:!0})}catch(e){console.log("updateDbSchemaDataForUser ERROR:",e.message),(0,d.A)({component:"/api/updateDbSchemaDataForUser/main-catch-error",message:e.message,user:a}),r.json({success:!1,msg:e.message})}}letE=(0,l.M)(t,"default"),D=(0,l.M)(t,"config"),y=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:t})},60125:(e,r,a)=>{a.d(r,{A:()=>s});vart=a(95969);asyncfunctions({request:e,databaseSlug:r,user:a,query:s}){try{leto=a.id,l=null;if(!s?.delegated)return{dbUserId:o};letn=s.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${n}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[d])throwError("Cookie not present");leta=(0,t.A)({encryptedString:e.cookies[d]});if(!a)throwError("Invalid Token");if((l=JSON.parse(a)).databaseSlug===r)return{dbUserId:o=l.rootUserId,rootUserId:l.rootUserId,rootUserName:l.rootUserName,rootUserEmail:l.rootUserEmail,rootUserImage:l.roo