feat(webhooks): implement webhook system for contract event notifications (#13) - #44
Open
Ahbiz wants to merge 3 commits into
Open
feat(webhooks): implement webhook system for contract event notifications (#13)#44Ahbiz wants to merge 3 commits into
Ahbiz wants to merge 3 commits into
Conversation
Member
|
Failed CI. Fix it |
Member
|
Had to fix your conflict because I waited & you didn't fix it. Your CI still didn't pass |
Author
|
Ohhh sorry didn't see that, I wasn't aware of that.
Hope everything has been resolved now ?
…On Thu, 30 Jul 2026, 10:09 Karen Agbo, ***@***.***> wrote:
*KarenZita01* left a comment (EquipChain/EquipChain-backend#44)
<#44 (comment)>
Had to fix your conflict because I waited & you didn't fix it. Your CI
still didn't pass
—
Reply to this email directly, view it on GitHub
<#44?email_source=notifications&email_token=BKJ7GXWQWGNK2M5QF27YTMD5HMGE7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJSHA4DCMRSGY32M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5128812267>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BKJ7GXR7KORQ5MQLOWGV2535HMGE7AVCNFSNUABGKJSXA33TNF2G64TZHMYTENRRGE2TQNRVGI5US43TOVSTWNJQGAZDSNRQGY4DJILWAI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #13
This PR implements an asynchronous Webhook Notification System that allows external services to register HTTP endpoints and receive real-time HTTP POST notifications when contract or system events occur (e.g., meter reading creation/updates, contract state changes, system alerts, user registration, and admin actions).
Key Changes Made
1. Central Event Emitter (
src/services/eventEmitter.js)AppEventEmitterextending Node'sEventEmitterto dispatch typed contract and system events (meter.reading.created,contract.state.changed, etc.) asynchronously across services.2. Webhook Service (
src/services/webhook.js)registerWebhook,unregisterWebhook,listWebhooks,updateWebhook).{ id: "evt_...", type, created, data, webhookId: "wh_..." }.X-Webhook-Signatureheaders usingnode:cryptoHMAC-SHA256 based on the request body and shared secret.fetch()with configurable timeouts and automatic retries (up to 3 retries with 1min, 5min, 15min backoff).3. Admin Webhook Management API (
src/routes/admin/webhooks.js)/api/admin/webhooks:POST /api/admin/webhooks— Register a webhookGET /api/admin/webhooks— List registered webhooks (supports pagination and filtering)GET /api/admin/webhooks/:id— Get single webhook detailsPATCH /api/admin/webhooks/:id— Update webhook registrationDELETE /api/admin/webhooks/:id— Unregister webhookGET /api/admin/webhooks/:id/logs— Retrieve delivery logs for a webhook4. Admin Auth & Validation (
src/middleware/auth.js,src/schemas/webhook.schema.js)adminAuthmiddleware enforcing Bearer token or API key authentication for admin endpoints.createWebhookSchema,updateWebhookSchema,webhookQuerySchema) for strict request validation.5. Repository Enhancements (
src/repositories/WebhookRepository.js)WebhookRepositoryto support matching multiple event types per webhook, wildcard (*) filters, and detailed delivery attempt history.6. App Integration & Tests
index.jsto mount admin webhook routes and initialize the event listener service on startup.test/unit/webhook.test.js: Covers registration CRUD, HMAC signature generation/verification, event dispatching, retry logic, and delivery failure logging.test/integration/webhook.test.js: Verifies full end-to-end flow over local HTTP server listener and REST API endpoints.Verification & Testing
npm test