77 lines
28 KiB
JavaScript
77 lines
28 KiB
JavaScript
|
|
import{a as l,j as e,c as z}from"./vendor-react-BHG7lGYR.js";import{l as b,B as c,i as j,g as D,d as u}from"./index-BWcMVITa.js";import{V as F}from"./vendor-IYr-MHu4.js";import{A as L,a9 as $,b8 as S,X as M,l as U,C as G,i as C,Z as O,b9 as B,b6 as V,aa as K,_ as R,ba as E,aR as H,T as W,ag as X,bb as Y,bc as Z}from"./vendor-icons-DaGlTw4_.js";import{I as q}from"./input-BGBI2Wze.js";import"./vendor-router-D-s5vIeO.js";import"./vendor-tanstack-BzWBL1hV.js";import"./vendor-utils-CgOSfOkx.js";function J({specUrl:a,spec:i,useIframe:h=!1}){const d=l.useRef(null),p=l.useRef(null),[m,g]=l.useState(null),n=()=>{if(a)return a;const x=(j.API_URL.startsWith("http")?j.API_URL:`${window.location.origin}${j.API_URL}`).replace(/\/api\/v1$/,"");return h?`${x}/swagger/index.html`:`${x}/swagger/doc.json`},w=()=>`${(j.API_URL.startsWith("http")?j.API_URL:`${window.location.origin}${j.API_URL}`).replace(/\/api\/v1$/,"")}/swagger/index.html`;l.useEffect(()=>{d.current&&b.debug("Swagger UI initialized",{specUrl:a||n(),hasSpec:!!i,useIframe:h})},[a,i,h]);const y={url:i?void 0:n(),spec:i,deepLinking:!0,displayOperationId:!1,defaultModelsExpandDepth:1,defaultModelExpandDepth:1,docExpansion:"list",filter:!0,showExtensions:!0,showCommonExtensions:!0,tryItOutEnabled:!0,supportedSubmitMethods:["get","post","put","delete","patch"],requestInterceptor:r=>{const x=localStorage.getItem("access_token");x&&r.headers&&(r.headers.Authorization=`Bearer ${x}`);const v=localStorage.getItem("csrf_token");return v&&r.headers&&(r.headers["X-CSRF-Token"]=v),r},onComplete:()=>{g(null),b.debug("Swagger UI loaded successfully",{url:n()})},onFailure:r=>{g(r.message||"Failed to load Swagger documentation"),b.error("Failed to load Swagger UI",{error:r.message,stack:r.stack,url:n()})}},f=()=>{g(null),window.location.reload()};if(h)return e.jsx("div",{ref:d,className:"swagger-ui-container",style:{height:"100%",minHeight:"600px"},children:e.jsx("iframe",{ref:p,src:w(),className:"w-full h-full border-0 rounded-lg",style:{minHeight:"600px"},title:"Swagger UI Documentation",onLoad:()=>{b.debug("Swagger UI iframe loaded successfully"),g(null)},onError:()=>{g("Failed to load Swagger UI in iframe"),b.error("Failed to load Swagger UI iframe")}})});if(m){const r=w();return e.jsxs("div",{className:"flex flex-col items-center justify-center p-12 min-h-[600px]",children:[e.jsx(L,{className:"w-16 h-16 text-kodo-red mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-white mb-2",children:"Failed to Load API Documentation"}),e.jsx("p",{className:"text-sm text-kodo-secondary mb-4 text-center max-w-md",children:m}),e.jsxs("p",{className:"text-xs text-kodo-content-dim mb-6 text-center max-w-md",children:["Trying to load from: ",n(),e.jsx("br",{}),e.jsx("span",{className:"text-kodo-steel",children:"The Swagger JSON endpoint may not be available. Try opening Swagger UI directly."})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs(c,{onClick:f,variant:"default",children:[e.jsx($,{className:"w-4 h-4 mr-2"}),"Retry"]}),e.jsx(c,{onClick:()=>window.open(r,"_blank"),variant:"outline",children:"Open Swagger UI"}),e.jsx(c,{onClick:()=>{window.location.reload()},variant:"outline",children:"Use Iframe Mode"})]})]})}return e.jsxs("div",{ref:d,className:"swagger-ui-container",style:{height:"100%",minHeight:"600px"},children:[e.jsx("style",{children:`
|
||
|
|
.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(F,{...y})]})}const T=[{id:"k1",name:"Production App",prefix:"vz_8x92...",created:"Oct 10, 2023",lastUsed:"2 mins ago",status:"active",scopes:["read","write"]},{id:"k2",name:"Test Environment",prefix:"vz_9a21...",created:"Sep 15, 2023",lastUsed:"5 days ago",status:"active",scopes:["read"]}],I={listKeys:async()=>(await new Promise(a=>setTimeout(a,500)),T),createKey:async a=>{await new Promise(n=>setTimeout(n,800));const i=Math.random().toString(36).substr(2,8),h=Math.random().toString(36).substr(2,16),d=`vz_${i}_${h}`,p=`vz_${i}...`,g=new Date().toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"});return{id:`k-${Date.now()}`,name:a.name,prefix:p,created:g,lastUsed:"Never",status:"active",scopes:a.scopes,key:d}},revokeKey:async a=>(await new Promise(i=>setTimeout(i,400)),{success:!0}),getStats:async()=>(await new Promise(a=>setTimeout(a,400)),{requests_24h:145200,avg_latency:45,active_keys:T.length})},Q=[{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"}],ee=({onClose:a,onCreate:i})=>{const h=D(),[d,p]=l.useState(1),[m,g]=l.useState(""),[n,w]=l.useState(["user.read"]),[y,f]=l.useState(""),[r,x]=l.useState(!1),[v,k]=l.useState(!1);l.useEffect(()=>(k(!0),()=>k(!1)),[]);const _=o=>{w(s=>s.includes(o)?s.filter(t=>t!==o):[...s,o])},P=async o=>{if(o?.preventDefault(),o?.stopPropagation(),!m.trim()){h.error("Please enter a name for your API key");return}if(n.length===0){h.error("Please select at least one permission scope");return}x(!0);try{const s=await i({name:m.trim(),scopes:n});if(s.key)f(s.key);else{const t=`vz_${Math.random().toString(36).substr(2,8)}_${Math.random().toString(36).substr(2,16)}`;f(t)}p(2),x(!1)}catch(s){throw x(!1),s}},A=()=>{navigator.clipboard.writeText(y),h.success("API Key copied to clipboard")};return v?z.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:d===1?a: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(S,{className:"w-5 h-5 text-kodo-gold"})}),d===1?"Create API Key":"API Key Generated"]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-white/10 rounded-lg transition-colors",children:e.jsx(M,{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:d===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(q,{placeholder:"e.g. Production Server, Mobile App",value:m,onChange:o=>g(o.target.value),autoFocus:!0,disabled:r,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:Q.map(o=>e.jsxs("label",{className:u("flex items-center justify-between p-4 rounded-xl border cursor-pointer transition-all duration-200 group relative overflow-hidden",n.includes(o.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:"f
|