| 397 | * (same-owner connects, or sessions written before this field), so `complete` |
| 398 | * falls back to the session owner. */ |
| 399 | const clientOwnerFromPayload = (payload: unknown): Owner | null => { |
| 400 | const decoded = |
| 401 | typeof payload === "string" |
| 402 | ? decodeJsonPayload(payload).pipe(Option.getOrElse(() => payload)) |
| 403 | : payload; |
| 404 | if (decoded === null || typeof decoded !== "object") return null; |
| 405 | const value = (decoded as Record<string, unknown>).clientOwner; |
| 406 | return value === "user" || value === "org" ? value : null; |
| 407 | }; |
| 408 | |
| 409 | /** Narrow a stored `grant` string to the `OAuthGrant` union, or `null` when the |
| 410 | * value is neither known grant. EXPLICIT — there is no silent fallback to |