-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.service.ts
More file actions
294 lines (278 loc) · 8.21 KB
/
player.service.ts
File metadata and controls
294 lines (278 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import type {
AnimatedAvatarResponse,
AvatarFrameResponse,
BadgesResponse,
LastPlayedTimesResponse,
OwnedGamesResponse,
PlayerLinkDetailsResponse,
ProfileBackgroundResponse,
ProfileCustomizationResponse,
ProfileItemsEquippedResponse,
RecentlyPlayedGamesResponse,
SteamDeckKeyboardSkinsResponse,
SteamLevelResponse,
TopAchievementsForGamesResponse,
} from '../schemas/responses'
import { generateImageMediaUrl } from '../utils'
import { BaseService } from './_base.service'
export class PlayerService extends BaseService {
constructor(apiKey: string) {
super(apiKey, 'api', 'IPlayerService')
}
/**
* Gets the steam level for a user
*/
async getSteamLevel(steamUserId: string): Promise<SteamLevelResponse> {
const url = this.generateSteamUrl(`/GetSteamLevel/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: SteamLevelResponse
}>(url)
return response.response
}
/**
* Gets the badges for a user
*/
async getBadges(steamUserId: string): Promise<BadgesResponse> {
const url = this.generateSteamUrl(`/GetBadges/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: BadgesResponse
}>(url)
return response.response
}
/**
* Returns list of games owned by the the user
* @param config.include_appinfo - If true, includes additional details (name, icon) about each game
* @param config.include_played_free_games - Free games are excluded by default. If true, free games that have been played will be included.
* @param config.include_free_sub - Some games are in the free sub, which are excluded by default. If true, free sub games will be included.
* @param config.skip_unvetted_apps - If true, skip unvetted store apps.
* @param config.include_extended_appinfo - If true, include extended app info. include_appinfo must also be true.
*/
async getOwnedGames(
steamUserId: string,
config: {
include_appinfo?: boolean
include_played_free_games?: boolean
include_free_sub?: boolean
skip_unvetted_apps?: boolean
include_extended_appinfo?: boolean
} = {
include_appinfo: true,
include_played_free_games: false,
include_free_sub: false,
skip_unvetted_apps: false,
include_extended_appinfo: true,
},
): Promise<OwnedGamesResponse> {
const url = this.generateSteamUrl(`/GetOwnedGames/v1`, {
steamid: steamUserId,
...config,
})
const response = await this.sendGETRequest<{
response: OwnedGamesResponse
}>(url)
return response.response
}
/**
* Returns information about the games a user has played in the last two weeks
*/
async getRecentlyPlayedGames(
steamUserId: string,
): Promise<RecentlyPlayedGamesResponse> {
const url = this.generateSteamUrl(`/GetRecentlyPlayedGames/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: RecentlyPlayedGamesResponse
}>(url)
const games = response.response.games.map((game) => ({
...game,
img_logo_url: generateImageMediaUrl(game.appid, game.img_logo_url),
img_icon_url: generateImageMediaUrl(game.appid, game.img_icon_url),
}))
return {
...response.response,
games,
}
}
/**
*
* Gets the last played times for a user
* @param minLastPlayedTime - The minimum last played time to filter by
*/
async getLastPlayedTimes(
minLastPlayedTime: number | undefined,
): Promise<LastPlayedTimesResponse> {
const url = this.generateSteamUrl(`/ClientGetLastPlayedTimes/v1`, {
minlastplayedtime: minLastPlayedTime,
})
const response = await this.sendGETRequest<{
response: LastPlayedTimesResponse
}>(url)
return response.response
}
/**
* Gets which animated avatar is active for the user
*/
async getAnimatedAvatar(
steamUserId: string,
): Promise<AnimatedAvatarResponse> {
const url = this.generateSteamUrl(`/GetAnimatedAvatar/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: { avatar: AnimatedAvatarResponse }
}>(url)
return response.response.avatar
}
/**
* Gets which avatar frame is active for a specific user
*/
async getAvatarFrame(steamUserId: string): Promise<AvatarFrameResponse> {
const url = this.generateSteamUrl(`/GetAvatarFrame/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: { avatar_frame: AvatarFrameResponse }
}>(url)
return response.response.avatar_frame
}
/**
* Gets the active mini profile background for a user
*/
async getMiniProfileBackground(
steamUserId: string,
): Promise<ProfileBackgroundResponse> {
const url = this.generateSteamUrl(`/GetMiniProfileBackground/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: { profile_background: ProfileBackgroundResponse }
}>(url)
return response.response.profile_background
}
/**
* Gets the favourite badge for a user
* TODO: Not yet typed correctly
*/
async getFavouriteBadge(
steamUserId: string,
): Promise<{ has_favorite_badge: boolean }> {
const url = this.generateSteamUrl(`/GetFavoriteBadge/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: {
has_favorite_badge: boolean
}
}>(url)
return response.response
}
/**
* Replacement for WG GetPlayerLinkDetails
*/
async getPlayerLinkDetails(
steamUserId: string,
): Promise<PlayerLinkDetailsResponse> {
const url = this.generateSteamUrl(`/GetPlayerLinkDetails/v1`, {
'steamids[0]': steamUserId,
})
const response = await this.sendGETRequest<{
response: { accounts: PlayerLinkDetailsResponse }
}>(url)
return response.response.accounts
}
/**
* Gets which profile background is active for a user
*/
async getProfileBackground(
steamUserId: string,
): Promise<ProfileBackgroundResponse> {
const url = this.generateSteamUrl(`/GetProfileBackground/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: { profile_background: ProfileBackgroundResponse }
}>(url)
return response.response.profile_background
}
/**
*
* Gets the customizations (if any) for a profile
* @param config.include_purchased_customizations - If true, include purchased customizations.
* @param config.include_inactive_customizations - If true, include inactive customizations.
*/
async getProfileCustomization(
steamUserId: string,
config: {
include_purchased_customizations?: boolean
include_inactive_customizations?: boolean
} = {
include_purchased_customizations: false,
include_inactive_customizations: false,
},
): Promise<ProfileCustomizationResponse> {
const url = this.generateSteamUrl(`/GetProfileCustomization/v1`, {
steamid: steamUserId,
...config,
})
const response = await this.sendGETRequest<{
response: ProfileCustomizationResponse
}>(url)
return response.response
}
/**
* Returns the items the user has equipped on their profile
*/
async getProfileItemsEquipped(
steamUserId: string,
): Promise<ProfileItemsEquippedResponse> {
const url = this.generateSteamUrl(`/GetProfileItemsEquipped/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: ProfileItemsEquippedResponse
}>(url)
return response.response
}
/**
* Gets the steam deck keyboard skin for a user
*/
async getSteamDeckKeyboardSkin(
steamUserId: string,
): Promise<SteamDeckKeyboardSkinsResponse> {
const url = this.generateSteamUrl(`/GetSteamDeckKeyboardSkin/v1`, {
steamid: steamUserId,
})
const response = await this.sendGETRequest<{
response: SteamDeckKeyboardSkinsResponse
}>(url)
return response.response
}
/**
* Gets the top achievements for a user for a specific game
* @param config.max_achievements - The maximum number of achievements to return. If not set, will not show any achivement details
*/
async getTopAchievementsForGames(
steamUserId: string,
appId: number,
config: {
max_achievements?: number
} = {
max_achievements: 20,
},
): Promise<Array<TopAchievementsForGamesResponse>> {
const url = this.generateSteamUrl(`/GetTopAchievementsForGames/v1`, {
steamid: steamUserId,
'appids[0]': appId,
...config,
})
const response = await this.sendGETRequest<{
response: { games: Array<TopAchievementsForGamesResponse> }
}>(url)
return response.response.games
}
}