"use strict";(()=>{vare={};e.id=460,e.ids=[460],e.modules={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")},66912:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>f,routeModule:()=>g});vars={};t.r(s),t.d(s,{default:()=>E});vara=t(89947),o=t(2706),i=t(96762),n=t(77377),d=t(98e3),l=t(31495),u=t(60125),c=t(67619),_=t(69842);asyncfunctionE(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,_.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"User Auth Failed"});let{tableName:s,payload:a,tableSchema:o,dbSlug:i,dbId:E,delegated:f}=e.body;try{letc=await(0,u.A)({databaseSlug:i,request:e,user:t,query:e.query});if(!await(0,l.A)({user:t,confirmedDelegetedUser:c,database:i,table:s,dbId:E,priviledgeRegex:/Update Entries/i}))returnr.json({success:!1,msg:"Unauthorized"});let_=c?.rootUserId?`datasquirel_user_${c.rootUserId}_${i}`:`datasquirel_user_${t.id}_${i}`,f=await(0,d.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:_,tableName:s,data:a,tableSchema:o});if(!f.insertId)throwconsole.log("Table Insertion Failed =>",f),Error(f?.error||"Table Insertion Failed");await(0,n.A)({dbName:_,entryId:f.insertId,entryOrder:a.order,tableName:s,tableSchema:o}),r.json({success:!0})}catch(e){(0,c.default)({component:"/api/addTableEntry/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!",err:e.message})}}letf=(0,i.M)(s,"default"),p=(0,i.M)(s,"config"),g=newa.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:s})},31495:(e,r,t)=>{t.d(r,{A:()=>o});vars=t(48786),a=t(67619);asyncfunctiono({user:e,confirmedDelegetedUser:r,database:t,table:o,priviledgeRegex:i,dbId:n}){letd,l;try{r?.delegated?(d=await(0,s.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,o]),l=d[0]?.priviledge?.match(i)):(d=await(0,s.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,o,n]),l=!0)}catch(r){(0,a.default)({component:"checkUserRights",message:r.message,user:e})}return!!d&&!!d[0]&&!!l}},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,i=null;if(!a?.delegated)return{dbUserId:o};letn=a.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${n}_${r}`,l=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[l])throwError("Cookie not present");lett=(0,s.A)({encryptedString:e.cookies[l]});if(!t)throwError("Invalid Token");if((i=JSON.parse(t)).databaseSlug===r)return{dbUserId:o=i.rootUserId,rootUserId:i.rootUserId,rootUserName:i.rootUserName,rootUserEmail:i.rootUserEmail,rootUserImage:i.rootUserImage,databaseFullName:i.databaseFullName,databaseSlug:i.databaseSlug,allowedTables:i.allowedTables,priviledges:i.priviledges,database:i.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:o}}catch(e){returnnull}}},77377:(e,r,t)=>{t.d(r,{A:()=>a});lets=t(37275);asyncfunctiona({dbName:e,entryId:r,entryOrder:t,tableName:a,tableSchema:o}){try{if(o.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){leto=awaits({database:e,paradigm:"Full Access",queryString:`SELECT * FROM ${a} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!o?.[0])throwError("No Existing Order");awaits({database:e,paradigm:"Full Access",queryString:`UPDATE ${a} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${t} AND id != ?`,queryValues:[String(r)]})}return!0}catch(e){return!1}}},69842:(e,r,t)=>{t.d(r,{A:()=>d});vars=t(48786),a=t(95969),o=t(29021),i=t.n(o),n=t(89159);asyncfunctiond(e,r,t){try{let{keyCookieName:o,csrfCookieName:d}=(0,n.A)();if(!e.cookies?.[o]?.match(/./))throwError("Request Cookies not Found!");letl=(0,a.A)({encrypte