dsql-admin/dsql-app/.local_dist/server/pages/api/deleteApiKey.js

16 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=7015,e.ids=[7015],e.modules={27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},5261:(e,r,t)=>{t.r(r),t.d(r,{config:()=>h,default:()=>E,routeModule:()=>A});var a={};t.r(a),t.d(a,{default:()=>y});var i=t(89947),s=t(2706),n=t(96762),l=t(72907),o=t.n(l),u=t(77538),c=t.n(u),d=t(6420),p=t.n(d);t(47670);var f=t(64122),g=t.n(f),m=t(77619),_=t.n(m);let S=t(29021);async function y(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await p()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{id:a,key:i,user_id:s}=e.body;try{let e=process.env.DSQL_API_KEYS_PATH;if(!e)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let s=_()({key:String(o()(i)),user_id:t.id});if(!s?.sign)throw await g()({dbFullName:"datasquirel",tableName:"api_keys",identifierColumnName:"id",identifierValue:a}),Error("API KEY is Invalid");try{let r=`${e}/${s?.sign}`;S.unlinkSync(r)}catch(e){console.log("Error Deleting API key",e.message)}await g()({dbFullName:"datasquirel",tableName:"api_keys",identifierColumnName:"id",identifierValue:a}),r.json({success:!0})}catch(e){console.log(`ERROR Deleting API Key => ${e.message}`),c()({component:"/api/deleteApiKey/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Deletion Failed!"})}}let E=(0,n.M)(a,"default"),h=(0,n.M)(a,"config"),A=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/deleteApiKey",pathname:"/api/deleteApiKey",bundlePath:"",filename:""},userland:a})},77538:(e,r,t)=>{let a=t(29021),{IncomingMessage:i}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:i,req:s}){let n=new Date,l=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||a||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let i=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),s?.url&&(i+=`
URL: ${s.url}`),s?.body&&(i+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(i+=`
IP: ${l}`),i+=`
Date: ${n.toDateString()}
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let o=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",i),a.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let a=t(51348),i=t(72907),s=t(29021);async function n(e,r,t,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let l=i(e.cookies.datasquirelAuthKey);if(!l)return null;let o=JSON.parse(l);if(!o.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${o.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&&!s.existsSync(`${u}/${o.csrf_k}`))return null;if(0==o.verification_status&&!t){let e=await a(`SELECT verification_status FROM users WHERE id='${o.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return o?.date&&Date.now()-o.date>6048e5?null:o}e.exports=n},77619:(e,r,t)=>{let a=t(29021),i=t(72907);e.exports=({key:e,database:r,table:t,user_id:s})=>{if(!e||!s)return null;try{let n=process.env.DSQL_API_KEYS_PATH;if(!n)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let l=i(e),o=JSON.parse(l||""),u=a.existsSync(`${n}/${o.sign}`);if(String(o.user_id)!==String(s)||!u)return null;if(!o.target_database)return o;if(!r&&o.target_database)return null;let c=o.target_database?.split(",").includes(String(r));if(c&&!o.target_table)return o;if(c&&!t&&o.target_table)return null;if(o.target_table?.split(",").includes(String(t)))return o;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},64122:(e,r,t)=>{let a=t(51348),i=t(21339);async function s({dbContext:e,paradigm:r,dbFullName:t,tableName:s,identifierColumnName:n,identifierValue:l}){try{let o=!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),u=o?a:i,c=`DELETE FROM ${s} WHERE \`${n}\`=?`;return o?await u(c,[l]):await u({paradigm:r,queryString:c,database:t,queryValues:[l]})}catch(e){return null}}e.exports=s},72907:(e,r,t)=>{let{scryptSync:a,createDecipheriv:i}=t(55511),{Buffer:s}=t(79428);e.exports=e=>{let r=i("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),s.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[4050],()=>t(5261));module.exports=a})();