import { apiRequest } from "@/shared/api/client"; import { createObjectDecoder, isBoolean, isOneOf, isString, type ValueValidator } from "@/shared/api/decoder"; export type SystemInfoDTO = { publicApiBaseURL: string; }; const decodeSystemInfo = createObjectDecoder("system info", { publicApiBaseURL: isString }); export function getSystemInfo(): Promise { return apiRequest("/api/admin/v1/system", {}, decodeSystemInfo); } export type UpdateStatus = "unchecked" | "up_to_date" | "update_available" | "check_failed"; export type VersionInfoDTO = { currentVersion: string; latestVersion: string; updateAvailable: boolean; status: UpdateStatus; checkedAt: string | null; releaseUrl: string; releaseNotes: string; error: string; }; const isNullableString: ValueValidator = (value) => value === null || isString(value); const decodeVersionInfo = createObjectDecoder("version info", { currentVersion: isString, latestVersion: isString, updateAvailable: isBoolean, status: isOneOf("unchecked", "up_to_date", "update_available", "check_failed"), checkedAt: isNullableString, releaseUrl: isString, releaseNotes: isString, error: isString, }); export function getVersionInfo(): Promise { return apiRequest("/api/admin/v1/system/version", {}, decodeVersionInfo); } export function checkForUpdates(): Promise { return apiRequest("/api/admin/v1/system/update/check", { method: "POST" }, decodeVersionInfo); }