1import{i as L,r as n,j as e,L as j,ax as P,a6 as w,a5 as T,e as O,s as F}from"./index-C86sjUM7.js";import{K as h}from"./key-vksBdnFe.js";import{D as _}from"./download-BjVXJSVp.js";const B=()=>{const{getValidToken:N}=L(),[p,m]=n.useState(!1),[b,i]=n.useState(null),[a,g]=n.useState(null),[o,v]=n.useState(""),[c,f]=n.useState(""),k=()=>{const t=new Date;return t.setFullYear(t.getFullYear()+1),t.toISOString().split("T")[0]},[d,A]=n.useState(k()),[x,u]=n.useState(null),y=t=>{if(!t)return!1;const s=new Date(t),r=new Date,l=new Date;return l.setFullYear(l.getFullYear()+1),r.setHours(0,0,0,0),l.setHours(0,0,0,0),s.setHours(0,0,0,0),s<r?(u("Expiration date cannot be in the past."),!1):s>l?(u("Maximum expiration duration is 1 year. Please select an earlier date."),!1):(u(null),!0)},D=t=>{const s=t.target.value;A(s),y(s)},S=async()=>{if(!y(d))return;m(!0),i(null);const t=N();if(!t){i("Authentication failed. Please log in again."),m(!1);return}try{const s=await fetch("https://api.bluelanternsecurity.io/api-keys",{method:"POST",headers:{Authorization:`${t}`,"Content-Type":"application/json"},body:JSON.stringify({expiration_timestamp:new Date(d).toISOString(),name:o.trim(),attribution:c.trim()})});if(s.ok){const r=await s.json();let l=r;r.body&&typeof r.body=="string"&&(l=JSON.parse(r.body));const E=l.result||l;g(E)}else{const r=await s.json().catch(()=>({}));let l=r.message||`Failed to generate API Key (${s.status})`;s.status===402&&(l=r.message||"API keys require an active Seat License. Add a seat on your Account page (or seats on the Organization page for a shared account), then try again."),s.status===400&&c.trim()&&(l+=" Seat assignments must match an active seated (monitored) member â seat them on the Organization page first, or clear the field to create the key unassigned."),i(l)}}catch(s){console.error(s),i("An unexpected error occurred while generating the API key.")}finally{m(!1)}},I=t=>{navigator.clipboard.writeText(t)},C=()=>{if(!a)return;const t=document.createElement("a"),s=new Blob([`Blue Lantern Security API Key 2 3Key: ${a.api_key} 4Name: ${a.name||o.trim()||"Unnamed key"} 5Seat assignment: ${a.attribution||c.trim()||"Unassigned"} 6User ID: ${a.user_id} 7Expires: ${new Date(a.expiration_date).toLocaleString()} 8 9KEEP THIS FILE SAFE. YOU WILL NOT BE ABLE TO VIEW THIS KEY AGAIN.`],{type:"text/plain"});t.href=URL.createObjectURL(s),t.download="bls_api_key.txt",document.body.appendChild(t),t.click(),document.body.removeChild(t)},K=()=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-4 sm:flex-row sm:items-center",children:[e.jsx("div",{className:"p-3 bg-blue-500/10 rounded-xl text-blue-400",children:e.jsx(h,{className:"w-8 h-8"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-white",children:"API Access"}),e.jsx("p",{className:"text-slate-400",children:"Manage your programmatic access keys"})]})]}),a?e.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[e.jsxs("div",{className:"p-4 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-400 flex items-center gap-3",children:[e.jsx(T,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:"API Key Successfully Created"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-wider text-slate-500 font-semibold mb-2",children:"Your API Key"}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start",children:[e.jsx("code",{className:"flex-1 bg-slate-950 border border-slate-800 rounded-lg p-3 font-mono text-sm text-blue-400 break-all",children:a.api_key}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:flex-col",children:[e.jsxs("button",{onClick:()=>I(a.api_key),className:"inline-flex items-center justify-center gap-2 rounded-lg bg-slate-800 px-3 py-3 text-slate-300 transition-colors hover:bg-slate-700 hover:text-white",title:"Copy to clipboard",children:[e.jsx(O,{className:"w-5 h-5"}),e.jsx("span",{className:"text-sm font-medium sm:hidden",children:"Copy"})]}),e.jsxs("button",{onClick:C,className:"inline-flex items-center justify-center gap-2 rounded-lg bg-slate-800 px-3 py-3 text-slate-300 transition-colors hover:bg-slate-700 hover:text-white",title:"Download as .txt",children:[e.jsx(_,{className:"w-5 h-5"}),e.jsx("span",{className:"text-sm font-medium sm:hidden",children:"Download"})]})]})]}),e.jsxs("div",{className:"mt-4 p-4 bg-yellow-500/10 border border-yellow-500/20 rounded-xl flex items-start gap-3",children:[e.jsx(F,{className:"w-5 h-5 text-yellow-500 shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-sm text-yellow-200/90",children:[e.jsx("strong",{children:"Important:"})," You will not be able to see this key again. Please download it or save it to a secure password manager now. If you lose this key, you will need to generate a new one."]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(a.name||o.trim())&&e.jsxs("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-slate-800/50",children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Key Name"}),e.jsx("p",{className:"text-sm text-slate-300 break-words",children:a.name||o.trim()})]}),e.jsxs("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-slate-800/50",children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Seat Assignment"}),e.jsx("p",{className:"text-sm text-slate-300 break-words",children:a.attribution||c.trim()||"Unassigned"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-slate-800/50",children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"User ID"}),e.jsx("p",{className:"text-sm font-mono text-slate-300 truncate",children:a.user_id})]}),e.jsxs("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-slate-800/50",children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Expiration Date"}),e.jsx("p",{className:"text-sm font-mono text-slate-300",children:new Date(a.expiration_date).toLocaleDateString()})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-4 border-t border-slate-800",children:[e.jsx(j,{to:"/account",className:"text-blue-400 hover:text-blue-300 text-sm hover:underline",children:"Return to A
9ccount"}),e.jsxs("button",{onClick:()=>{g(null),f(""),i(null)},className:"inline-flex items-center gap-2 rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-slate-300 transition-colors hover:bg-slate-700 hover:text-white",children:[e.jsx(h,{className:"w-4 h-4"}),"Generate Another Key"]})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("p",{className:"text-slate-300",children:["Generate an API key to authenticate your requests programmatically. Please note that your key will expire on ",e.jsx("strong",{children:new Date(d).toLocaleDateString()}),"."]}),b&&e.jsxs("div",{className:"p-4 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 flex items-start gap-3",children:[e.jsx(w,{className:"w-5 h-5 shrink-0 mt-0.5"}),e.jsx("span",{children:b})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Key Name"}),e.jsx("input",{type:"text",value:o,onChange:t=>v(t.target.value),maxLength:120,placeholder:"e.g. CI pipeline",className:"w-full bg-slate-950 border border-slate-700 rounded-xl px-4 py-3 text-white placeholder:text-slate-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all"}),e.jsx("p",{className:"text-slate-500 text-sm mt-2",children:"A display label so you can tell your keys apart. Does not affect billing."})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:["Seat Assignment ",e.jsx("span",{className:"font-normal text-slate-500",children:"(optional)"})]}),e.jsx("input",{type:"email",value:c,onChange:t=>f(t.target.value),maxLength:120,placeholder:"[email protected]",className:"w-full bg-slate-950 border border-slate-700 rounded-xl px-4 py-3 text-white placeholder:text-slate-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all"}),e.jsx("p",{className:"text-slate-500 text-sm mt-2",children:"The seated member this key's runs bill to â it appears as the submitter on reports. Must be the exact email of an active seated (monitored) member; leave blank to create the key unassigned."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Expiration Date"}),e.jsx("input",{type:"date",value:d,onChange:D,className:"w-full sm:w-64 bg-slate-950 border border-slate-700 rounded-xl px-4 py-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all"}),x?e.jsxs("p",{className:"text-red-400 text-sm mt-2 flex items-center gap-1.5",children:[e.jsx(w,{className:"w-4 h-4"}),x]}):e.jsx("p",{className:"text-slate-500 text-sm mt-2",children:"The key will remain valid until this date (max 1 year)."})]}),e.jsx("button",{onClick:S,disabled:p||!!x,className:"w-full sm:w-auto bg-blue-600 hover:bg-blue-500 text-white font-semibold py-3 px-6 rounded-xl transition-all shadow-lg shadow-blue-500/25 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"w-4 h-4"}),"Generate API Key"]})})]})]});return e.jsx("div",{className:"min-h-screen bg-slate-950 px-4 pb-12 pt-24 text-white sm:px-6",children:e.jsxs("div",{className:"max-w-3xl mx-auto",children:[e.jsxs(j,{to:"/account",className:"inline-flex items-center text-slate-400 hover:text-white mb-8 transition-colors",children:[e.jsx(P,{className:"w-4 h-4 mr-2"}),"Back to Account"]}),e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border border-slate-800 bg-slate-900 p-6 shadow-xl sm:p-8",children:[e.jsx("div",{className:"absolute top-0 right-0 -mr-20 -mt-20 w-64 h-64 bg-blue-500/10 rounded-full blur-3xl pointer-events-none"}),e.jsx("div",{className:"relative z-10",children:K()})]})]})})};export{B as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.