"use strict";(()=>{var e={};e.id=5757,e.ids=[5757],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")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},96332:(e,r,t)=>{t.r(r),t.d(r,{config:()=>E,default:()=>p,routeModule:()=>m});var s={};t.r(s),t.d(s,{default:()=>f});var a=t(89947),n=t(2706),l=t(96762),o=t(29021),i=t.n(o),c=t(30944),u=t(67619),d=t(69842),_=t(48786);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,d.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=e.body,{id:a,user_id:n,table_name:l,table_slug:o,table_description:f}=s.table,{db_full_name:p}=s.database;await (0,c.A)({database:p,queryString:`DROP TABLE \`${p}\`.\`${o}\``});let E=a?[a]:[o,t.id,s.database.id];await (0,_.A)(a?"DELETE FROM user_database_tables WHERE id=?":"DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_id=?",E);try{let e;let s=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`,a=JSON.parse(i().readFileSync(s,"utf8")),n=a.filter((e,r)=>{if(e.dbFullName===p)return!0}),l=n[0].tables.filter((r,t)=>{if(r?.tableName===o)return e=t,!0});if(l[0].childTable){let e;let r=a.filter(e=>e.dbFullName===l[0].childTableDbFullName)[0].tables.filter(e=>{if(e.tableName===l[0].childTableName)return!0})[0];r.childrenTables?.filter((r,t)=>{r.tableName===o&&(e=t)}),"number"==typeof e&&r.childrenTables?.splice(e,1)}if(n[0].tables.splice(e,1),n[0].childrenDatabases)for(let e=0;ee.dbFullName===r.dbFullName)[0];e.tables=n[0].tables,await (0,_.A)("DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_slug=?",[o,t.id,e.dbSlug])}catch(e){(0,u.A)({component:"/api/deleteUserTable/lines-125-128",message:e.message,user:t})}}i().writeFileSync(`${s}`,JSON.stringify(a),"utf8"),r.json({success:!0})}catch(e){(0,u.A)({component:"/api/deleteUserTable/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"File Updates Failed"})}}let p=(0,l.M)(s,"default"),E=(0,l.M)(s,"config"),m=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/deleteUserTable",pathname:"/api/deleteUserTable",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>i});var s=t(48786),a=t(95969),n=t(29021),l=t.n(n),o=t(89159);async function i(e,r,t){try{let{keyCookieName:n,csrfCookieName:i}=(0,o.A)();if(!e.cookies?.[n]?.match(/./))throw Error("Request Cookies not Found!");let c=(0,a.A)({encryptedString:e.cookies[n]});if(!c)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(c);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!l().existsSync(`${d}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),l=r;e?.userId&&(l+=`user_${e.userId}_`),n&&(l+=`${n}_`),l+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=s;let i=r;return e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),{keyCookieName:l,csrfCookieName:o,oneTimeCodeName:i+=a}}},43775:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(95969);let a=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function n({unparsedResults:e,tableSchema:r}){let t=[];try{for(let n=0;n",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(29021),a=t.n(s);async function n({user:e,message:r,component:t,noMail:s,req:n}){let l=new Date,o=(()=>{if(!n)return null;try{let e=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)return null;return String(a)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),n?.url&&(s+=` URL: ${n.url}`),n?.body&&(s+=` Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(s+=` IP: ${o}`),s+=` Date: ${l.toDateString()} ========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let i=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",s),a().appendFileSync("./.tmp/error.log",` ${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>i});var s=t(43775),a=t(67619),n=t(48786),l=t(37275),o=t(7971);async function i({queryString:e,queryValuesArray:r,database:t,tableSchema:i,useLocal:c}){let u;let d=!!c||!!t?.match(/^datasquirel$/),_=c?o.A:d?n.A:l.A;try{u=e&&r&&Array.isArray(r)&&r[0]?d?await _(e,r):await _({paradigm:"Full Access",queryString:e,queryValues:r}):d?await _(e):await _({paradigm:"Full Access",queryString:e})}catch(e){console.log(`varDatabaseDbHandler Error: ${e.message}`),(0,a.A)({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(u&&i)try{let e=u;return await (0,s.A)({unparsedResults:e,tableSchema:i})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,a.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(u)return u;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(55511),a=t(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let i=(0,s.scryptSync)(n,l,o),c=a.Buffer.alloc(16,0),u=(0,s.createDecipheriv)("aes-192-cbc",i,c);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},37275:(e,r,t)=>{async function s(e,r,t){try{if("string"==typeof r){let s=await e.query(a(r),t);return JSON.parse(JSON.stringify(s))}if("object"!=typeof r)return null;{let t=[];for(let s=0;sn})},7971:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(9973),a=t.n(s),n=t(29021),l=t.n(n);async function o(...e){let r=a()({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):void 0,charset:"utf8mb4",ssl:function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!l().existsSync(r)){console.log(`${r} does not exist`);return}return{ca:l().readFileSync(`${e}/ca-cert.pem`),rejectUnauthorized:!1}}()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let t=await r.query(...e);return await r.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=96332);module.exports=t})();