"use strict";(()=>{var e={};e.id=7015,e.ids=[7015],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")},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}}})},33336:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>f,routeModule:()=>E});var n={};t.r(n),t.d(n,{default:()=>S});var a=t(89947),i=t(2706),s=t(96762),l=t(29021),o=t.n(l),u=t(95969),c=t(67619),d=t(69842),_=t(61932),p=t(56081);async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{user:t}=await (0,d.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{id:n,key:a,user_id:i}=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 i=(0,p.A)({key:String((0,u.A)({encryptedString:a})),user_id:t.id});if(!i?.sign)throw await (0,_.A)({dbFullName:"datasquirel",tableName:"api_keys",identifierColumnName:"id",identifierValue:n}),Error("API KEY is Invalid");try{let r=`${e}/${i?.sign}`;o().unlinkSync(r)}catch(e){console.log("Error Deleting API key",e.message)}await (0,_.A)({dbFullName:"datasquirel",tableName:"api_keys",identifierColumnName:"id",identifierValue:n}),r.json({success:!0})}catch(e){console.log(`ERROR Deleting API Key => ${e.message}`),(0,c.A)({component:"/api/deleteApiKey/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Deletion Failed!"})}}let f=(0,s.M)(n,"default"),g=(0,s.M)(n,"config"),E=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/deleteApiKey",pathname:"/api/deleteApiKey",bundlePath:"",filename:""},userland:n})},55153:(e,r,t)=>{t.d(r,{On:()=>a.a,_n:()=>s}),t(76102);var n=t(65967),a=t.n(n);t(30889);var i=t(93726);let s=t.n(i)()},69842:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(39383),a=t.n(n),i=t(55153);async function s(e,r,t,n){let s=a()({req:e,level:t?"deep":void 0}),l={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 n&&s.payload?.id&&(0,i._n)(process.env.DSQL_SU_USER_ID)!==s.payload.id?{user:null,appData:l}:{user:s.payload,appData:l}}},56081:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(29021),a=t.n(n),i=t(95969);let s=({key:e,database:r,table:t,user_id:n,media:s})=>{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 o=(0,i.A)({encryptedString:e}),u=JSON.parse(o||""),c=a().existsSync(`${l}/${u.sign}`);if(String(u.user_id)!==String(n)||!c)return null;if(!u.target_database||s)return u;if(!r&&u.target_database)return null;let d=u.target_database?.split(",").includes(String(r));if(d&&!u.target_table)return u;if(d&&!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:()=>i});var n=t(52939),a=t(64292);async function i({dbContext:e,dbFullName:r,tableName:t,identifierColumnName:i,identifierValue:s,forceLocal:l}){try{let o=!!l||(0,n.A)({dbContext:e,dbFullName:r}),u=o?global.DSQL_DB_CONN:global.DSQL_FULL_ACCESS_DB_CONN||global.DSQL_DB_CONN;o?global.DSQL_DB_CONN:global.DSQL_READ_ONLY_DB_CONN||global.DSQL_DB_CONN;let c=`DELETE FROM ${o?"":`\`${r}\`.`}\`${t}\` WHERE \`${i}\`=?`;return await (0,a.A)(u,c,[s])}catch(e){return null}}},67619:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(29021),a=t.n(n);async function i({user:e,message:r,component:t,noMail:n,req:i}){let s=new Date,l=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],r=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||n||r||i.socket.remoteAddress;if(!a)return null;return String(a)}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}`),i?.url&&(n+=`
URL: ${i.url}`),i?.body&&(n+=`
Request Body: ${JSON.stringify(i.body,null,4)}`),l&&(n+=`
IP: ${l}`),n+=`
Date: ${s.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",n),a().appendFileSync("./.tmp/error.log",`




${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(55511),a=t(79428),i=t(31542);function s({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:s,salt:l,keyLen:o,algorithm:u,bufferAllocSize:c}=(0,i.A)({encryptionKey:r});if(!s?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,n.scryptSync)(s,l,o),_=a.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(a(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 i=r[n],s=await e.query(a(i.query),i.values);t.push(JSON.parse(JSON.stringify(s)))}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 a(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>n})},31542:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(82535);function a(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=33336);module.exports=t})();