"use strict";(()=>{vare={};e.id=4105,e.ids=[4105],e.modules={60818:e=>{e.exports=require("dotenv")},27825:e=>{e.exports=require("lodash")},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,s){returnsinr?r[s]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,s)):"function"==typeofr&&"default"===s?r:void0}}})},46127:(e,r,s)=>{s.r(r),s.d(r,{config:()=>v,default:()=>m,routeModule:()=>D});vart={};s.r(t),s.d(t,{default:()=>b});vara=s(89947),n=s(2706),i=s(96762),o=s(6420),u=s.n(o),c=s(48225),l=s.n(c);s(27825);vard=s(51348),_=s.n(d),p=s(33873),f=s.n(p);s(79646);varS=s(19261),E=s.n(S);leth=s(29021);asyncfunctionb(e,r){if("POST"!==e.method)returnr.json({user:null,msg:"Registration Failed!"});lets=awaitu()(e,r,!0);if(!s)returnr.json({success:!1,msg:"Unauthorized"});lett=e.body.schema,a=e.body.dbId;try{lete=await_()("SELECT * FROM user_databases WHERE user_id = ? AND id = ?",[s.id,a]);if(!e?.[0])throwError("Invalid Database");letn=e[0],i=f().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`),o=JSON.parse(h.readFileSync(i,"utf-8")),u=o.find(e=>e.dbFullName==n.db_full_name);if(!u)throwError("This Database doesn't exist");if(u.tables=t.tables,u.childrenDatabases)for(lete=0;e<u.childrenDatabases.length;e++){let{dbFullName:r}=u.childrenDatabases[e],s=o.find(e=>e.dbFullName===r);if(!s||!s.tables){u.childrenDatabases?.splice(e,1);continue}s.tables=t.tables}h.writeFileSync(`${i}`,JSON.stringify(o),"utf8"),awaitE()({userId:s.id,targetDatabase:n.db_full_name}),r.json({success:!0})}catch(t){l()({component:"/api/acceptUserInvitation/catch-error",message:t.message,user:s,req:e}),r.json({success:!1})}}letm=(0,i.M)(t,"default"),v=(0,i.M)(t,"config"),D=newa.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/user-schema/replace-database-schema",pathname:"/api/user-schema/replace-database-schema",bundlePath:"",filename:""},userland:t})},6420:(e,r,s)=>{s(81630);lett=s(51348),a=s(72835),n=s(29021),i=s(31341);asyncfunctiono(e,r,s,o){let{keyCookieName:u,csrfCookieName:c}=i();if(!e.cookies?.[u]?.match(/./))returnnull;letl=a({encryptedString:e.cookies[u]});if(!l)returnnull;letd=JSON.parse(l);if(!d.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))returnnull;let_=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!n.existsSync(`${_}/${d.csrf_k}`))returnnull;if(0==d.verification_status&&!s){lete=awaitt(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}returnd?.date&&Date.now()-d.date>6048e5?null:d}e.exports=o},31341:e=>{e.exports=function(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),n+=s;leti=r;returne?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),{keyCookieName:n,csrfCookieName:i+=t}}},51348:(e,r,s)=>{lett=s(9973),a=s(21580),n=t({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void0,charset:"utf8mb4",ssl:a()}});asyncfunctioni(...e){try{letr=awaitn.query(...e);returnawaitn.end(),JSON.parse(JSON.stringify(r))}catch(e){returnconsole.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,r,s)=>{lett=s(29021);e.exports=function(){lete=process.env