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

16 lines
13 KiB
JavaScript
Raw Normal View History

2025-02-19 19:38:56 +00:00
"use strict";(()=>{var e={};e.id=9785,e.ids=[9785],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},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}}})},92145:(e,t,r)=>{r.r(t),r.d(t,{config:()=>u,default:()=>_,routeModule:()=>c});var a={};r.r(a),r.d(a,{default:()=>d});var n=r(89947),s=r(2706),i=r(96762),o=r(69842),l=r(49941);async function d(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let{user:r,appData:a}=await (0,o.A)(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});console.log("Invitation Received by current logged in user, Loggin in VIA API ...");let n=await (0,l.A)({query:e.body.query,user:r});t.json({success:!0,result:n})}let _=(0,i.M)(a,"default"),u=(0,i.M)(a,"config"),c=new n.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:a})},55153:(e,t,r)=>{r.d(t,{On:()=>n.a,_n:()=>i}),r(76102);var a=r(65967),n=r.n(a);r(30889);var s=r(93726);let i=r.n(s)()},69842:(e,t,r)=>{r.d(t,{A:()=>i});var a=r(39383),n=r.n(a),s=r(55153);async function i(e,t,r,a){let i=n()({req:e,level:r?"deep":void 0}),o={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return a&&i.payload?.id&&(0,s._n)(process.env.DSQL_SU_USER_ID)!==i.payload.id?{user:null,appData:o}:{user:i.payload,appData:o}}},49941:(e,t,r)=>{r.d(t,{A:()=>o});var a=r(67619),n=r(48786),s=r(98e3),i=r(62050);async function o({query:e,user:t}){try{let r=global.DSQL_USE_LOCAL?i.A:n.A,{invite:a,database_access:o,priviledge:l,email:d}=e,_=[a,d],u=await r("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",_);if(!u||!u[0])throw Error("No Invitation Found");let c=[a],p=await r("SELECT first_name,last_name,email FROM users WHERE id=?",c);if(p?.[0]){let e=await r("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[a,t.id,d]);if(e?.[0])console.log("User already added");else{(0,s.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:a,invited_user_id:t.id,database_access:o,first_name:t.first_name,last_name:t.last_name,phone:t.phone,email:t.email,username:t.username,user_type:"admin",user_priviledge:l,image:t.image,image_thumbnail:t.image_thumbnail}});let e=await r("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[a,d]);if(await r("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[a,t.id]),e&&e[0]){let r=e[0].db_tables_data.split("|");for(let e=0;e<r.length;e++){let[n,i]=r[e].split("-");await (0,s.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:t.id,root_user_id:a,database:n,table:i,priviledge:l}})}}}await r("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[a,d])}}catch(e){global.ERROR_CALLBACK?.("Add Admin User On Login Error",e),(0,a.A)({component:"addAdminUserOnLogin",message:e.m
2025-01-28 18:43:16 +00:00
Error Message: ${t}
Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-28 18:43:16 +00:00
User Email: ${e?.email}`),s?.url&&(a+=`
URL: ${s.url}`),s?.body&&(a+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),o&&(a+=`
IP: ${o}`),a+=`
Date: ${i.toDateString()}
========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let l=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",a),n().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-02-19 19:38:56 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},68829:(e,t,r)=>{r.d(t,{A:()=>i});var a=r(55511),n=r(79428),s=r(31542);function i({data:e,encryptionKey:t,encryptionSalt:r}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:i,salt:o,keyLen:l,algorithm:d,bufferAllocSize:_}=(0,s.A)({encryptionKey:t});if(!i?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let u=(0,a.scryptSync)(i,o,l),c=n.Buffer.alloc(_,0),p=(0,a.createCipheriv)(d,u,c);try{let t=p.update(e,"utf8","hex");return t+=p.final("hex")}catch(t){return console.log("Error in encrypting =>",t.message),global.ERROR_CALLBACK?.("Error Encrypting Data",t),e}}},48786:(e,t,r)=>{r.d(t,{A:()=>n});var a=r(7447);async function n(...e){let t=(0,a.A)();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 global.ERROR_CALLBACK?.("DB_HANDLER Error",e),{success:!1,error:e.message}}finally{await t?.end()}}},62050:(e,t,r)=>{r.d(t,{A:()=>n});var a=r(7447);async function n(...e){let t=(0,a.A)();try{let r=await t.query(...e);return JSON.parse(JSON.stringify(r))}catch(e){return global.ERROR_CALLBACK?.("LOCAL_DB_HANDLER Error",e),{success:!1,error:e.message}}finally{await t?.end()}}},52939:(e,t,r)=>{r.d(t,{A:()=>a});function a({dbContext:e,dbFullName:t}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!t||!!t.match(/^datasquirel$/))}},64292:(e,t,r)=>{async function a(e,t,r){try{if(!e)throw Error("No Connection Found!");if(!t)throw Error("Query String Required!");if("string"==typeof t){let a=await e.query(n(t),r);return JSON.parse(JSON.stringify(a))}if("object"!=typeof t)return null;{let r=[];for(let a=0;a<t.length;a++)try{let s=t[a],i=await e.query(n(s.query),s.values);r.push(JSON.parse(JSON.stringify(i)))}catch(e){global.ERROR_CALLBACK?.("Connection DB Handler Query Error",e),r.push(null)}return r}}catch(e){return global.ERROR_CALLBACK?.("Connection DB Handler Error",e),null}finally{e?.end()}}function n(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}r.d(t,{A:()=>a})},7447:(e,t,r)=>{r.d(t,{A:()=>s});var a=r(9973),n=r.n(a);function s(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||n()({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"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||n()({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||n()({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||n()({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"}})}},31542:(e,t,r)=>{r.d(t,{A:()=>n});var a=r(82535);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?(0,a.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,t,r)=>{r.d(t,{A:()=>a});function a(e,t){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;if(t)return Number(r.toFixed(t))