extension

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const ExtensionDescription = "Unified multi-channel notification delivery engine"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "herald"

ExtensionName is the name registered with Forge.

View Source
const ExtensionVersion = "1.8.0"

ExtensionVersion is the semantic version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Config embeds the core herald configuration.
	herald.Config `json:",inline" yaml:",inline" mapstructure:",squash"`

	// BasePath is the URL prefix for all herald routes (default: "/herald").
	BasePath string `json:"base_path" yaml:"base_path" mapstructure:"base_path"`

	// DisableRoutes disables automatic route registration with the Forge router.
	DisableRoutes bool `json:"disable_routes" yaml:"disable_routes" mapstructure:"disable_routes"`

	// DisableMigrate disables automatic database migration on Register.
	DisableMigrate bool `json:"disable_migrate" yaml:"disable_migrate" mapstructure:"disable_migrate"`

	// GroveDatabase is the name of a grove.DB registered in the DI container.
	// When set, the extension resolves this named database and auto-constructs
	// the appropriate store based on the driver type (pg/sqlite/mongo).
	// When empty and WithGroveDatabase was called, the default (unnamed) DB is used.
	GroveDatabase string `json:"grove_database" mapstructure:"grove_database" yaml:"grove_database"`

	// Providers declares notification providers seeded into the store on
	// startup (seed-if-absent). Credentials may use ${ENV} interpolation.
	Providers []ProviderConfig `json:"providers" yaml:"providers" mapstructure:"providers"`

	// CredentialsKey encrypts provider credentials at rest: 32 bytes,
	// standard base64. Without it credentials are stored in plaintext, and
	// the dashboard says so. Supports ${ENV} interpolation.
	CredentialsKey string `json:"credentials_key" yaml:"credentials_key" mapstructure:"credentials_key"`

	// CredentialsKeyID is stored beside every value the key encrypts
	// (default "k1"). Change it when you rotate to a new key.
	CredentialsKeyID string `json:"credentials_key_id" yaml:"credentials_key_id" mapstructure:"credentials_key_id"`

	// PreviousCredentialsKeys only decrypt, so values written under an older
	// key keep working after a rotation.
	PreviousCredentialsKeys []CredentialKeyConfig `json:"previous_credentials_keys" yaml:"previous_credentials_keys" mapstructure:"previous_credentials_keys"`

	// DashboardAppID is the app the dashboard shows to a session that carries
	// no app_id claim. Empty means the "" app, where standalone installs keep
	// their data. A session whose claim is present but unusable is refused,
	// never shown this app.
	DashboardAppID string `json:"dashboard_app_id" yaml:"dashboard_app_id" mapstructure:"dashboard_app_id"`

	// RequireConfig requires config to be present in YAML files.
	// If true and no config is found, Register returns an error.
	RequireConfig bool `json:"-" yaml:"-"`
}

Config holds configuration for the Herald Forge extension. Fields can be set programmatically via ExtOption functions or loaded from YAML configuration files (under "extensions.herald" or "herald" keys).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

func (Config) ToHeraldOptions

func (c Config) ToHeraldOptions() []herald.Option

ToHeraldOptions converts the embedded Config into herald.Option values.

type CredentialKeyConfig

type CredentialKeyConfig struct {
	ID  string `json:"id" yaml:"id" mapstructure:"id"`
	Key string `json:"key" yaml:"key" mapstructure:"key"`
}

CredentialKeyConfig is one previous credential key.

type ExtOption

type ExtOption func(*Extension)

ExtOption configures the Herald Forge extension.

func WithAPIMiddleware

func WithAPIMiddleware(mw ...forge.Middleware) ExtOption

WithAPIMiddleware runs mw in front of every Herald REST route. Herald can't know your auth scheme, so this is where you put it. Without it, startup warns that the API is unauthenticated. Tenant isolation rests on this middleware too: it must bind each caller to the app_id they may use.

It applies only to routes Herald mounts itself. A host that disables them and mounts the API through Extension.RegisterRoutes gets no middleware from Herald and must apply its own on that router.

func WithBasePath

func WithBasePath(path string) ExtOption

WithBasePath sets the URL prefix for all herald routes.

func WithConfig

func WithConfig(cfg Config) ExtOption

WithConfig sets the extension configuration directly.

func WithDisableMigrate

func WithDisableMigrate() ExtOption

