"use strict";(()=>{vare={};e.id=3133,e.ids=[3133],e.modules={60818:e=>{e.exports=require("dotenv")},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")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},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}}})},47095:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>m,routeModule:()=>y});vars={};t.r(s),t.d(s,{default:()=>E});vara=t(89947),o=t(2706),n=t(96762),i=t(39831),l=t.n(i),u=t(48225),d=t.n(u),c=t(6420),p=t.n(c),_=t(19261),f=t.n(_);letS=t(29021);t(33873);let{execSync:b}=t(79646);asyncfunctionE(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitp()(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{leti=awaitl()({request:e,user:t,databaseSlug:o,query:e.query}),u=i?.rootUserId?i.rootUserId:t.id,d=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${u}/main.json`,c=JSON.parse(S.readFileSync(d,"utf-8")),p=c.findIndex(e=>e.dbFullName===a),_=c[p].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===s.childTableDbFullName&&e.childTableName===s.childTableName&&e.tableName===s.tableName);c[p].tables[_]=s,S.writeFileSync(`${d}`,JSON.stringify(c),"utf8"),awaitf()({userId:u,targetDatabase:n}),r.json({success:!0})}catch(e){console.log(e.message),d()({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Foreign Key update Failed."})}}letm=(0,n.M)(s,"default"),g=(0,n.M)(s,"config"),y=newa.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:s})},39831:(e,r,t)=>{t(81630);lets=t(72835);e.exports=asyncfunction({request:e,databaseSlug:r,user:t,query:a}){try{leto=t.id,n=null;if(!a?.delegated)return{dbUserId:o};leti=a.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])throwError("Cookie not present");lett=s({encryptedString:e.cookies[u]});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}}},6420:(e,r,t)=>{t(81630);lets=t(51348),a=t(72835),o=t(29021),n=t(31341);asyncfunctioni(e,r,t,i){let{keyCookieName:l,csrfCookieName:u}=n();if(!e.cookies?.[l]?.match(/./))returnnull;letd=a({encryptedString:e.cookies[l]});if(!d)returnnull;letc=JSON.parse(d);if(!c.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))returnnull;letp=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!p)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!o.existsSync(`${p}/${c.csrf_k}`))returnnull;if(0==c.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}returnc?.date&&Date.now()-c.date>6048e5?null:c}e.exports=i},31341:e=>{e.exports=function(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=r;e?.userId&&(a+=`user_${e.userId}_`),e?.database&&(a+=`${e.database}_`),a+=t;leto=r;returne?.userId&&(o+=`user_${e.userId}_`),e?.database&&(o+=`${e.database}_