| 29 | * Parse JSONL content into AnalyticsEvent[], skipping malformed lines. |
| 30 | */ |
| 31 | export function parseJSONL(content: string): AnalyticsEvent[] { |
| 32 | const events: AnalyticsEvent[] = []; |
| 33 | for (const line of content.split('\n')) { |
| 34 | const trimmed = line.trim(); |
| 35 | if (!trimmed) continue; |
| 36 | try { |
| 37 | const obj = JSON.parse(trimmed); |
| 38 | if (typeof obj === 'object' && obj !== null && typeof obj.ts === 'string') { |
| 39 | events.push(obj as AnalyticsEvent); |
| 40 | } |
| 41 | } catch { |
| 42 | // skip malformed lines |
| 43 | } |
| 44 | } |
| 45 | return events; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Filter events by period. Supports "7d", "30d", and "all". |