import type { SubnetAutopsyPacket } from '../types'; export interface SeerSubnetAutopsyEvent { type: 'subnet_immune_autopsy'; prefix: string; triggered?: string; cause?: string; packet?: SubnetAutopsyPacket; } export function parseSeerSubnetAutopsy(payload: unknown): SeerSubnetAutopsyEvent | null { if (!payload || typeof payload !== 'object') return null; const raw = payload as Record; if (raw.type !== 'subnet_immune_autopsy') return null; const prefix = typeof raw.prefix === 'string' ? raw.prefix.trim() : ''; if (!prefix) return null; return { type: 'subnet_immune_autopsy', prefix, triggered: typeof raw.triggered === 'string' ? raw.triggered : undefined, cause: typeof raw.cause === 'string' ? raw.cause : undefined, packet: raw.packet as SubnetAutopsyPacket | undefined, }; } /** Normalize subnet labels to /24 prefix keys used by the API. */ export function subnetAutopsyPrefix(label: string): string { const s = label.trim().replace(/\.x$/i, '').replace(/\/24$/, ''); const parts = s.split('.'); if (parts.length >= 3) { return `${parts[0]}.${parts[1]}.${parts[2]}`; } return s; }