(payload: unknown)
| 51 | } |
| 52 | |
| 53 | export function parseManagedUsagePayload(payload: unknown): ParsedManagedUsage { |
| 54 | if (typeof payload !== 'object' || payload === null) { |
| 55 | return { summary: null, limits: [] }; |
| 56 | } |
| 57 | const rec = payload as Record<string, unknown>; |
| 58 | const summary = toUsageRow(rec['usage'], 'Weekly limit'); |
| 59 | const limits: UsageRow[] = []; |
| 60 | const rawLimits = rec['limits']; |
| 61 | if (Array.isArray(rawLimits)) { |
| 62 | for (let idx = 0; idx < rawLimits.length; idx++) { |
| 63 | const item = rawLimits[idx] as Record<string, unknown> | undefined; |
| 64 | if (!item || typeof item !== 'object') continue; |
| 65 | const detailRaw = item['detail']; |
| 66 | const detail = isRecord(detailRaw) ? detailRaw : item; |
| 67 | const windowRaw = item['window']; |
| 68 | const window = isRecord(windowRaw) ? windowRaw : {}; |
| 69 | const label = limitLabel(item, detail, window, idx); |
| 70 | const row = toUsageRow(detail, label); |
| 71 | if (row !== null) limits.push(row); |
| 72 | } |
| 73 | } |
| 74 | return { summary, limits }; |
| 75 | } |
| 76 | |
| 77 | function toUsageRow(raw: unknown, defaultLabel: string): UsageRow | null { |
| 78 | if (!isRecord(raw)) return null; |
no test coverage detected