dsql-admin/dsql-app/.local_dist/server/chunks/8540.js

16 lines
6.1 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";exports.id=8540,exports.ids=[8540],exports.modules={77619:(e,t,r)=>{let a=r(29021),l=r(72835);e.exports=({key:e,database:t,table:r,user_id:n})=>{if(!e||!n)return null;try{let s=process.env.DSQL_API_KEYS_PATH;if(!s)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let i=l({encryptedString:e}),o=JSON.parse(i||""),u=a.existsSync(`${s}/${o.sign}`);if(String(o.user_id)!==String(n)||!u)return null;if(!o.target_database)return o;if(!t&&o.target_database)return null;let c=o.target_database?.split(",").includes(String(t));if(c&&!o.target_table)return o;if(c&&!r&&o.target_table)return null;if(o.target_table?.split(",").includes(String(r)))return o;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},64122:(e,t,r)=>{let a=r(51348),l=r(21339),n=r(44900);async function s({dbContext:e,paradigm:t,dbFullName:r,tableName:s,identifierColumnName:i,identifierValue:o,useLocal:u}){try{let c=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),d=u?n:c?a:l,p=`DELETE FROM ${s} WHERE \`${i}\`=?`;return c?await d(p,[o]):await d({paradigm:t,queryString:p,database:r,queryValues:[o]})}catch(e){return null}}e.exports=s},8238:(e,t,r)=>{r(29021);let a=r(44900),l=r(94709),n=r(96064),s=r(48225),i=r(47670),o=r(33364),u=r(64122),c=r(6061),d=r(33872);async function p({dbFullName:e,query:t,readOnly:r,dbSchema:p,queryValuesArray:m,tableName:g,local:f}){let y,b,_;if(p)try{let e=g||("string"==typeof t?null:t?t?.table:null);if(!e)throw Error("No table name provided");_=p.tables.filter(t=>t?.tableName===e)[0]}catch(e){}try{if("string"==typeof t){let s=d(t);if(r&&s.match(/^alter|^delete|information_schema|databases|^create/i))throw Error("Wrong Input!");if(f){console.log("Using Local ...");let e=await a(s,m);y=_?c({unparsedResults:e,tableSchema:_}):e}else y=r?await n({queryString:s,queryValuesArray:m?.map(e=>String(e)),database:e,tableSchema:_}):await l({queryString:s,queryValuesArray:m?.map(e=>String(e)),database:e,tableSchema:_})}else if("object"==typeof t){let{data:r,action:a,table:l,identifierColumnName:n,identifierValue:s,update:c,duplicateColumnName:d,duplicateColumnValue:p}=t;switch(a.toLowerCase()){case"insert":y=await i({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:l,data:r,update:c,duplicateColumnName:d,duplicateColumnValue:p,tableSchema:_}),y?.insertId||(b=Error("Couldn't insert data"));break;case"update":y=await o({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:l,data:r,identifierColumnName:n,identifierValue:s,tableSchema:_});break;case"delete":y=await u({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:l,identifierColumnName:n,identifierValue:s,tableSchema:_});break;default:y=null}}}catch(e){s({component:"functions/backend/runQuery",message:e.message}),y=null,e=e.message}return{result:y,error:b}}e.exports=p},30003:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},94709:(e,t,r)=>{let a=r(21339),l=r(6061),n=r(48225);e.exports=async function({queryString:e,database:t,tableSchema:r,queryValuesArray:s,local:i}){let o;try{o=await a({paradigm:"Full Access",database:t,queryString:e,queryValues:s})}catch(e){return n({component:"fullAccessDbHandler",message:e.message}),e.message}if(o&&r){let e=o;return await l({unparsedResults:e,tableSchema:r})}return o||null}},6061:(e,t,r)=>{let a=r(72835),l=r(30003);e.exports=async function({unparsedResults:e,tableSchema:t}){let r=[];try{for(let n=0;n<e.length;n++){let s=e[n],i=Object.keys(s);for(let e=0;e<i.length;e++){let r=i[e],n=t?.fields[e];if(r?.match(l))continue;let o=s[r];("number"==typeof o||o)&&n?.encrypted&&o?.match(/./)&&(s[r]=a({encryptedString:o}))}r.push(s)}return r}catch(t){return console.log("ERROR in parseDbResults Function =>",t.message),e}}},48225:(e,t,r)=>{let a=r(29021),{IncomingMessage:l}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:l,req:n}){let s=new Date,i=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],t=n.he
Error Message: ${t}
Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(l+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),n?.url&&(l+=`
URL: ${n.url}`),n?.body&&(l+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),i&&(l+=`
IP: ${i}`),l+=`
Date: ${s.toDateString()}
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let o=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",l),a.appendFileSync("./.tmp/error.log",`
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},96064:(e,t,r)=>{r(29021);let a=r(48225),l=r(6061),n=r(21339);e.exports=async function({queryString:e,database:t,queryValuesArray:r,tableSchema:s}){let i;try{i=await n({paradigm:"Read Only",database:t,queryString:e,queryValues:r})}catch(e){return a({component:"varReadOnlyDatabaseDbHandler",message:e.message,noMail:!0}),e.message}if(!i)return null;{let e=i;return await l({unparsedResults:e,tableSchema:s})}}},72835:(e,t,r)=>{let{scryptSync:a,createDecipheriv:l}=r(55511),{Buffer:n}=r(79428);e.exports=({encryptedString:e,encryptionKey:t,encryptionSalt:r})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let s=t||process.env.DSQL_ENCRYPTION_PASSWORD,i=r||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!s?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=l("aes-192-cbc",a(s,i,o),n.alloc(16,0));try{let t=u.update(e,"hex","utf8");return t+=u.final("utf8")}catch(t){return console.log("Error in decrypting =>",t.message),e}}},33872:(e,t,r)=>{r(55591),r(81630),e.exports=function(e){return e.replace(/\n|\r|\n\r|\r\n/gm," ").replace(/ {2,}/g," ").trim()}}};