plugin

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package plugin re-exports the public plugin types from pkg/plugin.

This allows internal code to continue importing "internal/plugin" unchanged while the canonical type definitions live in the public pkg/plugin package, accessible to external plugin authors.

Index

Constants

This section is empty.

Variables

View Source
var DefaultResourcePolicy = pkgplugin.DefaultResourcePolicy

DefaultResourcePolicy re-exports the default policy constructor.

View Source
var PluginCallerKey = pluginCallerKeyType{}

PluginCallerKey is the context key for tracking which plugin is making a call.

View Source
var PluginLanguageKey = pluginLangKeyType{}

Functions

func RegisterPluginJobs

func RegisterPluginJobs(mgr *Manager, sched *scheduler.Service) int

RegisterPluginJobs registers all plugin-defined jobs with the scheduler. Call this after plugins are loaded and the scheduler is created.

func SetTemplateOverrides

func SetTemplateOverrides(registry *TemplateOverrideRegistry)

SetTemplateOverrides sets the global template override registry.

func SetTemplatePluginManager

func SetTemplatePluginManager(mgr *Manager)

SetTemplatePluginManager sets the plugin manager for template tags. Call this during app initialization after creating the plugin manager.

Types

type CascadeSpec added in v0.8.0

type CascadeSpec = pkgplugin.CascadeSpec

type CustomFieldFilter added in v0.8.0

type CustomFieldFilter = pkgplugin.CustomFieldFilter

type CustomFieldSpec added in v0.8.0

type CustomFieldSpec = pkgplugin.CustomFieldSpec

type DefaultHostAPI

type DefaultHostAPI struct {
}

DefaultHostAPI provides a basic implementation of HostAPI. In production, this would be wired to actual database, cache, etc.

func NewDefaultHostAPI

func NewDefaultHostAPI() *DefaultHostAPI

NewDefaultHostAPI creates a new default host API.

func (*DefaultHostAPI) CacheDelete

func (h *DefaultHostAPI) CacheDelete(ctx context.Context, key string) error

CacheDelete removes a value from cache.

func (*DefaultHostAPI) CacheGet

func (h *DefaultHostAPI) CacheGet(ctx context.Context, key string) ([]byte, bool, error)

CacheGet retrieves a value from cache.

func (*DefaultHostAPI) CacheSet

func (h *DefaultHostAPI) CacheSet(ctx context.Context, key string, value []byte, ttlSeconds int) error

CacheSet stores a value in cache.

func (*DefaultHostAPI) CallPlugin

func (h *DefaultHostAPI) CallPlugin(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)

CallPlugin calls a function in another plugin.

func (*DefaultHostAPI) ConfigGet

func (h *DefaultHostAPI) ConfigGet(ctx context.Context, key string) (string, error)

ConfigGet retrieves a configuration value.

func (*DefaultHostAPI) CustomFieldsGet added in v0.8.0

func (h *DefaultHostAPI) CustomFieldsGet(ctx context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)

CustomFieldsGet retrieves custom field values for an entity.

func (*DefaultHostAPI) CustomFieldsQuery added in v0.8.0

func (h *DefaultHostAPI) CustomFieldsQuery(ctx context.Context, entityType string, filters []CustomFieldFilter) ([]int64, error)

CustomFieldsQuery finds entities by custom field values.

func (*DefaultHostAPI) CustomFieldsSet added in v0.8.0

func (h *DefaultHostAPI) CustomFieldsSet(ctx context.Context, entityType string, objectID int64, values map[string]any) error

CustomFieldsSet stores custom field values for an entity.

func (*DefaultHostAPI) DBExec

func (h *DefaultHostAPI) DBExec(ctx context.Context, query string, args ...any) (int64, error)

DBExec executes a statement and returns affected rows.

func (*DefaultHostAPI) DBQuery

func (h *DefaultHostAPI) DBQuery(ctx context.Context, query string, args ...any) ([]map[string]any, error)

DBQuery executes a query and returns rows as maps.

func (*DefaultHostAPI) EntityHardDelete added in v0.8.0

func (h *DefaultHostAPI) EntityHardDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntityHardDelete is not available in default host.

func (*DefaultHostAPI) EntityRestore added in v0.8.0

