"use strict";(()=>{vare={};e.id=1658,e.ids=[1658],e.modules={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")},81630:e=>{e.exports=require("http")},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}}})},43390:(e,r,t)=>{t.r(r),t.d(r,{config:()=>D,default:()=>g,routeModule:()=>y});vars={};t.r(s),t.d(s,{default:()=>m});vara=t(89947),n=t(2706),o=t(96762),i=t(64122),l=t.n(i),u=t(73677),c=t.n(u),d=t(39831),_=t.n(d),p=t(77538),S=t.n(p),f=t(6420),E=t.n(f);asyncfunctionm(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitE()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{dbFullName:s,tableName:a,entryId:n,dbSlug:o,dbId:i,delegated:u}=e.body;try{letu=await_()({databaseSlug:o,request:e,user:t,query:e.query});if(!awaitc()({user:t,confirmedDelegetedUser:u,database:o,table:a,dbId:i,priviledgeRegex:/Delete Entries/i}))returnr.json({success:!1,msg:"Unauthorized"});awaitl()({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:s,tableName:a,identifierColumnName:"id",identifierValue:n}),r.json({success:!0})}catch(e){S()({component:"/api/deleteTableEntry/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Deletion Failed!"})}}letg=(0,o.M)(s,"default"),D=(0,o.M)(s,"config"),y=newa.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/deleteTableEntry",pathname:"/api/deleteTableEntry",bundlePath:"",filename:""},userland:s})},73677:(e,r,t)=>{lets=t(51348),a=t(77538);e.exports=asyncfunction({user:e,confirmedDelegetedUser:r,database:t,table:n,priviledgeRegex:o,dbId:i}){letl,u;try{r?.delegated?(l=awaits("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=awaits("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,n,i]),u=!0)}catch(r){a({component:"checkUserRights",message:r.message,user:e})}return!!l&&!!l[0]&&!!u}},39831:(e,r,t)=>{t(81630);lets=t(72907);e.exports=asyncfunction({request:e,databaseSlug:r,user:t,query:a}){try{letn=t.id,o=null;if(!a?.delegated)return{dbUserId:n};leti=a.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=s(e.cookies[u]);if(!t)throwError("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUserId:n=o.rootUserId,rootUserId:o.rootUserId,rootUserName:o.rootUserName,rootUserEmail:o.rootUserEmail,rootUserImage:o.rootUserImage,databaseFullName:o.databaseFullName,databaseSlug:o.databaseSlug,allowedTables:o.allowedTables,priviledges:o.priviledges,database:o.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:n}}catch(e){returnnull}}},77538:(e,r,t)=>{lets=t(29021),{IncomingMessage:a}=t(81630);e.exports=asyncfunction({user:e,message:r,component:t,noMail:a,req:n}){leto=newDate,i=(()=>{if(!n)returnnull;try{lete=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.socket.remoteAddress;if(!a)returnnull;returnString(a)}catch(e){returnnull}})();try{leta=`🚀 SERVER ERROR ===========================
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let s=t(51348),a=t(72907),n=t(29021);async function o(e,r,t,o){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=a(e.cookies.datasquirelAuthKey);if(!i)return null;let l=JSON.parse(i);if(!l.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!n.existsSync(`${u}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await s(`SELECTverification_statusFROMusersWHEREid='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=o},64122:(e,r,t)=>{let s=t(51348),a=t(21339);async function n({dbContext:e,paradigm:r,dbFullName:t,tableName:n,identifierColumnName:o,identifierValue:i}){try{let l=!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),u=l?s:a,c=`DELETEFROM${n}WHERE\`${o}\`=?`;returnl?awaitu(c,[i]):awaitu({paradigm:r,queryString:c,database:t,queryValues:[i]})}catch(e){returnnull}}e.exports=n},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:a}=t(55511),{Buffer:n}=t(79428);e.exports=e=>{letr=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{lett=r.update(e,"hex","utf8");returnt+=r.final("utf8")}catch(e){returnnull}}},51348:(e,r,t)=>{lets=t(9973),a=t(21580),n=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void0,charset:"utf8mb4",ssl:a()}});asyncfunctiono(...e){try{letr=awaitn.query(...e);returnawaitn.end(),JSON.parse(JSON.stringify(r))}catch(e){returnconsole.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21339:(e,r,t)=>{lets=t(29021);t(33873);leta=t(9973),n=t(21580),o=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:n()}});e.exports=function({paradigm:e,database:r,queryString:t,queryValues:i}){try{returnnewPromise((l,u)=>{letc=!!e?.match(/full.access|^fa$/i);try{functiond(e){o.end(),l(JSON.parse(JSON.stringify(e)))}function_(e){o.end(),l({error:e.message,queryStringGenerated:t,queryValuesGenerated:i,sql:e.sql})}o=c?a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:r,ssl:n()}}):a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:r,ssl:n()}}),i&&Array.isArray(i)&&i[0]?o.query(t,i).then(d).catch(_):o.query(t).then(d).catch(_)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),l({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,r,t)=>{lets=t(29021);e.exports=function(){lete=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;letr=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{vart;Object.defineProperty(r,"A",{enumerable:!0,get:function(){returnt}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};varr=require("../../webpack-api-runtime.js");r.C(e);vart=r(r.s=43390);module.exports=t})();