Files
MikrotikManager/lib/certificate-snapshots.ts
T

11 lines
662 B
TypeScript

import type {CertificatesState,CertificateServerState} from "@mmapp/contracts/certificates"
export type CertificateSnapshot = { latest: CertificateServerState; confirmed: CertificateServerState | null }
export type CertificateSnapshots = Record<string, CertificateSnapshot>
/** 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,
}]))
}