models

package
v0.0.0-...-c8b8c93 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 15 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 = 10 * time.Second
View Source
const HTTP_RUBY string = "http_ruby"
View Source
const SUBSCRIPTION_BUCKET_DURATION int64 = 10
View Source
const TARGET_WALLET_CODE string = "target_wallet_code"

Variables

This section is empty.

Functions

func GetAllBillableMetricFilters

func GetAllBillableMetricFilters(db *gorm.DB) utils.Result[[]BillableMetricFilter]

func GetAllBillableMetrics

func GetAllBillableMetrics(db *gorm.DB) utils.Result[[]BillableMetric]

func GetAllChargeFilterValues

func GetAllChargeFilterValues(db *gorm.DB) utils.Result[[]ChargeFilterValue]

func GetAllChargeFilters

func GetAllChargeFilters(db *gorm.DB) utils.Result[[]ChargeFilter]

func GetAllCharges

func GetAllCharges(db *gorm.DB) utils.Result[[]Charge]

func GetAllSubscriptions

func GetAllSubscriptions(db *gorm.DB) utils.Result[[]Subscription]

We want to get terminated subscriptions to permit grace period events backfill So we select all non terminated subscriptions and subs terminated less that one month ago

func GetAllWithStreaming

func GetAllWithStreaming[T any](db *gorm.DB, config StreamQueryConfig) utils.Result[[]T]

func StreamRows

func StreamRows[T any](db *gorm.DB, config StreamQueryConfig, callback func(T) error) (int, error)

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;->" json:"id"`
	OrganizationID  string          `gorm:"->" json:"organization_id"`
	Code            string          `gorm:"->" json:"code"`
	AggregationType AggregationType `gorm:"->" json:"aggregation_type"`
	FieldName       string          `gorm:"->" json:"field_name"`
	Expression      string          `gorm:"->" json:"expression"`
	CreatedAt       utils.NullTime  `gorm:"->" json:"created_at"`
	UpdatedAt       utils.NullTime  `gorm:"->" json:"updated_at"`
	DeletedAt       utils.NullTime  `gorm:"index;->" json:"deleted_at"`
}

type BillableMetricFilter

type BillableMetricFilter struct {
	ID               string            `gorm:"primaryKey;->" json:"id"`
	OrganizationID   string            `gorm:"->" json:"organization_id"`
	BillableMetricID string            `gorm:"->" json:"billable_metric_id"`
	Key              string            `gorm:"->" json:"key"`
	Values           utils.StringArray `gorm:"type:text[];->" json:"values"`
	CreatedAt        utils.NullTime    `gorm:"->" json:"created_at"`
	UpdatedAt        utils.NullTime    `gorm:"->" json:"updated_at"`
	DeletedAt        utils.NullTime    `gorm:"->" json:"deleted_at"`
}

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 Charge

type Charge struct {
	ID                  string            `gorm:"primaryKey;->" json:"id"`
	OrganizationID      string            `gorm:"->" json:"organization_id"`
	PlanID              string            `gorm:"->" json:"plan_id"`
	BillableMetricID    string            `gorm:"->" json:"billable_metric_id"`
	PayInAdvance        bool              `gorm:"->" json:"pay_in_advance"`
	AcceptsTargetWallet bool              `gorm:"->" json:"accepts_target_wallet"`
	PricingGroupKeys    utils.StringArray `gorm:"type:jsonb;->" json:"properties.pricing_group_keys"`
	CreatedAt           utils.NullTime    `gorm:"->" json:"created_at"`
	UpdatedAt           utils.NullTime    `gorm:"->" json:"updated_at"`
	DeletedAt           utils.NullTime    `gorm:"->" json:"deleted_at"`
}

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 ChargeFilter

type ChargeFilter struct {
	ID               string            `gorm:"primaryKey;->" json:"id"`
	OrganizationID   string            `gorm:"->" json:"organization_id"`
	ChargeID         string            `gorm:"->" json:"charge_id"`
	PricingGroupKeys utils.StringArray `gorm:"type:jsonb;->" json:"properties.pricing_group_keys"`
	CreatedAt        utils.NullTime    `gorm:"->" json:"created_at"`
	UpdatedAt        utils.NullTime    `gorm:"->" json:"updated_at"`
	DeletedAt        utils.NullTime    `gorm:"->" json:"deleted_at"`
}

type ChargeFilterValue

type ChargeFilterValue struct {
	ID                     string            `gorm:"primaryKey;->" json:"id"`
	OrganizationID         string            `gorm:"->" json:"organization_id"`
	ChargeFilterID         string            `gorm:"->" json:"charge_filter_id"`
	BillableMetricFilterID string            `gorm:"->" json:"billable_metric_filter_id"`
	Values                 utils.StringArray `gorm:"type:text[];->" json:"values"`
	CreatedAt              utils.NullTime    `gorm:"->" json:"created_at"`
	UpdatedAt              utils.NullTime    `gorm:"->" json:"updated_at"`
	DeletedAt              utils.NullTime    `gorm:"->" json:"deleted_at"`
}

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"`
	TargetWalletCode        *string           `json:"target_wallet_code"`
}

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) IsReprocess

func (ev *Event) IsReprocess() bool

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

Flag adds a subscription to the sorted set for delayed refresh. The member key includes a time bucket (value|bucket) so that events within the same SUBSCRIPTION_BUCKET_DURATION window share a member — ZADD overwrites the score to the latest event, waiting after the last event in that window. Once the window elapses, new events create a new member, ensuring the previous one ages out and gets picked up by the consumer (no starvation).

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"`
	AcceptsTargetWallet   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"`
	Reprocess      bool `json:"reprocess"`
}

type StreamQueryConfig

type StreamQueryConfig struct {
	TableName      string
	SelectFields   []string
	WhereCondition string
	WhereArgs      []interface{}
	LogInterval    int
}

type Subscription

type Subscription struct {
	ID             string         `gorm:"primaryKey;->" json:"id"`
	OrganizationID *string        `gorm:"->" json:"organization_id"`
	ExternalID     string         `gorm:"->" json:"external_id"`
	PlanID         string         `gorm:"->" json:"plan_id"`
	CreatedAt      utils.NullTime `gorm:"->" json:"created_at"`
	UpdatedAt      utils.NullTime `gorm:"->" json:"updated_at"`
	StartedAt      utils.NullTime `gorm:"->" json:"started_at"`
	TerminatedAt   utils.NullTime `gorm:"->" json:"terminated_at"`
}

Jump to

Keyboard shortcuts

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