Documentation
¶
Overview ¶
Package catalog provides the core functionality for managing and validating the catalog of products, features, and prices in the Openlane project
Index ¶
- Constants
- Variables
- type Billing
- type Catalog
- func (c *Catalog) EnsurePrices(ctx context.Context, sc *entitlements.StripeClient, currency string) error
- func (c *Catalog) IsCurrent() bool
- func (c *Catalog) SaveCatalog(path string) (string, error)
- func (c *Catalog) ValidatePrices(ctx context.Context, sc *entitlements.StripeClient) error
- func (c *Catalog) Visible(audience string) *Catalog
- type Feature
- type FeatureSet
- type Price
- type Usage
Constants ¶
const ManagedByKey = "managed_by"
ManagedByKey is the metadata key applied to Stripe resources created via the catalog
const ManagedByValue = "module-manager"
ManagedByValue identifies objects managed by the catalog automation
Variables ¶
var ( // ErrCatalogValidationFailed is returned when the catalog fails validation ErrCatalogValidationFailed = errors.New("catalog validation failed") // ErrProductMissingFeature is returned when a product is missing a required feature ErrProductMissingFeature = errors.New("product missing required feature") // ErrYamlToJSONConversion = errors.New("failed to convert YAML to JSON for catalog validation") ErrYamlToJSONConversion = errors.New("failed to convert YAML to JSON for catalog validation") // ErrMatchingPriceNotFound = errors.New("matching price not found for feature") ErrMatchingPriceNotFound = errors.New("matching price not found for feature") // ErrFailedToCreateProduct = errors.New("failed to create product in Stripe") ErrFailedToCreateProduct = errors.New("failed to create product in Stripe") // ErrFailedToCreatePrice = errors.New("failed to create price in Stripe") ErrFailedToCreatePrice = errors.New("failed to create price in Stripe") // ErrContextandClientRequired = errors.New("context and client are required for catalog operations" ErrContextandClientRequired = errors.New("context and client are required for catalog operations") )
Functions ¶
This section is empty.
Types ¶
type Billing ¶
type Billing struct {
Prices []Price `json:"prices" yaml:"prices" jsonschema:"description=List of price options for this feature"`
}
Billing contains one or more price options for a module or addon
type Catalog ¶
type Catalog struct {
Version string `json:"version" yaml:"version" jsonschema:"description=Catalog version,example=1.0.0"`
SHA string `json:"sha" yaml:"sha" jsonschema:"description=SHA of the catalog version"`
Modules FeatureSet `json:"modules" yaml:"modules" jsonschema:"description=Set of modules available in the catalog"`
Addons FeatureSet `json:"addons" yaml:"addons" jsonschema:"description=Set of addons available in the catalog"`
}
Catalog contains all modules and addons offered by Openlane
func LoadCatalog ¶
LoadCatalog reads and parses a Catalog definition from disk.
func (*Catalog) EnsurePrices ¶
func (c *Catalog) EnsurePrices(ctx context.Context, sc *entitlements.StripeClient, currency string) error
EnsurePrices verifies prices exist in Stripe and creates them when missing. New products are created using the feature display name and description. Matching is performed by unit amount, interval, nickname, lookup key and metadata instead of a fixed price ID. The discovered Stripe price ID is stored back in the catalog struct but not persisted to disk.
func (*Catalog) SaveCatalog ¶
SaveCatalog writes the catalog to disk in YAML format, as well as computing and updating the SHA
func (*Catalog) ValidatePrices ¶
func (c *Catalog) ValidatePrices(ctx context.Context, sc *entitlements.StripeClient) error
ValidatePrices ensures every feature's price attributes match a Stripe price. Matching considers unit amount, interval, nickname, lookup key and metadata.
type Feature ¶
type Feature struct {
DisplayName string `` /* 127-byte string literal not displayed */
Description string `` /* 171-byte string literal not displayed */
Billing Billing `json:"billing" yaml:"billing" jsonschema:"description=Billing information for the feature"`
Audience string `` /* 140-byte string literal not displayed */
Usage *Usage `json:"usage,omitempty" yaml:"usage,omitempty" jsonschema:"description=Usage limits granted by the feature"`
}
Feature defines a purchasable module or addon feature
type FeatureSet ¶
FeatureSet is a mapping of feature identifiers to metadata
type Price ¶
type Price struct {
Interval string `json:"interval" yaml:"interval" jsonschema:"enum=year,enum=month,description=Billing interval for the price,example=month"`
UnitAmount int64 `json:"unit_amount" yaml:"unit_amount" jsonschema:"description=Amount to be charged per interval,example=1000"`
Nickname string `` /* 141-byte string literal not displayed */
LookupKey string `` /* 180-byte string literal not displayed */
Metadata map[string]string `` /* 141-byte string literal not displayed */
PriceID string `json:"price_id,omitempty" yaml:"price_id,omitempty" jsonschema:"description=Stripe price ID,example=price_1N2Yw2A1b2c3d4e5"`
}
Price describes a single price option for a module or addon
Directories
¶
| Path | Synopsis |
|---|---|
|
Package features handles feature entitlements
|
Package features handles feature entitlements |
|
Package gencatalog is the output of parsing the catalog file
|
Package gencatalog is the output of parsing the catalog file |
|
Package genjsonschema generates JSON schema files from Go structs for use in validating catalogs
|
Package genjsonschema generates JSON schema files from Go structs for use in validating catalogs |
|
Package main inside of genyaml generates Go source files from a catalog YAML file
|
Package main inside of genyaml generates Go source files from a catalog YAML file |