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 +49 -69
- package/lib/index.d.ts +95 -14
- package/lib/index.js +378 -35
- package/lib/processors/game.d.ts +299 -0
- package/lib/processors/game.js +390 -0
- package/lib/processors/global_statistics.d.ts +9 -0
- package/lib/processors/global_statistics.js +2 -0
- package/lib/processors/map.d.ts +8 -0
- package/lib/processors/map.js +2 -0
- package/lib/processors/meta.d.ts +45 -0
- package/lib/processors/meta.js +2 -0
- package/lib/processors/player.d.ts +37 -8
- package/lib/processors/player.js +37 -30
- package/lib/processors/player_search.d.ts +6 -0
- package/lib/processors/player_search.js +11 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +2 -0
- package/package.json +26 -27
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
29
|
+
### Fetch Player Infomation
|
|
26
30
|
|
|
27
31
|
```ts
|
|
28
|
-
|
|
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
|
|
36
|
+
### Fetch Player Search
|
|
38
37
|
|
|
39
38
|
```ts
|
|
40
|
-
|
|
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 {
|
|
50
|
-
|
|
51
|
-
// Returns all games
|
|
52
|
-
const { data, error } = await getMonthlyStats("player");
|
|
46
|
+
import { Timeframe, Game } from "hive-bedrock-data";
|
|
53
47
|
|
|
54
|
-
// Returns
|
|
55
|
-
const { data, error } = await
|
|
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
|
-
//
|
|
58
|
-
const { data, error } = await
|
|
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
|
|
57
|
+
### Fetch Seasonal Player Statistics
|
|
65
58
|
|
|
66
59
|
```ts
|
|
67
|
-
import {
|
|
60
|
+
import { Game } from "hive-bedrock-data";
|
|
68
61
|
|
|
69
|
-
// Returns a
|
|
70
|
-
const { data, error } = await
|
|
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
|
|
66
|
+
### Fetch All-Time/Monthly Leaderboard
|
|
74
67
|
|
|
75
68
|
```ts
|
|
76
|
-
import {
|
|
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
|
-
//
|
|
79
|
-
const { data, error } = await
|
|
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
|
|
80
|
+
### Fetch Seasonal Leaderboard
|
|
83
81
|
|
|
84
82
|
```ts
|
|
85
|
-
import {
|
|
83
|
+
import { Game } from "hive-bedrock-data";
|
|
86
84
|
|
|
87
|
-
// Returns a
|
|
88
|
-
const { data, error } = await
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
111
|
+
const { data, error, meta } = await api.getGameMetadata(Game.TreasureWars);
|
|
124
112
|
```
|
|
125
113
|
|
|
126
|
-
##
|
|
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
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
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 {};
|