contract

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package contract wires Herald into the Forge dashboard's contract path. It registers the `herald` contributor with the dashboard's contract registry and answers its intents from the live Herald engine.

This package is the surface the React dashboard shell reads. Every handler resolves the app from the session (scope.go) before it reads or writes anything, and no request field ever names an app.

Index

Constants

View Source
const ContributorName = "herald"

ContributorName is the join key with packages/plugin-herald's `extension` field. A mismatch hides the React plugin with no error anywhere, because that is what an uninstalled extension looks like.

Variables

This section is empty.

Functions

func Register

Register loads and validates the embedded manifest, registers the `herald` contributor with reg, and binds every handler against deps.

Types

type AppRef

type AppRef struct {
	ID    string `json:"id"`
	Label string `json:"label"`
}

AppRef names the app a session is looking at.

type ChannelPreferenceWire

type ChannelPreferenceWire struct {
	Email *bool `json:"email"`
	SMS   *bool `json:"sms"`
	Push  *bool `json:"push"`
	InApp *bool `json:"inapp"`
}

ChannelPreferenceWire is one type's per-channel settings. A null channel is "never set", which Herald treats as opted in.

type CredentialStatus

type CredentialStatus struct {
	Key        string `json:"key"`
	Protection string `json:"protection"`
	KeyID      string `json:"keyId,omitempty"`
}

CredentialStatus is how one stored credential is protected. It never carries the value.

type Deps

type Deps struct {
	// Herald is the engine. Required.
	Herald *herald.Herald

	// Logger receives an Error-level entry for every error a handler maps to
	// INTERNAL. Optional.
	Logger forge.Logger

	// DefaultAppID is the app a session with no app_id claim reads and
	// writes. Empty means the "" app, where standalone installs keep their
	// data. It is never used for a session whose claim is present but
	// unusable: that session is refused.
	DefaultAppID string

	// APIProtected reports whether the REST API was mounted behind host
	// middleware. Optional; nil reads as false. It's a func because the API is
	// mounted after the contract may be registered.
	APIProtected func() bool
}

Deps bundles what the handlers need.

type DriverInfo

type DriverInfo struct {
	Name    string      `json:"name"`
	Channel string      `json:"channel"`
	Fields  []FieldInfo `json:"fields"`
}

DriverInfo is a registered driver. Fields is null for a driver that doesn't describe itself, so the form falls back to key/value rows, and an empty list for one that needs nothing.

type FieldInfo

type FieldInfo struct {
	Key       string `json:"key"`
	Label     string `json:"label"`
	Help      string `json:"help,omitempty"`
	Required  bool   `json:"required"`
	Secret    bool   `json:"secret"`
	Placement string `json:"placement"`
}

FieldInfo describes one value a driver reads.

type LocaleState

type LocaleState struct {
	Locale string `json:"locale"`
	Active bool   `json:"active"`
}

LocaleState is one version's locale and whether it's live.

type MessageCount

type MessageCount struct {
	Status  string `json:"status"`
	Channel string `json:"channel"`
	N       int    `json:"n"`
}

MessageCount is the number of messages with one status on one channel.

type MessageDetail

type MessageDetail struct {
	MessageSummary
	Subject           string            `json:"subject,omitempty"`
	Body              string            `json:"body"`
	Metadata          map[string]string `json:"metadata"`
	Attempts          int               `json:"attempts"`
	Async             bool              `json:"async"`
	EnvID             string            `json:"envId,omitempty"`
	ProviderMessageID string            `json:"providerMessageId,omitempty"`
	Template          *TemplateRef      `json:"template"`
}

MessageDetail is every logged field of a message. Body holds the text part only, truncated at the engine's truncateBodyAt; HTML bodies aren't logged.

type MessageSummary

type MessageSummary struct {
	ID           string       `json:"id"`
	Recipient    string       `json:"recipient"`
	Channel      string       `json:"channel"`
	Status       string       `json:"status"`
	TemplateSlug string       `json:"templateSlug,omitempty"`
	Provider     *ProviderRef `json:"provider"`
	Error        string       `json:"error,omitempty"`
	CreatedAt    time.Time    `json:"createdAt"`
	SentAt       *time.Time   `json:"sentAt,omitempty"`
}

MessageSummary is a delivery-log row.

type NotificationWire

type NotificationWire struct {
	ID        string            `json:"id"`
	UserID    string            `json:"userId"`
	Type      string            `json:"type"`
	Title     string            `json:"title"`
	Body      string            `json:"body,omitempty"`
	ActionURL string            `json:"actionUrl,omitempty"`
	ImageURL  string            `json:"imageUrl,omitempty"`
	Read      bool              `json:"read"`
	ReadAt    *time.Time        `json:"readAt,omitempty"`
	Metadata  map[string]string `json:"metadata"`
	ExpiresAt *time.Time        `json:"expiresAt,omitempty"`
	CreatedAt time.Time         `json:"createdAt"`
}

