dsql-admin/dsql-app/.local_dist/server/pages/admin/[user_id]/api-keys.js
Benjamin Toby 6364f6a312 Updates
2024-12-15 12:57:19 +01:00

1 line
15 KiB
JavaScript

"use strict";(()=>{var e={};e.id=9419,e.ids=[9419],e.modules={30671:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,a){return a in t?t[a]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,a)):"function"==typeof t&&"default"===a?t:void 0}}})},30284:(e,t,a)=>{a.r(t),a.d(t,{config:()=>I,default:()=>F,getServerSideProps:()=>O,getStaticPaths:()=>z,getStaticProps:()=>D,reportWebVitals:()=>G,routeModule:()=>W,unstable_getServerProps:()=>$,unstable_getServerSideProps:()=>V,unstable_getStaticParams:()=>L,unstable_getStaticPaths:()=>R,unstable_getStaticProps:()=>H});var s,l={};a.r(l),a.d(l,{ApiKeysContext:()=>q,default:()=>T,getServerSideProps:()=>E});var i=a(63865),r=a(9455),n=a(30671),c=a(49407),d=a(89600),p=a(8732),o=a(82015),u=a.n(o),x=a(95222),h=a(20048),m=a.n(h),y=a(58548),f=a(55158),g=a(24671),j=a(63715),A=a(32415),v=a(62506);function b({apiKeyObject:e,setTargetApiKey:t}){let[a,s]=u().useState(!1);return(0,p.jsxs)("div",{className:"card no-hover justify-between items-center"+(e.scope.match(/fullAccess/)?" green":""),onClick:a=>{a.target?.closest("button")||(t(e),(0,f.PB)("target-media-popup"))},children:[a&&(0,p.jsx)(A.A,{width:"20px"}),(0,p.jsxs)("div",{className:"text-sm flex-wrap",children:[(0,p.jsx)("div",{children:e.scope.match(/readOnly/)?(0,p.jsx)("span",{className:"notification"}):e.scope.match(/fullAccess/)?(0,p.jsx)("span",{className:"notification success"}):"No Scope"}),(0,p.jsx)("span",{className:"title text-xl",style:{fontSize:"16px"},children:e.name}),(0,p.jsxs)("span",{className:"text-slate-400 ",children:["Created: ",e.date_created.substring(0,24)]})]}),(0,p.jsxs)(v.A,{children:[(0,p.jsx)("button",{className:"outlined light-gray small-text",onClick:t=>{alert(e.apiKeyPayload)},children:"Reveal Api Key"}),(0,p.jsx)("button",{className:"outlined light-gray small-text",onClick:t=>{navigator.clipboard.writeText(e.apiKeyPayload).then(()=>{alert("Api Key Copied To Clipboard")})},children:"Copy Api Key"}),(0,p.jsx)("button",{className:"outlined light-gray small-text"+(a?" pointer-events-none opacity-40":""),onClick:t=>{s(!0),window.confirm("Delete this Api Key?")?(0,j.A)("/api/deleteApiKey",{method:"post",body:e},!0).then(e=>{}).finally(()=>{window.location.reload()}):s(!1)},children:"Delete Api Key"})]})]})}function k({user:e,apiKeys:t,setTargetApiKey:a}){return(0,p.jsx)(u().Fragment,{children:(0,p.jsxs)("section",{className:"p-0 items-start gap-4 overflow-visible bg-transparent border-transparent",children:[(0,p.jsx)("div",{className:"w-full flex-col items-stretch gap-4",children:t&&t[0]&&t.map((e,t)=>(0,p.jsx)(b,{apiKeyObject:e,setTargetApiKey:a},t))}),!t||!t[0]&&(0,p.jsxs)("div",{className:"button outlined gray dashed w-full p-10 flex-col",onClick:e=>{(0,f.PB)("add-new-api-key-popup")},children:[(0,p.jsx)("span",{className:"text-slate-400",children:"No Api Keys Added."}),(0,p.jsx)("span",{className:"",children:"Add Api Key"})]})]})})}function _(e){let{user:t,apiKeys:a,setApiKeys:s,setTargetApiKey:l}=u().useContext(q);return(0,p.jsxs)(u().Fragment,{children:[(0,p.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,p.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,p.jsx)("h1",{className:"text-3xl m-0",children:"Api Keys"}),(0,p.jsxs)("button",{className:"flex items-center gap-2",onClick:e=>{(0,f.PB)("add-new-api-key-popup")},children:[(0,p.jsx)("span",{className:"symbol",children:"+"}),(0,p.jsx)("span",{children:"Add New Api Key"})]})]}),(0,p.jsx)(y.A,{user:t})]}),t?.verification_status?.toString().match(/1/)?(0,p.jsx)(k,{apiKeys:a,setTargetApiKey:l,user:t}):(0,p.jsx)(g.A,{})]})}function w({targetApiKey:e}){let[t,a]=u().useState(!1);return(0,p.jsxs)(f.Ay,{title:"target-api-key-preview-popup",noContainer:!0,fullPage:!0,children:[t&&(0,p.jsx)(A.A,{}),e&&(0,p.jsx)(u().Fragment,{children:(0,p.jsx)("span",{children:"Target Api Key"})})]})}var N=a(27462);function S({targetApiKey:e}){async function t(e){return await (0,N.A)({tableName:"api_keys",columnName:"slug",value:e})}let[a,l]=u().useState(!1),[i,r]=u().useState(null);return(0,p.jsxs)(f.Ay,{title:"add-new-api-key-popup",children:[a&&(0,p.jsx)(A.A,{}),(0,p.jsx)("h4",{className:"m-0",children:"Add New Api Key"}),(0,p.jsxs)("form",{className:"w-full flex flex-col items-stretch gap-2",onSubmit:e=>{e.preventDefault(),l(!0);let t=e.target,a={api_key_name:t.api_key_name.value,api_key_slug:t.api_key_slug.value,api_key_scope:t.api_key_scope.value,target_database:t.target_database?.value||void 0,target_table:t.target_table?.value||void 0};(0,j.A)("/api/addApiKey",{method:"post",body:a},!0).then(e=>{e.success?window.location.reload():setTimeout(()=>{l(!1)},2e3)})},children:[i&&(0,p.jsx)("div",{children:(0,p.jsx)("span",{children:i})}),(0,p.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,p.jsx)("label",{htmlFor:"api_key_name",children:"Api Key Name"}),(0,p.jsx)("input",{type:"text",name:"api_key_name",id:"api_key_name",placeholder:"Api Key Name",onInput:e=>{let t=e.target;t&&(t.closest("form").api_key_slug.value=t.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,""))},required:!0})]}),(0,p.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,p.jsx)("label",{htmlFor:"api_key_slug",children:"Api Key Slug"}),(0,p.jsx)("input",{type:"text",name:"api_key_slug",id:"api_key_slug",placeholder:"Api Key Slug",onInput:e=>{let a=e.target;a?.value.match(/./)?(a?.classList.remove("warning"),r(null)):a?.classList.add("warning"),window.clearTimeout(s),s=setTimeout(()=>{t(a.value).then(e=>{e.result?(a?.classList.add("warning"),r("Duplicate Table Name")):(a?.classList.remove("warning"),r(null))})},300)},required:!0})]}),(0,p.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,p.jsxs)("div",{className:"",children:[(0,p.jsx)("label",{htmlFor:"api_key_scope",children:"Api Scope"}),(0,p.jsxs)("div",{className:"dropdown-wrapper reversed",children:[(0,p.jsx)("span",{className:"px-2 py-1 bg-slate-100 rounded-full text-xs font-semibold",children:"Info"}),(0,p.jsx)("div",{className:"dropdown always left-aligned -ml-10 -mb-2",style:{minWidth:"300px"},children:(0,p.jsxs)("div",{className:"flex-col items-start gap-2 text-sm leading-snug",children:[(0,p.jsx)("span",{children:"Scope is the range of access the API Key can have"}),(0,p.jsxs)("ul",{className:"ml-0 pl-4 flex flex-col gap-2",children:[(0,p.jsx)("li",{children:(0,p.jsxs)("span",{children:[(0,p.jsx)("b",{children:"Read Only:"})," Can only read from databases"]})}),(0,p.jsx)("li",{children:(0,p.jsxs)("span",{children:[(0,p.jsx)("b",{children:"Full Access:"})," Can read and Write to databases"]})})]})]})})]})]}),(0,p.jsxs)("select",{name:"api_key_scope",id:"api_key_scope",children:[(0,p.jsx)("option",{value:"readOnly",children:"Read Only"}),(0,p.jsx)("option",{value:"fullAccess",children:"Full Access"})]})]}),(0,p.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,p.jsx)("label",{htmlFor:"target_database",children:"Target Databases"}),(0,p.jsx)("input",{type:"text",name:"target_database",id:"target_database",placeholder:"Target Databases (optional). Comma Separated"})]}),(0,p.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,p.jsx)("label",{htmlFor:"target_table",children:"Target Tables"}),(0,p.jsx)("input",{type:"text",name:"target_table",id:"target_table",placeholder:"Target Tables (optional). Comma Separated"})]}),(0,p.jsx)("button",{type:"submit",className:a?" pointer-events-none opacity-40":"",children:"Create New Api Key"})]})]})}var P=a(67216),M=a.n(P),C=a(77463),K=a.n(C);let q=u().createContext({});function T({user:e,fetchedApiKeys:t}){let a=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)("title",{children:"Api Keys | Datasquirel"}),(0,p.jsx)("meta",{name:"description",content:"Welcome to your data app"})]}),[s,l]=u().useState(t),[i,r]=u().useState(null),[n,c]=u().useState(null);return(0,p.jsx)(q.Provider,{value:{user:e,apiKeys:s,setApiKeys:l,targetApiKey:n,setTargetApiKey:c,newApiKey:i,setNewApiKey:r},children:(0,p.jsxs)(u().Fragment,{children:[(0,p.jsx)(x.A,{head:a,user:e,children:(0,p.jsx)(_,{})}),n&&(0,p.jsx)(w,{targetApiKey:n}),(0,p.jsx)(S,{})]})})}async function E({req:e,res:t,query:a}){let s=await m()(e,t);if(!s?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let l=await M()(`SELECT * FROM api_keys WHERE user_id='${s.id}'`),i=[];if(l&&l[0])for(let e=0;e<l.length;e++){let t=l[e],a=K()({encryptedString:t.key});i.push({...t,apiKeyPayload:a})}return{props:{user:s,fetchedApiKeys:i}}}let F=(0,n.M)(l,"default"),D=(0,n.M)(l,"getStaticProps"),z=(0,n.M)(l,"getStaticPaths"),O=(0,n.M)(l,"getServerSideProps"),I=(0,n.M)(l,"config"),G=(0,n.M)(l,"reportWebVitals"),H=(0,n.M)(l,"unstable_getStaticProps"),R=(0,n.M)(l,"unstable_getStaticPaths"),L=(0,n.M)(l,"unstable_getStaticParams"),$=(0,n.M)(l,"unstable_getServerProps"),V=(0,n.M)(l,"unstable_getServerSideProps"),W=new i.PagesRouteModule({definition:{kind:r.A.PAGES,page:"/admin/[user_id]/api-keys",pathname:"/admin/[user_id]/api-keys",bundlePath:"",filename:""},components:{App:d.default,Document:c.default},userland:l})},55158:(e,t,a)=>{a.d(t,{Ay:()=>n,PB:()=>c,fs:()=>d});var s=a(8732),l=a(58150),i=a(82015),r=a.n(i);function n({children:e,title:t,data:a,fullPage:i,wrapperClasses:n,closePopupDispatch:c,wrapperStyle:p,noContainer:o}){return i?(0,s.jsxs)("div",{className:"popup-bg overflow-hidden "+(n||""),"data-popupid":t||null,style:p,children:[o?(0,s.jsx)(r().Fragment,{children:e}):(0,s.jsx)("div",{className:"relative w-full h-full z-50","data-data":a?JSON.stringify(a):"",children:e}),(0,s.jsx)("button",{className:"popup-cancel-button fixed outlined gray",onClick:e=>{d(),c&&c()},children:(0,s.jsx)(l.A,{color:"white",size:20})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{d(),c&&c()}})]}):(0,s.jsxs)("div",{className:"popup-bg","data-popupid":t||null,children:[o?(0,s.jsx)(r().Fragment,{children:e}):(0,s.jsxs)("div",{className:"popup-content-container minimal-scrollbars","data-data":a?JSON.stringify(a):"",children:[e,(0,s.jsx)("button",{className:"outlined gray popup-cancel-button",onClick:e=>{d(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})})]}),o&&(0,s.jsx)("button",{className:"gray popup-cancel-button",onClick:e=>{d(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{d(),c&&c()}})]})}function c(e,t){let a=document.querySelector(`[data-popupid='${e}']`);a&&(a.style.display="flex",t&&t(a))}function d(e){document.querySelectorAll("[data-popupid]").forEach(e=>{e.style.display="none"}),e&&e()}},24671:(e,t,a)=>{a.d(t,{A:()=>l});var s=a(8732);function l(e){return(0,s.jsxs)("a",{href:"/email-verification",className:"card w-full items-center justify-center py-4 gap-2",children:[(0,s.jsx)("img",{src:"/images/warning.png",alt:"Down Arrow",width:25,className:""}),(0,s.jsx)("span",{children:"Your Account is not verified. Please verify your account."})]})}a(82015)},62506:(e,t,a)=>{a.d(t,{A:()=>r});var s=a(8732),l=a(82015),i=a.n(l);function r({children:e,column:t,className:a}){let l=i().useRef();return(0,s.jsx)("div",{className:"items-stretch gap-0"+(t?" flex-col":" flex-wrap xl:flex-nowrap")+(a?" "+a:""),ref:l,children:e})}},27462:(e,t,a)=>{a.d(t,{A:()=>l}),a(22326);var s=a(63715);async function l({tableName:e,columnName:t,value:a,dbFullName:l,dispatch:i,userId:r,dbId:n}){return await (0,s.A)(`/api/checkDuplicateData?tableName=${e}&type=${t}&value=${a}${l?"&dbFullName="+l:""}${r?"&userId="+r:""}${n?"&dbId="+n:""}`)}},23293:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},92441:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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"}]])},34637:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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"}]])},29743:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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"}]])},10643:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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"}]])},25294:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(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"}]])},58150:(e,t,a)=>{a.d(t,{A:()=>s});let s=(0,a(82544).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},9455:(e,t)=>{var a;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return a}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(a||(a={}))},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},82015:e=>{e.exports=require("react")},22326:e=>{e.exports=require("react-dom")},8732:e=>{e.exports=require("react/jsx-runtime")},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")}};var t=require("../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),s=t.X(0,[883,9821,9600,7070],()=>a(30284));module.exports=s})();