hive-bedrock-api 3.0.0-alpha.9 → 4.0.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 CHANGED
@@ -3,7 +3,7 @@
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
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).
6
+ > This API responses returned from this package will differ from the responses returned by the official Hive API. This due to our preference and needs when using this package on [Hive Backpack](https://hivebackpack.com).
7
7
 
8
8
  ## Getting started
9
9
 
@@ -16,7 +16,7 @@ You should also include `hive-bedrock-data` as it includes useful functions and
16
16
 
17
17
  ## Usage
18
18
 
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.
19
+ To start using the API, construct the main class `HiveAPI`. This class takes in options that will be used in every HTTP request.
20
20
 
21
21
  ```ts
22
22
  const api = new HiveAPI({
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
- {
2
- "name": "hive-bedrock-api",
3
- "version": "3.0.0-alpha.9",
4
- "description": "An API wrapper for the Hive Minecraft Bedrock Edition server.",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/CubeEdge-Studios/hive-bedrock.git"
10
- },
11
- "license": "MIT",
12
- "author": "Cubeedge Studios",
13
- "dependencies": {
14
- "hive-bedrock-data": "^2.0.0-alpha.6"
15
- },
16
- "scripts": {
17
- "build": "tsc"
18
- },
19
- "files": [
20
- "lib/**/*"
21
- ],
22
- "devDependencies": {
23
- "ts-node": "^10.9.1",
24
- "typescript": "^5.1.3"
25
- }
26
- }
1
+ {
2
+ "name": "hive-bedrock-api",
3
+ "version": "4.0.0",
4
+ "description": "An API wrapper for the Hive Minecraft Bedrock Edition server.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/CubeEdge-Studios/hive-bedrock.git"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Cubeedge Studios",
13
+ "dependencies": {
14
+ "hive-bedrock-data": "^4.0.0"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc"
18
+ },
19
+ "files": [
20
+ "lib/**/*"
21
+ ],
22
+ "devDependencies": {
23
+ "ts-node": "^10.9.1",
24
+ "typescript": "^5.1.3"
25
+ }
26
+ }
package/lib/index.d.ts DELETED
@@ -1,99 +0,0 @@
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.Monthly, 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
- getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
69
- month?: number;
70
- year?: number;
71
- }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
72
- private _getLeaderboardAllTime;
73
- private _getLeaderboardMonthly;
74
- /**
75
- * `/game/season/{game}/{season}` Gets seasonal statistics for a game
76
- * @param game The game to get the statistics for
77
- * @param season The season to get the statistics for
78
- * @returns The seasonal statistics for the game
79
- */
80
- getSeasonalLeaderboard<G extends Game>(game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][]>>;
81
- /**
82
- * `/global/statistics` Gets global statistics
83
- * @returns The global statistics
84
- */
85
- getGlobalStatistics(): Promise<MethodResponse<ProcessedGlobalStatisticsResponse>>;
86
- /**
87
- * `/game/map/{game}` Gets information about the maps in a game
88
- * @param game The game to get the maps for (fails for games without maps)
89
- * @returns A list of maps in the game
90
- */
91
- getGameMaps(game: Game): Promise<MethodResponse<ProcessedMapResponse>>;
92
- /**
93
- * `/game/meta/{game}` Gets metadata about a game
94
- * @param game The game to get the metadata for
95
- * @returns The metadata for the game
96
- */
97
- getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
98
- }
99
- export {};
package/lib/index.js DELETED
@@ -1,386 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __importDefault = (this && this.__importDefault) || function (mod) {
66
- return (mod && mod.__esModule) ? mod : { "default": mod };
67
- };
68
- Object.defineProperty(exports, "__esModule", { value: true });
69
- var hive_bedrock_data_1 = require("hive-bedrock-data");
70
- var player_1 = __importDefault(require("./processors/player"));
71
- var player_search_1 = __importDefault(require("./processors/player_search"));
72
- var game_1 = __importDefault(require("./processors/game"));
73
- var HiveAPI = /** @class */ (function () {
74
- function HiveAPI(options) {
75
- if (options === void 0) { options = { resolveDynamicTitles: true, apiBaseEndpoint: hive_bedrock_data_1.API_BASE_ENDPOINT }; }
76
- this.options = options;
77
- }
78
- HiveAPI.prototype._fetchAPI = function (endpoint) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var url, start, request, meta, response, err_1;
81
- var _a, _b;
82
- return __generator(this, function (_c) {
83
- switch (_c.label) {
84
- case 0:
85
- url = this.options.apiBaseEndpoint + endpoint;
86
- _c.label = 1;
87
- case 1:
88
- _c.trys.push([1, 4, , 5]);
89
- start = performance.now();
90
- return [4 /*yield*/, fetch(url, __assign(__assign({}, this.options.requestInit), { headers: __assign({ "X-Hive-Resolve-Stat-Track": ((_a = this.options.resolveDynamicTitles) !== null && _a !== void 0 ? _a : true).toString() }, (_b = this.options.requestInit) === null || _b === void 0 ? void 0 : _b.headers) }))];
91
- case 2:
92
- request = _c.sent();
93
- if (!request.ok)
94
- return [2 /*return*/, { data: null, error: { status: request.status } }];
95
- meta = {
96
- duration: Math.ceil(performance.now() - start),
97
- ratelimit: {
98
- limit: Number(request.headers.get("X-Ratelimit-Limit")),
99
- remaining: Number(request.headers.get("X-Ratelimit-Remaining")),
100
- reset: Number(request.headers.get("X-Ratelimit-Reset")),
101
- },
102
- retryAfter: Number(request.headers.get("Retry-After")),
103
- };
104
- return [4 /*yield*/, request.json()];
105
- case 3:
106
- response = _c.sent();
107
- return [2 /*return*/, { data: response, error: null, meta: meta }];
108
- case 4:
109
- err_1 = _c.sent();
110
- return [2 /*return*/, { data: null, error: { status: 500, message: err_1.message } }];
111
- case 5: return [2 /*return*/];
112
- }
113
- });
114
- });
115
- };
116
- /**
117
- * `/game/all/main/{identifier}` Gets information about a player
118
- * @param identifier Username or UUID of the player
119
- * @returns The player information
120
- */
121
- HiveAPI.prototype.getPlayer = function (identifier) {
122
- return __awaiter(this, void 0, void 0, function () {
123
- var _a, response, error, meta, data;
124
- return __generator(this, function (_b) {
125
- switch (_b.label) {
126
- case 0: return [4 /*yield*/, this._fetchAPI("/game/all/main/".concat(identifier))];
127
- case 1:
128
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
129
- if (error)
130
- return [2 /*return*/, { data: null, error: error, meta: meta }];
131
- data = (0, player_1.default)(response);
132
- if (!data)
133
- return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player data" }, meta: meta }];
134
- return [2 /*return*/, { data: data, error: null, meta: meta }];
135
- }
136
- });
137
- });
138
- };
139
- /**
140
- * `/player/search/{prefix}` Gets a list of players that match the prefix
141
- * @param prefix The prefix to search for (must be at least 4 characters long)
142
- * @returns A list of players that match the prefix
143
- */
144
- HiveAPI.prototype.getPlayerSearch = function (prefix) {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var _a, response, error, meta, data;
147
- return __generator(this, function (_b) {
148
- switch (_b.label) {
149
- case 0: return [4 /*yield*/, this._fetchAPI("/player/search/".concat(prefix))];
150
- case 1:
151
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
152
- if (error)
153
- return [2 /*return*/, { data: null, error: error, meta: meta }];
154
- data = (0, player_search_1.default)(response);
155
- if (!data)
156
- return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player search data" }, meta: meta }];
157
- return [2 /*return*/, { data: data, error: null, meta: meta }];
158
- }
159
- });
160
- });
161
- };
162
- HiveAPI.prototype.getStatistics = function (identifier, timeframe, options) {
163
- return __awaiter(this, void 0, void 0, function () {
164
- return __generator(this, function (_a) {
165
- if (timeframe === hive_bedrock_data_1.Timeframe.AllTime) {
166
- if (options === null || options === void 0 ? void 0 : options.game)
167
- return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
168
- return [2 /*return*/, this._getStatisticsAllTime(identifier)];
169
- }
170
- if (options === null || options === void 0 ? void 0 : options.game)
171
- return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
172
- return [2 /*return*/, this._getStatisticsMonthly(identifier, undefined, options === null || options === void 0 ? void 0 : options.month, options === null || options === void 0 ? void 0 : options.year)];
173
- });
174
- });
175
- };
176
- HiveAPI.prototype._getStatisticsAllTime = function (identifier, game) {
177
- return __awaiter(this, void 0, void 0, function () {
178
- var _a, response, error, meta, data;
179
- return __generator(this, function (_b) {
180
- switch (_b.label) {
181
- case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game !== null && game !== void 0 ? game : "all", "/").concat(identifier))];
182
- case 1:
183
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
184
- if (error)
185
- return [2 /*return*/, { data: null, error: error, meta: meta }];
186
- if (game)
187
- return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, false, response), error: null, meta: meta }];
188
- data = Object.fromEntries(Object.entries(response).map(function (_a) {
189
- var _b;
190
- var _c = __read(_a, 2), id = _c[0], res = _c[1];
191
- return [id, id === "main" ? null : (_b = (0, game_1.default)(id, hive_bedrock_data_1.Timeframe.AllTime, false, res)) !== null && _b !== void 0 ? _b : null];
192
- }));
193
- delete data.main;
194
- return [2 /*return*/, {
195
- data: {
196
- player: (0, player_1.default)(response),
197
- statistics: data,
198
- },
199
- error: null,
200
- meta: meta,
201
- }];
202
- }
203
- });
204
- });
205
- };
206
- HiveAPI.prototype._getStatisticsMonthly = function (identifier, game, month, year) {
207
- return __awaiter(this, void 0, void 0, function () {
208
- var _a, response, error, meta, data;
209
- return __generator(this, function (_b) {
210
- switch (_b.label) {
211
- case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/player/".concat(game !== null && game !== void 0 ? game : "all", "/").concat(identifier, "/").concat(year !== null && year !== void 0 ? year : new Date().getFullYear(), "/").concat(month !== null && month !== void 0 ? month : new Date().getMonth() + 1))];
212
- case 1:
213
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
214
- if (error)
215
- return [2 /*return*/, { data: null, error: error, meta: meta }];
216
- if (game)
217
- return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, false, response), error: null, meta: meta }];
218
- data = Object.fromEntries(Object.entries(response).map(function (_a) {
219
- var _b;
220
- var _c = __read(_a, 2), id = _c[0], res = _c[1];
221
- return [id, id === "main" ? null : (_b = (0, game_1.default)(id, hive_bedrock_data_1.Timeframe.Monthly, false, res)) !== null && _b !== void 0 ? _b : null];
222
- }));
223
- delete data.main;
224
- return [2 /*return*/, {
225
- data: {
226
- statistics: data,
227
- },
228
- error: null,
229
- meta: meta,
230
- }];
231
- }
232
- });
233
- });
234
- };
235
- /**
236
- * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
237
- * @param identifier Username or UUID of the player
238
- * @param game The game to get the statistics for
239
- * @param season The season to get the statistics for
240
- * @returns The player's seasonal statistics
241
- */
242
- HiveAPI.prototype.getSeasonalStatistics = function (identifier_1, game_2) {
243
- return __awaiter(this, arguments, void 0, function (identifier, game, season) {
244
- var _a, response, error, meta, data;
245
- if (season === void 0) { season = 1; }
246
- return __generator(this, function (_b) {
247
- switch (_b.label) {
248
- case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season))];
249
- case 1:
250
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
251
- if (error)
252
- return [2 /*return*/, { data: null, error: error, meta: meta }];
253
- data = (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, response);
254
- return [2 /*return*/, { data: data, error: null, meta: meta }];
255
- }
256
- });
257
- });
258
- };
259
- HiveAPI.prototype.getLeaderboard = function (timeframe, game, options) {
260
- return __awaiter(this, void 0, void 0, function () {
261
- return __generator(this, function (_a) {
262
- if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
263
- return [2 /*return*/, this._getLeaderboardMonthly(game, (options === null || options === void 0 ? void 0 : options.month) || new Date().getMonth() + 1, (options === null || options === void 0 ? void 0 : options.year) || new Date().getFullYear())];
264
- return [2 /*return*/, this._getLeaderboardAllTime(game)];
265
- });
266
- });
267
- };
268
- // /game/all/{game}
269
- HiveAPI.prototype._getLeaderboardAllTime = function (game) {
270
- return __awaiter(this, void 0, void 0, function () {
271
- var _a, response, error, meta, data;
272
- return __generator(this, function (_b) {
273
- switch (_b.label) {
274
- case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game))];
275
- case 1:
276
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
277
- if (error)
278
- return [2 /*return*/, { data: null, error: error, meta: meta }];
279
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, true, res); });
280
- return [2 /*return*/, { data: data, error: null, meta: meta }];
281
- }
282
- });
283
- });
284
- };
285
- // /game/monthly/{game}/{year}/{month}
286
- HiveAPI.prototype._getLeaderboardMonthly = function (game, month, year) {
287
- return __awaiter(this, void 0, void 0, function () {
288
- var _a, response, error, meta, data;
289
- return __generator(this, function (_b) {
290
- switch (_b.label) {
291
- case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/").concat(year, "/").concat(month))];
292
- case 1:
293
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
294
- if (error)
295
- return [2 /*return*/, { data: null, error: error, meta: meta }];
296
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
297
- return [2 /*return*/, { data: data, error: null, meta: meta }];
298
- }
299
- });
300
- });
301
- };
302
- /**
303
- * `/game/season/{game}/{season}` Gets seasonal statistics for a game
304
- * @param game The game to get the statistics for
305
- * @param season The season to get the statistics for
306
- * @returns The seasonal statistics for the game
307
- */
308
- HiveAPI.prototype.getSeasonalLeaderboard = function (game_2) {
309
- return __awaiter(this, arguments, void 0, function (game, season) {
310
- var _a, response, error, meta, data;
311
- if (season === void 0) { season = 1; }
312
- return __generator(this, function (_b) {
313
- switch (_b.label) {
314
- case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season !== null && season !== void 0 ? season : 1))];
315
- case 1:
316
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
317
- if (error)
318
- return [2 /*return*/, { data: null, error: error, meta: meta }];
319
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
320
- return [2 /*return*/, { data: data, error: null, meta: meta }];
321
- }
322
- });
323
- });
324
- };
325
- /**
326
- * `/global/statistics` Gets global statistics
327
- * @returns The global statistics
328
- */
329
- HiveAPI.prototype.getGlobalStatistics = function () {
330
- return __awaiter(this, void 0, void 0, function () {
331
- var _a, response, error, meta;
332
- return __generator(this, function (_b) {
333
- switch (_b.label) {
334
- case 0: return [4 /*yield*/, this._fetchAPI("/global/statistics")];
335
- case 1:
336
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
337
- if (error)
338
- return [2 /*return*/, { data: null, error: error, meta: meta }];
339
- return [2 /*return*/, { data: response, error: null, meta: meta }];
340
- }
341
- });
342
- });
343
- };
344
- /**
345
- * `/game/map/{game}` Gets information about the maps in a game
346
- * @param game The game to get the maps for (fails for games without maps)
347
- * @returns A list of maps in the game
348
- */
349
- HiveAPI.prototype.getGameMaps = function (game) {
350
- return __awaiter(this, void 0, void 0, function () {
351
- var _a, response, error, meta;
352
- return __generator(this, function (_b) {
353
- switch (_b.label) {
354
- case 0: return [4 /*yield*/, this._fetchAPI("/game/map/".concat(game))];
355
- case 1:
356
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
357
- if (error)
358
- return [2 /*return*/, { data: null, error: error, meta: meta }];
359
- return [2 /*return*/, { data: response, error: null, meta: meta }];
360
- }
361
- });
362
- });
363
- };
364
- /**
365
- * `/game/meta/{game}` Gets metadata about a game
366
- * @param game The game to get the metadata for
367
- * @returns The metadata for the game
368
- */
369
- HiveAPI.prototype.getGameMetadata = function (game) {
370
- return __awaiter(this, void 0, void 0, function () {
371
- var _a, response, error, meta;
372
- return __generator(this, function (_b) {
373
- switch (_b.label) {
374
- case 0: return [4 /*yield*/, this._fetchAPI("/game/meta/".concat(game))];
375
- case 1:
376
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
377
- if (error)
378
- return [2 /*return*/, { data: null, error: error, meta: meta }];
379
- return [2 /*return*/, { data: response, error: null, meta: meta }];
380
- }
381
- });
382
- });
383
- };
384
- return HiveAPI;
385
- }());
386
- exports.default = HiveAPI;