@retroachievements/api 2.2.0 → 2.3.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.
@@ -0,0 +1,47 @@
1
+ import type { AuthObject } from "../utils/public";
2
+ import type { UserWantToPlayList } from "./models";
3
+ /**
4
+ * A call to this function will retrieve a user's "Want to Play Games" list.
5
+ *
6
+ * @param authorization An object containing your username and webApiKey.
7
+ * This can be constructed with `buildAuthorization()`.
8
+ *
9
+ * @param payload.username The user for which to retrieve the
10
+ * want to play games list for.
11
+ *
12
+ * @param payload.offset Defaults to 0. The number of entries to skip.
13
+ *
14
+ * @param payload.count Defaults to 100, has a max of 500.
15
+ *
16
+ * @example
17
+ * ```
18
+ * const wantToPlayList = await getUserWantToPlayList(
19
+ * authorization,
20
+ * { username: "wv_pinball" }
21
+ * );
22
+ * ```
23
+ *
24
+ * @returns An object containing a user's list of "Want to Play Games".
25
+ * ```json
26
+ * {
27
+ * "count": 100,
28
+ * "total": 1287,
29
+ * "results": [
30
+ * {
31
+ * "id": 20246,
32
+ * "title": "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
33
+ * "imageIcon": "/Images/074560.png",
34
+ * "consoleID": 1,
35
+ * "consoleName": "Genesis/Mega Drive",
36
+ * "pointsTotal": 1500,
37
+ * "achievementsPublished": 50
38
+ * }
39
+ * ]
40
+ * }
41
+ * ```
42
+ */
43
+ export declare const getUserWantToPlayList: (authorization: AuthObject, payload: {
44
+ username: string;
45
+ offset?: number;
46
+ count?: number;
47
+ }) => Promise<UserWantToPlayList>;
@@ -0,0 +1 @@
1
+ export {};
@@ -12,4 +12,5 @@ export * from "./getUserProgress";
12
12
  export * from "./getUserRecentAchievements";
13
13
  export * from "./getUserRecentlyPlayedGames";
14
14
  export * from "./getUserSummary";
15
+ export * from "./getUserWantToPlayList";
15
16
  export * from "./models";
@@ -0,0 +1,13 @@
1
+ export interface GetUserWantToPlayListResponse {
2
+ Count: number;
3
+ Total: number;
4
+ Results: Array<{
5
+ ID: number;
6
+ Title: string;
7
+ ImageIcon: string;
8
+ ConsoleID: number;
9
+ ConsoleName: string;
10
+ PointsTotal: number;
11
+ AchievementsPublished: number;
12
+ }>;
13
+ }
@@ -13,6 +13,7 @@ export * from "./get-user-progress-response.model";
13
13
  export * from "./get-user-recent-achievements-response.model";
14
14
  export * from "./get-user-recently-played-games-response.model";
15
15
  export * from "./get-user-summary-response.model";
16
+ export * from "./get-user-want-to-play-list-response.model";
16
17
  export * from "./user-awards.model";
17
18
  export * from "./user-claims.model";
18
19
  export * from "./user-claims-response.model";
@@ -26,3 +27,4 @@ export * from "./user-progress.model";
26
27
  export * from "./user-recent-achievement.model";
27
28
  export * from "./user-recently-played-games.model";
28
29
  export * from "./user-summary.model";
30
+ export * from "./user-want-to-play-list.model";
@@ -0,0 +1,13 @@
1
+ export interface UserWantToPlayList {
2
+ count: number;
3
+ total: number;
4
+ results: Array<{
5
+ id: number;
6
+ title: string;
7
+ imageIcon: string;
8
+ consoleId: number;
9
+ consoleName: string;
10
+ pointsTotal: number;
11
+ achievementsPublished: number;
12
+ }>;
13
+ }
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "raweb",
11
11
  "retro gaming"
12
12
  ],
13
- "version": "2.2.0",
13
+ "version": "2.3.0",
14
14
  "typings": "dist/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
