models

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeliveryStatusSuccess = "success"
	DeliveryStatusFailed  = "failed"
)

Variables

View Source
var (
	ErrInvalidTopics       = errors.New("validation failed: invalid topics")
	ErrInvalidTopicsFormat = errors.New("validation failed: invalid topics format")
)
View Source
var (
	ErrTenantNotFound                  = errors.New("tenant does not exist")
	ErrTenantDeleted                   = errors.New("tenant has been deleted")
	ErrDuplicateDestination            = errors.New("destination already exists")
	ErrDestinationNotFound             = errors.New("destination does not exist")
	ErrDestinationDeleted              = errors.New("destination has been deleted")
	ErrMaxDestinationsPerTenantReached = errors.New("maximum number of destinations per tenant reached")
)

Functions

This section is empty.

Types

type AESCipher

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

func (*AESCipher) Decrypt

func (a *AESCipher) Decrypt(toBeDecrypted []byte) ([]byte, error)

func (*AESCipher) Encrypt

func (a *AESCipher) Encrypt(toBeEncrypted []byte) ([]byte, error)

type Cipher

type Cipher interface {
	Encrypt(data []byte) ([]byte, error)
	Decrypt(data []byte) ([]byte, error)
}

func NewAESCipher

func NewAESCipher(secret string) Cipher

type Config

type Config = MapStringString

type Credentials

type Credentials = MapStringString

type Data

type Data map[string]interface{}

func (*Data) String

func (d *Data) String() string

func (*Data) UnmarshalBinary

func (d *Data) UnmarshalBinary(data []byte) error

type Delivery

type Delivery struct {
	ID              string                 `json:"id"`
	DeliveryEventID string                 `json:"delivery_event_id"`
	EventID         string                 `json:"event_id"`
	DestinationID   string                 `json:"destination_id"`
	Status          string                 `json:"status"`
	Time            time.Time              `json:"time"`
	Code            string                 `json:"code"`
	ResponseData    map[string]interface{} `json:"response_data"`
}

type DeliveryEvent

type DeliveryEvent struct {
	ID            string
	Attempt       int
	DestinationID string
	Event         Event
	Delivery      *Delivery
	Telemetry     *DeliveryEventTelemetry
	Manual        bool // Indicates if this is a manual retry
}

func NewDeliveryEvent

func NewDeliveryEvent(event Event, destinationID string) DeliveryEvent

func NewManualDeliveryEvent

func NewManualDeliveryEvent(event Event, destinationID string) DeliveryEvent

func (*DeliveryEvent) FromMessage

func (e *DeliveryEvent) FromMessage(msg *mqs.Message) error

func (*DeliveryEvent) GetRetryID

func (e *DeliveryEvent) GetRetryID() string

GetRetryID returns the ID used for scheduling retries. We use Event.ID instead of DeliveryEvent.ID because: 1. Each event should only have one scheduled retry at a time 2. Event.ID is always accessible, while DeliveryEvent.ID may require additional queries in retry scenarios

func (*DeliveryEvent) ToMessage

func (e *DeliveryEvent) ToMessage() (*mqs.Message, error)

type DeliveryEventTelemetry

type DeliveryEventTelemetry struct {
	TraceID string
	SpanID  string
}

type DeliveryMetadata added in v0.8.0

type DeliveryMetadata = MapStringString

type Destination

type Destination struct {
	ID               string           `json:"id" redis:"id"`
	TenantID         string           `json:"tenant_id" redis:"-"`
	Type             string           `json:"type" redis:"type"`
	Topics           Topics           `json:"topics" redis:"-"`
	Filter           Filter           `json:"filter,omitempty" redis:"-"`
	Config           Config           `json:"config" redis:"-"`
	Credentials      Credentials      `json:"credentials" redis:"-"`
	DeliveryMetadata DeliveryMetadata `json:"delivery_metadata,omitempty" redis:"-"`
	Metadata         Metadata         `json:"metadata,omitempty" redis:"-"`
	CreatedAt        time.Time        `json:"created_at" redis:"created_at"`
	UpdatedAt        time.Time        `json:"updated_at" redis:"updated_at"`
	DisabledAt       *time.Time       `json:"disabled_at" redis:"disabled_at"`
}

func (*Destination) MatchEvent added in v0.10.0

func (d *Destination) MatchEvent(event Event) bool

MatchEvent checks if the destination matches the given event. Returns true if the destination is enabled, topic matches, and filter matches.

func (*Destination) ToSummary

func (d *Destination) ToSummary() *DestinationSummary

func (*Destination) Validate

func (d *Destination) Validate(topics []string) error

type DestinationFilter

type DestinationFilter struct {
	Type   []string
	Topics []string
}

type DestinationSummary

type DestinationSummary struct {
	ID       string `json:"id"`
	Type     string `json:"type"`
	Topics   Topics `json:"topics"`
	Filter   Filter `json:"filter,omitempty"`
	Disabled bool   `json:"disabled"`
}

func (*DestinationSummary) MarshalBinary

func (ds *DestinationSummary) MarshalBinary() ([]byte, error)

