@molecule/app-http 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-19T22:40:45.495Z
6
+ Generated: 2026-10-25T20:03:35.125Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-http
@@ -135,14 +135,53 @@ interface HttpClient {
135
135
 
136
136
  /**
137
137
  * Sets the authorization token.
138
+ *
139
+ * A static token: every request carries it until the next `setAuthToken` call. A client
140
+ * that has a {@link HttpClient.setAuthTokenResolver | resolver} (registered through
141
+ * `@molecule/app-http`'s `setAuthTokenSource`) ignores this value when it assembles a
142
+ * request — the resolver IS the session, and reading it per request is what keeps a
143
+ * session adopted without an auth event from sending the previous account's bearer. Once
144
+ * the resolver is removed, the static token is sent again.
138
145
  */
139
146
  setAuthToken(token: string | null): void
140
147
 
141
148
  /**
142
- * Returns the current authorization token, or `null` if not set.
149
+ * Returns the token the client applies to its next request: the resolver's answer when one
150
+ * is registered, else the static token from `setAuthToken`.
143
151
  */
144
152
  getAuthToken(): string | null
145
153
 
154
+ /**
155
+ * Registers the LIVE token resolver every request of this client reads, or clears it with
156
+ * `null`.
157
+ *
158
+ * `@molecule/app-http`'s `setAuthTokenSource()` calls this on every client it bonds, and the
159
+ * client MUST consult the resolver again each time it assembles a request (and report it from
160
+ * `getAuthToken()`). A session can change with no auth event and no observable state change —
161
+ * `authClient.setSession()` with the same profile data, or the OAuth callback's
162
+ * `setAccessToken()` — so a token pushed only at bond time or on `login`/`logout` events
163
+ * leaves every later request carrying the PREVIOUS session's bearer while the UI shows the
164
+ * new one.
165
+ *
166
+ * The resolved token takes the static token's place, with the same precedence: an
167
+ * `Authorization` header passed per request or in the client's default headers wins over it
168
+ * exactly where it won over a static token in this transport.
169
+ *
170
+ * A resolver that returns `null` (or `undefined`) means "this session has no body token": the
171
+ * request carries no `Authorization` header of the client's own. A cookie-session API issues
172
+ * no bearer, and the server prefers the header over the fresh cookie, so a kept bearer
173
+ * authenticates as the prior — possibly deleted — session.
174
+ *
175
+ * Optional, so an implementation written against the previous interface still conforms.
176
+ * `setAuthTokenSource()` follows such a client through a request interceptor instead, pushing
177
+ * the source with `setAuthToken` before each request: that request carries the change only
178
+ * when the transport applies its token after running its interceptors, so a transport that
179
+ * applies it earlier sends a session adopted mid-page from the following request on.
180
+ *
181
+ * @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
182
+ */
183
+ setAuthTokenResolver?(resolver: AuthTokenResolver | null): void
184
+
146
185
  /**
147
186
  * Registers a handler for authentication errors (401).
148
187
  *
@@ -159,7 +198,10 @@ HTTP client configuration.
159
198
  ```typescript
160
199
  interface HttpClientConfig {
161
200
  /**
162
- * Base URL for all requests.
201
+ * Base URL for all requests: a path (`/api`) or an absolute URL
202
+ * (`https://api.example.com/api`). A request path that already starts with the base's
203
+ * path (`/api/users`) is not prefixed again, and a URL with its own host (`https://…`,
204
+ * `//cdn…`) is requested as written.
163
205
  */
164
206
  baseURL?: string
165
207
 
@@ -417,6 +459,19 @@ interface HttpResponse<T = unknown> {
417
459
 
418
460
  ### Types
419
461
 
462
+ #### `AuthTokenResolver`
463
+
464
+ A live access-token resolver: called once per request, it returns the token the session
465
+ holds NOW (`null`/`undefined` when the session carries no body token — a cookie-session API).
466
+
467
+ `@molecule/app-http`'s `setAuthTokenSource()` installs one on every client it bonds, so the
468
+ app's auth bond decides the bearer and the client resolves it per request instead of holding
469
+ a copy that a session adopted mid-page can leave stale.
470
+
471
+ ```typescript
472
+ type AuthTokenResolver = () => string | null | undefined
473
+ ```
474
+
420
475
  #### `RequestInterceptor`
421
476
 
422
477
  Intercepts outgoing requests to modify headers, URL, or body
@@ -771,27 +826,41 @@ function unwrapSingle(res: unknown): T | null
771
826
 
772
827
  #### `setAuthTokenSource(source)`
773
828
 
774
- Registers the token source a newly bonded client is hydrated from, or clears
775
- it with `null`.
829
+ Registers the token source every bonded client reads on EACH request, or removes it with
830
+ `null`.
831
+
832
+ Every client that receives the source — the one bonded now, any bonded later, and the
833
+ fallback {@link getClient} returns while none is bonded — is hydrated from `source()` and
834
+ reads it again for every request: through {@link HttpClient.setAuthTokenResolver} where the
835
+ client implements it (`createFetchClient`, `@molecule/app-http-axios` from 1.2.0), else
836
+ through a request interceptor that pushes it with `setAuthToken`, which a transport applying
837
+ its token after its interceptors sends on that same request and one applying it before them
838
+ from the next request on. So a restored session reaches a client bonded after the auth setup
839
+ (which holds no client reference), and a session adopted later with no auth event
840
+ (`setSession`, `setAccessToken`) never leaves the previous account's bearer on the wire.
841
+
842
+ A source that returns `null` means "no body token": the client sends no `Authorization`
843
+ header of its own (see {@link HttpClient.setAuthTokenResolver} for why a kept bearer is a
844
+ bug). A header passed per request or in a client's default headers keeps the precedence that
845
+ client's transport gives it over the client's token.
776
846
 
777
- The source is read once per bond: the client bonded AFTER this call (and the
778
- one bonded now, if any) receives `source()` through `setAuthToken`. That is
779
- what carries a restored session's token into a client the auth setup ran
780
- before — the setup does not need to hold a client reference at all.
847
+ A replaced source is followed from the next request on. Removing it (`null`) leaves the
848
+ bonded client (and the fallback) on the token the source returned at that moment, as a
849
+ static token that `setAuthToken` controls from then on.
781
850
 
782
851
  ```typescript
783
- function setAuthTokenSource(source: (() => string | null | undefined) | null): void
852
+ function setAuthTokenSource(source: AuthTokenResolver | null): void
784
853
  ```
785
854
 
786
- - `source` — Returns the current access token (null when signed out), or `null` to clear.
855
+ - `source` — Returns the current access token (null when signed out), or `null` to remove it.
787
856
 
788
857
  #### `setClient(client)`
789
858
 
790
859
  Registers an HTTP client as the active singleton.
791
860
 
792
861
  A registered `setAuthTokenSource` token source is applied to the client
793
- here, so a client bonded after the auth setup still carries the restored
794
- session's token.
862
+ here, so a client bonded after the auth setup resolves the restored
863
+ session's token on every request it makes.
795
864
 
796
865
  ```typescript
797
866
  function setClient(client: HttpClient): void
@@ -813,6 +882,8 @@ prefix, so the fallback only runs in an app that never bonded one.
813
882
  Returning it WITHOUT bonding is what keeps a later `setClient()` authoritative: a
814
883
  caller that captured this fallback early does not make it the app's client, so the
815
884
  scaffold's client (and its token source) still takes effect for every later call.
885
+ The fallback follows a registered `setAuthTokenSource` source like a bonded client
886
+ does, so an app that bonds no client at all still sends the current session.
816
887
 
817
888
  ```typescript
818
889
  function getClient(): HttpClient
@@ -949,7 +1020,7 @@ Two mistakes that break in preview/production (seen in real imported apps):
949
1020
  - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
950
1021
  bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
951
1022
  dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
952
- `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
1023
+ `data`, and the API then validates none of the fields it was sent. A scaffold bonds
953
1024
  `'/api'`; an app that builds its own client must pass `{ baseURL }`.
954
1025
  - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
955
1026
  key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
@@ -975,8 +1046,11 @@ module registers its own: `setAuthGate(() => session.whenRestored())`.
975
1046
  Waiting for the restore does NOT attach the token: a client created beside the auth bond needs
976
1047
  `createDefaultHttpClientWithAuthBearer({ baseURL, getToken: () => authClient.getAccessToken(),
977
1048
  authScheme })` from `@molecule/app-bonds-default-react` (or an auth client built with
978
- `createDefaultAuthClientWithHttpSync`, which mirrors the token into the bonded client), because
979
- `setAuthGate` alone sends no `Authorization` header.
1049
+ `createDefaultAuthClientWithHttpSync`, which registers the auth client's token source with
1050
+ `setAuthTokenSource`: the client reads it on each request, so a session adopted mid-page by
1051
+ `setSession()` or an OAuth callback's `setAccessToken()` is sent instead of the previous
1052
+ account's token — `setAuthTokenSource` says which request first carries it on a transport
1053
+ without `setAuthTokenResolver`), because `setAuthGate` alone sends no `Authorization` header.
980
1054
 
981
1055
  **The gate never holds its own restore's request.** A request the settle function issues
982
1056
  while it runs (its call reaches this client before the function awaits anything) is part of
@@ -7,8 +7,8 @@
7
7
  * answers for an anonymous viewer — `following: false` on a user you follow.
8
8
  * It is invisible on localhost, where the restore wins the race against the
9
9
  * first effect, and appears over the network as soon as the restore takes one
10
- * round trip: X1 xr-molecule-flash-m95 spent ~25 min chasing this as "database
11
- * leftovers" on the deployed URL.
10
+ * round trip: on a deployed URL it reads as stale server data rather than as a
11
+ * request that left without its header.
12
12
  *
13
13
  * So the auth bond registers a gate here (`setAuthGate`) and every request
14
14
  * waits for it (`awaitAuthGate`) — the race is impossible to write by hand.
@@ -31,11 +31,10 @@
31
31
  *
32
32
  * `awaitAuthGate` holds every request while the gate is pending — except the ones the gate's
33
33
  * settle function issues itself. Those are part of the restore it is waiting for; holding them
34
- * makes the gate wait on itself, and nothing but the timeout releases anything (X1
35
- * xr-molecule-flash-m97 and xr-molecule-flash-m173 both lost minutes to this: an app
34
+ * makes the gate wait on itself, and nothing but the timeout releases anything: an app
36
35
  * registering `setAuthGate(() => restoreSession())` over a restore that fetched through the
37
- * same client, every page held for the full bound, and 917 `GET /api/user` requests named by
38
- * one console line). So `setAuthGate(() => restoreSession())` works as written when
36
+ * same client holds every page for the full bound, and one console line can name hundreds of
37
+ * `GET /api/user` requests. So `setAuthGate(() => restoreSession())` works as written when
39
38
  * `restoreSession` calls the gated client.
40
39
  *
41
40
  * "Issued by the gate" means issued while the settle function is running: this package's
@@ -44,7 +43,7 @@
44
43
  * read, a `Promise.resolve()`) and only then calls the client issues its request from a later
45
44
  * continuation, which nothing can attribute to the gate — browsers ship no async-context API
46
45
  * (`AsyncContext`/`AsyncLocalStorage`) to ask, and releasing requests merely because the gate is
47
- * pending would drop exactly the first-paint requests the gate exists to hold (m95). A provider
46
+ * pending would drop exactly the first-paint requests the gate exists to hold. A provider
48
47
  * whose request pipeline awaits the gate in a scheduled interceptor (the Axios bond) reaches it
49
48
  * a microtask after the settle function returns, outside the window, for the same reason. Such a
50
49
  * request must pass `skipAuthGate: true` (`RequestConfig.skipAuthGate`), and a timeout with
@@ -1 +1 @@
1
- {"version":3,"file":"auth-gate.d.ts","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAkEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAG,IAIhE,CAAA;AA8ED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAU,UAAU,eAAe,KAAG,OAAO,CAAC,IAAI,CAwC3E,CAAA"}
1
+ {"version":3,"file":"auth-gate.d.ts","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAkEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAG,IAIhE,CAAA;AA8ED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAU,UAAU,eAAe,KAAG,OAAO,CAAC,IAAI,CAwC3E,CAAA"}
package/dist/auth-gate.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * answers for an anonymous viewer — `following: false` on a user you follow.
8
8
  * It is invisible on localhost, where the restore wins the race against the
9
9
  * first effect, and appears over the network as soon as the restore takes one
10
- * round trip: X1 xr-molecule-flash-m95 spent ~25 min chasing this as "database
11
- * leftovers" on the deployed URL.
10
+ * round trip: on a deployed URL it reads as stale server data rather than as a
11
+ * request that left without its header.
12
12
  *
13
13
  * So the auth bond registers a gate here (`setAuthGate`) and every request
14
14
  * waits for it (`awaitAuthGate`) — the race is impossible to write by hand.
@@ -31,11 +31,10 @@
31
31
  *
32
32
  * `awaitAuthGate` holds every request while the gate is pending — except the ones the gate's
33
33
  * settle function issues itself. Those are part of the restore it is waiting for; holding them
34
- * makes the gate wait on itself, and nothing but the timeout releases anything (X1
35
- * xr-molecule-flash-m97 and xr-molecule-flash-m173 both lost minutes to this: an app
34
+ * makes the gate wait on itself, and nothing but the timeout releases anything: an app
36
35
  * registering `setAuthGate(() => restoreSession())` over a restore that fetched through the
37
- * same client, every page held for the full bound, and 917 `GET /api/user` requests named by
38
- * one console line). So `setAuthGate(() => restoreSession())` works as written when
36
+ * same client holds every page for the full bound, and one console line can name hundreds of
37
+ * `GET /api/user` requests. So `setAuthGate(() => restoreSession())` works as written when
39
38
  * `restoreSession` calls the gated client.
40
39
  *
41
40
  * "Issued by the gate" means issued while the settle function is running: this package's
@@ -44,7 +43,7 @@
44
43
  * read, a `Promise.resolve()`) and only then calls the client issues its request from a later
45
44
  * continuation, which nothing can attribute to the gate — browsers ship no async-context API
46
45
  * (`AsyncContext`/`AsyncLocalStorage`) to ask, and releasing requests merely because the gate is
47
- * pending would drop exactly the first-paint requests the gate exists to hold (m95). A provider
46
+ * pending would drop exactly the first-paint requests the gate exists to hold. A provider
48
47
  * whose request pipeline awaits the gate in a scheduled interceptor (the Axios bond) reaches it
49
48
  * a microtask after the settle function returns, outside the window, for the same reason. Such a
50
49
  * request must pass `skipAuthGate: true` (`RequestConfig.skipAuthGate`), and a timeout with
@@ -75,7 +74,7 @@ let reportedStall = null;
75
74
  * that arrives while the gate is pending.
76
75
  *
77
76
  * Without it each held request re-invokes the gate, and a gate that issues a request on every
78
- * call floods the network: the m97 shape measured 855 `fetch` calls for one page (`task-auth-
77
+ * call floods the network: the shape measured 855 `fetch` calls for one page (`task-auth-
79
78
  * gate-deadlock.report.md`). `null` when no invocation is in flight; `setAuthGate` clears it
80
79
  * so a re-registered gate is never shared with the old one's waiters.
81
80
  */
@@ -161,7 +160,7 @@ const describeRequest = (request) => request?.method || request?.url
161
160
  * The report is console output, and every reader of it truncates: molecule-dev's route walk
162
161
  * keeps the first 200 characters of a console error, so the sentence naming the fix has to
163
162
  * come first — and the request list is capped so the message stays readable when a deadlocked
164
- * gate has held hundreds of requests (xr-molecule-flash-m173: 917 `GET /api/user`).
163
+ * gate has held hundreds of requests (one deadlocked gate named 917 `GET /api/user` calls).
165
164
  */
166
165
  const MAX_NAMED_HELD_REQUESTS = 5;
167
166
  /**
@@ -170,8 +169,8 @@ const MAX_NAMED_HELD_REQUESTS = 5;
170
169
  * deployed URL reads as "the site is slow", which is what the gate itself was added for.
171
170
  *
172
171
  * Leads with the cause and the fix, then names at most `MAX_NAMED_HELD_REQUESTS` distinct
173
- * requests and counts the rest: an unbounded join buried the fix clause behind 900 names in
174
- * xr-molecule-flash-m173, and no reader of the line ever reached it.
172
+ * requests and counts the rest: an unbounded join buries the fix clause behind 900 names,
173
+ * and no reader of the line ever reaches it.
175
174
  */
176
175
  const reportStalledGate = (stuck) => {
177
176
  if (reportedStall === stuck)
@@ -1 +1 @@
1
- {"version":3,"file":"auth-gate.js","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAIhD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEhC,iFAAiF;AACjF,IAAI,IAAI,GAAiC,IAAI,CAAA;AAE7C;;;GAGG;AACH,MAAM,YAAY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OAAO,EAAE,YAAY;QAAE,OAAM;IAEjC,MAAM,OAAO,GAAG,IAAI,CAAA;IACpB,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,0FAA0F;IAC1F,yDAAyD;IACzD,IAAI,YAAY;QAAE,OAAM;IAExB,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;IACpC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAA;IAEjD,IAAI,KAAgD,CAAA;IACpD,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC;YACjB,wFAAwF;YACxF,iFAAiF;YACjF,0BAA0B;YAC1B,UAAU,CAAC,OAAO,CAAC;YACnB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC5B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;oBACtB,QAAQ,GAAG,IAAI,CAAA;oBACf,mFAAmF;oBACnF,iBAAiB,CAAC,OAAO,CAAC,CAAA;oBAC1B,OAAO,EAAE,CAAA;gBACX,CAAC,EAAE,eAAe,CAAC,CAAA;YACrB,CAAC,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAA;QAC9B,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,yFAAyF;IACzF,8EAA8E;IAC9E,IAAI,CAAC,QAAQ,IAAI,aAAa,KAAK,OAAO;QAAE,aAAa,GAAG,IAAI,CAAA;AAClE,CAAC,CAAA"}
package/dist/client.d.ts CHANGED
@@ -8,6 +8,15 @@
8
8
  import type { ErrorInterceptor, RequestInterceptor, ResponseInterceptor } from './interceptors.js';
9
9
  import type { RetryOptions } from './retry.js';
10
10
  import type { FullRequestConfig, HttpResponse, RequestConfig } from './types.js';
11
+ /**
12
+ * A live access-token resolver: called once per request, it returns the token the session
13
+ * holds NOW (`null`/`undefined` when the session carries no body token — a cookie-session API).
14
+ *
15
+ * `@molecule/app-http`'s `setAuthTokenSource()` installs one on every client it bonds, so the
16
+ * app's auth bond decides the bearer and the client resolves it per request instead of holding
17
+ * a copy that a session adopted mid-page can leave stale.
18
+ */
19
+ export type AuthTokenResolver = () => string | null | undefined;
11
20
  /**
12
21
  * HTTP client interface.
13
22
  *
@@ -68,12 +77,50 @@ export interface HttpClient {
68
77
  addErrorInterceptor(interceptor: ErrorInterceptor): () => void;
69
78
  /**
70
79
  * Sets the authorization token.
80
+ *
81
+ * A static token: every request carries it until the next `setAuthToken` call. A client
82
+ * that has a {@link HttpClient.setAuthTokenResolver | resolver} (registered through
83
+ * `@molecule/app-http`'s `setAuthTokenSource`) ignores this value when it assembles a
84
+ * request — the resolver IS the session, and reading it per request is what keeps a
85
+ * session adopted without an auth event from sending the previous account's bearer. Once
86
+ * the resolver is removed, the static token is sent again.
71
87
  */
72
88
  setAuthToken(token: string | null): void;
73
89
  /**
74
- * Returns the current authorization token, or `null` if not set.
90
+ * Returns the token the client applies to its next request: the resolver's answer when one
91
+ * is registered, else the static token from `setAuthToken`.
75
92
  */
76
93
  getAuthToken(): string | null;
94
+ /**
95
+ * Registers the LIVE token resolver every request of this client reads, or clears it with
96
+ * `null`.
97
+ *
98
+ * `@molecule/app-http`'s `setAuthTokenSource()` calls this on every client it bonds, and the
99
+ * client MUST consult the resolver again each time it assembles a request (and report it from
100
+ * `getAuthToken()`). A session can change with no auth event and no observable state change —
101
+ * `authClient.setSession()` with the same profile data, or the OAuth callback's
102
+ * `setAccessToken()` — so a token pushed only at bond time or on `login`/`logout` events
103
+ * leaves every later request carrying the PREVIOUS session's bearer while the UI shows the
104
+ * new one.
105
+ *
106
+ * The resolved token takes the static token's place, with the same precedence: an
107
+ * `Authorization` header passed per request or in the client's default headers wins over it
108
+ * exactly where it won over a static token in this transport.
109
+ *
110
+ * A resolver that returns `null` (or `undefined`) means "this session has no body token": the
111
+ * request carries no `Authorization` header of the client's own. A cookie-session API issues
112
+ * no bearer, and the server prefers the header over the fresh cookie, so a kept bearer
113
+ * authenticates as the prior — possibly deleted — session.
114
+ *
115
+ * Optional, so an implementation written against the previous interface still conforms.
116
+ * `setAuthTokenSource()` follows such a client through a request interceptor instead, pushing
117
+ * the source with `setAuthToken` before each request: that request carries the change only
118
+ * when the transport applies its token after running its interceptors, so a transport that
119
+ * applies it earlier sends a session adopted mid-page from the following request on.
120
+ *
121
+ * @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
122
+ */
123
+ setAuthTokenResolver?(resolver: AuthTokenResolver | null): void;
77
124
  /**
78
125
  * Registers a handler for authentication errors (401).
79
126
  *
@@ -86,7 +133,10 @@ export interface HttpClient {
86
133
  */
87
134
  export interface HttpClientConfig {
88
135
  /**
89
- * Base URL for all requests.
136
+ * Base URL for all requests: a path (`/api`) or an absolute URL
137
+ * (`https://api.example.com/api`). A request path that already starts with the base's
138
+ * path (`/api/users`) is not prefixed again, and a URL with its own host (`https://…`,
139
+ * `//cdn…`) is requested as written.
90
140
  */
91
141
  baseURL?: string;
92
142
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAClG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhF;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEtC;;;OAGG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,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AI,CAAA;IAExC;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,oBAAoB,CAAC,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,GAAG,IAAI,CAAA;IAE/D;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEvC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,GAAG,KAAK,CAAA;CAC7B"}
package/dist/index.d.ts CHANGED
@@ -49,7 +49,7 @@
49
49
  * - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
50
50
  * bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
51
51
  * dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
52
- * `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
52
+ * `data`, and the API then validates none of the fields it was sent. A scaffold bonds
53
53
  * `'/api'`; an app that builds its own client must pass `{ baseURL }`.
54
54
  * - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
55
55
  * key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
@@ -75,8 +75,11 @@
75
75
  * Waiting for the restore does NOT attach the token: a client created beside the auth bond needs
76
76
  * `createDefaultHttpClientWithAuthBearer({ baseURL, getToken: () => authClient.getAccessToken(),
77
77
  * authScheme })` from `@molecule/app-bonds-default-react` (or an auth client built with
78
- * `createDefaultAuthClientWithHttpSync`, which mirrors the token into the bonded client), because
79
- * `setAuthGate` alone sends no `Authorization` header.
78
+ * `createDefaultAuthClientWithHttpSync`, which registers the auth client's token source with
79
+ * `setAuthTokenSource`: the client reads it on each request, so a session adopted mid-page by
80
+ * `setSession()` or an OAuth callback's `setAccessToken()` is sent instead of the previous
81
+ * account's token — `setAuthTokenSource` says which request first carries it on a transport
82
+ * without `setAuthTokenResolver`), because `setAuthGate` alone sends no `Authorization` header.
80
83
  *
81
84
  * **The gate never holds its own restore's request.** A request the settle function issues
82
85
  * while it runs (its call reaches this client before the function awaits anything) is part of
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyGG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@
49
49
  * - **`getClient()` itself knows no baseURL.** The fallback client it mints when nothing is
50
50
  * bonded has `baseURL: ''`, so `getClient().get('/articles')` requests the PAGE origin — in
51
51
  * dev the Vite server answers its own `index.html` with a 200, and the HTML arrives as
52
- * `data` (xr-molecule-flash-m126 lost 6.5 minutes to that). A scaffold bonds
52
+ * `data`, and the API then validates none of the fields it was sent. A scaffold bonds
53
53
  * `'/api'`; an app that builds its own client must pass `{ baseURL }`.
54
54
  * - **The client is PUBLIC — never put a secret in it.** Anything the browser sends (an API
55
55
  * key, a service-role / `sk_…` key, a signing secret) is visible to every user. Secrets
@@ -75,8 +75,11 @@
75
75
  * Waiting for the restore does NOT attach the token: a client created beside the auth bond needs
76
76
  * `createDefaultHttpClientWithAuthBearer({ baseURL, getToken: () => authClient.getAccessToken(),
77
77
  * authScheme })` from `@molecule/app-bonds-default-react` (or an auth client built with
78
- * `createDefaultAuthClientWithHttpSync`, which mirrors the token into the bonded client), because
79
- * `setAuthGate` alone sends no `Authorization` header.
78
+ * `createDefaultAuthClientWithHttpSync`, which registers the auth client's token source with
79
+ * `setAuthTokenSource`: the client reads it on each request, so a session adopted mid-page by
80
+ * `setSession()` or an OAuth callback's `setAccessToken()` is sent instead of the previous
81
+ * account's token — `setAuthTokenSource` says which request first carries it on a transport
82
+ * without `setAuthTokenResolver`), because `setAuthGate` alone sends no `Authorization` header.
80
83
  *
81
84
  * **The gate never holds its own restore's request.** A request the settle function issues
82
85
  * while it runs (its call reaches this client before the function awaits anything) is part of
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyGG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAc/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UA8ajE,CAAA"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAqB,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA4ClF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UAqbjE,CAAA"}
package/dist/provider.js CHANGED
@@ -16,6 +16,34 @@ function sleep(ms) {
16
16
  }
17
17
  /** A response whose body is an HTML document, not JSON. */
18
18
  const HTML_CONTENT_TYPE = /^text\/html\b/i;
19
+ /** A URL that names its own host: a scheme (`https://`) or protocol-relative (`//cdn…`). */
20
+ const ABSOLUTE_URL = /^([a-z][a-z\d+\-.]*:)?\/\//i;
21
+ /** The scheme and host of an absolute baseURL (`https://host:8443`); nothing for a path. */
22
+ const BASE_AUTHORITY = /^([a-z][a-z\d+\-.]*:)?\/\/[^/?#]*/i;
23
+ /**
24
+ * The URL a request goes to under the client's baseURL.
25
+ *
26
+ * A URL that names its own host is used as written. Callers (e.g.
27
+ * `@molecule/app-billing-react` hooks) pass absolute `/api/...` paths whether or not a
28
+ * baseURL is bonded, so a path that already starts with the baseURL's path — `/api/users`
29
+ * under `/api` or under `https://host/api` — is the full path and is not prefixed a second
30
+ * time. Any other URL is joined onto the baseURL with exactly one `/`, as Axios joins them.
31
+ *
32
+ * @param baseURL - The client's baseURL.
33
+ * @param url - The request URL.
34
+ * @returns The URL to fetch.
35
+ */
36
+ function joinBaseURL(baseURL, url) {
37
+ if (!baseURL || ABSOLUTE_URL.test(url))
38
+ return url;
39
+ const base = baseURL.replace(/\/+$/, '');
40
+ const authority = BASE_AUTHORITY.exec(base)?.[0] ?? '';
41
+ const basePath = base.slice(authority.length);
42
+ if (basePath && url.startsWith(basePath) && /^(?:$|[/?#])/.test(url.slice(basePath.length))) {
43
+ return authority + url;
44
+ }
45
+ return url ? `${base}/${url.replace(/^\/+/, '')}` : baseURL;
46
+ }
19
47
  /**
20
48
  * Creates a fetch-based HTTP client using the native Fetch API.
21
49
  *
@@ -29,10 +57,18 @@ const HTML_CONTENT_TYPE = /^text\/html\b/i;
29
57
  export const createFetchClient = (config = {}) => {
30
58
  const logger = getLogger('http');
31
59
  let authToken = null;
60
+ // The app's live session token, installed by `setAuthTokenSource()` through `setClient()`.
61
+ // It is read per request, never stored: a session adopted without an auth event
62
+ // (`setSession`, the OAuth callback's `setAccessToken`) changes the token with no event and,
63
+ // when the profile data is unchanged, no state notification either — a stored copy would keep
64
+ // sending the previous account's bearer.
65
+ let authTokenResolver = null;
32
66
  const requestInterceptors = [];
33
67
  const responseInterceptors = [];
34
68
  const errorInterceptors = [];
35
69
  const authErrorHandlers = new Set();
70
+ /** The bearer this request carries: the resolver's answer, else the static token. */
71
+ const resolveAuthToken = () => authTokenResolver ? (authTokenResolver() ?? null) : authToken;
36
72
  // Track whether the document is currently navigating / unloading.
37
73
  // Browser tears down in-flight fetch()es on navigation as
38
74
  // `TypeError: Failed to fetch`, which is indistinguishable from a
@@ -69,16 +105,7 @@ export const createFetchClient = (config = {}) => {
69
105
  finalConfig = await interceptor(finalConfig);
70
106
  }
71
107
  // Build URL
72
- let url = finalConfig.url;
73
- if (client.baseURL && !url.startsWith('http://') && !url.startsWith('https://')) {
74
- // Guard against double-prefixing: callers (e.g. @molecule/app-billing-react
75
- // hooks) pass absolute `/api/...` paths whether or not a baseURL is bonded.
76
- // If the URL already starts with the bonded baseURL, leave it alone.
77
- const prefix = client.baseURL.endsWith('/') ? client.baseURL : client.baseURL + '/';
78
- if (!url.startsWith(prefix) && url !== client.baseURL) {
79
- url = client.baseURL + url;
80
- }
81
- }
108
+ let url = joinBaseURL(client.baseURL, finalConfig.url);
82
109
  // Add query params
83
110
  if (finalConfig.params) {
84
111
  const params = new URLSearchParams();
@@ -97,9 +124,11 @@ export const createFetchClient = (config = {}) => {
97
124
  ...client.defaultHeaders,
98
125
  ...finalConfig.headers,
99
126
  };
100
- // Add auth token
101
- if (authToken) {
102
- headers['Authorization'] = `${config.authScheme ?? 'Bearer'} ${authToken}`;
127
+ // Add auth token. Resolved HERE, after the gate: the session this request belongs to is
128
+ // the one the restore settled on, and it cannot have changed since a copy was taken.
129
+ const token = resolveAuthToken();
130
+ if (token) {
131
+ headers['Authorization'] = `${config.authScheme ?? 'Bearer'} ${token}`;
103
132
  }
104
133
  // Add content-type for JSON
105
134
  if (finalConfig.data && !headers['Content-Type']) {
@@ -358,8 +387,11 @@ export const createFetchClient = (config = {}) => {
358
387
  setAuthToken(token) {
359
388
  authToken = token;
360
389
  },
390
+ setAuthTokenResolver(resolver) {
391
+ authTokenResolver = resolver;
392
+ },
361
393
  getAuthToken() {
362
- return authToken;
394
+ return resolveAuthToken();
363
395
  },
364
396
  onAuthError(handler) {
365
397
  authErrorHandlers.add(handler);
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,gCAAgC;AAChC,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED,2DAA2D;AAC3D,MAAM,iBAAiB,GAAG,gBAAgB,CAAA;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAA2B,EAAE,EAAc,EAAE;IAC7E,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,SAAS,GAAkB,IAAI,CAAA;IACnC,MAAM,mBAAmB,GAAyB,EAAE,CAAA;IACpD,MAAM,oBAAoB,GAA0B,EAAE,CAAA;IACtD,MAAM,iBAAiB,GAAuB,EAAE,CAAA;IAChD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAc,CAAA;IAE/C,kEAAkE;IAClE,0DAA0D;IAC1D,kEAAkE;IAClE,u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QACnB,CAAC;QAED,oBAAoB,CAAC,QAAkC;YACrD,iBAAiB,GAAG,QAAQ,CAAA;QAC9B,CAAC;QAED,YAAY;YACV,OAAO,gBAAgB,EAAE,CAAA;QAC3B,CAAC;QAED,WAAW,CAAC,OAAmB;YAC7B,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC9B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAChD,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -8,31 +8,45 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { HttpClient } from './client.js';
11
+ import type { AuthTokenResolver, HttpClient } from './client.js';
12
12
  import type { HttpResponse, RequestConfig } from './types.js';
13
13
  /**
14
- * Registers the token source a newly bonded client is hydrated from, or clears
15
- * it with `null`.
16
- *
17
- * The source is read once per bond: the client bonded AFTER this call (and the
18
- * one bonded now, if any) receives `source()` through `setAuthToken`. That is
19
- * what carries a restored session's token into a client the auth setup ran
20
- * before — the setup does not need to hold a client reference at all.
21
- *
22
- * @param source - Returns the current access token (null when signed out), or `null` to clear.
14
+ * Registers the token source every bonded client reads on EACH request, or removes it with
15
+ * `null`.
16
+ *
17
+ * Every client that receives the source — the one bonded now, any bonded later, and the
18
+ * fallback {@link getClient} returns while none is bonded — is hydrated from `source()` and
19
+ * reads it again for every request: through {@link HttpClient.setAuthTokenResolver} where the
20
+ * client implements it (`createFetchClient`, `@molecule/app-http-axios` from 1.2.0), else
21
+ * through a request interceptor that pushes it with `setAuthToken`, which a transport applying
22
+ * its token after its interceptors sends on that same request and one applying it before them
23
+ * from the next request on. So a restored session reaches a client bonded after the auth setup
24
+ * (which holds no client reference), and a session adopted later with no auth event
25
+ * (`setSession`, `setAccessToken`) never leaves the previous account's bearer on the wire.
26
+ *
27
+ * A source that returns `null` means "no body token": the client sends no `Authorization`
28
+ * header of its own (see {@link HttpClient.setAuthTokenResolver} for why a kept bearer is a
29
+ * bug). A header passed per request or in a client's default headers keeps the precedence that
30
+ * client's transport gives it over the client's token.
31
+ *
32
+ * A replaced source is followed from the next request on. Removing it (`null`) leaves the
33
+ * bonded client (and the fallback) on the token the source returned at that moment, as a
34
+ * static token that `setAuthToken` controls from then on.
35
+ *
36
+ * @param source - Returns the current access token (null when signed out), or `null` to remove it.
23
37
  *
24
38
  * @example
25
39
  * ```typescript
26
40
  * setAuthTokenSource(() => authClient.getAccessToken())
27
41
  * ```
28
42
  */
29
- export declare const setAuthTokenSource: (source: (() => string | null | undefined) | null) => void;
43
+ export declare const setAuthTokenSource: (source: AuthTokenResolver | null) => void;
30
44
  /**
31
45
  * Registers an HTTP client as the active singleton.
32
46
  *
33
47
  * A registered `setAuthTokenSource` token source is applied to the client
34
- * here, so a client bonded after the auth setup still carries the restored
35
- * session's token.
48
+ * here, so a client bonded after the auth setup resolves the restored
49
+ * session's token on every request it makes.
36
50
  *
37
51
  * @param client - The HTTP client implementation to bond.
38
52
  *
@@ -56,6 +70,8 @@ export declare const setClient: (client: HttpClient) => void;
56
70
  * Returning it WITHOUT bonding is what keeps a later `setClient()` authoritative: a
57
71
  * caller that captured this fallback early does not make it the app's client, so the
58
72
  * scaffold's client (and its token source) still takes effect for every later call.
73
+ * The fallback follows a registered `setAuthTokenSource` source like a bonded client
74
+ * does, so an app that bonds no client at all still sends the current session.
59
75
  *
60
76
  * @returns The active HTTP client, or the unbonded fallback when none is bonded.
61
77
  */
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AA6B7D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,MAAM,MAAM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AAC,CAC1D,CAAA;AAEpC;;;GAGG;AACH,eAAO,MAAM,WAAW,mBAA4D,CAAA"}
package/dist/utilities.js CHANGED
@@ -22,28 +22,90 @@ let warnedAboutFallback = false;
22
22
  * `setClient()` captured a no-baseURL client that every later `setClient()`
23
23
  * could not reach — the app's real client was bonded and the caller's token
24
24
  * sync kept writing into the orphan, so every request went out bare
25
- * (xr-molecule-flash-m156, 401 `token is missing` after a reload).
25
+ * (a 401 `token is missing` after a reload).
26
26
  */
27
27
  let unbondedFallback = null;
28
28
  /**
29
- * The auth client whose token every HTTP client starts with, or null.
30
- *
31
- * `setClient` applies it at bond time, which is the only moment that can reach a
32
- * client created AFTER the auth setup ran — the scaffold wires auth before http,
33
- * so the auth bond's initial token had no client to land on
34
- * (`createDefaultAuthClientWithHttpSync` in `@molecule/app-bonds-default-react`).
29
+ * The auth client whose token every HTTP client the app bonds resolves on every request,
30
+ * or null.
31
+ *
32
+ * `setClient` installs it, which is the only moment that can reach a client created AFTER
33
+ * the auth setup ran — the scaffold wires auth before http, so the auth bond's initial
34
+ * token had no client to land on (`createDefaultAuthClientWithHttpSync` in
35
+ * `@molecule/app-bonds-default-react`). The client then reads the source itself for each
36
+ * request instead of holding a token copied at bond time: a session adopted mid-page —
37
+ * `setSession()`, the OAuth callback's `setAccessToken()` — changes the token with no auth
38
+ * event and, when the profile data is unchanged, with no state notification either, so a
39
+ * copy would keep sending the previous account's bearer.
35
40
  */
36
41
  let authTokenSource = null;
37
42
  /**
38
- * Registers the token source a newly bonded client is hydrated from, or clears
39
- * it with `null`.
40
- *
41
- * The source is read once per bond: the client bonded AFTER this call (and the
42
- * one bonded now, if any) receives `source()` through `setAuthToken`. That is
43
- * what carries a restored session's token into a client the auth setup ran
44
- * before — the setup does not need to hold a client reference at all.
45
- *
46
- * @param source - Returns the current access token (null when signed out), or `null` to clear.
43
+ * The source each client WITHOUT {@link HttpClient.setAuthTokenResolver} follows (a transport
44
+ * written against the previous interface), read by the request interceptor
45
+ * {@link applyAuthTokenSource} adds to that client once.
46
+ */
47
+ const interceptedSources = new WeakMap();
48
+ /**
49
+ * Gives one client the app's token source, or takes it away.
50
+ *
51
+ * A client that implements {@link HttpClient.setAuthTokenResolver} reads the source itself as
52
+ * it assembles each request. One that does not gets a request interceptor that pushes
53
+ * `source()` through `setAuthToken` before each of its requests: a transport that applies its
54
+ * token after running its interceptors (as `createFetchClient` does) sends the current session
55
+ * on that same request, and one that applies it before them (`@molecule/app-http-axios`
56
+ * before 1.2.0) from the following request on.
57
+ *
58
+ * Either way the client is hydrated now. Taking the source away leaves the client on the token
59
+ * the source returned at that moment, under `setAuthToken`'s control from then on — never on
60
+ * an older copy taken at bond time.
61
+ *
62
+ * @param client - The client receiving the source.
63
+ * @param source - The source to install, or `null` to take it away.
64
+ * @param previous - The source this call replaces or removes, if any.
65
+ */
66
+ const applyAuthTokenSource = (client, source, previous) => {
67
+ if (client.setAuthTokenResolver) {
68
+ client.setAuthTokenResolver(source);
69
+ }
70
+ else {
71
+ if (!interceptedSources.has(client)) {
72
+ client.addRequestInterceptor((config) => {
73
+ const current = interceptedSources.get(client);
74
+ if (current)
75
+ client.setAuthToken(current() ?? null);
76
+ return config;
77
+ });
78
+ }
79
+ interceptedSources.set(client, source);
80
+ }
81
+ const settled = source ?? previous;
82
+ if (settled)
83
+ client.setAuthToken(settled() ?? null);
84
+ };
85
+ /**
86
+ * Registers the token source every bonded client reads on EACH request, or removes it with
87
+ * `null`.
88
+ *
89
+ * Every client that receives the source — the one bonded now, any bonded later, and the
90
+ * fallback {@link getClient} returns while none is bonded — is hydrated from `source()` and
91
+ * reads it again for every request: through {@link HttpClient.setAuthTokenResolver} where the
92
+ * client implements it (`createFetchClient`, `@molecule/app-http-axios` from 1.2.0), else
93
+ * through a request interceptor that pushes it with `setAuthToken`, which a transport applying
94
+ * its token after its interceptors sends on that same request and one applying it before them
95
+ * from the next request on. So a restored session reaches a client bonded after the auth setup
96
+ * (which holds no client reference), and a session adopted later with no auth event
97
+ * (`setSession`, `setAccessToken`) never leaves the previous account's bearer on the wire.
98
+ *
99
+ * A source that returns `null` means "no body token": the client sends no `Authorization`
100
+ * header of its own (see {@link HttpClient.setAuthTokenResolver} for why a kept bearer is a
101
+ * bug). A header passed per request or in a client's default headers keeps the precedence that
102
+ * client's transport gives it over the client's token.
103
+ *
104
+ * A replaced source is followed from the next request on. Removing it (`null`) leaves the
105
+ * bonded client (and the fallback) on the token the source returned at that moment, as a
106
+ * static token that `setAuthToken` controls from then on.
107
+ *
108
+ * @param source - Returns the current access token (null when signed out), or `null` to remove it.
47
109
  *
48
110
  * @example
49
111
  * ```typescript
@@ -51,17 +113,21 @@ let authTokenSource = null;
51
113
  * ```
52
114
  */
53
115
  export const setAuthTokenSource = (source) => {
116
+ const previous = authTokenSource;
54
117
  authTokenSource = source;
55
118
  const bonded = bondGet(BOND_TYPE);
56
- if (bonded && source)
57
- bonded.setAuthToken(source() ?? null);
119
+ if (bonded)
120
+ applyAuthTokenSource(bonded, source, previous);
121
+ if (unbondedFallback && unbondedFallback !== bonded) {
122
+ applyAuthTokenSource(unbondedFallback, source, previous);
123
+ }
58
124
  };
59
125
  /**
60
126
  * Registers an HTTP client as the active singleton.
61
127
  *
62
128
  * A registered `setAuthTokenSource` token source is applied to the client
63
- * here, so a client bonded after the auth setup still carries the restored
64
- * session's token.
129
+ * here, so a client bonded after the auth setup resolves the restored
130
+ * session's token on every request it makes.
65
131
  *
66
132
  * @param client - The HTTP client implementation to bond.
67
133
  *
@@ -74,7 +140,7 @@ export const setAuthTokenSource = (source) => {
74
140
  export const setClient = (client) => {
75
141
  bond(BOND_TYPE, client);
76
142
  if (authTokenSource)
77
- client.setAuthToken(authTokenSource() ?? null);
143
+ applyAuthTokenSource(client, authTokenSource, null);
78
144
  };
79
145
  /**
80
146
  * Retrieves the bonded HTTP client. If none is bonded, returns a module-level
@@ -89,6 +155,8 @@ export const setClient = (client) => {
89
155
  * Returning it WITHOUT bonding is what keeps a later `setClient()` authoritative: a
90
156
  * caller that captured this fallback early does not make it the app's client, so the
91
157
  * scaffold's client (and its token source) still takes effect for every later call.
158
+ * The fallback follows a registered `setAuthTokenSource` source like a bonded client
159
+ * does, so an app that bonds no client at all still sends the current session.
92
160
  *
93
161
  * @returns The active HTTP client, or the unbonded fallback when none is bonded.
94
162
  */
@@ -96,8 +164,11 @@ export const getClient = () => {
96
164
  const existing = bondGet(BOND_TYPE);
97
165
  if (existing)
98
166
  return existing;
99
- if (!unbondedFallback)
167
+ if (!unbondedFallback) {
100
168
  unbondedFallback = createFetchClient();
169
+ if (authTokenSource)
170
+ applyAuthTokenSource(unbondedFallback, authTokenSource, null);
171
+ }
101
172
  if (!warnedAboutFallback) {
102
173
  warnedAboutFallback = true;
103
174
  getLogger('http').warn('@molecule/app-http: no client is bonded — requests go to the page origin with no baseURL. ' +
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,SAAS,GAAG,aAAa,CAAA;AAE/B,kEAAkE;AAClE,IAAI,mBAAmB,GAAG,KAAK,CAAA;AAE/B;;;;;;;;;GASG;AACH,IAAI,gBAAgB,GAAsB,IAAI,CAAA;AAE9C;;;;;;;GAOG;AACH,IAAI,eAAe,GAA6C,IAAI,CAAA;AAEpE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAgD,EAAQ,EAAE;IAC3F,eAAe,GAAG,MAAM,CAAA;IACxB,MAAM,MAAM,GAAG,OAAO,CAAa,SAAS,CAAC,CAAA;IAC7C,IAAI,MAAM,IAAI,MAAM;QAAE,MAAM,CAAC,YAA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MAAM,KAAK,GAAG,CACnB,GAAW,EACX,IAAc,EACd,MAAsB,EACI,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAEtE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAc,GAAW,EAAE,MAAsB,EAA4B,EAAE,CAChG,SAAS,EAAE,CAAC,MAAM,CAAI,GAAG,EAAE,MAAM,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-http",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Client HTTP interface for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,11 +34,11 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@molecule/app-bond": "1.0.3",
37
- "@molecule/app-i18n": "1.0.3",
38
- "@molecule/app-logger": "1.0.2",
39
- "@types/node": "26.1.2",
37
+ "@molecule/app-i18n": "1.1.0",
38
+ "@molecule/app-logger": "1.0.3",
39
+ "@types/node": "26.6.5",
40
40
  "typescript": "6.0.3",
41
- "vitest": "4.1.11"
41
+ "vitest": "4.1.12"
42
42
  },
43
43
  "repository": {
44
44
  "type": "git",