hive-bedrock-api 2.1.11 → 3.0.0-alpha.2

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 CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  An API wrapper for the Hive Minecraft Bedrock Edition server. Which allows you to get stats for leaderboards, players, cosmetics, unique player counts, maps and metadata.
4
4
 
5
+ > [!NOTE]
6
+ > This API responses returnded from this package will differ from the responses returned by the offical Hive API. This due to our preference and needs when using this package on [Hive Backpack](https://hivebackpack.com).
7
+
5
8
  ## Getting started
6
9
 
7
10
  ```bash
@@ -9,128 +12,105 @@ $ npm install hive-bedrock-api
9
12
  $ yarn add hive-bedrock-api
10
13
  ```
11
14
 
15
+ You should also include `hive-bedrock-data` as it includes useful functions and game information.
16
+
12
17
  ## Usage
13
18
 
14
- See [API.md](docs/API.md) for detailed documentation.
15
-
16
- ### Fetch Player Infomation
19
+ To start using this API wrapper you may construct the main class `HiveAPI`. This class can take in seperate options that will be used in every http request.
17
20
 
18
21
  ```ts
19
- import { getPlayerInformation } from "hive-bedrock-api";
20
-
21
- // Returns player, cosmetics, server statistics and profile infomation
22
- const { data, error } = await getPlayerInformation("player");
22
+ const api = new HiveAPI({
23
+ resolveDynamicTitles: true,
24
+ apiBaseEndpoint: "https://api.playhive.com/v0",
25
+ requestInit: { headers: {} },
26
+ });
23
27
  ```
24
28
 
25
- ### Fetch All-Time Player Statistics
29
+ ### Fetch Player Infomation
26
30
 
27
31
  ```ts
28
- import { getAllTimeStatistics, Game } from "hive-bedrock-api";
29
-
30
- // Returns all games
31
- const { data, error } = await getAllTimeStats("player");
32
-
33
- // Returns a single game
34
- const { data, error } = await getAllTimeStats("player", Game.HideAndSeek);
32
+ // Returns player, cosmetics, server statistics and profile infomation
33
+ const { data, error, meta } = await api.getPlayer("player");
35
34
  ```
36
35
 
37
- ### Fetch Season Player Statistics
36
+ ### Fetch Player Search
38
37
 
39
38
  ```ts
40
- import { getSeasonStatistics, Game } from "hive-bedrock-api";
41
-
42
- // Returns a game statistics
43
- const { data, error } = await getSeasonStatistics("player", Game.BedWars);
39
+ // Returns a list of players matching the prefix
40
+ const { data, error, meta } = await api.getPlayerSearch("prefix");
44
41
  ```
45
42
 
46
- ### Fetch Monthly Player Statistics
43
+ ### Fetch All-Time/Monthly Player Statistics
47
44
 
48
45
  ```ts
49
- import { getMonthlyStatistics, Game } from "hive-bedrock-api";
50
-
51
- // Returns all games
52
- const { data, error } = await getMonthlyStats("player");
46
+ import { Timeframe, Game } from "hive-bedrock-data";
53
47
 
54
- // Returns a single game
55
- const { data, error } = await getMonthlyStats("player", Game.BlockDrop);
48
+ // Returns all all-time games
49
+ const { data, error, meta } = await api.getStatistics("player", Timeframe.AllTime);
50
+ // Returns all monthly games
51
+ const { data, error, meta } = await api.getStatistics("player", Timeframe.Monthly);
56
52
 
57
- // Returns a single game in a previous month (can return muliple games)
58
- const { data, error } = await getMonthlyStats("player", Game.BlockDrop, {
59
- year: 2023,
60
- month: 1, // January
61
- });
53
+ // Add in options a game to return a single game
54
+ const { data, error, meta } = await api.getStatistics("player", Timeframe.AllTime, { game: Game.BedWars });
62
55
  ```
63
56
 
64
- ### Fetch All-Time Leaderboard
57
+ ### Fetch Seasonal Player Statistics
65
58
 
66
59
  ```ts
67
- import { getAllTimeLeaderboard, Game } from "hive-bedrock-api";
60
+ import { Game } from "hive-bedrock-data";
68
61
 
69
- // Returns a single game
70
- const { data, error } = await getAllTimeLeaderboard(Game.TreasureWars);
62
+ // Returns seasonal statistics for a game
63
+ const { data, error, meta } = await api.getSeasonalStatistics("player", Game.BedWars, 1);
71
64
  ```
72
65
 
73
- ### Fetch Season Leaderboard
66
+ ### Fetch All-Time/Monthly Leaderboard
74
67
 
75
68
  ```ts
76
- import { getSeasonLeaderboard, Game } from "hive-bedrock-api";
69
+ import { Timeframe, Game } from "hive-bedrock-data";
70
+
71
+ // Returns all-time leaderboard
72
+ const { data, error, meta } = await api.getLeaderboard(Timeframe.AllTime, Game.SkyWars);
73
+ // Returns monthly leaderboard
74
+ const { data, error, meta } = await api.getLeaderboard(Timeframe.Monthly, Game.SkyWars);
77
75
 
78
- // Returns a single game
79
- const { data, error } = await getSeasonLeaderboard(Game.BedWars);
76
+ // Add in options the month and year for a specific leaderboard
77
+ const { data, error, meta } = await api.getLeaderboard(Timeframe.Monthly, { month: 11, year: 2024 });
80
78
  ```
81
79
 
82
- ### Fetch Monthly Leaderboard
80
+ ### Fetch Seasonal Leaderboard
83
81
 
84
82
  ```ts
85
- import { getMonthlyLeaderboard, Game } from "hive-bedrock-api";
83
+ import { Game } from "hive-bedrock-data";
86
84
 
87
- // Returns a single game
88
- const { data, error } = await getMonthlyLeaderboard(Game.TreasureWars);
89
-
90
- // Returns a single game from a previous month
91
- const { data, error } = await getMonthlyLeaderboard(Game.BlockParty, {
92
- year: 2023,
93
- month: 11, // November
94
- amount: 50,
95
- skip: 20, // Sum of skip and amount must be <=100
96
- });
85
+ // Returns seasonal leaderboard for a game
86
+ const { data, error, meta } = await api.getSeasonalLeaderboard(Game.BedWars, 1);
97
87
  ```
98
88
 
99
89
  ### Fetch Global Statistics
100
90
 
101
91
  ```ts
102
- import { getGlobalStatistics } from "hive-bedrock-api";
103
-
104
92
  // Returns unqiue total player counts for different games
105
- const { data, error } = await getGlobalStatistics();
93
+ const { data, error, meta } = await api.getGlobalStatistics();
106
94
  ```
107
95
 
108
96
  ### Fetch Maps
109
97
 
110
98
  ```ts
111
- import { getMaps, Game } from "hive-bedrock-api";
99
+ import { Game } from "hive-bedrock-data";
112
100
 
113
101
  // Returns data for a specific game's currently active maps
114
- const { data, error } = await getMaps(Game.TreasureWars);
102
+ const { data, error, meta } = await api.getGameMaps(Game.TreasureWars);
115
103
  ```
116
104
 
117
105
  ### Fetch Metadata
118
106
 
119
107
  ```ts
120
- import { getMetadata, Game } from "hive-bedrock-api";
108
+ import { Game } from "hive-bedrock-data";
121
109
 
122
110
  // Returns data for a specific game's currently active maps
123
- const { data, error } = await getMetadata(Game.TreasureWars);
111
+ const { data, error, meta } = await api.getGameMetadata(Game.TreasureWars);
124
112
  ```
125
113
 
126
- ## API Response Changes
127
-
128
- Different API responses are edited by the wrapper to provide more data:
129
-
130
- - Game responses have a new value "id" showing the parent game
131
- - A new value for "losses" is provided
132
- - A new value for "kdr" is provided
133
- - "xp" is converted and a "level" is provided
134
- - "total_ratings" for just build is provided
114
+ ## Documentation
135
115
 
136
- See [API.md](docs/API.md#game-statistics-types) for specific fields and their corresponding types per game.
116
+ More documentation will be added about what is returned when using this package.
package/lib/index.d.ts CHANGED
@@ -1,14 +1,95 @@
1
- import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
2
- import getAllTimeStatistics from "./methods/getAllTimeStatistics";
3
- import getGlobalStatistics from "./methods/getGlobalStatistics";
4
- import getMaps from "./methods/getMaps";
5
- import getMetdata from "./methods/getMetadata";
6
- import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard";
7
- import getMonthlyStatistics from "./methods/getMonthlyStatistics";
8
- import getPlayerInfomation from "./methods/getPlayerInfomation";
9
- import getSeasonLeaderboard from "./methods/getSeasonLeaderboard";
10
- import getSeasonStatistics from "./methods/getSeasonStatistics";
11
- export { getAllTimeLeaderboard, getMonthlyLeaderboard, getAllTimeStatistics, getMonthlyStatistics, getGlobalStatistics, getMaps, getMetdata, getPlayerInfomation, getSeasonLeaderboard, getSeasonStatistics, };
12
- export { Game } from "hive-bedrock-data";
13
- export type * from "./types/output";
14
- export * from "./processors/index";
1
+ import { Game, Timeframe } from "hive-bedrock-data";
2
+ import { MethodResponse } from "./utils";
3
+ import { ProcessedPlayerResponse } from "./processors/player";
4
+ import { ProcessedGlobalStatisticsResponse } from "./processors/global_statistics";
5
+ import { ProcessedMapResponse } from "./processors/map";
6
+ import { ProcessedGameMetadata } from "./processors/meta";
7
+ import { ProcessedPlayerSearchResponse } from "./processors/player_search";
8
+ import { ProcessedAllGamesResponse, ProcessedGame } from "./processors/game";
9
+ interface Options {
10
+ resolveDynamicTitles?: boolean;
11
+ apiBaseEndpoint?: string;
12
+ requestInit?: RequestInit;
13
+ }
14
+ export default class HiveAPI {
15
+ options: Options;
16
+ constructor(options?: Options);
17
+ private _fetchAPI;
18
+ /**
19
+ * `/game/all/main/{identifier}` Gets information about a player
20
+ * @param identifier Username or UUID of the player
21
+ * @returns The player information
22
+ */
23
+ getPlayer(identifier: string): Promise<MethodResponse<ProcessedPlayerResponse>>;
24
+ /**
25
+ * `/player/search/{prefix}` Gets a list of players that match the prefix
26
+ * @param prefix The prefix to search for (must be at least 4 characters long)
27
+ * @returns A list of players that match the prefix
28
+ */
29
+ getPlayerSearch(prefix: string): Promise<MethodResponse<ProcessedPlayerSearchResponse>>;
30
+ /**
31
+ * Gets statistics for a player
32
+ * @param identifier Username or UUID of the player
33
+ * @param timeframe The timeframe to get the statistics for
34
+ * @param options Additional options including specific game, month, and year
35
+ * @returns The player statistics
36
+ */
37
+ getStatistics(identifier: string, timeframe: Timeframe.AllTime): Promise<MethodResponse<ProcessedAllGamesResponse>>;
38
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.AllTime, options: {
39
+ game: G;
40
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, false>[G]>>;
41
+ getStatistics(identifier: string, timeframe: Timeframe.Monthly, options?: {
42
+ month?: number;
43
+ year?: number;
44
+ }): Promise<MethodResponse<ProcessedAllGamesResponse>>;
45
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Monthly, options: {
46
+ game: G;
47
+ month?: number;
48
+ year?: number;
49
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, false>[G]>>;
50
+ private _getStatisticsAllTime;
51
+ private _getStatisticsMonthly;
52
+ /**
53
+ * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
54
+ * @param identifier Username or UUID of the player
55
+ * @param game The game to get the statistics for
56
+ * @param season The season to get the statistics for
57
+ * @returns The player's seasonal statistics
58
+ */
59
+ getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G] | null>>;
60
+ /**
61
+ * `/game/all/{game}` Gets statistics for a game
62
+ * @param timeframe The timeframe to get the statistics for
63
+ * @param game The game to get the statistics for
64
+ * @param options Additional options including specific month and year
65
+ */
66
+ getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
67
+ getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
68
+ private _getLeaderboardAllTime;
69
+ private _getLeaderboardMonthly;
70
+ /**
71
+ * `/game/season/{game}/{season}` Gets seasonal statistics for a game
72
+ * @param game The game to get the statistics for
73
+ * @param season The season to get the statistics for
74
+ * @returns The seasonal statistics for the game
75
+ */
76
+ getSeasonalLeaderboard<G extends Game>(game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][]>>;
77
+ /**
78
+ * `/global/statistics` Gets global statistics
79
+ * @returns The global statistics
80
+ */
81
+ getGlobalStatistics(): Promise<MethodResponse<ProcessedGlobalStatisticsResponse>>;
82
+ /**
83
+ * `/game/map/{game}` Gets information about the maps in a game
84
+ * @param game The game to get the maps for (fails for games without maps)
85
+ * @returns A list of maps in the game
86
+ */
87
+ getGameMaps(game: Game): Promise<MethodResponse<ProcessedMapResponse>>;
88
+ /**
89
+ * `/game/meta/{game}` Gets metadata about a game
90
+ * @param game The game to get the metadata for
91
+ * @returns The metadata for the game
92
+ */
93
+ getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
94
+ }
95
+ export {};