command

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 10 Imported by: 5

Documentation

Overview

Package command exposes go-command compatible command handlers implementing go-users business logic (lifecycle transitions, invites, role updates, etc.). Commands are wired by the service layer and can be invoked by any transport.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLifecycleUserIDRequired indicates the transition command lacks a user ID.
	ErrLifecycleUserIDRequired = errors.New("go-users: lifecycle transition requires user id")
	// ErrLifecycleTargetRequired indicates the desired lifecycle state is missing.
	ErrLifecycleTargetRequired = errors.New("go-users: lifecycle transition requires target state")
	// ErrActorRequired indicates an actor reference was not supplied.
	ErrActorRequired = types.ErrActorRequired
	// ErrUserRequired indicates a user payload was not supplied.
	ErrUserRequired = errors.New("go-users: user payload required")
	// ErrUserEmailRequired indicates a user email address was missing.
	ErrUserEmailRequired = errors.New("go-users: user email required")
	// ErrInviteEmailRequired occurs when an invite omits the email address.
	ErrInviteEmailRequired = errors.New("go-users: invite requires email")
	// ErrPasswordHashRequired occurs when a password reset omits the hashed password.
	ErrPasswordHashRequired = errors.New("go-users: password reset requires password hash")
	// ErrUserIDsRequired occurs when bulk handlers are invoked without targets.
	ErrUserIDsRequired = errors.New("go-users: user ids required")
	// ErrUsersRequired occurs when bulk user import lacks users.
	ErrUsersRequired = errors.New("go-users: users required")
	// ErrRoleNameRequired occurs when a role command omits the role name.
	ErrRoleNameRequired = errors.New("go-users: role name required")
	// ErrRoleIDRequired signals the role ID was missing.
	ErrRoleIDRequired = errors.New("go-users: role id required")
	// ErrUserIDRequired occurs when assignment commands omit the user.
	ErrUserIDRequired = types.ErrUserIDRequired
	// ErrActivityVerbRequired indicates an activity log entry is missing a verb.
	ErrActivityVerbRequired = errors.New("go-users: activity verb required")
	// ErrPreferenceKeyRequired indicates the preference key was missing.
	ErrPreferenceKeyRequired = errors.New("go-users: preference key required")
	// ErrPreferenceValueRequired indicates the preference value payload was missing.
	ErrPreferenceValueRequired = errors.New("go-users: preference value required")
)

Functions

This section is empty.

Types

type ActivityLogCommand

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

ActivityLogCommand logs arbitrary activity records.

func NewActivityLogCommand

func NewActivityLogCommand(cfg ActivityLogConfig) *ActivityLogCommand

NewActivityLogCommand constructs the logging command handler.

func (*ActivityLogCommand) Execute

func (c *ActivityLogCommand) Execute(ctx context.Context, input ActivityLogInput) error

Execute validates and persists the supplied record.

type ActivityLogConfig

type ActivityLogConfig struct {
	Sink  types.ActivitySink
	Hooks types.Hooks
	Clock types.Clock
}

ActivityLogConfig wires dependencies for the log command.

type ActivityLogInput

type ActivityLogInput struct {
	Record types.ActivityRecord
}

ActivityLogInput wraps a record to persist through the ActivitySink.

func (ActivityLogInput) Type

func (ActivityLogInput) Type() string

Type implements gocommand.Message.

func (ActivityLogInput) Validate

func (input ActivityLogInput) Validate() error

Validate implements gocommand.Message.

type AssignRoleCommand

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

AssignRoleCommand wraps registry assignments.

func NewAssignRoleCommand

func NewAssignRoleCommand(registry types.RoleRegistry, guard scope.Guard) *AssignRoleCommand

NewAssignRoleCommand constructs the handler.

func (*AssignRoleCommand) Execute

func (c *AssignRoleCommand) Execute(ctx context.Context, input AssignRoleInput) error

Execute assigns the requested role.

type AssignRoleInput

type AssignRoleInput struct {
	UserID uuid.UUID
	RoleID uuid.UUID
	Scope  types.ScopeFilter
	Actor  types.ActorRef
}

AssignRoleInput assigns a role to a user.

func (AssignRoleInput) Type

func (AssignRoleInput) Type() string

Type implements gocommand.Message.

func (AssignRoleInput) Validate

func (input AssignRoleInput) Validate() error

Validate implements gocommand.Message.