func (h *DefaultHostAPI) EntityRestore(ctx context.Context, entityType string, entityID int64) error

EntityRestore is not available in default host.

func (*DefaultHostAPI) EntitySoftDelete added in v0.8.0

func (h *DefaultHostAPI) EntitySoftDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntitySoftDelete is not available in default host.

func (*DefaultHostAPI) HTTPRequest

func (h *DefaultHostAPI) HTTPRequest(ctx context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)

HTTPRequest makes an outbound HTTP request.

func (*DefaultHostAPI) Log

func (h *DefaultHostAPI) Log(ctx context.Context, level, message string, fields map[string]any)

Log writes a log entry.

func (*DefaultHostAPI) OrgID added in v0.8.0

func (h *DefaultHostAPI) OrgID(ctx context.Context) int64

OrgID returns 0 (no org context in default host).

func (*DefaultHostAPI) PublishEvent added in v0.7.0

func (h *DefaultHostAPI) PublishEvent(ctx context.Context, eventType string, data string) error

PublishEvent sends an SSE event to connected browser clients.

func (*DefaultHostAPI) RecycleBinList added in v0.8.0

func (h *DefaultHostAPI) RecycleBinList(ctx context.Context, entityType string) (json.RawMessage, error)

RecycleBinList is not available in default host.

func (*DefaultHostAPI) SecureConfigGet added in v0.8.0

func (h *DefaultHostAPI) SecureConfigGet(ctx context.Context, key string) (string, error)

SecureConfigGet returns empty (not available in default host).

func (*DefaultHostAPI) SecureConfigSet added in v0.8.0

func (h *DefaultHostAPI) SecureConfigSet(ctx context.Context, key string, value string) error

SecureConfigSet returns error (not available in default host).

func (*DefaultHostAPI) SendEmail

func (h *DefaultHostAPI) SendEmail(ctx context.Context, to, subject, body string, html bool) error

SendEmail sends an email.

func (*DefaultHostAPI) Translate

func (h *DefaultHostAPI) Translate(ctx context.Context, key string, args ...any) string

Translate translates a key to the current locale.

type ErrorCodeSpec

type ErrorCodeSpec = pkgplugin.ErrorCodeSpec

type GKRegistration

type GKRegistration = pkgplugin.GKRegistration

type HostAPI

type HostAPI = pkgplugin.HostAPI

type I18nSpec

type I18nSpec = pkgplugin.I18nSpec

type JobSpec

type JobSpec = pkgplugin.JobSpec

type LazyLoader

type LazyLoader interface {
	EnsureLoaded(ctx context.Context, name string) error
	Discovered() []string
}

LazyLoader is the interface for lazy-loading plugins on demand.

type LogBuffer

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

LogBuffer is a ring buffer for plugin logs.

func GetLogBuffer

func GetLogBuffer() *LogBuffer

GetLogBuffer returns the global plugin log buffer.

func NewLogBuffer

func NewLogBuffer(maxSize int) *LogBuffer

NewLogBuffer creates a new log buffer with the given max size.

func (*LogBuffer) Add

func (b *LogBuffer) Add(entry LogEntry)

Add adds a log entry to the buffer.

func (*LogBuffer) Clear

func (b *LogBuffer) Clear()

Clear removes all entries from the buffer.

func (*LogBuffer) Count

func (b *LogBuffer) Count() int

Count returns the number of entries in the buffer.

func (*LogBuffer) GetAll

func (b *LogBuffer) GetAll() []LogEntry

GetAll returns all log entries, newest first.

func (*LogBuffer) GetByLevel

func (b *LogBuffer) GetByLevel(minLevel string) []LogEntry

GetByLevel returns log entries at or above the given level, newest first.

func (*LogBuffer) GetByPlugin

func (b *LogBuffer) GetByPlugin(pluginName string) []LogEntry

GetByPlugin returns log entries for a specific plugin, newest first.

func (*LogBuffer) GetRecent

func (b *LogBuffer) GetRecent(n int) []LogEntry

GetRecent returns the most recent n entries, newest first.

func (*LogBuffer) Log

func (b *LogBuffer) Log(plugin, level, message string, fields map[string]any)

Log adds a log entry with the given parameters.

