pluginsdk/plugin/provisioner.go
Alex Dunmow b6d40ed8ac feat: bootstrap block/pluginsdk — the proto-first plugin SDK (P1)
Bootstrap the plugin-facing SDK module so the fleet migration (P2) becomes a
mechanical block/core/X -> block/pluginsdk/X import rewrite.

- abi/proto/v1: the single source-of-truth ABI proto tree, copied from the cms
  authoring source (cms/backend/abi/proto/v1) with go_package retargeted to
  git.dev.alexdunmow.com/block/pluginsdk/abi/v1;abiv1. Kills the hand-kept
  cms/core proto duplication (audit gap 4).
- abi/v1: generated Go bindings (buf generate); byte-identical to core's abi/v1
  save the embedded go_package path.
- plugin/ (registration + DI surface), plugin/wasmguest/** (transport shim,
  caps stubs, bnwasm db driver, testdata fixtures + golden .pb), and the
  guest-facing type packages: blocks (+builtin/shared/tags), templates
  (+pongo/bn), auth, settings, content, gating, crypto, rbac, video, ai,
  subscriptions, menus, datasources. Internal imports rewritten core ->
  pluginsdk; zero block/core references remain.
- README/AGENTS(+CLAUDE symlink)/Makefile: proto is the contract, Go is one
  binding; no replace directives; templates/bn is a synced copy authored in cms.

Spec: cms docs/superpowers/specs/2026-07-07-proto-first-plugin-sdk-design.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 10:51:00 +08:00

113 lines
3.1 KiB
Go

package plugin
import (
"context"
"encoding/json"
"github.com/google/uuid"
)
// Provisioner allows plugins to ensure required resources exist on startup.
// All methods are idempotent — they check first and only create if missing.
type Provisioner interface {
EnsureDataTable(config DataTableConfig) error
MergeSiteSettings(defaults map[string]any) error
EnsureSetting(key string, defaultValue any) error
EnsurePage(config PageConfig) error
OverrideSiteSettings(overrides map[string]any) error
EnsureMenuItem(menuName string, config MenuItemConfig) error
RegisterEmbeddingConfig(config EmbeddingConfigDef) error
EnsureEmbed(config EmbedConfig) error
EnsureJobSchedule(config JobScheduleConfig) error
UpdateDataTableRowField(ctx context.Context, rowID uuid.UUID, fieldKey string, value any) error
DisableOrphanedJobSchedules(registeredTypes []string) error
EnsurePlugin(name string) error
EnsureCustomColor(config CustomColorConfig) error
// EnsureMedia deposits an image under the plugin-chosen MediaDeposit.ID if a
// row with that ID does not already exist. Idempotent: an existing ID is a
// no-op; if the bytes differ from what was first deposited it logs a warning
// rather than overwriting (seeded media is immutable once placed).
EnsureMedia(deposit MediaDeposit) error
}
// DataTableConfig defines a data table to provision.
type DataTableConfig struct {
Key string
Name string
Description string
Schema json.RawMessage
PrimaryKey string
}
// PageConfig defines a page to provision.
type PageConfig struct {
Slug string
ParentSlug string
Title string
TemplateKey string
Blocks []PageBlockConfig
DetailSourceType string
DetailSourceKey string
DetailSlugField string
ReconcileBlocks bool
ReconcileTemplate bool
}
// PageBlockConfig defines a block within a provisioned page.
type PageBlockConfig struct {
BlockKey string
Title string
Content map[string]any
HtmlContent *string
Slot string
SortOrder int32
}
// EmbeddingConfigDef defines embedding text generation for a data table.
type EmbeddingConfigDef struct {
TableKey string
TextTemplate string
Enabled bool
}
// MenuItemConfig defines a menu item to provision.
type MenuItemConfig struct {
Label string
URL string
PageSlug string
SortOrder int32
}
// EmbedConfig defines an embeddable component template.
type EmbedConfig struct {
Key string
Title string
Description string
Icon string
LabelField string
Template string
RenderFunc func(ctx context.Context, content map[string]any) string
DataSource EmbedDataSource
}
// EmbedDataSource specifies where embed data comes from.
type EmbedDataSource struct {
Type string
TableKey string
}
// JobScheduleConfig defines a cron schedule for a background job.
type JobScheduleConfig struct {
JobType string
CronExpression string
Config json.RawMessage
}
// CustomColorConfig defines a custom theme color variable.
type CustomColorConfig struct {
Name string
LightValue string
DarkValue string
Source string
}