type BulkUserImportCommand added in v0.7.0

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

BulkUserImportCommand imports users in bulk, reusing the create command.

func NewBulkUserImportCommand added in v0.7.0

func NewBulkUserImportCommand(create *UserCreateCommand) *BulkUserImportCommand

NewBulkUserImportCommand constructs the bulk import handler.

func (*BulkUserImportCommand) Execute added in v0.7.0

Execute imports each user sequentially, recording per-record results.

type BulkUserImportInput added in v0.7.0

type BulkUserImportInput struct {
	Users           []*types.AuthUser
	Actor           types.ActorRef
	Scope           types.ScopeFilter
	DefaultStatus   types.LifecycleState
	ContinueOnError bool
	DryRun          bool
	Results         *[]BulkUserImportResult
}

BulkUserImportInput applies user creation in bulk without file parsing.

func (BulkUserImportInput) Type added in v0.7.0

func (BulkUserImportInput) Type() string

Type implements gocommand.Message.

func (BulkUserImportInput) Validate added in v0.7.0

func (input BulkUserImportInput) Validate() error

Validate implements gocommand.Message.

type BulkUserImportResult added in v0.7.0

type BulkUserImportResult struct {
	Index  int
	UserID uuid.UUID
	Email  string
	Status types.LifecycleState
	Err    error
}

BulkUserImportResult captures the outcome for a single record.

type BulkUserTransitionCommand

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

BulkUserTransitionCommand iterates through the supplied user IDs, reusing the single-user lifecycle command to enforce policies uniformly.

func NewBulkUserTransitionCommand

func NewBulkUserTransitionCommand(lifecycle *UserLifecycleTransitionCommand) *BulkUserTransitionCommand

NewBulkUserTransitionCommand constructs the bulk handler.

func (*BulkUserTransitionCommand) Execute

Execute transitions each user sequentially. Errors are aggregated.

type BulkUserTransitionInput

type BulkUserTransitionInput struct {
	UserIDs     []uuid.UUID
	Target      types.LifecycleState
	Actor       types.ActorRef
	Reason      string
	Metadata    map[string]any
	Scope       types.ScopeFilter
	StopOnError bool
	Results     *[]BulkUserTransitionResult
}

BulkUserTransitionInput applies the same lifecycle change to multiple users.

func (BulkUserTransitionInput) Type

Type implements gocommand.Message.

func (BulkUserTransitionInput) Validate

func (input BulkUserTransitionInput) Validate() error

Validate implements gocommand.Message.

type BulkUserTransitionResult

type BulkUserTransitionResult struct {
	UserID uuid.UUID
	Err    error
}

BulkUserTransitionResult captures the outcome for a single user.

type CreateRoleCommand

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

CreateRoleCommand invokes the injected role registry.

func NewCreateRoleCommand

func NewCreateRoleCommand(registry types.RoleRegistry, guard scope.Guard) *CreateRoleCommand

NewCreateRoleCommand wires a role creation handler.

func (*CreateRoleCommand) Execute

func (c *CreateRoleCommand) Execute(ctx context.Context, input CreateRoleInput) error

Execute validates and forwards the creation payload to the registry.

type CreateRoleInput

type CreateRoleInput struct {
	Name        string
	Order       int
	Description string
	RoleKey     string
	Permissions []string
	Metadata    map[string]any
	IsSystem    bool
	Scope       types.ScopeFilter
	Actor       types.ActorRef
	Result      *types.RoleDefinition
}

CreateRoleInput carries data for creating custom roles.

func (CreateRoleInput) Type

func (CreateRoleInput) Type() string

Type implements gocommand.Message.

func (CreateRoleInput) Validate

func (input CreateRoleInput) Validate() error

Validate implements gocommand.Message.

type DeleteRoleCommand

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

DeleteRoleCommand deletes roles through the registry.

func NewDeleteRoleCommand

func NewDeleteRoleCommand(registry types.RoleRegistry, guard scope.Guard) *DeleteRoleCommand

NewDeleteRoleCommand constructs the handler.

func (*DeleteRoleCommand) Execute

func (c *DeleteRoleCommand) Execute(ctx context.Context, input DeleteRoleInput) error

Execute deletes the requested role after validation.

type DeleteRoleInput

type DeleteRoleInput struct {
	RoleID uuid.UUID
	Scope  types.ScopeFilter
	Actor  types.ActorRef
}

