feat(statuspages): email subscriptions, RSS feed and a JSON API
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m5s
ci / lint (pull_request) Successful in 10m24s
ci / build (pull_request) Successful in 18m10s
ci / image (pull_request) Successful in 5m16s

Visitors can subscribe to a page's incidents by email where the
organization allows it. They confirm their address first; confirmation
and unsubscribe links only show a button, so mail scanners do not act on
them, and mails carry RFC 8058 one-click unsubscribe headers. Subscribers
get a mail when an incident opens or resolves and for every public
update.

Every page also has an RSS feed of incidents and planned maintenance and
a read-only JSON API (status, summary, components, incidents), both
served from the cached snapshot.

Abuse protection: status page servers limit feed and API reads,
subscription requests and link actions per visitor; the API limits
subscription requests per visitor, mailbox and page, and a new limit caps
the subscriptions an organization's pages gain in seven days (platform
default and per-organization override, 1000 in the cloud). Unconfirmed
subscriptions count towards it and are deleted after a week.

The fixed cap of 200 monitors per status page is gone; the configurable
limit alone decides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-26 18:18:08 +01:00
1 parent df39b765cb
commit cca4e80e54
39 files changed
+4332 -1408

No files matched your search

+104
View File
@@ -0,0 +1,104 @@
-- name: CountRecentSubscribers :one
-- Subscriptions the organization's pages gained since $2, confirmed or
-- not, for the weekly limit.
SELECT count(*) FROM status_page_subscribers WHERE org_id = $1 AND created_at > $2;
-- name: GetPageSubscriberByEmail :one
SELECT * FROM status_page_subscribers WHERE page_id = $1 AND email = $2;
-- name: CreatePageSubscriber :one
INSERT INTO status_page_subscribers (org_id, page_id, email, locale, page_url)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;
-- name: TouchPendingSubscriber :exec
-- Keeps a pending subscription's language and link current when the
-- visitor asks again.
UPDATE status_page_subscribers SET locale = $2, page_url = $3
WHERE id = $1 AND confirmed_at IS NULL;
-- name: GetPageSubscriber :one
SELECT s.*, p.title AS page_title FROM status_page_subscribers s
JOIN status_pages p ON p.id = s.page_id
WHERE s.id = $1;
-- name: ConfirmPageSubscriber :exec
UPDATE status_page_subscribers SET confirmed_at = coalesce(confirmed_at, now()) WHERE id = $1;
-- name: DeletePageSubscriber :execrows
DELETE FROM status_page_subscribers WHERE id = $1 AND page_id = $2;
-- name: ListPageSubscribers :many
-- The newest subscribers of a page first.
SELECT id, email, locale, created_at, confirmed_at FROM status_page_subscribers
WHERE page_id = $1
ORDER BY created_at DESC, id
LIMIT sqlc.arg(max_rows);
-- name: CountPageSubscribers :one
SELECT count(*) FILTER (WHERE confirmed_at IS NOT NULL)::integer AS confirmed,
count(*) FILTER (WHERE confirmed_at IS NULL)::integer AS pending
FROM status_page_subscribers WHERE page_id = $1;
-- name: EnqueueSubscriberNotifications :execrows
-- Queues the event of incident for every confirmed subscriber of the
-- published pages showing its monitor that take subscriptions.
INSERT INTO subscriber_notifications (org_id, subscriber_id, incident_id, update_id, event)
SELECT s.org_id, s.id, i.id, sqlc.narg(update_id)::uuid, sqlc.arg(event)
FROM incidents i
JOIN status_page_monitors spm ON spm.monitor_id = i.monitor_id
JOIN status_pages p ON p.id = spm.page_id
JOIN status_page_subscribers s ON s.page_id = p.id
WHERE i.id = sqlc.arg(incident_id) AND s.confirmed_at IS NOT NULL
AND p.published AND p.subscriptions AND p.suspended_at IS NULL
ON CONFLICT DO NOTHING;
-- name: ClaimSubscriberNotifications :many
-- System scope; leased like ClaimNotifications.
UPDATE subscriber_notifications SET next_attempt_at = now() + interval '5 minutes'
WHERE id IN (
SELECT id FROM subscriber_notifications
WHERE status = 'pending' AND next_attempt_at <= now()
ORDER BY next_attempt_at
LIMIT sqlc.arg(max)
FOR UPDATE SKIP LOCKED
)
RETURNING id;
-- name: SubscriberNotificationDetails :many
-- System scope: what a mail to a subscriber says.
SELECT n.id, n.event, n.attempts,
s.id AS subscriber_id, s.email, s.locale, s.page_url,
p.id AS page_id, p.slug, p.title AS page_title, p.custom_domain, p.domain_verified_at,
EXISTS (SELECT 1 FROM agents a WHERE a.org_id = p.org_id AND a.kind = 'statuspage' AND a.last_seen_at IS NOT NULL) AS own_servers,
i.started_at, i.resolved_at, i.title AS incident_title,
coalesce(nullif(spm.label, ''), m.name)::text AS component,
coalesce(u.status, '')::text AS update_status, coalesce(st.name, '')::text AS update_status_name,
coalesce(u.message, '')::text AS update_message
FROM subscriber_notifications n
JOIN status_page_subscribers s ON s.id = n.subscriber_id
JOIN status_pages p ON p.id = s.page_id
JOIN incidents i ON i.id = n.incident_id
JOIN monitors m ON m.id = i.monitor_id
LEFT JOIN status_page_monitors spm ON spm.page_id = p.id AND spm.monitor_id = m.id
LEFT JOIN incident_updates u ON u.id = n.update_id
LEFT JOIN incident_statuses st ON st.id = u.status_id
WHERE n.id = ANY (sqlc.arg(ids)::uuid[]);
-- name: MarkSubscriberNotificationSent :exec
UPDATE subscriber_notifications SET status = 'sent', sent_at = now(), attempts = attempts + 1, last_error = NULL
WHERE id = $1;
-- name: MarkSubscriberNotificationFailed :exec
UPDATE subscriber_notifications SET attempts = attempts + 1, last_error = sqlc.arg(last_error),
status = CASE WHEN attempts + 1 >= sqlc.arg(max_attempts)::int THEN 'failed' ELSE 'pending' END,
next_attempt_at = now() + make_interval(secs => sqlc.arg(retry_in_seconds)::int)
WHERE id = sqlc.arg(id);
-- name: PurgeUnconfirmedSubscribers :execrows
-- Unconfirmed subscriptions are kept for as long as they count towards the
-- weekly limit, so letting them lapse frees no room for more.
DELETE FROM status_page_subscribers WHERE confirmed_at IS NULL AND created_at < $1;
-- name: PurgeSubscriberNotifications :execrows
DELETE FROM subscriber_notifications WHERE status IN ('sent', 'failed') AND created_at < $1;