type LogEntry

type LogEntry struct {
	Timestamp time.Time      `json:"timestamp"`
	Plugin    string         `json:"plugin"`
	Level     string         `json:"level"` // debug, info, warn, error
	Message   string         `json:"message"`
	Fields    map[string]any `json:"fields,omitempty"`
}

LogEntry represents a single plugin log entry.

type Manager

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

Manager handles plugin lifecycle: loading, registration, and invocation.

func NewManager

func NewManager(host HostAPI) *Manager

NewManager creates a plugin manager with the given host API.

func (*Manager) AllPluginStats added in v0.7.0

func (m *Manager) AllPluginStats() []StatsSnapshot

AllPluginStats returns resource usage stats for all plugins.

func (*Manager) AllPolicies added in v0.7.0

func (m *Manager) AllPolicies() map[string]ResourcePolicy

AllPolicies returns all current policies.

func (*Manager) AllWidgets

func (m *Manager) AllWidgets(location string) []PluginWidget

AllWidgets returns widgets from all plugins (including lazy-loaded) for a location. This triggers lazy loading for all discovered plugins to ensure complete widget list.

func (*Manager) Call

func (m *Manager) Call(ctx context.Context, pluginName, fn string, args []byte) ([]byte, error)

Call invokes a function on a specific plugin. If lazy loading is enabled and the plugin isn't loaded yet, it will be loaded first.

func (*Manager) CallFrom

func (m *Manager) CallFrom(ctx context.Context, callerPlugin, targetPlugin, fn string, args []byte) ([]byte, error)

CallFrom invokes a function on a plugin, with caller context for better errors. If lazy loading is enabled and the plugin isn't loaded yet, it will be loaded first.

func (*Manager) Disable

func (m *Manager) Disable(name string) error

Disable disables a plugin without unloading it.

func (*Manager) Discovered

func (m *Manager) Discovered() []string

Discovered returns the names of discovered but not necessarily loaded plugins.

func (*Manager) Enable

func (m *Manager) Enable(name string) error

Enable enables a previously disabled plugin. If the plugin is lazy-loaded and not yet registered, it will be loaded first.

func (*Manager) Get

func (m *Manager) Get(name string) (Plugin, bool)

Get returns a plugin by name.

func (*Manager) GetPolicy added in v0.7.0

func (m *Manager) GetPolicy(name string) (ResourcePolicy, bool)

GetPolicy returns the current policy for a plugin.

func (*Manager) HiddenMenuItems added in v0.7.0

func (m *Manager) HiddenMenuItems() []string

HiddenMenuItems returns all menu item IDs that enabled plugins want hidden.

func (*Manager) Host added in v0.7.0

func (m *Manager) Host() HostAPI

Host returns the manager's HostAPI instance.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled(name string) bool

IsEnabled returns whether a plugin is enabled.

func (*Manager) Jobs

func (m *Manager) Jobs() []PluginJob

Jobs returns all jobs from all enabled plugins.

func (*Manager) LandingPage added in v0.7.0

func (m *Manager) LandingPage() string

LandingPage returns the landing page URL from the first enabled plugin that declares one. If no plugin sets a landing page, returns empty string.

func (*Manager) List

func (m *Manager) List() []GKRegistration

List returns all registered plugin manifests.

func (*Manager) MenuItems

func (m *Manager) MenuItems(location string) []PluginMenuItem

MenuItems returns all menu items from all enabled plugins.

func (*Manager) PluginStats added in v0.7.0

func (m *Manager) PluginStats(name string) (StatsSnapshot, bool)

PluginStats returns resource usage stats for a plugin.

func (*Manager) Register

func (m *Manager) Register(ctx context.Context, p Plugin) error

Register loads and initializes a plugin.

func (*Manager) ReplacePlugin added in v0.7.0

func (m *Manager) ReplacePlugin(ctx context.Context, oldName string, newPlugin Plugin) error

ReplacePlugin atomically replaces an existing plugin with a new one. This prevents race conditions during hot reload.

func (*Manager) Routes

func (m *Manager) Routes() []PluginRoute

Routes returns all routes from all enabled plugins.

func (*Manager) SetLazyLoader

func (m *Manager) SetLazyLoader(loader LazyLoader)

