"use strict";(()=>{vare={};e.id=4371,e.ids=[4371],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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")},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}}})},81147:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>A,routeModule:()=>b});vara={};t.r(a),t.d(a,{default:()=>S});vars=t(89947),n=t(2706),o=t(96762),i=t(29021),l=t.n(i),u=t(48786),c=t(31495),d=t(60125),p=t(67619),_=t(69842),f=t(30802),g=t(76856);asyncfunctionS(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,_.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{dbFullName:a,dbSlug:s,dbId:n,tableNameOld:o,payload:i,delegated:S}=e.body,{tableName:A,tableFullName:m,tableDescription:b}=i;if(!A?.match(/./)||A.match(/[^a-zA-Z0-9-_]/))returnr.json({success:!1,msg:"Bad Input"});try{leti=await(0,d.A)({databaseSlug:s,request:e,user:t,query:e.query});if(!await(0,c.A)({user:t,confirmedDelegetedUser:i,database:s,table:o,dbId:n,priviledgeRegex:/Edit Table/i}))returnconsole.log("User Unauthorized"),r.json({success:!1,msg:"Unauthorized"});let_=i?.rootUserId?i.rootUserId:t.id,D=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${_}/main.json`,y=JSON.parse(l().readFileSync(D,"utf8")),E=y.filter(e=>e.dbFullName===a)[0].tables.filter((e,r)=>{if(e.tableName===o)return!0});if(E&&E[0])E[0].tableName=A,E[0].tableNameOld=o,E[0].tableFullName=m,b&&(E[0].tableDescription=b),E[0].childrenTables&&E[0].childrenTables.forEach(e=>{try{y.filter(r=>r.dbFullName===e.dbNameFull)[0].tables.filter(r=>{if(r.tableName===e.tableName)return!0})[0].childTableName=A}catch(e){(0,p.A)({component:"/api/updateUserTable/lines-131-138",message:e.message,user:t})}});elsethrowError("Table Does not exist");l().writeFileSync(`${D}`,JSON.stringify(y),"utf8"),await(0,f.A)({dbFullName:"datasquirel",tableName:"user_database_tables",identifierColumnName:"table_slug",identifierValue:o,data:{table_name:m,table_slug:A,table_description:b}}),S&&i&&await(0,u.A)("UPDATE delegated_user_tables SET `table`=? WHERE delegated_user_id=? AND root_user_id=? AND `table`=? AND `database`=?",[A,t.id,i.rootUserId,o,s]);leth=a.replace(/[^a-z\_0-9]/g,"");await(0,g.A)({userId:_,targetDatabase:h}),r.json({success:!0})}catch(e){(0,p.A)({component:"/api/updateUserTable/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}}letA=(0,o.M)(a,"default"),m=(0,o.M)(a,"config"),b=news.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/updateUserTable",pathname:"/api/updateUserTable",bundlePath:"",filename:""},userland:a})},31495:(e,r,t)=>{t.d(r,{A:()=>n});vara=t(48786),s=t(67619);asyncfunctionn({user:e,confirmedDelegetedUser:r,database:t,table:n,priviledgeRegex:o,dbId:i}){letl,u;try{r?.delegated?(l=await(0,a.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,n]),u=l[0]?.priviledge?.match(o)):(l=await(0,a.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,n,i]),u=!0)}catch(r){(0,s.A)({component:"checkUserRights",message:r.message,user:e})}return!!l&&!!l[0]&&!!u}},60125:(e,r,t)=>{t.d(r,{A:()=>s});vara=t(95969);asyncfunctions({request:e,databaseSlug:r,user:t,query:s}){try{letn=t.id,o=null;if(!s?.delegated)return{dbUserId:n};leti=s.dbUserId,l=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${l}`;try{if(!e.cookies?.[u])throwError("Cookie not present");lett=(0,a.A)({encryptedString:e.cookies[u]});if(!t)throwEr