Open History to see the last commit
1import type { AuthConnectDevice } from "@t3tools/contracts";
2
3/**
4 * T3 Connect device keys first seen on a host after `seenThrough`, a host-clock watermark each
5 * client keeps for itself so a session the relay minted cannot mark its own arrival as read.
6 * A client that has never looked starts from the newest key, so it does not announce itself.
7 */
8export function unseenConnectDevices(
9 devices: ReadonlyArray<AuthConnectDevice>,
10 seenThrough: number | undefined,
11): { readonly unseen: ReadonlyArray<AuthConnectDevice>; readonly newest: number } {
12 const newest = Math.max(0, ...devices.map((device) => device.approvedAt.epochMilliseconds));
13 if (seenThrough === undefined) return { unseen: [], newest };
14 return {
15 unseen: devices.filter((device) => device.approvedAt.epochMilliseconds > seenThrough),
16 newest: Math.max(seenThrough, newest),
17 };
18}