feat: add platform audit alerts

This commit is contained in:
Codex
2026-06-30 06:12:33 +08:00
parent b9957d18d5
commit 5bb0512ba7
20 changed files with 1061 additions and 23 deletions

View File

@@ -235,6 +235,52 @@ export interface PlatformAuditExportItem {
filters?: Record<string, unknown> | null;
}
export interface PlatformAuditAlertRuleItem {
id: string;
code?: string | null;
name?: string | null;
description?: string | null;
enabled?: boolean | null;
severity?: string | null;
actionPatterns?: string[] | null;
targetTypes?: string[] | null;
tenantId?: string | null;
conditions?: Record<string, unknown> | null;
metadata?: Record<string, unknown> | null;
createdAt?: string | null;
updatedAt?: string | null;
}
export interface PlatformAuditAlertItem {
id: string;
ruleId?: string | null;
ruleCode?: string | null;
ruleName?: string | null;
auditLogId?: string | null;
tenantId?: string | null;
tenantSlug?: string | null;
tenantName?: string | null;
severity?: string | null;
status?: string | null;
action?: string | null;
targetType?: string | null;
targetId?: string | null;
title?: string | null;
summary?: string | null;
details?: Record<string, unknown> | null;
actorUserId?: string | null;
actorUsername?: string | null;
actorName?: string | null;
ipAddress?: string | null;
userAgent?: string | null;
auditCreatedAt?: string | null;
acknowledgedAt?: string | null;
resolvedAt?: string | null;
resolutionNote?: string | null;
createdAt?: string | null;
updatedAt?: string | null;
}
export interface CreatePlatformTenantInput {
slug: string;
name: string;
@@ -371,6 +417,39 @@ export async function exportPlatformAuditLogs(query: {
});
}
export async function loadPlatformAuditAlertRules(query: { enabled?: boolean; limit?: number } = {}) {
return apiRequest<{ items?: PlatformAuditAlertRuleItem[] }>('/api/platform-admin/audit-alert-rules', {
query,
tenantId: null,
});
}
export async function loadPlatformAuditAlerts(query: {
tenantId?: string;
status?: string;
severity?: string;
ruleCode?: string;
q?: string;
limit?: number;
} = {}) {
return apiRequest<{ items?: PlatformAuditAlertItem[] }>('/api/platform-admin/audit-alerts', {
query: { ...query, limit: query.limit || 50 },
tenantId: null,
});
}
export async function updatePlatformAuditAlertStatus(input: {
alertId: string;
status: 'acknowledged' | 'resolved' | 'ignored';
resolutionNote?: string;
}) {
return apiRequest<{ item?: PlatformAuditAlertItem }>('/api/platform-admin/audit-alerts/status', {
method: 'POST',
body: input,
tenantId: null,
});
}
export async function loadPlatformInvoices(query: { tenantId?: string; status?: string; limit?: number } = {}) {
return apiRequest<{ items?: PlatformInvoiceItem[] }>('/api/platform-admin/invoices', {
query: { ...query, limit: query.limit || 80 },