models

package
v0.0.0-...-e8bbd60 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggregationTypeCount = iota
	AggregationTypeSum
	AggregationTypeMax
	AggregationTypeUniqueCount

	AggregationTypeWeightedSum
	AggregationTypeLatest
	AggregationTypeCustom
)
View Source
const CACHE_KEY_VERSION = "1"
View Source
const EXPIRATION_TIME = 5 * time.Second
View Source
const HTTP_RUBY string = "http_ruby"

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationType

type AggregationType int

func (AggregationType) String

func (t AggregationType) String() string

type ApiStore

type ApiStore struct {
	// contains filtered or unexported fields
}

func NewApiStore

func NewApiStore(db *database.DB) *ApiStore

func (*ApiStore) FetchBillableMetric

func (store *ApiStore) FetchBillableMetric(organizationID string, code string) utils.Result[*BillableMetric]

func (*ApiStore) FetchFlatFilters

func (store *ApiStore) FetchFlatFilters(planID string, billableMetricCode string) utils.Result[[]FlatFilter]

func (*ApiStore) FetchSubscription

func (store *ApiStore) FetchSubscription(organizationID string, externalID string, timestamp time.Time) utils.Result[*Subscription]

type BillableMetric

type BillableMetric struct {
	ID              string          `gorm:"primaryKey;->"`
	OrganizationID  string          `gorm:"->"`
	Code            string          `gorm:"->"`
	AggregationType AggregationType `gorm:"->"`
	FieldName       string          `gorm:"->"`
	Expression      string          `gorm:"->"`
	CreatedAt       time.Time       `gorm:"->"`
	UpdatedAt       time.Time       `gorm:"->"`
	DeletedAt       gorm.DeletedAt  `gorm:"index;->"`
}

type CacheStore

type CacheStore struct {
	// contains filtered or unexported fields
}

func NewCacheStore

func NewCacheStore(ctx context.Context, redis *redis.RedisDB) *CacheStore

func (*CacheStore) Close

func (store *CacheStore) Close() error

func (*CacheStore) ExpireKey

func (store *CacheStore) ExpireKey(key string) utils.Result[bool]

type Cacher

type Cacher interface {
	Close() error
	ExpireKey(key string) utils.Result[bool]
}

type ChargeCache

type ChargeCache struct {
	CacheStore Cacher
}

func NewChargeCache

func NewChargeCache(cacheStore *Cacher) *ChargeCache

func (*ChargeCache) Expire

func (cache *ChargeCache) Expire(ff *FlatFilter, subID string) utils.Result[bool]

type EnrichedEvent

type EnrichedEvent struct {
	InitialEvent   *Event          `json:"-"`
	BillableMetric *BillableMetric `json:"-"`
	Subscription   *Subscription   `json:"-"`
	FlatFilter     *FlatFilter     `json:"-"`

	OrganizationID          string            `json:"organization_id"`
	ExternalSubscriptionID  string            `json:"external_subscription_id"`
	SubscriptionID          string            `json:"subscription_id"`
	PlanID                  string            `json:"plan_id"`
	TransactionID           string            `json:"transaction_id"`
	Code                    string            `json:"code"`
	AggregationType         string            `json:"aggregation_type"`
	Properties              map[string]any    `json:"properties"`
	PreciseTotalAmountCents string            `json:"precise_total_amount_cents"`
	Source                  string            `json:"source,omitempty"`
	Value                   *string           `json:"value"`
	Timestamp               float64           `json:"timestamp"`
	TimestampStr            string            `json:"-"`
	Time                    time.Time         `json:"-"`
	ChargeID                *string           `json:"charge_id"`
	ChargeUpdatedAt         *time.Time        `json:"charge_updated_at"`
	ChargeFilterID          *string           `json:"charge_filter_id"`
	ChargeFilterUpdatedAt   *time.Time        `json:"charge_filter_updated_at"`
	GroupedBy               map[string]string `json:"grouped_by"`
}

type Event

