"use strict";(()=>{var e={};e.id=8078,e.ids=[8078],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}}})},31483:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>p,routeModule:()=>D});var n={};t.r(n),t.d(n,{default:()=>d});var s=t(89947),a=t(2706),o=t(96762),l=t(67619),i=t(56081),u=t(61932),c=t(30944);async function _({dbFullName:e,deletedUserId:r}){let t=`SELECT * FROM ${e}.users WHERE id = ?`,n=await (0,c.A)({queryString:t,queryValuesArray:[r],database:e});return n?.[0]?{success:!0,result:await (0,u.A)({dbContext:"Dsql User",dbFullName:e,tableName:"users",identifierColumnName:"id",identifierValue:r})}:{success:!1,msg:"User not found"}}async function d(e,r){if("POST"!==e.method)return r.json({success:!1,payload:null,msg:"Failed!"});try{let t=e.headers.authorization,{deletedUserId:n,database:s}=e.body,a=(0,i.A)({key:t,database:s?.db_slug,user_id:String(e.query.user_id)});if(!a?.user_id)throw Error("Api Credentials invalid!");if(!a.full_access||!a.sign)return r.json({success:!1,msg:"Unauthorized"});let o=`datasquirel_user_${a.user_id}_${s}`,l=await _({dbFullName:o,deletedUserId:n});r.json(l)}catch(t){(0,l.A)({component:"/api/user/delete-user/main-catch-error",message:t.message,user:{},req:e}),r.json({success:!1,msg:"Wrong Credentials"})}}let p=(0,o.M)(n,"default"),S=(0,o.M)(n,"config"),D=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/user/[user_id]/delete-user",pathname:"/api/user/[user_id]/delete-user",bundlePath:"",filename:""},userland:n})},56081:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),s=t.n(n),a=t(95969);let o=({key:e,database:r,table:t,user_id:n,media:o})=>{if(!e||!n)return null;try{let l=process.env.DSQL_API_KEYS_PATH;if(!l)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let i=(0,a.A)({encryptedString:e}),u=JSON.parse(i||""),c=s().existsSync(`${l}/${u.sign}`);if(String(u.user_id)!==String(n)||!c)return null;if(!u.target_database||o)return u;if(!r&&u.target_database)return null;let _=u.target_database?.split(",").includes(String(r));if(_&&!u.target_table)return u;if(_&&!t&&u.target_table)return null;if(u.target_table?.split(",").includes(String(t)))return u;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),{error:`api-cred ERROR: ${e.message}`}}}},61932:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(52939),s=t(64292);async function a({dbContext:e,dbFullName:r,tableName:t,identifierColumnName:a,identifierValue:o,forceLocal:l}){try{let i=!!l||(0,n.A)({dbContext:e,dbFullName:r}),u=i?global.DSQL_DB_CONN:global.DSQL_FULL_ACCESS_DB_CONN||global.DSQL_DB_CONN;i?global.DSQL_DB_CONN:global.DSQL_READ_ONLY_DB_CONN||global.DSQL_DB_CONN;let c=`DELETE FROM ${i?"":`\`${r}\`.`}\`${t}\` WHERE \`${a}\`=?`;return await (0,s.A)(u,c,[o])}catch(e){return null}}},43775:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(95969);let s=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function a({unparsedResults:e,tableSchema:r}){let t=[];try{for(let a=0;a<e.length;a++){let o=e[a],l=Object.keys(o);for(let e=0;e<l.length;e++){let t=l[e],a=r?.fields[e];if(t?.match(s))continue;let i=o[t];("number"==typeof i||i)&&a?.encrypted&&i?.match(/./)&&(o[t]=(0,n.A)({encryptedString:i}))}t.push(o)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(29021),s=t.n(n);async function a({user:e,message:r,component:t,noMail:n,req:a}){let o=new Date,l=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||a.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),a?.url&&(n+=`
URL: ${a.url}`),a?.body&&(n+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),l&&(n+=`
IP: ${l}`),n+=`
Date: ${o.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let i=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",n),s().appendFileSync("./.tmp/error.log",`




${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>l});var n=t(43775),s=t(67619),a=t(7447),o=t(64292);async function l({queryString:e,queryValuesArray:r,database:t,tableSchema:l,debug:i}){let u=(0,a.A)({fa:!0});global.DSQL_USE_LOCAL&&(u=(0,a.A)({local:!0})),t?.match(/^datasquirel$/)&&(u=(0,a.A)()),i&&(console.log("varDatabaseDbHandler:query:",e),console.log("varDatabaseDbHandler:values:",r),console.log("varDatabaseDbHandler:CONNECTION:",u.getConfig()));let c=await (0,o.A)(u,e,r);if(i&&console.log("varDatabaseDbHandler:results:",c),c&&l)try{return await (0,n.A)({unparsedResults:c,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,s.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(c)return c;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(55511),s=t(79428),a=t(31542);function o({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:o,salt:l,keyLen:i,algorithm:u,bufferAllocSize:c}=(0,a.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let _=(0,n.scryptSync)(o,l,i),d=s.Buffer.alloc(c,0),p=(0,n.createDecipheriv)(u,_,d);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},52939:(e,r,t)=>{t.d(r,{A:()=>n});function n({dbContext:e,dbFullName:r}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!r||!!r.match(/^datasquirel$/))}},64292:(e,r,t)=>{async function n(e,r,t){try{if(!e)throw Error("No Connection Found!");if(!r)throw Error("Query String Required!");if("string"==typeof r){let n=await e.query(s(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;n<r.length;n++)try{let a=r[n],o=await e.query(s(a.query),a.values);t.push(JSON.parse(JSON.stringify(o)))}catch(e){console.log(`connDbHandler Query Error: ${e.message}`),t.push(null)}return t}}catch(r){return console.log(`connDbHandler Error: ${r.message}`),console.log(e?.config()),null}finally{e?.end()}}function s(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>n})},7447:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(9973),s=t.n(n);function a(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||s()({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||s()({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||s()({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||s()({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"}})}},31542:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(82535);function s(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?(0,n.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,t)=>{t.d(r,{A:()=>n});function n(e,r){try{let t=Number(e);if("number"!=typeof t||isNaN(t))return 0;if(r)return Number(t.toFixed(r));return Math.round(t)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}},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=31483);module.exports=t})();