flowpilot

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorTechnical             = NewFlowError("technical_error", "Something went wrong.", http.StatusInternalServerError)
	ErrorFlowExpired           = NewFlowError("flow_expired_error", "The flow has expired.", http.StatusGone)
	ErrorFlowDiscontinuity     = NewFlowError("flow_discontinuity_error", "The flow can't be continued.", http.StatusInternalServerError)
	ErrorOperationNotPermitted = NewFlowError("operation_not_permitted_error", "The operation is not permitted.", http.StatusForbidden)
	ErrorFormDataInvalid       = NewFlowError("form_data_invalid_error", "Form data invalid.", http.StatusBadRequest)
)

Predefined flow error types

View Source
var (
	ErrorValueMissing  = NewInputError("value_missing_error", "The value is missing.")
	ErrorValueInvalid  = NewInputError("value_invalid_error", "The value is invalid.")
	ErrorValueTooLong  = NewInputError("value_too_long_error", "The value is too long.")
	ErrorValueTooShort = NewInputError("value_too_short_error", "The value is too short.")
)

Predefined input error types

Functions

func UseCompression

func UseCompression(b bool) func(*defaultFlow)

UseCompression causes the flow data to be compressed before stored to the db.

func WithInputData

func WithInputData(inputData InputData) func(*defaultFlow)

WithInputData sets the InputData for flowExecutionOptions.

func WithQueryParamKey

func WithQueryParamKey(key string) func(*defaultFlow)

WithQueryParamKey sets the ActionName for flowExecutionOptions.

func WithQueryParamValue

func WithQueryParamValue(value string) func(*defaultFlow)

WithQueryParamValue sets the ActionName for flowExecutionOptions.

Types

type Action

type Action interface {
	GetName() ActionName              // Get the action name.
	GetDescription() string           // Get the action description.
	Initialize(InitializationContext) // Initialize the action.
	Execute(ExecutionContext) error   // Execute the action.
}

Action defines the interface for flow actions.

type ActionName

type ActionName string

ActionName represents the name of an action.

type Actions

type Actions []Action

Actions represents a list of Action

type BeforeEachActionExecutionContext

type BeforeEachActionExecutionContext interface {
	// contains filtered or unexported methods
}

type Context

type Context interface {
	// contains filtered or unexported methods
}

type ExecutionContext

type ExecutionContext interface {
	// contains filtered or unexported methods
}

ExecutionContext is a shorthand for actionExecutionContinuationContext within flow execution method.

type Flow

type Flow interface {
	// Execute executes the flow using the provided FlowDB and options.
	// It returns the result of the flow execution and an error if any.
	Execute(db FlowDB, opts ...func(*defaultFlow)) (FlowResult, error)
	// ResultFromError converts an error into a FlowResult.
	ResultFromError(err error) FlowResult
	// Set sets a value with the given key in the flow context.
	Set(string, interface{})
	// contains filtered or unexported methods
}

Flow represents a flow.

type FlowBuilder

type FlowBuilder interface {
	TTL(ttl time.Duration) FlowBuilder
	State(stateName StateName, actions ...Action) FlowBuilder
	InitialState(stateNames ...StateName) FlowBuilder
	ErrorState(stateName StateName) FlowBuilder
	BeforeState(stateName StateName, hooks ...HookAction) FlowBuilder
	AfterState(stateName StateName, hooks ...HookAction) FlowBuilder
	AfterFlow(flowName FlowName, hooks ...HookAction) FlowBuilder
	Debug(enabled bool) FlowBuilder
	SubFlows(subFlows ...subFlow) FlowBuilder
	Build() (Flow, error)
	MustBuild() Flow
	BeforeEachAction(hooks ...HookAction) FlowBuilder
	AfterEachAction(hooks ...HookAction) FlowBuilder
}

func NewFlow

func NewFlow(name FlowName) FlowBuilder

NewFlow creates a new defaultFlowBuilder that builds a new flow available under the specified path.

type FlowDB

type FlowDB interface {
	GetFlow(flowID uuid.UUID) (*FlowModel, error)
	CreateFlow(flowModel FlowModel) error
	UpdateFlow(flowModel FlowModel) error
}

FlowDB is the interface for interacting with the flow database.

type FlowError

type FlowError interface {
	Wrap(error) FlowError
	Status() int
	// contains filtered or unexported methods
}

FlowError is an interface representing flow-related errors.

func NewFlowError

func NewFlowError(code, message string, status int) FlowError

NewFlowError creates a new FlowError instance.

type FlowModel

type FlowModel struct {
	ID        uuid.UUID // Unique ID of the flow.
	Data      string    // Stash data associated with the flow.
	CSRFToken string    // Current CSRF token
	Version   int       // Version of the flow.
	ExpiresAt time.Time // Expiry time of the flow.
	CreatedAt time.Time // Creation time of the flow.
	UpdatedAt time.Time // Update time of the flow.
}

FlowModel represents the database model for a flow.

type FlowName

type FlowName string

FlowName represents the name of the flow.

type FlowResult

type FlowResult interface {
	GetResponse() Response
	GetStatus() int
}

FlowResult interface defines methods for obtaining response and status.

type HookAction

type HookAction interface {
	Execute(HookExecutionContext) error
}

HookAction defines the interface for a hook action.

type HookExecutionContext

type HookExecutionContext interface {
	GetFlowError() FlowError
	AddLink(...Link)
	ScheduleStates(...StateName)
	// contains filtered or unexported methods
}

type InitializationContext

