feat(notifications): Web Push delivers notifications to every device, even with TREK closed

A fourth built-in channel next to email, webhook and ntfy. Browsers
register per device, the server encrypts per RFC 8291 and signs per RFC
8292 with node:crypto and sends only to known push services through the
SSRF guard. The event matrix decides per category what arrives by push;
admins switch the channel on under Notifications.

VAPID keys come from the environment or are generated once, only while
neither stored row exists, and kept encrypted. A pair that does not
decrypt or match is never overwritten and never swapped for another one:
push stays off with an error in the log and every device stays
registered until the key is fixed. The subject is VAPID_SUBJECT, then an
https APP_URL, then the project URL.

Only chat messages collapse into one notification per trip, and a
replacement still alerts. A 403 removes a device only after three
failures in a row; 404 and 410 remove it at once. Password change, reset
and an admin setting a password drop the user's devices with the other
credentials. The request log redacts subscriptions and endpoints, boot
errors print *** for every secret variable, and logout forgets the
device with a plain fetch so an expired session cannot redirect midway.

Addresses discussion #894.
This commit is contained in:
Maurice
2026-09-24 23:17:03 +00:00
parent 7ce31756a3
commit 650451bdf7
177 changed files with 7809 additions and 271 deletions
@@ -1185,3 +1185,47 @@ describe('NotificationsTab — webhook and channel-test failures', () => {
expect(await screen.findByText('Test failed.')).toBeInTheDocument();
});
});
// ─────────────────────────────────────────────────────────────────────────────
// Web Push (#894)
// ─────────────────────────────────────────────────────────────────────────────
//
// The Push column comes from the server like every other; what this tab adds is
// the per-device card, shown only while the admin has the channel switched on.
// jsdom has no push APIs, so the real hook reads this "browser" as unable to
// receive push, which is exactly what the card must then say.
const pushMatrix = (active: boolean) => ({
preferences: { trip_invite: { inapp: true, push: true } },
channels: [
{ id: 'inapp', source: 'builtin', labelKey: 'settings.notificationPreferences.inapp', active: true, configured: true },
{ id: 'push', source: 'builtin', labelKey: 'settings.notificationPreferences.push', active, configured: false },
],
event_types: ['trip_invite'],
implemented_combos: { trip_invite: ['inapp', 'push'] },
});
describe('NotificationsTab: Web Push', () => {
beforeEach(() => {
resetAllStores();
seedStore(useAuthStore, { isAuthenticated: true, user: buildUser() });
});
it('FE-COMP-NOTIFICATIONS-PUSH-001: an active push channel gets its column and the device card', async () => {
mockMatrix(pushMatrix(true));
render(<NotificationsTab />);
expect(await screen.findByText('Push notifications on this device')).toBeInTheDocument();
expect(screen.getByText('Push')).toBeInTheDocument();
expect(await screen.findByRole('status')).toHaveTextContent(/push/i);
});
it('FE-COMP-NOTIFICATIONS-PUSH-002: no card and no column while the admin has push off', async () => {
mockMatrix(pushMatrix(false));
render(<NotificationsTab />);
await screen.findByText(/in-app/i);
expect(screen.queryByText('Push notifications on this device')).not.toBeInTheDocument();
expect(screen.queryByText('Push')).not.toBeInTheDocument();
});
});