This commit introduces a complete transparency infrastructure including: Core Transparency Modules: - AuditLog: Immutable, cryptographically-linked audit trail for all actions - EventStream: Real-time SSE streaming and webhook support - TransparencyDashboard: Aggregated metrics and system health monitoring - DigitalSignatures: Cryptographic verification for handoffs and certificates API Endpoints: - /api/transparency/dashboard - Full platform metrics - /api/transparency/audit - Query and log audit entries - /api/transparency/events - SSE stream and event history - /api/transparency/webhooks - Webhook management - /api/transparency/signatures - Digital signature operations - /api/transparency/certificate/[plantId] - Plant authenticity certificates - /api/transparency/export - Multi-format data export - /api/transparency/report - Compliance reporting - /api/transparency/health - System health checks Features: - Immutable audit logging with chain integrity verification - Real-time event streaming via Server-Sent Events - Webhook support with HMAC signature verification - Digital signatures for transport handoffs and ownership transfers - Certificate of Authenticity generation for plants - Multi-format data export (JSON, CSV, summary) - Public transparency portal at /transparency - System health monitoring for all components Documentation: - Comprehensive TRANSPARENCY.md guide with API examples
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
/**
|
|
* Health Check API
|
|
* GET /api/transparency/health
|
|
*
|
|
* Returns the health status of all transparency components.
|
|
*/
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { getTransparencyDashboard, getAuditLog } from '../../../lib/transparency';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const dashboard = getTransparencyDashboard();
|
|
const auditLog = getAuditLog();
|
|
|
|
const health = await dashboard.getSystemHealth();
|
|
const auditIntegrity = auditLog.verifyIntegrity();
|
|
|
|
const response = {
|
|
status: health.status,
|
|
timestamp: new Date().toISOString(),
|
|
uptime: health.uptime,
|
|
components: health.components,
|
|
auditIntegrity: {
|
|
valid: auditIntegrity.valid,
|
|
errorCount: auditIntegrity.errors.length
|
|
}
|
|
};
|
|
|
|
// Set appropriate status code based on health
|
|
const statusCode = health.status === 'healthy' ? 200 :
|
|
health.status === 'degraded' ? 200 : 503;
|
|
|
|
return res.status(statusCode).json(response);
|
|
} catch (error) {
|
|
console.error('[API] Health check error:', error);
|
|
return res.status(503).json({
|
|
status: 'unhealthy',
|
|
timestamp: new Date().toISOString(),
|
|
error: 'Health check failed'
|
|
});
|
|
}
|
|
}
|