push

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 22 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 push is the native mobile-push side of the companion app: a provider-agnostic Sender port plus its adapters, APNs for iOS (apns.go) and Firebase Cloud Messaging for Android (fcm.go). It carries NO approval authority — a push is only a WAKE ("you have a pending approval"); the approve/deny happens in-app over the authenticated WebSocket, so the signed HITL decision never leaves the daemon. Which devices are reachable is the auth store's (a push token lives on the paired device); this package only delivers to tokens the caller supplies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APNS

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

APNS delivers pushes to Apple Push Notification service over HTTP/2 with a token-based (ES256 JWT) authorization. It implements Sender. The provider auth token is cached and reused up to APNs' one-hour ceiling (regenerated at ~50 minutes). Safe for concurrent use.

func APNSFromEnv

func APNSFromEnv(onBadToken func(token string)) (*APNS, error)

APNSFromEnv builds the adapter from NOCTURN_APNS_KEY / _KEY_ID / _TEAM_ID / _BUNDLE_ID (and the optional NOCTURN_APNS_PRODUCTION), reporting permanently invalid tokens to onBadToken. It returns (nil, nil) when NOCTURN_APNS_KEY is unset — push is simply off — so the caller falls back to a no-op.

func NewAPNS

func NewAPNS(cfg APNSConfig) (*APNS, error)

NewAPNS parses the .p8 signing key and builds the adapter. It fails if the key is missing, not PEM, or not an ECDSA PKCS#8 key.

func (*APNS) Send

func (a *APNS) Send(ctx context.Context, m Message, tokens []string) error

Send delivers m to every token. A token APNs rejects as permanently invalid is reported via OnBadToken. It returns nil if at least one token was delivered, else an error — so a caller can treat "nobody reachable" as fail-closed.

type APNSConfig

type APNSConfig struct {
	Key        string
	KeyID      string
	TeamID     string
	BundleID   string
	Production bool
	OnBadToken func(token string)

	// Host overrides the APNs host:port. Empty selects the live/sandbox host from Production.
	Host string
	// HTTPClient overrides the HTTP/2 client. Nil uses the default, which negotiates HTTP/2 via ALPN.
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

APNSConfig configures the Apple Push adapter. Key is the token-signing key (a PKCS#8 EC private key downloaded from the Apple Developer portal) — either its PEM content or a path to the .p8; KeyID and TeamID identify it; BundleID is the app's bundle identifier (the apns-topic). Production selects the live APNs host vs the sandbox. OnBadToken, if set, is called with any token APNs reports permanently invalid, so the caller can drop it.

type FCM added in v0.5.0

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

FCM delivers pushes to Android devices through the FCM HTTP v1 API, authenticated as a service account. The access token is minted from the account's key and refreshed by x/oauth2 before it expires; no Google SDK is involved.

func FCMFromEnv added in v0.5.0

func FCMFromEnv(onBadToken func(token string)) (*FCM, error)

FCMFromEnv builds the adapter from NOCTURN_FCM_CREDENTIALS (the service account JSON, or a path to it), reporting unregistered tokens to onBadToken. It returns nil, nil when the variable is unset: Android push is simply off.

func NewFCM added in v0.5.0

func NewFCM(cfg FCMConfig) (*FCM, error)

NewFCM reads the service account and builds the adapter. It fails if the credentials are missing, not a service account key, or lack a project id, an email or a private key.

func (*FCM) Send added in v0.5.0

func (f *FCM) Send(ctx context.Context, m Message, tokens []string) error

Send delivers m to every token. A token FCM reports as unregistered is passed to OnBadToken. It returns nil if at least one token was delivered, else an error, so "nobody reachable" fails closed.

type FCMConfig added in v0.5.0

type FCMConfig struct {
	Credentials string
	OnBadToken  func(token string)

	// Endpoint overrides the send URL (tests); %s is replaced with the project id.
	Endpoint string
	// TokenURL overrides the service account's token endpoint (tests).
	TokenURL string
	// HTTPClient overrides the client for both the token exchange and the sends.
	HTTPClient *http.Client
}

FCMConfig configures the Firebase Cloud Messaging adapter, which reaches Android devices. Credentials is a Firebase service account key (the JSON a project's console downloads), either its content or a path to the file; the project id and the signing key are read from it. OnBadToken, if set, is called with any token FCM reports as no longer registered, so the caller can drop it.

type Message

type Message struct {
	Title string
	Body  string
	Data  map[string]string
}

Message is one push to deliver. Title/Body are the user-visible notification; Data is an opaque key/value payload the app reads on tap. It never carries an approval token — resolution is in-app.

type Sender

type Sender interface {
	Send(ctx context.Context, m Message, tokens []string) error
}

Sender delivers a Message to a set of device tokens. The APNs adapter implements it; a nil Sender (no provider configured) means push is simply off.

Jump to

Keyboard shortcuts

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