controlplane

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFreemiusEvent

func ApplyFreemiusEvent(store *Store, ev FreemiusWebhookEvent, planMap map[string]entitlement.Plan) error

ApplyFreemiusEvent updates license state from a webhook (idempotent).

func EncodeJSON

func EncodeJSON(w interface{ Write([]byte) (int, error) }, v any) error

EncodeJSON writes v as JSON to w.

func IssueToken

func IssueToken(rec *LicenseRecord, key ed25519.PrivateKey) (string, entitlement.State, error)

IssueToken signs an entitlement JWT for a license record.

func Listen

func Listen(addr string, handler http.Handler) error

Listen starts the HTTP server with sane timeouts for the sandbox API.

Types

type Config

type Config struct {
	Addr          string
	Env           string // "dev" (default) or "production"
	DBPath        string
	WebhookSecret string
	SigningKey    ed25519.PrivateKey
	FreemiusPlans map[string]entitlement.Plan // Freemius plan ID -> our plan name
	Version       string
}

Config configures the control plane HTTP server.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads server config from environment.

func (Config) IsProduction added in v0.8.0

func (c Config) IsProduction() bool

IsProduction reports whether the server is running in production mode, which disables sandbox license seeding and requires an explicit signing key.

type FreemiusWebhookEvent

type FreemiusWebhookEvent struct {
	EventID    string
	Event      string
	LicenseKey string
	PlanID     string
	Plan       string
	UserID     string
	Email      string
}

FreemiusWebhookEvent is the normalized shape we act on, after extracting it from either Freemius's real nested payload or the flat sandbox shape used for local testing (see controlplane/README.md).

type LicenseRecord

type LicenseRecord struct {
	LicenseKey   string
	Plan         entitlement.Plan
	Subject      string
	Entitlements []string
	Revoked      bool
	Version      int
}

LicenseRecord is the server-side view of a Freemius license.

type PackageOffer

type PackageOffer struct {
	Name         string   `json:"name"`
	Description  string   `json:"description"`
	Entitlements []string `json:"entitlements"`
}

PackageOffer is a catalog entry returned by the API.

func PackageCatalog

func PackageCatalog() []PackageOffer

PackageCatalog returns curated package metadata for GET /v1/packages.

type Server

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

Server is the control plane HTTP API.

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer constructs a Server backed by the SQLite license store at cfg.DBPath. Sandbox licenses are only seeded outside production.

func (*Server) Close added in v0.8.0

func (s *Server) Close() error

Close releases the underlying license store.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the root http.Handler.

type Store

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

Store persists license and webhook-idempotency state to a local SQLite file. A restart or redeploy must not lose customer license records, which an in-memory store would.

func NewStore

func NewStore(path string, seedSandbox bool) (*Store, error)

NewStore opens (creating if needed) the SQLite-backed license store at path. When seedSandbox is true, two fixed sandbox licenses are inserted so `m controlplane serve` works out of the box for local testing — this must be false in production.

func (*Store) Close added in v0.8.0

func (s *Store) Close() error

Close releases the underlying database handle.

func (*Store) GetLicense

func (s *Store) GetLicense(key string) (*LicenseRecord, bool)

func (*Store) MarkWebhookSeen

func (s *Store) MarkWebhookSeen(id string) (bool, error)

MarkWebhookSeen records a webhook event id and reports whether this is the first time it's been seen (false means it's a duplicate delivery — skip re-applying it).

func (*Store) RevokeLicense

func (s *Store) RevokeLicense(key string) error

RevokeLicense marks a license revoked without deleting its history.

func (*Store) UpsertLicense

func (s *Store) UpsertLicense(rec LicenseRecord) error

UpsertLicense inserts or updates a license record (idempotent per webhook delivery), bumping the version on update so cached client entitlements know to refresh.

Jump to

Keyboard shortcuts

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