Documentation
¶
Overview ¶
Package saas preserves app ownership, subscriptions and atomic usage independently of commerce provisioning.
Index ¶
- Constants
- Variables
- type App
- type AppInput
- type ConsumeRequest
- type Consumption
- type Entitlement
- type Module
- type Overview
- type Renewal
- type Saved
- type Service
- func (s *Service) AcceptEvent(ctx context.Context, app, event, key, hash string) (bool, error)
- func (s *Service) Consume(ctx context.Context, entitlement string, req ConsumeRequest) (Consumption, error)
- func (s *Service) ConsumeNonce(ctx context.Context, app, key, nonce string, expires time.Time) error
- func (s *Service) CreateApp(ctx context.Context, q AppInput) (Saved, error)
- func (s *Service) CreateSubscription(ctx context.Context, q SubscriptionInput) (Saved, error)
- func (s *Service) DeleteUnused(ctx context.Context, kind, id string) error
- func (s *Service) Overview(ctx context.Context, management bool) (Overview, error)
- func (s *Service) UpdateApp(ctx context.Context, id string, q AppInput) (Saved, error)
- func (s *Service) UpdateServices(ctx context.Context, id string, q ServicesUpdate) (Saved, error)
- func (s *Service) UpdateStatus(ctx context.Context, id string, q StatusUpdate) error
- func (s *Service) UpdateSubscription(ctx context.Context, id string, q SubscriptionInput) (Saved, error)
- type ServicesUpdate
- type StatusUpdate
- type SubscriptionInput
- type Usage
Constants ¶
const PermManage = "saas.manage"
Variables ¶
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
OwnerID string `json:"owner_id"`
Version string `json:"version"`
Mode string `json:"mode"`
ID string `json:"id"`
PublicID string `json:"public_id"`
Name string `json:"name"`
Slug string `json:"slug"`
Status string `json:"status"`
BaseURL string `json:"base_url"`
Runtime string `json:"runtime"`
Framework string `json:"framework"`
LastSeenAt string `json:"last_seen_at"`
FulfillmentEnabled bool `json:"fulfillment_enabled"`
}
type ConsumeRequest ¶
type Consumption ¶
type Entitlement ¶
type Entitlement struct {
Version string `json:"version"`
ID string `json:"id"`
PublicID string `json:"public_id"`
AppID string `json:"app_id"`
AppName string `json:"app_name"`
SubjectType string `json:"subject_type"`
ExternalID string `json:"external_id"`
PlanID string `json:"plan_id"`
Status string `json:"status"`
Features json.RawMessage `json:"features"`
Limits json.RawMessage `json:"limits"`
ValidUntil string `json:"valid_until"`
Renewal Renewal `json:"renewal"`
}
type Module ¶
type Module struct{ Service *Service }
Module adds owner-scoped SaaS state. Import and external protocol adapters are separate concerns.
func (*Module) Migrations ¶
type Overview ¶
type Overview struct {
Apps []App `json:"apps"`
Entitlements []Entitlement `json:"entitlements"`
Usage []Usage `json:"usage"`
}
type Renewal ¶
type Renewal struct {
State string `` /* 128-byte string literal not displayed */
RemainingSeconds *int64 `json:"remaining_seconds" doc:"Positive remaining seconds rounded up; zero when expired, null for missing or invalid expiry."`
RemainingDays *int `json:"remaining_days" doc:"Remaining 24-hour days rounded up; zero when expired, null for missing or invalid expiry."`
ReminderDays int `json:"reminder_days" doc:"Reminder window in days (7). No notification is sent."`
ObservedAt string `json:"observed_at" doc:"UTC RFC3339 observation time shared by this overview."`
}
Renewal describes expiry only; entitlement status still controls access. Missing/invalid dates leave remaining values null, never implying unlimited access.
type Service ¶
func NewService ¶
func (*Service) AcceptEvent ¶
AcceptEvent records replay protection only. It does not authenticate a legacy external webhook or fulfill subscriptions.
func (*Service) Consume ¶
func (s *Service) Consume(ctx context.Context, entitlement string, req ConsumeRequest) (Consumption, error)
Consume applies one owned entitlement's usage atomically. Missing quotas deny rather than grant unlimited usage.
func (*Service) ConsumeNonce ¶
func (s *Service) ConsumeNonce(ctx context.Context, app, key, nonce string, expires time.Time) error
ConsumeNonce is an internal replay guard, not a substitute for authenticating a request signature. A legacy key is never accepted until a protocol adapter marks it configured.
func (*Service) CreateApp ¶
CreateApp establishes explicit ownership and local subscription gating; it never provisions infrastructure.
func (*Service) CreateSubscription ¶
func (*Service) DeleteUnused ¶
DeleteUnused permanently removes only an unused native object. Imported or referenced history must be disabled/revoked instead.
func (*Service) UpdateServices ¶
UpdateServices preserves ownership, plan, quota and unrelated feature data. A stale version prevents a retried renewal from extending the term twice.
func (*Service) UpdateStatus ¶
func (*Service) UpdateSubscription ¶
func (s *Service) UpdateSubscription(ctx context.Context, id string, q SubscriptionInput) (Saved, error)
UpdateSubscription changes explicit native plan limits with a version guard. Existing usage is retained.
type ServicesUpdate ¶
type ServicesUpdate struct {
ExpectedVersion *string `json:"expected_version"`
Status *string `json:"status,omitempty"`
RenewMonths int `json:"renew_months,omitempty"`
CentralOutboundMail *bool `json:"central_outbound_mail,omitempty"`
ExistingDomainLinked *bool `json:"existing_domain_linked,omitempty"`
}
ServicesUpdate edits recorded service entitlements only. It does not provision mailboxes, register domains, change DNS or record a payment.
type StatusUpdate ¶
type StatusUpdate struct {
ExpectedStatus string `json:"expected_status"`
Status string `json:"status"`
}
StatusUpdate requires the current status to avoid lost concurrent management changes.
type SubscriptionInput ¶
type SubscriptionInput struct {
ExpectedVersion string `json:"expected_version"`
AppID string `json:"app_id"`
OwnerID string `json:"owner_id"`
PlanID string `json:"plan_id"`
Status string `json:"status"`
Features map[string]bool `json:"features"`
Limits map[string]int64 `json:"limits"`
ValidUntil string `json:"valid_until"`
IdempotencyKey string `json:"idempotency_key"`
}