"use strict";(()=>{var e={};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:()=>S});var s={};t.r(s),t.d(s,{default:()=>R});var r=t(89947),l=t(2706),i=t(96762),d=t(51348),u=t.n(d),n=t(48225),o=t.n(n),_=t(6420),p=t.n(_),f=t(47670),m=t.n(f),c=t(19261),b=t.n(c);let N=t(29021);t(33873);let{execSync:A}=t(79646);async function R(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let s=await p()(e,a,!0);if(!s)return a.json({success:!1,msg:"Unauthorized"});let{dbFullName:r,dbSlug:l,dbId:i}=e.body,d=t(8693),n=t(95610),_=[...n.slice(0,2),...d.fields,...n.slice(2)];d.fields=[..._];try{let e;let t=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,n=JSON.parse(N.readFileSync(t,"utf8")),_=n.filter(e=>e.dbFullName===r)[0],p=_.tables.filter((a,t)=>{if("users"===a.tableName)return e=t,!0});if(p?.[0]&&"number"==typeof e?_.tables[e]=d:_.tables.push(d),_.childrenDatabases)for(let e=0;e<_.childrenDatabases.length;e++){let a=_.childrenDatabases[e];try{n.filter(e=>e.dbFullName===a.dbFullName)[0].tables=_.tables;let e=await u()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[s.id,a.dbFullName]);await m()({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 m()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:i,db_slug:l,table_name:"Users",table_slug:"users"}});let f=r.replace(/[^a-z\_0-9]/g,"");await b()({userId:s.id,targetDatabase:f}),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!"})}}let T=(0,i.M)(s,"default"),y=(0,i.M)(s,"config"),S=new r.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUsersTableToDatabase",pathname:"/api/addUsersTableToDatabase",bundlePath:"",filename:""},userland:s})},6420:(e,a,t)=>{t(81630);let s=t(51348),r=t(72835),l=t(29021),i=t(31341);async function d(e,a,t,d){let{keyCookieName:u,csrfCookieName:n}=i();if(!e.cookies?.[u]?.match(/./))return null;let o=r({encryptedString:e.cookies[u]});if(!o)return null;let _=JSON.parse(o);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))return null;let p=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!p)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!l.existsSync(`${p}/${_.csrf_k}`))return null;if(0==_.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}return _?.date&&Date.now()-_.date>6048e5?null:_}e.exports=d},31341:e=>{e.exports=function(e){let a=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",r=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",l=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=a;e?.userId&&(i+=`user_${e.userId}_`),l&&(i+=`${l}_`),i+=t;let d=a;e?.userId&&(d+=`user_${e.userId}_`),l&&(d+=`${l}_`),d+=s;let u=a;return e?.userId&&(u+=`user_${e.userId}_`),l&&(u+=`${l}_`),{keyCookieName:i,csrfCookieName:d,oneTimeCodeName:u+=r}}},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":true},{"fieldName":"phone","dataType":"VARCHAR(50)"},{"fieldName":"user_type","dataType":"VARCHAR(20)","defaultValue":"default"},{"fieldName":"username","dataType":"VARCHAR(100)","nullValue":true},{"fieldName":"password","dataType":"TEXT"},{"fieldName":"image","dataType":"VARCHAR(250)"},{"fieldName":"image_thumbnail","dataType":"VARCHAR(250)"},{"fieldName":"address","dataType":"VARCHAR(255)"},{"fieldName":"city","dataType":"VARCHAR(50)"},{"fieldName":"state","dataType":"VARCHAR(50)"},{"fieldName":"country","dataType":"VARCHAR(50)"},{"fieldName":"zip_code","dataType":"VARCHAR(50)"},{"fieldName":"social_login","dataType":"TINYINT","defaultValue":"0"},{"fieldName":"social_platform","dataType":"VARCHAR(50)","nullValue":true},{"fieldName":"social_id","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"more_user_data","dataType":"BIGINT","defaultValue":"0"},{"fieldName":"verification_status","dataType":"TINYINT","defaultValue":"0"},{"fieldName":"temp_login_code","dataType":"VARCHAR(50)","nullValue":true}]}')}};var a=require("../../webpack-api-runtime.js");a.C(e);var t=e=>a(a.s=e),s=a.X(0,[4050,2451],()=>t(13461));module.exports=s})();