events

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Time

func Time(date time.Time) *time.Time

Time handles the time.Time checking if the current date is a zero-value. If it is, it will return a pointer to the current time. Otherwise, we will return nil Using that, we can handle empty dates nil, instead of zero-value

Types

type APIVersion

type APIVersion string

APIVersion defines the current API version

const (
	// CurrentAPIVersion specify the lastest API version
	CurrentAPIVersion APIVersion = "1.2.0"
)

type App

type App struct {
	// ID defines the application id that is provided by the publisher
	ID string `bson:"id" json:"id"`

	// Version defines the application version which the event was triggered
	Version string `bson:"version" json:"version"`

	// Name holds the name of the app. It helps us add more context to the payload
	Name string `bson:"name" json:"name"`

	// IsBundle defines if the app is a group of apps.
	IsBundle bool `bson:"isBundle" json:"isBundle"`

	BundledAppIDs []string     `bson:"bundledAppIds,omitempty" json:"bundledAppIds,omitempty"`
	BundledIn     []BundleInfo `bson:"bundledIn,omitempty" json:"bundledIn,omitempty"` // BundledIn only includes id and name
}

App holds information about the application which the event was triggered

type BundleInfo

type BundleInfo struct {
	ID   string `bson:"id" json:"id,omitempty"`
	Name string `bson:"name" json:"name,omitempty"`
}

BundleInfo defines information about a bundle when the app is included in a bundle. This way we can identify the bundle and the app is included in it

type Event

type Event struct {
	// unique generated id
	ID string `bson:"_id,omitempty" json:"id"`

	// Type defines an unique string key that identifies an event
	// E.g: application.purchased
	Type EventType `bson:"type" json:"type"`

	// Event definition version. We can use this field handle the event definition schema evolution
	// E.g: 1.0
	APIVersion `bson:"apiVersion" json:"apiVersion"`

	// Defines a UTC timestamp within the time when an event was created
	// E.g: 1651772844
	When time.Time `bson:"when" json:"when"`

	// Data has the event specific payload
	Data json.RawMessage `bson:"data" json:"data"`
}

Event represent something that happened An event is always related to an app. We will always have the application info at the root of the event

func New

func New(name EventType, data interface{}) Event

New creates a new event with the status of created

type EventObjectType

type EventObjectType string

EventObjectType holds the event type we are working.

const (
	// SubscriptionDataType describes the type of the data we are holding.
	// It allow us easily map data from the database to a struct
	SubscriptionDataType EventObjectType = "subscription"

	// PurchaseDataType describes the type of the data we are holding.
	// It allow us easily map data from the database to a struct
	PurchaseDataType EventObjectType = "purchase"
)

type EventType

type EventType string

EventType is a unique key defined by event

const (
	// AppSubscribedEventType defines the string constant name for the event that happens when
	// a user subscribes to a plan
	AppSubscribedEventType EventType = "app.subscription.created"

	// AppSubscriptionCancelledEventType defines the string constant name for the event that happens when
	// a user cancels a subscription
	AppSubscriptionCancelledEventType EventType = "app.subscription.cancelled"

	// AppSubscriptionModifiedEventType defines the string constant name for the event that happens when
	// a subscription is modified
	AppSubscriptionModifiedEventType EventType = "app.subscription.modified"

	// AppSubscriptionMigratedEventType defines the event related to when a subscription is migrate to use the bundle
	AppSubscriptionMigratedEventType EventType = "app.subscription.migrated"

	// AppPurchasedEventType indicates which type the struct is. Could make it easier for us data map this event from the database
	AppPurchasedEventType EventType = "app.purchase.created"
)

func (EventType) Valid

func (et EventType) Valid() bool

type Workspace

type Workspace struct {
	ID        string `bson:"id" json:"id"`
	AccountID string `bson:"accountId" json:"accountId"`
	NickName  string `bson:"nickName" json:"nickName"`
	Address   string `bson:"address" json:"address"`
}

Workspace defines the workspace where the event was triggered

Jump to

Keyboard shortcuts

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