| 150 | } |
| 151 | |
| 152 | function clampTimestamp(v: unknown): string | undefined { |
| 153 | if (typeof v !== 'string') return undefined; |
| 154 | const t = Date.parse(v); |
| 155 | if (!Number.isFinite(t)) return undefined; |
| 156 | const now = Date.now(); |
| 157 | // Rollups arrive up to a few days late (offline buffers); reject implausible times. |
| 158 | if (t > now + 10 * 60_000 || t < now - 30 * 86_400_000) return undefined; |
| 159 | return new Date(t).toISOString(); |
| 160 | } |
| 161 | |
| 162 | function sanitizeEvent(raw: unknown): StoredEvent | null { |
| 163 | if (typeof raw !== 'object' || raw === null) return null; |