Documentation
¶
Overview ¶
Package push delivers integration-bus events to browsers as Web Push notifications (RFC 8030 delivery, RFC 8291 encryption, RFC 8292 VAPID; the wire work is internal/webpush).
Each browser subscription is its own bus subscriber ("webpush:<id>"), not one subscriber fanning out to many browsers. That is what gives a push the same delivery semantics as a Slack post: its own cursor, its own outbox rows keyed by an idempotency key, its own retries and dead letters. A fan-out subscriber would have had to retry the whole event when one phone was offline -- re-notifying every browser that had already shown it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Kinds = []integrations.Kind{ integrations.KindNeedsJudgment, integrations.KindChangeSetReady, integrations.KindVerifyFailed, integrations.KindOutcomeDrifted, }
Kinds are the event kinds a browser can ask to be notified about: the four that mean "a person is needed", which is what a notification on a phone is for. Pinned against integrations.AllKinds by a test.
Functions ¶
Types ¶
type Notifier ¶
type Notifier struct {
SubscriptionID string
Subscription webpush.Subscription
Events map[integrations.Kind]bool
Sender *webpush.Sender
// Redact masks credentials in every string that leaves the machine. The
// payload is end-to-end encrypted to the browser, but it is still shown
// on a lock screen.
Redact func(string) string
// OnResult records each attempt's outcome ("" on success).
OnResult func(ctx context.Context, errText string)
// OnGone is called when the push service says the subscription no
// longer exists; the caller deletes it.
OnGone func(ctx context.Context)
}
Notifier is the bus subscriber for one browser subscription.
func (*Notifier) Deliver ¶
Deliver implements integrations.Subscriber, mapping push-service answers onto the dispatcher's retry semantics: a dead subscription is permanent (and deleted), a 429's Retry-After is honoured, a 4xx that retrying cannot fix is permanent, anything else is retried with backoff.
type Payload ¶
type Payload struct {
Title string `json:"title"`
Body string `json:"body"`
// URL is a same-origin path + hash the notification opens. Relative, so
// it lands on whichever address the browser subscribed from.
URL string `json:"url"`
Tag string `json:"tag"`
Kind string `json:"kind"`
}
Payload is the JSON the service worker receives (web/public/sw.js).
func BuildPayload ¶
func BuildPayload(ev integrations.Event, redact func(string) string) Payload
BuildPayload renders ev as a notification.