mirror of
https://github.com/Xevion/banner.git
synced 2026-01-31 10:23:39 -06:00
feat: enhance audit log with smart diffing, conditional request caching, auto refreshing
This commit is contained in:
+35
-2
@@ -66,6 +66,10 @@ export interface AuditLogEntry {
|
||||
fieldChanged: string;
|
||||
oldValue: string;
|
||||
newValue: string;
|
||||
subject: string | null;
|
||||
courseNumber: string | null;
|
||||
crn: string | null;
|
||||
courseTitle: string | null;
|
||||
}
|
||||
|
||||
export interface AuditLogResponse {
|
||||
@@ -181,10 +185,39 @@ export class BannerApiClient {
|
||||
return this.request<ScrapeJobsResponse>("/admin/scrape-jobs");
|
||||
}
|
||||
|
||||
async getAdminAuditLog(): Promise<AuditLogResponse> {
|
||||
return this.request<AuditLogResponse>("/admin/audit-log");
|
||||
/**
|
||||
* Fetch the audit log with conditional request support.
|
||||
*
|
||||
* Returns `null` when the server responds 304 (data unchanged).
|
||||
* Stores and sends `Last-Modified` / `If-Modified-Since` automatically.
|
||||
*/
|
||||
async getAdminAuditLog(): Promise<AuditLogResponse | null> {
|
||||
const headers: Record<string, string> = {};
|
||||
if (this._auditLastModified) {
|
||||
headers["If-Modified-Since"] = this._auditLastModified;
|
||||
}
|
||||
|
||||
const response = await this.fetchFn(`${this.baseUrl}/admin/audit-log`, { headers });
|
||||
|
||||
if (response.status === 304) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const lastMod = response.headers.get("Last-Modified");
|
||||
if (lastMod) {
|
||||
this._auditLastModified = lastMod;
|
||||
}
|
||||
|
||||
return (await response.json()) as AuditLogResponse;
|
||||
}
|
||||
|
||||
/** Stored `Last-Modified` value for audit log conditional requests. */
|
||||
private _auditLastModified: string | null = null;
|
||||
|
||||
async getMetrics(params?: MetricsParams): Promise<MetricsResponse> {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.course_id !== undefined) query.set("course_id", String(params.course_id));
|
||||
|
||||
Reference in New Issue
Block a user