Skip to content

feat(webhooks): declarative provider routing (closes #2254) - #2326

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2254-webhook-routing
Nov 24, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2254-webhook-routing

Conversation

@IVANLI2412

Copy link
Copy Markdown
Contributor

Closes #2254

Summary

Implements declarative webhook routing with provider handlers, entirely within the technical scope (backend/src/webhooks/dispatcher.ts and backend/src/webhooks/providers/).

  • New providers/ module (zero dependencies):
    • types.ts — WebhookProvider/ProviderKind, HandlerErrorCode, HandlerError, ProviderHandler, WebhookRoute, RouteRegistry, RouteMatch, NormalizedWebhookEvent, observability hook interfaces. All route declarations are plain, frozen data.
    • matching.ts — pure normalizeProvider, normalizeEventType, routeKey, compileRoute and matchRoute. Exact provider+event routes beat wildcard (*) routes; ties break on priority, then registration order.
    • registry.ts — createRouteRegistry(config?, metrics?, logger?) with register / unregister / match / has / handlers / providers / size / clear. Configurable duplicate policy (error | replace | keepFirst), optional provider allow-list, frozen config and frozen returned snapshots.
    • handlers.ts — first-class, side-effect-free Stripe / PayPal / GitHub handlers that normalize payloads into a NormalizedWebhookEvent and forward to an injected sink; createProviderRoutes(sink) builds a complete frozen 10-route table.
    • index.ts — barrel exports, DEFAULT_PROVIDER_ROUTES, createDefaultRouteRegistry.
  • dispatcher.ts extension (preserves the existing JWT flow): the JWT claim gate, signature hook, DispatchError codes and legacy handler map are untouched in behavior. A declarative provider-route lookup is inserted after signature validation and before handler invocation; matched provider routes take precedence, legacy event-type handlers remain as a fallback. Handler contexts now also receive provider, eventType and matchedRoute metadata. Added createDeclarativeDispatcher, registerRoute and routeRegistry exposure.

Observability

Every registration, match, miss, duplicate, removal and clear emits a namespaced metric (webhook.route.*) and an audit log entry through the same hook shapes already used by the JWT validator, so callers can pass their existing hooks straight through.

Verification

  • Direct Node 26 type-stripping harness importing the real .ts sources: 52/52 assertions passed, 0 failures (covering normalization, registration, duplicate policies, allow-list, exact/wildcard/priority matching, all three built-in handlers, unregister/clear, metrics/logger hooks, frozen results, and dispatcher integration including JWT rejection).
  • Jest test file backend/src/webhooks/providers/__tests__/index.test.ts: 39 tests / 107 assertions passed, 0 failures via a describe/it/expect shim runner (no node_modules available in this environment).
  • Regression: existing backend/src/webhooks/__tests__/dispatcher.test.ts 18/18 passed and jwt.test.ts 42/42 passed — the JWT gate is unchanged.
  • Secret scan (python tools/check_secrets.py): SECRETS_EXIT=0.
  • No force push; branch pushed to IVANLI2412/SubTrackr as fix/issue-2254-webhook-routing.

Payouts

Base Mainnet (USDC/ETH): 0xC5dD2Ea54FF138bb3f71D3466092eA31eF115868
Solana (USDC/SOL): DN3pfYEvdkoTBP4oaEVvemsr98fZPhDSAbfVfmewRGQ5
PayPal: ivanzenteno3@gmail.com

@github-actions
github-actions Bot merged commit a74f48b into Smartdevs17:main Nov 24, 2026
7 of 27 checks passed
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.

Extract provider webhook routing behind a declarative dispatcher

1 participant