@retroachievements/api 2.0.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 +7 -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/getRecentGameAwards.d.ts +50 -0
- package/dist/feed/getRecentGameAwards.test.d.ts +1 -0
- package/dist/feed/index.d.ts +1 -0
- 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/feed/models/get-recent-game-awards-response.model.d.ts +14 -0
- package/dist/feed/models/index.d.ts +2 -0
- package/dist/feed/models/recent-game-awards.model.d.ts +14 -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/dist/user/models/game-info-and-user-progress.model.d.ts +2 -1
- package/dist/user/models/get-game-info-and-user-progress-response.model.d.ts +2 -1
- package/dist/user/models/get-user-completion-progress-response.model.d.ts +2 -1
- package/dist/user/models/user-completion-progress-entity.model.d.ts +2 -1
- package/dist/utils/public/models/award-kind.model.d.ts +1 -0
- package/dist/utils/public/models/index.d.ts +1 -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 +78 -0
- package/src/feed/getRecentGameAwards.ts +85 -0
- package/src/feed/index.ts +1 -0
- 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/feed/models/get-recent-game-awards-response.model.ts +15 -0
- package/src/feed/models/index.ts +2 -0
- package/src/feed/models/recent-game-awards.model.ts +15 -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
- package/src/user/models/game-info-and-user-progress.model.ts +2 -6
- package/src/user/models/get-game-info-and-user-progress-response.model.ts +2 -6
- package/src/user/models/get-user-completion-progress-response.model.ts +3 -6
- package/src/user/models/user-completion-progress-entity.model.ts +3 -6
- package/src/utils/public/models/award-kind.model.ts +5 -0
- package/src/utils/public/models/index.ts +1 -0
|
@@ -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";
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
GameExtended,
|
|
3
3
|
GameExtendedAchievementEntity,
|
|
4
4
|
} from "../../game/models";
|
|
5
|
+
import type { AwardKind } from "../../utils/public";
|
|
5
6
|
|
|
6
7
|
export type GameExtendedAchievementEntityWithUserProgress =
|
|
7
8
|
GameExtendedAchievementEntity & {
|
|
@@ -17,11 +18,6 @@ export interface GameInfoAndUserProgress extends GameExtended {
|
|
|
17
18
|
userCompletion: string;
|
|
18
19
|
userCompletionHardcore: string;
|
|
19
20
|
|
|
20
|
-
highestAwardKind?:
|
|
21
|
-
| "mastered"
|
|
22
|
-
| "completed"
|
|
23
|
-
| "beaten-hardcore"
|
|
24
|
-
| "beaten-softcore"
|
|
25
|
-
| null;
|
|
21
|
+
highestAwardKind?: AwardKind | null;
|
|
26
22
|
highestAwardDate?: string;
|
|
27
23
|
}
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
GameExtendedRawAchievementEntity,
|
|
3
3
|
GetGameExtendedResponse,
|
|
4
4
|
} from "../../game/models";
|
|
5
|
+
import type { AwardKind } from "../../utils/public";
|
|
5
6
|
|
|
6
7
|
type GetGameExtendedResponseWithoutClaims = Omit<
|
|
7
8
|
GetGameExtendedResponse,
|
|
@@ -26,11 +27,6 @@ export interface GetGameInfoAndUserProgressResponse
|
|
|
26
27
|
UserCompletion: string;
|
|
27
28
|
UserCompletionHardcore: string;
|
|
28
29
|
|
|
29
|
-
HighestAwardKind?:
|
|
30
|
-
| "mastered"
|
|
31
|
-
| "completed"
|
|
32
|
-
| "beaten-hardcore"
|
|
33
|
-
| "beaten-softcore"
|
|
34
|
-
| null;
|
|
30
|
+
HighestAwardKind?: AwardKind | null;
|
|
35
31
|
HighestAwardDate?: string;
|
|
36
32
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
|
|
1
3
|
interface RawUserCompletionProgressEntity {
|
|
2
4
|
GameID: number;
|
|
3
5
|
Title: string;
|
|
@@ -9,12 +11,7 @@ interface RawUserCompletionProgressEntity {
|
|
|
9
11
|
NumAwardedHardcore: number;
|
|
10
12
|
|
|
11
13
|
MostRecentAwardedDate?: string;
|
|
12
|
-
HighestAwardKind?:
|
|
13
|
-
| "mastered"
|
|
14
|
-
| "completed"
|
|
15
|
-
| "beaten-hardcore"
|
|
16
|
-
| "beaten-softcore"
|
|
17
|
-
| null;
|
|
14
|
+
HighestAwardKind?: AwardKind | null;
|
|
18
15
|
HighestAwardDate?: string | null;
|
|
19
16
|
}
|
|
20
17
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
|
|
1
3
|
export interface UserCompletionProgressEntity {
|
|
2
4
|
gameId: number;
|
|
3
5
|
title: string;
|
|
@@ -9,11 +11,6 @@ export interface UserCompletionProgressEntity {
|
|
|
9
11
|
numAwardedHardcore: number;
|
|
10
12
|
|
|
11
13
|
mostRecentAwardedDate?: string;
|
|
12
|
-
highestAwardKind?:
|
|
13
|
-
| "mastered"
|
|
14
|
-
| "completed"
|
|
15
|
-
| "beaten-hardcore"
|
|
16
|
-
| "beaten-softcore"
|
|
17
|
-
| null;
|
|
14
|
+
highestAwardKind?: AwardKind | null;
|
|
18
15
|
highestAwardDate?: string;
|
|
19
16
|
}
|