func (*DestinationSummary) MatchFilter added in v0.10.0

func (ds *DestinationSummary) MatchFilter(event Event) bool

MatchFilter checks if the given event matches the destination's filter. Returns true if no filter is set (nil or empty) or if the event matches the filter.

func (*DestinationSummary) UnmarshalBinary

func (ds *DestinationSummary) UnmarshalBinary(data []byte) error

type EntityStore

type EntityStore interface {
	RetrieveTenant(ctx context.Context, tenantID string) (*Tenant, error)
	UpsertTenant(ctx context.Context, tenant Tenant) error
	DeleteTenant(ctx context.Context, tenantID string) error
	ListDestinationByTenant(ctx context.Context, tenantID string, options ...ListDestinationByTenantOpts) ([]Destination, error)
	RetrieveDestination(ctx context.Context, tenantID, destinationID string) (*Destination, error)
	CreateDestination(ctx context.Context, destination Destination) error
	UpsertDestination(ctx context.Context, destination Destination) error
	DeleteDestination(ctx context.Context, tenantID, destinationID string) error
	MatchEvent(ctx context.Context, event Event) ([]DestinationSummary, error)
}

func NewEntityStore

func NewEntityStore(redisClient redis.Cmdable, opts ...EntityStoreOption) EntityStore

type EntityStoreOption

type EntityStoreOption func(*entityStoreImpl)

func WithAvailableTopics

func WithAvailableTopics(topics []string) EntityStoreOption

func WithCipher

func WithCipher(cipher Cipher) EntityStoreOption

func WithDeploymentID added in v0.7.0

func WithDeploymentID(deploymentID string) EntityStoreOption

func WithMaxDestinationsPerTenant

func WithMaxDestinationsPerTenant(maxDestinationsPerTenant int) EntityStoreOption

type Event

type Event struct {
	ID               string    `json:"id"`
	TenantID         string    `json:"tenant_id"`
	DestinationID    string    `json:"destination_id"`
	Topic            string    `json:"topic"`
	EligibleForRetry bool      `json:"eligible_for_retry"`
	Time             time.Time `json:"time"`
	Metadata         Metadata  `json:"metadata"`
	Data             Data      `json:"data"`
	Status           string    `json:"status,omitempty"`

	// Telemetry data, must exist to properly trace events between publish receiver & delivery handler
	Telemetry *EventTelemetry `json:"telemetry,omitempty"`
}

func (*Event) FromMessage

func (e *Event) FromMessage(msg *mqs.Message) error

func (*Event) ToMessage

func (e *Event) ToMessage() (*mqs.Message, error)

type EventTelemetry

type EventTelemetry struct {
	TraceID      string
	SpanID       string
	ReceivedTime string // format time.RFC3339Nano
}

type Filter added in v0.10.0

type Filter map[string]any

Filter represents a JSON schema filter for event matching. It uses the simplejsonmatch schema syntax for filtering events.

func (*Filter) MarshalBinary added in v0.10.0

func (f *Filter) MarshalBinary() ([]byte, error)

func (*Filter) UnmarshalBinary added in v0.10.0

func (f *Filter) UnmarshalBinary(data []byte) error

type ListDestinationByTenantOpts

type ListDestinationByTenantOpts struct {
	Filter *DestinationFilter
}

func WithDestinationFilter

func WithDestinationFilter(filter DestinationFilter) ListDestinationByTenantOpts

type MapStringString

type MapStringString map[string]string

func (*MapStringString) MarshalBinary

func (m *MapStringString) MarshalBinary() ([]byte, error)

func (*MapStringString) UnmarshalBinary

func (m *MapStringString) UnmarshalBinary(data []byte) error

func (*MapStringString) UnmarshalJSON

func (m *MapStringString) UnmarshalJSON(data []byte) error

type Metadata

type Metadata = MapStringString

type Tenant

type Tenant struct {
	ID                string    `json:"id" redis:"id"`
	DestinationsCount int       `json:"destinations_count" redis:"-"`
	Topics            []string  `json:"topics" redis:"-"`
	Metadata          Metadata  `json:"metadata,omitempty" redis:"-"`
	CreatedAt         time.Time `json:"created_at" redis:"created_at"`
	UpdatedAt         time.Time `json:"updated_at" redis:"updated_at"`
}

type Topics

type Topics []string

func TopicsFromString

func TopicsFromString(s string) Topics

func (*Topics) MarshalBinary

func (t *Topics) MarshalBinary() ([]byte, error)

func (*Topics) MarshalJSON

func (t *Topics) MarshalJSON() ([]byte, error)

func (*Topics) MatchTopic added in v0.9.0

func (t *Topics) MatchTopic(eventTopic string) bool

func (*Topics) MatchesAll

func (t *Topics) MatchesAll() bool

func (*Topics) UnmarshalBinary

func (t *Topics) UnmarshalBinary(data []byte) error

func (*Topics) UnmarshalJSON

func (t *Topics) UnmarshalJSON(data []byte) error

func (*Topics) Validate

func (t *Topics) Validate(availableTopics []string) error

Jump to

Keyboard shortcuts

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