pas-external 0.9.0

Ppoppo Accounts System (PAS) external SDK — OAuth2 PKCE, JWT verification port, Axum middleware, session liveness
Documentation
//! [`Fetcher`] port — authoritative substrate readout for sv-axis.

use async_trait::async_trait;

/// Authoritative `sv:{sub}` source for the cache-miss path.
///
/// Promoted to the SDK in Phase 11.Z from chat-auth's private
/// `SessionVersionFetcher` trait (§3 Row 6 "replace, don't layer"). The
/// shape stays narrow: one async method returning the current `sv` for
/// a given `sub` (ULID-form `ppnum_id`), or a typed [`FetchError`] on
/// failure.
///
/// **Fail-closed contract.** Failure here surfaces as
/// [`super::EpochRevocationError::Transient`] from the composer, which
/// the engine maps to [`AuthError::SessionVersionLookupUnavailable`]
/// and the SDK maps to
/// [`crate::token::VerifyError::SessionVersionLookupUnavailable`].
/// Silently admitting on fetch failure would let stale tokens slip
/// through after a break-glass — the entire point of the sv axis.
///
/// ## Implementations
///
/// - [`super::UserinfoFetcher`] — opinionated HTTP reader of PAS
///   `/userinfo`. Reads the `session_version` field (re-enabled in
///   Phase 11.Z under the `session_version` scope). RCW/CTW default.
/// - chat-auth-internal — cross-schema SQL `SELECT session_version
///   FROM scaccounts.ppnum_humans WHERE ppnum_id = $1`. Kept consumer-
///   side because it depends on chat-auth's `PgPool` and the cross-
///   schema search-path policy.
///
/// [`AuthError::SessionVersionLookupUnavailable`]: ppoppo_token::access_token::AuthError::SessionVersionLookupUnavailable
#[async_trait]
pub trait Fetcher: Send + Sync {
    /// Read the authoritative current `sv` for the given subject
    /// (ULID-form `ppnum_id` from the `sub` claim).
    async fn fetch(&self, sub: &str) -> Result<i64, FetchError>;
}

/// Opaque fetch failure. Carries a free-form detail for audit logs;
/// the composer collapses every variant onto
/// [`super::EpochRevocationError::Transient`] (fail-closed) so the
/// engine sees a uniform contract regardless of substrate flavor.
#[derive(Debug, thiserror::Error)]
#[error("session_version fetch failed: {0}")]
pub struct FetchError(pub String);