"use strict";(()=>{var e={};e.id=4133,e.ids=[4133],e.modules={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")},92003:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>g,routeModule:()=>m});var a={};t.r(a),t.d(a,{default:()=>p});var s=t(89947),i=t(2706),n=t(96762),l=t(29021),u=t.n(l),o=t(67619),d=t(56081),c=t(10776);async function p(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 a=(0,d.A)({key:t,user_id:String(e.query.user_id)});if(!a?.user_id)throw Error("Api Credentials invalid!");let{user_id:s,full_access:i}=a;if(!i)return r.json({success:!1,msg:"Unauthorized"});let n=e.query.schema,l=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.toString().replace(/\//g,"")}/main.json`,o=JSON.parse(u().readFileSync(l,"utf8")),p=o.findIndex(e=>e.dbFullName==n?.dbFullName);if(n?.dbFullName&&o.find(e=>e.dbFullName==n.dbFullName),p<0)return r.json({success:!1,payload:null});o[p]=n,u().writeFileSync(l,JSON.stringify(o,null,4),"utf8"),await (0,c.A)({userId:s.toString().replace(/\/| /g,""),targetDatabase:o[p].dbFullName}),r.json({success:!0,payload:"Success!"})}catch(t){(0,o.A)({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 g=(0,n.M)(a,"default"),f=(0,n.M)(a,"config"),m=new s.PagesAPIRouteModule({definition:{kind:i.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:a})},56081:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(29021),s=t.n(a),i=t(95969);let n=({key:e,database:r,table:t,user_id:a,media:n})=>{if(!e||!a)return null;try{let l=process.env.DSQL_API_KEYS_PATH;if(!l)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let u=(0,i.A)({encryptedString:e}),o=JSON.parse(u||""),d=s().existsSync(`${l}/${o.sign}`);if(String(o.user_id)!==String(a)||!d)return null;if(!o.target_database||n)return o;if(!r&&o.target_database)return null;let c=o.target_database?.split(",").includes(String(r));if(c&&!o.target_table)return o;if(c&&!t&&o.target_table)return null;if(o.target_table?.split(",").includes(String(t)))return o;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),{error:`api-cred ERROR: ${e.message}`}}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(55511),s=t(79428),i=t(31542);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:n,salt:l,keyLen:u,algorithm:o,bufferAllocSize:d}=(0,i.A)({encryptionKey:r});if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=(0,a.scryptSync)(n,l,u),p=s.Buffer.alloc(d,0),g=(0,a.createDecipheriv)(o,c,p);try{let r=g.update(e,"hex","utf8");return r+=g.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[6060,776],()=>t(92003));module.exports=a})();