(fastify)
| 13 | const TAGS = ['Export'] as const; |
| 14 | |
| 15 | const exportRouter: FastifyPluginAsyncZodOpenApi = async (fastify) => { |
| 16 | await activateRateLimiter({ fastify, max: 100, timeWindow: '10 seconds' }); |
| 17 | |
| 18 | fastify.addHook('preHandler', async (req: FastifyRequest, reply) => { |
| 19 | try { |
| 20 | const client = await validateExportRequest(req.headers); |
| 21 | req.client = client; |
| 22 | } catch (e) { |
| 23 | if (e instanceof Prisma.PrismaClientKnownRequestError) { |
| 24 | return reply.status(401).send({ error: 'Unauthorized', message: 'Client ID seems to be malformed' }); |
| 25 | } |
| 26 | if (e instanceof Error) { |
| 27 | return reply.status(401).send({ error: 'Unauthorized', message: e.message }); |
| 28 | } |
| 29 | return reply.status(401).send({ error: 'Unauthorized', message: 'Unexpected error' }); |
| 30 | } |
| 31 | }); |
| 32 | |
| 33 | fastify.addHook('preValidation', async (req) => { |
| 34 | req.query = parseQueryString(req.query as Record<string, unknown>) as typeof req.query; |
| 35 | }); |
| 36 | |
| 37 | fastify.route({ |
| 38 | method: 'GET', |
| 39 | url: '/events', |
| 40 | schema: { |
| 41 | tags: TAGS, |
| 42 | description: 'Export a paginated list of raw events with optional filtering by date, profile, and event type.', |
| 43 | querystring: eventsScheme, |
| 44 | }, |
| 45 | handler: controller.events, |
| 46 | }); |
| 47 | |
| 48 | fastify.route({ |
| 49 | method: 'GET', |
| 50 | url: '/charts', |
| 51 | schema: { |
| 52 | tags: TAGS, |
| 53 | description: 'Export aggregated chart/analytics data for a series of events over a time range.', |
| 54 | querystring: chartSchemeFull, |
| 55 | }, |
| 56 | handler: controller.charts, |
| 57 | }); |
| 58 | }; |
| 59 | |
| 60 | export default exportRouter; |
nothing calls this directly
no test coverage detected