dsql-admin/dsql-app/.local_dist/server/pages/api/deleteDbUser.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

13 lines
6.3 KiB
JavaScript

"use strict";(()=>{var e={};e.id=7081,e.ids=[7081],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,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},80061:(e,t,r)=>{r.r(t),r.d(t,{config:()=>_,default:()=>d,routeModule:()=>S});var s={};r.r(s),r.d(s,{default:()=>p});var a=r(89947),n=r(2706),o=r(96762),c=r(57638),i=r.n(c),u=r(6420),l=r.n(u);async function p(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});if(!await l()(e,t,!0))return t.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,userId:s}=e.body;await i()({database:r,queryString:"DELETE FROM users WHERE id = ?",queryValuesArray:[s]}),t.json({success:!0,msg:"User Deleted!"})}r(29021);let d=(0,o.M)(s,"default"),_=(0,o.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/deleteDbUser",pathname:"/api/deleteDbUser",bundlePath:"",filename:""},userland:s})},6420:(e,t,r)=>{r(81630);let s=r(51348),a=r(72907),n=r(29021);async function o(e,t,r,o){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let c=a(e.cookies.datasquirelAuthKey);if(!c)return null;let i=JSON.parse(c);if(!i.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${i.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(r&&!n.existsSync(`${u}/${i.csrf_k}`))return null;if(0==i.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${i.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return i?.date&&Date.now()-i.date>6048e5?null:i}e.exports=o},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:a}=r(55511),{Buffer:n}=r(79428);e.exports=e=>{let t=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},30003:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},6061:(e,t,r)=>{let s=r(72907),a=r(30003);e.exports=async function({unparsedResults:e,tableSchema:t}){let r=[];try{for(let n=0;n<e.length;n++){let o=e[n],c=Object.keys(o);for(let e=0;e<c.length;e++){let r=c[e],n=t?.fields[e];if(r?.match(a))continue;let i=o[r];("number"==typeof i||i)&&n?.encrypted&&i?.match(/./)&&(o[r]=s(i))}r.push(o)}return r}catch(t){return console.log("ERROR in parseDbResults Function =>",t.message),e}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:a}){let n=`🚀 SERVER ERROR ===========================
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}
Error Message: ${t}
Component: ${r}
Date: ${Date()}
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
${o}`)}},57638:(e,t,r)=>{r(29021);let s=r(6061),a=r(48225),n=r(51348),o=r(21339);e.exports=async function({queryString:e,queryValuesArray:t,database:r,tableSchema:c}){let i;let u=!!r?.match(/^datasquirel$/),l=u?n:o;try{i=e&&t&&Array.isArray(t)&&t[0]?u?await l(e,t):await l({paradigm:"Full Access",database:r,queryString:e,queryValues:t}):u?await l(e):await l({paradigm:"Full Access",database:r,queryString:e})}catch(e){a({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(i&&c)try{let e=i;return await s({unparsedResults:e,tableSchema:c})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",r,e),a({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(i)return i;else return null}},51348:(e,t,r)=>{let s=r(9973),a=r(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):void 0,charset:"utf8mb4",ssl:a()}});async function o(...e){try{let t=await n.query(...e);return await n.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21339:(e,t,r)=>{let s=r(29021);r(33873);let a=r(9973),n=r(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:t,queryString:r,queryValues:c}){try{return new Promise((i,u)=>{let l=!!e?.match(/full.access|^fa$/i);try{function p(e){o.end(),i(JSON.parse(JSON.stringify(e)))}function d(e){o.end(),i({error:e.message,queryStringGenerated:r,queryValuesGenerated:c,sql:e.sql})}o=l?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:t,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:t,ssl:n()}}),c&&Array.isArray(c)&&c[0]?o.query(r,c).then(p).catch(d):o.query(r).then(p).catch(d)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),i({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,t,r)=>{let s=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,t)=>{var r;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,t,r)=>{e.exports=r(75600)}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=t(t.s=80061);module.exports=r})();