"use strict";exports.id=4050,exports.ids=[4050],exports.modules={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}}})},47670:(e,t,r)=>{let a=r(82703),s=r(72583),n=r(16570);r(33364);let o=r(33364);r(27825);let c=r(51348),i=r(21339);async function l({dbContext:e,paradigm:t,dbFullName:r,tableName:l,data:d,tableSchema:u,duplicateColumnName:p,duplicateColumnValue:_,update:S,encryptionKey:f,encryptionSalt:h}){let m=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),g=m?c:i;if(d?.date_created_timestamp&&delete d.date_created_timestamp,d?.date_updated_timestamp&&delete d.date_updated_timestamp,d?.date_updated&&delete d.date_updated,d?.date_updated_code&&delete d.date_updated_code,d?.date_created&&delete d.date_created,d?.date_created_code&&delete d.date_created_code,p&&"string"==typeof p){let a=m?await g(`SELECT * FROM \`${l}\` WHERE \`${p}\`=?`,[_]):await g({paradigm:"Read Only",database:r,queryString:`SELECT * FROM \`${l}\` WHERE \`${p}\`=?`,queryValues:[_]});if(a?.[0]&&!S)return null;if(a&&a[0]&&S)return await o({dbContext:e,paradigm:t,dbFullName:r,tableName:l,data:d,tableSchema:u,encryptionKey:f,encryptionSalt:h,identifierColumnName:p,identifierValue:_||""})}let y=Object.keys(d),D=[],E=[];for(let e=0;ee.fieldName==t):null,c=o&&o[0]?o[0]:null;if(null==r||void 0==r||c?.dataType?.match(/int$/i)&&"string"==typeof r&&!r?.match(/./))continue;c?.encrypted&&(r=a(r,f,h),console.log("DSQL: Encrypted value =>",r)),c?.richText&&(r=s(r,n)),c?.pattern&&!new RegExp(c.pattern,c.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),D.push("`"+t+"`"),"object"==typeof r&&(r=JSON.stringify(r)),"number"==typeof r?E.push(String(r)):E.push(r)}catch(e){console.log("DSQL: Error in parsing data keys =>",e.message);continue}d?.date_created||(D.push("`date_created`"),E.push(Date())),d?.date_created_code||(D.push("`date_created_code`"),E.push(Date.now())),d?.date_updated||(D.push("`date_updated`"),E.push(Date())),d?.date_updated_code||(D.push("`date_updated_code`"),E.push(Date.now()));let L=`INSERT INTO \`${l}\` (${D.join(",")}) VALUES (${E.map(()=>"?").join(",")})`;return m?await g(L,E):await g({paradigm:t,database:r,queryString:L,queryValues:E})}e.exports=l},33364:(e,t,r)=>{let a=r(82703),s=r(72583),n=r(16570),o=r(51348),c=r(21339);async function i({dbContext:e,paradigm:t,dbFullName:r,tableName:i,data:l,tableSchema:d,identifierColumnName:u,identifierValue:p,encryptionKey:_,encryptionSalt:S}){if(!l||!Object.keys(l).length)return null;let f=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),h=f?o:c,m=Object.keys(l),g=[],y=[];for(let e=0;ee.fieldName===t):null,c=o&&o[0]?o[0]:null;if(null==r||void 0==r)continue;c?.richText&&(r=s(r,n)),c?.encrypted&&(r=a(r,_,S)),"object"==typeof r&&(r=JSON.stringify(r)),c?.pattern&&!new RegExp(c.pattern,c.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"}}),g.push(`\`${t}\`=?`),"number"==typeof r?y.push(String(r)):y.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}g.push(`date_updated='${Date()}'`),g.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE ${i} SET ${g.join(",")} WHERE \`${u}\`=?`;return y.push(p),f?await h(D,y):await h({paradigm:t,database:r,queryString:D,queryValues:y})}e.exports=i},82703:(e,t,r)=>{let{scryptSync:a,createCipheriv:s}=r(55511),{Buffer:n}=r(79428),o=r(48225);e.exports=(e,t,r)=>{let c=s("aes-192-cbc",a(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let t=c.update(e,"utf8","hex");return t+=c.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 a=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:s}){let n=`🚀 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()} ========================================`;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",n),a.appendFileSync("./.tmp/error.log",` ${o}`)}},51348:(e,t,r)=>{let a=r(9973),s=r(21580),n=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:s()}});async function o(...e){try{let t=await n.query(...e);return await n.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 a=r(29021);r(33873);let s=r(9973),n=r(21580),o=s({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:n()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:c}){try{return new Promise((i,l)=>{let d=!!e?.match(/full.access|^fa$/i);try{function u(e){o.end(),i(JSON.parse(JSON.stringify(e)))}function p(e){o.end(),i({error:e.message,queryStringGenerated:r,queryValuesGenerated:c,sql:e.sql})}o=d?s({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:n()}}):s({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:n()}}),c&&Array.isArray(c)&&c[0]?o.query(r,c).then(u).catch(p):o.query(r).then(u).catch(p)}catch(e){a.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),i({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,t,r)=>{let a=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!a.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:a.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)}};