@@ -2,7 +2,20 @@ import type { ConnectionMeta } from 'devframe/types'
22import type { DevframeConnection } from './connection'
33import { DEVFRAME_CONNECTION_KEY } from 'devframe/constants'
44
5+ /**
6+ * @deprecated Legacy window-global meta handoff, fully subsumed by the
7+ * connection stored under `DEVFRAME_CONNECTION_KEY` (which carries the meta
8+ * together with its source URL and auth token). Still written and read for
9+ * compatibility with viewers bundling an older `devframe/client`; the read
10+ * path goes first, then the writes, in future releases.
11+ */
512const CONNECTION_META_KEY = '__DEVFRAME_CONNECTION_META__'
13+ /**
14+ * Key for the persisted auth token. The `localStorage` entry stays — it is
15+ * what lets trust survive reloads and reach sibling tabs. The *window-global*
16+ * entry under this key is deprecated: same-realm viewers read the token from
17+ * the connection under `DEVFRAME_CONNECTION_KEY` instead.
18+ */
619const CONNECTION_AUTH_TOKEN_KEY = '__DEVFRAME_CONNECTION_AUTH_TOKEN__'
720
821function readFromWindows < T > ( key : string ) : T | undefined {
@@ -26,6 +39,12 @@ export function readStoredConnection(): DevframeConnection | undefined {
2639 return readFromWindows < DevframeConnection > ( DEVFRAME_CONNECTION_KEY )
2740}
2841
42+ /**
43+ * @deprecated Reads the legacy meta global, kept only so a viewer embedded
44+ * under a host running an older `devframe/client` still inherits a
45+ * connection. Use {@link readStoredConnection} — `DEVFRAME_CONNECTION_KEY`
46+ * is the authoritative handoff.
47+ */
2948export function readStoredConnectionMeta ( ) : ( ConnectionMeta & { baseUrl ?: string } ) | undefined {
3049 return readFromWindows < ConnectionMeta & { baseUrl ?: string } > ( CONNECTION_META_KEY )
3150}
@@ -41,13 +60,18 @@ export function readStoredAuthToken(userAuthToken?: string): string | undefined
4160 }
4261 catch { }
4362
63+ // Deprecated window-global fallback — an older `devframe/client` host may
64+ // still publish the token this way. New hosts hand it over inside the
65+ // connection under `DEVFRAME_CONNECTION_KEY`.
4466 return readFromWindows < string > ( CONNECTION_AUTH_TOKEN_KEY )
4567}
4668
4769export function storeConnection ( connection : DevframeConnection ) : void {
4870 ; ( globalThis as any ) [ DEVFRAME_CONNECTION_KEY ] = connection
49- // Keep the established metadata/auth globals in sync for viewers that still
50- // consume the legacy handoff directly.
71+ // Deprecated: mirror into the legacy meta global so viewers bundling an
72+ // older `devframe/client` still inherit a connection. The connection under
73+ // `DEVFRAME_CONNECTION_KEY` is authoritative; this write goes away once the
74+ // legacy read path is retired.
5175 ; ( globalThis as any ) [ CONNECTION_META_KEY ] = {
5276 ...connection . connectionMeta ,
5377 baseUrl : connection . metaBaseUrl ,
@@ -61,6 +85,9 @@ export function storeAuthToken(token: string): void {
6185 localStorage . setItem ( CONNECTION_AUTH_TOKEN_KEY , token )
6286 }
6387 catch { }
88+ // Deprecated: mirror into the legacy window global for viewers bundling an
89+ // older `devframe/client`. New viewers read the token from the connection
90+ // under `DEVFRAME_CONNECTION_KEY`.
6491 ; ( globalThis as any ) [ CONNECTION_AUTH_TOKEN_KEY ] = token
6592
6693 const connection = readStoredConnection ( )
0 commit comments