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) LookupKeyConflicts(ctx context.Context, sc lookupClient, opts ...LookupKeyCheckOption) ([]LookupKeyConflict, error)
- 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 LookupKeyCheckOption
- type LookupKeyConflict
- 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") // ErrLookupKeyConflict indicates a price lookup key already exists in Stripe ErrLookupKeyConflict = errors.New("lookup key conflict") )
Functions ¶
This section is empty.
Types ¶
type Billing ¶
type Billing struct {
// Prices is a list of price options for the feature, each with its own billing interval and amount
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 is the version of the catalog, following semantic versioning
// It is used to track changes and updates to the catalog structure and content.
// Example: "1.0.0", "2.3.1"
Version string `json:"version" yaml:"version" jsonschema:"description=Catalog version,example=1.0.0"`
// SHA is the SHA256 hash of the catalog version string, used to verify integrity
SHA string `json:"sha" yaml:"sha" jsonschema:"description=SHA of the catalog version"`
// Modules is a set of purchasable modules available in the catalog
// Each module has its own set of features, pricing, and audience targeting.
// Example: "compliance", "reporting", "analytics"
Modules FeatureSet `json:"modules" yaml:"modules" jsonschema:"description=Set of modules available in the catalog"`
// Addons is a set of purchasable addons 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) LookupKeyConflicts ¶ added in v0.23.0
func (c *Catalog) LookupKeyConflicts(ctx context.Context, sc lookupClient, opts ...LookupKeyCheckOption) ([]LookupKeyConflict, error)
LookupKeyConflicts checks the catalog for any lookup key conflicts with existing Stripe products, features, or prices. It returns a slice of LookupKeyConflict structs describing any conflicts found
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 is the human-readable name for the feature
DisplayName string `` /* 127-byte string literal not displayed */
// LookupKey is a stable identifier for the feature, used for referencing in Stripe
// and other systems. It should be lowercase, alphanumeric, and can include underscores or dashes.
// Example: "compliance", "advanced_reporting"
// Pattern: ^[a-z0-9_-]+$
LookupKey string `` /* 155-byte string literal not displayed */
// Description provides additional context about the feature
Description string `` /* 171-byte string literal not displayed */
// Billing contains the pricing information for the feature
Billing Billing `json:"billing" yaml:"billing" jsonschema:"description=Billing information for the feature"`
// Audience indicates the intended audience for the feature - it can either be "public", "private", or "beta".
// - "public" features are available to all users
// - "private" features are restricted to specific users or organizations
// - "beta" features are in testing and may not be fully stable
Audience string `` /* 140-byte string literal not displayed */
// Usage defines the usage limits granted by the feature, such as storage or record counts
Usage *Usage `json:"usage,omitempty" yaml:"usage,omitempty" jsonschema:"description=Usage limits granted by the feature"`
// ProductID is the Stripe product ID associated with this feature
ProductID string `json:"product_id,omitempty" yaml:"product_id,omitempty" jsonschema:"description=Stripe product ID"`
// PersonalOrg indicates if the feature should be automatically added to personal organizations
PersonalOrg bool `` /* 126-byte string literal not displayed */
// IncludeWithTrial indicates if the feature should be automatically included with trial subscriptions
IncludeWithTrial bool `` /* 137-byte string literal not displayed */
}
Feature defines a purchasable module or addon feature
type FeatureSet ¶
FeatureSet is a mapping of feature identifiers to metadata
type LookupKeyCheckOption ¶ added in v0.23.0
type LookupKeyCheckOption func(*lookupKeyCheckConfig)
LookupKeyCheckOption configures lookup key conflict checks
func WithFailFast ¶ added in v0.23.0
func WithFailFast(f bool) LookupKeyCheckOption
WithFailFast stops checking after the first conflict is found
type LookupKeyConflict ¶ added in v0.23.0
LookupKeyConflict describes an existing Stripe price using a lookup key
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
type Usage ¶
type Usage struct {
// EvidenceStorageGB is the storage limit in GB for evidence related to the feature
EvidenceStorageGB int64 `` /* 142-byte string literal not displayed */
// RecordCount is the maximum number of records allowed for the feature
RecordCount int64 `` /* 131-byte string literal not displayed */
}
Usage defines usage limits granted by a feature.
Directories
¶
| Path | Synopsis |
|---|---|
|
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 |