flows

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFlow

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

BaseFlow provides a basic implementation of the Flow interface.

func NewBaseFlow

func NewBaseFlow(id, name string) *BaseFlow

NewBaseFlow creates a new base flow.

func (*BaseFlow) AddAfterHook

func (f *BaseFlow) AddAfterHook(stepID string, hook HookFunc) Flow

AddAfterHook adds a hook to run after a specific step.

func (*BaseFlow) AddBeforeHook

func (f *BaseFlow) AddBeforeHook(stepID string, hook HookFunc) Flow

AddBeforeHook adds a hook to run before a specific step.

func (*BaseFlow) AddStep

func (f *BaseFlow) AddStep(step *Step) Flow

AddStep adds a step to the flow.

func (*BaseFlow) Execute

func (f *BaseFlow) Execute(ctx context.Context, data map[string]any) (*FlowResult, error)

Execute runs the flow with the given context and data.

func (*BaseFlow) ID

func (f *BaseFlow) ID() string

ID returns the flow ID.

func (*BaseFlow) Name

func (f *BaseFlow) Name() string

Name returns the flow name.

func (*BaseFlow) Steps

func (f *BaseFlow) Steps() []*Step

Steps returns all steps in the flow.

type Flow

type Flow interface {
	// ID returns the unique identifier for this flow
	ID() string

	// Name returns the human-readable name for this flow
	Name() string

	// Execute runs the flow with the given context and data
	Execute(ctx context.Context, data map[string]any) (*FlowResult, error)

	// Steps returns all steps in this flow
	Steps() []*Step

	// AddStep adds a step to the flow
	AddStep(step *Step) Flow

	// AddBeforeHook adds a hook to run before a specific step
	AddBeforeHook(stepID string, hook HookFunc) Flow

	// AddAfterHook adds a hook to run after a specific step
	AddAfterHook(stepID string, hook HookFunc) Flow
}

Flow represents a customizable authentication flow.

func CreateSignupFlow

func CreateSignupFlow(userService *user.Service, sessionService *session.Service) Flow

CreateSignupFlow creates a customizable signup flow with hooks.

type FlowBuilder

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

FlowBuilder provides a fluent interface for building flows.

func NewFlowBuilder

func NewFlowBuilder(id, name string) *FlowBuilder

NewFlowBuilder creates a new flow builder.

func (*FlowBuilder) After

func (b *FlowBuilder) After(stepID string, hook HookFunc) *FlowBuilder

After adds an after hook for the specified step.

func (*FlowBuilder) Before

func (b *FlowBuilder) Before(stepID string, hook HookFunc) *FlowBuilder

Before adds a before hook for the specified step.

func (*FlowBuilder) Build

func (b *FlowBuilder) Build() Flow

Build returns the constructed flow.

func (*FlowBuilder) Step

func (b *FlowBuilder) Step(id, name, stepType string, required bool, config map[string]any, handler StepHandler) *FlowBuilder

Step adds a step to the flow being built.

type FlowContext

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

FlowContext provides execution context for flows with state management.

func NewFlowContext

func NewFlowContext(ctx context.Context, flowID string) *FlowContext

NewFlowContext creates a new flow context.

func (*FlowContext) AddError

func (fc *FlowContext) AddError(err string)

AddError adds an error to the context.

func (*FlowContext) ClearErrors

func (fc *FlowContext) ClearErrors()

ClearErrors removes all errors.

func (*FlowContext) Clone

func (fc *FlowContext) Clone() *FlowContext

Clone creates a copy of the flow context.

func (*FlowContext) Context

func (fc *FlowContext) Context() context.Context

Context returns the underlying context.Context.

func (*FlowContext) CurrentStep

func (fc *FlowContext) CurrentStep() string

CurrentStep returns the current step ID.

func (*FlowContext) Duration

func (fc *FlowContext) Duration() time.Duration

Duration returns how long the flow has been running.

func (*FlowContext) FlowID

func (fc *FlowContext) FlowID() string

FlowID returns the flow ID.

func (*FlowContext) Get

func (fc *FlowContext) Get(key string) (any, bool)

Get retrieves a value from the flow data.

func (*FlowContext) GetBool

func (fc *FlowContext) GetBool(key string) bool

GetBool retrieves a boolean value from the flow data.

func (*FlowContext) GetData

func (fc *FlowContext) GetData() map[string]any

GetData returns a copy of all flow data.

func (*FlowContext) GetErrors

func (fc *FlowContext) GetErrors() []string

GetErrors returns all errors.

