hive-bedrock-api 3.0.0-alpha.23 → 3.0.0-alpha.25

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 (91) hide show
  1. package/lib/helpers/fetchEndpoint.d.ts +3 -0
  2. package/lib/helpers/fetchEndpoint.js +88 -0
  3. package/lib/helpers/isGame.d.ts +2 -0
  4. package/lib/helpers/isGame.js +7 -0
  5. package/lib/helpers/toPoint.d.ts +1 -0
  6. package/lib/helpers/toPoint.js +10 -0
  7. package/lib/index.d.ts +106 -0
  8. package/lib/index.js +424 -0
  9. package/lib/methods/getAllTimeLeaderboard.d.ts +4 -0
  10. package/lib/methods/getAllTimeLeaderboard.js +85 -0
  11. package/lib/methods/getAllTimeStatistics.d.ts +10 -0
  12. package/lib/methods/getAllTimeStatistics.js +126 -0
  13. package/lib/methods/getGlobalStatistics.d.ts +3 -0
  14. package/lib/methods/getGlobalStatistics.js +56 -0
  15. package/lib/methods/getMaps.d.ts +3 -0
  16. package/lib/methods/getMaps.js +81 -0
  17. package/lib/methods/getMetadata.d.ts +3 -0
  18. package/lib/methods/getMetadata.js +81 -0
  19. package/lib/methods/getMonthlyLeaderboard.d.ts +11 -0
  20. package/lib/methods/getMonthlyLeaderboard.js +88 -0
  21. package/lib/methods/getMonthlyStatistics.d.ts +10 -0
  22. package/lib/methods/getMonthlyStatistics.js +132 -0
  23. package/lib/methods/getPlayerInfomation.d.ts +3 -0
  24. package/lib/methods/getPlayerInfomation.js +72 -0
  25. package/lib/methods/getSeasonLeaderboard.d.ts +10 -0
  26. package/lib/methods/getSeasonLeaderboard.js +87 -0
  27. package/lib/methods/getSeasonStatistics.d.ts +10 -0
  28. package/lib/methods/getSeasonStatistics.js +87 -0
  29. package/lib/processors/bed.d.ts +19 -0
  30. package/lib/processors/bed.js +35 -0
  31. package/lib/processors/bridge.d.ts +24 -0
  32. package/lib/processors/bridge.js +40 -0
  33. package/lib/processors/build.d.ts +19 -0
  34. package/lib/processors/build.js +35 -0
  35. package/lib/processors/ctf.d.ts +19 -0
  36. package/lib/processors/ctf.js +35 -0
  37. package/lib/processors/dr.d.ts +19 -0
  38. package/lib/processors/dr.js +35 -0
  39. package/lib/processors/drop.d.ts +17 -0
  40. package/lib/processors/drop.js +34 -0
  41. package/lib/processors/game.d.ts +315 -0
  42. package/lib/processors/game.js +395 -0
  43. package/lib/processors/global_statistics.d.ts +9 -0
  44. package/lib/processors/global_statistics.js +2 -0
  45. package/lib/processors/grav.d.ts +17 -0
  46. package/lib/processors/grav.js +34 -0
  47. package/lib/processors/ground.d.ts +19 -0
  48. package/lib/processors/ground.js +35 -0
  49. package/lib/processors/helpers/processBuildRatings.d.ts +8 -0
  50. package/lib/processors/helpers/processBuildRatings.js +23 -0
  51. package/lib/processors/helpers/processGameAndXP.d.ts +6 -0
  52. package/lib/processors/helpers/processGameAndXP.js +10 -0
  53. package/lib/processors/helpers/processHiderKillsAndDeaths.d.ts +5 -0
  54. package/lib/processors/helpers/processHiderKillsAndDeaths.js +13 -0
  55. package/lib/processors/helpers/processKillsAndDeaths.d.ts +5 -0
  56. package/lib/processors/helpers/processKillsAndDeaths.js +13 -0
  57. package/lib/processors/helpers/processMurdersAndDeaths.d.ts +5 -0
  58. package/lib/processors/helpers/processMurdersAndDeaths.js +13 -0
  59. package/lib/processors/helpers/processPlayedAndVictories.d.ts +6 -0
  60. package/lib/processors/helpers/processPlayedAndVictories.js +12 -0
  61. package/lib/processors/hide.d.ts +19 -0
  62. package/lib/processors/hide.js +35 -0
  63. package/lib/processors/index.d.ts +12 -0
  64. package/lib/processors/index.js +73 -0
  65. package/lib/processors/map.d.ts +8 -0
  66. package/lib/processors/map.js +2 -0
  67. package/lib/processors/meta.d.ts +45 -0
  68. package/lib/processors/meta.js +2 -0
  69. package/lib/processors/murder.d.ts +19 -0
  70. package/lib/processors/murder.js +35 -0
  71. package/lib/processors/parkour.d.ts +5 -0
  72. package/lib/processors/parkour.js +99 -0
  73. package/lib/processors/party.d.ts +17 -0
  74. package/lib/processors/party.js +34 -0
  75. package/lib/processors/player.d.ts +61 -0
  76. package/lib/processors/player.js +54 -0
  77. package/lib/processors/player_search.d.ts +6 -0
  78. package/lib/processors/player_search.js +11 -0
  79. package/lib/processors/sg.d.ts +19 -0
  80. package/lib/processors/sg.js +35 -0
  81. package/lib/processors/sky.d.ts +19 -0
  82. package/lib/processors/sky.js +35 -0
  83. package/lib/processors/wars.d.ts +19 -0
  84. package/lib/processors/wars.js +35 -0
  85. package/lib/types/output.d.ts +62 -0
  86. package/lib/types/output.js +3 -0
  87. package/lib/types/types.d.ts +24 -0
  88. package/lib/types/types.js +2 -0
  89. package/lib/utils.d.ts +21 -0
  90. package/lib/utils.js +2 -0
  91. package/package.json +2 -2
