(
req: FastifyRequest<{
Body: ITrackHandlerPayload | DeprecatedPostEventPayload;
}>,
reply: FastifyReply
)
| 6 | import { isDuplicatedEvent } from '@/utils/deduplicate'; |
| 7 | |
| 8 | export async function duplicateHook( |
| 9 | req: FastifyRequest<{ |
| 10 | Body: ITrackHandlerPayload | DeprecatedPostEventPayload; |
| 11 | }>, |
| 12 | reply: FastifyReply |
| 13 | ) { |
| 14 | const ip = req.clientIp; |
| 15 | const origin = req.headers.origin; |
| 16 | const clientId = req.headers['openpanel-client-id']; |
| 17 | const body = req?.body; |
| 18 | const isTrackPayload = getIsTrackPayload(req); |
| 19 | const isReplay = isTrackPayload && req.body.type === 'replay'; |
| 20 | const shouldCheck = ip && origin && clientId && !isReplay; |
| 21 | const isDuplicate = shouldCheck |
| 22 | ? await isDuplicatedEvent({ |
| 23 | ip, |
| 24 | origin, |
| 25 | payload: body, |
| 26 | projectId: clientId as string, |
| 27 | }) |
| 28 | : false; |
| 29 | |
| 30 | if (isDuplicate) { |
| 31 | return reply.status(200).send('Duplicate event'); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function getIsTrackPayload( |
| 36 | req: FastifyRequest<{ |
nothing calls this directly
no test coverage detected