Entitlements

class Entitlements(val storage: Storage, actorScope: CoroutineScope = CoroutineScope(Dispatchers.Default), val actor: StateActor<EntitlementsContext, EntitlementsState> = StateActor(createInitialEntitlementsState(storage), actorScope), val tracker: suspend (TrackableSuperwallEvent) -> Unit = {}) : EntitlementsContext(source)

Facade over the entitlements state held in a StateActor.

Implements EntitlementsContext directly — actions receive this as their context, eliminating the intermediate object.

State mutations use StateActor.update (synchronous CAS, routed through interceptors) and are persisted immediately through persist. The initial state is rebuilt from storage by createInitialEntitlementsState before the actor starts, so cached status, product entitlements and web entitlements are available synchronously after construction.

Constructors

Link copied to clipboard
constructor(storage: Storage, actorScope: CoroutineScope = CoroutineScope(Dispatchers.Default), actor: StateActor<EntitlementsContext, EntitlementsState> = StateActor(createInitialEntitlementsState(storage), actorScope), tracker: suspend (TrackableSuperwallEvent) -> Unit = {})

Properties

Link copied to clipboard

The active entitlements. Uses mergeEntitlementsPrioritized to deduplicate entitlements by ID, keeping the highest priority version of each and merging productIds.

Link copied to clipboard
Link copied to clipboard

All entitlements, regardless of whether they're active or not. Includes web entitlements from the latest redemption response.

Link copied to clipboard

Returns a snapshot of all entitlements by product ID. Used when loading purchases to enrich entitlements with transaction data.

Link copied to clipboard

The inactive entitlements.

Link copied to clipboard
open override val scope: CoroutineScope
Link copied to clipboard
open override val state: StateFlow<EntitlementsState>

Delegate state reads to the actor.

Link copied to clipboard
val status: StateFlow<SubscriptionStatus>

A StateFlow of the entitlement status of the user. Set this using Superwall.instance.setEntitlementStatus.

Link copied to clipboard
open override val storage: Storage
Link copied to clipboard
open override val tracker: suspend (TrackableSuperwallEvent) -> Unit
Link copied to clipboard

Active web entitlements from the latest redemption response. Updated by WebPaywallRedeemer through setWebEntitlements.

Functions

Link copied to clipboard

Returns a Set of Entitlements belonging to given product IDs.

Link copied to clipboard
open fun delete(storable: Storable<*>)

Delete a value from storage.

Link copied to clipboard

Fire-and-forget dispatch of a sub-action on this context's actor.

Link copied to clipboard
open suspend fun immediate(action: TypedAction<EntitlementsContext>)
Link copied to clipboard
Link copied to clipboard
open fun <T : Any> persist(storable: Storable<T>, value: T)

Persist a value to storage.

Link copied to clipboard
open fun <T : Any> read(storable: Storable<T>): Result<T>
Link copied to clipboard

Sets the entitlement status and updates the corresponding entitlement collections.

Link copied to clipboard
open fun sideEffect(what: suspend () -> Unit)
Link copied to clipboard
open fun track(event: TrackableSuperwallEvent)
Link copied to clipboard
open override fun update(reducer: Reducer<EntitlementsState>)

Apply a state reducer inline.