Documentation
¶
Index ¶
- Constants
- Variables
- func Adapt(m Module) auth.PluginModule
- func Provide[T any](ctx *Context, impl T) error
- type Context
- func (c *Context) Adapter() adapter.Adapter
- func (c *Context) Cache() cache.Cache
- func (c *Context) Core() *auth.Auth
- func (c *Context) DB() *DB
- func (c *Context) Email() email.Sender
- func (c *Context) Events() *auth.Events
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) Hooks() *auth.Hooks
- func (c *Context) Host() *auth.Host
- func (c *Context) Logger() *slog.Logger
- func (c *Context) ModuleID() string
- func (c *Context) Now() time.Time
- func (c *Context) Schema() *schema.Schema
- func (c *Context) Set(key string, val any)
- func (c *Context) StandardContext() context.Context
- func (c *Context) Store() store.Store
- type DB
- type Dependent
- type Error
- type ErrorKind
- type Event
- type EventHandler
- type EventName
- type HTTPClient
- type HookFunc
- type HookRegistry
- type Hooks
- type Lifecycle
- type Migration
- type MigrationProvider
- type Module
- type Repository
- func (r *Repository[T]) Count(ctx context.Context, where ...adapter.Condition) (int64, error)
- func (r *Repository[T]) Create(ctx context.Context, entity *T) error
- func (r *Repository[T]) Delete(ctx context.Context, where ...adapter.Condition) (int64, error)
- func (r *Repository[T]) FindMany(ctx context.Context, q adapter.Query) ([]T, error)
- func (r *Repository[T]) FindOne(ctx context.Context, where ...adapter.Condition) (*T, error)
- func (r *Repository[T]) Update(ctx context.Context, where []adapter.Condition, update map[string]any) (int64, error)
Constants ¶
const ( EventUserCreated = auth.EventUserCreated EventUserSignedIn = auth.EventUserSignedIn EventUserSignedOut = auth.EventUserSignedOut EventSessionCreated = auth.EventSessionCreated EventSessionRevoked = auth.EventSessionRevoked EventPasswordChanged = auth.EventPasswordChanged EventEmailVerified = auth.EventEmailVerified )
Common core event names re-exported for plugin convenience.
Variables ¶
var ( // ErrNotFound is returned when a requested capability or module is not found. ErrNotFound = errors.New("plugin-sdk: not found") // ErrDuplicate is returned when a module or capability is registered more than once. ErrDuplicate = errors.New("plugin-sdk: duplicate registration") // ErrPluginDependency is returned when a required plugin dependency is missing or cyclic. ErrPluginDependency = errors.New("plugin-sdk: dependency error") )
var ( // ErrAdapterNotConfigured is returned when attempting to access the database without an active adapter. ErrAdapterNotConfigured = errors.New("sdk db: adapter not configured") )
Functions ¶
func Adapt ¶
func Adapt(m Module) auth.PluginModule
Adapt converts an sdk.Module into an auth.PluginModule acceptable by core auth.New.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context provides the host runtime environment and services to a plugin module. It acts as the isolation boundary so plugins only interact with public infrastructure contracts and never private core internals.
func NewContext ¶
NewContext creates a new plugin context wrapping the host runtime.
func NewTestContext ¶
NewTestContext creates a standalone test Context with injected adapters.
func (*Context) Adapter ¶
Adapter returns the generic schema-driven storage adapter, or nil if none is configured.
func (*Context) Cache ¶
Cache returns the shared cache adapter, or nil when none is configured. Plugins must namespace their cache keys.
func (*Context) Email ¶
Email returns the transactional email sender, or nil when none is configured.
func (*Context) Get ¶
Get retrieves a value by key from the contextual execution bag. It is safe for concurrent use.
func (*Context) Set ¶
Set stores a key-value pair in the contextual execution bag. It is safe for concurrent use.
func (*Context) StandardContext ¶
StandardContext returns a background context.Context.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the database access client exposed to plugin modules.
type Dependent ¶
type Dependent interface {
Dependencies() []string
}
Dependent is implemented by plugins that declare dependencies on other plugin modules.
type Error ¶
Error represents a categorized plugin error that transport adapters can map to HTTP/gRPC codes.
type ErrorKind ¶
type ErrorKind int
ErrorKind classifies domain errors into architectural categories for transport adapters.
type EventHandler ¶
type EventHandler = auth.EventHandler
EventHandler is the callback invoked when an event is published.
type HTTPClient ¶
HTTPClient abstracts outgoing HTTP request execution, allowing custom transports, telemetry decoration, and mock execution in unit tests without starting real network servers. It is satisfied by *http.Client.
type HookFunc ¶
HookFunc is a generic synchronous workflow interception function for plugin-defined hooks.
type HookRegistry ¶
type HookRegistry[T any] struct { // contains filtered or unexported fields }
HookRegistry provides registration and execution for plugin-defined workflow hooks.
func NewHookRegistry ¶
func NewHookRegistry[T any]() *HookRegistry[T]
NewHookRegistry creates a new hook registry for payload type T.
func (*HookRegistry[T]) Execute ¶
func (r *HookRegistry[T]) Execute(ctx context.Context, payload T) error
Execute runs all registered hooks sequentially. Aborts on the first error.
func (*HookRegistry[T]) Register ¶
func (r *HookRegistry[T]) Register(fn HookFunc[T])
Register appends a hook function to the registry.
type Lifecycle ¶
Lifecycle defines optional lifecycle callbacks that a plugin module can implement. It is an alias to auth.Lifecycle for seamless backward compatibility.
type Migration ¶
type Migration struct {
Version int
Description string
Up func(ctx context.Context) error
Down func(ctx context.Context) error
}
Migration represents a single schema or data migration step.
type MigrationProvider ¶
type MigrationProvider interface {
Migrations() []Migration
}
MigrationProvider is optionally implemented by modules that require database schema migrations.
type Module ¶
type Module interface {
// ID returns the unique identifier for the plugin module.
ID() string
// Init initializes the plugin module within the given SDK context.
Init(ctx *Context) error
}
Module is the interface that every plugin module using the SDK must implement.
func ResolveInitOrder ¶
ResolveInitOrder sorts modules topologically so dependencies initialize before dependents.
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
Repository provides a strongly typed generic data access contract over a specific model.
func For ¶
func For[T any](db *DB, modelName string) *Repository[T]
For creates a typed Repository from a DB instance.
func FromAdapter ¶
func FromAdapter[T any](a adapter.Adapter, modelName string) *Repository[T]
FromAdapter creates a typed Repository directly from an adapter (e.g. inside a transaction).
func Model ¶
func Model[T any](c *Context, modelName string) *Repository[T]
Model returns a typed Repository for the specified model using the plugin context.
Usage:
repo := sdk.Model[FactorRecord](ctx, "two_factors")
record, err := repo.FindOne(ctx, adapter.Eq("user_id", uid))
func (*Repository[T]) Create ¶
func (r *Repository[T]) Create(ctx context.Context, entity *T) error
Create inserts a typed entity into the model.