/** * One identity state per session. * * The session's identity is assembled from two sources — the OIDC session * itself and (on NSS localhost setups) a cookie-backed fallback — and is * observed by consumers that must invalidate what the previous identity * fetched. Doing that with independent flags and predicates per call site let * each new async path (a slow restore, a probe answering late, a refocus) * reintroduce the same class of bug, so the identity lives here, once: * * TEMPORARY, pending the uvdsl change: two mechanisms here exist only because * `@uvdsl/solid-oidc-client-browser` announces `sessionStateChange` when * `isActive` changes and nothing else — it does not report a WebID change that * keeps the session active, and it does not push a login/logout made in * another tab. Until it does (issue drafted), the cookie fallback is the only * way to see an NSS cookie identity change at all (see * `reportCookieIdentity`) and `watchTokenUpdates()` is the only way to see an * A -> B switch. Both are isolated here so they become a small deletion, not * a hunt, when uvdsl reports identity changes itself. * * - `sessionIsActive()` is the single activity rule (`isActive` is * authoritative, an explicit `false` wins over a cached WebID); * - every observation (session event, token update, refocus resync, cookie * probe result) is applied to ONE record, so a change is detected and * reported once, whichever path noticed it; * - the record carries a `version` (bumped when a transition is applied) and * the newest refresh attempt, so an answer that belongs to an identity the * session has since left — a restore started under Alice answering after * Bob logged in — is dropped instead of being applied; * - the transition is derived from the previous/next snapshots * (`classifyTransition`, `identityReplaced`), not from flags: there is * nothing to keep in sync, and an unchanged identity costs no event. * * Reported events (same vocabulary as before): * 'logout' — the session went from active to inactive; * 'sessionChange' — any other change of active state or WebID; * 'identityReplaced' — an identity that WAS actively established is gone or * replaced, so data fetched under it must be dropped. * Start-up (none -> A) and a token refresh for the same identity are not * replacements. * * A session whose backing store no longer holds it (a cross-tab logout) is * marked `cleared` here: the local session object keeps reporting the previous * identity, so the mark is what makes the derived reads report logged out * until the session reports an identity again. * * DO NOT keep identity state anywhere else: `SolidAuthnLogic` reads it, * `authSession` publishes it (`info`, events) and `solidLogicSingleton` * decides from it whose credentials a request would carry. */ export type SessionLike = { isActive?: boolean; webId?: string; info?: { isLoggedIn?: boolean; webId?: string; }; addEventListener?: (type: string, listener: () => void) => void; setTokenDetails?: (...args: unknown[]) => unknown; restore?: () => Promise; }; export type IdentityEvent = 'logout' | 'sessionChange' | 'identityReplaced'; /** The session's own view: what the raw session reports, cleared-aware. */ export type IdentitySnapshot = { isActive: boolean; webId?: string; }; export type DocumentLike = { visibilityState?: string; addEventListener?: (type: string, listener: () => void) => void; removeEventListener?: (type: string, listener: () => void) => void; }; /** * Which legacy event a session transition should emit: * 'logout' — the session went from active to inactive; * 'sessionChange' — any other change of active state or WebID (a login here * is also announced as 'login' by SolidAuthnLogic; the * duplicate is harmless — consumers only invalidate); * null — nothing changed, so a refocused tab with the same * identity costs no event and no invalidation. */ export declare function classifyTransition(prev: IdentitySnapshot, next: IdentitySnapshot): 'logout' | 'sessionChange' | null; /** * Whether an established identity was replaced or cleared — a session that had * a WebID no longer reports the same one (A -> B), or no longer reports being * active (A -> logged out, A -> none). Data fetched under the previous * identity cannot be re-validated document by document, so this is the signal * to discard it. * * Only the transition OUT of an ACTIVELY established identity counts: once the * session has gone inactive (webId possibly retained), the replacement was * already reported — clearing the WebID afterwards or logging in as someone * else is not a second replacement. */ export declare function identityReplaced(prev: IdentitySnapshot, next: IdentitySnapshot): boolean; /** * Whether the session counts as active. `isActive` is authoritative — an * explicit `false` wins even when a WebID is still cached (a logout that has * not cleared it yet); the WebID only fills in an undefined state. */ export declare const sessionIsActive: (session: SessionLike) => boolean; type Subscriber = { onEvent?: (event: IdentityEvent) => void; /** The whole transition, once — for consumers that only invalidate. */ onTransition?: (events: IdentityEvent[]) => void; onRefocus?: () => void | Promise; resync?: () => unknown; }; /** * Whether a session was reported cleared: its backing store lost the session * while this tab still had one, so its identity no longer holds here. */ export declare function sessionWasCleared(session: unknown): boolean; /** * Whether the session explicitly reports itself inactive. An explicit `false` * — `isActive` on the session or `isLoggedIn` on the legacy `info` shape — * wins over a retained WebID: a partial logout that has not cleared the cached * WebID must not keep identifying the previous user. Consumers that would * otherwise act on the WebID alone (authenticated fetch, currentUser) use this * to stand down. */ export declare function sessionExplicitlyInactive(session: SessionLike): boolean; /** * Whether the OIDC session currently owns the identity. A session that was * reported cleared does not, and neither does one that explicitly reports * itself logged out (a legacy shape that still carries a WebID would otherwise * pass `sessionIsActive()` alone). */ export declare function sessionOwnsIdentity(session: SessionLike): boolean; /** The WebID the raw session publishes, or undefined when it owns none. */ export declare function sessionIdentityWebId(session: SessionLike): string | undefined; /** * The identity a caller should act as: the session's own when it owns one, the * cookie-probed one when the session is inactive (or cleared) and a probe * established it, and undefined when neither does. This is the last word for * `currentUser()`, `info` consumers and the fetch bridge. */ export declare function effectiveIdentity(session: SessionLike): { webId?: string; source: 'none' | 'session' | 'cookie'; }; /** * The legacy `info` shape is session-derived and stays derived: callers * snapshot and restore it, so a retained value must never answer for the * session. `isLoggedIn` follows `sessionIsActive` — an explicit `isActive: * false` reports logged out even when a WebID is still cached, or the fetch * bridge would keep routing anonymous requests through the authenticated * fetch. */ export declare function legacySessionInfo(session: SessionLike): { webId?: string; isLoggedIn?: boolean; }; /** * Runs `session.restore()`, sharing an attempt that is already in flight. * * @returns the shared promise, or undefined when the session has no restore. */ export declare function restoreSession(session: SessionLike | undefined): Promise | undefined; export type IdentitySubscription = { /** * Applies a cookie-probe result. Ignored once the subscription is released, * so a probe that answers after its owner was replaced cannot resurrect an * identity — and while the session owns the identity it must not be replaced * by a cookie one at all. */ reportCookieIdentity: (webId: string | null) => void; unsubscribe: () => void; }; /** * Observes the session for identity transitions, and for refocuses (one * document listener per session, removed when the last subscription is * released, so a replaced logic instance adds no second listener). * * `onEvent` receives the derived events; `onRefocus` runs on a refocus (the * cookie revalidation, in SolidAuthnLogic); `resync` re-reads the session * before the comparison (authSession owns it, because it knows that a restore * rejection means "no session"). */ export declare function subscribeIdentity(session: SessionLike, options?: Subscriber): IdentitySubscription; /** * Reload the page when the identity that was active in this tab is replaced or * cleared — the pragmatic way to drop everything fetched under the previous * identity (store, panes, editability), instead of repairing every read path. * * Consumer-side on purpose: navigation is an application decision (solid-ui, * mashlib), and tests inject their own action. */ export declare function reloadOnIdentityReplaced(events: { on?: (event: 'identityReplaced', handler: () => void) => void; } | undefined, reload?: () => void): void; /** * Re-reads the session and reports the transition, without a resync action * (a plain observation, used by tests and by callers that already know the * session was refreshed). */ export declare function observeSession(session: SessionLike): void; export {}; //# sourceMappingURL=identityState.d.ts.map