@wvdsh/sdk-js 1.3.6 → 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 +11 -11
- package/dist/index.js +53 -18
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ type LeaderboardEntries = FunctionReturnType<typeof api.sdk.leaderboards.listEnt
|
|
|
82
82
|
type UpsertedLeaderboardEntry = FunctionReturnType<typeof api.sdk.leaderboards.upsertLeaderboardEntry>["entry"] & {
|
|
83
83
|
userId: GenericId<"users">;
|
|
84
84
|
username: string;
|
|
85
|
+
userAvatarUrl?: string;
|
|
85
86
|
};
|
|
86
87
|
type WavedashEvent = (typeof WavedashEvents)[keyof typeof WavedashEvents];
|
|
87
88
|
interface WavedashConfig {
|
|
@@ -701,18 +702,8 @@ declare class OverlayManager extends WavedashManager {
|
|
|
701
702
|
|
|
702
703
|
declare class FriendsManager extends WavedashManager {
|
|
703
704
|
private userCache;
|
|
705
|
+
private leaderboardPageUserCache;
|
|
704
706
|
constructor(sdk: WavedashSDK);
|
|
705
|
-
/**
|
|
706
|
-
* Cache users from any source (friends, lobby users)
|
|
707
|
-
* Accepts both Friend format (avatarUrl) and LobbyUser format (userAvatarUrl)
|
|
708
|
-
* @param users - Array of users with userId, username, and optional avatar r2Key
|
|
709
|
-
*/
|
|
710
|
-
cacheUsers(users: Array<{
|
|
711
|
-
userId: GenericId<"users">;
|
|
712
|
-
username: string;
|
|
713
|
-
avatarUrl?: string;
|
|
714
|
-
userAvatarUrl?: string;
|
|
715
|
-
}>): void;
|
|
716
707
|
/**
|
|
717
708
|
* Returns CDN URL with size transformation for a cached user's avatar.
|
|
718
709
|
* @param userId - The user ID to get the avatar URL for
|
|
@@ -727,6 +718,15 @@ declare class FriendsManager extends WavedashManager {
|
|
|
727
718
|
* @returns The username, or null if user not cached
|
|
728
719
|
*/
|
|
729
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
|
+
*/
|
|
730
730
|
listFriends(): Promise<Friend[]>;
|
|
731
731
|
}
|
|
732
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) {
|
|
@@ -1098,7 +1101,8 @@ var LeaderboardManager = class extends WavedashManager {
|
|
|
1098
1101
|
return {
|
|
1099
1102
|
...result.entry,
|
|
1100
1103
|
userId: this.sdk.wavedashUser.id,
|
|
1101
|
-
username: this.sdk.wavedashUser.username
|
|
1104
|
+
username: this.sdk.wavedashUser.username,
|
|
1105
|
+
userAvatarUrl: this.sdk.wavedashUser.avatarUrl
|
|
1102
1106
|
};
|
|
1103
1107
|
}
|
|
1104
1108
|
// ================
|
|
@@ -3008,21 +3012,10 @@ function getCdnImageUrl(r2Key, host, options) {
|
|
|
3008
3012
|
var FriendsManager = class extends WavedashManager {
|
|
3009
3013
|
constructor(sdk) {
|
|
3010
3014
|
super(sdk);
|
|
3015
|
+
// Persistent cache for users with a durable relationship (self, friends, shared lobby).
|
|
3011
3016
|
this.userCache = /* @__PURE__ */ new Map();
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
* Cache users from any source (friends, lobby users)
|
|
3015
|
-
* Accepts both Friend format (avatarUrl) and LobbyUser format (userAvatarUrl)
|
|
3016
|
-
* @param users - Array of users with userId, username, and optional avatar r2Key
|
|
3017
|
-
*/
|
|
3018
|
-
cacheUsers(users) {
|
|
3019
|
-
for (const user of users) {
|
|
3020
|
-
this.userCache.set(user.userId, {
|
|
3021
|
-
username: user.username,
|
|
3022
|
-
// Support both Friend (avatarUrl) and LobbyUser (userAvatarUrl) formats
|
|
3023
|
-
avatarR2Key: user.avatarUrl ?? user.userAvatarUrl
|
|
3024
|
-
});
|
|
3025
|
-
}
|
|
3017
|
+
// Transient cache for only the most recently loaded leaderboard page. Cleared on each new page.
|
|
3018
|
+
this.leaderboardPageUserCache = /* @__PURE__ */ new Map();
|
|
3026
3019
|
}
|
|
3027
3020
|
/**
|
|
3028
3021
|
* Returns CDN URL with size transformation for a cached user's avatar.
|
|
@@ -3032,7 +3025,7 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3032
3025
|
* @returns CDN URL with size transformation, or null if user not cached or has no avatar
|
|
3033
3026
|
*/
|
|
3034
3027
|
getUserAvatarUrl(userId, size = AvatarSize.MEDIUM) {
|
|
3035
|
-
const user = this.userCache.get(userId);
|
|
3028
|
+
const user = this.userCache.get(userId) ?? this.leaderboardPageUserCache.get(userId);
|
|
3036
3029
|
if (!user?.avatarR2Key) {
|
|
3037
3030
|
return null;
|
|
3038
3031
|
}
|
|
@@ -3050,8 +3043,17 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3050
3043
|
* @returns The username, or null if user not cached
|
|
3051
3044
|
*/
|
|
3052
3045
|
getUsername(userId) {
|
|
3053
|
-
return this.userCache.get(userId)?.username ?? null;
|
|
3046
|
+
return this.userCache.get(userId)?.username ?? this.leaderboardPageUserCache.get(userId)?.username ?? null;
|
|
3054
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
|
+
*/
|
|
3055
3057
|
async listFriends() {
|
|
3056
3058
|
const friends = await this.sdk.convexClient.query(
|
|
3057
3059
|
api8.sdk.friends.listFriends,
|
|
@@ -3060,6 +3062,39 @@ var FriendsManager = class extends WavedashManager {
|
|
|
3060
3062
|
this.cacheUsers(friends);
|
|
3061
3063
|
return friends;
|
|
3062
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
|
+
}
|
|
3063
3098
|
};
|
|
3064
3099
|
|
|
3065
3100
|
// src/utils/logger.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wvdsh/sdk-js",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Wavedash JavaScript SDK",
|
|
6
6
|
"main": "./dist/client.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript-eslint": "^8.52.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@wvdsh/api": "^0.1.
|
|
52
|
+
"@wvdsh/api": "^0.1.16",
|
|
53
53
|
"convex": "^1.34.0",
|
|
54
54
|
"lodash.throttle": "^4.1.1"
|
|
55
55
|
}
|