push

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package push defines the per-project push settings: the enabled switch for the push-device registry (milestone 20) and the Web Push VAPID public key browser clients subscribe with. Plain, non-secret config — the matching VAPID private key stays with the developer's sender and never touches moth.

Like the paywall config it is a small versioned document stored on the project row (as a moth.projectconfig.v1.StoredPush protobuf message), but deliberately simpler: a full-replacement setting with no revision history. It is delivered to clients through the public moth.auth.v1.GetProjectConfig response.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is stamped on every encoded push-settings document. Parse rejects documents from a different version; future schema changes bump it and add an explicit upgrade path.

Variables

This section is empty.

Functions

func Encode

func Encode(c Config) ([]byte, error)

Encode serializes the config as its canonical storage document (a moth.projectconfig.v1.StoredPush protobuf message), stamping the current schema version.

func ToProto

func ToProto(c Config) *projectconfigv1.StoredPush

ToProto converts the domain config into its storage message.

func ValidateVAPIDPublicKey

func ValidateVAPIDPublicKey(key string) error

ValidateVAPIDPublicKey checks a non-empty VAPID public key for shape: base64url without padding, decoding to an uncompressed P-256 public point (65 bytes starting 0x04) — what the browser's `applicationServerKey` requires. It is the single server-side rule; Config.Validate and any prompt-time validation (the CLI wizard, `moth setup`) call it so a typo is caught the same way everywhere.

Types

type Config

type Config struct {
	// Version is the schema version of the document (SchemaVersion).
	Version int
	// Enabled is the master switch for the push registry; when false the
	// client-facing moth.push.v1 RPCs refuse registrations.
	Enabled bool
	// WebPushVAPIDPublicKey is the VAPID public key (base64url, uncompressed
	// P-256 point) browser clients subscribe with; empty when the project
	// does not use Web Push.
	WebPushVAPIDPublicKey string
}

Config is one project's push settings.

func Default

func Default() Config

Default returns the settings of a project that never configured push: disabled, no VAPID key.

func FromProto

func FromProto(msg *projectconfigv1.StoredPush) Config

FromProto converts a storage message into the domain config.

func FromStored

func FromStored(raw []byte) Config

FromStored returns the settings a project effectively runs with: the parsed stored document, or Default() when the project never configured push (empty bytes) or — defensively — when the stored document cannot be parsed (a newer schema or corruption reads as "disabled", never as an error on the hot paths).

func Parse

func Parse(raw []byte) (Config, error)

Parse decodes a stored push-settings document (moth.projectconfig.v1.StoredPush). It rejects documents from a different schema version — including empty input, which callers treat as "push never configured" before parsing; it does not validate values (Validate does).

func (Config) Validate

func (c Config) Validate() error

Validate checks the config and returns the first violation. The VAPID key is validated for shape only (base64url, uncompressed P-256 point) — moth never uses it to send, so a key the browser would reject is the only mistake worth catching here.

Jump to

Keyboard shortcuts

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