1 line
7.1 KiB
JavaScript
1 line
7.1 KiB
JavaScript
"use strict";exports.id=1251,exports.ids=[1251],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}}})},98e3:(e,t,r)=>{r.d(t,{A:()=>d});var n=r(72583),a=r.n(n),o=r(92652),s=r(30802),l=r(48786),c=r(37275),i=r(68829),u=r(7971);async function d({dbContext:e,paradigm:t,dbFullName:r,tableName:n,data:d,tableSchema:p,duplicateColumnName:f,duplicateColumnValue:_,update:g,encryptionKey:h,encryptionSalt:y,useLocal:S}){let E=!!S||!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),m=S?u.A:E?l.A:c.default;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,f&&"string"==typeof f){let a=E?await m(`SELECT * FROM \`${n}\` WHERE \`${f}\`=?`,[_]):await m({paradigm:"Read Only",queryString:`SELECT * FROM \`${r}\`.\`${n}\` WHERE \`${f}\`=?`,queryValues:[_]});if(a?.[0]&&!g)return null;if(a&&a[0]&&g)return await (0,s.A)({dbContext:e,paradigm:t,dbFullName:r,tableName:n,data:d,tableSchema:p,encryptionKey:h,encryptionSalt:y,identifierColumnName:f,identifierValue:_||""})}let D=Object.keys(d),A=[],N=[];for(let e=0;e<D.length;e++)try{let t=D[e],r=d?.[t],n=p?p?.fields?.filter(e=>e.fieldName==t):null,s=n&&n[0]?n[0]:null;if(null==r||void 0==r||s?.dataType?.match(/int$/i)&&"string"==typeof r&&!r?.match(/./))continue;s?.encrypted&&(r=(0,i.default)({data:r,encryptionKey:h,encryptionSalt:y}),console.log("DSQL: Encrypted value =>",r));let l=/<[^>]+>/g;(s?.richText||String(r).match(l))&&(r=a()(r,o.A)),s?.pattern&&!new RegExp(s.pattern,s.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),A.push("`"+t+"`"),"object"==typeof r&&(r=JSON.stringify(r)),"number"==typeof r?N.push(String(r)):N.push(r)}catch(e){console.log("DSQL: Error in parsing data keys =>",e.message);continue}d?.date_created||(A.push("`date_created`"),N.push(Date())),d?.date_created_code||(A.push("`date_created_code`"),N.push(Date.now())),d?.date_updated||(A.push("`date_updated`"),N.push(Date())),d?.date_updated_code||(A.push("`date_updated_code`"),N.push(Date.now()));let L=`INSERT INTO \`${r}\`.\`${n}\` (${A.join(",")}) VALUES (${N.map(()=>"?").join(",")})`;return E?await m(L,N):await m({paradigm:t,queryString:L,queryValues:N})}},30802:(e,t,r)=>{r.d(t,{A:()=>u});var n=r(72583),a=r.n(n),o=r(92652),s=r(48786),l=r(37275),c=r(68829),i=r(7971);async function u({dbContext:e,paradigm:t,dbFullName:r,tableName:n,data:u,tableSchema:d,identifierColumnName:p,identifierValue:f,encryptionKey:_,encryptionSalt:g,useLocal:h}){if(!u||!Object.keys(u).length)return null;let y=!!h||!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),S=h?i.A:y?s.A:l.default,E=Object.keys(u),m=[],D=[];for(let e=0;e<E.length;e++)try{let t=E[e],r=u[t],n=d?d?.fields?.filter(e=>e.fieldName===t):null,s=n&&n[0]?n[0]:null;if(null==r||void 0==r)continue;let l=/<[^>]+>/g;(s?.richText||String(r).match(l))&&(r=a()(r,o.A)),s?.encrypted&&(r=(0,c.default)({data:r,encryptionKey:_,encryptionSalt:g})),"object"==typeof r&&(r=JSON.stringify(r)),s?.pattern&&!new RegExp(s.pattern,s.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"}}),m.push(`\`${t}\`=?`),"number"==typeof r?D.push(String(r)):D.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}m.push(`date_updated='${Date()}'`),m.push(`date_updated_code='${Date.now()}'`);let A=`UPDATE \`${r}\`.\`${n}\` SET ${m.join(",")} WHERE \`${p}\`=?`;return D.push(f),y?await S(A,D):await S({paradigm:t,queryString:A,queryValues:D})}},92652:(e,t,r)=>{r.d(t,{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"]}}},68829:(e,t,r)=>{r.r(t),r.d(t,{default:()=>o});var n=r(55511),a=r(79428);function o({data:e,encryptionKey:t,encryptionSalt:r}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let o=t||process.env.DSQL_ENCRYPTION_PASSWORD,s=r||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!s?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let c=(0,n.scryptSync)(o,s,l),i=a.Buffer.alloc(16,0),u=(0,n.createCipheriv)("aes-192-cbc",c,i);try{let t=u.update(e,"utf8","hex");return t+=u.final("hex")}catch(t){return console.log("Error in encrypting =>",t.message),e}}},48786:(e,t,r)=>{r.d(t,{A:()=>n});async function n(...e){let t=global.DSQL_DB_CONN;try{if(!t)throw Error("No Connection provided to DB_HANDLER function!");let r=await t.query(...e);return JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await t?.end()}}},37275:(e,t,r)=>{async function n(e,t,r){try{if("string"==typeof t){let n=await e.query(a(t),r);return JSON.parse(JSON.stringify(n))}if("object"!=typeof t)return null;{let r=[];for(let n=0;n<t.length;n++)try{let o=t[n],s=await e.query(a(o.query),o.values);r.push(JSON.parse(JSON.stringify(s)))}catch(e){r.push(null)}return r}}catch(e){return null}finally{e.end()}}function a(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}async function o({paradigm:e,queryString:t,queryValues:r}){try{switch(e){case"Read Only":return await n(global.DSQL_READ_ONLY_DB_CONN,t,r);case"Full Access":case"FA":return await n(global.DSQL_FULL_ACCESS_DB_CONN,t,r);default:return null}}catch(e){return console.log(`DSQL_USER_DB_HANDLER Error: ${e.message}`),null}}r.r(t),r.d(t,{default:()=>o})},7971:(e,t,r)=>{r.d(t,{A:()=>l});var n=r(9973),a=r.n(n),o=r(29021),s=r.n(o);async function l(...e){let t=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 t=`${e}/ca-cert.pem`;if(!s().existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s().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 r=await t.query(...e);return await t.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}},2706:(e,t)=>{Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}});var r=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,t,r)=>{e.exports=r(75600)}}; |