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

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/package.json +2 -2
  2. package/lib/helpers/fetchEndpoint.d.ts +0 -3
  3. package/lib/helpers/fetchEndpoint.js +0 -88
  4. package/lib/helpers/isGame.d.ts +0 -2
  5. package/lib/helpers/isGame.js +0 -7
  6. package/lib/helpers/toPoint.d.ts +0 -1
  7. package/lib/helpers/toPoint.js +0 -10
  8. package/lib/index.d.ts +0 -101
  9. package/lib/index.js +0 -404
  10. package/lib/methods/getAllTimeLeaderboard.d.ts +0 -4
  11. package/lib/methods/getAllTimeLeaderboard.js +0 -85
  12. package/lib/methods/getAllTimeStatistics.d.ts +0 -10
  13. package/lib/methods/getAllTimeStatistics.js +0 -126
  14. package/lib/methods/getGlobalStatistics.d.ts +0 -3
  15. package/lib/methods/getGlobalStatistics.js +0 -56
  16. package/lib/methods/getMaps.d.ts +0 -3
  17. package/lib/methods/getMaps.js +0 -81
  18. package/lib/methods/getMetadata.d.ts +0 -3
  19. package/lib/methods/getMetadata.js +0 -81
  20. package/lib/methods/getMonthlyLeaderboard.d.ts +0 -11
  21. package/lib/methods/getMonthlyLeaderboard.js +0 -88
  22. package/lib/methods/getMonthlyStatistics.d.ts +0 -10
  23. package/lib/methods/getMonthlyStatistics.js +0 -132
  24. package/lib/methods/getPlayerInfomation.d.ts +0 -3
  25. package/lib/methods/getPlayerInfomation.js +0 -72
  26. package/lib/methods/getSeasonLeaderboard.d.ts +0 -10
  27. package/lib/methods/getSeasonLeaderboard.js +0 -87
  28. package/lib/methods/getSeasonStatistics.d.ts +0 -10
  29. package/lib/methods/getSeasonStatistics.js +0 -87
  30. package/lib/processors/bed.d.ts +0 -19
  31. package/lib/processors/bed.js +0 -35
  32. package/lib/processors/bridge.d.ts +0 -24
  33. package/lib/processors/bridge.js +0 -40
  34. package/lib/processors/build.d.ts +0 -19
  35. package/lib/processors/build.js +0 -35
  36. package/lib/processors/ctf.d.ts +0 -19
  37. package/lib/processors/ctf.js +0 -35
  38. package/lib/processors/dr.d.ts +0 -19
  39. package/lib/processors/dr.js +0 -35
  40. package/lib/processors/drop.d.ts +0 -17
  41. package/lib/processors/drop.js +0 -34
  42. package/lib/processors/game.d.ts +0 -315
  43. package/lib/processors/game.js +0 -395
  44. package/lib/processors/global_statistics.d.ts +0 -9
  45. package/lib/processors/global_statistics.js +0 -2
  46. package/lib/processors/grav.d.ts +0 -17
  47. package/lib/processors/grav.js +0 -34
  48. package/lib/processors/ground.d.ts +0 -19
  49. package/lib/processors/ground.js +0 -35
  50. package/lib/processors/helpers/processBuildRatings.d.ts +0 -8
  51. package/lib/processors/helpers/processBuildRatings.js +0 -23
  52. package/lib/processors/helpers/processGameAndXP.d.ts +0 -6
  53. package/lib/processors/helpers/processGameAndXP.js +0 -10
  54. package/lib/processors/helpers/processHiderKillsAndDeaths.d.ts +0 -5
  55. package/lib/processors/helpers/processHiderKillsAndDeaths.js +0 -13
  56. package/lib/processors/helpers/processKillsAndDeaths.d.ts +0 -5
  57. package/lib/processors/helpers/processKillsAndDeaths.js +0 -13
  58. package/lib/processors/helpers/processMurdersAndDeaths.d.ts +0 -5
  59. package/lib/processors/helpers/processMurdersAndDeaths.js +0 -13
  60. package/lib/processors/helpers/processPlayedAndVictories.d.ts +0 -6
  61. package/lib/processors/helpers/processPlayedAndVictories.js +0 -12
  62. package/lib/processors/hide.d.ts +0 -19
  63. package/lib/processors/hide.js +0 -35
  64. package/lib/processors/index.d.ts +0 -12
  65. package/lib/processors/index.js +0 -73
  66. package/lib/processors/map.d.ts +0 -8
  67. package/lib/processors/map.js +0 -2
  68. package/lib/processors/meta.d.ts +0 -45
  69. package/lib/processors/meta.js +0 -2
  70. package/lib/processors/murder.d.ts +0 -19
  71. package/lib/processors/murder.js +0 -35
  72. package/lib/processors/parkour.d.ts +0 -5
  73. package/lib/processors/parkour.js +0 -99
  74. package/lib/processors/party.d.ts +0 -17
  75. package/lib/processors/party.js +0 -34
  76. package/lib/processors/player.d.ts +0 -61
  77. package/lib/processors/player.js +0 -54
  78. package/lib/processors/player_search.d.ts +0 -6
  79. package/lib/processors/player_search.js +0 -11
  80. package/lib/processors/sg.d.ts +0 -19
  81. package/lib/processors/sg.js +0 -35
  82. package/lib/processors/sky.d.ts +0 -19
  83. package/lib/processors/sky.js +0 -35
  84. package/lib/processors/wars.d.ts +0 -19
  85. package/lib/processors/wars.js +0 -35
  86. package/lib/types/output.d.ts +0 -62
  87. package/lib/types/output.js +0 -3
  88. package/lib/types/types.d.ts +0 -24
  89. package/lib/types/types.js +0 -2
  90. package/lib/utils.d.ts +0 -21
  91. package/lib/utils.js +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "3.0.0-alpha.21",
