1 line
8.2 KiB
JavaScript
1 line
8.2 KiB
JavaScript
"use strict";(()=>{var e={};e.id=4065,e.ids=[4065],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},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")},33873:e=>{e.exports=require("path")},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}}})},63177:(e,r,t)=>{t.r(r),t.d(r,{config:()=>h,default:()=>y,routeModule:()=>A});var n={};t.r(n),t.d(n,{default:()=>g});var a=t(89947),s=t(2706),o=t(96762),i=t(76856),l=t(29021),c=t.n(l),u=t(33873),d=t.n(u);let p=async({userId:e,dbSchema:r,targetDb:t})=>(await (0,i.A)({userId:e,targetDatabase:t}),`User ${e} Db Schema Updated`),_=async({userId:e,dbSchema:r,database:t})=>{let n=d().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),a=JSON.parse(c().readFileSync(n,"utf-8")),s=a.findIndex(e=>e.dbFullName==t.db_full_name);if(s<0)throw Error("Target Database not found in user schema data");let o={...a[s]};return a[s]=r,a[s].dbName=o.dbName,a[s].dbFullName=o.dbFullName,a[s].dbSlug=o.dbSlug,a[s].dbImage=o.dbImage,await p({dbSchema:a,userId:e,targetDb:t.db_full_name})};var f=t(67619),S=t(69842),m=t(30802);async function g(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,S.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{url:n,key:a,database:s,dbSchema:o,type:i,remoteDbs:l,targetDb:c}=e.body;try{if(!c?.tables)throw Error("No Target Database");await (0,m.A)({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:n,remote_connection_key:a,remote_connection_type:i,remote_db_full_name:c.dbFullName},identifierColumnName:"db_full_name",identifierValue:s.db_full_name}),await _({dbSchema:c,database:s,userId:t.id}),r.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),(0,f.A)({component:"/api/connect/verify/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Operation Failed!"})}}let y=(0,o.M)(n,"default"),h=(0,o.M)(n,"config"),A=new a.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:n})},69842:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(39908),a=t.n(n);async function s(e,r,t){let n=a()({req:e,level:t?"deep":void 0});return console.log(n),n.payload}},30802:(e,r,t)=>{t.d(r,{A:()=>u});var n=t(72583),a=t.n(n),s=t(92652),o=t(48786),i=t(37897),l=t(68829),c=t(62050);async function u({dbContext:e,paradigm:r,dbFullName:t,tableName:n,data:u,tableSchema:d,identifierColumnName:p,identifierValue:_,encryptionKey:f,encryptionSalt:S,useLocal:m}){if(!u||!Object.keys(u).length)return null;let g=!!m||!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),y=m?c.A:g?o.A:i.A,h=Object.keys(u),A=[],D=[];for(let e=0;e<h.length;e++)try{let r=h[e],t=u[r],n=d?d?.fields?.filter(e=>e.fieldName===r):null,o=n&&n[0]?n[0]:null;if(null==t||void 0==t)continue;let i=/<[^>]+>/g;(o?.richText||String(t).match(i))&&(t=a()(t,s.A)),o?.encrypted&&(t=(0,l.A)({data:t,encryptionKey:f,encryptionSalt:S})),"object"==typeof t&&(t=JSON.stringify(t)),o?.pattern&&!new RegExp(o.pattern,o.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"}}),A.push(`\`${r}\`=?`),"number"==typeof t?D.push(String(t)):D.push(t)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}A.push(`date_updated='${Date()}'`),A.push(`date_updated_code='${Date.now()}'`);let N=`UPDATE \`${t}\`.\`${n}\` SET ${A.join(",")} WHERE \`${p}\`=?`;return D.push(_),g?await y(N,D):await y({paradigm:r,queryString:N,queryValues:D})}},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"]}}},68829:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(55511),a=t(79428),s=t(32443);function o({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:o,salt:i,keyLen:l,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let d=(0,n.scryptSync)(o,i,l),p=a.Buffer.alloc(u,0),_=(0,n.createCipheriv)(c,d,p);try{let r=_.update(e,"utf8","hex");return r+=_.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(7447);async function a(...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()}}},37897:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(64292),a=t(7447);async function s({paradigm:e,queryString:r,queryValues:t}){let s="Read Only"==e?(0,a.A)({ro:!0}):(0,a.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()}}},62050:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(7447);async function a(...e){let r=(0,n.A)();console.log("Querying ...");try{let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}finally{await r?.end()}}},64292:(e,r,t)=>{async function n(e,r,t){try{if("string"==typeof r){let n=await e.query(a(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;n<r.length;n++)try{let s=r[n],o=await e.query(a(s.query),s.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()}t.d(r,{A:()=>n})},7447:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(9973),a=t.n(n);function s(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||a()({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||a()({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||a()({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"}})}},32443:(e,r,t)=>{t.d(r,{A:()=>n});function n(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?function(e,r){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;return Math.round(r)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},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=e=>r(r.s=e),n=r.X(0,[9814],()=>t(63177));module.exports=n})(); |