A lifecycle a step hook returned, which decides what happens next, as the hook_called event records it. A hook that keeps the default returns no lifecycle.
hook_called
import assert from "node:assert/strict";import type { Lifecycle } from "itinera/policy";function ends(lifecycle: Lifecycle | undefined): string { switch (lifecycle?.kind) { case undefined: return "kept the default"; case "FinishWorkflow": return "finished the journey"; case "FailWorkflow": return `failed the journey: ${lifecycle.reason.code}`; }}assert.equal(ends(undefined), "kept the default");assert.equal(ends({ kind: "FinishWorkflow" }), "finished the journey");assert.equal( ends({ kind: "FailWorkflow", reason: { code: "fraud" } }), "failed the journey: fraud",); Copy
import assert from "node:assert/strict";import type { Lifecycle } from "itinera/policy";function ends(lifecycle: Lifecycle | undefined): string { switch (lifecycle?.kind) { case undefined: return "kept the default"; case "FinishWorkflow": return "finished the journey"; case "FailWorkflow": return `failed the journey: ${lifecycle.reason.code}`; }}assert.equal(ends(undefined), "kept the default");assert.equal(ends({ kind: "FinishWorkflow" }), "finished the journey");assert.equal( ends({ kind: "FailWorkflow", reason: { code: "fraud" } }), "failed the journey: fraud",);
A lifecycle a step hook returned, which decides what happens next, as the
hook_calledevent records it. A hook that keeps the default returns no lifecycle.