import { healthService } from 'App/services'; import { categoryKeyNames, lastAskedKey, healthResponseKey, } from 'Components/Header/HealthStatus/const'; import { IServiceStats } from 'Components/Header/HealthStatus/HealthStatus'; function mapResponse(resp: Record) { const services = Object.keys(resp); const healthMap: Record = {}; services.forEach((service) => { if (service === 'details') return; if (service === 'ssl') { healthMap[service] = { name: categoryKeyNames[service], healthOk: resp[service].health, serviceName: service, // @ts-ignore subservices: { ssl: resp[service] }, }; return; } healthMap[service] = { // @ts-ignore name: categoryKeyNames[service], healthOk: true, subservices: resp[service], serviceName: service, }; Object.values(healthMap[service].subservices).forEach( (subservice: Record) => { if (!subservice?.health) healthMap[service].healthOk = false; }, ); }); const overallHealth = Object.values(healthMap).every( (service: Record) => service.healthOk, ); return { overallHealth, healthMap, details: resp.details }; } export async function getHealthRequest(isPublic?: boolean) { const r = await healthService.fetchStatus(isPublic); const healthMap = mapResponse(r); const asked = new Date().getTime(); localStorage.setItem(healthResponseKey, JSON.stringify(healthMap)); localStorage.setItem(lastAskedKey, asked.toString()); return { healthMap, asked }; }