"use strict";(()=>{vare={};e.id=861,e.ids=[861],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")},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")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,t){returntinr?r[t]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,t)):"function"==typeofr&&"default"===t?r:void0}}})},15679:(e,r,t)=>{t.r(r),t.d(r,{config:()=>E,default:()=>m,routeModule:()=>A});vars={};t.r(s),t.d(s,{default:()=>b});vara=t(89947),o=t(2706),n=t(96762),l=t(48786),i=t(60125),d=t(67619),c=t(69842),u=t(4820),_=t(29021),p=t.n(_),f=t(27825),D=t.n(f),S=t(76856);asyncfunctionb(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,c.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.schema,a=e.body.database,o=e.body.table;e.body.delegated;try{letn;letd=await(0,i.A)({request:e,user:t,databaseSlug:a,query:e.query}),c=d?.rootUserId?d.rootUserId:t.id,_=`datasquirel_user_${c}_${a}`.replace(/[^a-z\_0-9]/g,"");if(d?.delegated){lete=await(0,l.A)("SELECT * FROM user_users WHERE invited_user_id=? AND user_id=? AND user_priviledge LIKE '%Edit Tables%'",[t.id,d.rootUserId]);e&&e[0]&&(n=!0)}elsen=!0;if(!n)returnr.json({success:!1,msg:"Unauthorized"});letf=(0,u.A)({userId:c});if(!f)throwError("Database schema not found!");if(!function({dbSchemaData:e,delegatedUser:r,dbFullName:t,schema:s,table:a,userId:o}){letn=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/main.json`;try{if(!e)throwError("Database schema not found!");leto=D().cloneDeep(e),l=o.find(e=>e.dbFullName==t);if(!l)throwError("Old Database schema not found!");leti=o.findIndex(e=>e.dbFullName==t);if(i<0)throwError("Target Database index not found!");letd=s.find(e=>e.dbFullName===t);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!");letc=d.tables.find(e=>e.tableName==a.tableName);if(!c)throwError("Table schema not found!");letu=l.tables.findIndex(e=>e.tableName==a.tableName);c&&(o[i].tables[u]=c);let_=l?.childrenDatabases;_?.forEach(e=>{letr=o.findIndex(r=>r.dbFullName===e.dbFullName);o[r]&&l&&(o[r].tables=l.tables.map(e=>{letr=D().cloneDeep(e);returndeleter.childrenTables,r}))});letf=o?.[i]?.tables?.[u]?.childrenTables;returnf&&f.forEach(e=>{letr=o.findIndex(r=>r.dbFullName==e.dbNameFull),t=o[r]?.tables?.findIndex(r=>r.tableName===e.tableName);o[r]?.tables[t]&&(o[r].tables[t].fields=D().cloneDeep(c.fields),o[r].tables[t].indexes=D().cloneDeep(c.indexes))}),p().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),!0}catch(e){returnconsole.log("updateSchemaData.ts ERROR: ",e.message),!1}}({dbFullName:_,dbSchemaData:f,delegatedUser:d,schema:s,table:o,userId:c}))throwError("Update Failed!");returnawait(0,S.A)({userId:c,targetDatabase:_}),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:t}),r.json({success:!1,msg:e.message})}}letm=(0,n.M)(s,"default"),E=(0,n.M)(s,"config"),A=newa.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbSchemaDataForUser",pathname:"/api/updateDbSchemaDataForUser",bundlePath:"",filename:""},userland:s})},60125:(e,r,t)=>{t.d(r,{A:()=>a});vars=t(95969);asyncfunctiona({request:e,databaseSlug:r,user:t,query:a}){try{leto=t.id,n=null;if(!a?.delegated)return{dbUserId:o};letl=a.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[d])throwError("Cookie not present");lett=(0,s.A)({encryptedString:e.cookies[d]});if(!t)throwError("Invalid Token");if((n=JSON.parse(t)