Skip to content

Webhook event replay re deliver past events by time range#414

Open
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Webhook-event-replay-re-deliver-past-events-by-time-range-#245
Open

Webhook event replay re deliver past events by time range#414
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Webhook-event-replay-re-deliver-past-events-by-time-range-#245

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Provide a way to re-deliver past system events for a given webhook when subscribers were unavailable.
  • Persist recent published events in-memory so replays can be requested by time window.
  • Ensure replays respect a webhook's registered events and reuse the existing delivery path.

Description

  • Add a bounded in-memory event log (globalThis.__openStellarEventLog__) capped at 500 entries and helper APIs listPublishedSystemEvents() and resetPublishedSystemEventLogForTests() in lib/events/system-events.ts.
  • Implement replayEventsToWebhook(webhookId, from, to) in lib/webhooks/delivery.ts which looks up the webhook, filters the persisted events by occurredAt window and webhook events, and calls the existing deliverToWebhook() for each match.
  • Add POST /api/webhooks/[id]/replay at app/api/webhooks/[id]/replay/route.ts with strict ISO timestamp validation for from/to, from <= to checks, returns { ok: true, queued: number }, and returns 404 when the webhook is not found.
  • Update OpenAPI metadata at app/api/openapi.json/route.ts and add unit tests in __tests__/api/webhooks.test.ts covering zero-event replay, type-filtered replay, full-window replay, unknown webhook 404, and ring-buffer eviction behavior.

Testing

  • Ran unit tests: vitest for __tests__/api/webhooks.test.ts and __tests__/api/openapi.test.ts — both test files passed.
  • Ran targeted ESLint on modified files — lint checks for changed files passed; full repo npm run lint reported pre-existing unrelated issues in other files.
  • Attempted npm run build — failed in this environment due to Next.js failing to fetch Google Fonts (unrelated to these changes).

Closes #245

@sonarqubecloud

Copy link
Copy Markdown

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

3 similar comments
@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, please review and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook event replay: re-deliver past events by time range

1 participant