"use strict";(()=>{var e={};e.id=2735,e.ids=[2735],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},12057:(e,r,s)=>{s.r(r),s.d(r,{config:()=>p,default:()=>D,routeModule:()=>L});var t={};s.r(t),s.d(t,{default:()=>S});var a=s(89947),i=s(2706),n=s(96762),o=s(29021),_=s.n(o),d=s(33873),u=s.n(d),c=s(48786),l=s(67619),E=s(69842);async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{user:s}=await (0,E.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});"production".match(/prod/i);try{await (0,c.A)(`DELETE FROM users WHERE id='${s.id}'`),await (0,c.A)(`DELETE FROM user_users WHERE invited_user_id='${s.id}' OR user_id='${s.id}'`),await (0,c.A)(`DELETE FROM delegated_user_tables WHERE delegated_user_id='${s.id}' OR root_user_id='${s.id}'`),await (0,c.A)(`DELETE FROM user_databases WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM user_database_tables WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM user_media WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM delegated_users WHERE user_id='${s.id}' OR delegated_user_id='${s.id}'`),await (0,c.A)(`DELETE FROM unsubscribes WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM notifications WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM api_keys WHERE user_id='${s.id}'`),await (0,c.A)(`DELETE FROM invitations WHERE inviting_user_id='${s.id}' OR invited_user_email='${s.email}'`);let e=await (0,c.A)("SELECT * FROM mariadb_users WHERE user_id = ?",[s.id]);for(let r=0;r<e.length;r++){let{username:s,host:t}=e[r];await (0,c.A)(`DROP USER IF EXISTS '${s}'@'${t}'`)}let t=await (0,c.A)(`SHOW databases LIKE 'datasquirel_user_${s.id}_%'`);for(let e=0;e<t.length;e++){let r=t[e],s=Object.values(r);await (0,c.A)(`DROP database IF EXISTS ${s}`)}let a=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`;_().existsSync(a)&&_().unlinkSync(a);let i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let n=u().join(i,`images/user-images/user-${s.id}`);_().existsSync(n)&&function({rootFolderPath:e}){try{(function e(r){try{let s=_().readdirSync(r);for(let t=0;t<s.length;t++){let a=s[t];a?.match(/\..{2,5}$/)?_().unlinkSync(`${r}/${a}`):e(`${r}/${a}`)}_().rmdirSync(`${r}`)}catch(e){try{_().unlinkSync(r)}catch(e){}}})(e),_().rmSync(`${e}`,{recursive:!0,force:!0})}catch(e){return console.log("ERROR in deleteFolderRecursively.ts function =>",e.message),!1}}({rootFolderPath:n}),r.json({success:!0})}catch(e){(0,l.A)({component:"/api/addApiKey/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"User could not be deleted!"})}}let D=(0,n.M)(t,"default"),p=(0,n.M)(t,"config"),L=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/deleteUser",pathname:"/api/deleteUser",bundlePath:"",filename:""},userland:t})},55153:(e,r,s)=>{s.d(r,{On:()=>a.a,_n:()=>n}),s(76102);var t=s(65967),a=s.n(t);s(30889);var i=s(93726);let n=s.n(i)()},69842:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(39383),a=s.n(t),i=s(55153);async function n(e,r,s,t){let n=a()({req:e,level:s?"deep":void 0}),o={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return t&&n.payload?.id&&(0,i._n)(process.env.DSQL_SU_USER_ID)!==n.payload.id?{user:null,appData:o}:{user:n.payload,appData:o}}},67619:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(29021),a=s.n(t);async function i({user:e,message:r,component:s,noMail:t,req:i}){let n=new Date,o=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],r=i.headers["x-real-ip"],s=i.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],a=s||t||r||i.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${s}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),i?.url&&(t+=`
URL: ${i.url}`),i?.body&&(t+=`
Request Body: ${JSON.stringify(i.body,null,4)}`),o&&(t+=`
IP: ${o}`),t+=`
Date: ${n.toDateString()}
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let _=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",t),a().appendFileSync("./.tmp/error.log",`




${_}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(7447);async function a(...e){let r=(0,t.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(9973),a=s.n(t);function i(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=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,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=r(r.s=12057);module.exports=s})();