@@ -0,0 +1,3 @@
1
+ import { APIResponse } from "../types/types";
2
+ import { Routes } from "hive-bedrock-data";
3
+ export default function fetchEndpoint<T extends string>(endpoint: T, init?: RequestInit): Promise<APIResponse<Routes<T>>>;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = fetchEndpoint;
40
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
41
+ function fetchEndpoint(endpoint, init) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var time_start, request, time_end, duration, response, err_1;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ _a.trys.push([0, 3, , 4]);
48
+ time_start = performance.now();
49
+ return [4 /*yield*/, fetch(hive_bedrock_data_1.API_BASE_ENDPOINT + endpoint, init)];
50
+ case 1:
51
+ request = _a.sent();
52
+ time_end = performance.now();
53
+ duration = Math.round(time_end - time_start);
54
+ if (!request.ok)
55
+ return [2 /*return*/, {
56
+ status: request.status,
57
+ data: null,
58
+ error: {
59
+ code: request.status,
60
+ message: request.statusText,
61
+ },
62
+ duration: duration,
63
+ }];
64
+ return [4 /*yield*/, request.json()];
65
+ case 2:
66
+ response = _a.sent();
67
+ return [2 /*return*/, {
68
+ status: request.status,
69
+ headers: request.headers,
70
+ data: response,
71
+ error: null,
72
+ duration: duration,
73
+ }];
74
+ case 3:
75
+ err_1 = _a.sent();
76
+ return [2 /*return*/, {
77
+ status: 500,
78
+ data: null,
79
+ error: {
80
+ code: 500,
81
+ message: "Failed to fetch endpoint data.",
82
+ },
83
+ }];
84
+ case 4: return [2 /*return*/];
85
+ }
86
+ });
87
+ });
88
+ }
@@ -0,0 +1,2 @@
1
+ import { Game } from "hive-bedrock-data";
2
+ export default function isGame(game_id: Game): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = isGame;
4
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
5
+ function isGame(game_id) {
6
+ return Object.values(hive_bedrock_data_1.Game).includes(game_id);
7
+ }
@@ -0,0 +1 @@
1
+ export default function toPoint(num: number, point: number): number;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = toPoint;
4
+ function toPoint(num, point) {
5
+ if (isNaN(num))
6
+ return 0;
7
+ if (num === Infinity)
8
+ return 0;
9
+ return Math.round(num * (10 ^ point)) / (10 ^ point);
10
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,106 @@
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 { AvailableLeaderboardResponse, ProcessedAllGamesResponse, ProcessedGame, ProcessedMonthlyGamesResponse } from "./processors/game";
9
+ interface Options {
10
+ resolveDynamicTitles?: boolean;
11
+ useModernLeaderboardSource?: boolean;
12
+ apiBaseEndpoint?: string;
13
+ requestInit?: RequestInit;
14
+ }
15
+ export default class HiveAPI {
16
+ options: Options;
17
+ constructor(options?: Options);
18
+ private _fetchAPI;
19
+ /**
20
+ * `/game/all/main/{identifier}` Gets information about a player
21
+ * @param identifier Username or UUID of the player
22
+ * @returns The player information
23
+ */
24
+ getPlayer(identifier: string): Promise<MethodResponse<ProcessedPlayerResponse>>;
25
+ /**
26
+ * `/player/search/{prefix}` Gets a list of players that match the prefix
27
+ * @param prefix The prefix to search for (must be at least 4 characters long)
28
+ * @returns A list of players that match the prefix
29
+ */
30
+ getPlayerSearch(prefix: string): Promise<MethodResponse<ProcessedPlayerSearchResponse>>;
31
+ /**
32
+ * Gets statistics for a player
33
+ * @param identifier Username or UUID of the player
34
+ * @param timeframe The timeframe to get the statistics for
35
+ * @param options Additional options including specific game, month, and year
36
+ * @returns The player statistics
37
+ */
38
+ getStatistics(identifier: string, timeframe: Timeframe.AllTime): Promise<MethodResponse<ProcessedAllGamesResponse>>;
39
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.AllTime, options: {
40
+ game: G;
41
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, false>[G]>>;
42
+ getStatistics(identifier: string, timeframe: Timeframe.Monthly, options?: {
43
+ month?: number;
44
+ year?: number;
45
+ }): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
46
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Monthly, options: {
47
+ game: G;
48
+ month?: number;
49
+ year?: number;
50
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, false>[G]>>;
51
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Seasonal, options?: {
52
+ game: G;
53
+ season?: number;
54
+ }): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
55
+ private _getStatisticsAllTime;
56
+ private _getStatisticsMonthly;
57
+ private _getStatisticsSeasonal;
58
+ getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
59
+ /**
60
+ * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
61
+ * @param identifier Username or UUID of the player
62
+ * @param game The game to get the statistics for
63
+ * @param season The season to get the statistics for
64
+ * @returns The player's seasonal statistics
65
+ */
66
+ getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedMonthlyGamesResponse["statistics"][G] | null>>;
67
+ /**
68
+ * `/game/all/{game}` Gets statistics for a game
69
+ * @param timeframe The timeframe to get the statistics for
70
+ * @param game The game to get the statistics for
71
+ * @param options Additional options including specific month and year
72
+ */
73
+ getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
74
+ getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
75
+ getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
76
+ month?: number;
77
+ year?: number;
78
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
79
+ private _getLeaderboardAllTime;
80
+ private _getLeaderboardMonthly;
81
+ /**
82
+ * `/game/season/{game}/{season}` Gets seasonal statistics for a game
83
+ * @param game The game to get the statistics for
84
+ * @param season The season to get the statistics for
85
+ * @returns The seasonal statistics for the game
86
+ */
87
+ getSeasonalLeaderboard<G extends Game>(game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][]>>;
88
+ /**
89
+ * `/global/statistics` Gets global statistics
90
+ * @returns The global statistics
91
+ */
92
+ getGlobalStatistics(): Promise<MethodResponse<ProcessedGlobalStatisticsResponse>>;
93
+ /**
94
+ * `/game/map/{game}` Gets information about the maps in a game
95
+ * @param game The game to get the maps for (fails for games without maps)
96
+ * @returns A list of maps in the game
97
+ */
98
+ getGameMaps(game: Game): Promise<MethodResponse<ProcessedMapResponse>>;
99
+ /**
100
+ * `/game/meta/{game}` Gets metadata about a game
101
+ * @param game The game to get the metadata for
102
+ * @returns The metadata for the game
103
+ */
104
+ getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
105
+ }
106
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,424 @@
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 = {}; }
76
+ var _a;
77
+ this.options = options;
78
+ this.options = options;
79
+ this.options.apiBaseEndpoint = (_a = this.options.apiBaseEndpoint) !== null && _a !== void 0 ? _a : hive_bedrock_data_1.API_BASE_ENDPOINT;
80
+ }
81
+ HiveAPI.prototype._fetchAPI = function (endpoint) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var url, start, request, meta, response, err_1;
84
+ var _a, _b;
85
+ return __generator(this, function (_c) {
86
+ switch (_c.label) {
87
+ case 0:
88
+ url = this.options.apiBaseEndpoint + endpoint;
89
+ _c.label = 1;
90
+ case 1:
91
+ _c.trys.push([1, 4, , 5]);
92
+ start = performance.now();
93
+ 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(), "X-Hive-Leaderboard-Source": this.options.useModernLeaderboardSource ? "modern" : "legacy" }, (_b = this.options.requestInit) === null || _b === void 0 ? void 0 : _b.headers) }))];
94
+ case 2:
95
+ request = _c.sent();
96
+ if (!request.ok)
97
+ return [2 /*return*/, { data: null, error: { status: request.status } }];
98
+ meta = {
99
+ duration: Math.ceil(performance.now() - start),
100
+ ratelimit: {
101
+ limit: Number(request.headers.get("X-Ratelimit-Limit")),
102
+ remaining: Number(request.headers.get("X-Ratelimit-Remaining")),
103
+ reset: Number(request.headers.get("X-Ratelimit-Reset")),
104
+ },
105
+ retryAfter: Number(request.headers.get("Retry-After")),
106
+ };
107
+ return [4 /*yield*/, request.json()];
108
+ case 3:
109
+ response = _c.sent();
110
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
111
+ case 4:
112
+ err_1 = _c.sent();
113
+ return [2 /*return*/, { data: null, error: { status: 500, message: err_1.message } }];
114
+ case 5: return [2 /*return*/];
115
+ }
116
+ });
117
+ });
118
+ };
119
+ /**
120
+ * `/game/all/main/{identifier}` Gets information about a player
121
+ * @param identifier Username or UUID of the player
122
+ * @returns The player information
123
+ */
124
+ HiveAPI.prototype.getPlayer = function (identifier) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var _a, response, error, meta, data;
127
+ return __generator(this, function (_b) {
128
+ switch (_b.label) {
129
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/all/main/".concat(identifier))];
130
+ case 1:
131
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
132
+ if (error)
133
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
134
+ data = (0, player_1.default)(response);
135
+ if (!data)
136
+ return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player data" }, meta: meta }];
137
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
138
+ }
139
+ });
140
+ });
141
+ };
142
+ /**
143
+ * `/player/search/{prefix}` Gets a list of players that match the prefix
144
+ * @param prefix The prefix to search for (must be at least 4 characters long)
145
+ * @returns A list of players that match the prefix
146
+ */
147
+ HiveAPI.prototype.getPlayerSearch = function (prefix) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var _a, response, error, meta, data;
150
+ return __generator(this, function (_b) {
151
+ switch (_b.label) {
152
+ case 0: return [4 /*yield*/, this._fetchAPI("/player/search/".concat(prefix))];
153
+ case 1:
154
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
155
+ if (error)
156
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
157
+ data = (0, player_search_1.default)(response);
158
+ if (!data)
159
+ return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player search data" }, meta: meta }];
160
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
161
+ }
162
+ });
163
+ });
164
+ };
165
+ HiveAPI.prototype.getStatistics = function (identifier, timeframe, options) {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ if (timeframe === hive_bedrock_data_1.Timeframe.AllTime) {
169
+ if (options === null || options === void 0 ? void 0 : options.game)
170
+ return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
171
+ return [2 /*return*/, this._getStatisticsAllTime(identifier)];
172
+ }
173
+ else if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal) {
174
+ if (!(options === null || options === void 0 ? void 0 : options.game))
175
+ throw new Error("Game must be specified for seasonal statistics");
176
+ return [2 /*return*/, this._getStatisticsSeasonal(identifier, options === null || options === void 0 ? void 0 : options.game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
177
+ }
178
+ if (options === null || options === void 0 ? void 0 : options.game)
179
+ return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
180
+ 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)];
181
+ });
182
+ });
183
+ };
184
+ HiveAPI.prototype._getStatisticsAllTime = function (identifier, game) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var _a, response, error, meta, data;
187
+ return __generator(this, function (_b) {
188
+ switch (_b.label) {
189
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game !== null && game !== void 0 ? game : "all", "/").concat(identifier))];
190
+ case 1:
191
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
192
+ if (error)
193
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
194
+ if (game)
195
+ return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, false, response), error: null, meta: meta }];
196
+ data = Object.fromEntries(Object.entries(response).map(function (_a) {
197
+ var _b;
198
+ var _c = __read(_a, 2), id = _c[0], res = _c[1];
199
+ 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];
200
+ }));
201
+ delete data.main;
202
+ return [2 /*return*/, {
203
+ data: {
204
+ player: (0, player_1.default)(response),
205
+ statistics: data,
206
+ },
207
+ error: null,
208
+ meta: meta,
209
+ }];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ HiveAPI.prototype._getStatisticsMonthly = function (identifier, game, month, year) {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ var _a, response, error, meta, data;
217
+ return __generator(this, function (_b) {
218
+ switch (_b.label) {
219
+ 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))];
220
+ case 1:
221
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
222
+ if (error)
223
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
224
+ if (game)
225
+ return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, false, response), error: null, meta: meta }];
226
+ data = Object.fromEntries(Object.entries(response).map(function (_a) {
227
+ var _b;
228
+ var _c = __read(_a, 2), id = _c[0], res = _c[1];
229
+ 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];
230
+ }));
231
+ delete data.main;
232
+ return [2 /*return*/, {
233
+ data: {
234
+ statistics: data,
235
+ },
236
+ error: null,
237
+ meta: meta,
238
+ }];
239
+ }
240
+ });
241
+ });
242
+ };
243
+ HiveAPI.prototype._getStatisticsSeasonal = function (identifier, game, season) {
244
+ return __awaiter(this, void 0, void 0, function () {
245
+ var _a, response, error, meta;
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 !== null && season !== void 0 ? season : 1))];
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
+ return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
254
+ }
255
+ });
256
+ });
257
+ };
258
+ HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var _a, response, error, meta;
261
+ return __generator(this, function (_b) {
262
+ switch (_b.label) {
263
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/available"))];
264
+ case 1:
265
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
266
+ if (error)
267
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
268
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
269
+ }
270
+ });
271
+ });
272
+ };
273
+ /**
274
+ * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
275
+ * @param identifier Username or UUID of the player
276
+ * @param game The game to get the statistics for
277
+ * @param season The season to get the statistics for
278
+ * @returns The player's seasonal statistics
279
+ */
280
+ HiveAPI.prototype.getSeasonalStatistics = function (identifier_1, game_2) {
281
+ return __awaiter(this, arguments, void 0, function (identifier, game, season) {
282
+ var _a, response, error, meta, data;
283
+ if (season === void 0) { season = 1; }
284
+ return __generator(this, function (_b) {
285
+ switch (_b.label) {
286
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season))];
287
+ case 1:
288
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
289
+ if (error)
290
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
291
+ data = (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, response);
292
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
293
+ }
294
+ });
295
+ });
296
+ };
297
+ HiveAPI.prototype.getLeaderboard = function (timeframe, game, options) {
298
+ return __awaiter(this, void 0, void 0, function () {
299
+ return __generator(this, function (_a) {
300
+ if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
301
+ 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())];
302
+ return [2 /*return*/, this._getLeaderboardAllTime(game)];
303
+ });
304
+ });
305
+ };
306
+ // /game/all/{game}
307
+ HiveAPI.prototype._getLeaderboardAllTime = function (game) {
308
+ return __awaiter(this, void 0, void 0, function () {
309
+ var _a, response, error, meta, data;
310
+ return __generator(this, function (_b) {
311
+ switch (_b.label) {
312
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game))];
313
+ case 1:
314
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
315
+ if (error)
316
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
317
+ data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, true, res); });
318
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
319
+ }
320
+ });
321
+ });
322
+ };
323
+ // /game/monthly/{game}/{year}/{month}
324
+ HiveAPI.prototype._getLeaderboardMonthly = function (game, month, year) {
325
+ return __awaiter(this, void 0, void 0, function () {
326
+ var _a, response, error, meta, data;
327
+ return __generator(this, function (_b) {
328
+ switch (_b.label) {
329
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/").concat(year, "/").concat(month))];
330
+ case 1:
331
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
332
+ if (error)
333
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
334
+ data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
335
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
336
+ }
337
+ });
338
+ });
339
+ };
340
+ /**
341
+ * `/game/season/{game}/{season}` Gets seasonal statistics for a game
342
+ * @param game The game to get the statistics for
343
+ * @param season The season to get the statistics for
344
+ * @returns The seasonal statistics for the game
345
+ */
346
+ HiveAPI.prototype.getSeasonalLeaderboard = function (game_2) {
347
+ return __awaiter(this, arguments, void 0, function (game, season) {
348
+ var _a, response, error, meta, data;
349
+ if (season === void 0) { season = 1; }
350
+ return __generator(this, function (_b) {
351
+ switch (_b.label) {
352
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season !== null && season !== void 0 ? season : 1))];
353
+ case 1:
354
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
355
+ if (error)
356
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
357
+ data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
358
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
359
+ }
360
+ });
361
+ });
362
+ };
363
+ /**
364
+ * `/global/statistics` Gets global statistics
365
+ * @returns The global statistics
366
+ */
367
+ HiveAPI.prototype.getGlobalStatistics = function () {
368
+ return __awaiter(this, void 0, void 0, function () {
369
+ var _a, response, error, meta;
370
+ return __generator(this, function (_b) {
371
+ switch (_b.label) {
372
+ case 0: return [4 /*yield*/, this._fetchAPI("/global/statistics")];
373
+ case 1:
374
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
375
+ if (error)
376
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
377
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
378
+ }
379
+ });
380
+ });
381
+ };
382
+ /**
383
+ * `/game/map/{game}` Gets information about the maps in a game
384
+ * @param game The game to get the maps for (fails for games without maps)
385
+ * @returns A list of maps in the game
386
+ */
387
+ HiveAPI.prototype.getGameMaps = function (game) {
388
+ return __awaiter(this, void 0, void 0, function () {
389
+ var _a, response, error, meta;
390
+ return __generator(this, function (_b) {
391
+ switch (_b.label) {
392
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/map/".concat(game))];
393
+ case 1:
394
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
395
+ if (error)
396
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
397
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
398
+ }
399
+ });
400
+ });
401
+ };
402
+ /**
403
+ * `/game/meta/{game}` Gets metadata about a game
404
+ * @param game The game to get the metadata for
405
+ * @returns The metadata for the game
406
+ */
407
+ HiveAPI.prototype.getGameMetadata = function (game) {
408
+ return __awaiter(this, void 0, void 0, function () {
409
+ var _a, response, error, meta;
410
+ return __generator(this, function (_b) {
411
+ switch (_b.label) {
412
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/meta/".concat(game))];
413
+ case 1:
414
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
415
+ if (error)
416
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
417
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
418
+ }
419
+ });
420
+ });
421
+ };
422
+ return HiveAPI;
423
+ }());
424
+ exports.default = HiveAPI;
@@ -0,0 +1,4 @@
1
+ import { Game } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ import { AllTimeProcessedLeaderboard } from "../types/output";
4
+ export default function getAllTimeLeaderboard<G extends Game>(game_id: G, options?: Partial<Options>): Promise<APIResponse<AllTimeProcessedLeaderboard<G>>>;