"use strict";(()=>{var e={};e.id=3683,e.ids=[3683],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")},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}}})},96016:(e,t,r)=>{r.r(t),r.d(t,{config:()=>f,default:()=>d,routeModule:()=>S});var s={};r.r(s),r.d(s,{default:()=>p});var n=r(89947),a=r(2706),o=r(96762),i=r(33364),c=r.n(i),u=r(6420),l=r.n(u);async function p(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});if(!await l()(e,t,!0))return t.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,payload:s}=e.body,n=(()=>{let e=Object.keys(s),t={};return e.forEach(e=>{!e?.match(/user_type|priviledge|database_access|databases?|confirm/)&&(e?.match(/databases|confirm/)||(t[e]=s[e]))}),t})(),a=await c()({dbFullName:r,tableName:"users",identifierColumnName:"id",identifierValue:s.id,data:{...n},dbContext:"Dsql User",paradigm:"Full Access"});t.json({success:!!a?.affectedRows,msg:a?.affectedRows?"User Updated":a})}let d=(0,o.M)(s,"default"),f=(0,o.M)(s,"config"),S=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateDbUser",pathname:"/api/updateDbUser",bundlePath:"",filename:""},userland:s})},6420:(e,t,r)=>{r(81630);let s=r(51348),n=r(72907),a=r(29021);async function o(e,t,r,o){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 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(r&&!a.existsSync(`${u}/${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=o},33364:(e,t,r)=>{let s=r(82703),n=r(72583),a=r(16570),o=r(51348),i=r(21339);async function c({dbContext:e,paradigm:t,dbFullName:r,tableName:c,data:u,tableSchema:l,identifierColumnName:p,identifierValue:d,encryptionKey:f,encryptionSalt:S}){if(!u||!Object.keys(u).length)return null;let _=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),h=_?o:i,m=Object.keys(u),D=[],g=[];for(let e=0;ee.fieldName===t):null,i=o&&o[0]?o[0]:null;if(null==r||void 0==r)continue;i?.richText&&(r=n(r,a)),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"}}),D.push(`\`${t}\`=?`),"number"==typeof r?g.push(String(r)):g.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}D.push(`date_updated='${Date()}'`),D.push(`date_updated_code='${Date.now()}'`);let y=`UPDATE ${c} SET ${D.join(",")} WHERE \`${p}\`=?`;return g.push(d),_?await h(y,g):await h({paradigm:t,database:r,queryString:y,queryValues:g})}e.exports=c},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:n}=r(55511),{Buffer:a}=r(79428);e.exports=e=>{let t=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.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:a}=r(79428),o=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),a.alloc(16,0));try{let t=i.update(e,"utf8","hex");return t+=i.final("hex")}catch(e){return o({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 a=`🚀 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 o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",` ${o}`)}},51348:(e,t,r)=>{let s=r(9973),n=r(21580),a=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 o(...e){try{let t=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21339:(e,t,r)=>{let s=r(29021);r(33873);let n=r(9973),a=r(21580),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,charset:"utf8mb4",ssl:a()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:i}){try{return new Promise((c,u)=>{let l=!!e?.match(/full.access|^fa$/i);try{function p(e){o.end(),c(JSON.parse(JSON.stringify(e)))}function d(e){o.end(),c({error:e.message,queryStringGenerated:r,queryValuesGenerated:i,sql:e.sql})}o=l?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: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,database:t,ssl:a()}}),i&&Array.isArray(i)&&i[0]?o.query(r,i).then(p).catch(d):o.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=96016);module.exports=r})();