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