Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

reject invalid events page and clamp tinybird offset

Pedro Ladeiraf989103a6a67
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index 066572753b..7869051ce3 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -155,7 +155,7 @@ export const getEvents = async (params: EventsFilters) => {
...(params.root !== undefined ? { root: params.root } : {}),
...(params.saleType ? { saleType: params.saleType } : {}),
order: sortOrder,
- offset: (params.page - 1) * params.limit,
+ offset: Math.max(0, (params.page - 1) * params.limit),
limit: params.limit,
sortBy: params.sortBy,
start: formatUTCDateTimeClickhouse(startDate),
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 0140736a5f..84dcfe0c9a 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -535,11 +535,23 @@ export const eventsQuerySchema = analyticsQuerySchema
.describe(
"The type of event to retrieve analytics for. Defaults to 'clicks'.",
),
- page: z.coerce.number().default(1),
+ page: z.coerce
+ .number({ error: "Page must be a number." })
+ .int({ message: "Page must be an integer." })
+ .positive({ message: "Page must be greater than 0." })
+ .default(1)
+ .describe(
+ "The page number for pagination (1-based). The first page is `1`.",
+ )
+ .meta({ example: 1 }),
limit: z.coerce
- .number()
+ .number({ error: "Limit must be a number." })
+ .int({ message: "Limit must be an integer." })
+ .positive({ message: "Limit must be greater than 0." })
.max(1000, { message: "Max pagination limit is 1000 items per page." })
- .default(DEFAULT_PAGINATION_LIMIT),
+ .default(DEFAULT_PAGINATION_LIMIT)
+ .describe("The number of events to return per page.")
+ .meta({ example: DEFAULT_PAGINATION_LIMIT }),
sortOrder,
sortBy: z
.enum(["timestamp"])