@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.
Files changed (133) hide show
  1. package/README.md +3 -2
  2. package/dist/achievement/getAchievementUnlocks.d.ts +1 -1
  3. package/dist/api.cjs +1 -1
  4. package/dist/api.cjs.map +1 -1
  5. package/dist/api.modern.js +1 -1
  6. package/dist/api.modern.js.map +1 -1
  7. package/dist/api.module.js +1 -1
  8. package/dist/api.module.js.map +1 -1
  9. package/dist/api.umd.js +1 -1
  10. package/dist/api.umd.js.map +1 -1
  11. package/dist/console/getConsoleIds.d.ts +15 -4
  12. package/dist/console/getGameList.d.ts +1 -1
  13. package/dist/console/models/fetched-system.model.d.ts +7 -0
  14. package/dist/console/models/get-console-ids-response.model.d.ts +2 -0
  15. package/dist/console/models/index.d.ts +1 -1
  16. package/dist/feed/getAchievementOfTheWeek.d.ts +1 -1
  17. package/dist/feed/getActiveClaims.d.ts +1 -1
  18. package/dist/feed/getRecentGameAwards.d.ts +50 -0
  19. package/dist/feed/getRecentGameAwards.test.d.ts +1 -0
  20. package/dist/feed/getTopTenUsers.d.ts +3 -3
  21. package/dist/feed/index.d.ts +1 -0
  22. package/dist/feed/models/get-recent-game-awards-response.model.d.ts +14 -0
  23. package/dist/feed/models/index.d.ts +2 -0
  24. package/dist/feed/models/recent-game-awards.model.d.ts +14 -0
  25. package/dist/feed/models/top-ten-users-entity.model.d.ts +1 -1
  26. package/dist/game/getAchievementCount.d.ts +1 -1
  27. package/dist/game/getAchievementDistribution.d.ts +1 -1
  28. package/dist/game/getGame.d.ts +1 -1
  29. package/dist/game/getGameExtended.d.ts +1 -1
  30. package/dist/game/getGameRankAndScore.d.ts +1 -1
  31. package/dist/game/getGameRating.d.ts +1 -1
  32. package/dist/ticket/getTicketData.d.ts +9 -9
  33. package/dist/user/getAchievementsEarnedBetween.d.ts +4 -4
  34. package/dist/user/getAchievementsEarnedOnDay.d.ts +4 -4
  35. package/dist/user/getGameInfoAndUserProgress.d.ts +9 -5
  36. package/dist/user/getUserAwards.d.ts +4 -4
  37. package/dist/user/getUserClaims.d.ts +4 -4
  38. package/dist/user/getUserCompletedGames.d.ts +4 -4
  39. package/dist/user/getUserCompletionProgress.d.ts +4 -4
  40. package/dist/user/getUserGameRankAndScore.d.ts +4 -4
  41. package/dist/user/getUserPoints.d.ts +4 -4
  42. package/dist/user/getUserProfile.d.ts +4 -4
  43. package/dist/user/getUserProgress.d.ts +4 -4
  44. package/dist/user/getUserRecentAchievements.d.ts +4 -4
  45. package/dist/user/getUserRecentlyPlayedGames.d.ts +4 -4
  46. package/dist/user/getUserSummary.d.ts +4 -4
  47. package/dist/user/models/game-info-and-user-progress.model.d.ts +3 -0
  48. package/dist/user/models/get-game-info-and-user-progress-response.model.d.ts +3 -0
  49. package/dist/user/models/get-user-completion-progress-response.model.d.ts +2 -1
  50. package/dist/user/models/user-completion-progress-entity.model.d.ts +2 -1
  51. package/dist/utils/public/buildAuthorization.d.ts +1 -1
  52. package/dist/utils/public/models/auth-object.model.d.ts +2 -2
  53. package/dist/utils/public/models/award-kind.model.d.ts +1 -0
  54. package/dist/utils/public/models/index.d.ts +1 -0
  55. package/package.json +6 -12
  56. package/src/__playground.ts +4 -4
  57. package/src/achievement/getAchievementUnlocks.test.ts +1 -1
  58. package/src/achievement/getAchievementUnlocks.ts +1 -1
  59. package/src/console/getConsoleIds.test.ts +15 -3
  60. package/src/console/getConsoleIds.ts +28 -6
  61. package/src/console/getGameList.test.ts +1 -1
  62. package/src/console/getGameList.ts +1 -1
  63. package/src/console/models/fetched-system.model.ts +7 -0
  64. package/src/console/models/get-console-ids-response.model.ts +2 -0
  65. package/src/console/models/index.ts +1 -1
  66. package/src/feed/getAchievementOfTheWeek.test.ts +2 -2
  67. package/src/feed/getAchievementOfTheWeek.ts +1 -1
  68. package/src/feed/getActiveClaims.test.ts +1 -1
  69. package/src/feed/getActiveClaims.ts +1 -1
  70. package/src/feed/getClaims.test.ts +1 -1
  71. package/src/feed/getRecentGameAwards.test.ts +73 -0
  72. package/src/feed/getRecentGameAwards.ts +85 -0
  73. package/src/feed/getTopTenUsers.test.ts +11 -11
  74. package/src/feed/getTopTenUsers.ts +4 -4
  75. package/src/feed/index.ts +1 -0
  76. package/src/feed/models/get-recent-game-awards-response.model.ts +15 -0
  77. package/src/feed/models/index.ts +2 -0
  78. package/src/feed/models/recent-game-awards.model.ts +15 -0
  79. package/src/feed/models/top-ten-users-entity.model.ts +1 -1
  80. package/src/game/getAchievementCount.test.ts +1 -1
  81. package/src/game/getAchievementCount.ts +1 -1
  82. package/src/game/getAchievementDistribution.test.ts +4 -4
  83. package/src/game/getAchievementDistribution.ts +1 -1
  84. package/src/game/getGame.test.ts +1 -1
  85. package/src/game/getGame.ts +1 -1
  86. package/src/game/getGameExtended.test.ts +1 -1
  87. package/src/game/getGameExtended.ts +1 -1
  88. package/src/game/getGameRankAndScore.test.ts +1 -1
  89. package/src/game/getGameRankAndScore.ts +1 -1
  90. package/src/game/getGameRating.test.ts +1 -1
  91. package/src/game/getGameRating.ts +1 -1
  92. package/src/ticket/getTicketData.test.ts +7 -7
  93. package/src/ticket/getTicketData.ts +13 -13
  94. package/src/user/getAchievementsEarnedBetween.test.ts +2 -2
  95. package/src/user/getAchievementsEarnedBetween.ts +6 -6
  96. package/src/user/getAchievementsEarnedOnDay.test.ts +2 -2
  97. package/src/user/getAchievementsEarnedOnDay.ts +6 -6
  98. package/src/user/getGameInfoAndUserProgress.test.ts +3 -3
  99. package/src/user/getGameInfoAndUserProgress.ts +22 -11
  100. package/src/user/getUserAwards.test.ts +2 -2
  101. package/src/user/getUserAwards.ts +6 -6
  102. package/src/user/getUserClaims.test.ts +2 -2
  103. package/src/user/getUserClaims.ts +6 -6
  104. package/src/user/getUserCompletedGames.test.ts +2 -2
  105. package/src/user/getUserCompletedGames.ts +6 -6
  106. package/src/user/getUserCompletionProgress.test.ts +2 -2
  107. package/src/user/getUserCompletionProgress.ts +6 -6
  108. package/src/user/getUserGameRankAndScore.test.ts +2 -2
  109. package/src/user/getUserGameRankAndScore.ts +6 -6
  110. package/src/user/getUserPoints.test.ts +2 -2
  111. package/src/user/getUserPoints.ts +6 -6
  112. package/src/user/getUserProfile.test.ts +2 -2
  113. package/src/user/getUserProfile.ts +6 -6
  114. package/src/user/getUserProgress.test.ts +2 -2
  115. package/src/user/getUserProgress.ts +6 -6
  116. package/src/user/getUserRecentAchievements.test.ts +2 -2
  117. package/src/user/getUserRecentAchievements.ts +6 -6
  118. package/src/user/getUserRecentlyPlayedGames.test.ts +2 -2
  119. package/src/user/getUserRecentlyPlayedGames.ts +6 -6
  120. package/src/user/getUserSummary.test.ts +4 -4
  121. package/src/user/getUserSummary.ts +6 -6
  122. package/src/user/models/game-info-and-user-progress.model.ts +4 -0
  123. package/src/user/models/get-game-info-and-user-progress-response.model.ts +4 -0
  124. package/src/user/models/get-user-completion-progress-response.model.ts +3 -6
  125. package/src/user/models/user-completion-progress-entity.model.ts +3 -6
  126. package/src/utils/internal/buildRequestUrl.test.ts +2 -2
  127. package/src/utils/internal/buildRequestUrl.ts +1 -1
  128. package/src/utils/public/buildAuthorization.test.ts +3 -3
  129. package/src/utils/public/buildAuthorization.ts +4 -4
  130. package/src/utils/public/models/auth-object.model.ts +2 -2
  131. package/src/utils/public/models/award-kind.model.ts +5 -0
  132. package/src/utils/public/models/index.ts +1 -0
  133. 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?: "mastered" | "completed" | "beaten-hardcore" | "beaten-softcore" | null;
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?: "mastered" | "completed" | "beaten-hardcore" | "beaten-softcore" | null;
12
+ highestAwardKind?: AwardKind | null;
12
13
  highestAwardDate?: string;
