Skip to content

Fix Duplicate Webhook Mapping in Route Handler #70

Description

@Lakes41

Difficulty: Hard

Type: Bug

Summary

Remove the duplicate webhook mapping implementation from the webhook route so the dashboard has one reliable, tested path for converting webhook payloads into activity events.

Current Behaviour

apps/dashboard/app/api/webhooks/route.ts imports mapWebhookToActivity from @/lib/activity/mapper and also defines a local mapWebhookToActivity function in the same file. This creates a naming conflict and makes the route hard to maintain. The local mapper also applies sanitised metadata differently from the shared mapper, so webhook activity behaviour can drift depending on which mapper is used.

Expected Behaviour

Webhook payloads should be mapped through a single shared mapper module. The route handler should focus on request parsing, signature verification, validation, idempotency, and response handling.

Suggested Implementation

Remove the local mapWebhookToActivity function from apps/dashboard/app/api/webhooks/route.ts. Move sanitised metadata and sanitised descriptions into the shared mapper in apps/dashboard/lib/activity/mapper.ts, or wrap the mapper with a clear sanitisation step before storage. Add tests that confirm every supported webhook event maps correctly and that unsupported events return null.

Files or Areas Likely Affected

  • apps/dashboard/app/api/webhooks/route.ts
  • apps/dashboard/lib/activity/mapper.ts
  • apps/dashboard/lib/activity/sanitise.ts
  • apps/dashboard/lib/activity/types.ts
  • apps/dashboard/test/

Acceptance Criteria

  • apps/dashboard/app/api/webhooks/route.ts no longer declares a local mapWebhookToActivity function.
  • Webhook activity mapping is handled by one shared mapper module.
  • Stored webhook metadata is sanitised before being persisted.
  • Supported webhook event types produce the expected activity event shapes.
  • Unsupported webhook event types are ignored safely without throwing.
  • pnpm typecheck passes without mapper naming conflicts.

Additional Notes

This issue should not change the webhook signature verification contract. Keep the scope limited to mapping, sanitisation, and route cleanup.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions