"use strict";(()=>{var e={};e.id=964,e.ids=[964],e.modules={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")},79551:e=>{e.exports=require("url")},28354:e=>{e.exports=require("util")},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}}})},85617:(e,t,r)=>{r.r(t),r.d(t,{config:()=>m,default:()=>_,routeModule:()=>g});var s={};r.r(s),r.d(s,{default:()=>S});var n=r(89947),o=r(2706),a=r(96762),i=r(77538),c=r.n(i),l=r(6420),u=r.n(l),p=r(33364),d=r.n(p);r(29021),r(28354);let{URL:f}=r(79551);async function S(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await u()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{dbId:s}=e.body;try{if(!s)throw Error("No Target Database ID provided");await d()({tableName:"user_databases",data:{remote_connected:0,remote_connection_host:"",remote_connection_key:"",remote_connection_type:"",remote_db_full_name:""},identifierColumnName:"id",identifierValue:s}),t.json({success:!0})}catch(e){console.log("Disconnect Error, =>",e.message),c()({component:"/api/connect/verify/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Operation Failed!"})}}let _=(0,a.M)(s,"default"),m=(0,a.M)(s,"config"),g=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/connect/disconnect",pathname:"/api/connect/disconnect",bundlePath:"",filename:""},userland:s})},77538:(e,t,r)=>{let s=r(29021),{IncomingMessage:n}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:n,req:o}){let a=new Date,i=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],t=o.headers["x-real-ip"],r=o.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=r||s||t||o.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR =========================== Error Message: ${t} Component: ${r}`;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}`),o?.url&&(n+=` URL: ${o.url}`),o?.body&&(n+=` Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(n+=` IP: ${i}`),n+=` Date: ${a.toDateString()} ========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let c=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",` ${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let s=r(51348),n=r(72907),o=r(29021);async function a(e,t,r,a){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=n(e.cookies.datasquirelAuthKey);if(!i)return null;let c=JSON.parse(i);if(!c.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let l=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!l)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!o.existsSync(`${l}/${c.csrf_k}`))return null;if(0==c.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=a},33364:(e,t,r)=>{let s=r(82703),n=r(72583),o=r(16570),a=r(51348),i=r(21339);async function c({dbContext:e,paradigm:t,dbFullName:r,tableName:c,data:l,tableSchema:u,identifierColumnName:p,identifierValue:d,encryptionKey:f,encryptionSalt:S}){if(!l||!Object.keys(l).length)return null;let _=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),m=_?a:i,g=Object.keys(l),h=[],y=[];for(let e=0;ee.fieldName===t):null,i=a&&a[0]?a[0]:null;if(null==r||void 0==r)continue;i?.richText&&(r=n(r,o)),i?.encrypted&&(r=s(r,f,S)),"object"==typeof r&&(r=JSON.stringify(r)),i?.pattern&&!new RegExp(i.pattern,i.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),"string"==typeof r&&r.match(/^null$/i)&&(r={toSqlString:function(){return"NULL"}}),"string"!=typeof r||r.match(/./i)||(r={toSqlString:function(){return"NULL"}}),h.push(`\`${t}\`=?`),"number"==typeof r?y.push(String(r)):y.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}h.push(`date_updated='${Date()}'`),h.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE ${c} SET ${h.join(",")} WHERE \`${p}\`=?`;return y.push(d),_?await m(D,y):await m({paradigm:t,database:r,queryString:D,queryValues:y})}e.exports=c},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:n}=r(55511),{Buffer:o}=r(79428);e.exports=e=>{let t=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},82703:(e,t,r)=>{let{scryptSync:s,createCipheriv:n}=r(55511),{Buffer:o}=r(79428),a=r(48225);e.exports=(e,t,r)=>{let i=n("aes-192-cbc",s(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let t=i.update(e,"utf8","hex");return t+=i.final("hex")}catch(e){return a({component:"encrypt",message:e.message}),null}}},16570:e=>{e.exports={allowedTags:["b","i","em","strong","a","p","span","ul","ol","li","h1","h2","h3","h4","h5","h6","img","div","button","pre","code","br"],allowedAttributes:{a:["href"],img:["src","alt","width","height","class","style"],"*":["style","class"]}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:n}){let o=`🚀 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 a=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",o),s.appendFileSync("./.tmp/error.log",` ${a}`)}},51348:(e,t,r)=>{let s=r(9973),n=r(21580),o=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:n()}});async function a(...e){try{let t=await o.query(...e);return await o.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=a},21339:(e,t,r)=>{let s=r(29021);r(33873);let n=r(9973),o=r(21580),a=n({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:o()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:i}){try{return new Promise((c,l)=>{let u=!!e?.match(/full.access|^fa$/i);try{function p(e){a.end(),c(JSON.parse(JSON.stringify(e)))}function d(e){a.end(),c({error:e.message,queryStringGenerated:r,queryValuesGenerated:i,sql:e.sql})}a=u?n({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:o()}}):n({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:o()}}),i&&Array.isArray(i)&&i[0]?a.query(r,i).then(p).catch(d):a.query(r).then(p).catch(d)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),c({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=85617);module.exports=r})();