func (*FlowContext) GetInt

func (fc *FlowContext) GetInt(key string) int

GetInt retrieves an integer value from the flow data.

func (*FlowContext) GetMetadata

func (fc *FlowContext) GetMetadata(key string) (any, bool)

GetMetadata retrieves a metadata value.

func (*FlowContext) GetString

func (fc *FlowContext) GetString(key string) string

GetString retrieves a string value from the flow data.

func (*FlowContext) HasErrors

func (fc *FlowContext) HasErrors() bool

HasErrors returns true if there are any errors.

func (*FlowContext) MergeData

func (fc *FlowContext) MergeData(data map[string]any)

MergeData merges new data into existing flow data.

func (*FlowContext) OrgID

func (fc *FlowContext) OrgID() string

OrgID returns the organization ID.

func (*FlowContext) SessionID

func (fc *FlowContext) SessionID() string

SessionID returns the session ID.

func (*FlowContext) Set

func (fc *FlowContext) Set(key string, value any)

Set stores a value in the flow data.

func (*FlowContext) SetCurrentStep

func (fc *FlowContext) SetCurrentStep(stepID string)

SetCurrentStep sets the current step ID.

func (*FlowContext) SetData

func (fc *FlowContext) SetData(data map[string]any)

SetData replaces all flow data.

func (*FlowContext) SetMetadata

func (fc *FlowContext) SetMetadata(key string, value any)

SetMetadata stores a metadata value.

func (*FlowContext) SetOrgID

func (fc *FlowContext) SetOrgID(orgID string)

SetOrgID sets the organization ID.

func (*FlowContext) SetSessionID

func (fc *FlowContext) SetSessionID(sessionID string)

SetSessionID sets the session ID.

func (*FlowContext) SetUserID

func (fc *FlowContext) SetUserID(userID string)

SetUserID sets the user ID.

func (*FlowContext) StartTime

func (fc *FlowContext) StartTime() time.Time

StartTime returns when the flow context was created.

func (*FlowContext) UserID

func (fc *FlowContext) UserID() string

UserID returns the user ID.

type FlowResult

type FlowResult struct {
	Success   bool           `json:"success"`
	Data      map[string]any `json:"data"`
	Errors    []string       `json:"errors,omitempty"`
	NextStep  string         `json:"next_step,omitempty"`
	Completed bool           `json:"completed"`
}

FlowResult represents the result of executing a flow.

type HookFunc

type HookFunc func(ctx context.Context, step *Step, data map[string]any) error

HookFunc defines the function signature for before/after hooks.

type Registry

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

Registry manages all available flows in the system.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new flow registry.

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all flows from the registry.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered flows.

func (*Registry) Exists

func (r *Registry) Exists(id string) bool

Exists checks if a flow with the given ID exists.

func (*Registry) Get

func (r *Registry) Get(id string) (Flow, error)

Get retrieves a flow by its ID.

func (*Registry) List

func (r *Registry) List() []Flow

List returns all registered flows.

func (*Registry) ListIDs

func (r *Registry) ListIDs() []string

ListIDs returns all registered flow IDs.

func (*Registry) Register

func (r *Registry) Register(flow Flow) error

Register registers a new flow in the registry.

func (*Registry) Unregister

func (r *Registry) Unregister(id string) error

Unregister removes a flow from the registry.

type SignupFlow

type SignupFlow struct {
	*BaseFlow
	// contains filtered or unexported fields
}

SignupFlow implements the user registration flow.

func NewSignupFlow

func NewSignupFlow(userService *user.Service, sessionService *session.Service) *SignupFlow

NewSignupFlow creates a new signup flow.

type Step

type Step struct {
	ID          string         `json:"id"`
	Name        string         `json:"name"`
	Type        string         `json:"type"`
	Required    bool           `json:"required"`
	Config      map[string]any `json:"config"`
	BeforeHooks []HookFunc     `json:"-"`
	AfterHooks  []HookFunc     `json:"-"`
	Handler     StepHandler    `json:"-"`
}

Step represents a single step in an authentication flow.

type StepHandler

type StepHandler func(ctx context.Context, step *Step, data map[string]any) (*StepResult, error)

StepHandler defines the function signature for step handlers.

type StepResult

type StepResult struct {
	Success bool           `json:"success"`
	Data    map[string]any `json:"data"`
	Error   string         `json:"error,omitempty"`
	Skip    bool           `json:"skip"`
	Stop    bool           `json:"stop"`
}

StepResult represents the result of executing a single step.

Jump to

Keyboard shortcuts

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