@molecule/app-http 1.1.2 → 1.1.3
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 +84 -12
- package/dist/auth-gate.d.ts +31 -2
- package/dist/auth-gate.d.ts.map +1 -1
- package/dist/auth-gate.js +98 -9
- package/dist/auth-gate.js.map +1 -1
- package/dist/client.d.ts +4 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +3 -1
- package/dist/provider.js.map +1 -1
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,20 +3,20 @@ 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-
|
|
6
|
+
Generated: 2026-10-17T00:21:23.012Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-http
|
|
10
10
|
|
|
11
|
-
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
-
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
-
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
-
|
|
15
11
|
Client HTTP interface for molecule.dev.
|
|
16
12
|
|
|
17
13
|
Provides a unified HTTP client API that works across different
|
|
18
14
|
HTTP libraries (fetch, axios, ky, etc.).
|
|
19
15
|
|
|
16
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
17
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
18
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
19
|
+
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
22
|
```tsx
|
|
@@ -163,7 +163,10 @@ interface HttpClientConfig {
|
|
|
163
163
|
/**
|
|
164
164
|
* The scheme of the `Authorization` header the auth token is sent with:
|
|
165
165
|
* `Bearer` (default), or what your API expects, e.g. `Token` for an API that
|
|
166
|
-
* reads `Authorization: Token <jwt>`.
|
|
166
|
+
* reads `Authorization: Token <jwt>`. It is an option of the client's
|
|
167
|
+
* CONSTRUCTOR (`createFetchClient({ baseURL, authScheme: 'Token' })`, or the
|
|
168
|
+
* bonded provider's `createAxiosClient({ … })`), never a property of the client
|
|
169
|
+
* it returns.
|
|
167
170
|
*/
|
|
168
171
|
authScheme?: string
|
|
169
172
|
}
|
|
@@ -173,7 +176,7 @@ interface HttpClientConfig {
|
|
|
173
176
|
|
|
174
177
|
HTTP request options (headers, query params, timeout, credentials, response type, abort signal).
|
|
175
178
|
|
|
176
|
-
|
|
179
|
+
````typescript
|
|
177
180
|
interface RequestConfig {
|
|
178
181
|
/**
|
|
179
182
|
* Request headers.
|
|
@@ -195,6 +198,26 @@ interface RequestConfig {
|
|
|
195
198
|
*/
|
|
196
199
|
withCredentials?: boolean
|
|
197
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Send this request WITHOUT waiting for the session restore (the auth gate).
|
|
203
|
+
*
|
|
204
|
+
* A request the gate itself depends on must set this. A gate registered with
|
|
205
|
+
* `setAuthGate` that waits for a session restore whose own request goes through this
|
|
206
|
+
* client otherwise waits on itself: the gate holds the restore's request, the restore's
|
|
207
|
+
* promise never settles, and every request on the page stalls until the gate times out —
|
|
208
|
+
* so pass `skipAuthGate: true` on the restore's own request:
|
|
209
|
+
*
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // the request the gate's restore makes, through the same client the gate holds back
|
|
212
|
+
* await http.get(currentUserEndpoint, { skipAuthGate: true })
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* `@molecule/app-auth`'s own restore does not need it — it sends its request with
|
|
216
|
+
* `fetch`, not through this client. An app with its own session store that registers a
|
|
217
|
+
* gate with `setAuthGate` does.
|
|
218
|
+
*/
|
|
219
|
+
skipAuthGate?: boolean
|
|
220
|
+
|
|
198
221
|
/**
|
|
199
222
|
* Response type.
|
|
200
223
|
*/
|
|
@@ -215,6 +238,35 @@ interface RequestConfig {
|
|
|
215
238
|
*/
|
|
216
239
|
options?: Record<string, unknown>
|
|
217
240
|
}
|
|
241
|
+
````
|
|
242
|
+
|
|
243
|
+
#### `AuthGateRequest`
|
|
244
|
+
|
|
245
|
+
What the auth gate is told about the request it is about to hold: whether the request
|
|
246
|
+
opts out of the wait, and how to name it in the stalled-gate report.
|
|
247
|
+
|
|
248
|
+
A request's own `RequestConfig` satisfies this — the providers pass it straight through
|
|
249
|
+
(`awaitAuthGate(requestConfig)`), so a provider never has to build one by hand.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
interface AuthGateRequest {
|
|
253
|
+
/**
|
|
254
|
+
* Send this request without waiting for the gate at all — see
|
|
255
|
+
* `RequestConfig.skipAuthGate`.
|
|
256
|
+
*/
|
|
257
|
+
skipAuthGate?: boolean
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The request's HTTP method, for the message logged when the gate never settles.
|
|
261
|
+
*/
|
|
262
|
+
method?: string
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The request's URL, for the message logged when the gate never settles. A URL may carry
|
|
266
|
+
* an id; it never carries a credential (tokens travel in headers).
|
|
267
|
+
*/
|
|
268
|
+
url?: string
|
|
269
|
+
}
|
|
218
270
|
```
|
|
219
271
|
|
|
220
272
|
#### `FullRequestConfig`
|
|
@@ -349,13 +401,18 @@ template auth that is `() => authClient.whenRestored()`, which resolves
|
|
|
349
401
|
immediately when no restore is in flight, so registering it never makes a
|
|
350
402
|
request wait longer than the restore it was about to race anyway.
|
|
351
403
|
|
|
404
|
+
A gate whose restore sends its OWN request through the gated client deadlocks — the
|
|
405
|
+
gate holds the request it is waiting for. That request must pass `skipAuthGate: true`
|
|
406
|
+
(see `RequestConfig.skipAuthGate`); `@molecule/app-auth`'s own restore does not
|
|
407
|
+
need it because it uses `fetch` rather than the bonded client.
|
|
408
|
+
|
|
352
409
|
```typescript
|
|
353
410
|
function setAuthGate(next: (() => Promise<void>) | null): void
|
|
354
411
|
```
|
|
355
412
|
|
|
356
413
|
- `next` — The gate, or `null` to clear a previously registered one.
|
|
357
414
|
|
|
358
|
-
#### `awaitAuthGate()`
|
|
415
|
+
#### `awaitAuthGate(request)`
|
|
359
416
|
|
|
360
417
|
Awaits the registered gate, if any. Every HTTP provider calls this before it
|
|
361
418
|
sends a request; callers never need to.
|
|
@@ -363,12 +420,15 @@ sends a request; callers never need to.
|
|
|
363
420
|
A gate that rejects (a restore that failed) is logged and cleared of consequence: the request
|
|
364
421
|
is sent rather than held forever, because a dead restore must not block every request for the
|
|
365
422
|
life of the page. The same holds for a gate that never settles — the wait is bounded by
|
|
366
|
-
|
|
423
|
+
`GATE_TIMEOUT_MS`, and a timeout with requests held is reported at error level naming the fix
|
|
424
|
+
(`skipAuthGate`).
|
|
367
425
|
|
|
368
426
|
```typescript
|
|
369
|
-
function awaitAuthGate(): Promise<void>
|
|
427
|
+
function awaitAuthGate(request?: AuthGateRequest): Promise<void>
|
|
370
428
|
```
|
|
371
429
|
|
|
430
|
+
- `request` — The request being gated, so a request the gate itself depends on can opt out (`skipAuthGate`) and a stalled gate can name what it held. A provider passes its own request config; a caller passing nothing gets the plain wait.
|
|
431
|
+
|
|
372
432
|
**Returns:** A promise that settles when the gate has released the request.
|
|
373
433
|
|
|
374
434
|
#### `createFetchClient(config)`
|
|
@@ -586,8 +646,12 @@ Two mistakes that break in preview/production (seen in real imported apps):
|
|
|
586
646
|
Auth (the bearer token / session cookie) is attached by the client's interceptors — do not
|
|
587
647
|
read a token from `localStorage` or hand-attach it (the token is memory-only; see the user
|
|
588
648
|
resource).
|
|
589
|
-
An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`)
|
|
590
|
-
`authScheme: 'Token'`
|
|
649
|
+
An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`) passes
|
|
650
|
+
`authScheme: 'Token'` to the client's CONSTRUCTOR — `setClient(createFetchClient({ baseURL,
|
|
651
|
+
authScheme: 'Token' }))`, or the bonded provider's constructor
|
|
652
|
+
(`createAxiosClient({ … })` from `@molecule/app-http-axios`). It is NOT a property of
|
|
653
|
+
`getClient()`'s result: that is a built client, and `client.authScheme = 'Token'` is a type
|
|
654
|
+
error (TS2339) that changes no header. Do not hand-write a fetch wrapper for the scheme either.
|
|
591
655
|
|
|
592
656
|
A request made while the session is still being restored WAITS for that restore, so a page
|
|
593
657
|
that fetches viewer-dependent data on mount (a profile's `following` flag, a feed, a
|
|
@@ -596,6 +660,14 @@ bond registers that wait with `setAuthGate`; apps that bond auth through
|
|
|
596
660
|
`@molecule/app-bonds-default-react` get it without doing anything. An app with its own session
|
|
597
661
|
module registers its own: `setAuthGate(() => session.whenRestored())`.
|
|
598
662
|
|
|
663
|
+
**A request the gate itself depends on must opt out of it: pass `skipAuthGate: true`.** A gate
|
|
664
|
+
that waits for a session restore whose own request goes through this client waits on itself —
|
|
665
|
+
that request is held by the gate waiting for it, so the restore never settles and every request
|
|
666
|
+
the gate holds stalls until it times out (3 s). The request that restores the session for a gate
|
|
667
|
+
you registered yourself is therefore written
|
|
668
|
+
`http.get(currentUserEndpoint, { skipAuthGate: true })`; `@molecule/app-auth`'s own restore does
|
|
669
|
+
not need it (it calls `fetch`, not this client).
|
|
670
|
+
|
|
599
671
|
## Translations
|
|
600
672
|
|
|
601
673
|
Translation strings are provided by `@molecule/app-locales-http`.
|
package/dist/auth-gate.d.ts
CHANGED
|
@@ -20,8 +20,28 @@
|
|
|
20
20
|
* `setupHttpDefault()`), and a gate installed on the throwaway client the auth
|
|
21
21
|
* bond saw would be silently lost.
|
|
22
22
|
*
|
|
23
|
+
* ## A request the gate is waiting for must opt out
|
|
24
|
+
*
|
|
25
|
+
* `awaitAuthGate` holds every request while the gate is pending — including one the gate
|
|
26
|
+
* itself depends on. A gate that waits for a session restore whose own request goes through
|
|
27
|
+
* the SAME client waits on itself: the restore's `GET /users/me` is held by the gate, the
|
|
28
|
+
* restore's promise cannot settle, and nothing but the timeout releases anything (X1
|
|
29
|
+
* xr-molecule-flash-m97 lost ~4 min to exactly this — an app registering
|
|
30
|
+
* `setAuthGate(() => whenSettled())` over a restore that fetched through its own client, with
|
|
31
|
+
* every request stalling the full bound and only a console warning to show for it). So a
|
|
32
|
+
* request the gate's restore makes must pass `skipAuthGate: true`
|
|
33
|
+
* (`RequestConfig.skipAuthGate`).
|
|
34
|
+
*
|
|
35
|
+
* Which held request is the gate's own is NOT detectable here: the gate is arbitrary code
|
|
36
|
+
* returning a promise, so a request cannot be attributed to the async chain that awaits it —
|
|
37
|
+
* and browsers have no async-context API (`AsyncContext` is not shipped) to ask. Releasing
|
|
38
|
+
* requests merely because the gate is pending and they carry no token would drop exactly the
|
|
39
|
+
* first-paint requests the gate exists to hold. The opt-out is therefore the fix, and a
|
|
40
|
+
* timeout with requests held is reported as an error naming it.
|
|
41
|
+
*
|
|
23
42
|
* @module
|
|
24
43
|
*/
|
|
44
|
+
import type { AuthGateRequest } from './types.js';
|
|
25
45
|
/**
|
|
26
46
|
* Registers the gate every HTTP request awaits before it is sent, or clears it
|
|
27
47
|
* with `null`.
|
|
@@ -31,6 +51,11 @@
|
|
|
31
51
|
* immediately when no restore is in flight, so registering it never makes a
|
|
32
52
|
* request wait longer than the restore it was about to race anyway.
|
|
33
53
|
*
|
|
54
|
+
* A gate whose restore sends its OWN request through the gated client deadlocks — the
|
|
55
|
+
* gate holds the request it is waiting for. That request must pass `skipAuthGate: true`
|
|
56
|
+
* (see `RequestConfig.skipAuthGate`); `@molecule/app-auth`'s own restore does not
|
|
57
|
+
* need it because it uses `fetch` rather than the bonded client.
|
|
58
|
+
*
|
|
34
59
|
* @param next - The gate, or `null` to clear a previously registered one.
|
|
35
60
|
*
|
|
36
61
|
* @example
|
|
@@ -48,9 +73,13 @@ export declare const setAuthGate: (next: (() => Promise<void>) | null) => void;
|
|
|
48
73
|
* A gate that rejects (a restore that failed) is logged and cleared of consequence: the request
|
|
49
74
|
* is sent rather than held forever, because a dead restore must not block every request for the
|
|
50
75
|
* life of the page. The same holds for a gate that never settles — the wait is bounded by
|
|
51
|
-
*
|
|
76
|
+
* `GATE_TIMEOUT_MS`, and a timeout with requests held is reported at error level naming the fix
|
|
77
|
+
* (`skipAuthGate`).
|
|
52
78
|
*
|
|
79
|
+
* @param request - The request being gated, so a request the gate itself depends on can opt
|
|
80
|
+
* out (`skipAuthGate`) and a stalled gate can name what it held. A provider passes its own
|
|
81
|
+
* request config; a caller passing nothing gets the plain wait.
|
|
53
82
|
* @returns A promise that settles when the gate has released the request.
|
|
54
83
|
*/
|
|
55
|
-
export declare const awaitAuthGate: () => Promise<void>;
|
|
84
|
+
export declare const awaitAuthGate: (request?: AuthGateRequest) => Promise<void>;
|
|
56
85
|
//# sourceMappingURL=auth-gate.d.ts.map
|
package/dist/auth-gate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-gate.d.ts","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth-gate.d.ts","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA6CjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAG,IAGhE,CAAA;AA6BD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAU,UAAU,eAAe,KAAG,OAAO,CAAC,IAAI,CAuC3E,CAAA"}
|
package/dist/auth-gate.js
CHANGED
|
@@ -20,22 +20,66 @@
|
|
|
20
20
|
* `setupHttpDefault()`), and a gate installed on the throwaway client the auth
|
|
21
21
|
* bond saw would be silently lost.
|
|
22
22
|
*
|
|
23
|
+
* ## A request the gate is waiting for must opt out
|
|
24
|
+
*
|
|
25
|
+
* `awaitAuthGate` holds every request while the gate is pending — including one the gate
|
|
26
|
+
* itself depends on. A gate that waits for a session restore whose own request goes through
|
|
27
|
+
* the SAME client waits on itself: the restore's `GET /users/me` is held by the gate, the
|
|
28
|
+
* restore's promise cannot settle, and nothing but the timeout releases anything (X1
|
|
29
|
+
* xr-molecule-flash-m97 lost ~4 min to exactly this — an app registering
|
|
30
|
+
* `setAuthGate(() => whenSettled())` over a restore that fetched through its own client, with
|
|
31
|
+
* every request stalling the full bound and only a console warning to show for it). So a
|
|
32
|
+
* request the gate's restore makes must pass `skipAuthGate: true`
|
|
33
|
+
* (`RequestConfig.skipAuthGate`).
|
|
34
|
+
*
|
|
35
|
+
* Which held request is the gate's own is NOT detectable here: the gate is arbitrary code
|
|
36
|
+
* returning a promise, so a request cannot be attributed to the async chain that awaits it —
|
|
37
|
+
* and browsers have no async-context API (`AsyncContext` is not shipped) to ask. Releasing
|
|
38
|
+
* requests merely because the gate is pending and they carry no token would drop exactly the
|
|
39
|
+
* first-paint requests the gate exists to hold. The opt-out is therefore the fix, and a
|
|
40
|
+
* timeout with requests held is reported as an error naming it.
|
|
41
|
+
*
|
|
23
42
|
* @module
|
|
24
43
|
*/
|
|
25
44
|
import { getLogger } from '@molecule/app-logger';
|
|
26
45
|
const logger = getLogger('http');
|
|
27
46
|
/** The registered gate, or null when no auth bond wired one (anonymous apps). */
|
|
28
47
|
let gate = null;
|
|
48
|
+
/**
|
|
49
|
+
* The requests the gate is holding right now, keyed by the waiting request: `GET /users/me`.
|
|
50
|
+
* Read only by the stalled-gate report, so it can name what was held back.
|
|
51
|
+
*/
|
|
52
|
+
const heldRequests = new Map();
|
|
53
|
+
/**
|
|
54
|
+
* The gate whose wait timed out with requests held, reported once.
|
|
55
|
+
*
|
|
56
|
+
* A deadlocked gate times out for EVERY request it holds, and the caller's own page shows it
|
|
57
|
+
* as one fault: one report per stuck gate names the fix, N reports (one per request, on every
|
|
58
|
+
* page load) are noise — and console errors are read by users and by strict console-error
|
|
59
|
+
* gates. Cleared when the same gate later releases a request normally.
|
|
60
|
+
*/
|
|
61
|
+
let reportedStall = null;
|
|
29
62
|
/**
|
|
30
63
|
* How long a request may be held by the gate before it is sent anyway.
|
|
31
64
|
*
|
|
32
65
|
* The gate waits for the session restore, and a restore that never settles — a stalled
|
|
33
66
|
* connection, an endpoint that hangs without answering — must not hold back every request for
|
|
34
67
|
* the life of the page: an unauthenticated request that arrives is a better failure than an app
|
|
35
|
-
* that never loads. A settled restore is what the deployed race needs (one round trip,
|
|
36
|
-
* of milliseconds), so this bound is far above any wait it is meant to cause.
|
|
68
|
+
* that never loads. A settled restore is what the deployed race needs (one round trip,
|
|
69
|
+
* hundreds of milliseconds), so this bound is far above any wait it is meant to cause.
|
|
70
|
+
*
|
|
71
|
+
* It is also the cost of a gate that was wired wrong (its restore sends its request through
|
|
72
|
+
* the client the gate holds back — see the module doc): every request it holds stalls this
|
|
73
|
+
* long before it goes out. Measured, so the bound is a number and not a guess:
|
|
74
|
+
* `createJWTAuthClient.initialize()` against a server answering `/users/me` after a delay
|
|
75
|
+
* costs exactly one round trip (0 ms → 7-50 ms; 140 ms → 152-194 ms; 400 ms → 402-413 ms),
|
|
76
|
+
* and a real deployed round trip measures ~140 ms from this VM to a Fly `iad` machine
|
|
77
|
+
* (`docs/experiments/x0/live/task-deployed-latency.report.md`) with 300-410 ms to a deployed
|
|
78
|
+
* app's proxied path over the open internet. 3 s is therefore ~8-20x a normal restore and
|
|
79
|
+
* still clears a slow mobile link — while a missed opt-out costs at most 3 s per request
|
|
80
|
+
* instead of 10.
|
|
37
81
|
*/
|
|
38
|
-
const GATE_TIMEOUT_MS =
|
|
82
|
+
const GATE_TIMEOUT_MS = 3_000;
|
|
39
83
|
/**
|
|
40
84
|
* Registers the gate every HTTP request awaits before it is sent, or clears it
|
|
41
85
|
* with `null`.
|
|
@@ -45,6 +89,11 @@ const GATE_TIMEOUT_MS = 10_000;
|
|
|
45
89
|
* immediately when no restore is in flight, so registering it never makes a
|
|
46
90
|
* request wait longer than the restore it was about to race anyway.
|
|
47
91
|
*
|
|
92
|
+
* A gate whose restore sends its OWN request through the gated client deadlocks — the
|
|
93
|
+
* gate holds the request it is waiting for. That request must pass `skipAuthGate: true`
|
|
94
|
+
* (see `RequestConfig.skipAuthGate`); `@molecule/app-auth`'s own restore does not
|
|
95
|
+
* need it because it uses `fetch` rather than the bonded client.
|
|
96
|
+
*
|
|
48
97
|
* @param next - The gate, or `null` to clear a previously registered one.
|
|
49
98
|
*
|
|
50
99
|
* @example
|
|
@@ -56,6 +105,30 @@ const GATE_TIMEOUT_MS = 10_000;
|
|
|
56
105
|
*/
|
|
57
106
|
export const setAuthGate = (next) => {
|
|
58
107
|
gate = next;
|
|
108
|
+
reportedStall = null;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Names a held request for the stalled-gate report. A provider that passes no request
|
|
112
|
+
* description still gets a report — it just cannot say which request was held.
|
|
113
|
+
*/
|
|
114
|
+
const describeRequest = (request) => request?.method || request?.url
|
|
115
|
+
? `${request?.method ?? 'GET'} ${request?.url ?? ''}`.trim()
|
|
116
|
+
: 'a request';
|
|
117
|
+
/**
|
|
118
|
+
* Reports a gate that timed out while holding requests: once per stuck gate, at error level
|
|
119
|
+
* so it reaches the page's error console and any error transport — a console warning on a
|
|
120
|
+
* deployed URL reads as "the site is slow", which is what the gate itself was added for.
|
|
121
|
+
*/
|
|
122
|
+
const reportStalledGate = (stuck) => {
|
|
123
|
+
if (reportedStall === stuck)
|
|
124
|
+
return;
|
|
125
|
+
reportedStall = stuck;
|
|
126
|
+
const held = [...heldRequests.values()].join(', ');
|
|
127
|
+
logger.error(`The auth gate has not settled after ${GATE_TIMEOUT_MS}ms and ${heldRequests.size} request(s) ` +
|
|
128
|
+
`were held by it (${held}); sending them without waiting. If the gate waits for a session ` +
|
|
129
|
+
`restore that makes its own request through this HTTP client, that request is being held by ` +
|
|
130
|
+
`the gate waiting for it: send it with \`skipAuthGate: true\`, or clear the gate with ` +
|
|
131
|
+
`\`setAuthGate(null)\` if nothing restores a session.`);
|
|
59
132
|
};
|
|
60
133
|
/**
|
|
61
134
|
* Awaits the registered gate, if any. Every HTTP provider calls this before it
|
|
@@ -64,19 +137,31 @@ export const setAuthGate = (next) => {
|
|
|
64
137
|
* A gate that rejects (a restore that failed) is logged and cleared of consequence: the request
|
|
65
138
|
* is sent rather than held forever, because a dead restore must not block every request for the
|
|
66
139
|
* life of the page. The same holds for a gate that never settles — the wait is bounded by
|
|
67
|
-
*
|
|
140
|
+
* `GATE_TIMEOUT_MS`, and a timeout with requests held is reported at error level naming the fix
|
|
141
|
+
* (`skipAuthGate`).
|
|
68
142
|
*
|
|
143
|
+
* @param request - The request being gated, so a request the gate itself depends on can opt
|
|
144
|
+
* out (`skipAuthGate`) and a stalled gate can name what it held. A provider passes its own
|
|
145
|
+
* request config; a caller passing nothing gets the plain wait.
|
|
69
146
|
* @returns A promise that settles when the gate has released the request.
|
|
70
147
|
*/
|
|
71
|
-
export const awaitAuthGate = async () => {
|
|
148
|
+
export const awaitAuthGate = async (request) => {
|
|
149
|
+
// The request IS the gate's restore (or otherwise must not wait): holding it would make
|
|
150
|
+
// the gate wait on itself — see the module doc.
|
|
151
|
+
if (request?.skipAuthGate)
|
|
152
|
+
return;
|
|
72
153
|
const current = gate;
|
|
73
154
|
if (!current)
|
|
74
155
|
return;
|
|
156
|
+
const token = Symbol('held-request');
|
|
157
|
+
heldRequests.set(token, describeRequest(request));
|
|
75
158
|
let timer;
|
|
76
159
|
let timedOut = false;
|
|
77
160
|
try {
|
|
78
161
|
await Promise.race([
|
|
79
|
-
|
|
162
|
+
// `(async () => current())()` also turns a gate that throws SYNCHRONOUSLY into a rejection:
|
|
163
|
+
// a gate is someone else's code, and no shape of it may reject the request it was holding.
|
|
164
|
+
(async () => current())().catch((error) => {
|
|
80
165
|
logger.warn('The auth gate rejected; sending the request without waiting for it', {
|
|
81
166
|
error,
|
|
82
167
|
});
|
|
@@ -84,6 +169,8 @@ export const awaitAuthGate = async () => {
|
|
|
84
169
|
new Promise((resolve) => {
|
|
85
170
|
timer = setTimeout(() => {
|
|
86
171
|
timedOut = true;
|
|
172
|
+
// Reported while this request is still in `heldRequests`, so the message names it.
|
|
173
|
+
reportStalledGate(current);
|
|
87
174
|
resolve();
|
|
88
175
|
}, GATE_TIMEOUT_MS);
|
|
89
176
|
}),
|
|
@@ -92,9 +179,11 @@ export const awaitAuthGate = async () => {
|
|
|
92
179
|
finally {
|
|
93
180
|
if (timer)
|
|
94
181
|
clearTimeout(timer);
|
|
182
|
+
heldRequests.delete(token);
|
|
95
183
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
184
|
+
// The gate released a real request, so any stall reported for it is over: a later one is
|
|
185
|
+
// news again (a fresh restore on a gate that was merely slow the first time).
|
|
186
|
+
if (!timedOut && reportedStall === current)
|
|
187
|
+
reportedStall = null;
|
|
99
188
|
};
|
|
100
189
|
//# sourceMappingURL=auth-gate.js.map
|
package/dist/auth-gate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-gate.js","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth-gate.js","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,C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10 @@ export interface HttpClientConfig {
|
|
|
98
98
|
/**
|
|
99
99
|
* The scheme of the `Authorization` header the auth token is sent with:
|
|
100
100
|
* `Bearer` (default), or what your API expects, e.g. `Token` for an API that
|
|
101
|
-
* reads `Authorization: Token <jwt>`.
|
|
101
|
+
* reads `Authorization: Token <jwt>`. It is an option of the client's
|
|
102
|
+
* CONSTRUCTOR (`createFetchClient({ baseURL, authScheme: 'Token' })`, or the
|
|
103
|
+
* bonded provider's `createAxiosClient({ … })`), never a property of the client
|
|
104
|
+
* it returns.
|
|
102
105
|
*/
|
|
103
106
|
authScheme?: string;
|
|
104
107
|
}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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,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;;OAEG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAEzE;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/E;;OAEG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,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C,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAEjG;;OAEG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAElF;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAAA;IAElE;;;OAGG;IACH,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAAA;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAA;IAE9D;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAExC;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;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;CACpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,8 +41,12 @@
|
|
|
41
41
|
* Auth (the bearer token / session cookie) is attached by the client's interceptors — do not
|
|
42
42
|
* read a token from `localStorage` or hand-attach it (the token is memory-only; see the user
|
|
43
43
|
* resource).
|
|
44
|
-
* An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`)
|
|
45
|
-
* `authScheme: 'Token'`
|
|
44
|
+
* An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`) passes
|
|
45
|
+
* `authScheme: 'Token'` to the client's CONSTRUCTOR — `setClient(createFetchClient({ baseURL,
|
|
46
|
+
* authScheme: 'Token' }))`, or the bonded provider's constructor
|
|
47
|
+
* (`createAxiosClient({ … })` from `@molecule/app-http-axios`). It is NOT a property of
|
|
48
|
+
* `getClient()`'s result: that is a built client, and `client.authScheme = 'Token'` is a type
|
|
49
|
+
* error (TS2339) that changes no header. Do not hand-write a fetch wrapper for the scheme either.
|
|
46
50
|
*
|
|
47
51
|
* A request made while the session is still being restored WAITS for that restore, so a page
|
|
48
52
|
* that fetches viewer-dependent data on mount (a profile's `following` flag, a feed, a
|
|
@@ -51,6 +55,14 @@
|
|
|
51
55
|
* `@molecule/app-bonds-default-react` get it without doing anything. An app with its own session
|
|
52
56
|
* module registers its own: `setAuthGate(() => session.whenRestored())`.
|
|
53
57
|
*
|
|
58
|
+
* **A request the gate itself depends on must opt out of it: pass `skipAuthGate: true`.** A gate
|
|
59
|
+
* that waits for a session restore whose own request goes through this client waits on itself —
|
|
60
|
+
* that request is held by the gate waiting for it, so the restore never settles and every request
|
|
61
|
+
* the gate holds stalls until it times out (3 s). The request that restores the session for a gate
|
|
62
|
+
* you registered yourself is therefore written
|
|
63
|
+
* `http.get(currentUserEndpoint, { skipAuthGate: true })`; `@molecule/app-auth`'s own restore does
|
|
64
|
+
* not need it (it calls `fetch`, not this client).
|
|
65
|
+
*
|
|
54
66
|
* @module
|
|
55
67
|
*/
|
|
56
68
|
export * from './auth-gate.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -41,8 +41,12 @@
|
|
|
41
41
|
* Auth (the bearer token / session cookie) is attached by the client's interceptors — do not
|
|
42
42
|
* read a token from `localStorage` or hand-attach it (the token is memory-only; see the user
|
|
43
43
|
* resource).
|
|
44
|
-
* An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`)
|
|
45
|
-
* `authScheme: 'Token'`
|
|
44
|
+
* An API that wants another scheme than `Bearer` (`Authorization: Token <jwt>`) passes
|
|
45
|
+
* `authScheme: 'Token'` to the client's CONSTRUCTOR — `setClient(createFetchClient({ baseURL,
|
|
46
|
+
* authScheme: 'Token' }))`, or the bonded provider's constructor
|
|
47
|
+
* (`createAxiosClient({ … })` from `@molecule/app-http-axios`). It is NOT a property of
|
|
48
|
+
* `getClient()`'s result: that is a built client, and `client.authScheme = 'Token'` is a type
|
|
49
|
+
* error (TS2339) that changes no header. Do not hand-write a fetch wrapper for the scheme either.
|
|
46
50
|
*
|
|
47
51
|
* A request made while the session is still being restored WAITS for that restore, so a page
|
|
48
52
|
* that fetches viewer-dependent data on mount (a profile's `following` flag, a feed, a
|
|
@@ -51,6 +55,14 @@
|
|
|
51
55
|
* `@molecule/app-bonds-default-react` get it without doing anything. An app with its own session
|
|
52
56
|
* module registers its own: `setAuthGate(() => session.whenRestored())`.
|
|
53
57
|
*
|
|
58
|
+
* **A request the gate itself depends on must opt out of it: pass `skipAuthGate: true`.** A gate
|
|
59
|
+
* that waits for a session restore whose own request goes through this client waits on itself —
|
|
60
|
+
* that request is held by the gate waiting for it, so the restore never settles and every request
|
|
61
|
+
* the gate holds stalls until it times out (3 s). The request that restores the session for a gate
|
|
62
|
+
* you registered yourself is therefore written
|
|
63
|
+
* `http.get(currentUserEndpoint, { skipAuthGate: true })`; `@molecule/app-auth`'s own restore does
|
|
64
|
+
* not need it (it calls `fetch`, not this client).
|
|
65
|
+
*
|
|
54
66
|
* @module
|
|
55
67
|
*/
|
|
56
68
|
export * from './auth-gate.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -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;AAK/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,
|
|
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;AAK/D;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,gBAAqB,KAAG,UA+VjE,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -53,7 +53,9 @@ export const createFetchClient = (config = {}) => {
|
|
|
53
53
|
// Wait for the session restore before anything else: the interceptors below
|
|
54
54
|
// read the auth token, and the request must not leave unauthenticated just
|
|
55
55
|
// because a page effect ran before the restore settled (see auth-gate.ts).
|
|
56
|
-
|
|
56
|
+
// The request config goes with it so a request the gate itself depends on can opt out
|
|
57
|
+
// (`skipAuthGate`) and a stalled gate can name what it held.
|
|
58
|
+
await awaitAuthGate(requestConfig);
|
|
57
59
|
// Apply request interceptors
|
|
58
60
|
let finalConfig = { ...requestConfig };
|
|
59
61
|
for (const interceptor of requestInterceptors) {
|
package/dist/provider.js.map
CHANGED
|
@@ -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;AAI9C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;;;;;;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;IA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ACH,CAAC,CAAA;QACH,CAAC;QAED,mBAAmB,CAAC,WAA6B;YAC/C,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACnC,OAAO,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;gBACpD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;oBACjB,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC,CAAA;QACH,CAAC;QAED,YAAY,CAAC,KAAoB;YAC/B,SAAS,GAAG,KAAK,CAAA;QACnB,CAAC;QAED,YAAY;YACV,OAAO,SAAS,CAAA;QAClB,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"}
|
package/dist/types.d.ts
CHANGED
|
@@ -27,6 +27,25 @@ export interface RequestConfig {
|
|
|
27
27
|
* Whether to include credentials (cookies).
|
|
28
28
|
*/
|
|
29
29
|
withCredentials?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Send this request WITHOUT waiting for the session restore (the auth gate).
|
|
32
|
+
*
|
|
33
|
+
* A request the gate itself depends on must set this. A gate registered with
|
|
34
|
+
* `setAuthGate` that waits for a session restore whose own request goes through this
|
|
35
|
+
* client otherwise waits on itself: the gate holds the restore's request, the restore's
|
|
36
|
+
* promise never settles, and every request on the page stalls until the gate times out —
|
|
37
|
+
* so pass `skipAuthGate: true` on the restore's own request:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // the request the gate's restore makes, through the same client the gate holds back
|
|
41
|
+
* await http.get(currentUserEndpoint, { skipAuthGate: true })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* `@molecule/app-auth`'s own restore does not need it — it sends its request with
|
|
45
|
+
* `fetch`, not through this client. An app with its own session store that registers a
|
|
46
|
+
* gate with `setAuthGate` does.
|
|
47
|
+
*/
|
|
48
|
+
skipAuthGate?: boolean;
|
|
30
49
|
/**
|
|
31
50
|
* Response type.
|
|
32
51
|
*/
|
|
@@ -44,6 +63,29 @@ export interface RequestConfig {
|
|
|
44
63
|
*/
|
|
45
64
|
options?: Record<string, unknown>;
|
|
46
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* What the auth gate is told about the request it is about to hold: whether the request
|
|
68
|
+
* opts out of the wait, and how to name it in the stalled-gate report.
|
|
69
|
+
*
|
|
70
|
+
* A request's own `RequestConfig` satisfies this — the providers pass it straight through
|
|
71
|
+
* (`awaitAuthGate(requestConfig)`), so a provider never has to build one by hand.
|
|
72
|
+
*/
|
|
73
|
+
export interface AuthGateRequest {
|
|
74
|
+
/**
|
|
75
|
+
* Send this request without waiting for the gate at all — see
|
|
76
|
+
* `RequestConfig.skipAuthGate`.
|
|
77
|
+
*/
|
|
78
|
+
skipAuthGate?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The request's HTTP method, for the message logged when the gate never settles.
|
|
81
|
+
*/
|
|
82
|
+
method?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The request's URL, for the message logged when the gate never settles. A URL may carry
|
|
85
|
+
* an id; it never carries a credential (tokens travel in headers).
|
|
86
|
+
*/
|
|
87
|
+
url?: string;
|
|
88
|
+
}
|
|
47
89
|
/**
|
|
48
90
|
* Full request configuration including method and URL.
|
|
49
91
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO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;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAElB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC;;OAEG;IACH,IAAI,EAAE,CAAC,CAAA;IAEP;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE/B;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAA;CAC1B;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAGzB,MAAM,EAAE,MAAM;IACd,QAAQ,CAAC,EAAE,YAAY;IACvB,MAAM,CAAC,EAAE,iBAAiB;IAC1B,QAAQ,CAAC,EAAE,MAAM;gBAJxB,OAAO,EAAE,MAAM,EACR,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,YAAY,YAAA,EACvB,MAAM,CAAC,EAAE,iBAAiB,YAAA,EAC1B,QAAQ,CAAC,EAAE,MAAM,YAAA;CAK3B"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoJH;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGzB;IACA;IACA;IACA;IALT,YACE,OAAe,EACR,MAAc,EACd,QAAuB,EACvB,MAA0B,EAC1B,QAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAe;QACvB,WAAM,GAAN,MAAM,CAAoB;QAC1B,aAAQ,GAAR,QAAQ,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IACzB,CAAC;CACF"}
|