Documentation
¶
Overview ¶
Package notification adapts the shared helpers/notify inbox to ContentKit's authenticated user API. Persistence and lifecycle belong to helpers/notify; hosts own rendering and application-specific actions.
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, pool *pgxpool.Pool, schema string) error
- func ValidateEventCursors(ctx context.Context, pool *pgxpool.Pool, schema string) error
- type Config
- type EventImportResult
- type Options
- type Publication
- type Published
- type Store
- func (s *Store) AllowOrigin(origin notify.OriginScope) error
- func (s *Store) AppID() string
- func (s *Store) BindMerchant(ctx context.Context, tenantID string, origin notify.OriginScope) error
- func (s *Store) EraseAppRecipient(ctx context.Context, r notify.Recipient) error
- func (s *Store) ErasedRecipients(ctx context.Context, after string, limit int) ([]notify.Recipient, error)
- func (s *Store) EventCursor(ctx context.Context, origin notify.OriginScope) (string, error)
- func (s *Store) Get(ctx context.Context, r notify.Recipient, id string) (notify.Item, error)
- func (s *Store) Handler(a auth.Authenticator) (http.Handler, error)
- func (s *Store) ImportEvents(ctx context.Context, origin notify.OriginScope, after, next string, ...) (EventImportResult, error)
- func (s *Store) List(ctx context.Context, r notify.Recipient, o notify.ListOptions) (notify.Page, error)
- func (s *Store) Namespace() string
- func (s *Store) Publish(ctx context.Context, in notify.Input) (notify.Item, error)
- func (s *Store) PublishBatch(ctx context.Context, in []notify.Input) ([]notify.Item, error)
- func (s *Store) PublishTx(ctx context.Context, tx pgx.Tx, in notify.Input) (notify.Item, error)
- func (s *Store) SetDismissed(ctx context.Context, r notify.Recipient, id string, dismissed bool) (notify.Item, error)
- func (s *Store) SetRead(ctx context.Context, r notify.Recipient, id string, read bool) (notify.Item, error)
Constants ¶
const MaxPublish = 100
MaxPublish bounds one publish batch.
Variables ¶
var ErrEventCursorChanged = errors.New("notification: event cursor changed")
ErrEventCursorChanged means another replica committed this source page first. Read the new cursor before trying again; never overwrite newer progress.
var ErrMerchantBinding = errors.New("notification: merchant is bound to another tenant or source")
ErrMerchantBinding rejects a source that is not the tenant's verified billing association. It never reassigns a tenant or merchant during normal startup.
var ErrRecipientNotFound = errors.New("notification: recipient is not a live account in this tenant")
ErrRecipientNotFound means the requested user is not a live account in this tenant. Consumers may skip the notice; a directory outage is a different, retryable error. No account or erasure tombstone is created by this result.
Functions ¶
Types ¶
type Config ¶ added in v0.89.0
type Config struct {
Schema string `json:"schema" yaml:"schema"`
Namespace string `json:"namespace" yaml:"namespace"`
}
Config shares an account inbox without sharing a site's content catalog. Sites must share verified recipient IDs and the same Postgres database.
type EventImportResult ¶ added in v0.116.0
type EventImportResult struct{ Published, Skipped int }
EventImportResult counts the committed inbox effects, including idempotent replays. Missing and erased recipients are deliberately skipped.
type Options ¶
type Options struct {
Pool *pgxpool.Pool
Schema, Tenant string
Logger *slog.Logger
// AppID comes from the engine immutable Scope, never from an HTTP selector.
AppID string
// AccountExists proves a user recipient belongs to this store's account
// tenant. Scoped user publication fails closed without this lookup. The
// directory must be fixed to the target tenant, not the request actor's.
AccountExists func(context.Context, string) (bool, error)
// AccountExistsTx provides the same proof on the caller's transaction.
// PublishTx and batch publication never acquire a second pool connection.
AccountExistsTx func(context.Context, pgx.Tx, string) (bool, error)
}
Options selects the pool, ContentKit's schema and its tenant.
type Publication ¶ added in v0.81.0
Publication is a batch of notices a host service publishes.
type Published ¶ added in v0.81.0
Published is each notice of a Publication as stored, in order, without those dropped for an erased recipient.
type Store ¶
Store mounts a shared notification store as one ContentKit tenant's inbox. Embedded methods accept trusted host inputs; HTTP derives the user identity.
func (*Store) AllowOrigin ¶ added in v0.89.0
func (s *Store) AllowOrigin(origin notify.OriginScope) error
AllowOrigin adds one trusted producer namespace to a shared site's view. Called by integrations during startup; it grants no recipient authority.
func (*Store) AppID ¶ added in v0.89.0
AppID is the fixed app presentation boundary, empty only on legacy runtimes.
func (*Store) BindMerchant ¶ added in v0.89.0
BindMerchant pins one verified producer/merchant pair to an already registered tenant account store. Matching concurrent app startups are idempotent; neither another tenant's merchant nor another merchant for this tenant can be attached.
func (*Store) EraseAppRecipient ¶ added in v0.89.0
EraseAppRecipient fences only this configured app's notices, never the tenant inbox or another app's receipts. It also identifies the app's legacy native origin without including shared billing origins.
func (*Store) ErasedRecipients ¶ added in v0.89.0
func (s *Store) ErasedRecipients(ctx context.Context, after string, limit int) ([]notify.Recipient, error)
ErasedRecipients is the canonical account/app erasure list for replay after restoring only this app's data. It never returns a sibling's app-only fences.
func (*Store) EventCursor ¶ added in v0.116.0
EventCursor is the inbox's progress through one trusted source. It is local destination state; reading it does not register anything with the producer.
func (*Store) Handler ¶
Handler serves the authenticated person's inbox and read state, and the host service's publish route. People select no recipient and write no notices.
func (*Store) ImportEvents ¶ added in v0.116.0
func (s *Store) ImportEvents(ctx context.Context, origin notify.OriginScope, after, next string, inputs []notify.Input) (EventImportResult, error)
ImportEvents saves a source page and its continuation in the same transaction. Network reads and recipient mapping happen before this call. The row lock only covers local writes, so replicas cannot lose progress or partial pages.
func (*Store) Namespace ¶ added in v0.89.0
Namespace is the stable shared account namespace, or the legacy tenant.
func (*Store) Publish ¶ added in v0.89.0
Publish defaults native/host authored notices to this app. Tenant-wide publication is reserved for trusted in-process integrations; the HTTP route does not accept that authority from an app client.
func (*Store) PublishBatch ¶ added in v0.81.0
PublishBatch stores a batch in one transaction (see the publish route).