@oxyhq/core 8.1.0 → 9.1.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 -3
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/boot/coldBootV2.js +22 -332
- package/dist/cjs/crypto/keyManager.js +0 -95
- package/dist/cjs/index.js +6 -19
- package/dist/cjs/mixins/OxyServices.auth.js +4 -7
- package/dist/cjs/mixins/OxyServices.deviceBoot.js +19 -115
- package/dist/cjs/mixins/index.js +2 -3
- package/dist/cjs/session/SessionClient.js +29 -100
- package/dist/cjs/session/accountDialogController.js +0 -13
- package/dist/cjs/session/authStateStore.js +9 -89
- package/dist/cjs/session/createSessionClient.js +2 -9
- package/dist/cjs/session/refresh.js +46 -71
- package/dist/cjs/utils/registrableApex.js +2 -6
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/boot/coldBootV2.js +23 -330
- package/dist/esm/crypto/keyManager.js +0 -95
- package/dist/esm/index.js +7 -11
- package/dist/esm/mixins/OxyServices.auth.js +4 -7
- package/dist/esm/mixins/OxyServices.deviceBoot.js +20 -116
- package/dist/esm/mixins/index.js +2 -3
- package/dist/esm/session/SessionClient.js +29 -100
- package/dist/esm/session/accountDialogController.js +0 -13
- package/dist/esm/session/authStateStore.js +8 -88
- package/dist/esm/session/createSessionClient.js +2 -9
- package/dist/esm/session/refresh.js +46 -71
- package/dist/esm/utils/registrableApex.js +2 -6
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +3 -3
- package/dist/types/boot/coldBootV2.d.ts +28 -53
- package/dist/types/crypto/keyManager.d.ts +0 -21
- package/dist/types/index.d.ts +3 -5
- package/dist/types/mixins/OxyServices.auth.d.ts +4 -7
- package/dist/types/mixins/OxyServices.deviceBoot.d.ts +20 -60
- package/dist/types/models/interfaces.d.ts +15 -0
- package/dist/types/session/SessionClient.d.ts +6 -40
- package/dist/types/session/accountDialogController.d.ts +1 -3
- package/dist/types/session/authStateStore.d.ts +32 -57
- package/dist/types/session/createSessionClient.d.ts +2 -9
- package/dist/types/session/refresh.d.ts +32 -28
- package/dist/types/utils/registrableApex.d.ts +2 -6
- package/package.json +3 -3
- package/src/HttpService.ts +3 -3
- package/src/boot/__tests__/coldBootV2.test.ts +140 -353
- package/src/boot/coldBootV2.ts +35 -391
- package/src/crypto/keyManager.ts +0 -101
- package/src/index.ts +7 -30
- package/src/mixins/OxyServices.auth.ts +5 -9
- package/src/mixins/OxyServices.deviceBoot.ts +19 -142
- package/src/mixins/__tests__/OxyServices.deviceBoot.test.ts +9 -96
- package/src/mixins/__tests__/onTokensChanged.test.ts +0 -1
- package/src/mixins/__tests__/passwordSignIn.test.ts +33 -9
- package/src/mixins/index.ts +2 -3
- package/src/models/interfaces.ts +15 -0
- package/src/session/SessionClient.ts +31 -122
- package/src/session/__tests__/SessionClient.broadcastChannel.test.ts +113 -0
- package/src/session/__tests__/SessionClient.socket.test.ts +8 -8
- package/src/session/__tests__/authStateStore.test.ts +29 -42
- package/src/session/__tests__/refresh.test.ts +66 -52
- package/src/session/accountDialogController.ts +4 -18
- package/src/session/authStateStore.ts +32 -126
- package/src/session/createSessionClient.ts +2 -9
- package/src/session/refresh.ts +60 -92
- package/src/utils/registrableApex.ts +2 -6
- package/dist/cjs/boot/deviceBootReturn.js +0 -167
- package/dist/esm/boot/deviceBootReturn.js +0 -161
- package/dist/types/boot/deviceBootReturn.d.ts +0 -83
- package/src/boot/__tests__/deviceBootReturn.test.ts +0 -190
- package/src/boot/deviceBootReturn.ts +0 -210
- package/src/crypto/__tests__/sharedDeviceToken.test.ts +0 -24
- package/src/session/__tests__/SessionClient.signedOut.test.ts +0 -224
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unified token refresh — THE single
|
|
2
|
+
* Unified token refresh — THE single access-token re-mint for web + native.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
4
|
+
* The access token is short-lived; there is no refresh token. To keep a session
|
|
5
|
+
* alive past the access token's TTL the client re-mints via the zero-cookie
|
|
6
|
+
* device transport:
|
|
6
7
|
*
|
|
7
|
-
* - `refreshPersistedSession` — arm 1
|
|
8
|
-
* (`POST /
|
|
9
|
-
* (native only) re-mints via
|
|
10
|
-
*
|
|
11
|
-
* `AuthRefreshHandler` installed on `HttpService`)
|
|
12
|
-
*
|
|
8
|
+
* - `refreshPersistedSession` — arm 1 mints a fresh access token from the
|
|
9
|
+
* persisted `deviceId` + `deviceSecret` (`POST /session/device/token`),
|
|
10
|
+
* planting + persisting the rotated secret; arm 2 (native only) re-mints via
|
|
11
|
+
* the shared-keychain identity when there is no usable secret. It is used BOTH
|
|
12
|
+
* reactively (wrapped as the `AuthRefreshHandler` installed on `HttpService`)
|
|
13
|
+
* AND proactively (the scheduler below calls it).
|
|
13
14
|
* - `createAuthRefreshHandler` / `installAuthRefreshHandler` wire arm 1+2 into
|
|
14
15
|
* `HttpService.setAuthRefreshHandler`, keeping that layer's single-flight
|
|
15
16
|
* dedup + cooldown (this module does NOT reimplement them).
|
|
16
17
|
* - `startTokenRefreshScheduler` — a proactive scheduler decoupled from any
|
|
17
|
-
* React type:
|
|
18
|
-
*
|
|
18
|
+
* React type: re-mints ~60s before `exp`, re-arms on token change + web
|
|
19
|
+
* tab-focus, `.unref?.()`s its timer in Node.
|
|
19
20
|
*
|
|
20
21
|
* Framework-free; no module-level mutable state.
|
|
21
22
|
*/
|
|
@@ -24,33 +25,36 @@ import type { AuthRefreshHandler } from '../HttpService';
|
|
|
24
25
|
import type { AuthStateStore } from './authStateStore';
|
|
25
26
|
/**
|
|
26
27
|
* Lead time (ms) before access-token expiry at which the proactive scheduler
|
|
27
|
-
*
|
|
28
|
-
* (60s) so the scheduled
|
|
29
|
-
*
|
|
28
|
+
* re-mints. Mirrors `HttpService`'s per-request `TOKEN_REFRESH_LEAD_SECONDS`
|
|
29
|
+
* (60s) so the scheduled re-mint and the request-time preflight use the same
|
|
30
|
+
* window — the scheduler just fires it during idle/background.
|
|
30
31
|
*/
|
|
31
32
|
export declare const TOKEN_REFRESH_LEAD_MS = 60000;
|
|
32
33
|
export interface RefreshDeps {
|
|
33
34
|
oxy: OxyServices;
|
|
34
35
|
store: AuthStateStore;
|
|
35
36
|
/**
|
|
36
|
-
* Whether to fall back to the native shared-keychain re-mint (arm 2) when
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Whether to fall back to the native shared-keychain re-mint (arm 2) when the
|
|
38
|
+
* persisted secret is absent / rejected. Defaults to `isNative()` — web has no
|
|
39
|
+
* shared keychain. Exposed for tests.
|
|
39
40
|
*/
|
|
40
41
|
allowSharedKeyFallback?: boolean;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* Re-mint the persisted session and return the fresh access token, or `null`
|
|
44
45
|
* when no arm could produce one.
|
|
45
46
|
*
|
|
46
|
-
* Arm 1 (`POST /
|
|
47
|
-
*
|
|
48
|
-
*
|
|
47
|
+
* Arm 1 (`POST /session/device/token`): if the store holds a `deviceId` +
|
|
48
|
+
* `deviceSecret`, mint — on success plant + persist the rotated secret. A 401
|
|
49
|
+
* means the secret is diverged (`invalid_device_secret`) or the device has no
|
|
50
|
+
* live session (`no_active_session`): drop the secret so the mint lane stops (or
|
|
51
|
+
* clear the store on web, where there is no fallback). A transient error leaves
|
|
52
|
+
* the store and returns `null`.
|
|
49
53
|
*
|
|
50
|
-
* Arm 2 (native shared-keychain): when
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
+
* Arm 2 (native shared-keychain): when the secret is absent or was just rejected,
|
|
55
|
+
* re-mint via `signInWithSharedIdentity` (which plants tokens). The shared
|
|
56
|
+
* keychain — not the per-origin store — is the durable native credential, so this
|
|
57
|
+
* arm does not write the store.
|
|
54
58
|
*/
|
|
55
59
|
export declare function refreshPersistedSession(deps: RefreshDeps): Promise<string | null>;
|
|
56
60
|
/**
|
|
@@ -71,7 +75,7 @@ export interface TokenRefreshSchedulerHandle {
|
|
|
71
75
|
dispose(): void;
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
|
-
* Start the proactive
|
|
78
|
+
* Start the proactive re-mint scheduler against `oxy`.
|
|
75
79
|
*
|
|
76
80
|
* Schedules a single timer to fire {@link TOKEN_REFRESH_LEAD_MS} before the
|
|
77
81
|
* current access token's `exp`, calling
|
|
@@ -79,11 +83,11 @@ export interface TokenRefreshSchedulerHandle {
|
|
|
79
83
|
* handler; deduped + cooldown-guarded). After every attempt it reschedules
|
|
80
84
|
* from the possibly-rotated token. It also reschedules whenever the token
|
|
81
85
|
* changes (a sign-out that clears the token cancels the timer) and, on web
|
|
82
|
-
* tab-focus,
|
|
86
|
+
* tab-focus, re-mints immediately if already inside the lead window (a
|
|
83
87
|
* long-hidden tab throttles timers, so the token can be expired on return).
|
|
84
88
|
*
|
|
85
89
|
* No-ops cleanly when there is no token or an opaque/no-`exp` token — the
|
|
86
|
-
* reactive 401 path stays the only
|
|
90
|
+
* reactive 401 path stays the only re-mint trigger in that case. The timer is
|
|
87
91
|
* `.unref?.()`-ed so it never keeps a Node/Jest event loop alive.
|
|
88
92
|
*/
|
|
89
93
|
export declare function startTokenRefreshScheduler(oxy: OxyServices): TokenRefreshSchedulerHandle;
|
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
* The client FAPI auto-detection helper was removed in the device-first cutover
|
|
5
5
|
* (which is why this file is now named for what it actually is, not the old
|
|
6
6
|
* `fapiAutoDetect`). What survives is the pure registrable-domain kernel, still
|
|
7
|
-
* used server
|
|
8
|
-
*
|
|
9
|
-
* `isSameSiteTrustedRequest`) and the `@oxyhq/core/server` CORS/re-export layer.
|
|
10
|
-
*
|
|
11
|
-
* `registrableApex` is NOT legacy — the device-first same-apex check is a live
|
|
12
|
-
* consumer, so this kernel stays regardless of the SSO/FedCM removal.
|
|
7
|
+
* used by the `@oxyhq/core/server` CORS layer (the `*.oxy.so` same-apex trust
|
|
8
|
+
* check) and its re-export surface.
|
|
13
9
|
*/
|
|
14
10
|
/**
|
|
15
11
|
* Compute the bare registrable apex (eTLD+1) of a hostname using the Public
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxyhq/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "OxyHQ SDK Foundation — API client, authentication, cryptographic identity, and shared utilities",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@oxyhq/contracts": "^0.
|
|
98
|
-
"@oxyhq/protocol": "^0.1.
|
|
97
|
+
"@oxyhq/contracts": "^0.13.0",
|
|
98
|
+
"@oxyhq/protocol": "^0.1.3",
|
|
99
99
|
"bip39": "^3.1.0",
|
|
100
100
|
"buffer": "^6.0.3",
|
|
101
101
|
"elliptic": "^6.6.1",
|
package/src/HttpService.ts
CHANGED
|
@@ -74,13 +74,13 @@ export interface RequestOptions {
|
|
|
74
74
|
* Skip BOTH the bearer auth header (and its near-expiry preflight refresh)
|
|
75
75
|
* AND the 401-driven auto-refresh/retry for this request.
|
|
76
76
|
*
|
|
77
|
-
* Required for the body-authenticated
|
|
78
|
-
* /
|
|
77
|
+
* Required for the body-authenticated device-secret mint (`POST
|
|
78
|
+
* /session/device/token`): it does not need a bearer, and — critically — it is
|
|
79
79
|
* itself invoked from inside the registered `AuthRefreshHandler`. If it went
|
|
80
80
|
* through the normal preflight, `getAuthHeader` would call
|
|
81
81
|
* `refreshAccessToken` while the handler-owning `tokenRefreshPromise` is
|
|
82
82
|
* still in flight and await ITSELF (deadlock). Skipping auth makes the
|
|
83
|
-
*
|
|
83
|
+
* mint call fully independent of the current (near-expired) bearer.
|
|
84
84
|
*/
|
|
85
85
|
skipAuth?: boolean;
|
|
86
86
|
}
|