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

77 lines
22 KiB
JavaScript
Raw Normal View History

import{a as c,c as W,j as e}from"./vendor-react-C9dYU-TK.js";import{c as D,B as p,q as X,l as j,x as k,S as y,u as q,h as Q,C as L,b as Z,d as ee,f as te,E as re}from"./index-BMBS6scK.js";import{S as R}from"./StatCard-DakRAUmq.js";import{I as se}from"./input-DeoQfymd.js";import{u as V}from"./useCopyToClipboard-BDqgiukK.js";import{a2 as P,X as ae,C as E,a3 as B,g as oe,e as ne,R as ie,a4 as le,P as ce,h as $,a5 as de,G as ue,a as ge,i as M}from"./vendor-icons-BSV6HBy1.js";import{w as me}from"./webhookService-tqAepGmM.js";import{T as xe,a as pe,b as O,c as F}from"./Tabs-CJTCBu5-.js";import{ae as he}from"./vendor-CjLUfV8Y.js";import"./vendor-router-Dr0ZB7zf.js";import"./vendor-tanstack-C4XaEYj2.js";import"./vendor-http-CctT3C58.js";import"./vendor-utils-D0JLFg89.js";import"./vendor-motion-CbAtAbUE.js";import"./vendor-i18n-PN7w4axr.js";import"./AnimatedNumber-C7V3zEin.js";import"./vendor-security-DsrNJhpn.js";const fe=[{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"}],be=({onClose:t,onCreate:n})=>{const s=X(),[a,d]=c.useState(1),[u,m]=c.useState(""),[l,b]=c.useState(["user.read"]),[h,v]=c.useState(""),[i,x]=c.useState(!1),[f,I]=c.useState(!1),N=c.useRef(null),{copied:U,copy:_}=V(),A=c.useCallback(()=>{if(typeof window>"u"||!N.current)return;const o=document.createRange();o.selectNodeContents(N.current),window.getSelection()?.removeAllRanges(),window.getSelection()?.addRange(o)},[]);c.useEffect(()=>(I(!0),()=>I(!1)),[]);const r=o=>{b(w=>w.includes(o)?w.filter(K=>K!==o):[...w,o])},g=async o=>{if(o?.preventDefault(),o?.stopPropagation(),!u.trim()){s.error("Please enter a name for your API key");return}if(l.length===0){s.error("Please select at least one permission scope");return}x(!0);try{const w=await n({name:u.trim(),scopes:l}),K=w?.key??w?.api_key;if(K)v(K);else{const Y=`vz_${Math.random().toString(36).substr(2,8)}_${Math.random().toString(36).substr(2,16)}`;v(Y)}d(2),x(!1)}catch(w){throw x(!1),w}},J=async o=>{if(o?.preventDefault(),o?.stopPropagation(),!h)return;await _(h)?s.success("API Key copied to clipboard"):s.error("Copy failed. Select the key above and copy manually (Ctrl+C).")};return f?W.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[var(--sumi-z-max)] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-background/90 backdrop-blur-md",onClick:a===1?t: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(P,{className:"w-5 h-5 text-warning"})}),a===1?"Create API Key":"API Key Generated"]}),e.jsx("button",{onClick:t,className:"p-2 hover:bg-foreground/10 rounded-lg transition-colors",children:e.jsx(ae,{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:o=>m(o.target.value),autoFocus:!0,disabled:i,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:fe.map(o=>e.jsxs("label",{className:D(
.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(he,{...h})]})}function je(){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(t=>e.jsx(y,{className:"h-28 rounded-xl"},t))}),e.jsx(y,{className:"h-64 w-full rounded-xl"}),e.jsx("span",{className:"sr-only",children:"Chargement du portail développeur..."})]})}const Me=()=>{const{addToast:t}=q(),{copy:n}=V(),[s,a]=c.useState(null),[d,u]=c.useState([]),[m,l]=c.useState(!0),[b,h]=c.useState(null),[v,i]=c.useState({}),[x,f]=c.useState(!1),I=async r=>{await n(r.prefix),a(r.id),t("Key prefix copied to clipboard","success"),setTimeout(()=>a(null),2e3)},N=async()=>{l(!0),h(null);try{const[r,g]=await Promise.all([S.listKeys(),S.getStats()]);u(r),i(g)}catch(r){const g=r instanceof Error?r:new Error(String(r));h(g),j.error("Error loading developer dashboard data",{error:g.message,stack:g.stack})}finally{l(!1)}};c.useEffect(()=>{N()},[]);const U=async r=>{try{const g=await S.createKey(r);return u([g,...d]),t("API Key created successfully","success"),g}catch(g){throw t("Failed to create API key","error"),g}},_=async r=>{if(confirm("Are you sure you want to revoke this key?")){await S.revokeKey(r);const g=await S.listKeys();u(g),t("API Key revoked","info")}},A=async r=>{confirm("Are you sure you want to delete this key permanently?")&&(await S.deleteKey(r),u(d.filter(g=>g.id!==r)),t("API Key deleted","info"))};return m?e.jsx(je,{}):b?e.jsx("div",{className:"py-12",children:e.jsx(Q,{error:b,variant:"card",onRetry:N})}):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(p,{variant:"secondary",icon:e.jsx(le,{className:"w-4 h-4"}),onClick:()=>window.open("https://docs.veza.io","_blank"),children:"Documentation"}),e.jsx(p,{variant:"primary",icon:e.jsx(ce,{className:"w-4 h-4"}),onClick:()=>f(!0),children:"Create API Key"})]})]}),e.jsxs(xe,{defaultValue:"overview",className:"w-full",children:[e.jsxs(pe,{className:"grid w-full grid-cols-2 mb-8",children:[e.jsxs(O,{value:"overview",className:"flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"}),"Overview & Keys"]}),e.jsxs(O,{value:"docs",className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),"API Documentation"]})]}),e.jsxs(F,{value:"overview",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[e.jsx(R,{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(R,{label:"Avg Latency",value:`${v.avg_latency||0}ms`,icon:e.jsx(ue,{className:"w-5 h-5"}),trend:-12,color:"lime"}),e.jsx(R,{label:"Active Keys",value:d.length,icon:e.jsx(P,{className:"w-5 h-5"}),color:"gold"})]}),e.jsxs(L,{variant:"default",children:[e.jsxs(Z,{className:"flex flex-row items-center justify-between space-y-0 pb-4 border-b border-border/30",children:[e.jsxs(ee,{className:"flex items-center gap-2",children:[e.jsx(P,{className:"w-4 h-4 text-warning"})," Active API Keys"]}),e.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:[d.filter(r=>r.status==="active").length," active"]})]}),