SetLazyLoader sets the lazy loader for on-demand plugin loading.

func (*Manager) SetPolicy added in v0.7.0

func (m *Manager) SetPolicy(name string, policy ResourcePolicy)

SetPolicy sets the resource policy for a plugin (admin override). Policy changes take effect immediately and are persisted to the database.

func (*Manager) ShutdownAll

func (m *Manager) ShutdownAll(ctx context.Context) error

ShutdownAll shuts down all plugins gracefully.

func (*Manager) Unregister

func (m *Manager) Unregister(ctx context.Context, name string) error

Unregister shuts down and removes a plugin.

func (*Manager) Widgets

func (m *Manager) Widgets(location string) []PluginWidget

Widgets returns all widgets from all enabled plugins for a location.

type MenuItemSpec = pkgplugin.MenuItemSpec

type Permission added in v0.7.0

type Permission = pkgplugin.Permission

type Plugin

type Plugin = pkgplugin.Plugin

type PluginCaller

type PluginCaller struct {
	Manager    *Manager
	PluginName string
	Ctx        context.Context // Optional context for i18n
}

PluginCaller wraps plugin function calls for templates. Exported so it can be used directly in template contexts.

func (*PluginCaller) Call

func (pc *PluginCaller) Call(fn string, args ...interface{}) interface{}

Call invokes a plugin function. Used via {{ plugin.Call("fn", args) }}

func (*PluginCaller) Translate

func (pc *PluginCaller) Translate(key string, args ...interface{}) string

Translate calls the plugin's translation with the current context language.

func (*PluginCaller) Widget

func (pc *PluginCaller) Widget(widgetID string) string

Widget renders a plugin widget by ID. Returns HTML string.

type PluginDisabledError

type PluginDisabledError struct {
	PluginName   string
	CallerPlugin string
}

PluginDisabledError is returned when trying to call a disabled plugin.

func (*PluginDisabledError) Error

func (e *PluginDisabledError) Error() string

type PluginJob

type PluginJob struct {
	PluginName string
	JobSpec
}

PluginJob pairs a job spec with its plugin name.

type PluginMenuItem

type PluginMenuItem struct {
	PluginName string
	MenuItemSpec
}

PluginMenuItem pairs a menu item spec with its plugin name.

type PluginNotFoundError

type PluginNotFoundError struct {
	PluginName   string // The missing plugin
	CallerPlugin string // The plugin that tried to call it (if known)
	Function     string // The function that was called
}

PluginNotFoundError is returned when a plugin dependency is missing.

func (*PluginNotFoundError) Error

func (e *PluginNotFoundError) Error() string

type PluginRoute

type PluginRoute struct {
	PluginName string
	RouteSpec  RouteSpec
}

PluginRoute pairs a route spec with its plugin name.

type PluginStats added in v0.7.0

type PluginStats struct {
	DBQueries    atomic.Int64
	DBExecs      atomic.Int64
	CacheOps     atomic.Int64
	HTTPRequests atomic.Int64
	Calls        atomic.Int64
	Errors       atomic.Int64
	LastCallAt   atomic.Int64 // unix millis
}

PluginStats tracks resource usage for a plugin.

func (*PluginStats) Snapshot added in v0.7.0

func (s *PluginStats) Snapshot(name string) StatsSnapshot

Snapshot returns a copy of the current stats.

type PluginWidget

type PluginWidget struct {
	PluginName string
	WidgetSpec
}

PluginWidget pairs a widget spec with its plugin name.

type ProdHostAPI

type ProdHostAPI struct {
	PluginManager *Manager   // For plugin-to-plugin calls
	SSEBroker     *SSEBroker // For publishing SSE events to browsers
	// contains filtered or unexported fields
}

ProdHostAPI is the production implementation of HostAPI. It wires plugins to real database, cache, email, and other services.

func NewProdHostAPI

func NewProdHostAPI(opts ...ProdHostAPIOption) *ProdHostAPI

NewProdHostAPI creates a production host API with the given options.

func (*ProdHostAPI) CacheDelete

func (h *ProdHostAPI) CacheDelete(ctx context.Context, key string) error

CacheDelete removes a value from cache.

func (*ProdHostAPI) CacheGet

