Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
// Client-safe wrappers for the /api/audit-log/** BFF routes.
|
|
|
|
import { apiGet } from "@/app/lib/clientApi";
|
|
|
|
export interface AuditChange {
|
|
before: unknown;
|
|
after: unknown;
|
|
}
|
|
|
|
export interface AuditEvent {
|
|
id: number;
|
|
occurredAt: string;
|
|
actorType: string;
|
|
actor: string;
|
|
platform: string;
|
|
module: string;
|
|
action: string;
|
|
httpMethod: string;
|
|
pathTemplate: string;
|
|
targetType: string;
|
|
targetId: string;
|
|
outcome: "SUCCESS" | "FAILURE";
|
|
httpStatus: number;
|
|
clientIp: string;
|
|
changes: string | null; // JSON string of { "<field>": { "before": <any>, "after": <any> } }
|
|
}
|
|
|
|
export interface AuditLogPage {
|
|
content: AuditEvent[];
|
|
totalElements: number;
|
|
totalPages: number;
|
|
number: number;
|
|
size: number;
|
|
}
|
|
|
|
export interface AuditFilter {
|
|
actor?: string;
|
|
actorType?: "ADMIN" | "MEMBER";
|
|
module?: string;
|
|
action?: string;
|
|
from?: string;
|
|
to?: string;
|
|
ip?: string;
|
|
page: number;
|
|
pageSize: number;
|
|
sortBy?: string;
|
|
sortDir?: "asc" | "desc";
|
|
}
|
|
|
|
export function buildQueryString(filter: AuditFilter): string {
|
|
const qs = new URLSearchParams();
|
|
if (filter.actor) qs.set("actor", filter.actor);
|
|
if (filter.actorType) qs.set("actorType", filter.actorType);
|
|
if (filter.module) qs.set("module", filter.module);
|
|
if (filter.action) qs.set("action", filter.action);
|
|
if (filter.from) qs.set("from", filter.from);
|
|
if (filter.to) qs.set("to", filter.to);
|
|
if (filter.ip) qs.set("ip", filter.ip);
|
|
qs.set("page", String(Math.max(0, filter.page - 1)));
|
|
qs.set("size", String(filter.pageSize));
|
|
return qs.toString();
|
|
}
|
|
|
|
/** Parse the changes JSON string into a map of field -> { before, after }. Returns null when changes is empty. */
|
|
export function parseChanges(raw: string | null): Record<string, AuditChange> | null {
|
|
if (!raw || raw.trim() === "") return null;
|
|
try {
|
|
const parsed = JSON.parse(raw);
|
|
return typeof parsed === "object" && parsed !== null ? (parsed as Record<string, AuditChange>) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function listAuditLog(filter: AuditFilter): Promise<AuditLogPage> {
|
|
const qs = buildQueryString(filter);
|
|
return apiGet<AuditLogPage>(`/api/audit-log?${qs}`);
|
|
}
|
|
|
|
export async function getAuditEvent(id: number): Promise<AuditEvent> {
|
|
return apiGet<AuditEvent>(`/api/audit-log/${id}`);
|
|
}
|