3
+ "version": "3.0.0-alpha.23",
4
4
  "description": "An API wrapper for the Hive Minecraft Bedrock Edition server.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "license": "MIT",
12
12
  "author": "Cubeedge Studios",
13
13
  "dependencies": {
14
- "hive-bedrock-data": "^2.0.0-alpha.11"
14
+ "hive-bedrock-data": "^2.0.0-alpha.12"
15
15
  },
16
16
  "scripts": {
17
17
  "build": "tsc"
@@ -1,3 +0,0 @@
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>>>;
@@ -1,88 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- import { Game } from "hive-bedrock-data";
2
- export default function isGame(game_id: Game): boolean;
@@ -1,7 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export default function toPoint(num: number, point: number): number;
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,101 +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 { 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
- private _getStatisticsAllTime;
52
- private _getStatisticsMonthly;
53
- getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
54
- /**
55
- * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
56
- * @param identifier Username or UUID of the player
57
- * @param game The game to get the statistics for
58
- * @param season The season to get the statistics for
59
- * @returns The player's seasonal statistics
60
- */
61
- getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedMonthlyGamesResponse["statistics"][G] | null>>;
62
- /**
63
- * `/game/all/{game}` Gets statistics for a game
64
- * @param timeframe The timeframe to get the statistics for
65
- * @param game The game to get the statistics for
66
- * @param options Additional options including specific month and year
67
- */
68
- getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
69
- getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
70
- getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
71
- month?: number;
72
- year?: number;
73
- }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
74
- private _getLeaderboardAllTime;
75
- private _getLeaderboardMonthly;
76
- /**
77
- * `/game/season/{game}/{season}` Gets seasonal statistics for a game
78
- * @param game The game to get the statistics for
79
- * @param season The season to get the statistics for
80
- * @returns The seasonal statistics for the game
81
- */
82
- getSeasonalLeaderboard<G extends Game>(game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][]>>;
83
- /**
84
- * `/global/statistics` Gets global statistics
85
- * @returns The global statistics
86
- */
87
- getGlobalStatistics(): Promise<MethodResponse<ProcessedGlobalStatisticsResponse>>;
88
- /**
89
- * `/game/map/{game}` Gets information about the maps in a game
90
- * @param game The game to get the maps for (fails for games without maps)
91
- * @returns A list of maps in the game
92
- */
93
- getGameMaps(game: Game): Promise<MethodResponse<ProcessedMapResponse>>;
94
- /**
95
- * `/game/meta/{game}` Gets metadata about a game
96
- * @param game The game to get the metadata for
97
- * @returns The metadata for the game
98
- */
99
- getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
100
- }
101
- export {};
package/lib/index.js DELETED
@@ -1,404 +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 = {}; }
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
- if (options === null || options === void 0 ? void 0 : options.game)
174
- return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
175
- 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)];
176
- });
177
- });
178
- };
179
- HiveAPI.prototype._getStatisticsAllTime = function (identifier, game) {
180
- return __awaiter(this, void 0, void 0, function () {
181
- var _a, response, error, meta, data;
182
- return __generator(this, function (_b) {
183
- switch (_b.label) {
184
- case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game !== null && game !== void 0 ? game : "all", "/").concat(identifier))];
185
- case 1:
186
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
187
- if (error)
188
- return [2 /*return*/, { data: null, error: error, meta: meta }];
189
- if (game)
190
- return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, false, response), error: null, meta: meta }];
191
- data = Object.fromEntries(Object.entries(response).map(function (_a) {
192
- var _b;
193
- var _c = __read(_a, 2), id = _c[0], res = _c[1];
194
- 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];
195
- }));
196
- delete data.main;
197
- return [2 /*return*/, {
198
- data: {
199
- player: (0, player_1.default)(response),
200
- statistics: data,
201
- },
202
- error: null,
203
- meta: meta,
204
- }];
205
- }
206
- });
207
- });
208
- };
209
- HiveAPI.prototype._getStatisticsMonthly = function (identifier, game, month, year) {
210
- return __awaiter(this, void 0, void 0, function () {
211
- var _a, response, error, meta, data;
212
- return __generator(this, function (_b) {
213
- switch (_b.label) {
214
- 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))];
215
- case 1:
216
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
217
- if (error)
218
- return [2 /*return*/, { data: null, error: error, meta: meta }];
219
- if (game)
220
- return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, false, response), error: null, meta: meta }];
221
- data = Object.fromEntries(Object.entries(response).map(function (_a) {
222
- var _b;
223
- var _c = __read(_a, 2), id = _c[0], res = _c[1];
224
- 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];
225
- }));
226
- delete data.main;
227
- return [2 /*return*/, {
228
- data: {
229
- statistics: data,
230
- },
231
- error: null,
232
- meta: meta,
233
- }];
234
- }
235
- });
236
- });
237
- };
238
- HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
239
- return __awaiter(this, void 0, void 0, function () {
240
- var _a, response, error, meta;
241
- return __generator(this, function (_b) {
242
- switch (_b.label) {
243
- case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/available"))];
244
- case 1:
245
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
246
- if (error)
247
- return [2 /*return*/, { data: null, error: error, meta: meta }];
248
- return [2 /*return*/, { data: response, error: null, meta: meta }];
249
- }
250
- });
251
- });
252
- };
253
- /**
254
- * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
255
- * @param identifier Username or UUID of the player
256
- * @param game The game to get the statistics for
257
- * @param season The season to get the statistics for
258
- * @returns The player's seasonal statistics
259
- */
260
- HiveAPI.prototype.getSeasonalStatistics = function (identifier_1, game_2) {
261
- return __awaiter(this, arguments, void 0, function (identifier, game, season) {
262
- var _a, response, error, meta, data;
263
- if (season === void 0) { season = 1; }
264
- return __generator(this, function (_b) {
265
- switch (_b.label) {
266
- case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season))];
267
- case 1:
268
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
269
- if (error)
270
- return [2 /*return*/, { data: null, error: error, meta: meta }];
271
- data = (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, response);
272
- return [2 /*return*/, { data: data, error: null, meta: meta }];
273
- }
274
- });
275
- });
276
- };
277
- HiveAPI.prototype.getLeaderboard = function (timeframe, game, options) {
278
- return __awaiter(this, void 0, void 0, function () {
279
- return __generator(this, function (_a) {
280
- if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
281
- 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())];
282
- return [2 /*return*/, this._getLeaderboardAllTime(game)];
283
- });
284
- });
285
- };
286
- // /game/all/{game}
287
- HiveAPI.prototype._getLeaderboardAllTime = function (game) {
288
- return __awaiter(this, void 0, void 0, function () {
289
- var _a, response, error, meta, data;
290
- return __generator(this, function (_b) {
291
- switch (_b.label) {
292
- case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game))];
293
- case 1:
294
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
295
- if (error)
296
- return [2 /*return*/, { data: null, error: error, meta: meta }];
297
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.AllTime, true, res); });
298
- return [2 /*return*/, { data: data, error: null, meta: meta }];
299
- }
300
- });
301
- });
302
- };
303
- // /game/monthly/{game}/{year}/{month}
304
- HiveAPI.prototype._getLeaderboardMonthly = function (game, month, year) {
305
- return __awaiter(this, void 0, void 0, function () {
306
- var _a, response, error, meta, data;
307
- return __generator(this, function (_b) {
308
- switch (_b.label) {
309
- case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/").concat(year, "/").concat(month))];
310
- case 1:
311
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
312
- if (error)
313
- return [2 /*return*/, { data: null, error: error, meta: meta }];
314
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
315
- return [2 /*return*/, { data: data, error: null, meta: meta }];
316
- }
317
- });
318
- });
319
- };
320
- /**
321
- * `/game/season/{game}/{season}` Gets seasonal statistics for a game
322
- * @param game The game to get the statistics for
323
- * @param season The season to get the statistics for
324
- * @returns The seasonal statistics for the game
325
- */
326
- HiveAPI.prototype.getSeasonalLeaderboard = function (game_2) {
327
- return __awaiter(this, arguments, void 0, function (game, season) {
328
- var _a, response, error, meta, data;
329
- if (season === void 0) { season = 1; }
330
- return __generator(this, function (_b) {
331
- switch (_b.label) {
332
- case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season !== null && season !== void 0 ? season : 1))];
333
- case 1:
334
- _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
335
- if (error)
336
- return [2 /*return*/, { data: null, error: error, meta: meta }];
337
- data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
338
- return [2 /*return*/, { data: data, error: null, meta: meta }];
339
- }
340
- });
341
- });
342
- };
343
- /**
344
- * `/global/statistics` Gets global statistics
345
- * @returns The global statistics
346
- */
347
- HiveAPI.prototype.getGlobalStatistics = function () {
348
- return __awaiter(this, void 0, void 0, function () {
349
- var _a, response, error, meta;
350
- return __generator(this, function (_b) {
351
- switch (_b.label) {
352
- case 0: return [4 /*yield*/, this._fetchAPI("/global/statistics")];
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
- return [2 /*return*/, { data: response, error: null, meta: meta }];
358
- }
359
- });
360
- });
361
- };
362
- /**
363
- * `/game/map/{game}` Gets information about the maps in a game
364
- * @param game The game to get the maps for (fails for games without maps)
365
- * @returns A list of maps in the game
366
- */
367
- HiveAPI.prototype.getGameMaps = function (game) {
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("/game/map/".concat(game))];
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/meta/{game}` Gets metadata about a game
384
- * @param game The game to get the metadata for
385
- * @returns The metadata for the game
386
- */
387
- HiveAPI.prototype.getGameMetadata = 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/meta/".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
- return HiveAPI;
403
- }());
404
- exports.default = HiveAPI;
@@ -1,4 +0,0 @@
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>>>;