dsql-admin/dsql-app/.local_dist/server/pages/api/infiniteScroll.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

16 lines
9.9 KiB
JavaScript

"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 s={};t.r(s),t.d(s,{default:()=>d});var a=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 s=e.body;try{let a=await (0,c.A)({databaseSlug:s.dbName,request:e,user:t,query:e.query}),n=a?a?.rootUserId?a.rootUserId:a.dbUserId:null;if(!n)throw Error("User not Found!");let o=`datasquirel_user_${n}_${s.dbName}`,l=s.tableName,i=s.page,d=20*i,_=`SELECT * FROM ${o}.${l}`,f=[];s.search&&s.searchField&&(_+=` WHERE LOWER(\`${s.searchField.toLowerCase().replace(/ /g,"_")}\`) LIKE ?`,f.push(`%${s.search.toLowerCase()}%`)),_+=` ORDER BY id DESC LIMIT 20 OFFSET ${d}`;let p=await (0,u.A)({database:o,queryString:_,queryValuesArray:f,tableSchema:s.tableSchema}),E={success:!0,data:p,page:Number(i)+1};r.json(E)}catch(e){(0,i.A)({component:"/api/infiniteScroll/catch-error",message:e.message,user:t}),r.json({success:!1,data:null})}}let _=(0,o.M)(s,"default"),f=(0,o.M)(s,"config"),p=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/infiniteScroll",pathname:"/api/infiniteScroll",bundlePath:"",filename:""},userland:s})},60125:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(95969);async function a({request:e,databaseSlug:r,user:t,query:a}){try{let n=t.id,o=null;if(!a?.delegated)return{dbUserId:n};let l=a.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,s.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 s=t(48786),a=t(95969),n=t(29021),o=t.n(n),l=t(89159);async function i(e,r,t){try{let{keyCookieName:n,csrfCookieName:i}=(0,l.A)();if(!e.cookies?.[n]?.match(/./))throw Error("Request Cookies not Found!");let c=(0,a.A)({encryptedString:e.cookies[n]});if(!c)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(c);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!o().existsSync(`${d}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,s.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"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=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+=s;let i=r;return e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),{keyCookieName:o,csrfCookieName:l,oneTimeCodeName:i+=a}}},43775:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(95969);let a=/^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<e.length;n++){let o=e[n],l=Object.keys(o);for(let e=0;e<l.length;e++){let t=l[e],n=r?.fields[e];if(t?.match(a))continue;let i=o[t];("number"==typeof i||i)&&n?.encrypted&&i?.match(/./)&&(o[t]=(0,s.A)({encryptedString:i}))}t.push(o)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(29021),a=t.n(s);async function n({user:e,message:r,component:t,noMail:s,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"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),n?.url&&(s+=`
URL: ${n.url}`),n?.body&&(s+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),l&&(s+=`
IP: ${l}`),s+=`
Date: ${o.toDateString()}
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let i=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",s),a().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 s=t(43775),a=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.A;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,a.A)({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(u&&i)try{let e=u;return await (0,s.A)({unparsedResults:e,tableSchema:i})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,a.A)({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 s=t(55511),a=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,s.scryptSync)(n,o,l),c=a.Buffer.alloc(16,0),u=(0,s.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:()=>s});async function s(...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 s(e,r,t){try{if("string"==typeof r){let s=await e.query(a(r),t);return JSON.parse(JSON.stringify(s))}if("object"!=typeof r)return null;{let t=[];for(let s=0;s<r.length;s++)try{let n=r[s],o=await e.query(a(n.query),n.values);t.push(JSON.parse(JSON.stringify(o)))}catch(e){t.push(null)}return t}}catch(e){return null}finally{e.end()}}function a(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}async function n({paradigm:e,queryString:r,queryValues:t}){try{switch(e){case"Read Only":return await s(global.DSQL_READ_ONLY_DB_CONN,r,t);case"Full Access":case"FA":return await s(global.DSQL_FULL_ACCESS_DB_CONN,r,t);default:return null}}catch(e){return console.log(`DSQL_USER_DB_HANDLER Error: ${e.message}`),null}}t.d(r,{A:()=>n})},7971:(e,r,t)=>{t.d(r,{A:()=>l});var s=t(9973),a=t.n(s),n=t(29021),o=t.n(n);async function l(...e){let r=a()({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})();