MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / parseManagedUsagePayload

Function parseManagedUsagePayload

packages/oauth/src/managed-usage.ts:53–75  ·  view source on GitHub ↗
(payload: unknown)

Source from the content-addressed store, hash-verified

51}
52
53export 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
77function toUsageRow(raw: unknown, defaultLabel: string): UsageRow | null {
78 if (!isRecord(raw)) return null;

Callers 2

fetchManagedUsageFunction · 0.85

Calls 4

isRecordFunction · 0.90
toUsageRowFunction · 0.85
limitLabelFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected