Open History to see the last commit
1function isRecord(value: unknown): value is Record<string, unknown> {
2 return typeof value === 'object' && value !== null
3}
4
5/**
6 * Extract the payload record from an `api.otel-*` route's POST body,
7 * unwrapping the `forwardedProps` / `data` envelopes the test harness may
8 * nest it in. Throws on any non-object shape.
9 */
10export function recordFromBody(body: unknown): Record<string, unknown> {
11 if (!isRecord(body)) {
12 throw new Error('Invalid request body')
13 }
14
15 const data = body.forwardedProps ?? body.data ?? body
16 if (!isRecord(data)) {
17 throw new Error('Invalid request body')
18 }
19
20 return data
21}