dsql-admin/dsql-app/.local_dist/server/pages/api/updateClonedTableForeignKeys.js
Benjamin Toby 1564c2811a Updates
2025-01-14 08:24:54 +01:00

1 line
5.1 KiB
JavaScript

"use strict";(()=>{var e={};e.id=3133,e.ids=[3133],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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}}})},25477:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>E,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>f});var a=t(89947),o=t(2706),n=t(96762),i=t(29021),d=t.n(i),u=t(60125),l=t(67619),c=t(69842),_=t(76856);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,c.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{tableData:s}=e.body,a=e.body.database,o=e.body.dbSlug;e.body.delegated;let n=a.replace(/[^a-z\_0-9]/g,"");try{let i=await (0,u.A)({request:e,user:t,databaseSlug:o,query:e.query}),l=i?.rootUserId?i.rootUserId:t.id,c=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,f=JSON.parse(d().readFileSync(c,"utf-8")),E=f.findIndex(e=>e.dbFullName===a),p=f[E].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===s.childTableDbFullName&&e.childTableName===s.childTableName&&e.tableName===s.tableName);f[E].tables[p]=s,d().writeFileSync(`${c}`,JSON.stringify(f),"utf8"),await (0,_.A)({userId:l,targetDatabase:n}),r.json({success:!0})}catch(e){console.log(e.message),(0,l.A)({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Foreign Key update Failed."})}}let E=(0,n.M)(s,"default"),p=(0,n.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:s})},60125:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(95969);async function a({request:e,databaseSlug:r,user:t,query:a}){try{let o=t.id,n=null;if(!a?.delegated)return{dbUserId:o};let i=a.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[u])throw Error("Cookie not present");let t=(0,s.A)({encryptedString:e.cookies[u]});if(!t)throw Error("Invalid Token");if((n=JSON.parse(t)).databaseSlug===r)return{dbUserId:o=n.rootUserId,rootUserId:n.rootUserId,rootUserName:n.rootUserName,rootUserEmail:n.rootUserEmail,rootUserImage:n.rootUserImage,databaseFullName:n.databaseFullName,databaseSlug:n.databaseSlug,allowedTables:n.allowedTables,priviledges:n.priviledges,database:n.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:o}}catch(e){return null}}},69842:(e,r,t)=>{t.d(r,{A:()=>d});var s=t(48786),a=t(95969),o=t(29021),n=t.n(o),i=t(89159);async function d(e,r,t){try{let{keyCookieName:o,csrfCookieName:d}=(0,i.A)();if(!e.cookies?.[o]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,a.A)({encryptedString:e.cookies[o]});if(!u)throw Error("Couldn't decrypt auth cookie!");let l=JSON.parse(u);if(!l.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!n().existsSync(`${c}/${l.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==l.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(l?.date&&Date.now()-l.date>6048e5)throw Error("Key expired!");return l}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",o=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),o&&(n+=`${o}_`),n+=t;let i=r;e?.userId&&(i+=`user_${e.userId}_`),o&&(i+=`${o}_`),i+=s;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),o&&(d+=`${o}_`),{keyCookieName:n,csrfCookieName:i,oneTimeCodeName:d+=a}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;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()}}},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),s=r.X(0,[2282],()=>t(25477));module.exports=s})();