export const name = "Google Workspace"; export const url = "https://workspace.google.com/status/"; const INCIDENTS_URL = "https://www.google.com/appsstatus/dashboard/incidents.json"; // status_impact → dashboard status const STATUS_MAP = { SERVICE_OUTAGE: "outage", SERVICE_DISRUPTION: "degraded", }; const IMPACT_LABEL = { SERVICE_OUTAGE: "outage", SERVICE_DISRUPTION: "service disruption", }; const SEVERITY_ORDER = ["operational", "degraded", "outage"]; function worstStatus(a, b) { return SEVERITY_ORDER.indexOf(a) >= SEVERITY_ORDER.indexOf(b) ? a : b; } export async function checkStatus() { const res = await fetch(INCIDENTS_URL); if (!res.ok) { throw new Error(`Google Workspace status request failed (${res.status})`); } const incidents = await res.json(); // Active incidents have no end timestamp const active = incidents.filter((i) => !i.end); if (active.length === 0) { return { name, status: "operational", message: "All services operating normally.", lastUpdated: new Date().toISOString(), }; } let overall = "operational"; const descriptions = []; for (const incident of active) { const mapped = STATUS_MAP[incident.status_impact] ?? "degraded"; overall = worstStatus(overall, mapped); const services = (incident.affected_products ?? []) .map((p) => p.title) .join(", "); const label = services || incident.service_name || "Unknown service"; const impact = IMPACT_LABEL[incident.status_impact] ?? "incident"; descriptions.push(`${label}: ${impact}`); } return { name, status: overall, message: descriptions.join(" | "), lastUpdated: new Date().toISOString(), }; }