"use strict";(()=>{var e={};e.id=8932,e.ids=[8932],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}}})},36629:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>_,routeModule:()=>p});var a={};t.r(a),t.d(a,{default:()=>d});var s=t(89947),n=t(2706),o=t(96762),l=t(69842),i=t(67619),c=t(60125),u=t(30944);async function d(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let a=e.body;try{let s=await (0,c.A)({databaseSlug:a.dbName,request:e,user:t,query:e.query}),n=s?s?.rootUserId?s.rootUserId:s.dbUserId:null;if(!n)throw Error("User not Found!");let o=`datasquirel_user_${n}_${a.dbName}`,l=a.tableName,i=a.page,d=20*i,_=`SELECT * FROM ${o}.${l}`,f=[];a.search&&a.searchField&&(_+=` WHERE LOWER(\`${a.searchField.toLowerCase().replace(/ /g,"_")}\`) LIKE ?`,f.push(`%${a.search.toLowerCase()}%`)),_+=` ORDER BY id DESC LIMIT 20 OFFSET ${d}`;let p=await (0,u.A)({database:o,queryString:_,queryValuesArray:f,tableSchema:a.tableSchema}),S={success:!0,data:p,page:Number(i)+1};r.json(S)}catch(e){(0,i.default)({component:"/api/infiniteScroll/catch-error",message:e.message,user:t}),r.json({success:!1,data:null})}}t(29021);let _=(0,o.M)(a,"default"),f=(0,o.M)(a,"config"),p=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/infiniteScroll",pathname:"/api/infiniteScroll",bundlePath:"",filename:""},userland:a})},60125:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(95969);async function s({request:e,databaseSlug:r,user:t,query:s}){try{let n=t.id,o=null;if(!s?.delegated)return{dbUserId:n};let l=s.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${l}_${r}`,c=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[c])throw Error("Cookie not present");let t=(0,a.A)({encryptedString:e.cookies[c]});if(!t)throw Error("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUserId:n=o.rootUserId,rootUserId:o.rootUserId,rootUserName:o.rootUserName,rootUserEmail:o.rootUserEmail,rootUserImage:o.rootUserImage,databaseFullName:o.databaseFullName,databaseSlug:o.databaseSlug,allowedTables:o.allowedTables,priviledges:o.priviledges,database:o.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:n}}catch(e){return null}}},69842:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(48786),s=t(95969),n=t(29021),o=t.n(n),l=t(89159);async function i(e,r,t){let{keyCookieName:n,csrfCookieName:i}=(0,l.A)();if(!e.cookies?.[n]?.match(/./))return null;let c=(0,s.A)({encryptedString:e.cookies[n]});if(!c)return null;let u=JSON.parse(c);if(!u.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!o().existsSync(`${d}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await (0,a.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}},89159:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),n&&(l+=`${n}_`),l+=a;let i=r;return e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),{keyCookieName:o,csrfCookieName:l,oneTimeCodeName:i+=s}}},43775:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(95969);let s=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function n({unparsedResults:e,tableSchema:r}){let t=[];try{for(let n=0;n",r.message),e}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>n});var a=t(29021),s=t.n(a);async function n({user:e,message:r,component:t,noMail:a,req:n}){let o=new Date,l=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||n.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),n?.url&&(a+=` URL: ${n.url}`),n?.body&&(a+=` Request Body: ${JSON.stringify(n.body,null,4)}`),l&&(a+=` IP: ${l}`),a+=` 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",a),s().appendFileSync("./.tmp/error.log",` ${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(43775),s=t(67619),n=t(48786),o=t(37275),l=t(7971);async function i({queryString:e,queryValuesArray:r,database:t,tableSchema:i,useLocal:c}){let u;let d=!!c||!!t?.match(/^datasquirel$/),_=c?l.A:d?n.A:o.default;try{u=e&&r&&Array.isArray(r)&&r[0]?d?await _(e,r):await _({paradigm:"Full Access",queryString:e,queryValues:r}):d?await _(e):await _({paradigm:"Full Access",queryString:e})}catch(e){console.log(`varDatabaseDbHandler Error: ${e.message}`),(0,s.default)({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(u&&i)try{let e=u;return await (0,a.A)({unparsedResults:e,tableSchema:i})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,s.default)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(u)return u;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(55511),s=t(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let i=(0,a.scryptSync)(n,o,l),c=s.Buffer.alloc(16,0),u=(0,a.createDecipheriv)("aes-192-cbc",i,c);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>a});async function a(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},37275:(e,r,t)=>{async function a(e,r,t){try{if("string"==typeof r){let a=await e.query(s(r),t);return JSON.parse(JSON.stringify(a))}if("object"!=typeof r)return null;{let t=[];for(let a=0;an})},7971:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(9973),s=t.n(a),n=t(29021),o=t.n(n);async function l(...e){let r=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:function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!o().existsSync(r)){console.log(`${r} does not exist`);return}return{ca:o().readFileSync(`${e}/ca-cert.pem`),rejectUnauthorized:!1}}()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let t=await r.query(...e);return await r.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}},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=36629);module.exports=t})();