Files
hanko/backend/flowpilot/builder_subflow.go
bjoern-m 601ffaae92 Introduce Flowpilot - integration (#1532)
This pull request introduces the new Flowpilot system along with several new features and various improvements. The key enhancements include configurable authorization, registration, and profile flows, as well as the ability to enable and disable user identifiers (e.g., email addresses and usernames) and login methods.

---------

Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io>
Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io>
Co-authored-by: lfleischmann <67686424+lfleischmann@users.noreply.github.com>
Co-authored-by: merlindru <hello@merlindru.com>
2024-08-06 16:07:29 +02:00

67 lines
1.8 KiB
Go

package flowpilot
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
}
// defaultFlowBuilder is a builder struct for creating a new subFlow.
type defaultSubFlowBuilder struct {
defaultFlowBuilderBase
}
// NewSubFlow creates a new SubFlowBuilder.
func NewSubFlow(name FlowName) SubFlowBuilder {
fbBase := newFlowBuilderBase(name)
return &defaultSubFlowBuilder{defaultFlowBuilderBase: fbBase}
}
func (sfb *defaultSubFlowBuilder) SubFlows(subFlows ...subFlow) SubFlowBuilder {
sfb.addSubFlows(subFlows...)
return sfb
}
// State adds a new state to the flow.
func (sfb *defaultSubFlowBuilder) State(stateName StateName, actions ...Action) SubFlowBuilder {
sfb.addState(stateName, actions...)
return sfb
}
func (sfb *defaultSubFlowBuilder) BeforeState(stateName StateName, hooks ...HookAction) SubFlowBuilder {
sfb.addBeforeStateHooks(stateName, hooks...)
return sfb
}
func (sfb *defaultSubFlowBuilder) AfterState(stateName StateName, hooks ...HookAction) SubFlowBuilder {
sfb.addAfterStateHooks(stateName, hooks...)
return sfb
}
// Build constructs and returns the subFlow object.
func (sfb *defaultSubFlowBuilder) Build() (subFlow, error) {
f := defaultFlowBase{
name: sfb.name,
flow: sfb.flow,
subFlows: sfb.subFlows,
beforeStateHooks: sfb.beforeStateHooks,
afterStateHooks: sfb.afterStateHooks,
}
return &f, nil
}
// MustBuild constructs and returns the subFlow object, panics on error.
func (sfb *defaultSubFlowBuilder) MustBuild() subFlow {
sf, err := sfb.Build()
if err != nil {
panic(err)
}
return sf
}