"use strict";(()=>{var e={};e.id=4133,e.ids=[4133],e.modules={60818:e=>{e.exports=require("dotenv")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},87854:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>m,routeModule:()=>_});var n={};t.r(n),t.d(n,{default:()=>g});var s=t(89947),a=t(2706),i=t(96762),u=t(48225),l=t.n(u),o=t(77619),d=t.n(o),c=t(19261),p=t.n(c);let f=t(29021);async function g(e,r){if("GET"!==e.method)return r.json({msg:"Failed!"});try{let t=e.headers.authorization;if(!t)return r.json({success:!1,msg:"Unauthorized"});let n=d()({key:t,user_id:String(e.query.user_id)});if(!n?.user_id)throw Error("Api Credentials invalid!");let{user_id:s,full_access:a}=n;if(!a)return r.json({success:!1,msg:"Unauthorized"});let i=e.query.schema,u=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.toString().replace(/\//g,"")}/main.json`,l=JSON.parse(f.readFileSync(u,"utf8")),o=l.findIndex(e=>e.dbFullName==i?.dbFullName);if(i?.dbFullName&&l.find(e=>e.dbFullName==i.dbFullName),o<0)return r.json({success:!1,payload:null});l[o]=i,f.writeFileSync(u,JSON.stringify(l,null,4),"utf8"),await p()({userId:s.toString().replace(/\/| /g,""),targetDatabase:l[o].dbFullName}),r.json({success:!0,payload:"Success!"})}catch(t){l()({component:"/api/query/update-schema-from-single-database/main-catch-error",message:t.message,req:e}),r.json({success:!1,payload:null,msg:"Something went wrong"})}}let m=(0,i.M)(n,"default"),S=(0,i.M)(n,"config"),_=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/query/[user_id]/update-schema-from-single-database",pathname:"/api/query/[user_id]/update-schema-from-single-database",bundlePath:"",filename:""},userland:n})},77619:(e,r,t)=>{let n=t(29021),s=t(72835);e.exports=({key:e,database:r,table:t,user_id:a})=>{if(!e||!a)return null;try{let i=process.env.DSQL_API_KEYS_PATH;if(!i)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let u=s({encryptedString:e}),l=JSON.parse(u||""),o=n.existsSync(`${i}/${l.sign}`);if(String(l.user_id)!==String(a)||!o)return null;if(!l.target_database)return l;if(!r&&l.target_database)return null;let d=l.target_database?.split(",").includes(String(r));if(d&&!l.target_table)return l;if(d&&!t&&l.target_table)return null;if(l.target_table?.split(",").includes(String(t)))return l;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},21580:(e,r,t)=>{let n=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!n.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:n.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),n=r.X(0,[2451],()=>t(87854));module.exports=n})();