type InitializationContext interface {
	// contains filtered or unexported methods
}

InitializationContext is a shorthand for actionInitializationContext within the flow initialization method.

type Input

type Input interface {
	MinLength(minLength int) Input
	MaxLength(maxLength int) Input
	Required(b bool) Input
	Hidden(b bool) Input
	Preserve(b bool) Input
	AllowedValue(name string, value interface{}) Input
	TrimSpace(b bool) Input
	LowerCase(b bool) Input
	// contains filtered or unexported methods
}

Input defines the interface for input fields.

func BooleanInput

func BooleanInput(name string) Input

BooleanInput creates a new input field of boolean type.

func EmailInput

func EmailInput(name string) Input

EmailInput creates a new input field of email type.

func JSONInput

func JSONInput(name string) Input

JSONInput creates a new input field of JSON type.

func NumberInput

func NumberInput(name string) Input

NumberInput creates a new input field of number type.

func PasswordInput

func PasswordInput(name string) Input

PasswordInput creates a new input field of password type.

func StringInput

func StringInput(name string) Input

StringInput creates a new input field of string type.

type InputData

type InputData struct {
	InputDataMap map[string]interface{} `json:"input_data"`
	CSRFToken    string                 `json:"csrf_token"`
}

InputData holds input data in JSON format.

type InputError

type InputError interface {
	Wrap(error) InputError
	// contains filtered or unexported methods
}

InputError is an interface representing input-related errors.

func NewInputError

func NewInputError(code, message string) InputError

NewInputError creates a new InputError instance.

type Link interface {
	Target(LinkTarget) Link
	// contains filtered or unexported methods
}

Link defines the interface for links.

func NewLink(name string, category LinkCategory, href string) Link

NewLink creates a new defaultLink instance with provided parameters.

type LinkCategory

type LinkCategory string

LinkCategory represents the category of the link.

type LinkTarget

type LinkTarget string

LinkTarget represents the html target attribute.

const (
	LinkTargetSelf   LinkTarget = "_self"
	LinkTargetBlank  LinkTarget = "_blank"
	LinkTargetParent LinkTarget = "_parent"
	LinkTargetTop    LinkTarget = "_top"
)

Link targets enumeration.

type Response

type Response struct {
	Name      StateName       `json:"name"`
	Status    int             `json:"status"`
	Payload   interface{}     `json:"payload,omitempty"`
	CSRFToken string          `json:"csrf_token"`
	Actions   ResponseActions `json:"actions"`
	Error     *ResponseError  `json:"error,omitempty"`
	Links     ResponseLinks   `json:"links"`
}

Response represents the response of an action execution.

type ResponseAction

type ResponseAction struct {
	Href        string         `json:"href"`
	Inputs      ResponseInputs `json:"inputs"`
	Name        ActionName     `json:"action"`
	Description string         `json:"description"`
}

ResponseAction represents a link to an action.

type ResponseActions

type ResponseActions map[ActionName]ResponseAction

ResponseActions is a collection of ResponseAction instances.

type ResponseAllowedValue

type ResponseAllowedValue struct {
	Value interface{} `json:"value"`
	Text  string      `json:"name"`
}

type ResponseAllowedValues

type ResponseAllowedValues []*ResponseAllowedValue

type ResponseError

type ResponseError struct {
	Code     string  `json:"code"`
	Message  string  `json:"message"`
	Cause    *string `json:"cause,omitempty"`
	Internal *string `json:"-"`
}

ResponseError represents an error for public exposure.

type ResponseInput

type ResponseInput struct {
	Name          string                 `json:"name"`
	Type          inputType              `json:"type"`
	Value         interface{}            `json:"value,omitempty"`
	MinLength     *int                   `json:"min_length,omitempty"`
	MaxLength     *int                   `json:"max_length,omitempty"`
	Required      *bool                  `json:"required,omitempty"`
	Hidden        *bool                  `json:"hidden,omitempty"`
	Error         *ResponseError         `json:"error,omitempty"`
	AllowedValues *ResponseAllowedValues `json:"allowed_values,omitempty"`
}

ResponseInput represents an input field for public exposure.

type ResponseInputs

type ResponseInputs map[string]*ResponseInput

ResponseInputs represents a collection of ResponseInput instances.

type ResponseLink struct {
	Name     string       `json:"name"` // tos, privacy, google, apple, microsoft, login, registration ... // how can we insert custom oauth provider here
	Href     string       `json:"href"`
	Category LinkCategory `json:"category"` // oauth, legal, other, ...
	Target   LinkTarget   `json:"target"`   // can be used to add the target of the a-tag e.g. _blank
}

ResponseLink represents a link for public exposure.

type ResponseLinks []ResponseLink

ResponseLinks is a collection of Link instances.

type StateName

type StateName string

StateName represents the name of a state in a flow.

type SubFlowBuilder

type SubFlowBuilder interface {
	State(stateName StateName, actions ...Action) SubFlowBuilder
	BeforeState(stateName StateName, hooks ...HookAction) SubFlowBuilder
	AfterState(stateName StateName, hooks ...HookAction) SubFlowBuilder
	SubFlows(subFlows ...subFlow) SubFlowBuilder
	Build() (subFlow, error)
	MustBuild() subFlow
}

func NewSubFlow

func NewSubFlow(name FlowName) SubFlowBuilder

NewSubFlow creates a new SubFlowBuilder.

type SubFlows

type SubFlows []subFlow

SubFlows represents a list of SubFlow interfaces.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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