import type {CertificatesState,CertificateServerState} from "@mmapp/contracts/certificates" export type CertificateSnapshot = { latest: CertificateServerState; confirmed: CertificateServerState | null } export type CertificateSnapshots = Record /** Replace the enabled-device inventory; retain each failed device's last confirmed snapshot. */ export function mergeCertificateSnapshots(previous:CertificateSnapshots,result:CertificatesState):CertificateSnapshots { return Object.fromEntries(result.servers.map(node=>[node.serverId,{ latest:node, confirmed:node.error===null?node:previous[node.serverId]?.confirmed??null, }])) }