func (h *ProdHostAPI) CacheGet(ctx context.Context, key string) ([]byte, bool, error)

CacheGet retrieves a value from cache.

func (*ProdHostAPI) CacheSet

func (h *ProdHostAPI) CacheSet(ctx context.Context, key string, value []byte, ttlSeconds int) error

CacheSet stores a value in cache.

func (*ProdHostAPI) CallPlugin

func (h *ProdHostAPI) CallPlugin(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)

CallPlugin calls a function in another plugin. This enables plugin-to-plugin communication via the host. If PluginCallerKey is set in the context, provides better error messages.

func (*ProdHostAPI) ConfigGet

func (h *ProdHostAPI) ConfigGet(ctx context.Context, key string) (string, error)

ConfigGet retrieves a configuration value by key path. Supports dot notation for nested values (e.g., "app.name").

func (*ProdHostAPI) CustomFieldsGet added in v0.8.0

func (h *ProdHostAPI) CustomFieldsGet(ctx context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)

CustomFieldsGet retrieves custom field values for an entity.

func (*ProdHostAPI) CustomFieldsQuery added in v0.8.0

func (h *ProdHostAPI) CustomFieldsQuery(ctx context.Context, entityType string, filters []CustomFieldFilter) ([]int64, error)

CustomFieldsQuery finds entities by custom field values.

func (*ProdHostAPI) CustomFieldsSet added in v0.8.0

func (h *ProdHostAPI) CustomFieldsSet(ctx context.Context, entityType string, objectID int64, values map[string]any) error

CustomFieldsSet stores custom field values for an entity.

func (*ProdHostAPI) DBExec

func (h *ProdHostAPI) DBExec(ctx context.Context, query string, args ...any) (int64, error)

DBExec executes an INSERT/UPDATE/DELETE and returns affected rows. Uses the default database. For named databases, prefix query with "@dbname:" (e.g., "@analytics:INSERT...").

func (*ProdHostAPI) DBQuery

func (h *ProdHostAPI) DBQuery(ctx context.Context, query string, args ...any) ([]map[string]any, error)

DBQuery executes a SELECT query and returns rows as maps. Uses the default database. For named databases, prefix query with "@dbname:" (e.g., "@analytics:SELECT...").

func (*ProdHostAPI) EntityHardDelete added in v0.8.0

func (h *ProdHostAPI) EntityHardDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntityHardDelete permanently removes an entity.

func (*ProdHostAPI) EntityRestore added in v0.8.0

func (h *ProdHostAPI) EntityRestore(ctx context.Context, entityType string, entityID int64) error

EntityRestore restores a soft-deleted entity.

func (*ProdHostAPI) EntitySoftDelete added in v0.8.0

func (h *ProdHostAPI) EntitySoftDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntitySoftDelete soft-deletes an entity.

func (*ProdHostAPI) HTTPRequest

func (h *ProdHostAPI) HTTPRequest(ctx context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)

HTTPRequest makes an outbound HTTP request.

func (*ProdHostAPI) Log

func (h *ProdHostAPI) Log(ctx context.Context, level, message string, fields map[string]any)

Log writes a structured log entry.

func (*ProdHostAPI) OrgID added in v0.8.0

func (h *ProdHostAPI) OrgID(ctx context.Context) int64

OrgID returns the active organisation ID from the request context.

func (*ProdHostAPI) PublishEvent added in v0.7.0

func (h *ProdHostAPI) PublishEvent(ctx context.Context, eventType string, data string) error

PublishEvent sends an SSE event to all connected browser clients.

func (*ProdHostAPI) RecycleBinList added in v0.8.0

func (h *ProdHostAPI) RecycleBinList(ctx context.Context, entityType string) (json.RawMessage, error)

RecycleBinList lists soft-deleted entities.

func (*ProdHostAPI) SecureConfigGet added in v0.8.0

func (h *ProdHostAPI) SecureConfigGet(ctx context.Context, key string) (string, error)

SecureConfigGet retrieves and decrypts a secret value.

func (*ProdHostAPI) SecureConfigSet added in v0.8.0

func (h *ProdHostAPI) SecureConfigSet(ctx context.Context, key string, value string) error

