@retroachievements/api 2.2.0 → 2.4.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.
- package/README.md +5 -0
- package/dist/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.modern.js +1 -1
- package/dist/api.modern.js.map +1 -1
- package/dist/api.module.js +1 -1
- package/dist/api.module.js.map +1 -1
- package/dist/api.umd.js +1 -1
- package/dist/api.umd.js.map +1 -1
- package/dist/comment/getComments.d.ts +58 -0
- package/dist/comment/getComments.test.d.ts +1 -0
- package/dist/comment/index.d.ts +2 -0
- package/dist/comment/models/comment-entity.model.d.ts +6 -0
- package/dist/comment/models/comment-response.model.d.ts +6 -0
- package/dist/comment/models/get-comments-response.model.d.ts +12 -0
- package/dist/comment/models/index.d.ts +3 -0
- package/dist/game/getGameHashes.d.ts +9 -9
- package/dist/index.d.ts +1 -0
- package/dist/user/getUserWantToPlayList.d.ts +47 -0
- package/dist/user/getUserWantToPlayList.test.d.ts +1 -0
- package/dist/user/index.d.ts +1 -0
- package/dist/user/models/get-user-want-to-play-list-response.model.d.ts +13 -0
- package/dist/user/models/index.d.ts +2 -0
- package/dist/user/models/user-want-to-play-list.model.d.ts +13 -0
- package/package.json +1 -1
- package/src/comment/getComments.test.ts +277 -0
- package/src/comment/getComments.ts +107 -0
- package/src/comment/index.ts +2 -0
- package/src/comment/models/comment-entity.model.ts +7 -0
- package/src/comment/models/comment-response.model.ts +7 -0
- package/src/comment/models/get-comments-response.model.ts +13 -0
- package/src/comment/models/index.ts +3 -0
- package/src/game/getGameExtended.test.ts +4 -1
- package/src/game/getGameHashes.test.ts +2 -2
- package/src/game/getGameHashes.ts +9 -9
- package/src/index.ts +1 -0
- package/src/user/getUserWantToPlayList.test.ts +75 -0
- package/src/user/getUserWantToPlayList.ts +76 -0
- package/src/user/index.ts +1 -0
- package/src/user/models/get-user-want-to-play-list-response.model.ts +13 -0
- package/src/user/models/index.ts +2 -0
- package/src/user/models/user-want-to-play-list.model.ts +13 -0
|
@@ -10,7 +10,7 @@ import type { GetGameHashesResponse } from "./models";
|
|
|
10
10
|
|
|
11
11
|
const server = setupServer();
|
|
12
12
|
|
|
13
|
-
describe("Function:
|
|
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
|
|
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
|
-
* "
|
|
33
|
+
* "results": [
|
|
34
34
|
* {
|
|
35
|
-
* "
|
|
36
|
-
* "
|
|
37
|
-
* "
|
|
38
|
-
* "
|
|
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
|
-
* "
|
|
42
|
-
* "
|
|
43
|
-
* "
|
|
44
|
-
* "
|
|
41
|
+
* "md5": "1bc674be034e43c96b86487ac69d9293",
|
|
42
|
+
* "name": "Sonic The Hedgehog (USA, Europe).md",
|
|
43
|
+
* "labels": ["nointro"],
|
|
44
|
+
* "patchUrl": null
|
|
45
45
|
* }
|
|
46
46
|
* ]
|
|
47
47
|
* }
|
package/src/index.ts
CHANGED
|
@@ -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
|
@@ -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
|
+
}
|
package/src/user/models/index.ts
CHANGED
|
@@ -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
|
+
}
|