(fastify)
| 7 | import { isBotHook } from '@/hooks/is-bot.hook'; |
| 8 | |
| 9 | const trackRouter: FastifyPluginAsyncZodOpenApi = async (fastify) => { |
| 10 | fastify.addHook('preValidation', duplicateHook); |
| 11 | fastify.addHook('preHandler', clientHook); |
| 12 | fastify.addHook('preHandler', isBotHook); |
| 13 | |
| 14 | await fastify.route({ |
| 15 | method: 'POST', |
| 16 | url: '/', |
| 17 | schema: { |
| 18 | body: zTrackHandlerPayload.and( |
| 19 | z.object({ |
| 20 | clientId: z.string().optional(), |
| 21 | clientSecret: z.string().optional(), |
| 22 | }) |
| 23 | ), |
| 24 | tags: ['Track'], |
| 25 | description: |
| 26 | 'Ingest a tracking event (track, identify, group, increment, decrement, replay).', |
| 27 | response: { |
| 28 | 200: z.object({ |
| 29 | deviceId: z.string(), |
| 30 | sessionId: z.string(), |
| 31 | }), |
| 32 | }, |
| 33 | }, |
| 34 | handler, |
| 35 | }); |
| 36 | |
| 37 | await fastify.route({ |
| 38 | method: 'GET', |
| 39 | url: '/device-id', |
| 40 | schema: { |
| 41 | tags: ['Track'], |
| 42 | description: |
| 43 | 'Get or generate a stable device ID and session ID for the current visitor.', |
| 44 | response: { |
| 45 | 200: z.object({ |
| 46 | deviceId: z.string(), |
| 47 | sessionId: z.string(), |
| 48 | message: z.string().optional(), |
| 49 | }), |
| 50 | }, |
| 51 | }, |
| 52 | handler: fetchDeviceId, |
| 53 | }); |
| 54 | }; |
| 55 | |
| 56 | export default trackRouter; |
nothing calls this directly
no outgoing calls
no test coverage detected