Skip to content

Invitation

Overview

The Invitation domain in comby handles the process of inviting users to join an organization or Tenant. It supports the lifecycle of an invitation, from creation and sending to acceptance or declination. The Invitation aggregate is at the core of this domain, providing the structure for managing invitations, tracking their state, and handling related domain events.

An Invitation can belong to only one Tenant. However, a user can be invited to multiple Tenants. This design enables a user to be associated with multiple Tenants through separate invitations.

Structure

The Invitation aggregate consists of the following elements:

References:

  • GroupUuids: A list of group UUIDs to which the invited account will be added upon accepting the invitation.
  • IdentityUuid: The UUID of the identity that created the invitation.
  • AccountUuid: The UUID of the account that accepts the invitation.

Value Objects:

  • Token: A unique token associated with the invitation, typically used for verification or authentication.
  • Email: The email address of the invitee.
  • State: Tracks the current state of the invitation, such as created, sent, accepted, or declined.

The domain defines several states to represent the lifecycle of an invitation:

  • created: The invitation has been created but not yet sent. sent: The invitation has been sent to the invitee.
  • sent: The invitation has been sent to the invitee.
  • accepted: The invitee has accepted the invitation, and the associated account has been added to the relevant groups.
  • declined: The invitee has declined the invitation. These states enable precise tracking of invitation progress and ensure consistent processing across the system.

Commands

InvitationCommandAccept

Domain Command Struct:

