|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 6 | + <title>CommandLayer Claims Admin</title> |
| 7 | + <link rel="stylesheet" href="/css/site.css" /> |
| 8 | + <style> |
| 9 | + body { background: #fafafa; color: #111827; } |
| 10 | + .container { max-width: 1200px; margin: 0 auto; padding: 24px; } |
| 11 | + .card { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 16px; margin-bottom: 16px; } |
| 12 | + table { width: 100%; border-collapse: collapse; } |
| 13 | + th, td { text-align: left; border-bottom: 1px solid #e5e7eb; padding: 8px; } |
| 14 | + tr:hover { background: #f9fafb; cursor: pointer; } |
| 15 | + pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; } |
| 16 | + .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; } |
| 17 | + input { padding: 8px; min-width: 300px; } |
| 18 | + button { padding: 8px 12px; } |
| 19 | + .muted { color: #6b7280; } |
| 20 | + </style> |
| 21 | +</head> |
| 22 | +<body> |
| 23 | + <div class="container"> |
| 24 | + <h1>CommandLayer Claims Admin</h1> |
| 25 | + <div class="card"> |
| 26 | + <div class="row"> |
| 27 | + <label for="apiKey">Admin API key</label> |
| 28 | + <input id="apiKey" type="password" placeholder="Enter ADMIN_API_KEY" /> |
| 29 | + <button id="saveKey">Save key</button> |
| 30 | + <button id="loadClaims">Load claims</button> |
| 31 | + <span id="status" class="muted"></span> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div class="card"> |
| 36 | + <h2>Claims</h2> |
| 37 | + <table> |
| 38 | + <thead> |
| 39 | + <tr><th>Claim ID</th><th>Tenant</th><th>Wallet</th><th>Pack</th><th>Status</th><th>Agents</th><th>Created</th></tr> |
| 40 | + </thead> |
| 41 | + <tbody id="claimsBody"></tbody> |
| 42 | + </table> |
| 43 | + </div> |
| 44 | + |
| 45 | + <div class="card"> |
| 46 | + <h2>Claim detail</h2> |
| 47 | + <div id="detail" class="muted">Select a claim row to view details.</div> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | +<script> |
| 51 | +(() => { |
| 52 | + const apiKeyInput = document.getElementById('apiKey'); |
| 53 | + const saveKeyBtn = document.getElementById('saveKey'); |
| 54 | + const loadClaimsBtn = document.getElementById('loadClaims'); |
| 55 | + const statusEl = document.getElementById('status'); |
| 56 | + const claimsBody = document.getElementById('claimsBody'); |
| 57 | + const detail = document.getElementById('detail'); |
| 58 | + |
| 59 | + apiKeyInput.value = sessionStorage.getItem('cl_admin_api_key') || localStorage.getItem('cl_admin_api_key') || ''; |
| 60 | + |
| 61 | + function authHeaders() { |
| 62 | + return { Authorization: `Bearer ${apiKeyInput.value.trim()}` }; |
| 63 | + } |
| 64 | + |
| 65 | + saveKeyBtn.addEventListener('click', () => { |
| 66 | + const v = apiKeyInput.value.trim(); |
| 67 | + sessionStorage.setItem('cl_admin_api_key', v); |
| 68 | + localStorage.setItem('cl_admin_api_key', v); |
| 69 | + statusEl.textContent = 'Saved.'; |
| 70 | + }); |
| 71 | + |
| 72 | + async function loadClaims() { |
| 73 | + statusEl.textContent = 'Loading claims...'; |
| 74 | + claimsBody.innerHTML = ''; |
| 75 | + const res = await fetch('/api/admin/claims', { headers: authHeaders() }); |
| 76 | + const data = await res.json(); |
| 77 | + if (!res.ok || !data.ok) { |
| 78 | + statusEl.textContent = `${res.status} ${data.status || 'error'}`; |
| 79 | + return; |
| 80 | + } |
| 81 | + for (const claim of data.claims) { |
| 82 | + const tr = document.createElement('tr'); |
| 83 | + tr.innerHTML = `<td>${claim.claimId}</td><td>${claim.tenant}</td><td>${claim.authenticatedAddress}</td><td>${claim.packId}</td><td>${claim.status}</td><td>${claim.agentCount}</td><td>${claim.createdAt}</td>`; |
| 84 | + tr.addEventListener('click', () => loadDetail(claim.claimId)); |
| 85 | + claimsBody.appendChild(tr); |
| 86 | + } |
| 87 | + statusEl.textContent = `Loaded ${data.claims.length} claims.`; |
| 88 | + } |
| 89 | + |
| 90 | + async function loadDetail(claimId) { |
| 91 | + const res = await fetch(`/api/admin/claim?claimId=${encodeURIComponent(claimId)}`, { headers: authHeaders() }); |
| 92 | + const data = await res.json(); |
| 93 | + if (!res.ok || !data.ok) { |
| 94 | + detail.textContent = `${res.status} ${data.status || 'error'}`; |
| 95 | + return; |
| 96 | + } |
| 97 | + const reqJson = data.claim.request_json || {}; |
| 98 | + const ensRecords = reqJson && reqJson.records ? reqJson.records : null; |
| 99 | + detail.innerHTML = ` |
| 100 | + <p><strong>claim ID:</strong> ${data.claim.claim_id}</p> |
| 101 | + <p><strong>tenant:</strong> ${data.claim.tenant}</p> |
| 102 | + <p><strong>wallet:</strong> ${data.claim.authenticated_address}</p> |
| 103 | + <p><strong>pack:</strong> ${data.claim.pack_id}</p> |
| 104 | + <p><strong>public key:</strong> ${data.claim.public_key || ''}</p> |
| 105 | + <p><strong>kid:</strong> ${data.claim.kid || ''}</p> |
| 106 | + <p><strong>status:</strong> ${data.claim.status}</p> |
| 107 | + <h3>Agents</h3> |
| 108 | + <pre>${JSON.stringify(data.agents, null, 2)}</pre> |
| 109 | + <h3>Events</h3> |
| 110 | + <pre>${JSON.stringify(data.events, null, 2)}</pre> |
| 111 | + <button id="copyClaimJson">Copy claim JSON</button> |
| 112 | + ${ensRecords ? '<button id="copyEnsRecords">Copy ENS records</button>' : ''} |
| 113 | + `; |
| 114 | + document.getElementById('copyClaimJson').addEventListener('click', async () => { |
| 115 | + await navigator.clipboard.writeText(JSON.stringify(data.claim, null, 2)); |
| 116 | + }); |
| 117 | + if (ensRecords) { |
| 118 | + document.getElementById('copyEnsRecords').addEventListener('click', async () => { |
| 119 | + await navigator.clipboard.writeText(JSON.stringify(ensRecords, null, 2)); |
| 120 | + }); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + loadClaimsBtn.addEventListener('click', loadClaims); |
| 125 | +})(); |
| 126 | +</script> |
| 127 | +</body> |
| 128 | +</html> |
0 commit comments