"use strict";(()=>{vare={};e.id=4105,e.ids=[4105],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},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}}})},55096:(e,r,t)=>{t.r(r),t.d(r,{config:()=>h,default:()=>p,routeModule:()=>A});vars={};t.r(s),t.d(s,{default:()=>E});vara=t(89947),n=t(2706),i=t(96762),o=t(69842),u=t(67619),d=t(48786),c=t(33873),l=t.n(c),_=t(76856);letf=t(29021);asyncfunctionE(e,r){if("POST"!==e.method)returnr.json({user:null,msg:"Registration Failed!"});lett=await(0,o.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});lets=e.body.schema,a=e.body.dbId;try{lete=await(0,d.A)("SELECT * FROM user_databases WHERE user_id = ? AND id = ?",[t.id,a]);if(!e?.[0])throwError("Invalid Database");letn=e[0],i=l().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`),o=JSON.parse(f.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=s.tables,u.childrenDatabases)for(lete=0;e<u.childrenDatabases.length;e++){let{dbFullName:r}=u.childrenDatabases[e],t=o.find(e=>e.dbFullName===r);if(!t||!t.tables){u.childrenDatabases?.splice(e,1);continue}t.tables=s.tables}f.writeFileSync(`${i}`,JSON.stringify(o),"utf8"),await(0,_.A)({userId:t.id,targetDatabase:n.db_full_name}),r.json({success:!0})}catch(s){(0,u.default)({component:"/api/acceptUserInvitation/catch-error",message:s.message,user:t,req:e}),r.json({success:!1})}}letp=(0,i.M)(s,"default"),h=(0,i.M)(s,"config"),A=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:s})},69842:(e,r,t)=>{t.d(r,{A:()=>u});vars=t(48786),a=t(95969),n=t(29021),i=t.n(n),o=t(89159);asyncfunctionu(e,r,t){try{let{keyCookieName:n,csrfCookieName:u}=(0,o.A)();if(!e.cookies?.[n]?.match(/./))throwError("Request Cookies not Found!");letd=(0,a.A)({encryptedString:e.cookies[n]});if(!d)throwError("Couldn't decrypt auth cookie!");letc=JSON.parse(d);if(!c.csrf_k)throwError("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))throwError("Deep Auth Failed. `csrf` key not found in request headers!");letl=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!l)throwError("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!i().existsSync(`${l}/${c.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==c.verification_status&&!t){lete=await(0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(c?.date&&Date.now()-c.date>6048e5)throwError("Key expired!");returnc}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=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=t;leto=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=s;letu=r;returne?.userId&&(u+=`user_${e.userId}_`),n&&(u+=`${n}_`),{keyCookieName:i,csrfCookieName:o,oneTimeCodeName:u+=a}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});asyncfunctions(...e){letr=global.DSQL_DB_CONN;try{if(!r)throwError("No Connection provided to DB_HANDLER function!");lett=awaitr.query(...e);returnJSON.parse(JSON.stringify(t))}catch(e){returnconsole.log("DB Error =>",e),{success:!1,er