paygate-mcp 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +219 -0
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,6 +108,8 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
108
108
|
- **Tool Availability** — `GET /tools/available?key=...` returns per-key tool availability with pricing, affordability (canAfford), ACL enforcement (accessible/denyReason), and per-tool + global rate limit status
|
|
109
109
|
- **Key Dashboard** — `GET /keys/dashboard?key=...` consolidated single-endpoint view with metadata, balance, health score, spending velocity, rate limits, quotas, usage summary, and recent activity timeline
|
|
110
110
|
- **Admin Notifications** — `GET /admin/notifications` scans all keys for actionable issues: expired/expiring keys, zero credits, credit depletion velocity, suspended keys, high error rates, and rate limit pressure — with severity filtering and priority sorting
|
|
111
|
+
- **System Dashboard** — `GET /admin/dashboard` system-wide overview with key counts (active/suspended/revoked/expired), credit summary (allocated/spent/remaining), usage breakdown with deny reasons, top consumers, top tools, notification counts, and uptime
|
|
112
|
+
- **Key Lifecycle Report** — `GET /admin/lifecycle` aggregated lifecycle trends with daily creation/revocation/suspension buckets, average key lifetime, and at-risk keys (expiring, expired, zero credits)
|
|
111
113
|
- **Config Hot Reload** — `POST /config/reload` reloads pricing, rate limits, webhooks, quotas, and behavior flags from config file without server restart
|
|
112
114
|
- **Webhook Events** — POST batched usage events to any URL for external billing/alerting
|
|
113
115
|
- **Config File Mode** — Load all settings from a JSON file (`--config`)
|
|
@@ -2429,6 +2431,77 @@ curl "http://localhost:3402/admin/notifications?severity=critical" \
|
|
|
2429
2431
|
|
|
2430
2432
|
Notifications are sorted by severity (critical first). Revoked keys are excluded. A single key can appear in multiple notifications (e.g., zero credits AND expiring soon). Filter with `?severity=critical|warning|info`. Read-only.
|
|
2431
2433
|
|
|
2434
|
+
### System Dashboard
|
|
2435
|
+
|
|
2436
|
+
Get a system-wide overview in a single request:
|
|
2437
|
+
|
|
2438
|
+
```bash
|
|
2439
|
+
curl http://localhost:3402/admin/dashboard \
|
|
2440
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2441
|
+
```
|
|
2442
|
+
|
|
2443
|
+
**Response:**
|
|
2444
|
+
|
|
2445
|
+
```json
|
|
2446
|
+
{
|
|
2447
|
+
"keys": { "total": 15, "active": 10, "suspended": 2, "revoked": 2, "expired": 1 },
|
|
2448
|
+
"credits": { "totalAllocated": 15000, "totalSpent": 4200, "totalRemaining": 10800 },
|
|
2449
|
+
"usage": {
|
|
2450
|
+
"totalCalls": 840,
|
|
2451
|
+
"totalAllowed": 790,
|
|
2452
|
+
"totalDenied": 50,
|
|
2453
|
+
"totalCreditsSpent": 4200,
|
|
2454
|
+
"denyReasons": [{ "reason": "insufficient_credits", "count": 30 }, { "reason": "rate_limited", "count": 20 }]
|
|
2455
|
+
},
|
|
2456
|
+
"topConsumers": [
|
|
2457
|
+
{ "name": "production-agent", "calls": 320, "credits": 1600, "denied": 5 },
|
|
2458
|
+
{ "name": "batch-worker", "calls": 210, "credits": 1050, "denied": 0 }
|
|
2459
|
+
],
|
|
2460
|
+
"topTools": [
|
|
2461
|
+
{ "tool": "search", "calls": 450, "credits": 2250, "denied": 20 },
|
|
2462
|
+
{ "tool": "generate", "calls": 300, "credits": 1500, "denied": 10 }
|
|
2463
|
+
],
|
|
2464
|
+
"notifications": { "critical": 2, "warning": 3, "info": 2 },
|
|
2465
|
+
"uptime": { "startedAt": "2026-02-27T00:00:00.000Z", "uptimeSeconds": 86400, "uptimeHours": 24 }
|
|
2466
|
+
}
|
|
2467
|
+
```
|
|
2468
|
+
|
|
2469
|
+
Combines key counts by state, credit allocation and spending totals, usage breakdown with deny reasons, top 10 consumers ranked by credits spent, top 10 tools ranked by call count, notification severity counts, and server uptime. Read-only.
|
|
2470
|
+
|
|
2471
|
+
### Key Lifecycle Report
|
|
2472
|
+
|
|
2473
|
+
Track key creation, revocation, suspension trends and identify at-risk keys:
|
|
2474
|
+
|
|
2475
|
+
```bash
|
|
2476
|
+
# Full lifecycle report
|
|
2477
|
+
curl http://localhost:3402/admin/lifecycle \
|
|
2478
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2479
|
+
|
|
2480
|
+
# Filter by date range
|
|
2481
|
+
curl "http://localhost:3402/admin/lifecycle?since=2026-02-01&until=2026-02-28" \
|
|
2482
|
+
-H "X-Admin-Key: YOUR_ADMIN_KEY"
|
|
2483
|
+
```
|
|
2484
|
+
|
|
2485
|
+
**Response:**
|
|
2486
|
+
|
|
2487
|
+
```json
|
|
2488
|
+
{
|
|
2489
|
+
"events": { "created": 25, "revoked": 3, "suspended": 5, "resumed": 4, "rotated": 2, "cloned": 1 },
|
|
2490
|
+
"trends": [
|
|
2491
|
+
{ "date": "2026-02-25", "created": 5, "revoked": 1, "suspended": 2, "resumed": 1 },
|
|
2492
|
+
{ "date": "2026-02-26", "created": 8, "revoked": 0, "suspended": 1, "resumed": 2 },
|
|
2493
|
+
{ "date": "2026-02-27", "created": 12, "revoked": 2, "suspended": 2, "resumed": 1 }
|
|
2494
|
+
],
|
|
2495
|
+
"averageLifetimeHours": 168.5,
|
|
2496
|
+
"atRisk": [
|
|
2497
|
+
{ "key": "pg_c815...09a6", "name": "staging-agent", "risk": "expiring_soon", "details": { "expiresAt": "2026-03-01T...", "daysRemaining": 2.5 } },
|
|
2498
|
+
{ "key": "pg_a3f1...b2e4", "name": "batch-worker", "risk": "zero_credits", "details": { "credits": 0 } }
|
|
2499
|
+
]
|
|
2500
|
+
}
|
|
2501
|
+
```
|
|
2502
|
+
|
|
2503
|
+
Shows aggregated lifecycle event counts, daily trend buckets (sorted chronologically), average key lifetime in hours (for revoked keys), and at-risk keys with their risk category (`expired`, `expiring_soon`, `zero_credits`). Supports `?since=` and `?until=` date filters. Excludes suspended and revoked keys from at-risk list. Read-only.
|
|
2504
|
+
|
|
2432
2505
|
### IP Allowlisting
|
|
2433
2506
|
|
|
2434
2507
|
Restrict API keys to specific IP addresses or CIDR ranges:
|
package/dist/server.d.ts
CHANGED
|
@@ -243,6 +243,8 @@ export declare class PayGateServer {
|
|
|
243
243
|
private handleSetMaintenance;
|
|
244
244
|
private handleAdminEventStream;
|
|
245
245
|
private handleAdminNotifications;
|
|
246
|
+
private handleSystemDashboard;
|
|
247
|
+
private handleKeyLifecycleReport;
|
|
246
248
|
private handleGetNotes;
|
|
247
249
|
private handleAddNote;
|
|
248
250
|
private handleDeleteNote;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAgB,eAAe,EAA0B,MAAM,MAAM,CAAC;AAI7E,OAAO,EAAE,aAAa,EAAkB,mBAAmB,EAAkB,MAAM,SAAS,CAAC;AAU7F,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,cAAc,EAAqD,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAS,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AwB;IAoJtC,OAAO,CAAC,sBAAsB;IA0F9B,OAAO,CAAC,sBAAsB;IA6E9B,qDAAqD;IACrD,OAAO,CAAC,UAAU;CAMnB"}
|
package/dist/server.js
CHANGED
|
@@ -804,6 +804,18 @@ class PayGateServer {
|
|
|
804
804
|
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
805
805
|
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
806
806
|
return;
|
|
807
|
+
case '/admin/dashboard':
|
|
808
|
+
if (req.method === 'GET')
|
|
809
|
+
return this.handleSystemDashboard(req, res);
|
|
810
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
811
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
812
|
+
return;
|
|
813
|
+
case '/admin/lifecycle':
|
|
814
|
+
if (req.method === 'GET')
|
|
815
|
+
return this.handleKeyLifecycleReport(req, res);
|
|
816
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
817
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use GET.' }));
|
|
818
|
+
return;
|
|
807
819
|
// ─── Plugin endpoints ──────────────────────────────────────────────
|
|
808
820
|
case '/plugins':
|
|
809
821
|
return this.handleListPlugins(req, res);
|
|
@@ -1345,6 +1357,8 @@ class PayGateServer {
|
|
|
1345
1357
|
toolAvailability: 'GET /tools/available?key=... — Per-key tool availability with pricing, affordability, and rate limit status (requires X-Admin-Key)',
|
|
1346
1358
|
keyDashboard: 'GET /keys/dashboard?key=... — Consolidated key overview with metadata, balance, health, velocity, rate limits, quotas, and recent activity (requires X-Admin-Key)',
|
|
1347
1359
|
adminNotifications: 'GET /admin/notifications — Actionable notifications for expiring keys, low credits, high error rates, and rate limit pressure (requires X-Admin-Key)',
|
|
1360
|
+
systemDashboard: 'GET /admin/dashboard — System-wide overview with key stats, credit summary, usage breakdown, top consumers, and uptime (requires X-Admin-Key)',
|
|
1361
|
+
keyLifecycle: 'GET /admin/lifecycle — Key lifecycle report with creation/revocation/expiry trends, average lifetime, and at-risk keys (requires X-Admin-Key)',
|
|
1348
1362
|
...(this.oauth ? {
|
|
1349
1363
|
oauthMetadata: 'GET /.well-known/oauth-authorization-server — OAuth 2.1 server metadata',
|
|
1350
1364
|
oauthRegister: 'POST /oauth/register — Register OAuth client',
|
|
@@ -4439,6 +4453,211 @@ class PayGateServer {
|
|
|
4439
4453
|
notifications: filtered,
|
|
4440
4454
|
}));
|
|
4441
4455
|
}
|
|
4456
|
+
// ─── /admin/dashboard — System-wide overview ──────────────────────────────
|
|
4457
|
+
handleSystemDashboard(req, res) {
|
|
4458
|
+
if (!this.checkAdmin(req, res))
|
|
4459
|
+
return;
|
|
4460
|
+
const allRecords = this.gate.store.getAllRecords();
|
|
4461
|
+
const now = Date.now();
|
|
4462
|
+
// ── Key statistics ──
|
|
4463
|
+
let activeCount = 0;
|
|
4464
|
+
let suspendedCount = 0;
|
|
4465
|
+
let revokedCount = 0;
|
|
4466
|
+
let expiredCount = 0;
|
|
4467
|
+
let totalAllocated = 0;
|
|
4468
|
+
let totalSpent = 0;
|
|
4469
|
+
let totalRemaining = 0;
|
|
4470
|
+
for (const record of allRecords) {
|
|
4471
|
+
totalAllocated += record.credits + (record.totalSpent || 0);
|
|
4472
|
+
totalSpent += record.totalSpent || 0;
|
|
4473
|
+
totalRemaining += record.credits;
|
|
4474
|
+
if (!record.active) {
|
|
4475
|
+
revokedCount++;
|
|
4476
|
+
}
|
|
4477
|
+
else if (record.expiresAt && new Date(record.expiresAt).getTime() <= now) {
|
|
4478
|
+
expiredCount++;
|
|
4479
|
+
}
|
|
4480
|
+
else if (record.suspended) {
|
|
4481
|
+
suspendedCount++;
|
|
4482
|
+
}
|
|
4483
|
+
else {
|
|
4484
|
+
activeCount++;
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
// ── Usage summary ──
|
|
4488
|
+
const usageSummary = this.gate.meter.getSummary();
|
|
4489
|
+
// ── Top consumers (by credits spent) ──
|
|
4490
|
+
const perKeyEntries = Object.entries(usageSummary.perKey)
|
|
4491
|
+
.map(([name, stats]) => ({ name, ...stats }))
|
|
4492
|
+
.sort((a, b) => b.credits - a.credits)
|
|
4493
|
+
.slice(0, 10);
|
|
4494
|
+
// ── Top tools (by call count) ──
|
|
4495
|
+
const perToolEntries = Object.entries(usageSummary.perTool)
|
|
4496
|
+
.map(([tool, stats]) => ({ tool, ...stats }))
|
|
4497
|
+
.sort((a, b) => b.calls - a.calls)
|
|
4498
|
+
.slice(0, 10);
|
|
4499
|
+
// ── Deny reason breakdown ──
|
|
4500
|
+
const denyReasons = Object.entries(usageSummary.denyReasons)
|
|
4501
|
+
.map(([reason, count]) => ({ reason, count }))
|
|
4502
|
+
.sort((a, b) => b.count - a.count);
|
|
4503
|
+
// ── Uptime ──
|
|
4504
|
+
const uptimeMs = now - this.startedAt;
|
|
4505
|
+
const uptimeSeconds = Math.floor(uptimeMs / 1000);
|
|
4506
|
+
const uptimeHours = Math.round(uptimeMs / 3_600_000 * 10) / 10;
|
|
4507
|
+
// ── Notification summary (counts only) ──
|
|
4508
|
+
const notifRecords = allRecords.filter(r => r.active);
|
|
4509
|
+
let criticalCount = 0;
|
|
4510
|
+
let warningCount = 0;
|
|
4511
|
+
let infoCount = 0;
|
|
4512
|
+
for (const record of notifRecords) {
|
|
4513
|
+
if (record.expiresAt) {
|
|
4514
|
+
const msToExpiry = new Date(record.expiresAt).getTime() - now;
|
|
4515
|
+
if (msToExpiry <= 0)
|
|
4516
|
+
criticalCount++;
|
|
4517
|
+
else if (msToExpiry <= 24 * 3_600_000)
|
|
4518
|
+
criticalCount++;
|
|
4519
|
+
else if (msToExpiry <= 168 * 3_600_000)
|
|
4520
|
+
warningCount++;
|
|
4521
|
+
}
|
|
4522
|
+
if (record.credits <= 0)
|
|
4523
|
+
criticalCount++;
|
|
4524
|
+
if (record.suspended)
|
|
4525
|
+
infoCount++;
|
|
4526
|
+
}
|
|
4527
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
4528
|
+
res.end(JSON.stringify({
|
|
4529
|
+
keys: {
|
|
4530
|
+
total: allRecords.length,
|
|
4531
|
+
active: activeCount,
|
|
4532
|
+
suspended: suspendedCount,
|
|
4533
|
+
revoked: revokedCount,
|
|
4534
|
+
expired: expiredCount,
|
|
4535
|
+
},
|
|
4536
|
+
credits: {
|
|
4537
|
+
totalAllocated,
|
|
4538
|
+
totalSpent,
|
|
4539
|
+
totalRemaining,
|
|
4540
|
+
},
|
|
4541
|
+
usage: {
|
|
4542
|
+
totalCalls: usageSummary.totalCalls,
|
|
4543
|
+
totalAllowed: usageSummary.totalCalls - usageSummary.totalDenied,
|
|
4544
|
+
totalDenied: usageSummary.totalDenied,
|
|
4545
|
+
totalCreditsSpent: usageSummary.totalCreditsSpent,
|
|
4546
|
+
denyReasons,
|
|
4547
|
+
},
|
|
4548
|
+
topConsumers: perKeyEntries,
|
|
4549
|
+
topTools: perToolEntries,
|
|
4550
|
+
notifications: {
|
|
4551
|
+
critical: criticalCount,
|
|
4552
|
+
warning: warningCount,
|
|
4553
|
+
info: infoCount,
|
|
4554
|
+
},
|
|
4555
|
+
uptime: {
|
|
4556
|
+
startedAt: new Date(this.startedAt).toISOString(),
|
|
4557
|
+
uptimeSeconds,
|
|
4558
|
+
uptimeHours,
|
|
4559
|
+
},
|
|
4560
|
+
}));
|
|
4561
|
+
}
|
|
4562
|
+
// ─── /admin/lifecycle — Key lifecycle report ──────────────────────────────
|
|
4563
|
+
handleKeyLifecycleReport(req, res) {
|
|
4564
|
+
if (!this.checkAdmin(req, res))
|
|
4565
|
+
return;
|
|
4566
|
+
const urlParts = req.url?.split('?') || [];
|
|
4567
|
+
const params = new URLSearchParams(urlParts[1] || '');
|
|
4568
|
+
const since = params.get('since') || undefined;
|
|
4569
|
+
const until = params.get('until') || undefined;
|
|
4570
|
+
// Query audit log for key lifecycle events
|
|
4571
|
+
const createdEvents = this.audit.query({
|
|
4572
|
+
types: ['key.created'], since, until, limit: 10_000,
|
|
4573
|
+
}).events;
|
|
4574
|
+
const revokedEvents = this.audit.query({
|
|
4575
|
+
types: ['key.revoked'], since, until, limit: 10_000,
|
|
4576
|
+
}).events;
|
|
4577
|
+
const suspendedEvents = this.audit.query({
|
|
4578
|
+
types: ['key.suspended'], since, until, limit: 10_000,
|
|
4579
|
+
}).events;
|
|
4580
|
+
const resumedEvents = this.audit.query({
|
|
4581
|
+
types: ['key.resumed'], since, until, limit: 10_000,
|
|
4582
|
+
}).events;
|
|
4583
|
+
const rotatedEvents = this.audit.query({
|
|
4584
|
+
types: ['key.rotated'], since, until, limit: 10_000,
|
|
4585
|
+
}).events;
|
|
4586
|
+
const clonedEvents = this.audit.query({
|
|
4587
|
+
types: ['key.cloned'], since, until, limit: 10_000,
|
|
4588
|
+
}).events;
|
|
4589
|
+
// Build daily buckets for trends
|
|
4590
|
+
const dayBuckets = new Map();
|
|
4591
|
+
const addToBucket = (events, field) => {
|
|
4592
|
+
for (const e of events) {
|
|
4593
|
+
const day = e.timestamp.slice(0, 10); // YYYY-MM-DD
|
|
4594
|
+
if (!dayBuckets.has(day))
|
|
4595
|
+
dayBuckets.set(day, { created: 0, revoked: 0, suspended: 0, resumed: 0 });
|
|
4596
|
+
dayBuckets.get(day)[field]++;
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
addToBucket(createdEvents, 'created');
|
|
4600
|
+
addToBucket(revokedEvents, 'revoked');
|
|
4601
|
+
addToBucket(suspendedEvents, 'suspended');
|
|
4602
|
+
addToBucket(resumedEvents, 'resumed');
|
|
4603
|
+
const trends = Array.from(dayBuckets.entries())
|
|
4604
|
+
.map(([date, counts]) => ({ date, ...counts }))
|
|
4605
|
+
.sort((a, b) => a.date.localeCompare(b.date));
|
|
4606
|
+
// Average key lifetime (for revoked keys that have creation metadata)
|
|
4607
|
+
const now = Date.now();
|
|
4608
|
+
const allRecords = this.gate.store.getAllRecords();
|
|
4609
|
+
const lifetimes = [];
|
|
4610
|
+
for (const record of allRecords) {
|
|
4611
|
+
if (!record.active && record.createdAt) {
|
|
4612
|
+
// Revoked key — estimate lifetime from created to now (or expiry)
|
|
4613
|
+
const created = new Date(record.createdAt).getTime();
|
|
4614
|
+
const end = record.expiresAt ? Math.min(new Date(record.expiresAt).getTime(), now) : now;
|
|
4615
|
+
if (created > 0 && end > created) {
|
|
4616
|
+
lifetimes.push(end - created);
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
const avgLifetimeHours = lifetimes.length > 0
|
|
4621
|
+
? Math.round(lifetimes.reduce((a, b) => a + b, 0) / lifetimes.length / 3_600_000 * 10) / 10
|
|
4622
|
+
: null;
|
|
4623
|
+
// At-risk keys: active keys expiring within 7 days or with zero credits
|
|
4624
|
+
const atRiskKeys = [];
|
|
4625
|
+
for (const record of allRecords) {
|
|
4626
|
+
if (!record.active)
|
|
4627
|
+
continue;
|
|
4628
|
+
if (record.suspended)
|
|
4629
|
+
continue;
|
|
4630
|
+
const maskedKey = record.key.slice(0, 7) + '...' + record.key.slice(-4);
|
|
4631
|
+
const keyName = record.name || undefined;
|
|
4632
|
+
if (record.credits <= 0) {
|
|
4633
|
+
atRiskKeys.push({ key: maskedKey, name: keyName, risk: 'zero_credits', details: { credits: 0 } });
|
|
4634
|
+
}
|
|
4635
|
+
if (record.expiresAt) {
|
|
4636
|
+
const msToExpiry = new Date(record.expiresAt).getTime() - now;
|
|
4637
|
+
if (msToExpiry <= 0) {
|
|
4638
|
+
atRiskKeys.push({ key: maskedKey, name: keyName, risk: 'expired', details: { expiresAt: record.expiresAt } });
|
|
4639
|
+
}
|
|
4640
|
+
else if (msToExpiry <= 7 * 24 * 3_600_000) {
|
|
4641
|
+
const daysLeft = Math.round(msToExpiry / 86_400_000 * 10) / 10;
|
|
4642
|
+
atRiskKeys.push({ key: maskedKey, name: keyName, risk: 'expiring_soon', details: { expiresAt: record.expiresAt, daysRemaining: daysLeft } });
|
|
4643
|
+
}
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
4647
|
+
res.end(JSON.stringify({
|
|
4648
|
+
events: {
|
|
4649
|
+
created: createdEvents.length,
|
|
4650
|
+
revoked: revokedEvents.length,
|
|
4651
|
+
suspended: suspendedEvents.length,
|
|
4652
|
+
resumed: resumedEvents.length,
|
|
4653
|
+
rotated: rotatedEvents.length,
|
|
4654
|
+
cloned: clonedEvents.length,
|
|
4655
|
+
},
|
|
4656
|
+
trends,
|
|
4657
|
+
averageLifetimeHours: avgLifetimeHours,
|
|
4658
|
+
atRisk: atRiskKeys,
|
|
4659
|
+
}));
|
|
4660
|
+
}
|
|
4442
4661
|
// ─── /keys/notes — Timestamped notes on API keys ─────────────────────────
|
|
4443
4662
|
handleGetNotes(req, res) {
|
|
4444
4663
|
if (!this.checkAdmin(req, res))
|