Deduplicate webhook deliveries
Keep the first delivery of each webhook event while preserving arrival order and caller-owned data.Description
Requirements
The solution exports a callable function named dedupeWebhookEvents.
Only the first event with each exact id is included in the result.
Retained events appear in the same relative order as their first deliveries.
Event ids are compared as case-sensitive strings.
An empty input array returns an empty array.
The function returns a new array containing new event objects.
The input array and its event objects are not mutated.
Retried delivery
[{ id: 'evt_1' }, { id: 'evt_2' }, { id: 'evt_1' }][{ id: 'evt_1' }, { id: 'evt_2' }]The second evt_1 delivery is ignored because its id has already been processed.
Constraints
Every event has a non-empty string idThe input may contain up to 10000 eventsKeep the first payload when duplicate ids contain different dataDo not mutate the input array or its event objects
Hints
Hint 1
Track exact identifiers as you scan once, and decide which encounter is allowed to populate the output.
Hint 2
Treat identifier casing as meaningful rather than normalizing it for comparison.
Hint 3
Create the accepted output objects independently so input records cannot be changed through the result.