1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
"use strict";(()=>{var e={};e.id=3133,e.ids=[3133],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")},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,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},25477:(e,r,s)=>{s.r(r),s.d(r,{config:()=>D,default:()=>S,routeModule:()=>f});var t={};s.r(t),s.d(t,{default:()=>p});var o=s(89947),a=s(2706),n=s(96762),i=s(29021),l=s.n(i),u=s(60125),c=s(67619),d=s(69842),_=s(76856);async function p(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await (0,d.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{tableData:t}=e.body,o=e.body.database,a=e.body.dbSlug;e.body.delegated;let n=o.replace(/[^a-z\_0-9]/g,"");try{let i=await (0,u.A)({request:e,user:s,databaseSlug:a,query:e.query}),c=i?.rootUserId?i.rootUserId:s.id,d=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${c}/main.json`,p=JSON.parse(l().readFileSync(d,"utf-8")),S=p.findIndex(e=>e.dbFullName===o),D=p[S].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===t.childTableDbFullName&&e.childTableName===t.childTableName&&e.tableName===t.tableName);p[S].tables[D]=t,l().writeFileSync(`${d}`,JSON.stringify(p),"utf8"),await (0,_.A)({userId:c,targetDatabase:n}),r.json({success:!0})}catch(e){console.log(e.message),(0,c.A)({component:"/api/addApiKey/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Foreign Key update Failed."})}}let S=(0,n.M)(t,"default"),D=(0,n.M)(t,"config"),f=new o.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:t})},60125:(e,r,s)=>{s.d(r,{A:()=>o});var t=s(95969);async function o({request:e,databaseSlug:r,user:s,query:o}){try{let a=s.id,n=null;if(!o?.delegated)return{dbUserId:a};let i=o.dbUserId,l=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${l}`;try{if(!e.cookies?.[u])throw Error("Cookie not present");let s=(0,t.A)({encryptedString:e.cookies[u]});if(!s)throw Error("Invalid Token");if((n=JSON.parse(s)).databaseSlug===r)return{dbUserId:a=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:a}}catch(e){return null}}},69842:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(39908),o=s.n(t);async function a(e,r,s){let t=o()({req:e,level:s?"deep":void 0});return console.log(t),t.payload}},95969:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(55511),o=s(79428),a=s(32443);function n({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:n,salt:i,keyLen:l,algorithm:u,bufferAllocSize:c}=(0,a.A)({encryptionKey:r});if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(n,i,l),_=o.Buffer.alloc(c,0),p=(0,t.createDecipheriv)(u,d,_);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},7447:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(9973),o=s.n(t);function a(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||o()({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||o()({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||o()({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,s)=>{s.d(r,{A:()=>t});function t(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 s}});var s=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,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9814],()=>s(25477));module.exports=t})(); |