"use strict";exports.id=9914,exports.ids=[9914],exports.modules={95248:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.d(a,{A:()=>h});var r=t(8732),l=t(82015),n=t.n(l),o=t(58548),d=t(46437),i=t(63715),c=t(32415),u=t(77826),m=t(87730),p=e([m]);function h(e){let{singleUser:a,database:t,user:s}=n().useContext(m.SingleDbUserContext),l=Object.keys(a).filter(e=>!e.match(/^id$|^date_|^user_id$|^social_|^disk_usage|user_type/)),[p,h]=n().useState(!1),[g,_]=n().useState(a.image);return(0,r.jsxs)(n().Fragment,{children:[(0,r.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,r.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(d.A,{}),g&&(0,r.jsx)("img",{src:g,alt:"",className:"avatar large outlined"}),(0,r.jsxs)("h1",{className:"text-3xl m-0",children:[a.first_name," ",a.last_name]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:`/admin/${s?.id}/databases/${t.db_slug}/users/${a.id}/change-password`,className:"button outlined gray",children:"Change Password"}),(0,r.jsx)("button",{className:"bg-red-500",onClick:e=>{h(!0),window.confirm("Delete this user?")&&(0,i.A)("/api/deleteDbUser",{method:"post",body:{userId:a.id,dbFullName:t.db_full_name}},!0).then(e=>{e.success&&(window.location.pathname=`/admin/${s?.id}/databases/${t.db_slug}/users`)})},children:"Delete User"})]})]}),(0,r.jsx)(o.A,{user:s})]}),(0,r.jsxs)("section",{className:"paper",children:[p&&(0,r.jsx)(c.A,{}),(0,r.jsx)("div",{className:"w-full flex-col items-stretch",children:(0,r.jsxs)("form",{className:"flex flex-col items-stretch gap-4",onSubmit:e=>{e.preventDefault(),h(!0);let s=e.target,r=Array.from(s),l={};r.forEach(e=>{!e?.nodeName?.match(/button/i)&&e?.name&&e?.value?.match(/./)&&(e?.name?.match(/username|email/)||(l[e.name]=e.value))});let n={dbFullName:t.db_full_name,payload:{...l,id:a.id}};(0,i.A)("/api/updateDbUser",{method:"post",body:n},!0).then(e=>{g?.imageBase64?(g.imageName=`${t.db_slug}-user-${a.id}`,g.mimeType="jpeg",delete g.imageBase64Full,(0,i.A)("/api/addUserMedia",{method:"post",body:{media:[g],folder:t.db_slug.replace(/_/g,"-"),type:"image"}},!0).then(e=>{e&&e.mediaData&&e.mediaData[0]?.media_url?(0,i.A)("/api/updateDbUser",{method:"post",body:{dbFullName:t.db_full_name,payload:{id:a.id,image:e.mediaData[0].media_url,image_thumbnail:e.mediaData[0].media_thumbnail_url}}},!0).then(e=>{e.success&&window.location.reload(),setTimeout(()=>{h(!1)},500)}):window.location.reload()})):window.location.reload()})},children:[l.map((e,t)=>e?.match(/password|^database|email|username/)?(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("input",{type:"text",name:e,id:e,value:a[e],placeholder:e,className:"opacity-40 pointer-events-none",onChange:e=>{e.preventDefault()}},t+1)]},t+1):e?.match(/more_user_data/)?(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("textarea",{name:e,id:e,defaultValue:a[e]?a[e]:void 0,placeholder:e,rows:6},t+1)]},t+1):(0,r.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,r.jsx)("label",{htmlFor:e,children:e}),(0,r.jsx)("input",{type:"text",name:e,id:e,defaultValue:a[e]?a[e]:void 0,placeholder:e},t+1)]},t+1)),(0,r.jsxs)("div",{className:"border border-slate-300 dark:border-slate-600 border-solid bg-slate-100 dark:bg-slate-700 rounded p-6 flex-col items-start w-full",children:[(0,r.jsx)("h3",{className:"m-0 text-lg font-semibold mb-1 text-slate-600",children:"Update Image"}),(0,r.jsx)(u.A,{userImage:g,setUserImage:_,className:"w-full"})]}),(0,r.jsx)("button",{children:"Update User"})]})})]})]})}m=(p.then?(await p)():p)[0],s()}catch(e){s(e)}})},31651:(e,a,t)=>{t(81630);let s=t(77463);e.exports=async function({request:e,databaseSlug:a,user:t,query:r}){try{let l=t.id,n=null;if(!r?.delegated)return{dbUserId:l};let o=r.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${o}_${a}`,i=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[i])throw Error("Cookie not present");let t=s({encryptedString:e.cookies[i]});if(!t)throw Error("Invalid Token");if((n=JSON.parse(t)).databaseSlug===a)return{dbUserId:l=n.rootUserId,rootUserId:n.rootUserId,rootUserName:n.rootUserName,rootUserEmail:n.rootUserEmail,rootUserImage:n.rootUserImage,databaseFullName:n.databaseFullName,databaseSlug:n.databaseSlug,allowedTables:n.allowedTables,priviledges:n.priviledges,database:n.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:l}}catch(e){return null}}},96089:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]])},25088:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]])},72935:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("FileInput",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 15h10",key:"jfw4w8"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]])},71296:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("FolderOutput",[["path",{d:"M2 7.5V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-1.5",key:"1yk7aj"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m5 10-3 3 3 3",key:"1r8ie0"}]])},98136:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(82544).A)("SquareTerminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]])},68743:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},89545:(e,a,t)=>{let s=t(77463),r=t(68743);e.exports=async function({unparsedResults:e,tableSchema:a}){let t=[];try{for(let l=0;l",a.message),e}}},22373:(e,a,t)=>{let s=t(29021),{IncomingMessage:r}=t(81630);e.exports=async function({user:e,message:a,component:t,noMail:r,req:l}){let n=new Date,o=(()=>{if(!l)return null;try{let e=l.headers["x-forwarded-for"],a=l.headers["x-real-ip"],t=l.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||s||a||l.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let r=`🚀 SERVER ERROR =========================== Error Message: ${a} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(r+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),l?.url&&(r+=` URL: ${l.url}`),l?.body&&(r+=` Request Body: ${JSON.stringify(l.body,null,4)}`),o&&(r+=` IP: ${o}`),r+=` Date: ${n.toDateString()} ========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let d=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",r),s.appendFileSync("./.tmp/error.log",` ${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},90378:(e,a,t)=>{t(29021);let s=t(89545),r=t(22373),l=t(67216),n=t(1231),o=t(88896);e.exports=async function({queryString:e,queryValuesArray:a,database:t,tableSchema:d,useLocal:i}){let c;let u=!!t?.match(/^datasquirel$/),m=i?o:u?l:n;try{c=e&&a&&Array.isArray(a)&&a[0]?u?await m(e,a):await m({paradigm:"Full Access",database:t,queryString:e,queryValues:a}):u?await m(e):await m({paradigm:"Full Access",database:t,queryString:e})}catch(e){r({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(c&&d)try{let e=c;return await s({unparsedResults:e,tableSchema:d})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),r({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(c)return c;else return null}},1231:(e,a,t)=>{let s=t(29021);t(33873);let r=t(9973),l=t(31976),n=r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:l()}});e.exports=function({paradigm:e,database:a,queryString:t,queryValues:o}){try{return new Promise((d,i)=>{let c=!!e?.match(/full.access|^fa$/i);try{function u(e){n.end(),d(JSON.parse(JSON.stringify(e)))}function m(e){n.end(),d({error:e.message,queryStringGenerated:t,queryValuesGenerated:o,sql:e.sql})}n=c?r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:a,ssl:l()}}):r({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:a,ssl:l()}}),o&&Array.isArray(o)&&o[0]?n.query(t,o).then(u).catch(m):n.query(t).then(u).catch(m)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),d({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},88896:(e,a,t)=>{let s=t(9973),r=t(31976);async function l(...e){let a=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:r()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let t=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}e.exports=l},87730:(e,a,t)=>{t.a(e,async(e,s)=>{try{t.r(a),t.d(a,{SingleDbUserContext:()=>D,default:()=>f,getServerSideProps:()=>S});var r=t(8732),l=t(82015),n=t.n(l),o=t(95222),d=t(20048),i=t.n(d),c=t(64098),u=t(31651),m=t.n(u),p=t(95248),h=t(67216),g=t.n(h),_=t(90378),y=t.n(_),b=e([c,p]);[c,p]=b.then?(await b)():b;let x=t(29021),D=n().createContext({});function f({user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:n,confirmedDelegetedUser:d}){let i=`${l.first_name} ${l.last_name} Users | Datasquirel"`,u=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("title",{children:i}),(0,r.jsx)("meta",{name:"description",content:"Welcome to your data app"})]});return(0,r.jsx)(o.A,{head:u,user:e,extraHeaderContent:(0,r.jsx)(c.A,{database:a,query:n,confirmedDelegetedUser:d,user:e}),children:(0,r.jsx)(D.Provider,{value:{user:e,database:a,table:t,dbSchemaData:s,singleUser:l,query:n,confirmedDelegetedUser:d},children:(0,r.jsx)(p.A,{})})})}async function S({req:e,res:a,query:t}){let s=await i()(e,a);if(!s?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let r=await m()({request:e,user:s,databaseSlug:t.single,query:t});if(!r)return{redirect:{destination:"/admin",permanent:!1}};let{dbUserId:l,rootUserId:n}=r,o=await g()(`SELECT * FROM user_databases WHERE user_id='${l}' AND db_slug='${t.single}'`);if(!o||!o[0])return console.log("Database Not Found"),{redirect:{destination:`/admin/${s?.id}/databases`,permanent:!1}};let d=JSON.parse(x.readFileSync(`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,"utf-8")),c=(d.filter(e=>e.dbFullName===o[0].db_full_name)[0]?.tables).filter(e=>"users"===e.tableName)[0],u=await y()({database:o[0].db_full_name,queryString:`SELECT * FROM users WHERE id='${t.user}'`,tableSchema:c});return u?.[0]?{props:{user:s,database:o?.[0]||null,table:c||{},dbSchemaData:d,singleUser:u?.[0]||null,query:t,confirmedDelegetedUser:r}}:{redirect:{destination:`/admin/${s?.id}/databases/${o[0].db_slug}/users`,permanent:!1}}}s()}catch(e){s(e)}})}};