@pwngh/economy-lab
    Preparing search index...

    Interface EntitlementStore

    Tracks which users own which items or features (entitlements), keyed by SKU (the product code).

    interface EntitlementStore {
        grant(
            userId: string,
            sku: string,
            attrs: EntitlementAttributes,
            options?: CallOptions,
        ): Promise<void>;
        list(
            userId: string,
            options?: CallOptions,
        ): AsyncIterable<EntitlementGrant>;
        owns(userId: string, sku: string, options?: CallOptions): Promise<boolean>;
        revoke(userId: string, sku: string, options?: CallOptions): Promise<void>;
    }
    Index
    • Upserts (userId, sku): re-granting overwrites the attributes and clears an earlier revoke, so re-buying after a refund restores ownership. Called inside the charge's transaction, so a rolled-back purchase grants nothing.

      Parameters

      Returns Promise<void>

    • Streams every non-revoked grant for the user, expired ones included, sorted by sku. Each row carries the expiry owns applies at read time (null never lapses), so a caller can reproduce the ownership decision.

      Parameters

      Returns AsyncIterable<EntitlementGrant>

    • True while a non-revoked grant exists whose expiresAt is null or at/after the current clock (the expiry check is inclusive).

      Parameters

      • userId: string
      • sku: string
      • Optionaloptions: CallOptions

      Returns Promise<boolean>

    • Marks the grant revoked: owns turns false and list stops streaming it. An unknown or already-revoked (userId, sku) changes nothing, and a later grant of the same sku restores ownership.

      Parameters

      • userId: string
      • sku: string
      • Optionaloptions: CallOptions

      Returns Promise<void>