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 ¶
- Variables
- type ActivityLogCommand
- type ActivityLogConfig
- type ActivityLogInput
- type AssignRoleCommand
- type AssignRoleInput
- type BulkUserTransitionCommand
- type BulkUserTransitionInput
- type BulkUserTransitionResult
- type CreateRoleCommand
- type CreateRoleInput
- type DeleteRoleCommand
- type DeleteRoleInput
- type InviteCommandConfig
- type LifecycleCommandConfig
- type PasswordResetCommandConfig
- type PreferenceCommandConfig
- type PreferenceDeleteCommand
- type PreferenceDeleteInput
- type PreferenceUpsertCommand
- type PreferenceUpsertInput
- type ProfileCommandConfig
- type ProfileUpsertCommand
- type ProfileUpsertInput
- type UnassignRoleCommand
- type UnassignRoleInput
- type UpdateRoleCommand
- type UpdateRoleInput
- type UserInviteCommand
- type UserInviteInput
- type UserInviteResult
- type UserLifecycleTransitionCommand
- type UserLifecycleTransitionInput
- type UserLifecycleTransitionResult
- type UserPasswordResetCommand
- type UserPasswordResetInput
- type UserPasswordResetResult
Constants ¶
This section is empty.
Variables ¶
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 // 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") // 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 ¶
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 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 ¶
func (c *BulkUserTransitionCommand) Execute(ctx context.Context, input BulkUserTransitionInput) error
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 ¶
func (BulkUserTransitionInput) Type() string
Type implements gocommand.Message.
func (BulkUserTransitionInput) Validate ¶
func (input BulkUserTransitionInput) Validate() error
Validate implements gocommand.Message.
type BulkUserTransitionResult ¶
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
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 ¶
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 ¶
func (c *PreferenceDeleteCommand) Execute(ctx context.Context, input PreferenceDeleteInput) error
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 ¶
func (PreferenceDeleteInput) Type() string
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 ¶
func (c *PreferenceUpsertCommand) Execute(ctx context.Context, input PreferenceUpsertInput) error
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 ¶
func (PreferenceUpsertInput) Type() string
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 ¶
func (c *ProfileUpsertCommand) Execute(ctx context.Context, input ProfileUpsertInput) error
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 ¶
func (c *UnassignRoleCommand) Execute(ctx context.Context, input UnassignRoleInput) error
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
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 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
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 ¶
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 ¶
func (c *UserLifecycleTransitionCommand) Execute(ctx context.Context, input UserLifecycleTransitionInput) error
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 ¶
func (UserLifecycleTransitionInput) Describe() string
Describe returns a human readable description of the command for debugging.
func (UserLifecycleTransitionInput) Type ¶
func (UserLifecycleTransitionInput) Type() string
Type implements gocommand.Message.
func (UserLifecycleTransitionInput) Validate ¶
func (input UserLifecycleTransitionInput) Validate() error
Validate implements gocommand.Message.
type UserLifecycleTransitionResult ¶
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 ¶
func (c *UserPasswordResetCommand) Execute(ctx context.Context, input UserPasswordResetInput) error
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 ¶
func (UserPasswordResetInput) Type() string
Type implements gocommand.Message.
func (UserPasswordResetInput) Validate ¶
func (input UserPasswordResetInput) Validate() error
Validate implements gocommand.Message.
type UserPasswordResetResult ¶
UserPasswordResetResult surfaces auditing metadata.