webpush

package
v0.134.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webpush owns browser Web Push encryption, VAPID identity, subscriptions, one-time notification actions and asynchronous event dispatch.

Index

Constants

View Source
const (
	DefaultVAPIDSubject = "mailto:gofer@localhost"
)

Variables

View Source
var (
	ErrActionUnauthorized = errors.New("webpush: invalid action token")
	ErrActionExpired      = errors.New("webpush: action token expired")
	ErrActionUsed         = errors.New("webpush: action token already used")
	ErrActionOption       = errors.New("webpush: action option is not allowed")
)
View Source
var ErrNoSubscriptions = errors.New("webpush: caller has no subscriptions")

Functions

This section is empty.

Types

type ActionClaims

type ActionClaims struct {
	CallerID      string   `json:"caller"`
	JobID         string   `json:"job"`
	InteractionID string   `json:"interaction"`
	Options       []string `json:"options"`
	ExpiresAt     int64    `json:"exp"`
	Nonce         string   `json:"nonce"`
}

ActionClaims is the authenticated, self-contained part of an OS notification action. The nonce registry supplies the one-time property; the HMAC supplies integrity and process identity.

type Jobs

type Jobs interface {
	Get(id string) (job.JobResult, bool)
	GetInteractions(jobID string) ([]job.Interaction, error)
	AnswerInteractionByPush(jobID, interactionID, answer string) (job.Interaction, error)
}

Jobs is the authoritative interaction/job seam used by dispatch and actions.

type NotificationAction

type NotificationAction struct {
	Action string `json:"action"`
	Title  string `json:"title"`
	Option string `json:"option"`
}

NotificationAction maps one OS notification button to the exact interaction option value bound into its action token.

type Options

type Options struct {
	Store                 *jobstore.Store
	Jobs                  Jobs
	ConfigDir             string
	Subject               string
	HTTPClient            *http.Client
	Now                   func() time.Time
	Random                io.Reader
	UserCallers           func() []string
	Visible               func(callerID, projectKey string) bool
	AllowInsecureLoopback bool
}

Options contains assembly-owned dependencies. Time/random/HTTP are injectable boundaries; production leaves them nil for secure defaults.

type PushPayload

type PushPayload struct {
	Title       string               `json:"title"`
	Body        string               `json:"body,omitempty"`
	ThreadID    string               `json:"thread_id,omitempty"`
	URL         string               `json:"url"`
	Tag         string               `json:"tag,omitempty"`
	ActionToken string               `json:"action_token,omitempty"`
	Actions     []NotificationAction `json:"actions,omitempty"`
}

PushPayload is intentionally small: no logs, full prompts or secrets.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service owns process-lifetime transient state. Subscription rows and job interactions remain authoritative in their existing stores.

func NewService

func NewService(opts Options) (*Service, error)

func (*Service) Act

func (s *Service) Act(token, option string) (job.Interaction, error)

func (*Service) Close

func (s *Service) Close()

func (*Service) DeleteSubscription

func (s *Service) DeleteSubscription(callerID, endpoint string) (bool, error)

func (*Service) ListSubscriptions

func (s *Service) ListSubscriptions(callerID string) ([]jobstore.PushSubscription, error)

func (*Service) NewActionToken

func (s *Service) NewActionToken(callerID, jobID, interactionID string, options []string) (string, error)

func (*Service) ObserveEvent

func (s *Service) ObserveEvent(scope, eventType string, detail map[string]any)

ObserveEvent implements job.JobEventObserver. It never blocks the job event path and never performs crypto/network I/O inline.

func (*Service) PublicKey

func (s *Service) PublicKey() (string, error)

func (*Service) QueueTest

func (s *Service) QueueTest(callerID string) (int, error)

QueueTest enqueues one non-action notification to the caller's current subscriptions. The return value is the number of endpoints accepted for async processing, not a delivery receipt.

func (*Service) Subscribe

func (s *Service) Subscribe(callerID string, input SubscriptionInput, userAgent string) (jobstore.PushSubscription, error)

type SubscriptionInput

type SubscriptionInput struct {
	Endpoint string           `json:"endpoint"`
	Keys     SubscriptionKeys `json:"keys"`
}

SubscriptionInput is the browser PushSubscription shape accepted by HTTP.

type SubscriptionKeys

type SubscriptionKeys struct {
	P256DH string `json:"p256dh"`
	Auth   string `json:"auth"`
}

Jump to

Keyboard shortcuts

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