@retroachievements/api 2.0.0 → 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 (34) hide show
  1. package/README.md +1 -0
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.cjs.map +1 -1
  4. package/dist/api.modern.js +1 -1
  5. package/dist/api.modern.js.map +1 -1
  6. package/dist/api.module.js +1 -1
  7. package/dist/api.module.js.map +1 -1
  8. package/dist/api.umd.js +1 -1
  9. package/dist/api.umd.js.map +1 -1
  10. package/dist/feed/getRecentGameAwards.d.ts +50 -0
  11. package/dist/feed/getRecentGameAwards.test.d.ts +1 -0
  12. package/dist/feed/index.d.ts +1 -0
  13. package/dist/feed/models/get-recent-game-awards-response.model.d.ts +14 -0
  14. package/dist/feed/models/index.d.ts +2 -0
  15. package/dist/feed/models/recent-game-awards.model.d.ts +14 -0
  16. package/dist/user/models/game-info-and-user-progress.model.d.ts +2 -1
  17. package/dist/user/models/get-game-info-and-user-progress-response.model.d.ts +2 -1
  18. package/dist/user/models/get-user-completion-progress-response.model.d.ts +2 -1
  19. package/dist/user/models/user-completion-progress-entity.model.d.ts +2 -1
  20. package/dist/utils/public/models/award-kind.model.d.ts +1 -0
  21. package/dist/utils/public/models/index.d.ts +1 -0
  22. package/package.json +1 -1
  23. package/src/feed/getRecentGameAwards.test.ts +73 -0
  24. package/src/feed/getRecentGameAwards.ts +85 -0
  25. package/src/feed/index.ts +1 -0
  26. package/src/feed/models/get-recent-game-awards-response.model.ts +15 -0
  27. package/src/feed/models/index.ts +2 -0
  28. package/src/feed/models/recent-game-awards.model.ts +15 -0
  29. package/src/user/models/game-info-and-user-progress.model.ts +2 -6
  30. package/src/user/models/get-game-info-and-user-progress-response.model.ts +2 -6
  31. package/src/user/models/get-user-completion-progress-response.model.ts +3 -6
  32. package/src/user/models/user-completion-progress-entity.model.ts +3 -6
  33. package/src/utils/public/models/award-kind.model.ts +5 -0
  34. package/src/utils/public/models/index.ts +1 -0
@@ -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
  }
@@ -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": "2.0.0",
13
+ "version": "2.1.0",
14
14
  "typings": "dist/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
@@ -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
+ };
package/src/feed/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./getAchievementOfTheWeek";
2
2
  export * from "./getActiveClaims";
3
3
  export * from "./getClaims";
4
+ export * from "./getRecentGameAwards";
4
5
  export * from "./getTopTenUsers";
5
6
  export * from "./models";
@@ -0,0 +1,15 @@
1
+ import type { AwardKind } from "../../utils/public";
2
+
3
+ export interface GetRecentGameAwardsResponse {
4
+ Count: number;
5
+ Total: number;
6
+ Results: Array<{
7
+ User: string;
8
+ AwardKind: AwardKind;
9
+ AwardDate: string;
10
+ GameID: number;
11
+ GameTitle: string;
12
+ ConsoleID: number;
13
+ ConsoleName: string;
14
+ }>;
15
+ }
@@ -3,8 +3,10 @@ export * from "./claim-set-type.enum";
3
3
  export * from "./claim-status.enum";
4
4
  export * from "./claim-type.enum";
5
5
  export * from "./get-achievement-of-the-week-response.model";
6
+ export * from "./get-recent-game-awards-response.model";
6
7
  export * from "./get-set-claims-response.model";
7
8
  export * from "./get-top-ten-users-response.model";
9
+ export * from "./recent-game-awards.model";
8
10
  export * from "./set-claim.model";
9
11
  export * from "./top-ten-users.model";
10
12
  export * from "./top-ten-users-entity.model";
@@ -0,0 +1,15 @@
1
+ import type { AwardKind } from "../../utils/public";
2
+
3
+ export interface RecentGameAwards {
4
+ count: number;
5
+ total: number;
6
+ results: Array<{
7
+ user: string;
8
+ awardKind: AwardKind;
9
+ awardDate: string;
10
+ gameId: number;
11
+ gameTitle: string;
12
+ consoleId: number;
13
+ consoleName: string;
14
+ }>;
15
+ }
@@ -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
  }
@@ -0,0 +1,5 @@
1
+ export type AwardKind =
2
+ | "beaten-softcore"
3
+ | "beaten-hardcore"
4
+ | "completed"
5
+ | "mastered";
@@ -1 +1,2 @@
1
1
  export * from "./auth-object.model";
2
+ export * from "./award-kind.model";