dsql-admin/dsql-app/.local_dist/server/pages/api/updateDbUser.js

1 line
8.4 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";(()=>{var e={};e.id=3683,e.ids=[3683],e.modules={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")},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}}})},18348:(e,t,r)=>{r.r(t),r.d(t,{config:()=>d,default:()=>u,routeModule:()=>f});var n={};r.r(n),r.d(n,{default:()=>l});var s=r(89947),a=r(2706),o=r(96762),i=r(30802),c=r(69842);async function l(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});if(!await (0,c.A)(e,t,!0))return t.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,payload:n}=e.body,s=(()=>{let e=Object.keys(n),t={};return e.forEach(e=>{!e?.match(/user_type|priviledge|database_access|databases?|confirm/)&&(e?.match(/databases|confirm/)||(t[e]=n[e]))}),t})(),a=await (0,i.A)({dbFullName:r,tableName:"users",identifierColumnName:"id",identifierValue:n.id,data:{...s},dbContext:"Dsql User",paradigm:"Full Access"});t.json({success:!!a?.affectedRows,msg:a?.affectedRows?"User Updated":a})}let u=(0,o.M)(n,"default"),d=(0,o.M)(n,"config"),f=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateDbUser",pathname:"/api/updateDbUser",bundlePath:"",filename:""},userland:n})},69842:(e,t,r)=>{r.d(t,{A:()=>c});var n=r(48786),s=r(95969),a=r(29021),o=r.n(a),i=r(89159);async function c(e,t,r){let{keyCookieName:a,csrfCookieName:c}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))return null;let l=(0,s.A)({encryptedString:e.cookies[a]});if(!l)return null;let u=JSON.parse(l);if(!u.csrf_k||r&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!o().existsSync(`${d}/${u.csrf_k}`))return null;if(0==u.verification_status&&!r){let e=await (0,n.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}},89159:(e,t,r)=>{r.d(t,{A:()=>n});function n(e){let t=process.env.DSQL_COOKIES_PREFIX||"dsql_",r=process.env.DSQL_COOKIES_KEY_NAME||"key",n=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=t;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=r;let i=t;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=n;let c=t;return e?.userId&&(c+=`user_${e.userId}_`),a&&(c+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:c+=s}}},30802:(e,t,r)=>{r.d(t,{A:()=>u});var n=r(72583),s=r.n(n),a=r(92652),o=r(48786),i=r(37275),c=r(68829),l=r(7971);async function u({dbContext:e,paradigm:t,dbFullName:r,tableName:n,data:u,tableSchema:d,identifierColumnName:f,identifierValue:_,encryptionKey:p,encryptionSalt:S,useLocal:g}){if(!u||!Object.keys(u).length)return null;let E=!!g||!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),y=g?l.A:E?o.A:i.default,h=Object.keys(u),m=[],D=[];for(let e=0;e<h.length;e++)try{let t=h[e],r=u[t],n=d?d?.fields?.filter(e=>e.fieldName===t):null,o=n&&n[0]?n[0]:null;if(null==r||void 0==r)continue;let i=/<[^>]+>/g;(o?.richText||String(r).match(i))&&(r=s()(r,a.A)),o?.encrypted&&(r=(0,c.default)({data:r,encryptionKey:p,encryptionSalt:S})),"object"==typeof r&&(r=JSON.stringify(r)),o?.pattern&&!new RegExp(o.pattern,o.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.