13
14
  }
@@ -14,7 +14,7 @@ import type { AuthObject } from "./models";
14
14
  * @example
15
15
  * ```
16
16
  * const authorization = buildAuthorization({
17
- * userName: "Scott",
17
+ * username: "Scott",
18
18
  * webApiKey: "LtjCwW16nJI7cqOyPIQtXk8v1cfF0tmO"
19
19
  * });
20
20
  * ```
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Each RetroAchievements API call is uniquely authenticated
3
- * using a userName + API key combination. Your account's personal
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
- userName: string;
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";
@@ -1 +1,2 @@
1
1
  export * from "./auth-object.model";
2
+ export * from "./award-kind.model";
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "raweb",
11
11
  "retro gaming"
12
12
  ],
13
- "version": "1.5.3",
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": "yarn format:check && yarn lint && yarn test:coverage && yarn build",
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": "4.3.8",
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
  }
@@ -17,7 +17,7 @@
17
17
  import { buildAuthorization, getAchievementCount } from "./index";
18
18
 
19
19
  // MODIFY THESE VALUES.
20
- const userName = "myUserName";
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 (userName === "myUserName" || webApiKey === "myWebApiKey") {
28
+ if (username === "myUsername" || webApiKey === "myWebApiKey") {
29
29
  console.error(
30
- "⛔️ ERROR: In __playground.ts, modify the userName and webApiKey variables to match your RA credentials.\n"
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({ userName, webApiKey });
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
- userName: "mockUserName",
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 userName and webApiKey.
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 { ConsoleId, GetConsoleIdsResponse } from "./models";
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
- userName: "mockUserName",
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: ConsoleId[] = [
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 { ConsoleId, GetConsoleIdsResponse } from "./models";
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 userName and webApiKey.
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
- ): Promise<ConsoleId[]> => {
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
- userName: "mockUserName",
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 userName and webApiKey.
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
@@ -0,0 +1,7 @@
1
+ export interface FetchedSystem {
2
+ id: number;
3
+ name: string;
4
+ iconUrl: string;
5
+ active: boolean;
6
+ isGameSystem: boolean;
7
+ }
@@ -2,4 +2,6 @@ export type GetConsoleIdsResponse = readonly {
2
2
  ID: string;
3
3
  Name: string;
4
4
  IconURL: string;
5
+ Active: boolean;
6
+ IsGameSystem: boolean;
5
7
  }[];
@@ -1,4 +1,4 @@
1
- export * from "./console-id.model";
1
+ export * from "./fetched-system.model";
2
2
  export * from "./game-list.model";
3
3
  export * from "./get-console-ids-response.model";
4
4
  export * from "./get-game-list-response.model";
@@ -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
- userName: "mockUserName",
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
- userName: "mockUserName",
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 userName and webApiKey.
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
- userName: "mockUserName",
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 userName and webApiKey.
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
- userName: "mockUserName",
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
- userName: "mockUserName",
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
- userName: "MaxMilyin",
54
+ username: "MaxMilyin",
55
55
  totalPoints: 346_289,
56
56
  totalRatioPoints: 995_092,
57
57
  },
58
58
  {
59
- userName: "HippopotamusRex",
59
+ username: "HippopotamusRex",
60
60
  totalPoints: 312_118,
61
61
  totalRatioPoints: 1_151_351,
62
62
  },
63
63
  {
64
- userName: "Sarconius",
64
+ username: "Sarconius",
65
65
  totalPoints: 257_862,
66
66
  totalRatioPoints: 1_181_770,
67
67
  },
68
- { userName: "guineu", totalPoints: 241_623, totalRatioPoints: 672_597 },
68
+ { username: "guineu", totalPoints: 241_623, totalRatioPoints: 672_597 },
69
69
  {
70
- userName: "Andrey199650",
70
+ username: "Andrey199650",
71
71
  totalPoints: 240_101,
72
72
  totalRatioPoints: 567_522,
73
73
  },
74
74
  {
75
- userName: "Wendigo",
75
+ username: "Wendigo",
76
76
  totalPoints: 227_903,
77
77
  totalRatioPoints: 1_099_685,
78
78
  },
79
79
  {
80
- userName: "donutweegee",
80
+ username: "donutweegee",
81
81
  totalPoints: 204_701,
82
82
  totalRatioPoints: 587_221,
83
83
  },
84
84
  {
85
- userName: "AmericanNinja",
85
+ username: "AmericanNinja",
86
86
  totalPoints: 202_980,
87
87
  totalRatioPoints: 567_618,
88
88
  },
89
89
  {
90
- userName: "Infernum",
90
+ username: "Infernum",
91
91
  totalPoints: 202_171,
92
92
  totalRatioPoints: 689_967,
93
93
  },
94
94
  {
95
- userName: "FabricioPrie",
95
+ username: "FabricioPrie",
96
96
  totalPoints: 196_974,
97
97
  totalRatioPoints: 450_436,
98
98
  },