DeleteRoleInput removes a custom role.

func (DeleteRoleInput) Type

func (DeleteRoleInput) Type() string

Type implements gocommand.Message.

func (DeleteRoleInput) Validate

func (input DeleteRoleInput) Validate() error

Validate implements gocommand.Message.

type InviteCommandConfig

type InviteCommandConfig struct {
	Repository types.AuthRepository
	Clock      types.Clock
	IDGen      types.IDGenerator
	Activity   types.ActivitySink
	Hooks      types.Hooks
	Logger     types.Logger
	TokenTTL   time.Duration
	ScopeGuard scope.Guard
}

InviteCommandConfig holds dependencies for the invite flow.

type LifecycleCommandConfig

type LifecycleCommandConfig struct {
	Repository types.AuthRepository
	Policy     types.TransitionPolicy
	Clock      types.Clock
	Logger     types.Logger
	Hooks      types.Hooks
	Activity   types.ActivitySink
	ScopeGuard scope.Guard
}

LifecycleCommandConfig configures the lifecycle command handler.

type PasswordResetCommandConfig

type PasswordResetCommandConfig struct {
	Repository types.AuthRepository
	Clock      types.Clock
	Activity   types.ActivitySink
	Hooks      types.Hooks
	Logger     types.Logger
	ScopeGuard scope.Guard
}

PasswordResetCommandConfig wires the reset handler.

type PreferenceCommandConfig

type PreferenceCommandConfig struct {
	Repository types.PreferenceRepository
	Hooks      types.Hooks
	Clock      types.Clock
	ScopeGuard scope.Guard
}

PreferenceCommandConfig wires dependencies for preference commands.

type PreferenceDeleteCommand

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

PreferenceDeleteCommand removes a scoped preference entry.

func NewPreferenceDeleteCommand

func NewPreferenceDeleteCommand(cfg PreferenceCommandConfig) *PreferenceDeleteCommand

NewPreferenceDeleteCommand constructs the delete handler.

func (*PreferenceDeleteCommand) Execute

Execute removes the preference entry for the supplied key.

type PreferenceDeleteInput

type PreferenceDeleteInput struct {
	UserID uuid.UUID
	Scope  types.ScopeFilter
	Level  types.PreferenceLevel
	Key    string
	Actor  types.ActorRef
}

PreferenceDeleteInput captures the delete payload.

func (PreferenceDeleteInput) Type

Type implements gocommand.Message.

func (PreferenceDeleteInput) Validate

func (input PreferenceDeleteInput) Validate() error

Validate implements gocommand.Message.

type PreferenceUpsertCommand

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

PreferenceUpsertCommand upserts a scoped preference record.

func NewPreferenceUpsertCommand

func NewPreferenceUpsertCommand(cfg PreferenceCommandConfig) *PreferenceUpsertCommand

NewPreferenceUpsertCommand constructs the handler.

func (*PreferenceUpsertCommand) Execute

Execute validates and persists the preference payload.

type PreferenceUpsertInput

type PreferenceUpsertInput struct {
	UserID uuid.UUID
	Scope  types.ScopeFilter
	Level  types.PreferenceLevel
	Key    string
	Value  map[string]any
	Actor  types.ActorRef
	Result *types.PreferenceRecord
}

PreferenceUpsertInput captures a preference mutation payload.

func (PreferenceUpsertInput) Type

Type implements gocommand.Message.

func (PreferenceUpsertInput) Validate

func (input PreferenceUpsertInput) Validate() error

Validate implements gocommand.Message.

type ProfileCommandConfig

type ProfileCommandConfig struct {
	Repository types.ProfileRepository
	Hooks      types.Hooks
	Clock      types.Clock
	ScopeGuard scope.Guard
}

ProfileCommandConfig wires dependencies for profile commands.

type ProfileUpsertCommand

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

ProfileUpsertCommand applies profile patches for a user.

func NewProfileUpsertCommand

func NewProfileUpsertCommand(cfg ProfileCommandConfig) *ProfileUpsertCommand

NewProfileUpsertCommand constructs the profile command handler.

func (*ProfileUpsertCommand) Execute

Execute applies the supplied patch creating the profile when necessary.

type ProfileUpsertInput

type ProfileUpsertInput struct {
	UserID uuid.UUID
	Patch  types.ProfilePatch
	Scope  types.ScopeFilter
	Actor  types.ActorRef
	Result *types.UserProfile
}

