integration

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 17 Imported by: 0

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

View Source
const MaxPurchaseDevices = 100

MaxPurchaseDevices bounds key generation and a single provisioning transaction.

View Source
const ResultRetention = 90 * 24 * time.Hour

Variables

This section is empty.

Functions

func Prune

func Prune(ctx context.Context, db *database.DB, now time.Time) (int64, error)

Prune removes a bounded batch so one housekeeping tick cannot monopolize the node's single scheduler goroutine.

func PruneNextPlanHistory

func PruneNextPlanHistory(ctx context.Context, db *database.DB, now time.Time) (int64, error)

PruneNextPlanHistory keeps one-year transition evidence without letting long-lived high-volume nodes accumulate unbounded activation rows.

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 QueueNextPlanInput struct {
	UserID             string
	TemplateID         string
	ResellerID         *string // nil = node owner; non-nil must own customer and plan assignment
	CarryUnusedTraffic bool
}

type QuotaTopUpInput added in v0.1.4

type QuotaTopUpInput struct {
	Key        string // caller's Idempotency-Key, never persisted as plaintext
	ResellerID *string
	UserID     string
	Bytes      int64
}

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

func (s *Service) ActivateDueNextPlans(ctx context.Context) (int, error)

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 (s *Service) CancelNextPlan(ctx context.Context, userID string, resellerID *string) error

func (*Service) Lookup

func (s *Service) Lookup(ctx context.Context, resellerID *string, key string) (*Result, error)

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 (s *Service) NextPlanForUser(ctx context.Context, userID string, resellerID *string) (*NextPlan, error)

func (*Service) Purchase

func (s *Service) Purchase(ctx context.Context, in PurchaseInput) (*Result, bool, error)

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

func (s *Service) QueueNextPlan(ctx context.Context, in QueueNextPlanInput) (*NextPlan, error)

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

func (s *Service) TopUpQuota(ctx context.Context, in QuotaTopUpInput) (*Result, bool, error)

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.

Jump to

Keyboard shortcuts

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