type Event struct {
	OrganizationID          string           `json:"organization_id"`
	ExternalSubscriptionID  string           `json:"external_subscription_id"`
	TransactionID           string           `json:"transaction_id"`
	Code                    string           `json:"code"`
	Properties              map[string]any   `json:"properties"`
	PreciseTotalAmountCents string           `json:"precise_total_amount_cents"`
	Source                  string           `json:"source,omitempty"`
	Timestamp               any              `json:"timestamp"`
	SourceMetadata          *SourceMetadata  `json:"source_metadata"`
	IngestedAt              utils.CustomTime `json:"ingested_at"`
}

func (*Event) NotAPIPostProcessed

func (ev *Event) NotAPIPostProcessed() bool

func (*Event) ToEnrichedEvent

func (ev *Event) ToEnrichedEvent() utils.Result[*EnrichedEvent]

type FailedEvent

type FailedEvent struct {
	Event               Event     `json:"event"`
	InitialErrorMessage string    `json:"initial_error_message"`
	ErrorMessage        string    `json:"error_message"`
	ErrorCode           string    `json:"error_code"`
	FailedAt            time.Time `json:"failed_at"`
}

type FlagStore

type FlagStore struct {
	// contains filtered or unexported fields
}

func NewFlagStore

func NewFlagStore(ctx context.Context, redis *redis.RedisDB, name string) *FlagStore

func (*FlagStore) Close

func (store *FlagStore) Close() error

func (*FlagStore) Flag

func (store *FlagStore) Flag(value string) error

type Flagger

type Flagger interface {
	Flag(value string) error
}

type FlatFilter

type FlatFilter struct {
	OrganizationID        string            `gorm:"->"`
	BillableMetricCode    string            `gorm:"->"`
	PlanID                string            `gorm:"->"`
	ChargeID              string            `gorm:"->"`
	ChargeUpdatedAt       time.Time         `gorm:"->"`
	ChargeFilterID        *string           `gorm:"->"`
	ChargeFilterUpdatedAt *time.Time        `gorm:"->"`
	Filters               *FlatFilterValues `gorm:"type:jsonb"`
	PricingGroupKeys      PricingGroupKeys  `gorm:"type:jsonb"`
	PayInAdvance          bool              `gorm:"type:boolean"`
}

func MatchingFilter

func MatchingFilter(filters []FlatFilter, event *EnrichedEvent) *FlatFilter

func (*FlatFilter) HasFilters

func (ff *FlatFilter) HasFilters() bool

func (*FlatFilter) IsMatchingEvent

func (ff *FlatFilter) IsMatchingEvent(event *EnrichedEvent) utils.Result[bool]

func (*FlatFilter) ToDefaultFilter

func (ff *FlatFilter) ToDefaultFilter() *FlatFilter

type FlatFilterValues

type FlatFilterValues map[string][]string

func (*FlatFilterValues) Keys

func (ffv *FlatFilterValues) Keys() []string

func (*FlatFilterValues) Scan

func (fm *FlatFilterValues) Scan(value any) error

Implements the sql.Scanner interface to convert JSONB into FlatFilterValues

func (FlatFilterValues) Value

func (fm FlatFilterValues) Value() (driver.Value, error)

Implements the driver.Valuer interface converting FlatFilterValues to a JSONB value

type PricingGroupKeys

type PricingGroupKeys []string

func (*PricingGroupKeys) Scan

func (fm *PricingGroupKeys) Scan(value any) error

Implements the sql.Scanner interface to convert JSONB into FlatFilterValues

func (PricingGroupKeys) Value

func (fm PricingGroupKeys) Value() (driver.Value, error)

Implements the driver.Valuer interface converting FlatFilterValues to a JSONB value

type SourceMetadata

type SourceMetadata struct {
	ApiPostProcess bool `json:"api_post_processed"`
}

type Subscription

type Subscription struct {
	ID           string       `gorm:"primaryKey;->"`
	ExternalID   string       `gorm:"->"`
	PlanID       string       `gorm:"->"`
	CreatedAt    time.Time    `gorm:"->"`
	UpdatedAt    time.Time    `gorm:"->"`
	StartedAt    sql.NullTime `gorm:"->"`
	TerminatedAt sql.NullTime `gorm:"->"`
}

Jump to

Keyboard shortcuts

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