WithDisableMigrate disables automatic database migration on Register.

func WithDisableRoutes

func WithDisableRoutes() ExtOption

WithDisableRoutes disables automatic route registration.

func WithDriver

func WithDriver(d driver.Driver) ExtOption

WithDriver registers a notification driver with the Herald instance.

func WithGroveDatabase

func WithGroveDatabase(name string) ExtOption

WithGroveDatabase sets the name of the grove.DB to resolve from the DI container. The extension will auto-construct the appropriate store backend (postgres/sqlite/mongo) based on the grove driver type. Pass an empty string to use the default (unnamed) grove.DB.

func WithHeraldOption

func WithHeraldOption(opt herald.Option) ExtOption

WithHeraldOption appends a raw herald.Option to the extension.

func WithRequireConfig

func WithRequireConfig(require bool) ExtOption

WithRequireConfig requires configuration to be present in YAML files. If true and no config is found, Register returns an error.

func WithStore

func WithStore(s store.Store) ExtOption

WithStore sets the persistence backend via a herald option.

type Extension

type Extension struct {
	*forge.BaseExtension
	// contains filtered or unexported fields
}

Extension adapts Herald as a Forge extension. It implements the forge.Extension interface for full Forge lifecycle integration including registration, migration, route mounting, and graceful shutdown.

func New

func New(opts ...ExtOption) *Extension

New creates a Herald Forge extension with the given options.

func (*Extension) API

func (e *Extension) API() *api.ForgeAPI

API returns the Forge API handler.

func (*Extension) APIProtected

func (e *Extension) APIProtected() bool

APIProtected reports whether the REST API was mounted behind middleware. False also when routes are disabled and the host mounts them itself.

func (*Extension) BasePath

func (e *Extension) BasePath() string

BasePath returns the configured URL base path.

func (*Extension) Health

func (e *Extension) Health(ctx context.Context) error

Health implements forge.Extension.

func (*Extension) Herald

func (e *Extension) Herald() *herald.Herald

Herald returns the underlying Herald instance. This is nil until Register is called.

func (*Extension) Init

func (e *Extension) Init(fapp forge.App) error

Init initializes the extension. In a Forge environment, this is called during Register. For standalone use, call it manually.

func (*Extension) Register

func (e *Extension) Register(fapp forge.App) error

Register implements forge.Extension. It loads configuration, initializes Herald, runs migrations, registers routes, and provides the Herald instance to the DI container.

func (*Extension) RegisterContractContributor

func (e *Extension) RegisterContractContributor(
	disp *dispatcher.Dispatcher,
	reg dashcontract.Registry,
	wreg dashcontract.WardenRegistry,
) error

RegisterContractContributor implements dashboard.ContractContributorAware. It registers the herald contract contributor, which is what the React shell reads.

func (*Extension) RegisterRoutes

func (e *Extension) RegisterRoutes(router forge.Router)

RegisterRoutes registers all Herald API routes into a Forge router. Use this for Forge extension integration where the parent app owns the router. Middleware from WithAPIMiddleware is not applied here: guard router yourself (router.Use, before calling this) or every route is open.

func (*Extension) Start

func (e *Extension) Start(ctx context.Context) error

Start begins the Herald engine.

func (*Extension) Stop

func (e *Extension) Stop(ctx context.Context) error

Stop gracefully shuts down the Herald engine.

type ProviderConfig

type ProviderConfig struct {
	Name        string            `json:"name" yaml:"name" mapstructure:"name"`
	Channel     string            `json:"channel" yaml:"channel" mapstructure:"channel"`
	Driver      string            `json:"driver" yaml:"driver" mapstructure:"driver"`
	AppID       string            `json:"app_id" yaml:"app_id" mapstructure:"app_id"`
	Credentials map[string]string `json:"credentials" yaml:"credentials" mapstructure:"credentials"`
	Settings    map[string]string `json:"settings" yaml:"settings" mapstructure:"settings"`
	Priority    int               `json:"priority" yaml:"priority" mapstructure:"priority"`
	Enabled     *bool             `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
}

ProviderConfig declares a notification provider in config.yaml. It is seeded into the store on startup (see SeedConfiguredProviders).

Directories

Path Synopsis
Package contract wires Herald into the Forge dashboard's contract path.
Package contract wires Herald into the Forge dashboard's contract path.

Jump to

Keyboard shortcuts

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