Documentation
¶
Overview ¶
Package integration implements durable, principal-scoped automation operations. Results contain identifiers and accounting state, never subscription capabilities or device private keys.
Index ¶
- Constants
- func Prune(ctx context.Context, db *database.DB, now time.Time) (int64, error)
- func PruneNextPlanHistory(ctx context.Context, db *database.DB, now time.Time) (int64, error)
- type DirectEntitlement
- type NextPlan
- type NextPlanActivation
- type NextPlanTerms
- type PurchaseInput
- type QueueNextPlanInput
- type QuotaTopUpInput
- type Result
- type Service
- func (s *Service) ActivateDueNextPlans(ctx context.Context) (int, error)
- func (s *Service) CancelNextPlan(ctx context.Context, userID string, resellerID *string) error
- func (s *Service) Lookup(ctx context.Context, resellerID *string, key string) (*Result, error)
- func (s *Service) NextPlanActivations(ctx context.Context, userID string, resellerID *string, limit int) ([]NextPlanActivation, error)
- func (s *Service) NextPlanForUser(ctx context.Context, userID string, resellerID *string) (*NextPlan, error)
- func (s *Service) Purchase(ctx context.Context, in PurchaseInput) (*Result, bool, error)
- func (s *Service) QueueNextPlan(ctx context.Context, in QueueNextPlanInput) (*NextPlan, error)
- func (s *Service) TopUpQuota(ctx context.Context, in QuotaTopUpInput) (*Result, bool, error)
Constants ¶
const MaxPurchaseDevices = 100
MaxPurchaseDevices bounds key generation and a single provisioning transaction.
const ResultRetention = 90 * 24 * time.Hour
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DirectEntitlement ¶ added in v0.1.4
type DirectEntitlement struct {
TrafficLimitBytes int64 `json:"traffic_limit_bytes"`
DurationSeconds int64 `json:"duration_seconds"`
DeviceLimit int `json:"device_limit"`
StartPolicy domain.StartPolicy `json:"start_policy,omitempty"`
SpeedLimitDownKbps *int `json:"speed_limit_down_kbps,omitempty"`
SpeedLimitUpKbps *int `json:"speed_limit_up_kbps,omitempty"`
InterfaceID string `json:"interface_id,omitempty"`
}
DirectEntitlement is a complete technical subscription supplied by an owner-scoped integration. It is not a sales SKU or a payment instruction. Requiring finite quota, duration and device count prevents an omitted JSON field from silently creating an unlimited paid subscription.
type NextPlan ¶
type NextPlan struct {
UserID string `json:"user_id"`
TemplateID string `json:"template_id"`
Terms NextPlanTerms `json:"terms"`
CarryUnusedTraffic bool `json:"carry_unused_traffic"`
State string `json:"state"`
ReviewReason string `json:"review_reason,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
type NextPlanActivation ¶
type NextPlanActivation struct {
ID string `json:"activation_id"`
UserID string `json:"user_id"`
TemplateID string `json:"template_id"`
Trigger string `json:"trigger"`
Before json.RawMessage `json:"before"`
After json.RawMessage `json:"after"`
ActivatedAt time.Time `json:"activated_at"`
}
type NextPlanTerms ¶
type NextPlanTerms struct {
Name string `json:"name"`
TrafficLimitBytes *int64 `json:"traffic_limit_bytes"`
DurationSeconds *int64 `json:"duration_seconds"`
DeviceLimit *int `json:"device_limit"`
SpeedLimitDownKbps *int `json:"speed_limit_down_kbps"`
SpeedLimitUpKbps *int `json:"speed_limit_up_kbps"`
InterfaceID *string `json:"interface_id"`
}
NextPlanTerms are fixed when the successor is queued. Catalog changes do not rewrite an already authorized future entitlement.
type PurchaseInput ¶
type PurchaseInput struct {
Key string // caller's Idempotency-Key, never persisted as plaintext
ResellerID *string
Username string
TemplateID string
Entitlement *DirectEntitlement
DeviceName string
DeviceKeys []device.KeyMaterial // one independent keypair per requested device
}
type QueueNextPlanInput ¶
type QuotaTopUpInput ¶ added in v0.1.4
type Result ¶
type Result struct {
ID string `json:"operation_id"`
Kind string `json:"kind"`
State string `json:"state"`
UserID string `json:"user_id"`
DeviceID string `json:"device_id,omitempty"`
DeviceIDs []string `json:"device_ids,omitempty"`
TemplateID string `json:"template_id,omitempty"`
Before *accounting.QuotaSnapshot `json:"before,omitempty"`
After *accounting.QuotaSnapshot `json:"after,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
type Service ¶
type Service struct {
DB *database.DB
Users *user.Service
Devices *device.Service
Plans *plan.Service
Links *subscription.Service
Accounting *accounting.Service
Now func() time.Time
}
func (*Service) ActivateDueNextPlans ¶
ActivateDueNextPlans runs in the node's existing scheduler after metering and before expiry enforcement. At most 50 successors are inspected per tick. Each transition, counters, event and history row commit in one transaction.
func (*Service) CancelNextPlan ¶
func (*Service) Lookup ¶
Lookup resolves a previously committed result within the same owner or reseller namespace. The key is never logged or stored in plaintext.
func (*Service) NextPlanActivations ¶
func (s *Service) NextPlanActivations(ctx context.Context, userID string, resellerID *string, limit int) ([]NextPlanActivation, error)
NextPlanActivations is a bounded recovery read for automation clients that missed an asynchronous activation or webhook. It contains no credentials.
func (*Service) NextPlanForUser ¶
func (*Service) Purchase ¶
Purchase inserts the user, requested devices, customer link and durable result in one SQLite write transaction. A retry after lost HTTP response returns the prior result without minting another customer or credential.
func (*Service) QueueNextPlan ¶
QueueNextPlan reserves exactly one successor. It does not take payment: callers must authorize the entitlement before invoking this operation.
func (*Service) TopUpQuota ¶ added in v0.1.4
TopUpQuota atomically increases a finite user's allowance and records a non-secret before/after result under the caller's principal namespace. Retrying the same key cannot apply the paid entitlement twice.