"use strict";(()=>{var e={};e.id=4105,e.ids=[4105],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")},55096:(e,r,s)=>{s.r(r),s.d(r,{config:()=>m,default:()=>D,routeModule:()=>E});var a={};s.r(a),s.d(a,{default:()=>f});var t=s(89947),i=s(2706),n=s(96762),o=s(29021),d=s.n(o),u=s(69842),l=s(67619),c=s(48786),_=s(33873),p=s.n(_),S=s(10776);async function f(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let{user:s}=await (0,u.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let a=e.body.schema,t=e.body.dbId;try{let e=await (0,c.A)("SELECT * FROM user_databases WHERE user_id = ?  AND id = ?",[s.id,t]);if(!e?.[0])throw Error("Invalid Database");let i=e[0],n=p().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`),o=JSON.parse(d().readFileSync(n,"utf-8")),u=o.find(e=>e.dbFullName==i.db_full_name);if(!u)throw Error("This Database doesn't exist");if(u.tables=a.tables,u.childrenDatabases)for(let e=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=a.tables}d().writeFileSync(`${n}`,JSON.stringify(o),"utf8"),await (0,S.A)({userId:s.id,targetDatabase:i.db_full_name}),r.json({success:!0})}catch(a){(0,l.A)({component:"/api/acceptUserInvitation/catch-error",message:a.message,user:s,req:e}),r.json({success:!1})}}let D=(0,n.M)(a,"default"),m=(0,n.M)(a,"config"),E=new t.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/user-schema/replace-database-schema",pathname:"/api/user-schema/replace-database-schema",bundlePath:"",filename:""},userland:a})},55153:(e,r,s)=>{s.d(r,{On:()=>t.a,_n:()=>n}),s(76102);var a=s(65967),t=s.n(a);s(30889);var i=s(93726);let n=s.n(i)()},69842:(e,r,s)=>{s.d(r,{A:()=>n});var a=s(39383),t=s.n(a),i=s(55153);async function n(e,r,s,a){let n=t()({req:e,level:s?"deep":void 0}),o={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 a&&n.payload?.id&&(0,i._n)(process.env.DSQL_SU_USER_ID)!==n.payload.id?{user:null,appData:o}:{user:n.payload,appData:o}}},48786:(e,r,s)=>{s.d(r,{A:()=>t});var a=s(7447);async function t(...e){let r=(0,a.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),a=r.X(0,[6060,776],()=>s(55096));module.exports=a})();