Skip to content

Hooks API Reference

Hooks allow you to subscribe to various events in the flow lifecycle.

FlowHooks<TInput>

ts
type FlowHooks<TInput> = {
  onFlowStart?: (event: FlowStartEvent<TInput>) => void | Promise<void>;
  onFlowComplete?: (event: FlowCompleteEvent<TInput>) => void | Promise<void>;
  onFlowFail?: (event: FlowFailEvent<TInput>) => void | Promise<void>;

  onStepStart?: (event: StepStartEvent<TInput>) => void | Promise<void>;
  onStepComplete?: (event: StepCompleteEvent<TInput>) => void | Promise<void>;
  onStepFail?: (event: StepFailEvent<TInput>) => void | Promise<void>;

  onCompensate?: (event: CompensateEvent<TInput>) => void | Promise<void>;
  onCompensateComplete?: (event: CompensateCompleteEvent<TInput>) => void | Promise<void>;
};

Event Objects

All hook events share some common properties:

  • flowName: string
  • input: TInput
  • context: FlowContext<TInput>

FlowCompleteEvent

Adds:

  • result: FlowResult

StepStartEvent

Adds:

  • stepName: string

StepCompleteEvent

Adds:

  • stepName: string
  • result: StepResult

StepFailEvent

Adds:

  • stepName: string
  • error: StepResult

CompensateEvent

Adds:

  • stepName: string
  • error: unknown (the error that triggered the compensation)

Released under the MIT License.