SecureConfigSet encrypts and stores a secret value.

func (*ProdHostAPI) SendEmail

func (h *ProdHostAPI) SendEmail(ctx context.Context, to, subject, body string, html bool) error

SendEmail sends an email using the configured provider.

func (*ProdHostAPI) Translate

func (h *ProdHostAPI) Translate(ctx context.Context, key string, args ...any) string

Translate translates a key to the current locale. The language is determined from the context (set via PluginLanguageKey). If no language is set, falls back to the default language.

type ProdHostAPIOption

type ProdHostAPIOption func(*ProdHostAPI)

ProdHostAPIOption is a functional option for ProdHostAPI.

func WithCache

func WithCache(c *cache.RedisCache) ProdHostAPIOption

WithCache sets the cache client.

func WithDB

func WithDB(name string, db *sql.DB) ProdHostAPIOption

WithDB adds a named database connection. Use "default" for the primary database.

func WithDefaultDB

func WithDefaultDB(name string) ProdHostAPIOption

WithDefaultDB sets which named database is the default.

func WithLogger

func WithLogger(logger *slog.Logger) ProdHostAPIOption

WithLogger sets the logger.

func WithPluginManager

func WithPluginManager(mgr *Manager) ProdHostAPIOption

WithPluginManager sets the plugin manager for plugin-to-plugin calls.

type ResourcePolicy added in v0.7.0

type ResourcePolicy = pkgplugin.ResourcePolicy

type ResourceRequest added in v0.7.0

type ResourceRequest = pkgplugin.ResourceRequest

type RouteSpec

type RouteSpec = pkgplugin.RouteSpec

type SSEBroker added in v0.7.0

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

SSEBroker manages SSE client connections and event broadcasting.

func NewSSEBroker added in v0.7.0

func NewSSEBroker() *SSEBroker

NewSSEBroker creates a new SSE broker.

func (*SSEBroker) ClientCount added in v0.7.0

func (b *SSEBroker) ClientCount() int

ClientCount returns the number of connected SSE clients.

func (*SSEBroker) Publish added in v0.7.0

func (b *SSEBroker) Publish(event SSEEvent)

Publish sends an event to all matching clients. Non-blocking: slow clients have their events dropped rather than blocking the publisher.

func (*SSEBroker) ServeHTTP added in v0.7.0

func (b *SSEBroker) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles SSE client connections. Query params:

  • plugin: filter events to a specific plugin (optional)

func (*SSEBroker) Subscribe added in v0.7.0

func (b *SSEBroker) Subscribe(pluginFilter string) chan SSEEvent

Subscribe adds a client and returns its event channel. The pluginFilter limits events to a specific plugin ("" receives all).

func (*SSEBroker) Unsubscribe added in v0.7.0

func (b *SSEBroker) Unsubscribe(ch chan SSEEvent)

Unsubscribe removes a client channel.

type SSEEvent added in v0.7.0

type SSEEvent struct {
	Plugin string // source plugin name
	Type   string // event type (e.g. "device-table")
	Data   string // event data (typically HTML fragment)
}

SSEEvent represents a server-sent event.

type SandboxedHostAPI added in v0.7.0

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

SandboxedHostAPI wraps a HostAPI with per-plugin permission enforcement and resource accounting. Each plugin gets its own sandbox instance.

func NewSandboxedHostAPI added in v0.7.0

func NewSandboxedHostAPI(inner HostAPI, pluginName string, policy ResourcePolicy) *SandboxedHostAPI

NewSandboxedHostAPI creates a permission-enforcing wrapper around a HostAPI.

func (*SandboxedHostAPI) CacheDelete added in v0.7.0

func (s *SandboxedHostAPI) CacheDelete(ctx context.Context, key string) error

func (*SandboxedHostAPI) CacheGet added in v0.7.0

func (s *SandboxedHostAPI) CacheGet(ctx context.Context, key string) ([]byte, bool, error)

func (*SandboxedHostAPI) CacheSet added in v0.7.0

func (s *SandboxedHostAPI) CacheSet(ctx context.Context, key string, value []byte, ttlSeconds int) error

func (*SandboxedHostAPI) CallPlugin added in v0.7.0

func (s *SandboxedHostAPI) CallPlugin(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)

