@retroachievements/api 2.1.0 → 2.2.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 +6 -5
- package/dist/achievement/models/achievement-unlock-entity.model.d.ts +1 -0
- package/dist/achievement/models/get-achievement-unlocks-response.model.d.ts +1 -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/feed/getAchievementOfTheWeek.d.ts +2 -1
- package/dist/feed/models/achievement-of-the-week.model.d.ts +1 -0
- package/dist/feed/models/get-achievement-of-the-week-response.model.d.ts +1 -0
- package/dist/game/getGameHashes.d.ts +45 -0
- package/dist/game/getGameHashes.test.d.ts +1 -0
- package/dist/game/index.d.ts +1 -0
- package/dist/game/models/game-hashes.model.d.ts +10 -0
- package/dist/game/models/get-game-hashes-response.model.d.ts +10 -0
- package/dist/game/models/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/achievement/getAchievementUnlocks.test.ts +2 -0
- package/src/achievement/getAchievementUnlocks.ts +7 -1
- package/src/achievement/models/achievement-unlock-entity.model.ts +1 -0
- package/src/achievement/models/get-achievement-unlocks-response.model.ts +1 -0
- package/src/console/getConsoleIds.test.ts +4 -1
- package/src/feed/getAchievementOfTheWeek.test.ts +4 -0
- package/src/feed/getAchievementOfTheWeek.ts +3 -1
- package/src/feed/getRecentGameAwards.test.ts +6 -1
- package/src/feed/models/achievement-of-the-week.model.ts +1 -0
- package/src/feed/models/get-achievement-of-the-week-response.model.ts +1 -0
- package/src/game/getGameHashes.test.ts +77 -0
- package/src/game/getGameHashes.ts +66 -0
- package/src/game/index.ts +1 -0
- package/src/game/models/game-hashes.model.ts +10 -0
- package/src/game/models/get-game-hashes-response.model.ts +10 -0
- package/src/game/models/index.ts +2 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ID } from "../utils/internal";
|
|
2
|
+
import type { AuthObject } from "../utils/public";
|
|
3
|
+
import type { GameHashes } from "./models";
|
|
4
|
+
/**
|
|
5
|
+
* A call to this function will retrieve a list of hashes linked to a game.
|
|
6
|
+
*
|
|
7
|
+
* @param authorization An object containing your username and webApiKey.
|
|
8
|
+
* This can be constructed with `buildAuthorization()`.
|
|
9
|
+
*
|
|
10
|
+
* @param payload.gameId The unique game ID. If you are unsure, open the
|
|
11
|
+
* game's page on the RetroAchievements.org website. For example, Dragster's
|
|
12
|
+
* URL is https://retroachievements.org/game/14402. We can see from the
|
|
13
|
+
* URL that the game ID is "14402".
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* const game = await getGameHashes(
|
|
18
|
+
* authorization,
|
|
19
|
+
* { gameId: 14402 }
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns An object containing a list of game hashes.
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "Results": [
|
|
27
|
+
* {
|
|
28
|
+
* "MD5": "1b1d9ac862c387367e904036114c4825",
|
|
29
|
+
* "Name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
|
|
30
|
+
* "Labels": ["nointro", "rapatches"],
|
|
31
|
+
* "PatchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* "MD5": "1bc674be034e43c96b86487ac69d9293",
|
|
35
|
+
* "Name": "Sonic The Hedgehog (USA, Europe).md",
|
|
36
|
+
* "Labels": ["nointro"],
|
|
37
|
+
* "PatchUrl": null
|
|
38
|
+
* }
|
|
39
|
+
* ]
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const getGameHashes: (authorization: AuthObject, payload: {
|
|
44
|
+
gameId: ID;
|
|
45
|
+
}) => Promise<GameHashes>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/game/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./getAchievementCount";
|
|
|
2
2
|
export * from "./getAchievementDistribution";
|
|
3
3
|
export * from "./getGame";
|
|
4
4
|
export * from "./getGameExtended";
|
|
5
|
+
export * from "./getGameHashes";
|
|
5
6
|
export * from "./getGameRankAndScore";
|
|
6
7
|
export * from "./getGameRating";
|
|
7
8
|
export * from "./models";
|
|
@@ -4,11 +4,13 @@ export * from "./game.model";
|
|
|
4
4
|
export * from "./game-extended.model";
|
|
5
5
|
export * from "./game-extended-achievement-entity.model";
|
|
6
6
|
export * from "./game-extended-claim-entity.model";
|
|
7
|
+
export * from "./game-hashes.model";
|
|
7
8
|
export * from "./game-rank-and-score-entity.model";
|
|
8
9
|
export * from "./game-rating.model";
|
|
9
10
|
export * from "./get-achievement-count-response.model";
|
|
10
11
|
export * from "./get-achievement-distribution-response.model";
|
|
11
12
|
export * from "./get-game-extended-response.model";
|
|
13
|
+
export * from "./get-game-hashes-response.model";
|
|
12
14
|
export * from "./get-game-rank-and-score-response.model";
|
|
13
15
|
export * from "./get-game-rating-response.model";
|
|
14
16
|
export * from "./get-game-response.model";
|
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ describe("Function: getAchievementUnlocks", () => {
|
|
|
45
45
|
{
|
|
46
46
|
User: "Tiotroll2022",
|
|
47
47
|
RAPoints: "348",
|
|
48
|
+
RASoftcorePoints: "363",
|
|
48
49
|
DateAwarded: "2023-01-29 21:45:41",
|
|
49
50
|
HardcoreMode: "0",
|
|
50
51
|
},
|
|
@@ -91,6 +92,7 @@ describe("Function: getAchievementUnlocks", () => {
|
|
|
91
92
|
{
|
|
92
93
|
user: "Tiotroll2022",
|
|
93
94
|
raPoints: 348,
|
|
95
|
+
raSoftcorePoints: 363,
|
|
94
96
|
dateAwarded: "2023-01-29 21:45:41",
|
|
95
97
|
hardcoreMode: false,
|
|
96
98
|
},
|
|
@@ -75,7 +75,13 @@ export const getAchievementUnlocks = async (
|
|
|
75
75
|
const rawResponse = await call<GetAchievementUnlocksResponse>({ url });
|
|
76
76
|
|
|
77
77
|
return serializeProperties(rawResponse, {
|
|
78
|
-
shouldCastToNumbers: [
|
|
78
|
+
shouldCastToNumbers: [
|
|
79
|
+
"ID",
|
|
80
|
+
"Points",
|
|
81
|
+
"TrueRatio",
|
|
82
|
+
"RAPoints",
|
|
83
|
+
"RASoftcorePoints",
|
|
84
|
+
],
|
|
79
85
|
shouldMapToBooleans: ["HardcoreMode"],
|
|
80
86
|
});
|
|
81
87
|
};
|
|
@@ -62,7 +62,10 @@ describe("Function: getConsoleIds", () => {
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
// ACT
|
|
65
|
-
const response = await getConsoleIds(authorization
|
|
65
|
+
const response = await getConsoleIds(authorization, {
|
|
66
|
+
shouldOnlyRetrieveActiveSystems: true,
|
|
67
|
+
shouldOnlyRetrieveGameSystems: true,
|
|
68
|
+
});
|
|
66
69
|
|
|
67
70
|
// ASSERT
|
|
68
71
|
const expectedResponse: FetchedSystem[] = [
|
|
@@ -53,6 +53,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
53
53
|
{
|
|
54
54
|
User: "Tirbaba2",
|
|
55
55
|
RAPoints: "72",
|
|
56
|
+
RASoftcorePoints: "72",
|
|
56
57
|
DateAwarded: "2022-10-10 01:42:19",
|
|
57
58
|
HardcoreMode: "1",
|
|
58
59
|
},
|
|
@@ -91,6 +92,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
91
92
|
{
|
|
92
93
|
user: "Tirbaba2",
|
|
93
94
|
raPoints: 72,
|
|
95
|
+
raSoftcorePoints: 72,
|
|
94
96
|
dateAwarded: "2022-10-10 01:42:19",
|
|
95
97
|
hardcoreMode: true,
|
|
96
98
|
},
|
|
@@ -131,6 +133,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
131
133
|
{
|
|
132
134
|
User: "Tirbaba2",
|
|
133
135
|
RAPoints: "72",
|
|
136
|
+
RASoftcorePoints: "72",
|
|
134
137
|
DateAwarded: "2022-10-10 01:42:19",
|
|
135
138
|
HardcoreMode: "0",
|
|
136
139
|
},
|
|
@@ -169,6 +172,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
169
172
|
{
|
|
170
173
|
user: "Tirbaba2",
|
|
171
174
|
raPoints: 72,
|
|
175
|
+
raSoftcorePoints: 72,
|
|
172
176
|
dateAwarded: "2022-10-10 01:42:19",
|
|
173
177
|
hardcoreMode: false,
|
|
174
178
|
},
|
|
@@ -48,7 +48,8 @@ import type {
|
|
|
48
48
|
* unlocks: [
|
|
49
49
|
* {
|
|
50
50
|
* user: "Tirbaba2",
|
|
51
|
-
*
|
|
51
|
+
* raPoints: "72",
|
|
52
|
+
* raSoftcorePoints: "72",
|
|
52
53
|
* dateAwarded: "2022-10-10 01:42:19",
|
|
53
54
|
* hardcoreMode: "1"
|
|
54
55
|
* }
|
|
@@ -75,6 +76,7 @@ export const getAchievementOfTheWeek = async (
|
|
|
75
76
|
"TrueRatio",
|
|
76
77
|
"TotalPlayers",
|
|
77
78
|
"RAPoints",
|
|
79
|
+
"RASoftcorePoints",
|
|
78
80
|
"UnlocksCount",
|
|
79
81
|
],
|
|
80
82
|
shouldMapToBooleans: ["HardcoreMode"],
|
|
@@ -49,7 +49,12 @@ describe("Function: getRecentGameAwards", () => {
|
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
// ACT
|
|
52
|
-
const response = await getRecentGameAwards(authorization
|
|
52
|
+
const response = await getRecentGameAwards(authorization, {
|
|
53
|
+
startDate: "2025-01-05",
|
|
54
|
+
offset: 10,
|
|
55
|
+
count: 10,
|
|
56
|
+
desiredAwardKinds: ["completed"],
|
|
57
|
+
});
|
|
53
58
|
|
|
54
59
|
const expectedResponse: RecentGameAwards = {
|
|
55
60
|
count: 1,
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { getGameHashes } from "./getGameHashes";
|
|
9
|
+
import type { GetGameHashesResponse } from "./models";
|
|
10
|
+
|
|
11
|
+
const server = setupServer();
|
|
12
|
+
|
|
13
|
+
describe("Function: getGameExtended", () => {
|
|
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(getGameHashes).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("given a game ID, retrieves extended metadata about the game", async () => {
|
|
25
|
+
// ARRANGE
|
|
26
|
+
const authorization = buildAuthorization({
|
|
27
|
+
username: "mockUserName",
|
|
28
|
+
webApiKey: "mockWebApiKey",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const mockResponse: GetGameHashesResponse = {
|
|
32
|
+
Results: [
|
|
33
|
+
{
|
|
34
|
+
Name: "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
|
|
35
|
+
MD5: "1b1d9ac862c387367e904036114c4825",
|
|
36
|
+
Labels: ["nointro", "rapatches"],
|
|
37
|
+
PatchUrl:
|
|
38
|
+
"https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
Name: "Sonic The Hedgehog (USA, Europe).md",
|
|
42
|
+
MD5: "1bc674be034e43c96b86487ac69d9293",
|
|
43
|
+
Labels: ["nointro"],
|
|
44
|
+
PatchUrl: null,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
server.use(
|
|
50
|
+
http.get(`${apiBaseUrl}/API_GetGameHashes.php`, () =>
|
|
51
|
+
HttpResponse.json(mockResponse)
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// ACT
|
|
56
|
+
const response = await getGameHashes(authorization, { gameId: 1 });
|
|
57
|
+
|
|
58
|
+
// ASSERT
|
|
59
|
+
expect(response).toEqual({
|
|
60
|
+
results: [
|
|
61
|
+
{
|
|
62
|
+
name: "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
|
|
63
|
+
md5: "1b1d9ac862c387367e904036114c4825",
|
|
64
|
+
labels: ["nointro", "rapatches"],
|
|
65
|
+
patchUrl:
|
|
66
|
+
"https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "Sonic The Hedgehog (USA, Europe).md",
|
|
70
|
+
md5: "1bc674be034e43c96b86487ac69d9293",
|
|
71
|
+
labels: ["nointro"],
|
|
72
|
+
patchUrl: null,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ID } from "../utils/internal";
|
|
2
|
+
import {
|
|
3
|
+
apiBaseUrl,
|
|
4
|
+
buildRequestUrl,
|
|
5
|
+
call,
|
|
6
|
+
serializeProperties,
|
|
7
|
+
} from "../utils/internal";
|
|
8
|
+
import type { AuthObject } from "../utils/public";
|
|
9
|
+
import type { GameHashes, GetGameHashesResponse } from "./models";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A call to this function will retrieve a list of hashes linked to a game.
|
|
13
|
+
*
|
|
14
|
+
* @param authorization An object containing your username and webApiKey.
|
|
15
|
+
* This can be constructed with `buildAuthorization()`.
|
|
16
|
+
*
|
|
17
|
+
* @param payload.gameId The unique game ID. If you are unsure, open the
|
|
18
|
+
* game's page on the RetroAchievements.org website. For example, Dragster's
|
|
19
|
+
* URL is https://retroachievements.org/game/14402. We can see from the
|
|
20
|
+
* URL that the game ID is "14402".
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* const game = await getGameHashes(
|
|
25
|
+
* authorization,
|
|
26
|
+
* { gameId: 14402 }
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @returns An object containing a list of game hashes.
|
|
31
|
+
* ```json
|
|
32
|
+
* {
|
|
33
|
+
* "Results": [
|
|
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"
|
|
39
|
+
* },
|
|
40
|
+
* {
|
|
41
|
+
* "MD5": "1bc674be034e43c96b86487ac69d9293",
|
|
42
|
+
* "Name": "Sonic The Hedgehog (USA, Europe).md",
|
|
43
|
+
* "Labels": ["nointro"],
|
|
44
|
+
* "PatchUrl": null
|
|
45
|
+
* }
|
|
46
|
+
* ]
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const getGameHashes = async (
|
|
51
|
+
authorization: AuthObject,
|
|
52
|
+
payload: { gameId: ID }
|
|
53
|
+
): Promise<GameHashes> => {
|
|
54
|
+
const { gameId } = payload;
|
|
55
|
+
|
|
56
|
+
const url = buildRequestUrl(
|
|
57
|
+
apiBaseUrl,
|
|
58
|
+
"/API_GetGameHashes.php",
|
|
59
|
+
authorization,
|
|
60
|
+
{ i: gameId }
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const rawResponse = await call<GetGameHashesResponse>({ url });
|
|
64
|
+
|
|
65
|
+
return serializeProperties(rawResponse);
|
|
66
|
+
};
|
package/src/game/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./getAchievementCount";
|
|
|
2
2
|
export * from "./getAchievementDistribution";
|
|
3
3
|
export * from "./getGame";
|
|
4
4
|
export * from "./getGameExtended";
|
|
5
|
+
export * from "./getGameHashes";
|
|
5
6
|
export * from "./getGameRankAndScore";
|
|
6
7
|
export * from "./getGameRating";
|
|
7
8
|
export * from "./models";
|
package/src/game/models/index.ts
CHANGED
|
@@ -4,11 +4,13 @@ export * from "./game.model";
|
|
|
4
4
|
export * from "./game-extended.model";
|
|
5
5
|
export * from "./game-extended-achievement-entity.model";
|
|
6
6
|
export * from "./game-extended-claim-entity.model";
|
|
7
|
+
export * from "./game-hashes.model";
|
|
7
8
|
export * from "./game-rank-and-score-entity.model";
|
|
8
9
|
export * from "./game-rating.model";
|
|
9
10
|
export * from "./get-achievement-count-response.model";
|
|
10
11
|
export * from "./get-achievement-distribution-response.model";
|
|
11
12
|
export * from "./get-game-extended-response.model";
|
|
13
|
+
export * from "./get-game-hashes-response.model";
|
|
12
14
|
export * from "./get-game-rank-and-score-response.model";
|
|
13
15
|
export * from "./get-game-rating-response.model";
|
|
14
16
|
export * from "./get-game-response.model";
|