TPSentinel LogoTPSentinel

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:

  • created
  • preparing
  • awaiting_user_action
  • ready
  • starting
  • running
  • paused
  • stopped
  • failed
  • destroyed

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:started
  • preparing:fetching-policy
  • preparing:check-started
  • preparing:check-passed
  • preparing:check-failed
  • preparing:awaiting-permissions
  • preparing:validating-permissions
  • preparing:permission-validation-failed
  • preparing:completed
  • preparing:failed

Identity events

  • preparing:identity-started
  • preparing:identity-capturing
  • preparing:identity-capture-failed
  • preparing:identity-verifying
  • preparing:identity-verified
  • preparing:identity-rejected
  • preparing:identity-failed

Anomaly events

  • anomaly:detected
  • anomaly:confirmed
  • anomaly:cleared
  • anomaly: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)
}

On this page