@wvdsh/sdk-js 1.3.7 → 1.3.8
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/index.d.ts +10 -11
- package/dist/index.js +51 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -702,18 +702,8 @@ declare class OverlayManager extends WavedashManager {
|
|
|
702
702
|
|
|
703
703
|
declare class FriendsManager extends WavedashManager {
|
|
704
704
|
private userCache;
|
|
705
|
+
private leaderboardPageUserCache;
|
|
705
706
|
constructor(sdk: WavedashSDK);
|
|
706
|
-
/**
|
|
707
|
-
* Cache users from any source (friends, lobby users)
|
|
708
|
-
* Accepts both Friend format (avatarUrl) and LobbyUser format (userAvatarUrl)
|
|
709
|
-
* @param users - Array of users with userId, username, and optional avatar r2Key
|
|
710
|
-
*/
|
|
711
|
-
cacheUsers(users: Array<{
|
|
712
|
-
userId: GenericId<"users">;
|
|
713
|
-
username: string;
|
|
714
|
-
avatarUrl?: string;
|
|
715
|
-
userAvatarUrl?: string;
|
|
716
|
-
}>): void;
|
|
717
707
|
/**
|
|
718
708
|
* Returns CDN URL with size transformation for a cached user's avatar.
|
|
719
709
|
* @param userId - The user ID to get the avatar URL for
|
|
@@ -728,6 +718,15 @@ declare class FriendsManager extends WavedashManager {
|
|
|
728
718
|
* @returns The username, or null if user not cached
|
|
729
719
|
*/
|
|
730
720
|
getUsername(userId: GenericId<"users">): string | null;
|
|
721
|
+
/**
|
|
722
|
+
* List all friends for the logged in user
|
|
723
|
+
* @returns Array<{
|
|
724
|
+
* avatarUrl?: string;
|
|
725
|
+
* isOnline: boolean;
|
|
726
|
+
* userId: Id<"users">;
|
|
727
|
+
* username: string;
|
|
728
|
+
* }>
|
|
729
|
+
*/
|
|
731
730
|
listFriends(): Promise<Friend[]>;
|
|
732
731
|
}
|
|
733
732
|
|
package/dist/index.js
CHANGED
|
@@ -1063,7 +1063,8 @@ var LeaderboardManager = class extends WavedashManager {
|
|
|
1063
1063
|
const entry = result.entry ? {
|
|
1064
1064
|
...result.entry,
|
|
1065
1065
|
userId: this.sdk.wavedashUser.id,
|
|
1066
|
-
username: this.sdk.wavedashUser.username
|
|
1066
|
+
username: this.sdk.wavedashUser.username,
|
|
1067
|
+
userAvatarUrl: this.sdk.wavedashUser.avatarUrl
|
|
1067
1068
|
} : null;
|
|
1068
1069
|
return entry ? [entry] : [];
|
|
1069
1070
|
}
|
|
@@ -1075,6 +1076,7 @@ var LeaderboardManager = class extends WavedashManager {
|
|
|
1075
1076
|
if (result && result.totalEntries) {
|
|
1076
1077
|
this.updateCachedTotalEntries(leaderboardId, result.totalEntries);
|
|
1077
1078
|
}
|
|
1079
|
+
this.sdk.friendsManager.cacheLeaderboardPage(result.entries);
|
|
1078
1080
|
return result.entries;
|
|
1079
1081
|
}
|
|
1080
1082
|
async listLeaderboardEntries(leaderboardId, offset, limit, friendsOnly = false) {
|
|
@@ -1085,6 +1087,7 @@ var LeaderboardManager = class extends WavedashManager {
|
|
|
1085
1087
|
if (result && result.totalEntries) {
|
|
1086
1088
|
this.updateCachedTotalEntries(leaderboardId, result.totalEntries);
|
|
1087
1089
|
}
|
|
1090
|
+
this.sdk.friendsManager.cacheLeaderboardPage(result.entries);
|
|
1088
1091
|
return result.entries;
|
|
1089
1092
|
}
|
|
1090
1093
|
async uploadLeaderboardScore(leaderboardId, score, keepBest, ugcId) {
|
|
@@ -3009,21 +3012,10 @@ function getCdnImageUrl(r2Key, host, options) {
|
|
|
3009
3012
|
var FriendsManager = class extends WavedashManager {
|
|
3010
3013
|
constructor(sdk) {
|
|
3011
3014
|
super(sdk);
|
|
3015
|
+
// Persistent cache for users with a durable relationship (self, friends, shared lobby).
|
|
3012
3016
|
this.userCache = /* @__PURE__ */ new Map();
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
* Cache users from any source (friends, lobby users)
|
|
3016
|
-
* Accepts both Friend format (avatarUrl) and LobbyUser format (userAvatarUrl)
|
|
3017
|
-
* @param users - Array of users with userId, username, and optional avatar r2Key
|
|
3018
|
-
*/
|
|
3019
|
-
cacheUsers(users) {
|
|
3020
|
-
for (const user of users) {
|
|
3021
|
-
this.userCache.set(user.userId, {
|
|
3022
|
-
username: user.username,
|
|
3023
|
-
// Support both Friend (avatarUrl) and LobbyUser (userAvatarUrl) formats
|
|
3024
|
-
avatarR2Key: user.avatarUrl ?? user.userAvatarUrl
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3017
|
+
// Transient cache for only the most recently loaded leaderboard page. Cleared on each new page.
|
|
3018
|
+
this.leaderboardPageUserCache = /* @__PURE__ */ new Map();
|
|
3027
3019
|
}
|
|
3028
3020
|
/**
|
|
3029
3021
|
* Returns CDN URL with size transformation for a cached user's avatar.
|
|
@@ -3033,7 +3025,7 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3033
3025
|
* @returns CDN URL with size transformation, or null if user not cached or has no avatar
|
|
3034
3026
|
*/
|
|
3035
3027
|
getUserAvatarUrl(userId, size = AvatarSize.MEDIUM) {
|
|
3036
|
-
const user = this.userCache.get(userId);
|
|
3028
|
+
const user = this.userCache.get(userId) ?? this.leaderboardPageUserCache.get(userId);
|
|
3037
3029
|
if (!user?.avatarR2Key) {
|
|
3038
3030
|
return null;
|
|
3039
3031
|
}
|
|
@@ -3051,8 +3043,17 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3051
3043
|
* @returns The username, or null if user not cached
|
|
3052
3044
|
*/
|
|
3053
3045
|
getUsername(userId) {
|
|
3054
|
-
return this.userCache.get(userId)?.username ?? null;
|
|
3046
|
+
return this.userCache.get(userId)?.username ?? this.leaderboardPageUserCache.get(userId)?.username ?? null;
|
|
3055
3047
|
}
|
|
3048
|
+
/**
|
|
3049
|
+
* List all friends for the logged in user
|
|
3050
|
+
* @returns Array<{
|
|
3051
|
+
* avatarUrl?: string;
|
|
3052
|
+
* isOnline: boolean;
|
|
3053
|
+
* userId: Id<"users">;
|
|
3054
|
+
* username: string;
|
|
3055
|
+
* }>
|
|
3056
|
+
*/
|
|
3056
3057
|
async listFriends() {
|
|
3057
3058
|
const friends = await this.sdk.convexClient.query(
|
|
3058
3059
|
api8.sdk.friends.listFriends,
|
|
@@ -3061,6 +3062,39 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3061
3062
|
this.cacheUsers(friends);
|
|
3062
3063
|
return friends;
|
|
3063
3064
|
}
|
|
3065
|
+
/**
|
|
3066
|
+
* Cache users from any source (friends, lobby users)
|
|
3067
|
+
* Accepts both Friend format (avatarUrl) and LobbyUser format (userAvatarUrl)
|
|
3068
|
+
* @param users - Array of users with userId, username, and optional avatar r2Key
|
|
3069
|
+
* @internal
|
|
3070
|
+
*/
|
|
3071
|
+
cacheUsers(users) {
|
|
3072
|
+
for (const user of users) {
|
|
3073
|
+
this.userCache.set(user.userId, {
|
|
3074
|
+
username: user.username,
|
|
3075
|
+
// Support both Friend (avatarUrl) and LobbyUser (userAvatarUrl) formats
|
|
3076
|
+
avatarR2Key: user.avatarUrl ?? user.userAvatarUrl
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
/**
|
|
3081
|
+
* Replace the leaderboard-page cache with the users from a single page of
|
|
3082
|
+
* leaderboard entries.
|
|
3083
|
+
*
|
|
3084
|
+
* In general devs should just use the username and userAvatarUrl returned
|
|
3085
|
+
* from `listLeaderboardEntries` directly, but we cache the latest leaderboard
|
|
3086
|
+
* page here just so getUserAvatarUrl and getUsername still work for the current page.
|
|
3087
|
+
* @internal
|
|
3088
|
+
*/
|
|
3089
|
+
cacheLeaderboardPage(users) {
|
|
3090
|
+
this.leaderboardPageUserCache.clear();
|
|
3091
|
+
for (const user of users) {
|
|
3092
|
+
this.leaderboardPageUserCache.set(user.userId, {
|
|
3093
|
+
username: user.username,
|
|
3094
|
+
avatarR2Key: user.userAvatarUrl
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3064
3098
|
};
|
|
3065
3099
|
|
|
3066
3100
|
// src/utils/logger.ts
|