"use strict";exports.id=3474,exports.ids=[3474],exports.modules={30671:(e,a)=>{Object.defineProperty(a,"M",{enumerable:!0,get:function(){return function e(a,t){return t in a?a[t]:"then"in a&&"function"==typeof a.then?a.then(a=>e(a,t)):"function"==typeof a&&"default"===t?a:void 0}}})},92090:(e,a,t)=>{t.a(e,async(e,r)=>{try{t.d(a,{A:()=>h});var l=t(8732),s=t(82015),n=t.n(s),i=t(53926),d=t(59023),o=t(46169),c=t(16757),u=t(20136),m=t(50264),p=e([m]);function h(){let{singleUser:e,database:a,user:t}=n().useContext(m.SingleDbUserContext),r=Object.keys(e).filter(e=>!e.match(/^id$|^date_|^user_id$|^social_|^disk_usage|user_type/)),[s,p]=n().useState(!1),[h,y]=n().useState(e.image);return(0,l.jsxs)(n().Fragment,{children:[(0,l.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,l.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)(d.A,{}),h&&"string"==typeof h&&(0,l.jsx)("img",{src:h,alt:"",className:"avatar large outlined"}),(0,l.jsxs)("h1",{className:"text-3xl m-0",children:[e.first_name," ",e.last_name]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("a",{href:`/admin/${t?.id}/databases/${a.db_slug}/users/${e.id}/change-password`,className:"button outlined gray",children:"Change Password"}),(0,l.jsx)("button",{className:"bg-red-500",onClick:r=>{p(!0),window.confirm("Delete this user?")&&(0,o.A)("/api/deleteDbUser",{method:"post",body:{userId:e.id,dbFullName:a.db_full_name}},!0).then(e=>{e.success&&(window.location.pathname=`/admin/${t?.id}/databases/${a.db_slug}/users`)})},children:"Delete User"})]})]}),(0,l.jsx)(i.A,{user:t})]}),(0,l.jsxs)("section",{className:"paper",children:[s&&(0,l.jsx)(c.A,{}),(0,l.jsx)("div",{className:"w-full flex-col items-stretch",children:(0,l.jsxs)("form",{className:"flex flex-col items-stretch gap-4",onSubmit:t=>{t.preventDefault(),p(!0);let r=t.target,l=Array.from(r),s={};l.forEach(e=>{!e?.nodeName?.match(/button/i)&&e?.name&&e?.value?.match(/./)&&(e?.name?.match(/username|email/)||(s[e.name]=e.value))});let n={dbFullName:a.db_full_name,payload:{...s,id:e.id}};(0,o.A)("/api/updateDbUser",{method:"post",body:n},!0).then(t=>{"object"==typeof h&&h?.imageBase64?(h.imageName=`${a.db_slug}-user-${e.id}`,h.mimeType="jpeg",delete h.imageBase64Full,(0,o.A)("/api/addUserMedia",{method:"post",body:{media:[h],folder:a.db_slug.replace(/_/g,"-"),type:"image"}},!0).then(t=>{t&&t.mediaData&&t.mediaData[0]?.media_url?(0,o.A)("/api/updateDbUser",{method:"post",body:{dbFullName:a.db_full_name,payload:{id:e.id,image:t.mediaData[0].media_url,image_thumbnail:t.mediaData[0].media_thumbnail_url}}},!0).then(e=>{e.success&&window.location.reload(),setTimeout(()=>{p(!1)},500)}):window.location.reload()})):window.location.reload()})},children:[r.map((a,t)=>a?.match(/password|^database|email|username/)?(0,l.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,l.jsx)("label",{htmlFor:a,children:a}),(0,l.jsx)("input",{type:"text",name:a,id:a,value:e[a],placeholder:a,className:"opacity-40 pointer-events-none",onChange:e=>{e.preventDefault()}},t+1)]},t+1):a?.match(/more_user_data/)?(0,l.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,l.jsx)("label",{htmlFor:a,children:a}),(0,l.jsx)("textarea",{name:a,id:a,defaultValue:e[a]?e[a]:void 0,placeholder:a,rows:6},t+1)]},t+1):(0,l.jsxs)("div",{className:"flex-col items-start w-full gap-1",children:[(0,l.jsx)("label",{htmlFor:a,children:a}),(0,l.jsx)("input",{type:"text",name:a,id:a,defaultValue:e[a]?e[a]:void 0,placeholder:a},t+1)]},t+1)),(0,l.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,l.jsx)("h3",{className:"m-0 text-lg font-semibold mb-1 text-slate-600",children:"Update Image"}),(0,l.jsx)(u.A,{userImage:h,setUserImage:y})]}),(0,l.jsx)("button",{children:"Update User"})]})})]})]})}m=(p.then?(await p)():p)[0],r()}catch(e){r(e)}})},20136:(e,a,t)=>{t.d(a,{A:()=>i});var r=t(8732),l=t(82015),s=t.n(l),n=t(65842);function i({user:e,userImage:a,setUserImage:t,database:l,className:i}){let d=s().useRef();return(0,r.jsxs)("div",{className:"card no-hover col"+(i?" "+i:""),children:[(0,r.jsx)("div",{className:"bg-white rounded-full overflow-hidden w-24 h-24",children:(0,r.jsx)("img",{src:a?"string"==typeof a?a:a.imageBase64Full:"/images/user-preset.png",alt:"Database Image",width:100,className:"w-full h-full object-cover",ref:d,"data-imagepreview":"image"})}),(0,r.jsxs)("div",{className:"w-full flex-col image-selector-wrapper",children:[(0,r.jsx)("div",{className:"button outlined secondary w-full whitespace-normal",onClick:e=>{e.target.closest(".image-selector-wrapper").querySelector("input").click()},children:"Upload Image"}),(0,r.jsx)("input",{type:"file",accept:".png,.jpg,.jpeg,.webp",placeholder:"Choose Database Image",className:"hidden",onChange:async e=>{let a=e.target.files?.[0];if(a){let e=await (0,n.A)({imageInputFile:a,maxWidth:400});t?.(e)}else window.alert("No File Provided!")}})]})]})}},22873:(e,a,t)=>{t.d(a,{A:()=>l});var r=t(71205);async function l({request:e,databaseSlug:a,user:t,query:l}){try{let s=t.id,n=null;if(!l?.delegated)return{dbUserId:s};let i=l.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${i}_${a}`,o=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[o])throw Error("Cookie not present");let t=(0,r.A)({encryptedString:e.cookies[o]});if(!t)throw Error("Invalid Token");if((n=JSON.parse(t)).databaseSlug===a)return{dbUserId:s=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:s}}catch(e){return null}}},65842:(e,a,t)=>{t.d(a,{A:()=>l});var r=t(76102);let l=t.n(r)().media.imageInputFileToBase64},23293:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},92441:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("BookText",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20",key:"t4utmx"}],["path",{d:"M8 7h6",key:"1f0q6e"}],["path",{d:"M8 11h8",key:"vwpz6n"}]])},96089:(e,a,t)=>{t.d(a,{A:()=>r});let r=(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"}]])},34637:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]])},25088:(e,a,t)=>{t.d(a,{A:()=>r});let r=(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:()=>r});let r=(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"}]])},29743:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("FileKey2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v6",key:"rc0qvx"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"4",cy:"16",r:"2",key:"1ehqvc"}],["path",{d:"m10 10-4.5 4.5",key:"7fwrp6"}],["path",{d:"m9 11 1 1",key:"wa6s5q"}]])},71296:(e,a,t)=>{t.d(a,{A:()=>r});let r=(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"}]])},10643:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]])},66916:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]])},83158:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},66918:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},10321:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("ShieldEllipsis",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]])},98136:(e,a,t)=>{t.d(a,{A:()=>r});let r=(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"}]])},25294:(e,a,t)=>{t.d(a,{A:()=>r});let r=(0,t(82544).A)("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]])},77047:(e,a,t)=>{t.d(a,{A:()=>s});var r=t(29021),l=t.n(r);async function s({user:e,message:a,component:t,noMail:r,req:s}){let n=new Date,i=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],a=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],r=Array.isArray(e)?e[0]:e?.split(",")[0],l=t||r||a||s.socket.remoteAddress;if(!l)return null;return String(l)}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}`),s?.url&&(r+=` URL: ${s.url}`),s?.body&&(r+=` Request Body: ${JSON.stringify(s.body,null,4)}`),i&&(r+=` IP: ${i}`),r+=` Date: ${n.toDateString()} ========================================`,l().existsSync("./.tmp/error.log")||l().writeFileSync("./.tmp/error.log","","utf-8");let d=l().readFileSync("./.tmp/error.log","utf-8");l().writeFileSync("./.tmp/error.log",r),l().appendFileSync("./.tmp/error.log",` ${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},52854:(e,a,t)=>{t.d(a,{A:()=>c});var r=t(71205);let l=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function s({unparsedResults:e,tableSchema:a}){let t=[];try{for(let s=0;s",a.message),e}}var n=t(77047),i=t(71934),d=t(43651),o=t(16175);async function c({queryString:e,queryValuesArray:a,database:t,tableSchema:r,useLocal:l}){let c;let u=!!l||!!t?.match(/^datasquirel$/),m=l?o.A:u?i.A:d.A;try{c=e&&a&&Array.isArray(a)&&a[0]?u?await m(e,a):await m({paradigm:"Full Access",queryString:e,queryValues:a}):u?await m(e):await m({paradigm:"Full Access",queryString:e})}catch(e){console.log(`varDatabaseDbHandler Error: ${e.message}`),(0,n.A)({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(c&&r)try{let e=c;return await s({unparsedResults:e,tableSchema:r})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,n.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(c)return c;else return null}},43651:(e,a,t)=>{async function r(e,a,t){try{if("string"==typeof a){let r=await e.query(l(a),t);return JSON.parse(JSON.stringify(r))}if("object"!=typeof a)return null;{let t=[];for(let r=0;rs})},16175:(e,a,t)=>{t.d(a,{A:()=>i});var r=t(9973),l=t.n(r),s=t(29021),n=t.n(s);async function i(...e){let a=l()({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:function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let a=`${e}/ca-cert.pem`;if(!n().existsSync(a)){console.log(`${a} does not exist`);return}return{ca:n().readFileSync(`${e}/ca-cert.pem`),rejectUnauthorized:!1}}()},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}}}},50264:(e,a,t)=>{t.a(e,async(e,r)=>{try{t.r(a),t.d(a,{SingleDbUserContext:()=>x,default:()=>f,getServerSideProps:()=>b});var l=t(8732),s=t(29021),n=t.n(s),i=t(82015),d=t.n(i),o=t(25562),c=t(92702),u=t(55880),m=t(22873),p=t(92090),h=t(71934),y=t(52854),g=e([u,p]);[u,p]=g.then?(await g)():g;let x=d().createContext({});function f({user:e,database:a,table:t,dbSchemaData:r,singleUser:s,query:n,confirmedDelegetedUser:i}){let d=`${s.first_name} ${s.last_name} Users | Datasquirel"`,c=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("title",{children:d}),(0,l.jsx)("meta",{name:"description",content:"Welcome to your data app"})]});return(0,l.jsx)(o.A,{head:c,user:e,extraHeaderContent:(0,l.jsx)(u.A,{database:a,query:n,confirmedDelegetedUser:i,user:e}),children:(0,l.jsx)(x.Provider,{value:{user:e,database:a,table:t,dbSchemaData:r,singleUser:s,query:n,confirmedDelegetedUser:i},children:(0,l.jsx)(p.A,{})})})}async function b({req:e,res:a,query:t}){let r=await (0,c.default)(e,a);if(!r?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let l=await (0,m.A)({request:e,user:r,databaseSlug:t.single,query:t});if(!l)return{redirect:{destination:"/admin",permanent:!1}};let{dbUserId:s,rootUserId:i}=l,d=await (0,h.A)(`SELECT * FROM user_databases WHERE user_id='${s}' AND db_slug='${t.single}'`);if(!d||!d[0])return console.log("Database Not Found"),{redirect:{destination:`/admin/${r?.id}/databases`,permanent:!1}};let o=JSON.parse(n().readFileSync(`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s}/main.json`,"utf-8")),u=(o.filter(e=>e.dbFullName===d[0].db_full_name)[0]?.tables).filter(e=>"users"===e.tableName)[0],p=await (0,y.A)({database:d[0].db_full_name,queryString:`SELECT * FROM ${d[0].db_full_name}.users WHERE id='${t.user}'`,tableSchema:u});return p?.[0]?{props:{user:r,database:d?.[0]||null,table:u||{},dbSchemaData:o,singleUser:p?.[0]||null,query:t,confirmedDelegetedUser:l}}:{redirect:{destination:`/admin/${r?.id}/databases/${d[0].db_slug}/users`,permanent:!1}}}r()}catch(e){r(e)}})},9455:(e,a)=>{Object.defineProperty(a,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})}};