go
type InvitationCommandAccept struct {
	InvitationUuid string `json:"invitationUuid"`
	AccountUuid    string `json:"accountUuid"`
	Token          string `json:"token"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandAccept(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandAccept) ([]comby.Event, error)

InvitationCommandCreate

Domain Command Struct:

go
type InvitationCommandCreate struct {
	InvitationUuid string   `json:"invitationUuid"`
	IdentityUuid   string   `json:"identityUuid"`
	GroupUuids     []string `json:"groupUuids"`
	Email          string   `json:"email"`
	Attributes     string   `json:"attributes,omitempty"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandCreate(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandCreate) ([]comby.Event, error)

InvitationCommandDecline

Domain Command Struct:

go
type InvitationCommandDecline struct {
	InvitationUuid string `json:"invitationUuid"`
	AccountUuid    string `json:"accountUuid"`
	Token          string `json:"token"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandDecline(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandDecline) ([]comby.Event, error)

InvitationCommandRemove

Domain Command Struct:

go
type InvitationCommandRemove struct {
	InvitationUuid string `json:"invitationUuid"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandRemove) ([]comby.Event, error)

InvitationCommandRemoveAttribute

Domain Command Struct:

go
type InvitationCommandRemoveAttribute struct {
	InvitationUuid string `json:"invitationUuid"`
	Key            string `json:"key"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandRemoveAttribute) ([]comby.Event, error)

InvitationCommandSend

Domain Command Struct:

go
type InvitationCommandSend struct {
	InvitationUuid string `json:"invitationUuid"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandSend(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandSend) ([]comby.Event, error)

InvitationCommandSetAttribute

Domain Command Struct:

go
type InvitationCommandSetAttribute struct {
	InvitationUuid string `json:"invitationUuid"`
	Key            string `json:"key"`
	Value          any    `json:"value"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandSetAttribute) ([]comby.Event, error)

InvitationCommandUpdate

Domain Command Struct:

go
type InvitationCommandUpdate struct {
	InvitationUuid string   `json:"invitationUuid"`
	Attributes     string   `json:"attributes,omitempty"`
	PatchedFields  []string `json:"patchedFields"`
}

Domain Command Handling Method:

go
func (cs *commandHandler) InvitationCommandUpdate(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandUpdate) ([]comby.Event, error)

Queries

Domain Query Structs:

Domain Query Responses:

InvitationQueryList

Domain Query Struct:

go
type InvitationQueryList struct {
	TenantUuid string `json:"tenantUuid"`
	Page       int64  `json:"page,omitempty"`
	PageSize   int64  `json:"pageSize,omitempty"`
	OrderBy    string `json:"orderBy,omitempty"`
	Attributes string `json:"attributes,omitempty"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) InvitationQueryList(ctx context.Context, qry comby.Query, domainQry *InvitationQueryList) (*InvitationQueryListResponse, error)

InvitationQueryModel

Domain Query Struct:

go
type InvitationQueryModel struct {
	InvitationUuid string `json:"invitationUuid"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) InvitationQueryModel(ctx context.Context, qry comby.Query, domainQry *InvitationQueryModel) (*InvitationQueryItemResponse, error)

InvitationQueryModelByInvitationToken

Domain Query Struct:

go
type InvitationQueryModelByInvitationToken struct {
	InvitationToken string `json:"invitationToken"`
}

Domain Query Handling Method:

go
func (qs *queryHandler) InvitationQueryModelByInvitationToken(ctx context.Context, qry comby.Query, domainQry *InvitationQueryModelByInvitationToken) (*InvitationQueryItemResponse, error)

InvitationQueryListResponse

go
type InvitationQueryListResponse struct {
	Items    []*readmodel.InvitationModel `json:"items,omitempty"`
	Total    int64                        `json:"total,omitempty"`
	Page     int64                        `json:"page,omitempty"`
	PageSize int64                        `json:"pageSize,omitempty"`
}

InvitationQueryItemResponse

go
type InvitationQueryItemResponse struct {
	Item *readmodel.InvitationModel `json:"item,omitempty"`
}

Events

InvitationAcceptedEvent

Domain Event Struct:

go
type InvitationAcceptedEvent struct {
	AccountUuid string `json:"accountUuid"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationAcceptedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAcceptedEvent) (error)

InvitationCreatedEvent

Domain Event Struct:

go
type InvitationCreatedEvent struct {
	IdentityUuid string   `json:"identityUuid"`
	GroupUuids   []string `json:"groupUuids"`
	Token        string   `json:"token"`
	Email        string   `json:"email"`
	Attributes   string   `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationCreatedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationCreatedEvent) (error)

InvitationDeclinedEvent

Domain Event Struct:

go
type InvitationDeclinedEvent struct {
	AccountUuid string `json:"accountUuid"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationDeclinedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationDeclinedEvent) (error)

InvitationRemovedEvent

Domain Event Struct:

go
type InvitationRemovedEvent struct {
	Reason string `json:"reason,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationRemovedEvent) (error)

InvitationAttributeRemovedEvent

Domain Event Struct:

go
type InvitationAttributeRemovedEvent struct {
	Key string `json:"key"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAttributeRemovedEvent) (error)

InvitationSentEvent

Domain Event Struct:

go
type InvitationSentEvent struct {
	State string `json:"state"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationSentEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationSentEvent) (error)

InvitationAttributeSetEvent

Domain Event Struct:

go
type InvitationAttributeSetEvent struct {
	Key   string `json:"key"`
	Value any    `json:"value"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAttributeSetEvent) (error)

InvitationUpdatedEvent

Domain Event Struct:

go
type InvitationUpdatedEvent struct {
	Attributes string `json:"attributes,omitempty"`
}

Domain Event Handling Method:

go
func (agg *Invitation) InvitationUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationUpdatedEvent) (error)

Aggregate

Aggregate Struct:

go
type Invitation struct {
	*comby.BaseAggregate
	// GroupUuids groups to which the invited account will be added
	GroupUuids []string
	// IdentityUuid who created the invitation
	IdentityUuid string
	// AccountUuid who accepted the invitation
	AccountUuid string
	// Value Objects
	Token string
	Email string
	State string
}

Methods

Accept

go
func (agg *Invitation) Accept(accountUuid string) (error)

Create

go
func (agg *Invitation) Create(identityUuid string, groupUuids []string, token, email, attributes string) (error)

Decline

go
func (agg *Invitation) Decline(accountUuid string) (error)

Remove

go
func (agg *Invitation) Remove() (error)

RemoveAttribute

go
func (agg *Invitation) RemoveAttribute(key string) (error)

Send

go
func (agg *Invitation) Send() (error)

SetAttribute

go
func (agg *Invitation) SetAttribute(key string, value any) (error)

Update

go
func (agg *Invitation) Update(attributes string) (error)

Event Handlers

Reactor

Domain EventMethod
aggregateInvitation.InvitationCreatedEventInvitationCreatedEvent
aggregateInvitation.InvitationAcceptedEventInvitationAcceptedEvent

InvitationReadmodel

Domain EventMethod
tenantAggregate.TenantCreatedEventTenantCreatedEvent
tenantAggregate.TenantUpdatedEventTenantUpdatedEvent
tenantAggregate.TenantRemovedEventTenantRemovedEvent
invitationAggregate.InvitationSentEventInvitationSentEvent
invitationAggregate.InvitationAcceptedEventInvitationAcceptedEvent
invitationAggregate.InvitationAttributeRemovedEventInvitationAttributeRemovedEvent
invitationAggregate.InvitationAttributeSetEventInvitationAttributeSetEvent
invitationAggregate.InvitationCreatedEventInvitationCreatedEvent
invitationAggregate.InvitationUpdatedEventInvitationUpdatedEvent
invitationAggregate.InvitationRemovedEventInvitationRemovedEvent
invitationAggregate.InvitationDeclinedEventInvitationDeclinedEvent
identityAggregate.IdentityCreatedEventIdentityCreatedEvent
identityAggregate.IdentityProfileUpdatedEventIdentityProfileUpdatedEvent
identityAggregate.IdentityRemovedEventIdentityRemovedEvent
groupAggregate.GroupUpdatedEventGroupUpdatedEvent
groupAggregate.GroupRemovedEventGroupRemovedEvent
groupAggregate.GroupAddedEventGroupAddedEvent
accountAggregate.AccountCredentialsUpdatedEventAccountCredentialsUpdatedEvent