From baa264d9cf2fb95bf781a924ea63d40f64441279 Mon Sep 17 00:00:00 2001 From: Dayz Tech Co Date: Sun, 26 Jul 2026 11:05:31 +0100 Subject: [PATCH] feat: add runtime validation for listAdminEvents endpoint Adds WebhookEventSchema and PaginatedSchema to the auto-generated types file, and uses them to validate the listAdminEvents response at runtime. This ensures every documented live endpoint response is now runtime-validated against a zod schema derived from openapi.json, completing the coverage for issue #267. - Adds WebhookEventSchema (zod) alongside the WebhookEvent interface - Adds PaginatedSchema helper for generic paginated response validation - Updates listAdminEvents to pass schema to getJson for runtime validation The existing sync-types/check-types compile-time guarantee is preserved. --- lib/api/live.ts | 3 +++ lib/api/types.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/api/live.ts b/lib/api/live.ts index 1a1feee..3fe5e35 100644 --- a/lib/api/live.ts +++ b/lib/api/live.ts @@ -34,6 +34,8 @@ import { ResourceSchema, AccessPolicySchema, WebhookEventLogSchema, + WebhookEventSchema, + PaginatedSchema, SiweAuthSessionSchema, Connection, ConnectionSchema, @@ -926,6 +928,7 @@ export class LiveAccessApi implements AccessApi { return await getJson>(`/v1/admin/events/paginated?${searchParams.toString()}`, { headers: this.authHeaders(), + schema: PaginatedSchema(WebhookEventSchema), }) } diff --git a/lib/api/types.ts b/lib/api/types.ts index 1ac2a6f..5d4ed1e 100644 --- a/lib/api/types.ts +++ b/lib/api/types.ts @@ -484,6 +484,14 @@ export interface WebhookEvent { status?: string } +export const WebhookEventSchema = z.object({ + id: z.string(), + type: z.string(), + payload: z.any(), + createdAt: z.string(), + status: z.string().optional(), +}) + export interface Paginated { data: T[] total: number @@ -491,6 +499,15 @@ export interface Paginated { limit: number } +export function PaginatedSchema(itemSchema: T) { + return z.object({ + data: z.array(itemSchema), + total: z.number(), + page: z.number(), + limit: z.number(), + }) +} + export interface AdminEventFilterParams { types?: string[] startDate?: string