NotificationWire is one in-app notification.

type PreferenceWire

type PreferenceWire struct {
	ID        string                           `json:"id"`
	UserID    string                           `json:"userId"`
	Overrides map[string]ChannelPreferenceWire `json:"overrides"`
	UpdatedAt time.Time                        `json:"updatedAt"`
}

PreferenceWire is a user's stored preference record.

type ProviderDetail

type ProviderDetail struct {
	ProviderSummary
	Settings []SettingEntry `json:"settings"`
	UsedBy   []RouteUse     `json:"usedBy"`
}

ProviderDetail is a provider with its settings and the routing rules that point at it, so deleting it can warn about what will dangle.

type ProviderRef

type ProviderRef struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Driver  string `json:"driver,omitempty"`
	Enabled *bool  `json:"enabled,omitempty"`
}

ProviderRef points at a provider. Driver and Enabled are set where a page needs them.

type ProviderSummary

type ProviderSummary struct {
	ID          string             `json:"id"`
	Name        string             `json:"name"`
	Channel     string             `json:"channel"`
	Driver      string             `json:"driver"`
	Priority    int                `json:"priority"`
	Enabled     bool               `json:"enabled"`
	Credentials []CredentialStatus `json:"credentials"`
	CreatedAt   time.Time          `json:"createdAt"`
	UpdatedAt   time.Time          `json:"updatedAt"`
}

ProviderSummary is a provider as list pages show it.

type ResolutionEntry

type ResolutionEntry struct {
	Locale    string  `json:"locale"`
	VersionID *string `json:"versionId"`
	Match     string  `json:"match"`
}

ResolutionEntry says which version answers a locale and how.

type RouteUse

type RouteUse struct {
	Scope   string `json:"scope"`
	ScopeID string `json:"scopeId"`
	Channel string `json:"channel"`
}

RouteUse is a routing rule that sends one channel through a provider.

type RoutedProvider

type RoutedProvider struct {
	ID       string `json:"id"`
	Name     string `json:"name,omitempty"`
	Dangling bool   `json:"dangling"`
}

RoutedProvider is a provider a rule points at. Dangling means the rule names an ID this app no longer has, so a send on that channel fails instead of falling back.

type ScopeRule

type ScopeRule struct {
	ID                  string                     `json:"id"`
	Scope               string                     `json:"scope"`
	ScopeID             string                     `json:"scopeId"`
	Providers           map[string]*RoutedProvider `json:"providers"`
	FromEmail           string                     `json:"fromEmail,omitempty"`
	FromName            string                     `json:"fromName,omitempty"`
	FromPhone           string                     `json:"fromPhone,omitempty"`
	DefaultLocale       string                     `json:"defaultLocale,omitempty"`
	DefaultLocaleUnused bool                       `json:"defaultLocaleUnused"`
	UpdatedAt           time.Time                  `json:"updatedAt"`
}

ScopeRule is one routing rule. Providers is keyed by channel and holds only the channels the rule sets.

type SettingEntry

type SettingEntry struct {
	Key    string  `json:"key"`
	Value  *string `json:"value,omitempty"`
	Secret bool    `json:"secret"`
}

SettingEntry is one setting. Value is omitted for a key the driver marks secret, which only a row written before placement rules can hold, and for every key when the driver isn't registered or has no schema.

type TemplateDetail

type TemplateDetail struct {
	TemplateSummary
	Variables []VariableWire `json:"variables"`
	Versions  []VersionWire  `json:"versions"`
}

TemplateDetail is a template with its variables and versions.

type TemplateRef

type TemplateRef struct {
	ID      string `json:"id"`
	Slug    string `json:"slug"`
	Channel string `json:"channel,omitempty"`
}

TemplateRef points at a template.

type TemplateSummary

type TemplateSummary struct {
	ID          string        `json:"id"`
	Slug        string        `json:"slug"`
	Name        string        `json:"name"`
	Channel     string        `json:"channel"`
	Category    string        `json:"category"`
	IsSystem    bool          `json:"isSystem"`
	Enabled     bool          `json:"enabled"`
	Locales     []LocaleState `json:"locales"`
	HasFallback bool          `json:"hasFallback"`
	UpdatedAt   time.Time     `json:"updatedAt"`
}

TemplateSummary is a template as list pages show it.

type VariableWire

type VariableWire struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Required    bool   `json:"required"`
	Default     string `json:"default,omitempty"`
	Description string `json:"description,omitempty"`
}

VariableWire is a declared template variable.

type VersionWire

type VersionWire struct {
	ID        string    `json:"id"`
	Locale    string    `json:"locale"`
	Subject   string    `json:"subject"`
	HTML      string    `json:"html"`
	Text      string    `json:"text"`
	Title     string    `json:"title"`
	Active    bool      `json:"active"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

VersionWire is one locale's content.

Jump to

Keyboard shortcuts

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