"use strict";(()=>{vare={};e.id=3133,e.ids=[3133],e.modules={39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/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")},25477:(e,r,a)=>{a.r(r),a.d(r,{config:()=>b,default:()=>m,routeModule:()=>f});vart={};a.r(t),a.d(t,{default:()=>g});vars=a(89947),o=a(2706),l=a(96762),n=a(29021),i=a.n(n),d=a(60125),u=a(67619),c=a(69842),p=a(76856);asyncfunctiong(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});leta=await(0,c.A)(e,r,!0);if(!a)returnr.json({success:!1,msg:"Unauthorized"});let{tableData:t}=e.body,s=e.body.database,o=e.body.dbSlug;e.body.delegated;letl=s.replace(/[^a-z\_0-9]/g,"");try{letn=await(0,d.A)({request:e,user:a,databaseSlug:o,query:e.query}),u=n?.rootUserId?n.rootUserId:a.id,c=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${u}/main.json`,g=JSON.parse(i().readFileSync(c,"utf-8")),m=g.findIndex(e=>e.dbFullName===s),b=g[m].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===t.childTableDbFullName&&e.childTableName===t.childTableName&&e.tableName===t.tableName);g[m].tables[b]=t,i().writeFileSync(`${c}`,JSON.stringify(g),"utf8"),await(0,p.A)({userId:u,targetDatabase:l}),r.json({success:!0})}catch(e){console.log(e.message),(0,u.A)({component:"/api/addApiKey/catch-error",message:e.message,user:a}),r.json({success:!1,msg:"Foreign Key update Failed."})}}letm=(0,l.M)(t,"default"),b=(0,l.M)(t,"config"),f=news.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:t})},60125:(e,r,a)=>{a.d(r,{A:()=>s});vart=a(95969);asyncfunctions({request:e,databaseSlug:r,user:a,query:s}){try{leto=a.id,l=null;if(!s?.delegated)return{dbUserId:o};letn=s.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${n}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cookies?.[d])throwError("Cookie not present");leta=(0,t.A)({encryptedString:e.cookies[d]});if(!a)throwError("Invalid Token");if((l=JSON.parse(a)).databaseSlug===r)return{dbUserId:o=l.rootUserId,rootUserId:l.rootUserId,rootUserName:l.rootUserName,rootUserEmail:l.rootUserEmail,rootUserImage:l.rootUserImage,databaseFullName:l.databaseFullName,databaseSlug:l.databaseSlug,allowedTables:l.allowedTables,priviledges:l.priviledges,database:l.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:o}}catch(e){returnnull}}},69842:(e,r,a)=>{a.d(r,{A:()=>o});vart=a(39383),s=a.n(t);asyncfunctiono(e,r,a){returns()({req:e,level:a?"deep":void0}).payload}},95969:(e,r,a)=>{a.d(r,{A:()=>l});vart=a(55511),s=a(79428),o=a(32443);functionl({encryptedString:e,encryptionKey:r,encryptionSalt:a}){if(!e?.match(/./))returnconsole.log("Encrypted string is invalid"),e;let{key:l,salt:n,keyLen:i,algorithm:d,bufferAllocSize:u}=(0,o.A)({encryptionKey:r});if(!l?.match(/.{8,}/))returnconsole.log("Decrption key is invalid"),e;if(!n?.match(/.{8,}/))returnconsole.log("Decrption salt is invalid"),e;letc=(0,t.scryptSync)(l,n,i),p=s.Buffer.alloc(u,0),g=(0,t.createDecipheriv)(d,c,p);try{letr=g.update(e,"hex","utf8");returnr+=g.final("utf8")}catch(r){returnconsole.log("Error in decrypting =>",r.message),e}}},32443:(e,r,a)=>{a.d(r,{A:()=>t});functiont(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{letr=Number(e);if("number"!=typeofr||isNaN(r))return0;returnMath.round(r)}catch(e){returnconsole.log(`Numberfy ERROR: ${e.message}`),0}