@ultimat3/core 31.18.1 → 31.20.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 +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/session-lost.ts +2 -4
- package/src/session-refusal.ts +31 -0
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ JSON.stringify({ dsn }); // the value never prints: a Secret redacts by value, a
|
|
|
43
43
|
| the per-tab page handle (`globalThis[Symbol.for('ultimate.client')]`) records land in | `record-sink.ts` |
|
|
44
44
|
| which principal the page acts for, and the epoch that moves when it changes | `client-scope.ts` |
|
|
45
45
|
| whether the page's session is lost — the first `X_UNAUTHENTICATED` / `X_SESSION_EXPIRED` on a page rendered for a principal, said once (`onSessionLost`, `sessionIsLost`), cleared by `rescope()`; on `./page` | `session-lost.ts` |
|
|
46
|
+
| whether a thrown value or a wire code says "this credential names no session" — `X_UNAUTHENTICATED` / `X_SESSION_EXPIRED`, the one list (`isSessionRefusal`, `isSessionRefusalCode`). The http `auth` stage reads such a throw from an authenticator as anonymous, the realtime sweep as a revocation | `session-refusal.ts` |
|
|
46
47
|
| a poll a hidden tab and a lost session stop — `visibleInterval(run, ms, { maxMs? })`: no call while hidden, one when shown, a failed run doubling the wait up to `maxMs` (jittered) and a success resetting it, an idempotent disposer; on `./page` (6,045 B alone, `page-bundle.test.ts`) | `visible-interval.ts` |
|
|
47
48
|
| which row survives a conflict — `server-wins`, `last-write-wins`, `custom` | `conflict-policy.ts` |
|
|
48
49
|
| the four shapes an async region can be in | `async-state.ts` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/core",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.20.0",
|
|
4
4
|
"description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"test": "bun test"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@ultimat3/schema": "31.
|
|
57
|
+
"@ultimat3/schema": "31.20.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/index.ts
CHANGED
|
@@ -950,6 +950,7 @@ export {
|
|
|
950
950
|
type ServiceFactory,
|
|
951
951
|
} from './service';
|
|
952
952
|
export { onSessionLost, sessionIsLost } from './session-lost';
|
|
953
|
+
export { isSessionRefusal, isSessionRefusalCode } from './session-refusal';
|
|
953
954
|
export type { FlightJoin, Scheduler, SingleFlight, SingleFlightOptions } from './single-flight';
|
|
954
955
|
export { singleFlight } from './single-flight';
|
|
955
956
|
export { ambientClock, noWaitClock } from './sleep-clock';
|
package/src/session-lost.ts
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { onRescope } from './client-scope';
|
|
8
8
|
import { sessionLostCell } from './record-sink';
|
|
9
|
-
|
|
10
|
-
/** The two codes that mean the credential this page was rendered with no longer resolves. */
|
|
11
|
-
const LOSS_CODES: ReadonlySet<string> = new Set(['X_UNAUTHENTICATED', 'X_SESSION_EXPIRED']);
|
|
9
|
+
import { SESSION_REFUSAL_CODES } from './session-refusal';
|
|
12
10
|
|
|
13
11
|
/** Whether a refusal has said this page's session is gone. `rescope()` clears it. */
|
|
14
12
|
export function sessionIsLost(): boolean {
|
|
@@ -81,7 +79,7 @@ export interface Refusal {
|
|
|
81
79
|
*/
|
|
82
80
|
export function noteRefusal(refusal: Refusal, principal: string | null | undefined): void {
|
|
83
81
|
if (typeof principal !== 'string' || refusal.status !== 401) return;
|
|
84
|
-
if (!
|
|
82
|
+
if (!SESSION_REFUSAL_CODES.has(refusal.code) || !isPageOrigin(refusal.url)) return;
|
|
85
83
|
const cell = sessionLostCell();
|
|
86
84
|
if (cell.lost) return;
|
|
87
85
|
cell.lost = true;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "This credential names no session", decided once. An authenticator answers it with `null` or by
|
|
3
|
+
* throwing one of these codes; every host — the http `auth` stage, the realtime re-auth sweep, the
|
|
4
|
+
* page's session-lost flag — reads both as the same answer, never as a backend failure.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isUltimateError } from './errors';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `@ultimat3/auth`'s two session refusals: `X_SESSION_EXPIRED` past either clock,
|
|
11
|
+
* `X_UNAUTHENTICATED` for a session unknown, revoked, forged or whose user is disabled. Exported
|
|
12
|
+
* inside core only, never from `index.ts`: `session-lost.ts` reads the set directly, because a
|
|
13
|
+
* function wrapper around it cost every page bundle 28 B and bought no behaviour.
|
|
14
|
+
*/
|
|
15
|
+
export const SESSION_REFUSAL_CODES: ReadonlySet<string> = new Set([
|
|
16
|
+
'X_UNAUTHENTICATED',
|
|
17
|
+
'X_SESSION_EXPIRED',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
/** Whether a wire code — a 401's `code` — says the credential names no session. */
|
|
21
|
+
export function isSessionRefusalCode(code: string): boolean {
|
|
22
|
+
return SESSION_REFUSAL_CODES.has(code);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a thrown value is an authenticator's "no session" rather than a failure. Only a coded
|
|
27
|
+
* `UltimateError` counts: a plain object with a `code` field is not one this framework raised.
|
|
28
|
+
*/
|
|
29
|
+
export function isSessionRefusal(thrown: unknown): boolean {
|
|
30
|
+
return isUltimateError(thrown) && SESSION_REFUSAL_CODES.has(thrown.code);
|
|
31
|
+
}
|