"use strict";exports.id=2984,exports.ids=[2984],exports.modules={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}}})},31495:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(48786),o=t(67619);async function s({user:e,confirmedDelegetedUser:r,database:t,table:s,priviledgeRegex:a,dbId:l}){let i,c;try{r?.delegated?(i=await (0,n.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,s]),c=i[0]?.priviledge?.match(a)):(i=await (0,n.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,s,l]),c=!0)}catch(r){(0,o.A)({component:"checkUserRights",message:r.message,user:e})}return!!i&&!!i[0]&&!!c}},60125:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(95969);async function o({request:e,databaseSlug:r,user:t,query:o}){try{let s=t.id,a=null;if(!o?.delegated)return{dbUserId:s};let l=o.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,n.A)({encryptedString:e.cookies[c]});if(!t)throw Error("Invalid Token");if((a=JSON.parse(t)).databaseSlug===r)return{dbUserId:s=a.rootUserId,rootUserId:a.rootUserId,rootUserName:a.rootUserName,rootUserEmail:a.rootUserEmail,rootUserImage:a.rootUserImage,databaseFullName:a.databaseFullName,databaseSlug:a.databaseSlug,allowedTables:a.allowedTables,priviledges:a.priviledges,database:a.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:s}}catch(e){return null}}},41520:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(64292),o=t(7447);async function s({paradigm:e,queryString:r,queryValues:t}){let s="Read Only"==e?(0,o.A)({ro:!0}):(0,o.A)({fa:!0});try{return await (0,n.A)(s,r,t)}catch(e){return console.log(`DSQL_USER_DB_HANDLER Error: ${e.message}`),null}finally{s?.end()}}async function a({dbName:e,entryId:r,entryOrder:t,tableName:n,tableSchema:o}){try{if(o.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let e=await s({paradigm:"Full Access",queryString:`SELECT * FROM ${n} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!e?.[0])throw Error("No Existing Order");await s({paradigm:"Full Access",queryString:`UPDATE ${n} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${t} AND id != ?`,queryValues:[String(r)]})}return!0}catch(e){return!1}}},69842:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(39383),o=t.n(n);async function s(e,r,t){return o()({req:e,level:t?"deep":void 0}).payload}},30802:(e,r,t)=>{t.d(r,{A:()=>c});var n=t(72583),o=t.n(n),s=t(92652),a=t(68829),l=t(52939),i=t(64292);async function c({dbContext:e,dbFullName:r,tableName:t,data:n,tableSchema:c,identifierColumnName:u,identifierValue:d,encryptionKey:_,encryptionSalt:S,forceLocal:p}){if(!n||!Object.keys(n).length)return null;let D=!!p||(0,l.A)({dbContext:e,dbFullName:r}),g=D?global.DSQL_DB_CONN:global.DSQL_FULL_ACCESS_DB_CONN||global.DSQL_DB_CONN;D?global.DSQL_DB_CONN:global.DSQL_READ_ONLY_DB_CONN||global.DSQL_DB_CONN;let f=Object.keys(n),E=[],y=[];for(let e=0;ee.fieldName===r):null,i=l&&l[0]?l[0]:null;if(null==t||void 0==t)continue;let u=/<[^>]+>/g;(i?.richText||String(t).match(u))&&(t=o()(t,s.A)),i?.encrypted&&(t=(0,a.A)({data:t,encryptionKey:_,encryptionSalt:S})),"object"==typeof t&&(t=JSON.stringify(t)),i?.pattern&&!new RegExp(i.pattern,i.patternFlags||"").test(t)&&(console.log("DSQL: Pattern not matched =>",t),t=""),"string"==typeof t&&t.match(/^null$/i)&&(t={toSqlString:function(){return"NULL"}}),"string"!=typeof t||t.match(/./i)||(t={toSqlString:function(){return"NULL"}}),E.push(`\`${r}\`=?`),"number"==typeof t?y.push(String(t)):y.push(t)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}E.push(`date_updated='${Date()}'`),E.push(`date_updated_code='${Date.now()}'`);let A=`UPDATE ${D?"":`\`${r}\`.`}\`${t}\` SET ${E.join(",")} WHERE \`${u}\`=?`;return y.push(d),await (0,i.A)(g,A,y)}},92652:(e,r,t)=>{t.d(r,{A:()=>n});let n={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"]}}},67619:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(29021),o=t.n(n);async function s({user:e,message:r,component:t,noMail:n,req:s}){let a=new Date,l=(()=>{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],o=t||n||r||s.socket.remoteAddress;if(!o)return null;return String(o)}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)}`),l&&(n+=` IP: ${l}`),n+=` Date: ${a.toDateString()} ========================================`,o().existsSync("./.tmp/error.log")||o().writeFileSync("./.tmp/error.log","","utf-8");let i=o().readFileSync("./.tmp/error.log","utf-8");o().writeFileSync("./.tmp/error.log",n),o().appendFileSync("./.tmp/error.log",` ${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(55511),o=t(79428),s=t(31542);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:a,salt:l,keyLen:i,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,n.scryptSync)(a,l,i),_=o.Buffer.alloc(u,0),S=(0,n.createDecipheriv)(c,d,_);try{let r=S.update(e,"hex","utf8");return r+=S.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(55511),o=t(79428),s=t(31542);function a({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:a,salt:l,keyLen:i,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!a?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let d=(0,n.scryptSync)(a,l,i),_=o.Buffer.alloc(u,0),S=(0,n.createCipheriv)(c,d,_);try{let r=S.update(e,"utf8","hex");return r+=S.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(7447);async function o(...e){let r=(0,n.A)();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()}}},52939:(e,r,t)=>{t.d(r,{A:()=>n});function n({dbContext:e,dbFullName:r}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!r||!!r.match(/^datasquirel$/))}},64292:(e,r,t)=>{async function n(e,r,t){try{if(!e)throw Error("No Connection Found!");if(!r)throw Error("Query String Required!");if("string"==typeof r){let n=await e.query(o(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;nn})},7447:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(9973),o=t.n(n);function s(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||o()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||o()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||o()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||o()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},31542:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(82535);function o(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)}};