dsql-admin/dsql-app/.local_dist/server/pages/api/connect/handshake.js

1 line
8.2 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"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,query