func (*SandboxedHostAPI) ConfigGet added in v0.7.0

func (s *SandboxedHostAPI) ConfigGet(ctx context.Context, key string) (string, error)

func (*SandboxedHostAPI) CustomFieldsGet added in v0.8.0

func (s *SandboxedHostAPI) CustomFieldsGet(ctx context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)

CustomFieldsGet retrieves custom field values, scoped to this plugin's prefixed fields + admin/legacy fields.

func (*SandboxedHostAPI) CustomFieldsQuery added in v0.8.0

func (s *SandboxedHostAPI) CustomFieldsQuery(ctx context.Context, entityType string, filters []CustomFieldFilter) ([]int64, error)

CustomFieldsQuery finds entities by custom field values, scoped to this plugin's fields.

func (*SandboxedHostAPI) CustomFieldsSet added in v0.8.0

func (s *SandboxedHostAPI) CustomFieldsSet(ctx context.Context, entityType string, objectID int64, values map[string]any) error

CustomFieldsSet stores custom field values, scoped to this plugin's fields.

func (*SandboxedHostAPI) DBExec added in v0.7.0

func (s *SandboxedHostAPI) DBExec(ctx context.Context, query string, args ...any) (int64, error)

func (*SandboxedHostAPI) DBQuery added in v0.7.0

func (s *SandboxedHostAPI) DBQuery(ctx context.Context, query string, args ...any) ([]map[string]any, error)

func (*SandboxedHostAPI) EntityHardDelete added in v0.8.0

func (s *SandboxedHostAPI) EntityHardDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntityHardDelete permanently removes an entity.

func (*SandboxedHostAPI) EntityRestore added in v0.8.0

func (s *SandboxedHostAPI) EntityRestore(ctx context.Context, entityType string, entityID int64) error

EntityRestore restores a soft-deleted entity.

func (*SandboxedHostAPI) EntitySoftDelete added in v0.8.0

func (s *SandboxedHostAPI) EntitySoftDelete(ctx context.Context, entityType string, entityID int64, reason string) error

EntitySoftDelete soft-deletes an entity.

func (*SandboxedHostAPI) HTTPRequest added in v0.7.0

func (s *SandboxedHostAPI) HTTPRequest(ctx context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)

func (*SandboxedHostAPI) Log added in v0.7.0

func (s *SandboxedHostAPI) Log(ctx context.Context, level, message string, fields map[string]any)

func (*SandboxedHostAPI) OrgID added in v0.8.0

func (s *SandboxedHostAPI) OrgID(ctx context.Context) int64

OrgID returns the active organisation ID from the request context.

func (*SandboxedHostAPI) PublishEvent added in v0.7.0

func (s *SandboxedHostAPI) PublishEvent(ctx context.Context, eventType string, data string) error

PublishEvent sends an SSE event to connected browser clients. The plugin name is automatically set from the sandbox context.

func (*SandboxedHostAPI) RecycleBinList added in v0.8.0

func (s *SandboxedHostAPI) RecycleBinList(ctx context.Context, entityType string) (json.RawMessage, error)

RecycleBinList lists soft-deleted entities.

func (*SandboxedHostAPI) SecureConfigGet added in v0.8.0

func (s *SandboxedHostAPI) SecureConfigGet(ctx context.Context, key string) (string, error)

SecureConfigGet retrieves a decrypted secret, scoped to this plugin.

func (*SandboxedHostAPI) SecureConfigSet added in v0.8.0

func (s *SandboxedHostAPI) SecureConfigSet(ctx context.Context, key string, value string) error

SecureConfigSet stores an encrypted secret, scoped to this plugin.

func (*SandboxedHostAPI) SendEmail added in v0.7.0

func (s *SandboxedHostAPI) SendEmail(ctx context.Context, to, subject, body string, html bool) error

func (*SandboxedHostAPI) Stats added in v0.7.0

func (s *SandboxedHostAPI) Stats() StatsSnapshot

Stats returns the resource accounting stats for this plugin.

func (*SandboxedHostAPI) Translate added in v0.7.0

func (s *SandboxedHostAPI) Translate(ctx context.Context, key string, args ...any) string

func (*SandboxedHostAPI) UpdatePolicy added in v0.7.0

