"use strict";(()=>{vare={};e.id=3382,e.ids=[3382],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}}})},84612:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>E,routeModule:()=>A});vars={};t.r(s),t.d(s,{default:()=>p});varo=t(89947),n=t(2706),a=t(96762),i=t(29021),u=t.n(i),c=t(33873),d=t.n(c),l=t(67619),_=t(69842),f=t(76856);asyncfunctionp(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,_.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{database:s,fileBase64:o}=e.body;s?.db_full_name?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});try{lete=Buffer.from(o,"base64").toString("utf-8"),n=JSON.parse(e),a=d().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${t.id}/main.json`);if(!u().existsSync(a))returnr.end();leti=JSON.parse(u().readFileSync(a,"utf-8")),c=i.find(e=>e.dbFullName==s.db_full_name);if(!c)throwError("Database not found!");c.tables=n.tables,u().writeFileSync(a,JSON.stringify(i),"utf-8"),await(0,f.A)({userId:t.id,targetDatabase:s.db_full_name}),r.json({success:!0})}catch(e){console.log("JSON import ERROR =>",e.message),(0,l.A)({component:"/api/importDatabase/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Import Failed!"})}}letE=(0,a.M)(s,"default"),S=(0,a.M)(s,"config"),A=newo.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/importDatabaseSchema",pathname:"/api/importDatabaseSchema",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>u});vars=t(48786),o=t(95969),n=t(29021),a=t.n(n),i=t(89159);asyncfunctionu(e,r,t){try{let{keyCookieName:n,csrfCookieName:u}=(0,i.A)();if(!e.cookies?.[n]?.match(/./))throwError("Request Cookies not Found!");letc=(0,o.A)({encryptedString:e.cookies[n]});if(!c)throwError("Couldn't decrypt auth cookie!");letd=JSON.parse(c);if(!d.csrf_k)throwError("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(d.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&&!a().existsSync(`${l}/${d.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==d.verification_status&&!t){lete=await(0,s.A)(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(d?.date&&Date.now()-d.date>6048e5)throwError("Key expired!");returnd}catch(r){returnconsole.log(`userAuth Error for ${e.url}: ${r.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",o=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+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),a+=t;leti=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=s;letu=r;returne?.userId&&(u+=`user_${e.userId}_`),n&&(u+=`${n}_`),{keyCookieName:a,csrfCookieName:i,oneTimeCodeName:u+=o}}},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,error:e.message}}finally{awaitr?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){returnt}});vart=function(e){returne.PAGES="PAGES",e.PAGES_API="PAGES