(
request: FastifyRequest<{
Body: ITrackHandlerPayload;
}>,
reply: FastifyReply
)
| 386 | } |
| 387 | |
| 388 | export async function handler( |
| 389 | request: FastifyRequest<{ |
| 390 | Body: ITrackHandlerPayload; |
| 391 | }>, |
| 392 | reply: FastifyReply |
| 393 | ) { |
| 394 | const validatedBody = request.body; |
| 395 | |
| 396 | // Handle alias (not supported) |
| 397 | if (validatedBody.type === 'alias') { |
| 398 | return reply.status(400).send({ |
| 399 | status: 400, |
| 400 | error: 'Bad Request', |
| 401 | message: 'Alias is not supported', |
| 402 | }); |
| 403 | } |
| 404 | |
| 405 | // Build request context |
| 406 | const context = await buildContext(request, validatedBody); |
| 407 | |
| 408 | // Dispatch to appropriate handler |
| 409 | switch (validatedBody.type) { |
| 410 | case 'track': |
| 411 | await handleTrack(validatedBody.payload, context); |
| 412 | break; |
| 413 | case 'identify': |
| 414 | await handleIdentify(validatedBody.payload, context); |
| 415 | break; |
| 416 | case 'increment': |
| 417 | await handleIncrement(validatedBody.payload, context); |
| 418 | break; |
| 419 | case 'decrement': |
| 420 | await handleDecrement(validatedBody.payload, context); |
| 421 | break; |
| 422 | case 'replay': { |
| 423 | // BACKCOMPAT(replay-sessionid): TEMPORARY legacy branch, remove when new SDK is fully deployed |
| 424 | if (!validatedBody.payload.sessionId) { |
| 425 | await handleReplay(validatedBody.payload, { |
| 426 | projectId: context.projectId, |
| 427 | sessionId: context.sessionId, |
| 428 | }); |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | await handleReplay(validatedBody.payload, { |
| 433 | projectId: context.projectId, |
| 434 | sessionId: validatedBody.payload.sessionId, |
| 435 | }); |
| 436 | break; |
| 437 | } |
| 438 | case 'group': |
| 439 | await handleGroup(validatedBody.payload, context); |
| 440 | break; |
| 441 | case 'assign_group': |
| 442 | await handleAssignGroup(validatedBody.payload, context); |
| 443 | break; |
| 444 | default: |
| 445 | return reply.status(400).send({ |
no test coverage detected