veza/apps/web/dist_verification/assets/DeveloperDashboardView-Dkv7ps0m.js

77 lines
18 KiB
JavaScript
Raw Normal View History

2026-02-07 19:36:48 +00:00
import{a as d,c as F,j as e}from"./vendor-react-YMhRUmcb.js";import{g as M,d as S,B as g,l as k,i as f,m as O,C as P}from"./index-D2uzyr9g.js";import{S as _}from"./StatCard-Xzk79Siz.js";import{I as G}from"./input-DL1WY4HG.js";import{ar as E,X as B,i as C,C as V,g as R,A as H,R as J,b7 as W,aa as X,aW as K,b1 as Y,az as q,aM as Q,T as A}from"./vendor-icons-DINCNwpk.js";import{w as Z}from"./webhookService-BUZkpEvD.js";import{T as ee,a as te,b as U,c as D}from"./Tabs-C8UCeQNW.js";import{X as se}from"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";const ae=[{id:"user.read",label:"Read User Data"},{id:"user.write",label:"Update User Profile"},{id:"tracks.read",label:"Read Tracks"},{id:"tracks.upload",label:"Upload Tracks"},{id:"sales.read",label:"Read Sales Data"}],oe=({onClose:t,onCreate:n})=>{const a=M(),[o,h]=d.useState(1),[x,m]=d.useState(""),[l,u]=d.useState(["user.read"]),[b,w]=d.useState(""),[i,s]=d.useState(!1),[c,j]=d.useState(!1);d.useEffect(()=>(j(!0),()=>j(!1)),[]);const z=r=>{u(p=>p.includes(r)?p.filter(N=>N!==r):[...p,r])},L=async r=>{if(r?.preventDefault(),r?.stopPropagation(),!x.trim()){a.error("Please enter a name for your API key");return}if(l.length===0){a.error("Please select at least one permission scope");return}s(!0);try{const p=await n({name:x.trim(),scopes:l});if(p.key)w(p.key);else{const N=`vz_${Math.random().toString(36).substr(2,8)}_${Math.random().toString(36).substr(2,16)}`;w(N)}h(2),s(!1)}catch(p){throw s(!1),p}},$=()=>{navigator.clipboard.writeText(b),a.success("API Key copied to clipboard")};return c?F.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",style:{zIndex:9999},children:[e.jsx("div",{className:"absolute inset-0 bg-kodo-void/90 backdrop-blur-md",onClick:o===1?t:void 0}),e.jsxs("div",{className:"relative w-full max-w-2xl bg-kodo-graphite border border-kodo-steel rounded-xl shadow-2xl animate-scaleIn overflow-hidden glass-hud flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-kodo-steel/50 flex justify-between items-center bg-white/5 flex-none z-10",children:[e.jsxs("h3",{className:"text-xl font-bold text-white flex items-center gap-3 font-display",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-kodo-gold/20 flex items-center justify-center border border-kodo-gold/30",children:e.jsx(E,{className:"w-5 h-5 text-kodo-gold"})}),o===1?"Create API Key":"API Key Generated"]}),e.jsx("button",{onClick:t,className:"p-2 hover:bg-white/10 rounded-lg transition-colors",children:e.jsx(B,{className:"w-5 h-5 text-kodo-content-dim hover:text-white"})})]}),e.jsx("div",{className:"p-8 overflow-y-auto custom-scrollbar flex-1 relative",children:o===1?e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-kodo-secondary uppercase tracking-wider mb-3",children:"Key Name"}),e.jsx(G,{placeholder:"e.g. Production Server, Mobile App",value:x,onChange:r=>m(r.target.value),autoFocus:!0,disabled:i,className:"bg-kodo-void/50 border-kodo-steel focus:border-kodo-cyan h-12 text-lg w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-kodo-secondary uppercase tracking-wider mb-4",children:"Permissions (Scopes)"}),e.jsx("div",{className:"grid grid-cols-1 gap-3",children:ae.map(r=>e.jsxs("label",{className:S("flex items-center justify-between p-4 rounded-xl border cursor-pointer transition-all duration-200 group relative overflow-hidden",l.includes(r.id)?"bg-kodo-cyan/10 border-kodo-cyan/50 shadow-[0_0_15px_rgba(102,252,241,0.1)]":"bg-kodo-void/30 border-kodo-steel/50 hover:border-kodo-steel hover:bg-white/5"),children:[e.jsxs("div",{className:"flex items-center gap-4 z-10 relative",children:[e.jsx("div",{className:S("w-5 h-5 rounded border flex items-center justify-center transition-colors flex-none",l.includes(r.id)?"bg-kodo-cyan border-kodo-cyan":"border-kodo-steel group-hover:border-kodo-content-dim"),children:l.includes(r.id)&&e.jsx(C,{classN
.swagger-ui-container .swagger-ui {
background: transparent;
}
.swagger-ui-container .swagger-ui .topbar {
display: none;
}
.swagger-ui-container .swagger-ui .info {
margin: 20px 0;
}
.swagger-ui-container .swagger-ui .info .title {
color: #fff;
}
.swagger-ui-container .swagger-ui .scheme-container {
background: rgba(255, 255, 255, 0.05);
padding: 10px;
border-radius: 8px;
margin: 20px 0;
}
.swagger-ui-container .swagger-ui .opblock {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
margin: 10px 0;
}
.swagger-ui-container .swagger-ui .opblock.opblock-post {
border-color: rgba(102, 252, 241, 0.3);
}
.swagger-ui-container .swagger-ui .opblock.opblock-get {
border-color: rgba(102, 252, 241, 0.3);
}
.swagger-ui-container .swagger-ui .opblock.opblock-put {
border-color: rgba(255, 193, 7, 0.3);
}
.swagger-ui-container .swagger-ui .opblock.opblock-delete {
border-color: rgba(244, 67, 54, 0.3);
}
.swagger-ui-container .swagger-ui .opblock .opblock-summary {
color: #fff;
}
.swagger-ui-container .swagger-ui .opblock .opblock-description-wrapper {
color: rgba(255, 255, 255, 0.8);
}
.swagger-ui-container .swagger-ui .parameter__name {
color: #66fcf1;
}
.swagger-ui-container .swagger-ui .response-col_status {
color: #fff;
}
.swagger-ui-container .swagger-ui .response-col_description {
color: rgba(255, 255, 255, 0.8);
}
.swagger-ui-container .swagger-ui input,
.swagger-ui-container .swagger-ui select,
.swagger-ui-container .swagger-ui textarea {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: #fff;
}
.swagger-ui-container .swagger-ui .btn {
background: #66fcf1;
color: #000;
border: none;
}
.swagger-ui-container .swagger-ui .btn:hover {
background: #52e8e0;
}
.swagger-ui-container .swagger-ui .btn.execute {
background: #66fcf1;
color: #000;
}
.swagger-ui-container .swagger-ui .btn.cancel {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
`}),e.jsx(se,{...b})]})}const pe=()=>{const{addToast:t}=O(),[n,a]=d.useState([]),[o,h]=d.useState(!0),[x,m]=d.useState({}),[l,u]=d.useState(!1);d.useEffect(()=>{(async()=>{h(!0);try{const[c,j]=await Promise.all([y.listKeys(),y.getStats()]);a(c),m(j)}catch(c){k.error("Error loading developer dashboard data",{error:c instanceof Error?c.message:String(c),stack:c instanceof Error?c.stack:void 0})}finally{h(!1)}})()},[]);const b=async s=>{try{const c=await y.createKey(s);a([c,...n]),t("API Key created successfully","success")}catch{t("Failed to create API key","error")}},w=async s=>{if(confirm("Are you sure you want to revoke this key?")){await y.revokeKey(s);const c=await y.listKeys();a(c),t("API Key revoked","info")}},i=async s=>{confirm("Are you sure you want to delete this key permanently?")&&(await y.deleteKey(s),a(n.filter(c=>c.id!==s)),t("API Key deleted","info"))};return o?e.jsx("div",{className:"flex justify-center py-24",children:e.jsx(R,{className:"w-10 h-10 text-kodo-steel animate-spin"})}):e.jsxs("div",{className:"space-y-8 animate-fadeIn pb-20",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-end gap-4 border-b border-kodo-steel/50 pb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold text-white mb-2",children:"DEVELOPER PORTAL"}),e.jsx("p",{className:"text-kodo-content-dim font-mono text-sm",children:"Build on top of the Veza Platform."})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{variant:"secondary",icon:e.jsx(W,{className:"w-4 h-4"}),onClick:()=>window.open("https://docs.veza.io","_blank"),children:"Documentation"}),e.jsx(g,{variant:"primary",icon:e.jsx(X,{className:"w-4 h-4"}),onClick:()=>u(!0),children:"Create API Key"})]})]}),e.jsxs(ee,{defaultValue:"overview",className:"w-full",children:[e.jsxs(te,{className:"grid w-full grid-cols-2 mb-8",children:[e.jsxs(U,{value:"overview",className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-4 h-4"}),"Overview & Keys"]}),e.jsxs(U,{value:"docs",className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"API Documentation"]})]}),e.jsxs(D,{value:"overview",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[e.jsx(_,{label:"API Requests (24h)",value:x.requests_24h?.toLocaleString()||0,icon:e.jsx(K,{className:"w-5 h-5"}),trend:5.2,color:"cyan"}),e.jsx(_,{label:"Avg Latency",value:`${x.avg_latency||0}ms`,icon:e.jsx(q,{className:"w-5 h-5"}),trend:-12,color:"lime"}),e.jsx(_,{label:"Active Keys",value:n.length,icon:e.jsx(E,{className:"w-5 h-5"}),color:"gold"})]}),e.jsxs(P,{variant:"default",children:[e.jsx("h3",{className:"font-bold text-white mb-6",children:"Active API Keys"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-kodo-content-dim uppercase border-b border-kodo-steel/50",children:[e.jsx("th",{className:"pb-3 pl-4",children:"Name"}),e.jsx("th",{className:"pb-3",children:"Key Prefix"}),e.jsx("th",{className:"pb-3",children:"Created"}),e.jsx("th",{className:"pb-3",children:"Last Used"}),e.jsx("th",{className:"pb-3 text-right pr-4",children:"Actions"})]})}),e.jsxs("tbody",{className:"text-sm",children:[n.map(s=>e.jsxs("tr",{className:"border-b border-kodo-steel/20 hover:bg-white/5 transition-colors",children:[e.jsx("td",{className:"py-4 pl-4 font-bold text-white",children:s.name}),e.jsx("td",{className:"py-4 font-mono text-kodo-gold",children:s.prefix}),e.jsx("td",{className:"py-4 text-kodo-content-dim",children:s.created}),e.jsx("td",{className:"py-4 text-kodo-text-main",children:s.lastUsed}),e.jsxs("td",{className:"py-4 text-right pr-4 flex justify-end gap-2",children:[e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-kodo-content-dim hover:text-white",onClick:()=>t("Full key hidden for security"),title:"View Key",children:e.jsx(Q,{className:"w-4 h-4"})}),s.status==="active"?e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-kodo-red hover:bg-kodo-red/10",onClick:()=>w