ProfileUpsertInput captures a profile patch request.

func (ProfileUpsertInput) Type

func (ProfileUpsertInput) Type() string

Type implements gocommand.Message.

func (ProfileUpsertInput) Validate

func (input ProfileUpsertInput) Validate() error

Validate implements gocommand.Message.

type UnassignRoleCommand

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

UnassignRoleCommand removes assignments.

func NewUnassignRoleCommand

func NewUnassignRoleCommand(registry types.RoleRegistry, guard scope.Guard) *UnassignRoleCommand

NewUnassignRoleCommand constructs the handler.

func (*UnassignRoleCommand) Execute

Execute removes the given assignment.

type UnassignRoleInput

type UnassignRoleInput struct {
	UserID uuid.UUID
	RoleID uuid.UUID
	Scope  types.ScopeFilter
	Actor  types.ActorRef
}

UnassignRoleInput removes a role assignment.

func (UnassignRoleInput) Type

func (UnassignRoleInput) Type() string

Type implements gocommand.Message.

func (UnassignRoleInput) Validate

func (input UnassignRoleInput) Validate() error

Validate implements gocommand.Message.

type UpdateRoleCommand

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

UpdateRoleCommand updates custom roles.

func NewUpdateRoleCommand

func NewUpdateRoleCommand(registry types.RoleRegistry, guard scope.Guard) *UpdateRoleCommand

NewUpdateRoleCommand constructs the command handler.

func (*UpdateRoleCommand) Execute

func (c *UpdateRoleCommand) Execute(ctx context.Context, input UpdateRoleInput) error

Execute forwards the update payload to the registry.

type UpdateRoleInput

type UpdateRoleInput struct {
	RoleID      uuid.UUID
	Name        string
	Order       int
	Description string
	RoleKey     string
	Permissions []string
	Metadata    map[string]any
	IsSystem    bool
	Scope       types.ScopeFilter
	Actor       types.ActorRef
	Result      *types.RoleDefinition
}

UpdateRoleInput captures mutable role fields.

func (UpdateRoleInput) Type

func (UpdateRoleInput) Type() string

Type implements gocommand.Message.

func (UpdateRoleInput) Validate

func (input UpdateRoleInput) Validate() error

Validate implements gocommand.Message.

type UserCreateCommand added in v0.6.0

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

UserCreateCommand creates active users directly.

func NewUserCreateCommand added in v0.6.0

func NewUserCreateCommand(cfg UserCreateCommandConfig) *UserCreateCommand

NewUserCreateCommand constructs the create handler.

func (*UserCreateCommand) Execute added in v0.6.0

func (c *UserCreateCommand) Execute(ctx context.Context, input UserCreateInput) error

Execute creates the user record and logs audit metadata.

type UserCreateCommandConfig added in v0.6.0

type UserCreateCommandConfig struct {
	Repository types.AuthRepository
	Clock      types.Clock
	Activity   types.ActivitySink
	Hooks      types.Hooks
	Logger     types.Logger
	ScopeGuard scope.Guard
}

UserCreateCommandConfig wires dependencies for the create command.

type UserCreateInput added in v0.6.0

type UserCreateInput struct {
	User   *types.AuthUser
	Status types.LifecycleState
	Actor  types.ActorRef
	Scope  types.ScopeFilter
	Result *types.AuthUser
}

UserCreateInput captures the payload for direct user creation.

func (UserCreateInput) Type added in v0.6.0

func (UserCreateInput) Type() string

Type implements gocommand.Message.

func (UserCreateInput) Validate added in v0.6.0

func (input UserCreateInput) Validate() error

Validate implements gocommand.Message.

type UserInviteCommand

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

UserInviteCommand creates pending users and records invite metadata.

func NewUserInviteCommand

func NewUserInviteCommand(cfg InviteCommandConfig) *UserInviteCommand

NewUserInviteCommand constructs the invite handler.

func (*UserInviteCommand) Execute

func (c *UserInviteCommand) Execute(ctx context.Context, input UserInviteInput) error

Execute creates the pending user record and registers invite metadata.

type UserInviteInput

type UserInviteInput struct {
	Email     string
	Username  string
	FirstName string
	LastName  string
	Role      string
	Metadata  map[string]any
	Actor     types.ActorRef
	Scope     types.ScopeFilter
	Result    *UserInviteResult
}

