emergency: 911 dialplan, notifications, test button, settings, warnings

Dialplan: sp-emergency-dial (911, 9911) first in sp-from-ext;
sp-emergency has no class, channel-limit or DND check, dials every
enabled trunk in name order with the E911 caller ID, and raises
UserEvent SpEmergency. Static sp-emergency-alert (_X! so "0" matches)
for the ring-out.

api: SpEmergency -> emergency_events row, live emergency.call (admins
and notify users only), email via nodemailer (SMTP from settings) and
an Originate to every notify extension, each outcome recorded. Test
button runs the same with TEST in front, records and dials nothing.
GET/PATCH /api/settings (smtp password write-only, references
checked, read-only system keys), SMTP test, /api/system/warnings.
Fix: clearing a nullable setting stored SQL NULL (now JSON null).

UI: Settings page (Email, Emergency with the 06 §6 notice), user
Emergency tab, dashboard warnings banner, red 911 banner.

Verified: generator/emergency.test.ts; trunk-test.ts dials 911 from a
caller with no class to the fake provider (E911 caller ID in RPID,
SpEmergency on AMI, alert plays on baresip 101); scripts/e2e/m3-t4.mjs
(SMTP sink receives the test email, 101 rings, banner shows).
nodemailer pinned to 10.0.11 (newest release over two weeks old).

Task: M3-T4
This commit is contained in:
iamdoubz committed 2026-10-17 20:52:50 -05:00
1 parent 4496f6b89a
commit 409724bc55
45 files changed
+1781 -139

No files matched your search

+6 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Live data from /api/live (05 §1): one WebSocket per tab, reconnecting with backoff.
import { create } from 'zustand';
import type { ExtensionLive, LiveMessage, TrunkLive } from '@selfphoneng/shared';
import type { EmergencyCall, ExtensionLive, LiveMessage, TrunkLive } from '@selfphoneng/shared';
type LiveStore = {
/** WebSocket state: 'connecting' before the first snapshot. */
@@ -10,6 +10,8 @@ type LiveStore = {
extensions: Record<string, ExtensionLive>;
/** Admins only (empty for users). */
trunks: Record<string, TrunkLive>;
/** 911 alerts received while this tab was open, newest last; dismissed ones are removed. */
emergencies: EmergencyCall[];
};
export const useLive = create<LiveStore>(() => ({
@@ -17,6 +19,7 @@ export const useLive = create<LiveStore>(() => ({
amiConnected: false,
extensions: {},
trunks: {},
emergencies: [],
}));
function apply(m: LiveMessage) {
@@ -41,6 +44,8 @@ function apply(m: LiveMessage) {
const { [m.data.trunkId]: _gone, ...rest } = s.trunks;
return { trunks: rest };
}
case 'emergency.call':
return { emergencies: [...s.emergencies, m.data] };
case 'ami.status':
return { amiConnected: m.data.connected };
default: