openrails

package
v0.98.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package openrails consumes independently acknowledged OpenRails notification events. Hosts own identity mapping, optional-event policy and scheduling. OpenRails produces facts; ContentKit owns the user inbox and its read state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BillingLifecycle added in v0.90.0

func BillingLifecycle(event Event) bool

BillingLifecycle selects unexpected billing outcomes. OpenRails keeps its complete event history; ContentKit avoids notifying about a user's own click.

Types

type Backend added in v0.90.0

type Backend interface {
	Register(context.Context) error
	Pending(context.Context, int) ([]Event, error)
	Acknowledge(context.Context, []string) error
	Retire(context.Context) error
}

Options binds one trusted OpenRails deployment, merchant and independent consumer. Token supplies a merchant-authorized application access token; Client may instead authenticate through its transport. URL precedes /v1.

type ConsumeOptions

type ConsumeOptions struct {
	Limit           int
	IncludeOptional bool
	// Filter is evaluated before recipient mapping; false intentionally skips+ACKs.
	Filter func(Event) bool
}

ConsumeOptions bounds one worker call. Optional events default to skip+ACK; opt in to map them, applying any per-user preferences inside RecipientMapper.

type ConsumeResult

type ConsumeResult struct{ Fetched, Delivered, Skipped, Acknowledged int }

ConsumeResult counts this attempt, including idempotent destination replays. Failed events remain pending. Acknowledged counts only a successful source ACK.

type Event

type Event struct {
	ID              string          `json:"id"`
	MerchantID      string          `json:"merchant_id"`
	CustomerID      string          `json:"customer_id"`
	EventType       string          `json:"event_type"`
	Data            json.RawMessage `json:"data"`
	CreatedAt       time.Time       `json:"created_at"`
	ActionRequested bool            `json:"action_requested,omitempty"`
	Optional        bool            `json:"optional,omitempty"`
}

Event is an immutable source fact, not an OpenRails-owned inbox item. Kind strings and JSON fields remain extensible. ActionRequested is historical, independent of a destination's tracked workflow state.

type Jobs added in v0.90.0

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

Jobs routes one shared worker to any number of explicitly configured sources. Each source has a distinct queue and durable consumer, and contributes to the same host fleet. A worker never acknowledges an unconfigured source's job.

func (*Jobs) Add added in v0.90.0

func (j *Jobs) Add(s *Source, destination notify.Publisher, mapper RecipientMapper, namespace string) (riverhelpers.Contribution, error)

Add contributes one source's queue, registration and periodic import. Call before starting the host fleet. Repeating a source is a configuration error.

type Options

type Options struct {
	// Backend connects an embedded OpenRails client; nil uses HTTP.
	Backend Backend
	// Name is the complete stable origin system; defaults to openrails:URL.
	Name       string
	URL        string
	MerchantID string
	// Consumer is stable across restarts and unique per destination within the
	// authenticated application/merchant. Tokens can rotate without losing ACKs.
	Consumer string
	Client   *http.Client
	Token    func(context.Context) (string, error)
}

type RecipientMapper

type RecipientMapper func(context.Context, Event) (recipientID string, deliver bool, err error)

RecipientMapper resolves the event's verified merchant/customer coordinates through host-owned account records. deliver=false deliberately skips the event and allows its ACK. An error keeps it pending for retry. Email equality alone must never establish the association. Future event kinds pass through.

type Source

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

Source consumes the notification events of one configured merchant.

func New

func New(opts Options) (*Source, error)

New validates configuration. Every HTTP request has a 15-second deadline. Redirects are refused to keep credentials on the configured deployment.

func (*Source) Consume

func (s *Source) Consume(ctx context.Context, destination notify.Publisher, mapper RecipientMapper, opts ConsumeOptions) (ConsumeResult, error)

Consume publishes one bounded pending page, then ACKs only committed or explicitly skipped events. Each consumer has independent ACKs. A failed ACK safely replays destination publication; local read/dismiss state survives. One failed mapping/publication does not prevent other events in the page. The host owns scheduling and retries; there is no cursor or time watermark.

func (*Source) Origin added in v0.90.0

func (s *Source) Origin() notify.OriginScope

Origin is the exact source namespace admitted by an integration.

func (*Source) Register

func (s *Source) Register(ctx context.Context) error

Register idempotently establishes this consumer's independent ACK namespace. Register before scheduling Consume; the source controls historical retention.

func (*Source) Retire

func (s *Source) Retire(ctx context.Context) error

Retire explicitly ends this consumer's delivery obligation. Do not retire on an ordinary worker shutdown: registration and ACKs must survive restarts.

Jump to

Keyboard shortcuts

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