04319025de
Under AUTH_ENABLED=true, api/services.ts, api/widgets.ts, and api/backups.ts called fetch() directly without attaching the OIDC access token, so every services/widgets/backups request 401'd while api/client.ts requests succeeded. The token was only attached in client.ts. Extract the auth-attaching fetch helpers (buildUrl/buildHeaders/ readErrorDetail + get/post/put/del/postForm) into a new api/shared.ts that consults getAccessToken(), rewrite services.ts/widgets.ts/ backups.ts to use them, and consolidate client.ts to import from shared.ts (removing its duplicated copies). Now every backend request goes through one auth-attaching path. As a side benefit, error messages surface the HTTP status + backend detail instead of a generic "Failed to ..." string. Bug masked in dev because dev runs AUTH_ENABLED=false. npm run build clean; 0 lint errors; 72 frontend tests pass.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { get, post } from "./shared";
|
|
import type {
|
|
BackupAlert,
|
|
BackupDashboardSummary,
|
|
BackupJob,
|
|
BackupRun,
|
|
} from "../types/backups";
|
|
|
|
export async function fetchBackupJobs(): Promise<BackupJob[]> {
|
|
return get<BackupJob[]>("/api/backups/jobs");
|
|
}
|
|
|
|
export async function fetchBackupJob(
|
|
jobId: string,
|
|
): Promise<{ job: BackupJob; runs: BackupRun[] }> {
|
|
return get<{ job: BackupJob; runs: BackupRun[] }>(`/api/backups/jobs/${jobId}`);
|
|
}
|
|
|
|
export async function fetchBackupRuns(
|
|
jobId?: string,
|
|
status?: string,
|
|
): Promise<BackupRun[]> {
|
|
return get<BackupRun[]>("/api/backups/runs", {
|
|
...(jobId ? { job_id: jobId } : {}),
|
|
...(status ? { status } : {}),
|
|
});
|
|
}
|
|
|
|
export async function fetchBackupRun(runId: string): Promise<BackupRun> {
|
|
return get<BackupRun>(`/api/backups/runs/${runId}`);
|
|
}
|
|
|
|
export async function fetchBackupAlerts(
|
|
jobId?: string,
|
|
acknowledged?: boolean,
|
|
severity?: string,
|
|
): Promise<BackupAlert[]> {
|
|
return get<BackupAlert[]>("/api/backups/alerts", {
|
|
...(jobId ? { job_id: jobId } : {}),
|
|
...(acknowledged !== undefined ? { acknowledged: String(acknowledged) } : {}),
|
|
...(severity ? { severity } : {}),
|
|
});
|
|
}
|
|
|
|
export async function acknowledgeBackupAlert(
|
|
alertId: string,
|
|
): Promise<BackupAlert> {
|
|
return post<BackupAlert>(`/api/backups/alerts/${alertId}/acknowledge`);
|
|
}
|
|
|
|
export async function fetchBackupDashboard(): Promise<BackupDashboardSummary> {
|
|
return get<BackupDashboardSummary>("/api/dashboard/backups");
|
|
}
|