UserInviteInput carries the data required to invite a new user.

func (UserInviteInput) Type

func (UserInviteInput) Type() string

Type implements gocommand.Message.

func (UserInviteInput) Validate

func (input UserInviteInput) Validate() error

Validate implements gocommand.Message.

type UserInviteResult

type UserInviteResult struct {
	User      *types.AuthUser
	Token     string
	ExpiresAt time.Time
}

UserInviteResult exposes the creation output and invite token details.

type UserLifecycleTransitionCommand

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

UserLifecycleTransitionCommand implements go-command.Commander, enforcing the configured transition policy and logging hooks/audits.

func NewUserLifecycleTransitionCommand

func NewUserLifecycleTransitionCommand(cfg LifecycleCommandConfig) *UserLifecycleTransitionCommand

NewUserLifecycleTransitionCommand wires the lifecycle handler.

func (*UserLifecycleTransitionCommand) Execute

Execute performs the lifecycle transition against the upstream repository.

type UserLifecycleTransitionInput

type UserLifecycleTransitionInput struct {
	UserID   uuid.UUID
	Target   types.LifecycleState
	Actor    types.ActorRef
	Reason   string
	Metadata map[string]any
	Scope    types.ScopeFilter
	Result   *UserLifecycleTransitionResult
}

UserLifecycleTransitionInput describes the lifecycle mutation request.

func (UserLifecycleTransitionInput) Describe

Describe returns a human readable description of the command for debugging.

func (UserLifecycleTransitionInput) Type

Type implements gocommand.Message.

func (UserLifecycleTransitionInput) Validate

func (input UserLifecycleTransitionInput) Validate() error

Validate implements gocommand.Message.

type UserLifecycleTransitionResult

type UserLifecycleTransitionResult struct {
	User *types.AuthUser
}

UserLifecycleTransitionResult carries the updated auth user.

type UserPasswordResetCommand

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

UserPasswordResetCommand wraps the AuthRepository password reset helper.

func NewUserPasswordResetCommand

func NewUserPasswordResetCommand(cfg PasswordResetCommandConfig) *UserPasswordResetCommand

NewUserPasswordResetCommand builds the handler.

func (*UserPasswordResetCommand) Execute

Execute resets the user's password hash and logs audit metadata.

type UserPasswordResetInput

type UserPasswordResetInput struct {
	UserID          uuid.UUID
	NewPasswordHash string
	Actor           types.ActorRef
	Scope           types.ScopeFilter
	Result          *UserPasswordResetResult
}

UserPasswordResetInput resets a user's password hash.

func (UserPasswordResetInput) Type

Type implements gocommand.Message.

func (UserPasswordResetInput) Validate

func (input UserPasswordResetInput) Validate() error

Validate implements gocommand.Message.

type UserPasswordResetResult

type UserPasswordResetResult struct {
	User *types.AuthUser
}

UserPasswordResetResult surfaces auditing metadata.

type UserUpdateCommand added in v0.6.0

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

UserUpdateCommand updates existing users while enforcing scopes.

func NewUserUpdateCommand added in v0.6.0

func NewUserUpdateCommand(cfg UserUpdateCommandConfig) *UserUpdateCommand

NewUserUpdateCommand constructs the update handler.

func (*UserUpdateCommand) Execute added in v0.6.0

func (c *UserUpdateCommand) Execute(ctx context.Context, input UserUpdateInput) error

Execute updates the user record and logs audit metadata.

type UserUpdateCommandConfig added in v0.6.0

type UserUpdateCommandConfig struct {
	Repository types.AuthRepository
	Policy     types.TransitionPolicy
	Clock      types.Clock
	Activity   types.ActivitySink
	Hooks      types.Hooks
	Logger     types.Logger
	ScopeGuard scope.Guard
}

UserUpdateCommandConfig wires dependencies for the update command.

type UserUpdateInput added in v0.6.0

type UserUpdateInput struct {
	User   *types.AuthUser
	Actor  types.ActorRef
	Scope  types.ScopeFilter
	Result *types.AuthUser
}

UserUpdateInput captures the payload for user updates.

func (UserUpdateInput) Type added in v0.6.0

func (UserUpdateInput) Type() string

Type implements gocommand.Message.

func (UserUpdateInput) Validate added in v0.6.0

func (input UserUpdateInput) Validate() error

Validate implements gocommand.Message.

Jump to

Keyboard shortcuts

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