"use strict";(()=>{vare={};e.id=4371,e.ids=[4371],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")},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")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){returnfunctione(t,r){returnrint?t[r]:"then"int&&"function"==typeoft.then?t.then(t=>e(t,r)):"function"==typeoft&&"default"===r?t:void0}}})},56363:(e,t,r)=>{r.r(t),r.d(t,{config:()=>N,default:()=>A,routeModule:()=>R});vars={};r.r(s),r.d(s,{default:()=>y});vara=r(89947),n=r(2706),l=r(96762),o=r(51348),i=r.n(o),u=r(73677),c=r.n(u),d=r(39831),p=r.n(d),_=r(77538),S=r.n(_),f=r(6420),m=r.n(f),g=r(33364),h=r.n(g);letb=r(29021),E=r(33873),{execSync:D}=r(79646);asyncfunctiony(e,t){if("POST"!==e.method)returnt.json({msg:"Failed!"});letr=awaitm()(e,t,!0);if(!r)returnt.json({success:!1,msg:"Unauthorized"});let{dbFullName:s,dbSlug:a,dbId:n,tableNameOld:l,payload:o,delegated:u}=e.body,{tableName:d,tableFullName:_,tableDescription:f}=o;if(!d?.match(/./)||d.match(/[^a-zA-Z0-9-_]/))returnt.json({success:!1,msg:"Bad Input"});try{leto=awaitp()({databaseSlug:a,request:e,user:r,query:e.query});if(!awaitc()({user:r,confirmedDelegetedUser:o,database:a,table:l,dbId:n,priviledgeRegex:/Edit Table/i}))returnconsole.log("User Unauthorized"),t.json({success:!1,msg:"Unauthorized"});letm=o?.rootUserId?o.rootUserId:r.id,g=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${m}/main.json`,y=JSON.parse(b.readFileSync(g,"utf8")),A=y.filter(e=>e.dbFullName===s)[0].tables.filter((e,t)=>{if(e.tableName===l)return!0});if(A&&A[0])A[0].tableName=d,A[0].tableNameOld=l,A[0].tableFullName=_,f&&(A[0].tableDescription=f),A[0].childrenTables&&A[0].childrenTables.forEach(e=>{try{y.filter(t=>t.dbFullName===e.dbNameFull)[0].tables.filter(t=>{if(t.tableName===e.tableName)return!0})[0].childTableName=d}catch(e){S()({component:"/api/updateUserTable/lines-131-138",message:e.message,user:r})}});elsethrowError("Table Does not exist");b.writeFileSync(`${g}`,JSON.stringify(y),"utf8"),awaith()({dbFullName:"datasquirel",tableName:"user_database_tables",identifierColumnName:"table_slug",identifierValue:l,data:{table_name:_,table_slug:d,table_description:f}}),u&&o&&awaiti()("UPDATE delegated_user_tables SET `table`=? WHERE delegated_user_id=? AND root_user_id=? AND `table`=? AND `database`=?",[d,r.id,o.rootUserId,l,a]);letN=E.join(process.cwd(),"/shell"),R=s.replace(/[^a-z\_0-9]/g,""),L=D(`node createDbFromSchema.js --user ${m} --database ${R}`,{cwd:N});console.log(L.toString()),t.json({success:!0})}catch(e){S()({component:"/api/updateUserTable/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Database Files could not be written!"})}}letA=(0,l.M)(s,"default"),N=(0,l.M)(s,"config"),R=newa.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/updateUserTable",pathname:"/api/updateUserTable",bundlePath:"",filename:""},userland:s})},73677:(e,t,r)=>{lets=r(51348),a=r(77538);e.exports=asyncfunction({user:e,confirmedDelegetedUser:t,database:r,table:n,priviledgeRegex:l,dbId:o}){leti,u;try{t?.delegated?(i=awaits("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[t.rootUserId,e.id,r,n]),u=i[0]?.priviledge?.match(l)):(i=awaits("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,n,o]),u=!0)}catch(t){a({component:"checkUserRights",message:t.message,user:e})}return!!i&&!!i[0]&&!!u}},39831:(e,t,r)=>{r(81630);lets=r(72907);e.exports=asyncfunction({request:e,databaseSlug:t,user:r,query:a}){try{letn=r.id,l=null;if(!a?.delegated)return{dbUserId:n};leto=a.dbUserId,i=`${process.env.DSQL_USER_DB_PREFIX}${o}_${t}`,u=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${i}`;try{if(!e.cooki
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let s=r(51348),a=r(72907),n=r(29021);async function l(e,t,r,l){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=a(e.cookies.datasquirelAuthKey);if(!o)return null;let i=JSON.parse(o);if(!i.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${i.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!n.existsSync(`${u}/${i.csrf_k}`))return null;if(0==i.verification_status&&!r){let e=await s(`SELECTverification_statusFROMusersWHEREid='${i.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return i?.date&&Date.now()-i.date>6048e5?null:i}e.exports=l},33364:(e,t,r)=>{let s=r(82703),a=r(72583),n=r(16570),l=r(51348),o=r(21339);async function i({dbContext:e,paradigm:t,dbFullName:r,tableName:i,data:u,tableSchema:c,identifierColumnName:d,identifierValue:p,encryptionKey:_,encryptionSalt:S}){if(!u||!Object.keys(u).length)return null;let f=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),m=f?l:o,g=Object.keys(u),h=[],b=[];for(let e=0;e<g.length;e++)try{let t=g[e],r=u[t],l=c?c?.fields?.filter(e=>e.fieldName===t):null,o=l&&l[0]?l[0]:null;if(null==r||void 0==r)continue;o?.richText&&(r=a(r,n)),o?.encrypted&&(r=s(r,_,S)),"object"==typeof r&&(r=JSON.stringify(r)),o?.pattern&&!new RegExp(o.pattern,o.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),"string"==typeof r&&r.match(/^null$/i)&&(r={toSqlString:function(){return"NULL"}}),"string"!=typeof r||r.match(/./i)||(r={toSqlString:function(){return"NULL"}}),h.push(`\`${t}\`=?`),"number"==typeofr?b.push(String(r)):b.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}h.push(`date_updated='${Date()}'`),h.push(`date_updated_code='${Date.now()}'`);letE=`UPDATE ${i} SET ${h.join(",")} WHERE \`${d}\`=?`;returnb.push(p),f?awaitm(E,b):awaitm({paradigm:t,database:r,queryString:E,queryValues:b})}e.exports=i},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:a}=r(55511),{Buffer:n}=r(79428);e.exports=e=>{lett=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{letr=t.update(e,"hex","utf8");returnr+=t.final("utf8")}catch(e){returnnull}}},82703:(e,t,r)=>{let{scryptSync:s,createCipheriv:a}=r(55511),{Buffer:n}=r(79428),l=r(48225);e.exports=(e,t,r)=>{leto=a("aes-192-cbc",s(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{lett=o.update(e,"utf8","hex");returnt+=o.final("hex")}catch(e){returnl({component:"encrypt",message:e.message}),null}}},16570:e=>{e.exports={allowedTags:["b","i","em","strong","a","p","span","ul","ol","li","h1","h2","h3","h4","h5","h6","img","div","button","pre","code","br"],allowedAttributes:{a:["href"],img:["src","alt","width","height","class","style"],"*":["style","class"]}}},48225:(e,t,r)=>{lets=r(29021);e.exports=asyncfunction({user:e,message:t,component:r,noMail:a}){letn=`🚀 SERVER ERROR ===========================