@retroachievements/api 1.5.3 → 2.1.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 +3 -2
- package/dist/achievement/getAchievementUnlocks.d.ts +1 -1
- 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/console/getConsoleIds.d.ts +15 -4
- package/dist/console/getGameList.d.ts +1 -1
- package/dist/console/models/fetched-system.model.d.ts +7 -0
- package/dist/console/models/get-console-ids-response.model.d.ts +2 -0
- package/dist/console/models/index.d.ts +1 -1
- package/dist/feed/getAchievementOfTheWeek.d.ts +1 -1
- package/dist/feed/getActiveClaims.d.ts +1 -1
- package/dist/feed/getRecentGameAwards.d.ts +50 -0
- package/dist/feed/getRecentGameAwards.test.d.ts +1 -0
- package/dist/feed/getTopTenUsers.d.ts +3 -3
- package/dist/feed/index.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/feed/models/top-ten-users-entity.model.d.ts +1 -1
- package/dist/game/getAchievementCount.d.ts +1 -1
- package/dist/game/getAchievementDistribution.d.ts +1 -1
- package/dist/game/getGame.d.ts +1 -1
- package/dist/game/getGameExtended.d.ts +1 -1
- package/dist/game/getGameRankAndScore.d.ts +1 -1
- package/dist/game/getGameRating.d.ts +1 -1
- package/dist/ticket/getTicketData.d.ts +9 -9
- package/dist/user/getAchievementsEarnedBetween.d.ts +4 -4
- package/dist/user/getAchievementsEarnedOnDay.d.ts +4 -4
- package/dist/user/getGameInfoAndUserProgress.d.ts +9 -5
- package/dist/user/getUserAwards.d.ts +4 -4
- package/dist/user/getUserClaims.d.ts +4 -4
- package/dist/user/getUserCompletedGames.d.ts +4 -4
- package/dist/user/getUserCompletionProgress.d.ts +4 -4
- package/dist/user/getUserGameRankAndScore.d.ts +4 -4
- package/dist/user/getUserPoints.d.ts +4 -4
- package/dist/user/getUserProfile.d.ts +4 -4
- package/dist/user/getUserProgress.d.ts +4 -4
- package/dist/user/getUserRecentAchievements.d.ts +4 -4
- package/dist/user/getUserRecentlyPlayedGames.d.ts +4 -4
- package/dist/user/getUserSummary.d.ts +4 -4
- package/dist/user/models/game-info-and-user-progress.model.d.ts +3 -0
- package/dist/user/models/get-game-info-and-user-progress-response.model.d.ts +3 -0
- 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/buildAuthorization.d.ts +1 -1
- package/dist/utils/public/models/auth-object.model.d.ts +2 -2
- 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 +6 -12
- package/src/__playground.ts +4 -4
- package/src/achievement/getAchievementUnlocks.test.ts +1 -1
- package/src/achievement/getAchievementUnlocks.ts +1 -1
- package/src/console/getConsoleIds.test.ts +15 -3
- package/src/console/getConsoleIds.ts +28 -6
- package/src/console/getGameList.test.ts +1 -1
- package/src/console/getGameList.ts +1 -1
- package/src/console/models/fetched-system.model.ts +7 -0
- package/src/console/models/get-console-ids-response.model.ts +2 -0
- package/src/console/models/index.ts +1 -1
- package/src/feed/getAchievementOfTheWeek.test.ts +2 -2
- package/src/feed/getAchievementOfTheWeek.ts +1 -1
- package/src/feed/getActiveClaims.test.ts +1 -1
- package/src/feed/getActiveClaims.ts +1 -1
- package/src/feed/getClaims.test.ts +1 -1
- package/src/feed/getRecentGameAwards.test.ts +73 -0
- package/src/feed/getRecentGameAwards.ts +85 -0
- package/src/feed/getTopTenUsers.test.ts +11 -11
- package/src/feed/getTopTenUsers.ts +4 -4
- package/src/feed/index.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/feed/models/top-ten-users-entity.model.ts +1 -1
- package/src/game/getAchievementCount.test.ts +1 -1
- package/src/game/getAchievementCount.ts +1 -1
- package/src/game/getAchievementDistribution.test.ts +4 -4
- package/src/game/getAchievementDistribution.ts +1 -1
- package/src/game/getGame.test.ts +1 -1
- package/src/game/getGame.ts +1 -1
- package/src/game/getGameExtended.test.ts +1 -1
- package/src/game/getGameExtended.ts +1 -1
- package/src/game/getGameRankAndScore.test.ts +1 -1
- package/src/game/getGameRankAndScore.ts +1 -1
- package/src/game/getGameRating.test.ts +1 -1
- package/src/game/getGameRating.ts +1 -1
- package/src/ticket/getTicketData.test.ts +7 -7
- package/src/ticket/getTicketData.ts +13 -13
- package/src/user/getAchievementsEarnedBetween.test.ts +2 -2
- package/src/user/getAchievementsEarnedBetween.ts +6 -6
- package/src/user/getAchievementsEarnedOnDay.test.ts +2 -2
- package/src/user/getAchievementsEarnedOnDay.ts +6 -6
- package/src/user/getGameInfoAndUserProgress.test.ts +3 -3
- package/src/user/getGameInfoAndUserProgress.ts +22 -11
- package/src/user/getUserAwards.test.ts +2 -2
- package/src/user/getUserAwards.ts +6 -6
- package/src/user/getUserClaims.test.ts +2 -2
- package/src/user/getUserClaims.ts +6 -6
- package/src/user/getUserCompletedGames.test.ts +2 -2
- package/src/user/getUserCompletedGames.ts +6 -6
- package/src/user/getUserCompletionProgress.test.ts +2 -2
- package/src/user/getUserCompletionProgress.ts +6 -6
- package/src/user/getUserGameRankAndScore.test.ts +2 -2
- package/src/user/getUserGameRankAndScore.ts +6 -6
- package/src/user/getUserPoints.test.ts +2 -2
- package/src/user/getUserPoints.ts +6 -6
- package/src/user/getUserProfile.test.ts +2 -2
- package/src/user/getUserProfile.ts +6 -6
- package/src/user/getUserProgress.test.ts +2 -2
- package/src/user/getUserProgress.ts +6 -6
- package/src/user/getUserRecentAchievements.test.ts +2 -2
- package/src/user/getUserRecentAchievements.ts +6 -6
- package/src/user/getUserRecentlyPlayedGames.test.ts +2 -2
- package/src/user/getUserRecentlyPlayedGames.ts +6 -6
- package/src/user/getUserSummary.test.ts +4 -4
- package/src/user/getUserSummary.ts +6 -6
- package/src/user/models/game-info-and-user-progress.model.ts +4 -0
- package/src/user/models/get-game-info-and-user-progress-response.model.ts +4 -0
- 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/internal/buildRequestUrl.test.ts +2 -2
- package/src/utils/internal/buildRequestUrl.ts +1 -1
- package/src/utils/public/buildAuthorization.test.ts +3 -3
- package/src/utils/public/buildAuthorization.ts +4 -4
- package/src/utils/public/models/auth-object.model.ts +2 -2
- package/src/utils/public/models/award-kind.model.ts +5 -0
- package/src/utils/public/models/index.ts +1 -0
- package/src/console/models/console-id.model.ts +0 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GameExtended, GameExtendedAchievementEntity } from "../../game/models";
|
|
2
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
3
|
export type GameExtendedAchievementEntityWithUserProgress = GameExtendedAchievementEntity & {
|
|
3
4
|
dateEarned: string;
|
|
4
5
|
dateEarnedHardcore: string;
|
|
@@ -9,4 +10,6 @@ export interface GameInfoAndUserProgress extends GameExtended {
|
|
|
9
10
|
numAwardedToUserHardcore: number;
|
|
10
11
|
userCompletion: string;
|
|
11
12
|
userCompletionHardcore: string;
|
|
13
|
+
highestAwardKind?: AwardKind | null;
|
|
14
|
+
highestAwardDate?: string;
|
|
12
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GameExtendedRawAchievementEntity, GetGameExtendedResponse } from "../../game/models";
|
|
2
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
3
|
type GetGameExtendedResponseWithoutClaims = Omit<GetGameExtendedResponse, "Claims">;
|
|
3
4
|
type GameExtendedRawAchievementEntityWithUserProgress = GameExtendedRawAchievementEntity & {
|
|
4
5
|
DateEarned: string;
|
|
@@ -10,5 +11,7 @@ export interface GetGameInfoAndUserProgressResponse extends GetGameExtendedRespo
|
|
|
10
11
|
NumAwardedToUserHardcore: number;
|
|
11
12
|
UserCompletion: string;
|
|
12
13
|
UserCompletionHardcore: string;
|
|
14
|
+
HighestAwardKind?: AwardKind | null;
|
|
15
|
+
HighestAwardDate?: string;
|
|
13
16
|
}
|
|
14
17
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
1
2
|
interface RawUserCompletionProgressEntity {
|
|
2
3
|
GameID: number;
|
|
3
4
|
Title: string;
|
|
@@ -8,7 +9,7 @@ interface RawUserCompletionProgressEntity {
|
|
|
8
9
|
NumAwarded: number;
|
|
9
10
|
NumAwardedHardcore: number;
|
|
10
11
|
MostRecentAwardedDate?: string;
|
|
11
|
-
HighestAwardKind?:
|
|
12
|
+
HighestAwardKind?: AwardKind | null;
|
|
12
13
|
HighestAwardDate?: string | null;
|
|
13
14
|
}
|
|
14
15
|
export interface GetUserCompletionProgressResponse {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
1
2
|
export interface UserCompletionProgressEntity {
|
|
2
3
|
gameId: number;
|
|
3
4
|
title: string;
|
|
@@ -8,6 +9,6 @@ export interface UserCompletionProgressEntity {
|
|
|
8
9
|
numAwarded: number;
|
|
9
10
|
numAwardedHardcore: number;
|
|
10
11
|
mostRecentAwardedDate?: string;
|
|
11
|
-
highestAwardKind?:
|
|
12
|
+
highestAwardKind?: AwardKind | null;
|
|
12
13
|
highestAwardDate?: string;
|
|
13
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Each RetroAchievements API call is uniquely authenticated
|
|
3
|
-
* using a
|
|
3
|
+
* using a username + API key combination. Your account's personal
|
|
4
4
|
* Web API Key can be found on the Settings page.
|
|
5
5
|
*/
|
|
6
6
|
export interface AuthObject {
|
|
@@ -9,7 +9,7 @@ export interface AuthObject {
|
|
|
9
9
|
* For example, https://retroachievements.org/user/Scott would have a value
|
|
10
10
|
* of "Scott".
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
username: string;
|
|
13
13
|
/**
|
|
14
14
|
* This can be found in the "Keys" section of your Settings page on the
|
|
15
15
|
* RetroAchievements.org website. This is a 32-digit alphanumeric key
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type AwardKind = "beaten-softcore" | "beaten-hardcore" | "completed" | "mastered";
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"raweb",
|
|
11
11
|
"retro gaming"
|
|
12
12
|
],
|
|
13
|
-
"version": "1.
|
|
13
|
+
"version": "2.1.0",
|
|
14
14
|
"typings": "dist/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dev": "esrun --watch src/__playground.ts",
|
|
33
33
|
"prebuild": "node src/set-version.js",
|
|
34
34
|
"build": "microbundle",
|
|
35
|
-
"prepare": "microbundle",
|
|
35
|
+
"prepare": "microbundle && husky install",
|
|
36
36
|
"format": "prettier --write . '**/*.{json,md,js,ts,tsx}'",
|
|
37
37
|
"format:write": "prettier --write . '**/*.{json,md,js,ts,tsx}'",
|
|
38
38
|
"format:check": "prettier --check . '**/*.{json,md,js,ts,tsx}'",
|
|
@@ -41,10 +41,9 @@
|
|
|
41
41
|
"test": "vitest run",
|
|
42
42
|
"test:watch": "vitest",
|
|
43
43
|
"test:coverage": "vitest run --coverage",
|
|
44
|
-
"verify": "
|
|
44
|
+
"verify": "pnpm format:check && pnpm lint && pnpm test:coverage && pnpm build",
|
|
45
45
|
"start": "microbundle watch"
|
|
46
46
|
},
|
|
47
|
-
"peerDependencies": {},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@commitlint/cli": "^17.4.2",
|
|
50
49
|
"@commitlint/config-conventional": "^17.4.2",
|
|
@@ -62,7 +61,7 @@
|
|
|
62
61
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
63
62
|
"eslint-plugin-sonarjs": "^0.23.0",
|
|
64
63
|
"eslint-plugin-unicorn": "^49.0.0",
|
|
65
|
-
"husky": "
|
|
64
|
+
"husky": "9.0.11",
|
|
66
65
|
"microbundle": "^0.15.1",
|
|
67
66
|
"msw": "^2.0.3",
|
|
68
67
|
"prettier": "2.8.3",
|
|
@@ -74,12 +73,6 @@
|
|
|
74
73
|
"vite": "^4.5.0",
|
|
75
74
|
"vitest": "^0.34.6"
|
|
76
75
|
},
|
|
77
|
-
"husky": {
|
|
78
|
-
"hooks": {
|
|
79
|
-
"pre-commit": "pretty-quick --staged && yarn lint",
|
|
80
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
76
|
"config": {
|
|
84
77
|
"commitizen": {
|
|
85
78
|
"path": "./node_modules/cz-conventional-changelog"
|
|
@@ -102,5 +95,6 @@
|
|
|
102
95
|
"url": "https://github.com/RetroAchievements/api-js/issues"
|
|
103
96
|
},
|
|
104
97
|
"homepage": "https://github.com/RetroAchievements/api-js#readme",
|
|
105
|
-
"author": "RAWeb Team"
|
|
98
|
+
"author": "RAWeb Team",
|
|
99
|
+
"packageManager": "pnpm@9.1.1+sha256.9551e803dcb7a1839fdf5416153a844060c7bce013218ce823410532504ac10b"
|
|
106
100
|
}
|
package/src/__playground.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { buildAuthorization, getAchievementCount } from "./index";
|
|
18
18
|
|
|
19
19
|
// MODIFY THESE VALUES.
|
|
20
|
-
const
|
|
20
|
+
const username = "myUsername";
|
|
21
21
|
const webApiKey = "myWebApiKey";
|
|
22
22
|
|
|
23
23
|
const main = async () => {
|
|
@@ -25,13 +25,13 @@ const main = async () => {
|
|
|
25
25
|
|
|
26
26
|
// -- Start testing stuff here --
|
|
27
27
|
|
|
28
|
-
if (
|
|
28
|
+
if (username === "myUsername" || webApiKey === "myWebApiKey") {
|
|
29
29
|
console.error(
|
|
30
|
-
"⛔️ ERROR: In __playground.ts, modify the
|
|
30
|
+
"⛔️ ERROR: In __playground.ts, modify the username and webApiKey variables to match your RA credentials.\n"
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const authorization = buildAuthorization({
|
|
34
|
+
const authorization = buildAuthorization({ username, webApiKey });
|
|
35
35
|
|
|
36
36
|
const achievementCount = await getAchievementCount(authorization, {
|
|
37
37
|
gameId: 14_402,
|
|
@@ -22,7 +22,7 @@ describe("Function: getAchievementUnlocks", () => {
|
|
|
22
22
|
it("retrieves metadata about unlocks for a target achievement", async () => {
|
|
23
23
|
// ARRANGE
|
|
24
24
|
const authorization = buildAuthorization({
|
|
25
|
-
|
|
25
|
+
username: "mockUserName",
|
|
26
26
|
webApiKey: "mockWebApiKey",
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
* A call to this function will retrieve a list of users who
|
|
16
16
|
* have earned a given achievement, targeted by the achievement's ID.
|
|
17
17
|
*
|
|
18
|
-
* @param authorization An object containing your
|
|
18
|
+
* @param authorization An object containing your username and webApiKey.
|
|
19
19
|
* This can be constructed with `buildAuthorization()`.
|
|
20
20
|
*
|
|
21
21
|
* @param payload.achievementId The target achievement we want to
|
|
@@ -6,7 +6,7 @@ import { setupServer } from "msw/node";
|
|
|
6
6
|
import { apiBaseUrl } from "../utils/internal";
|
|
7
7
|
import { buildAuthorization } from "../utils/public";
|
|
8
8
|
import { getConsoleIds } from "./getConsoleIds";
|
|
9
|
-
import type {
|
|
9
|
+
import type { FetchedSystem, GetConsoleIdsResponse } from "./models";
|
|
10
10
|
|
|
11
11
|
const server = setupServer();
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ describe("Function: getConsoleIds", () => {
|
|
|
24
24
|
it("retrieves a list of console IDs and their names and cleans properties", async () => {
|
|
25
25
|
// ARRANGE
|
|
26
26
|
const authorization = buildAuthorization({
|
|
27
|
-
|
|
27
|
+
username: "mockUserName",
|
|
28
28
|
webApiKey: "mockWebApiKey",
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -34,18 +34,24 @@ describe("Function: getConsoleIds", () => {
|
|
|
34
34
|
Name: "Mega Drive",
|
|
35
35
|
IconURL:
|
|
36
36
|
"https://static.retroachievements.org/assets/images/system/md.png",
|
|
37
|
+
Active: true,
|
|
38
|
+
IsGameSystem: true,
|
|
37
39
|
},
|
|
38
40
|
{
|
|
39
41
|
ID: "2",
|
|
40
42
|
Name: "Nintendo 64",
|
|
41
43
|
IconURL:
|
|
42
44
|
"https://static.retroachievements.org/assets/images/system/n64.png",
|
|
45
|
+
Active: true,
|
|
46
|
+
IsGameSystem: true,
|
|
43
47
|
},
|
|
44
48
|
{
|
|
45
49
|
ID: "3",
|
|
46
50
|
Name: "SNES",
|
|
47
51
|
IconURL:
|
|
48
52
|
"https://static.retroachievements.org/assets/images/system/snes.png",
|
|
53
|
+
Active: false,
|
|
54
|
+
IsGameSystem: false,
|
|
49
55
|
},
|
|
50
56
|
];
|
|
51
57
|
|
|
@@ -59,24 +65,30 @@ describe("Function: getConsoleIds", () => {
|
|
|
59
65
|
const response = await getConsoleIds(authorization);
|
|
60
66
|
|
|
61
67
|
// ASSERT
|
|
62
|
-
const expectedResponse:
|
|
68
|
+
const expectedResponse: FetchedSystem[] = [
|
|
63
69
|
{
|
|
64
70
|
id: 1,
|
|
65
71
|
name: "Mega Drive",
|
|
66
72
|
iconUrl:
|
|
67
73
|
"https://static.retroachievements.org/assets/images/system/md.png",
|
|
74
|
+
active: true,
|
|
75
|
+
isGameSystem: true,
|
|
68
76
|
},
|
|
69
77
|
{
|
|
70
78
|
id: 2,
|
|
71
79
|
name: "Nintendo 64",
|
|
72
80
|
iconUrl:
|
|
73
81
|
"https://static.retroachievements.org/assets/images/system/n64.png",
|
|
82
|
+
active: true,
|
|
83
|
+
isGameSystem: true,
|
|
74
84
|
},
|
|
75
85
|
{
|
|
76
86
|
id: 3,
|
|
77
87
|
name: "SNES",
|
|
78
88
|
iconUrl:
|
|
79
89
|
"https://static.retroachievements.org/assets/images/system/snes.png",
|
|
90
|
+
active: false,
|
|
91
|
+
isGameSystem: false,
|
|
80
92
|
},
|
|
81
93
|
];
|
|
82
94
|
|
|
@@ -5,16 +5,22 @@ import {
|
|
|
5
5
|
serializeProperties,
|
|
6
6
|
} from "../utils/internal";
|
|
7
7
|
import type { AuthObject } from "../utils/public";
|
|
8
|
-
import type {
|
|
8
|
+
import type { FetchedSystem, GetConsoleIdsResponse } from "./models";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A call to this function will retrieve the complete list
|
|
12
12
|
* of console ID and name pairs on the RetroAchievements.org
|
|
13
13
|
* platform.
|
|
14
14
|
*
|
|
15
|
-
* @param authorization An object containing your
|
|
15
|
+
* @param authorization An object containing your username and webApiKey.
|
|
16
16
|
* This can be constructed with `buildAuthorization()`.
|
|
17
17
|
*
|
|
18
|
+
* @param payload.shouldOnlyRetrieveActiveSystems If true, only systems that
|
|
19
|
+
* officially support achievements will be returned.
|
|
20
|
+
*
|
|
21
|
+
* @param payload.shouldOnlyRetrieveGameSystems If true, events and hubs will
|
|
22
|
+
* not be returned.
|
|
23
|
+
*
|
|
18
24
|
* @example
|
|
19
25
|
* ```
|
|
20
26
|
* const consoleIds = await getConsoleIds(authorization);
|
|
@@ -26,17 +32,33 @@ import type { ConsoleId, GetConsoleIdsResponse } from "./models";
|
|
|
26
32
|
* {
|
|
27
33
|
* id: "1",
|
|
28
34
|
* name: "Mega Drive",
|
|
29
|
-
* iconUrl: "https://static.retroachievements.org/assets/images/system/md.png"
|
|
35
|
+
* iconUrl: "https://static.retroachievements.org/assets/images/system/md.png",
|
|
36
|
+
* active: true,
|
|
37
|
+
* isGameSystem: true
|
|
30
38
|
* }
|
|
31
39
|
* ```
|
|
32
40
|
*/
|
|
33
41
|
export const getConsoleIds = async (
|
|
34
|
-
authorization: AuthObject
|
|
35
|
-
|
|
42
|
+
authorization: AuthObject,
|
|
43
|
+
payload?: {
|
|
44
|
+
shouldOnlyRetrieveActiveSystems: boolean;
|
|
45
|
+
shouldOnlyRetrieveGameSystems: boolean;
|
|
46
|
+
}
|
|
47
|
+
): Promise<FetchedSystem[]> => {
|
|
48
|
+
let callPayload: Record<string, any> | undefined;
|
|
49
|
+
|
|
50
|
+
if (payload?.shouldOnlyRetrieveActiveSystems) {
|
|
51
|
+
callPayload = { ...callPayload, a: 1 };
|
|
52
|
+
}
|
|
53
|
+
if (payload?.shouldOnlyRetrieveGameSystems) {
|
|
54
|
+
callPayload = { ...callPayload, g: 1 };
|
|
55
|
+
}
|
|
56
|
+
|
|
36
57
|
const url = buildRequestUrl(
|
|
37
58
|
apiBaseUrl,
|
|
38
59
|
"/API_GetConsoleIDs.php",
|
|
39
|
-
authorization
|
|
60
|
+
authorization,
|
|
61
|
+
callPayload
|
|
40
62
|
);
|
|
41
63
|
|
|
42
64
|
const rawResponse = await call<GetConsoleIdsResponse>({ url });
|
|
@@ -24,7 +24,7 @@ describe("Function: getGameList", () => {
|
|
|
24
24
|
it("retrieves a list of games and cleans their properties", async () => {
|
|
25
25
|
// ARRANGE
|
|
26
26
|
const authorization = buildAuthorization({
|
|
27
|
-
|
|
27
|
+
username: "mockUserName",
|
|
28
28
|
webApiKey: "mockWebApiKey",
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -12,7 +12,7 @@ import type { GameList, GetGameListResponse } from "./models";
|
|
|
12
12
|
* of games for a specified console on the RetroAchievements.org
|
|
13
13
|
* platform.
|
|
14
14
|
*
|
|
15
|
-
* @param authorization An object containing your
|
|
15
|
+
* @param authorization An object containing your username and webApiKey.
|
|
16
16
|
* This can be constructed with `buildAuthorization()`.
|
|
17
17
|
*
|
|
18
18
|
* @param payload.consoleId The unique console ID to retrieve a list of
|
|
@@ -27,7 +27,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
27
27
|
it("retrieves metadata about the current achievement of the week and cleans properties", async () => {
|
|
28
28
|
// ARRANGE
|
|
29
29
|
const authorization = buildAuthorization({
|
|
30
|
-
|
|
30
|
+
username: "mockUserName",
|
|
31
31
|
webApiKey: "mockWebApiKey",
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -105,7 +105,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
105
105
|
it("properly sets the hardcore boolean value when cleaning properties", async () => {
|
|
106
106
|
// ARRANGE
|
|
107
107
|
const authorization = buildAuthorization({
|
|
108
|
-
|
|
108
|
+
username: "mockUserName",
|
|
109
109
|
webApiKey: "mockWebApiKey",
|
|
110
110
|
});
|
|
111
111
|
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
* A call to this function will retrieve comprehensive
|
|
15
15
|
* metadata about the current Achievement of the Week.
|
|
16
16
|
*
|
|
17
|
-
* @param authorization An object containing your
|
|
17
|
+
* @param authorization An object containing your username and webApiKey.
|
|
18
18
|
* This can be constructed with `buildAuthorization()`.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
@@ -24,7 +24,7 @@ describe("Function: getActiveClaims", () => {
|
|
|
24
24
|
it("retrieves metadata about current active claims", async () => {
|
|
25
25
|
// ARRANGE
|
|
26
26
|
const authorization = buildAuthorization({
|
|
27
|
-
|
|
27
|
+
username: "mockUserName",
|
|
28
28
|
webApiKey: "mockWebApiKey",
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -11,7 +11,7 @@ import type { GetSetClaimsResponse, SetClaim } from "./models";
|
|
|
11
11
|
* A call to this function returns information about all
|
|
12
12
|
* (1000 max) active set claims.
|
|
13
13
|
*
|
|
14
|
-
* @param authorization An object containing your
|
|
14
|
+
* @param authorization An object containing your username and webApiKey.
|
|
15
15
|
* This can be constructed with `buildAuthorization()`.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
@@ -24,7 +24,7 @@ describe("Function: getClaims", () => {
|
|
|
24
24
|
it("retrieves metadata about a requested kind of claims", async () => {
|
|
25
25
|
// ARRANGE
|
|
26
26
|
const authorization = buildAuthorization({
|
|
27
|
-
|
|
27
|
+
username: "mockUserName",
|
|
28
28
|
webApiKey: "mockWebApiKey",
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { http, HttpResponse } from "msw";
|
|
2
|
+
import { setupServer } from "msw/node";
|
|
3
|
+
|
|
4
|
+
import { apiBaseUrl } from "../utils/internal";
|
|
5
|
+
import { buildAuthorization } from "../utils/public";
|
|
6
|
+
import { getRecentGameAwards } from "./getRecentGameAwards";
|
|
7
|
+
import type { GetRecentGameAwardsResponse, RecentGameAwards } from "./models";
|
|
8
|
+
|
|
9
|
+
const server = setupServer();
|
|
10
|
+
|
|
11
|
+
describe("Function: getRecentGameAwards", () => {
|
|
12
|
+
// MSW Setup
|
|
13
|
+
beforeAll(() => server.listen());
|
|
14
|
+
afterEach(() => server.resetHandlers());
|
|
15
|
+
afterAll(() => server.close());
|
|
16
|
+
|
|
17
|
+
it("is defined #sanity", () => {
|
|
18
|
+
// ASSERT
|
|
19
|
+
expect(getRecentGameAwards).toBeDefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("retrieves metadata about all recently-earned game awards on the site", async () => {
|
|
23
|
+
// ARRANGE
|
|
24
|
+
const authorization = buildAuthorization({
|
|
25
|
+
username: "mockUserName",
|
|
26
|
+
webApiKey: "mockWebApiKey",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const mockResponse: GetRecentGameAwardsResponse = {
|
|
30
|
+
Count: 1,
|
|
31
|
+
Total: 1,
|
|
32
|
+
Results: [
|
|
33
|
+
{
|
|
34
|
+
User: "renanbrj",
|
|
35
|
+
AwardKind: "mastered",
|
|
36
|
+
AwardDate: "2022-01-01T23:48:04+00:00",
|
|
37
|
+
GameID: 14_284,
|
|
38
|
+
GameTitle: "Batman Returns",
|
|
39
|
+
ConsoleID: 15,
|
|
40
|
+
ConsoleName: "Game Gear",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
server.use(
|
|
46
|
+
http.get(`${apiBaseUrl}/API_GetRecentGameAwards.php`, () =>
|
|
47
|
+
HttpResponse.json(mockResponse)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// ACT
|
|
52
|
+
const response = await getRecentGameAwards(authorization);
|
|
53
|
+
|
|
54
|
+
const expectedResponse: RecentGameAwards = {
|
|
55
|
+
count: 1,
|
|
56
|
+
total: 1,
|
|
57
|
+
results: [
|
|
58
|
+
{
|
|
59
|
+
user: "renanbrj",
|
|
60
|
+
awardKind: "mastered",
|
|
61
|
+
awardDate: "2022-01-01T23:48:04+00:00",
|
|
62
|
+
gameId: 14_284,
|
|
63
|
+
gameTitle: "Batman Returns",
|
|
64
|
+
consoleId: 15,
|
|
65
|
+
consoleName: "Game Gear",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// ASSERT
|
|
71
|
+
expect(response).toEqual(expectedResponse);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiBaseUrl,
|
|
3
|
+
buildRequestUrl,
|
|
4
|
+
call,
|
|
5
|
+
serializeProperties,
|
|
6
|
+
} from "../utils/internal";
|
|
7
|
+
import type { AuthObject, AwardKind } from "../utils/public";
|
|
8
|
+
import type { GetRecentGameAwardsResponse, RecentGameAwards } from "./models";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A call to this function will retrieve all recently granted game
|
|
12
|
+
* awards across the site's userbase.
|
|
13
|
+
*
|
|
14
|
+
* @param authorization An object containing your username and webApiKey.
|
|
15
|
+
* This can be constructed with `buildAuthorization()`.
|
|
16
|
+
*
|
|
17
|
+
* @param payload.startDate The date to fetch awards from.
|
|
18
|
+
*
|
|
19
|
+
* @param payload.offset Optional. Defaults to 0.
|
|
20
|
+
*
|
|
21
|
+
* @param payload.count Optional. Defaults to 25.
|
|
22
|
+
*
|
|
23
|
+
* @param payload.desiredAwardKinds Optional. Defaults to all. Accepts "beaten-softcore", "beaten-hardcore", "completed", and/or "mastered".
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const recentGameAwards = await getRecentGameAwards(
|
|
28
|
+
* authorization,
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @returns An object containing metadata about all recently granted game
|
|
33
|
+
* awards across the site's userbase
|
|
34
|
+
* ```
|
|
35
|
+
* {
|
|
36
|
+
* count: 1,
|
|
37
|
+
* total: 1,
|
|
38
|
+
* results: [
|
|
39
|
+
* {
|
|
40
|
+
* user: "renanbrj",
|
|
41
|
+
* awardKind: "mastered",
|
|
42
|
+
* awardDate: "2022-01-01T23:48:04+00:00",
|
|
43
|
+
* gameId: 14_284,
|
|
44
|
+
* gameTitle: "Batman Returns",
|
|
45
|
+
* consoleId: 15,
|
|
46
|
+
* consoleName: "Game Gear",
|
|
47
|
+
* },
|
|
48
|
+
* ],
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const getRecentGameAwards = async (
|
|
53
|
+
authorization: AuthObject,
|
|
54
|
+
payload?: Partial<{
|
|
55
|
+
startDate: string;
|
|
56
|
+
offset: number;
|
|
57
|
+
count: number;
|
|
58
|
+
desiredAwardKinds: AwardKind[];
|
|
59
|
+
}>
|
|
60
|
+
): Promise<RecentGameAwards> => {
|
|
61
|
+
const queryParams: Record<string, any> = {};
|
|
62
|
+
if (payload?.startDate) {
|
|
63
|
+
queryParams.d = payload.startDate;
|
|
64
|
+
}
|
|
65
|
+
if (payload?.offset) {
|
|
66
|
+
queryParams.o = payload.offset;
|
|
67
|
+
}
|
|
68
|
+
if (payload?.count) {
|
|
69
|
+
queryParams.c = payload.count;
|
|
70
|
+
}
|
|
71
|
+
if (payload?.desiredAwardKinds) {
|
|
72
|
+
queryParams.k = payload.desiredAwardKinds.join(",");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const url = buildRequestUrl(
|
|
76
|
+
apiBaseUrl,
|
|
77
|
+
"/API_GetRecentGameAwards.php",
|
|
78
|
+
authorization,
|
|
79
|
+
queryParams
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const rawResponse = await call<GetRecentGameAwardsResponse>({ url });
|
|
83
|
+
|
|
84
|
+
return serializeProperties(rawResponse);
|
|
85
|
+
};
|
|
@@ -22,7 +22,7 @@ describe("Function: getTopTenUsers", () => {
|
|
|
22
22
|
it("retrieves metadata about the current top ten users on the site", async () => {
|
|
23
23
|
// ARRANGE
|
|
24
24
|
const authorization = buildAuthorization({
|
|
25
|
-
|
|
25
|
+
username: "mockUserName",
|
|
26
26
|
webApiKey: "mockWebApiKey",
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -51,48 +51,48 @@ describe("Function: getTopTenUsers", () => {
|
|
|
51
51
|
// ASSERT
|
|
52
52
|
expect(response).toEqual([
|
|
53
53
|
{
|
|
54
|
-
|
|
54
|
+
username: "MaxMilyin",
|
|
55
55
|
totalPoints: 346_289,
|
|
56
56
|
totalRatioPoints: 995_092,
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
|
-
|
|
59
|
+
username: "HippopotamusRex",
|
|
60
60
|
totalPoints: 312_118,
|
|
61
61
|
totalRatioPoints: 1_151_351,
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
|
|
64
|
+
username: "Sarconius",
|
|
65
65
|
totalPoints: 257_862,
|
|
66
66
|
totalRatioPoints: 1_181_770,
|
|
67
67
|
},
|
|
68
|
-
{
|
|
68
|
+
{ username: "guineu", totalPoints: 241_623, totalRatioPoints: 672_597 },
|
|
69
69
|
{
|
|
70
|
-
|
|
70
|
+
username: "Andrey199650",
|
|
71
71
|
totalPoints: 240_101,
|
|
72
72
|
totalRatioPoints: 567_522,
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
|
-
|
|
75
|
+
username: "Wendigo",
|
|
76
76
|
totalPoints: 227_903,
|
|
77
77
|
totalRatioPoints: 1_099_685,
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
|
-
|
|
80
|
+
username: "donutweegee",
|
|
81
81
|
totalPoints: 204_701,
|
|
82
82
|
totalRatioPoints: 587_221,
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
|
|
85
|
+
username: "AmericanNinja",
|
|
86
86
|
totalPoints: 202_980,
|
|
87
87
|
totalRatioPoints: 567_618,
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
|
-
|
|
90
|
+
username: "Infernum",
|
|
91
91
|
totalPoints: 202_171,
|
|
92
92
|
totalRatioPoints: 689_967,
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
|
-
|
|
95
|
+
username: "FabricioPrie",
|
|
96
96
|
totalPoints: 196_974,
|
|
97
97
|
totalRatioPoints: 450_436,
|
|
98
98
|
},
|