"use strict";(()=>{vare={};e.id=4436,e.ids=[4436],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")},72583:e=>{e.exports=require("sanitize-html")},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")},13461:(e,a,t)=>{t.r(a),t.d(a,{config:()=>y,default:()=>T,routeModule:()=>g});vars={};t.r(s),t.d(s,{default:()=>R});varl=t(89947),r=t(2706),i=t(96762),d=t(51348),u=t.n(d),n=t(48225),o=t.n(n),f=t(6420),p=t.n(f),m=t(47670),_=t.n(m),c=t(19261),b=t.n(c);letN=t(29021);t(33873);let{execSync:A}=t(79646);asyncfunctionR(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lets=awaitp()(e,a,!0);if(!s)returna.json({success:!1,msg:"Unauthorized"});let{dbFullName:l,dbSlug:r,dbId:i}=e.body,d=t(8693),n=t(95610),f=[...n.slice(0,2),...d.fields,...n.slice(2)];d.fields=[...f];try{lete;lett=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,n=JSON.parse(N.readFileSync(t,"utf8")),f=n.filter(e=>e.dbFullName===l)[0],p=f.tables.filter((a,t)=>{if("users"===a.tableName)returne=t,!0});if(p?.[0]&&"number"==typeofe?f.tables[e]=d:f.tables.push(d),f.childrenDatabases)for(lete=0;e<f.childrenDatabases.length;e++){leta=f.childrenDatabases[e];try{n.filter(e=>e.dbFullName===a.dbFullName)[0].tables=f.tables;lete=awaitu()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[s.id,a.dbFullName]);await_()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:e[0].id,db_slug:e[0].db_slug,table_name:"Users",table_slug:"users"}})}catch(e){o()({component:"/api/addUsersTableToDatabase/lines-100-115",message:e.message,user:s})}}N.writeFileSync(`${t}`,JSON.stringify(n),"utf8"),await_()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:i,db_slug:r,table_name:"Users",table_slug:"users"}});letm=l.replace(/[^a-z\_0-9]/g,"");awaitb()({userId:s.id,targetDatabase:m}),a.json({success:!0})}catch(e){o()({component:"/api/addUsersTableToDatabase/main-catch-error",message:e.message,user:s}),a.json({success:!1,msg:"Database Files could not be written!"})}}letT=(0,i.M)(s,"default"),y=(0,i.M)(s,"config"),g=newl.PagesAPIRouteModule({definition:{kind:r.A.PAGES_API,page:"/api/addUsersTableToDatabase",pathname:"/api/addUsersTableToDatabase",bundlePath:"",filename:""},userland:s})},6420:(e,a,t)=>{t(81630);lets=t(51348),l=t(72835),r=t(29021),i=t(31341);asyncfunctiond(e,a,t,d){let{keyCookieName:u,csrfCookieName:n}=i();if(!e.cookies?.[u]?.match(/./))returnnull;leto=l({encryptedString:e.cookies[u]});if(!o)returnnull;letf=JSON.parse(o);if(!f.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${f.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&&!r.existsSync(`${p}/${f.csrf_k}`))returnnull;if(0==f.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${f.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}returnf?.date&&Date.now()-f.date>6048e5?null:f}e.exports=d},31341:e=>{e.exports=function(e){leta=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",l=a;e?.userId&&(l+=`user_${e.userId}_`),e?.database&&(l+=`${e.database}_`),l+=t;letr=a;returne?.userId&&(r+=`user_${e.userId}_`),e?.database&&(r+=`${e.database}_`),{keyCookieName:l,csrfCookieName:r+=s}}},8693:e=>{e.exports=JSON.parse('{"tableName":"users","tableFullName":"Users","fields":[{"fieldName":"first_name","dataType":"VARCHAR(100)","notNullValue":true},{"fieldName":"last_name","dataType":"VARCHAR(100)","notNullValue":true},{"fieldName":"email","dataType":"VARCHAR(200)","notNullValue":tr