func (s *SandboxedHostAPI) UpdatePolicy(policy ResourcePolicy)

UpdatePolicy updates the resource policy for this sandbox. Policy changes take effect immediately for new requests.

type StatsSnapshot added in v0.7.0

type StatsSnapshot struct {
	PluginName   string `json:"plugin_name"`
	DBQueries    int64  `json:"db_queries"`
	DBExecs      int64  `json:"db_execs"`
	CacheOps     int64  `json:"cache_ops"`
	HTTPRequests int64  `json:"http_requests"`
	Calls        int64  `json:"calls"`
	Errors       int64  `json:"errors"`
	LastCallAt   int64  `json:"last_call_at"`
}

StatsSnapshot returns a point-in-time copy of plugin stats.

type TemplateOverride

type TemplateOverride struct {
	PluginName   string // Plugin providing the override
	TemplateName string // Original template name being overridden
	Handler      string // Plugin function to call for template content
}

TemplateOverride stores information about a template override.

type TemplateOverrideRegistry

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

TemplateOverrideRegistry manages template overrides from plugins.

func GetTemplateOverrides

func GetTemplateOverrides() *TemplateOverrideRegistry

GetTemplateOverrides returns the global template override registry.

func NewTemplateOverrideRegistry

func NewTemplateOverrideRegistry(mgr *Manager) *TemplateOverrideRegistry

NewTemplateOverrideRegistry creates a new template override registry.

func (*TemplateOverrideRegistry) GetOverride

func (r *TemplateOverrideRegistry) GetOverride(templateName string) *TemplateOverride

GetOverride returns the override for a template, if any.

func (*TemplateOverrideRegistry) HasOverride

func (r *TemplateOverrideRegistry) HasOverride(templateName string) bool

HasOverride checks if a template has a plugin override.

func (*TemplateOverrideRegistry) List

List returns all registered overrides.

func (*TemplateOverrideRegistry) Register

func (r *TemplateOverrideRegistry) Register(pluginName string, templates []TemplateSpec)

Register registers template overrides from a plugin.

func (*TemplateOverrideRegistry) RenderOverride

func (r *TemplateOverrideRegistry) RenderOverride(ctx context.Context, templateName string, data map[string]any) (string, bool)

RenderOverride renders a template override by calling the plugin. Returns the rendered HTML and true if an override exists, empty string and false otherwise.

func (*TemplateOverrideRegistry) Unregister

func (r *TemplateOverrideRegistry) Unregister(pluginName string)

Unregister removes template overrides for a plugin.

type TemplateSpec

type TemplateSpec = pkgplugin.TemplateSpec

type UIAuthSpec added in v0.8.0

type UIAuthSpec = pkgplugin.UIAuthSpec

type UIBrandingSpec added in v0.8.0

type UIBrandingSpec = pkgplugin.UIBrandingSpec

type UINavItem added in v0.8.0

type UINavItem = pkgplugin.UINavItem

type UINavSpec added in v0.8.0

type UINavSpec = pkgplugin.UINavSpec

type UIPWASpec added in v0.8.0

type UIPWASpec = pkgplugin.UIPWASpec

type UIRouteSpec added in v0.8.0

type UIRouteSpec = pkgplugin.UIRouteSpec

type UISpec added in v0.8.0

type UISpec = pkgplugin.UISpec

type WidgetSpec

type WidgetSpec = pkgplugin.WidgetSpec

Directories

Path Synopsis
Package core provides core built-in plugins for GoatFlow.
Package core provides core built-in plugins for GoatFlow.
Package example provides example plugin implementations for testing.
Package example provides example plugin implementations for testing.
Package grpc provides gRPC-based plugin runtime using HashiCorp go-plugin.
Package grpc provides gRPC-based plugin runtime using HashiCorp go-plugin.
example command
Example gRPC plugin for GoatKit.
Example gRPC plugin for GoatKit.
Package packaging provides ZIP-based plugin packaging and extraction.
Package packaging provides ZIP-based plugin packaging and extraction.
Package wasm provides a WASM-based plugin runtime using wazero.
Package wasm provides a WASM-based plugin runtime using wazero.

Jump to

Keyboard shortcuts

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