"use strict";(()=>{var e={};e.id=7539,e.ids=[7539],e.modules={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")},33873:e=>{e.exports=require("path")},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}}})},68084:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>S,routeModule:()=>m});var n={};t.r(n),t.d(n,{default:()=>g});var i=t(89947),s=t(2706),o=t(96762),a=t(29021),l=t.n(a),c=t(67619),u=t(56081),d=t(95969),p=t(33873),f=t.n(p);async function g(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=e.body,{url:n,key:i,database:s,dbSchema:o,type:a}=t;try{let e=(0,u.A)({key:i,database:s?.db_slug,user_id:t.user_id});if(!e?.user_id)throw Error("Api Credentials invalid!");let n=(0,d.A)({encryptedString:i}),{user_id:o,full_access:a,csrf:c}=n?JSON.parse(n):null;if(!a||!c)return r.json({success:!1,msg:"Unauthorized"});let p=f().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${o}`,"main.json");if(!l().existsSync(p))throw Error("User Shcema data file doesn't exist!");let g=JSON.parse(l().readFileSync(p,"utf-8"));r.json({success:!0,payload:g})}catch(e){console.log("Connect Verification Error, =>",e.message),(0,c.A)({component:"/api/connect/main-catch-error",message:e.message}),r.json({success:!1,msg:"Connect Verification Operation Failed!"})}}let S=(0,o.M)(n,"default"),_=(0,o.M)(n,"config"),m=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/connect",pathname:"/api/connect",bundlePath:"",filename:""},userland:n})},56081:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),i=t.n(n),s=t(95969);let o=({key:e,database:r,table:t,user_id:n,media:o})=>{if(!e||!n)return null;try{let a=process.env.DSQL_API_KEYS_PATH;if(!a)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let l=(0,s.A)({encryptedString:e}),c=JSON.parse(l||""),u=i().existsSync(`${a}/${c.sign}`);if(String(c.user_id)!==String(n)||!u)return null;if(!c.target_database||o)return c;if(!r&&c.target_database)return null;let d=c.target_database?.split(",").includes(String(r));if(d&&!c.target_table)return c;if(d&&!t&&c.target_table)return null;if(c.target_table?.split(",").includes(String(t)))return c;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),{error:`api-cred ERROR: ${e.message}`}}}},67619:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(29021),i=t.n(n);async function s({user:e,message:r,component:t,noMail:n,req:s}){let o=new Date,a=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||n||r||s.socket.remoteAddress;if(!i)return null;return String(i)}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}`),s?.url&&(n+=`
URL: ${s.url}`),s?.body&&(n+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),a&&(n+=`
IP: ${a}`),n+=`
Date: ${o.toDateString()}
========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let l=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",n),i().appendFileSync("./.tmp/error.log",`




${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(55511),i=t(79428),s=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:a,keyLen:l,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,n.scryptSync)(o,a,l),p=i.Buffer.alloc(u,0),f=(0,n.createDecipheriv)(c,d,p);try{let r=f.update(e,"hex","utf8");return r+=f.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},31542:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(82535);function i(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=68084);module.exports=t})();