Lifecycle Events
Sentinel lifecycle methods and the public event surface
Lifecycle Events
Core lifecycle
Create a Sentinel instance, then use its lifecycle methods:
import { TPSentinel } from '@testpress/sentinel-core'
const sentinel = TPSentinel.create(config)
sentinel.getState()
sentinel.getPendingUserAction()
await sentinel.prepare()
await sentinel.resolveUserAction(payload)
await sentinel.start()
await sentinel.pause()
await sentinel.resume()
await sentinel.stop()
await sentinel.destroy()The Sentinel instance moves through these public session states:
createdpreparingawaiting_user_actionreadystartingrunningpausedstoppedfaileddestroyed
Use sentinel.getState() to read the current state.
Observing state changes
const unsubscribe = sentinel.onStateChanged(state => {
console.log('Sentinel state:', state)
})
unsubscribe()Pending user actions
During prepare(), Sentinel can move to awaiting_user_action. Read the pending
action and pass the user's response back to the SDK before continuing:
const action = sentinel.getPendingUserAction()
if (action) {
await sentinel.resolveUserAction(payload)
}Calling resolveUserAction(...) when there is no pending user action throws a
TPSentinelError.
Subscribing to events
Use on and off to manage event handlers directly:
const handler = payload => {
console.log(payload)
}
sentinel.on('anomaly:detected', handler)
sentinel.off('anomaly:detected', handler)Public event categories
Runtime events
runtime:failed
Preparation events
preparing:startedpreparing:fetching-policypreparing:check-startedpreparing:check-passedpreparing:check-failedpreparing:awaiting-permissionspreparing:validating-permissionspreparing:permission-validation-failedpreparing:completedpreparing:failed
Identity events
preparing:identity-startedpreparing:identity-capturingpreparing:identity-capture-failedpreparing:identity-verifyingpreparing:identity-verifiedpreparing:identity-rejectedpreparing:identity-failed
Anomaly events
anomaly:detectedanomaly:confirmedanomaly:clearedanomaly:resolved
sentinel.on('preparing:completed', event => {
console.log(event)
})
sentinel.on('runtime:failed', error => {
console.error(error)
})
sentinel.on('anomaly:confirmed', anomaly => {
console.log(anomaly)
})When to listen
- Use
onStateChanged(...)for overall lifecycle changes - Listen to preparation events if you are building a custom UI on top of
@testpress/sentinel-core - Listen to anomaly events if you want to surface warnings or audit activity in your own application
Error behavior
prepare(), start(), and resolveUserAction(...) can throw a TPSentinelError.
Handle these calls with try...catch when you need to show an error or perform
application-specific cleanup.
try {
await sentinel.prepare()
await sentinel.start()
} catch (error) {
console.error('Sentinel failed:', error)
}