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

77 lines
21 KiB
JavaScript
Raw Normal View History

import{a as i,c as J,j as e}from"./vendor-react-Dkpvlwai.js";import{g as X,d as E,B as x,l as S,i as N,S as y,n as W,E as Y,C as L,b as q,c as Q,e as Z,k as ee}from"./index-jE2AGx2y.js";import{S as _}from"./StatCard-5r7CYk9-.js";import{I as se}from"./input-CpxrTzwP.js";import{u as M}from"./useCopyToClipboard-BsHfBITc.js";import{au as A,X as re,i as U,e as G,L as te,a as ae,R as oe,be as ne,ae as le,b1 as $,b8 as ie,aG as ce,aF as de,T as z}from"./vendor-icons-CbmLcMl-.js";import{w as ue}from"./webhookService-BgsiUSts.js";import{T as ge,a as me,b as F,c as O}from"./Tabs-DcqFJUlH.js";import{X as xe}from"./vendor-CAoAb3tF.js";import"./vendor-router-4bycex72.js";import"./vendor-tanstack-BoI3DtL9.js";import"./vendor-utils-CDFfoeXY.js";import"./AnimatedNumber-Dt_wg-GW.js";const he=[{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"}],fe=({onClose:s,onCreate:c})=>{const n=X(),[a,m]=i.useState(1),[u,h]=i.useState(""),[l,b]=i.useState(["user.read"]),[f,v]=i.useState(""),[o,g]=i.useState(!1),[p,I]=i.useState(!1),j=i.useRef(null),{copied:D,copy:R}=M(),P=i.useCallback(()=>{if(typeof window>"u"||!j.current)return;const t=document.createRange();t.selectNodeContents(j.current),window.getSelection()?.removeAllRanges(),window.getSelection()?.addRange(t)},[]);i.useEffect(()=>(I(!0),()=>I(!1)),[]);const r=t=>{b(w=>w.includes(t)?w.filter(K=>K!==t):[...w,t])},d=async t=>{if(t?.preventDefault(),t?.stopPropagation(),!u.trim()){n.error("Please enter a name for your API key");return}if(l.length===0){n.error("Please select at least one permission scope");return}g(!0);try{const w=await c({name:u.trim(),scopes:l}),K=w?.key??w?.api_key;if(K)v(K);else{const H=`vz_${Math.random().toString(36).substr(2,8)}_${Math.random().toString(36).substr(2,16)}`;v(H)}m(2),g(!1)}catch(w){throw g(!1),w}},V=async t=>{if(t?.preventDefault(),t?.stopPropagation(),!f)return;await R(f)?n.success("API Key copied to clipboard"):n.error("Copy failed. Select the key above and copy manually (Ctrl+C).")};return p?J.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-background/90 backdrop-blur-md",onClick:a===1?s:void 0}),e.jsxs("div",{className:"relative w-full max-w-2xl bg-card border border-border rounded-xl shadow-2xl animate-scaleIn overflow-hidden glass-hud flex flex-col max-h-layout-modal",children:[e.jsxs("div",{className:"p-6 border-b border-border/50 flex justify-between items-center bg-foreground/5 flex-none z-10",children:[e.jsxs("h3",{className:"text-xl font-bold text-foreground flex items-center gap-3 font-heading",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-warning/20 flex items-center justify-center border border-warning/30",children:e.jsx(A,{className:"w-5 h-5 text-warning"})}),a===1?"Create API Key":"API Key Generated"]}),e.jsx("button",{onClick:s,className:"p-2 hover:bg-foreground/10 rounded-lg transition-colors",children:e.jsx(re,{className:"w-5 h-5 text-muted-foreground hover:text-foreground"})})]}),e.jsx("div",{className:"p-8 overflow-y-auto custom-scrollbar flex-1 relative",children:a===1?e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-muted-foreground uppercase tracking-wider mb-3",children:"Key Name"}),e.jsx(se,{placeholder:"e.g. Production Server, Mobile App",value:u,onChange:t=>h(t.target.value),autoFocus:!0,disabled:o,className:"bg-background/50 border-border focus:border-primary h-12 text-lg w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-muted-foreground uppercase tracking-wider mb-4",children:"Permissions (Scopes)"}),e.jsx("div",{className:"grid grid-cols-1 gap-3",children:he.map(t=>e.jsxs("label",{className:E("flex items-center justify-between p-4 rounded-xl border cursor-pointer transition-all duration-[var(--duration-fast)] group relative o
.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: #7c9dd6;
}
.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: #7c9dd6;
color: #000;
border: none;
}
.swagger-ui-container .swagger-ui .btn:hover {
background: #93afe0;
}
.swagger-ui-container .swagger-ui .btn.execute {
background: #7c9dd6;
color: #000;
}
.swagger-ui-container .swagger-ui .btn.cancel {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
`}),e.jsx(xe,{...f})]})}function be(){return e.jsxs("div",{className:"space-y-8 pb-20 max-w-layout-content mx-auto",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-end gap-4 border-b border-border/50 pb-6",children:[e.jsxs("div",{children:[e.jsx(y,{className:"h-9 w-56 mb-2"}),e.jsx(y,{className:"h-4 w-48"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(y,{className:"h-10 w-36 rounded-full"}),e.jsx(y,{className:"h-10 w-32 rounded-full"})]})]}),e.jsxs("div",{className:"flex gap-2 mb-8",children:[e.jsx(y,{className:"h-10 flex-1 rounded-lg"}),e.jsx(y,{className:"h-10 flex-1 rounded-lg"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[1,2,3].map(s=>e.jsx(y,{className:"h-28 rounded-xl"},s))}),e.jsx(y,{className:"h-64 w-full rounded-xl"}),e.jsx("span",{className:"sr-only",children:"Chargement du portail développeur..."})]})}const De=()=>{const{addToast:s}=W(),{copy:c}=M(),[n,a]=i.useState(null),[m,u]=i.useState([]),[h,l]=i.useState(!0),[b,f]=i.useState(null),[v,o]=i.useState({}),[g,p]=i.useState(!1),I=async r=>{await c(r.prefix),a(r.id),s("Key prefix copied to clipboard","success"),setTimeout(()=>a(null),2e3)},j=async()=>{l(!0),f(null);try{const[r,d]=await Promise.all([k.listKeys(),k.getStats()]);u(r),o(d)}catch(r){const d=r instanceof Error?r:new Error(String(r));f(d),S.error("Error loading developer dashboard data",{error:d.message,stack:d.stack})}finally{l(!1)}};i.useEffect(()=>{j()},[]);const D=async r=>{try{const d=await k.createKey(r);return u([d,...m]),s("API Key created successfully","success"),d}catch(d){throw s("Failed to create API key","error"),d}},R=async r=>{if(confirm("Are you sure you want to revoke this key?")){await k.revokeKey(r);const d=await k.listKeys();u(d),s("API Key revoked","info")}},P=async r=>{confirm("Are you sure you want to delete this key permanently?")&&(await k.deleteKey(r),u(m.filter(d=>d.id!==r)),s("API Key deleted","info"))};return h?e.jsx(be,{}):b?e.jsx("div",{className:"py-12",children:e.jsx(Y,{error:b,variant:"card",onRetry:j})}):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-border/50 pb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-heading font-bold text-foreground mb-2",children:"DEVELOPER PORTAL"}),e.jsx("p",{className:"text-muted-foreground font-mono text-sm",children:"Build on top of the Veza Platform."})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(x,{variant:"secondary",icon:e.jsx(ne,{className:"w-4 h-4"}),onClick:()=>window.open("https://docs.veza.io","_blank"),children:"Documentation"}),e.jsx(x,{variant:"primary",icon:e.jsx(le,{className:"w-4 h-4"}),onClick:()=>p(!0),children:"Create API Key"})]})]}),e.jsxs(ge,{defaultValue:"overview",className:"w-full",children:[e.jsxs(me,{className:"grid w-full grid-cols-2 mb-8",children:[e.jsxs(F,{value:"overview",className:"flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"}),"Overview & Keys"]}),e.jsxs(F,{value:"docs",className:"flex items-center gap-2",children:[e.jsx(ie,{className:"w-4 h-4"}),"API Documentation"]})]}),e.jsxs(O,{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:v.requests_24h?.toLocaleString()||0,icon:e.jsx($,{className:"w-5 h-5"}),trend:5.2,color:"cyan"}),e.jsx(_,{label:"Avg Latency",value:`${v.avg_latency||0}ms`,icon:e.jsx(ce,{className:"w-5 h-5"}),trend:-12,color:"lime"}),e.jsx(_,{label:"Active Keys",value:m.length,icon:e.jsx(A,{className:"w-5 h-5"}),color:"gold"})]}),e.jsxs(L,{variant:"default",children:[e.jsxs(q,{className:"flex flex-row items-center justify-between space-y-0 pb-4 border-b border-border/30",children:[e.jsxs(Q,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4 text-warning"})," Active API Keys"]}),e.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:[m.filter(r=>r.status==="active").length," active"]})]}),e