Skip to content

feat: route events to targets by event type - #3

Open
bahriy-dev wants to merge 1 commit into
mainfrom
feat/event-routing
Open

bahriy-dev wants to merge 1 commit into
mainfrom
feat/event-routing

Conversation

@bahriy-dev

@bahriy-dev bahriy-dev commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Every event used to go to every target. In a real shop the warehouse only needs paid orders and stock changes, and accounting only needs payments and refunds.

What changed

  • Targets can be a plain URL (all events) or { "url": "…", "events": ["order.paid", "stock.*"] }
  • Event type comes from X-Event-Type, or the payload's type / event field
  • Untyped events only go to unfiltered targets; duplicate URLs are collapsed
  • 202 response now includes eventType and the number of routed targets
  • README section with a full example, updated sources.example.json
  • New src/routing.ts with 6 tests (20 total)

Closes #2

Targets can now subscribe to specific event types with patterns such as
"order.paid" or "stock.*". Plain URLs still receive every event.
The event type is read from X-Event-Type or the payload's type/event field.
Adds src/routing.ts with 6 tests.

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYiLwGkrgfn7ftZh1WDFpq
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T07:09:49.659504Z efa8b56 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efa8b56abf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app.ts
Comment on lines +47 to +48
const eventType = eventTypeOf(header(req, 'x-event-type'), payload);
const targets = routeEvent(source.targets, eventType);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Authenticate the event type before using it to select targets

For sources with filtered targets, anyone possessing a valid request can change X-Event-Type and replay it within the signature tolerance to route the signed payload to otherwise excluded targets. verify() authenticates only the timestamp and raw body, but this header overrides the authenticated payload type. For example, replaying a signed stock.updated event with X-Event-Type: order.paid queues it for an accounting target subscribed only to paid orders; per-target deduplication does not prevent this new delivery. Bind header-based event types to the signature, or derive routing from authenticated payload data.

Useful? React with 👍 / 👎.

Comment thread src/routing.ts
const urls: string[] = [];
for (const target of targets) {
if (typeof target === 'string') urls.push(target);
else if (!target.events?.length) urls.push(target.url);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Distinguish an empty event subscription from an absent filter

When a target has an explicit events: [], this condition treats it as unfiltered and sends it every event, including untyped events. That contradicts the documented behavior that objects with an events filter receive only matching types: an empty subscription has no matches. Clearing a target's subscriptions therefore broadens delivery instead of stopping it. Treat only an absent events property as unfiltered and let an empty array match nothing.

Useful? React with 👍 / 👎.

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.

Route events to targets by event type

1 participant