@@ -75,7 +75,10 @@ describe("Function: getGameExtended", () => {
75
75
  );
76
76
 
77
77
  // ACT
78
- const response = await getGameExtended(authorization, { gameId: 14_402 });
78
+ const response = await getGameExtended(authorization, {
79
+ gameId: 14_402,
80
+ isRequestingUnofficialAchievements: true,
81
+ });
79
82
 
80
83
  // ASSERT
81
84
  expect(response).toEqual({
@@ -10,7 +10,7 @@ import type { GetGameHashesResponse } from "./models";
10
10
 
11
11
  const server = setupServer();
12
12
 
13
- describe("Function: getGameExtended", () => {
13
+ describe("Function: getGameHashes", () => {
14
14
  // MSW Setup
15
15
  beforeAll(() => server.listen());
16
16
  afterEach(() => server.resetHandlers());
@@ -21,7 +21,7 @@ describe("Function: getGameExtended", () => {
21
21
  expect(getGameHashes).toBeDefined();
22
22
  });
23
23
 
24
- it("given a game ID, retrieves extended metadata about the game", async () => {
24
+ it("given a game ID, retrieves a list of linked hashes", async () => {
25
25
  // ARRANGE
26
26
  const authorization = buildAuthorization({
27
27
  username: "mockUserName",
@@ -30,18 +30,18 @@ import type { GameHashes, GetGameHashesResponse } from "./models";
30
30
  * @returns An object containing a list of game hashes.
31
31
  * ```json
32
32
  * {
33
- * "Results": [
33
+ * "results": [
34
34
  * {
35
- * "MD5": "1b1d9ac862c387367e904036114c4825",
36
- * "Name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
37
- * "Labels": ["nointro", "rapatches"],
38
- * "PatchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
35
+ * "md5": "1b1d9ac862c387367e904036114c4825",
36
+ * "name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
37
+ * "labels": ["nointro", "rapatches"],
38
+ * "patchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
39
39
  * },
40
40
  * {
41
- * "MD5": "1bc674be034e43c96b86487ac69d9293",
42
- * "Name": "Sonic The Hedgehog (USA, Europe).md",
43
- * "Labels": ["nointro"],
44
- * "PatchUrl": null
41
+ * "md5": "1bc674be034e43c96b86487ac69d9293",
42
+ * "name": "Sonic The Hedgehog (USA, Europe).md",
43
+ * "labels": ["nointro"],
44
+ * "patchUrl": null
45
45
  * }
46
46
  * ]
47
47
  * }
@@ -0,0 +1,75 @@
1
+ /* eslint-disable sonarjs/no-duplicate-string */
2
+
3
+ import { http, HttpResponse } from "msw";
4
+ import { setupServer } from "msw/node";
5
+
6
+ import { apiBaseUrl } from "../utils/internal";
7
+ import { buildAuthorization } from "../utils/public";
8
+ import { getUserWantToPlayList } from "./getUserWantToPlayList";
9
+ import type { GetUserWantToPlayListResponse } from "./models";
10
+
11
+ const server = setupServer();
12
+
13
+ describe("Function: getUserWantToPlayList", () => {
14
+ // MSW Setup
15
+ beforeAll(() => server.listen());
16
+ afterEach(() => server.resetHandlers());
17
+ afterAll(() => server.close());
18
+
19
+ it("is defined #sanity", () => {
20
+ // ASSERT
21
+ expect(getUserWantToPlayList).toBeDefined();
22
+ });
23
+
24
+ it('given a username, retrieves that users "Want To Play Games"', async () => {
25
+ // ARRANGE
26
+ const authorization = buildAuthorization({
27
+ username: "mockUserName",
28
+ webApiKey: "mockWebApiKey",
29
+ });
30
+
31
+ const mockResponse: GetUserWantToPlayListResponse = {
32
+ Count: 100,
33
+ Total: 1287,
34
+ Results: [
35
+ {
36
+ ID: 20_246,
37
+ Title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
38
+ ImageIcon: "/Images/074560.png",
39
+ ConsoleID: 1,
40
+ ConsoleName: "Genesis/Mega Drive",
41
+ PointsTotal: 1500,
42
+ AchievementsPublished: 50,
43
+ },
44
+ ],
45
+ };
46
+
47
+ server.use(
48
+ http.get(`${apiBaseUrl}/API_GetUserWantToPlayList.php`, () =>
49
+ HttpResponse.json(mockResponse)
50
+ )
51
+ );
52
+
53
+ // ACT
54
+ const response = await getUserWantToPlayList(authorization, {
55
+ username: "xelnia",
56
+ });
57
+
58
+ // ASSERT
59
+ expect(response).toEqual({
60
+ count: 100,
61
+ total: 1287,
62
+ results: [
63
+ {
64
+ id: 20_246,
65
+ title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
66
+ imageIcon: "/Images/074560.png",
67
+ consoleId: 1,
68
+ consoleName: "Genesis/Mega Drive",
69
+ pointsTotal: 1500,
70
+ achievementsPublished: 50,
71
+ },
72
+ ],
73
+ });
74
+ });
75
+ });
@@ -0,0 +1,76 @@
1
+ import {
2
+ apiBaseUrl,
3
+ buildRequestUrl,
4
+ call,
5
+ serializeProperties,
6
+ } from "../utils/internal";
7
+ import type { AuthObject } from "../utils/public";
8
+ import type {
9
+ GetUserWantToPlayListResponse,
10
+ UserWantToPlayList,
11
+ } from "./models";
12
+
13
+ /**
14
+ * A call to this function will retrieve a user's "Want to Play Games" list.
15
+ *
16
+ * @param authorization An object containing your username and webApiKey.
17
+ * This can be constructed with `buildAuthorization()`.
18
+ *
19
+ * @param payload.username The user for which to retrieve the
20
+ * want to play games list for.
21
+ *
22
+ * @param payload.offset Defaults to 0. The number of entries to skip.
23
+ *
24
+ * @param payload.count Defaults to 100, has a max of 500.
25
+ *
26
+ * @example
27
+ * ```
28
+ * const wantToPlayList = await getUserWantToPlayList(
29
+ * authorization,
30
+ * { username: "wv_pinball" }
31
+ * );
32
+ * ```
33
+ *
34
+ * @returns An object containing a user's list of "Want to Play Games".
35
+ * ```json
36
+ * {
37
+ * "count": 100,
38
+ * "total": 1287,
39
+ * "results": [
40
+ * {
41
+ * "id": 20246,
42
+ * "title": "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
43
+ * "imageIcon": "/Images/074560.png",
44
+ * "consoleID": 1,
45
+ * "consoleName": "Genesis/Mega Drive",
46
+ * "pointsTotal": 1500,
47
+ * "achievementsPublished": 50
48
+ * }
49
+ * ]
50
+ * }
51
+ * ```
52
+ */
53
+ export const getUserWantToPlayList = async (
54
+ authorization: AuthObject,
55
+ payload: { username: string; offset?: number; count?: number }
56
+ ): Promise<UserWantToPlayList> => {
57
+ const queryParams: Record<string, any> = {};
58
+ queryParams.u = payload.username;
59
+ if (payload?.offset) {
60
+ queryParams.o = payload.offset;
61
+ }
62
+ if (payload?.count) {
63
+ queryParams.c = payload.count;
64
+ }
65
+
66
+ const url = buildRequestUrl(
67
+ apiBaseUrl,
68
+ "/API_GetUserWantToPlayList.php",
69
+ authorization,
70
+ queryParams
71
+ );
72
+
73
+ const rawResponse = await call<GetUserWantToPlayListResponse>({ url });
74
+
75
+ return serializeProperties(rawResponse);
76
+ };
package/src/user/index.ts CHANGED
@@ -12,4 +12,5 @@ export * from "./getUserProgress";
12
12
  export * from "./getUserRecentAchievements";
13
13
  export * from "./getUserRecentlyPlayedGames";
14
14
  export * from "./getUserSummary";
15
+ export * from "./getUserWantToPlayList";
15
16
  export * from "./models";
@@ -0,0 +1,13 @@
1
+ export interface GetUserWantToPlayListResponse {
2
+ Count: number;
3
+ Total: number;
4
+ Results: Array<{
5
+ ID: number;
6
+ Title: string;
7
+ ImageIcon: string;
8
+ ConsoleID: number;
9
+ ConsoleName: string;
10
+ PointsTotal: number;
11
+ AchievementsPublished: number;
12
+ }>;
13
+ }
@@ -13,6 +13,7 @@ export * from "./get-user-progress-response.model";
13
13
  export * from "./get-user-recent-achievements-response.model";
14
14
  export * from "./get-user-recently-played-games-response.model";
15
15
  export * from "./get-user-summary-response.model";
16
+ export * from "./get-user-want-to-play-list-response.model";
16
17
  export * from "./user-awards.model";
17
18
  export * from "./user-claims.model";
18
19
  export * from "./user-claims-response.model";
@@ -26,3 +27,4 @@ export * from "./user-progress.model";
26
27
  export * from "./user-recent-achievement.model";
27
28
  export * from "./user-recently-played-games.model";
28
29
  export * from "./user-summary.model";
30
+ export * from "./user-want-to-play-list.model";
@@ -0,0 +1,13 @@
1
+ export interface UserWantToPlayList {
2
+ count: number;
3
+ total: number;
4
+ results: Array<{
5
+ id: number;
6
+ title: string;
7
+ imageIcon: string;
8
+ consoleId: number;
9
+ consoleName: string;
10
+ pointsTotal: number;
11
+ achievementsPublished: number;
12
+ }>;
13
+ }