feat: service worker push notification router with topic registry (#55) - #82
Merged
elizabetheonoja-art merged 1 commit intoJun 25, 2026
Conversation
…ility-Protocol#55) Adds a topic-based push notification router so UI modules can subscribe to specific event topics, with 60s coalescence and a foreground in-app toast fallback. - types/notification.ts: topic/payload/action/toast types and bounds (3-level taxonomy, 200 topics × 5 handlers, 60s window, 2 actions, 4KB payload) - utils/topicRouter.ts: topic trie — insert/match with trailing-wildcard ancestor matching (meter.* → meter.water.breach), limit enforcement, isolated emit, plus the shared coalescenceKey helper - services/pushSubscriptionManager.ts: VAPID subscribe/unsubscribe with userVisibleOnly, REST register/DELETE, urlBase64ToUint8Array (injectable) - store/slices/notificationSlice.ts: coalescing queue store + useNotifications; identical events increment a count and extend the 60s auto-dismiss timer - hooks/usePushNotifications.ts: permission prompt, subscribe, and a navigator.serviceWorker message listener fanning foreground pushes to the topic router and toast queue - components/panels/ToastContainer.tsx: coalesced toasts with '(N more)' and up to 2 action buttons (url/route) - public/sw.js: push + notificationclick listeners — foreground clients get a postMessage, background shows a tag-coalesced system notification - unit tests for the router, subscription manager, and coalescence store
elizabetheonoja-art
approved these changes
Jun 25, 2026
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.
Service Worker Push Notification Router with Topic-Based Subscription Registry (#55)
Closes #55
src/types/notification.tssrc/utils/topicRouter.tsinsert(pattern, handler)→ unsubscribe,match(topic)collecting the exact path and every trailing-wildcard ancestor (meter.*→meter.water.breach), limit enforcement, isolatedemit, plus the sharedcoalescenceKey(topic, body)helper.src/services/pushSubscriptionManager.tssubscribe/unsubscribe(userVisibleOnly: true), REST register (POST)/remove (DELETE),urlBase64ToUint8Array. Transport + registration injectable.src/store/slices/notificationSlice.tsuseNotifications: same key → increment count and extend the 60s auto-dismiss timer; injectable clock/scheduler.src/hooks/usePushNotifications.tsnavigator.serviceWorkermessage listener that fans foreground pushes to the topic router and the toast queue.src/components/panels/ToastContainer.tsxpublic/sw.jspush+notificationclicklisteners: a visible client gets apostMessage; in the background a tag-coalesced system notification is shown (count folded into the title), and clicks focus/open the action's target.tests/unit/*