@oxyhq/core 3.4.16 → 3.4.18
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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/AuthManager.js +5 -0
- package/dist/cjs/HttpService.js +4 -1
- package/dist/cjs/mixins/OxyServices.auth.js +1 -1
- package/dist/cjs/mixins/OxyServices.sso.js +2 -1
- package/dist/cjs/mixins/OxyServices.user.js +1 -1
- package/dist/cjs/utils/accountUtils.js +16 -11
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/AuthManager.js +5 -0
- package/dist/esm/HttpService.js +4 -1
- package/dist/esm/mixins/OxyServices.auth.js +1 -1
- package/dist/esm/mixins/OxyServices.sso.js +2 -1
- package/dist/esm/mixins/OxyServices.user.js +1 -1
- package/dist/esm/utils/accountUtils.js +16 -11
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/mixins/OxyServices.user.d.ts +5 -8
- package/dist/types/models/interfaces.d.ts +11 -12
- package/dist/types/models/session.d.ts +2 -0
- package/dist/types/utils/accountUtils.d.ts +10 -7
- package/package.json +2 -2
- package/src/AuthManager.ts +6 -1
- package/src/HttpService.ts +4 -1
- package/src/__tests__/httpServiceCsrf.test.ts +68 -0
- package/src/mixins/OxyServices.auth.ts +1 -1
- package/src/mixins/OxyServices.sso.ts +4 -1
- package/src/mixins/OxyServices.user.ts +5 -4
- package/src/models/interfaces.ts +11 -12
- package/src/models/session.ts +3 -0
- package/src/utils/__tests__/accountUtils.test.ts +3 -4
- package/src/utils/accountUtils.ts +26 -15
package/dist/esm/AuthManager.js
CHANGED
|
@@ -397,6 +397,7 @@ export class AuthManager {
|
|
|
397
397
|
user: {
|
|
398
398
|
id: session.user.id,
|
|
399
399
|
username: session.user.username,
|
|
400
|
+
name: session.user.name,
|
|
400
401
|
avatar: session.user.avatar ?? null,
|
|
401
402
|
},
|
|
402
403
|
accessToken: session.accessToken,
|
|
@@ -628,6 +629,7 @@ export class AuthManager {
|
|
|
628
629
|
return {
|
|
629
630
|
id: account.user.id,
|
|
630
631
|
username: account.user.username,
|
|
632
|
+
name: account.user.name,
|
|
631
633
|
avatar: account.user.avatar ?? undefined,
|
|
632
634
|
};
|
|
633
635
|
}
|
|
@@ -672,6 +674,7 @@ export class AuthManager {
|
|
|
672
674
|
this.currentUser = {
|
|
673
675
|
id: hydrated.id,
|
|
674
676
|
username: hydrated.username,
|
|
677
|
+
name: hydrated.name,
|
|
675
678
|
avatar: hydrated.avatar ?? undefined,
|
|
676
679
|
};
|
|
677
680
|
this.notifyListeners();
|
|
@@ -873,6 +876,7 @@ export class AuthManager {
|
|
|
873
876
|
? {
|
|
874
877
|
id: updated.user.id,
|
|
875
878
|
username: updated.user.username,
|
|
879
|
+
name: updated.user.name,
|
|
876
880
|
avatar: updated.user.avatar ?? undefined,
|
|
877
881
|
}
|
|
878
882
|
: null;
|
|
@@ -928,6 +932,7 @@ export class AuthManager {
|
|
|
928
932
|
? {
|
|
929
933
|
id: next.user.id,
|
|
930
934
|
username: next.user.username,
|
|
935
|
+
name: next.user.name,
|
|
931
936
|
avatar: next.user.avatar ?? undefined,
|
|
932
937
|
}
|
|
933
938
|
: null;
|
package/dist/esm/HttpService.js
CHANGED
|
@@ -697,7 +697,10 @@ export class HttpService {
|
|
|
697
697
|
const refreshed = await this.refreshAccessToken('preflight');
|
|
698
698
|
if (refreshed)
|
|
699
699
|
return `Bearer ${refreshed}`;
|
|
700
|
-
|
|
700
|
+
if (decoded.exp > currentTime) {
|
|
701
|
+
return `Bearer ${accessToken}`;
|
|
702
|
+
}
|
|
703
|
+
// Refresh failed — don't use an expired token (would cause 401 loop)
|
|
701
704
|
return null;
|
|
702
705
|
}
|
|
703
706
|
return `Bearer ${accessToken}`;
|
|
@@ -489,7 +489,7 @@ export function OxyServicesAuthMixin(Base) {
|
|
|
489
489
|
continue;
|
|
490
490
|
}
|
|
491
491
|
const userId = e.user.id ?? e.user._id;
|
|
492
|
-
if (!userId || !e.user.username) {
|
|
492
|
+
if (!userId || !e.user.username || !e.user.name?.displayName) {
|
|
493
493
|
continue;
|
|
494
494
|
}
|
|
495
495
|
if (typeof e.authuser !== 'number') {
|
|
@@ -111,12 +111,13 @@ export function OxyServicesSsoMixin(Base) {
|
|
|
111
111
|
throw this.handleError(new Error('SSO exchange returned no sessionId'));
|
|
112
112
|
}
|
|
113
113
|
const userId = payload.user?.id ?? payload.user?._id;
|
|
114
|
-
if (!userId || typeof payload.user?.username !== 'string') {
|
|
114
|
+
if (!userId || typeof payload.user?.username !== 'string' || typeof payload.user.name?.displayName !== 'string') {
|
|
115
115
|
throw this.handleError(new Error('SSO exchange returned an invalid user'));
|
|
116
116
|
}
|
|
117
117
|
const user = {
|
|
118
118
|
id: userId,
|
|
119
119
|
username: payload.user.username,
|
|
120
|
+
name: payload.user.name,
|
|
120
121
|
avatar: payload.user.avatar,
|
|
121
122
|
};
|
|
122
123
|
// Plant the access token exactly like exchangeIdTokenForSession does.
|
|
@@ -24,7 +24,7 @@ export function OxyServicesUserMixin(Base) {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Lightweight username lookup for login flows.
|
|
27
|
-
* Returns minimal public info: exists, color, avatar, displayName.
|
|
27
|
+
* Returns minimal public info: exists, color, avatar, name.displayName.
|
|
28
28
|
* Faster than getProfileByUsername — no stats, no formatting.
|
|
29
29
|
*/
|
|
30
30
|
async lookupUsername(username) {
|
|
@@ -17,12 +17,13 @@ export const formatPublicKeyHandle = (publicKey) => {
|
|
|
17
17
|
* Resolve a friendly display name for a user.
|
|
18
18
|
*
|
|
19
19
|
* Order of preference:
|
|
20
|
-
* 1. `displayName` from the API contract.
|
|
20
|
+
* 1. `name.displayName` from the API user contract.
|
|
21
21
|
* 2. `name.full`, or composed `name.first name.last` for local unsaved shapes.
|
|
22
|
-
* 3. `name` when
|
|
23
|
-
* 4. `
|
|
24
|
-
* 5. `
|
|
25
|
-
* 6.
|
|
22
|
+
* 3. `name` when passed as a plain string by local non-DTO call sites.
|
|
23
|
+
* 4. pre-normalized account-row `displayName`.
|
|
24
|
+
* 5. `username`
|
|
25
|
+
* 6. `Account 0x12345678…` (derived from publicKey, when present)
|
|
26
|
+
* 7. Translated fallback (e.g. "Unnamed")
|
|
26
27
|
*
|
|
27
28
|
* The translation key `common.unnamed` is used for the final fallback. If the
|
|
28
29
|
* caller does not pass a locale, the default English translation is used.
|
|
@@ -31,9 +32,10 @@ export const getAccountDisplayName = (user, locale) => {
|
|
|
31
32
|
if (!user)
|
|
32
33
|
return translate(locale, 'common.unnamed');
|
|
33
34
|
const { name, displayName, username, publicKey } = user;
|
|
34
|
-
if (typeof displayName === 'string' && displayName.trim())
|
|
35
|
-
return displayName.trim();
|
|
36
35
|
if (name && typeof name === 'object') {
|
|
36
|
+
if (typeof name.displayName === 'string' && name.displayName.trim()) {
|
|
37
|
+
return name.displayName.trim();
|
|
38
|
+
}
|
|
37
39
|
if (typeof name.full === 'string' && name.full.trim())
|
|
38
40
|
return name.full.trim();
|
|
39
41
|
const first = typeof name.first === 'string' ? name.first.trim() : '';
|
|
@@ -45,6 +47,8 @@ export const getAccountDisplayName = (user, locale) => {
|
|
|
45
47
|
else if (typeof name === 'string' && name.trim()) {
|
|
46
48
|
return name.trim();
|
|
47
49
|
}
|
|
50
|
+
if (typeof displayName === 'string' && displayName.trim())
|
|
51
|
+
return displayName.trim();
|
|
48
52
|
if (typeof username === 'string' && username.trim())
|
|
49
53
|
return username.trim();
|
|
50
54
|
if (typeof publicKey === 'string' && publicKey.length > 0) {
|
|
@@ -96,18 +100,19 @@ export const createQuickAccount = (sessionId, userData, existingAccount, getFile
|
|
|
96
100
|
const userId = userData.id || (typeof userData._id === 'string' ? userData._id : userData._id?.toString());
|
|
97
101
|
// Preserve existing avatarUrl if avatar hasn't changed (prevents image reload)
|
|
98
102
|
let avatarUrl;
|
|
99
|
-
|
|
103
|
+
const avatar = userData.avatar ?? undefined;
|
|
104
|
+
if (existingAccount && existingAccount.avatar === avatar && existingAccount.avatarUrl) {
|
|
100
105
|
avatarUrl = existingAccount.avatarUrl;
|
|
101
106
|
}
|
|
102
|
-
else if (
|
|
103
|
-
avatarUrl = getFileDownloadUrl(
|
|
107
|
+
else if (avatar && getFileDownloadUrl) {
|
|
108
|
+
avatarUrl = getFileDownloadUrl(avatar, 'thumb');
|
|
104
109
|
}
|
|
105
110
|
return {
|
|
106
111
|
sessionId,
|
|
107
112
|
userId,
|
|
108
113
|
username: userData.username || '',
|
|
109
114
|
displayName,
|
|
110
|
-
avatar
|
|
115
|
+
avatar,
|
|
111
116
|
avatarUrl,
|
|
112
117
|
};
|
|
113
118
|
};
|