webpush

package
v2.33.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegenerateVAPIDKeys

func RegenerateVAPIDKeys(ctx context.Context, db database.Store) (newPrivateKey string, newPublicKey string, err error)

RegenerateVAPIDKeys regenerates the VAPID keys and deletes all existing push subscriptions as part of the transaction, as they are no longer valid.

Types

type Dispatcher

type Dispatcher interface {
	// Dispatch sends a web push notification to all subscriptions
	// for a user. Any notifications that fail to send are silently dropped.
	Dispatch(ctx context.Context, userID uuid.UUID, notification codersdk.WebpushMessage) error
	// Test sends a test web push notificatoin to a subscription to ensure it is valid.
	Test(ctx context.Context, req codersdk.WebpushSubscription) error
	// PublicKey returns the VAPID public key for the webpush dispatcher.
	PublicKey() string
}

Dispatcher is an interface that can be used to dispatch web push notifications to clients such as browsers.

func New

func New(ctx context.Context, log *slog.Logger, db database.Store, vapidSub string, opts ...Option) (Dispatcher, error)

New creates a new Dispatcher to dispatch web push notifications.

This is *not* integrated into the enqueue system unfortunately. That's because the notifications system has a enqueue system, and push notifications at time of implementation are being used for updates inside of a workspace, which we want to be immediate.

See: https://github.com/coder/internal/issues/528

type NoopWebpusher

type NoopWebpusher struct {
	Msg string
}

NoopWebpusher is a Dispatcher that always fails, returning Msg as the error. It is used as a fallback when VAPID key setup fails. The underlying error is not included to avoid leaking internal details (e.g. database errors) in API responses; it is logged at the call site instead.

func (*NoopWebpusher) Dispatch

func (*NoopWebpusher) PublicKey

func (*NoopWebpusher) PublicKey() string

func (*NoopWebpusher) Test

type Option added in v2.32.0

type Option func(*options)

Option configures optional behavior for a Webpusher.

func WithClock added in v2.32.0

func WithClock(clock quartz.Clock) Option

WithClock sets the clock used by the subscription cache. Defaults to a real clock when not provided.

func WithHTTPClient added in v2.33.0

func WithHTTPClient(client *http.Client) Option

WithHTTPClient overrides the default SSRF-safe HTTP client used to deliver push notifications. This is intended for tests that need to deliver to localhost test servers.

func WithSubscriptionCacheTTL added in v2.32.0

func WithSubscriptionCacheTTL(ttl time.Duration) Option

WithSubscriptionCacheTTL sets the in-memory subscription cache TTL. Defaults to three minutes when not provided or when given a non-positive duration.

type SubscriptionCacheInvalidator added in v2.32.0

type SubscriptionCacheInvalidator interface {
	InvalidateUser(userID uuid.UUID)
}

SubscriptionCacheInvalidator is an optional interface that lets local subscription mutation handlers invalidate cached subscriptions.

type Webpusher

type Webpusher struct {

	// public and private keys for VAPID. These are used to sign and encrypt
	// the message payload.
	VAPIDPublicKey  string
	VAPIDPrivateKey string
	// contains filtered or unexported fields
}

func (*Webpusher) Dispatch

func (n *Webpusher) Dispatch(ctx context.Context, userID uuid.UUID, msg codersdk.WebpushMessage) error

func (*Webpusher) InvalidateUser added in v2.32.0

func (n *Webpusher) InvalidateUser(userID uuid.UUID)

InvalidateUser clears the cached subscriptions for a user and advances its invalidation generation. Local subscribe and unsubscribe handlers call this after mutating subscriptions in the same process.

func (*Webpusher) PublicKey

func (n *Webpusher) PublicKey() string

PublicKey returns the VAPID public key for the webpush dispatcher. Clients need this, so it's exposed via the BuildInfo endpoint.

func (*Webpusher) Test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL