Update session replay payload to use { type, payload } format

This commit is contained in:
Mike Cao
2026-03-23 16:30:53 -07:00
parent aea373ca56
commit 7582aed67b
3 changed files with 14 additions and 7 deletions
+7 -4
View File
@@ -16,9 +16,12 @@ interface Cache {
}
const schema = z.object({
website: z.uuid(),
events: z.array(z.any()).max(200),
timestamp: z.coerce.number().int().optional(),
type: z.literal('record'),
payload: z.object({
website: z.uuid(),
events: z.array(z.any()).max(200),
timestamp: z.coerce.number().int().optional(),
}),
});
export async function POST(request: Request) {
@@ -29,7 +32,7 @@ export async function POST(request: Request) {
return error();
}
const { website: websiteId, events, timestamp } = body;
const { website: websiteId, events, timestamp } = body.payload;
if (!events?.length) {
return json({ ok: true });
+1
View File
@@ -99,6 +99,7 @@ export const COLLECTION_TYPE = {
event: 'event',
identify: 'identify',
performance: 'performance',
record: 'record',
} as const;
export const WEB_VITALS_THRESHOLDS = {
+6 -3
View File
@@ -39,9 +39,12 @@ import { record } from 'rrweb';
if (!session?.cache) return;
const body = JSON.stringify({
website,
events,
timestamp: Math.floor(Date.now() / 1000),
type: 'record',
payload: {
website,
events,
timestamp: Math.floor(Date.now() / 1000),
},
});
// keepalive has a 64KB body limit — only use it for small payloads on unload