"use strict";(()=>{vare={};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")},79646:e=>{e.exports=require("child_process")},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(){returnfunctione(r,t){returntinr?r[t]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,t)):"function"==typeofr&&"default"===t?r:void0}}})},25477:(e,r,t)=>{t.r(r),t.d(r,{config:()=>E,default:()=>p,routeModule:()=>S});vars={};t.r(s),t.d(s,{default:()=>f});vara=t(89947),o=t(2706),n=t(96762),i=t(60125),d=t(67619),l=t(69842),u=t(76856);letc=t(29021);t(33873);let{execSync:_}=t(79646);asyncfunctionf(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,l.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{tableData:s}=e.body,a=e.body.database,o=e.body.dbSlug;e.body.delegated;letn=a.replace(/[^a-z\_0-9]/g,"");try{letd=await(0,i.A)({request:e,user:t,databaseSlug:o,query:e.query}),l=d?.rootUserId?d.rootUserId:t.id,_=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,f=JSON.parse(c.readFileSync(_,"utf-8")),p=f.findIndex(e=>e.dbFullName===a),E=f[p].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===s.childTableDbFullName&&e.childTableName===s.childTableName&&e.tableName===s.tableName);f[p].tables[E]=s,c.writeFileSync(`${_}`,JSON.stringify(f),"utf8"),await(0,u.A)({userId:l,targetDatabase:n}),r.json({success:!0})}catch(e){console.log(e.message),(0,d.default)({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Foreign Key update Failed."})}}letp=(0,n.M)(s,"default"),E=(0,n.M)(s,"config"),S=newa.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});vars=t(95969);asyncfunctiona({request:e,databaseSlug:r,user:t,query:a}){try{leto=t.id,n=null;if(!a?.delegated)return{dbUserId:o};leti=a.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,l=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[l])throwError("Cookie not present");lett=(0,s.A)({encryptedString:e.cookies[l]});if(!t)throwError("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){returnnull}}},69842:(e,r,t)=>{t.d(r,{A:()=>d});vars=t(48786),a=t(95969),o=t(29021),n=t.n(o),i=t(89159);asyncfunctiond(e,r,t){try{let{keyCookieName:o,csrfCookieName:d}=(0,i.A)();if(!e.cookies?.[o]?.match(/./))throwError("Request Cookies not Found!");letl=(0,a.A)({encryptedString:e.cookies[o]});if(!l)throwError("Couldn't decrypt auth cookie!");letu=JSON.parse(l);if(!u.csrf_k)throwError("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throwError("Deep Auth Failed. `csrf` key not found in request headers!");letc=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throwError("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!n().existsSync(`${c}/${u.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){lete=await(0,s.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throwError("Key expired!");returnu}catch(e){returnconsole.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});functions(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s