hive-bedrock-api 4.0.0 → 4.0.1
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/lib/index.d.ts +115 -0
- package/lib/index.js +495 -0
- package/lib/processors/game.d.ts +293 -0
- package/lib/processors/game.js +396 -0
- package/lib/processors/global_statistics.d.ts +9 -0
- package/lib/processors/global_statistics.js +2 -0
- package/lib/processors/map.d.ts +8 -0
- package/lib/processors/map.js +2 -0
- package/lib/processors/meta.d.ts +45 -0
- package/lib/processors/meta.js +2 -0
- package/lib/processors/player.d.ts +62 -0
- package/lib/processors/player.js +55 -0
- package/lib/processors/player_search.d.ts +6 -0
- package/lib/processors/player_search.js +11 -0
- package/lib/utils.d.ts +21 -0
- package/lib/utils.js +2 -0
- package/package.json +4 -3
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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 * from "./processors/game";
|
|
16
|
+
export * from "./processors/global_statistics";
|
|
17
|
+
export * from "./processors/map";
|
|
18
|
+
export * from "./processors/meta";
|
|
19
|
+
export * from "./processors/player";
|
|
20
|
+
export * from "./processors/player_search";
|
|
21
|
+
export default class HiveAPI {
|
|
22
|
+
options: Options;
|
|
23
|
+
constructor(options?: Options);
|
|
24
|
+
private _fetchAPI;
|
|
25
|
+
/**
|
|
26
|
+
* `/game/all/main/{identifier}` Gets information about a player
|
|
27
|
+
* @param identifier Username or UUID of the player
|
|
28
|
+
* @returns The player information
|
|
29
|
+
*/
|
|
30
|
+
getPlayer(identifier: string): Promise<MethodResponse<ProcessedPlayerResponse>>;
|
|
31
|
+
/**
|
|
32
|
+
* `/player/search/{prefix}` Gets a list of players that match the prefix
|
|
33
|
+
* @param prefix The prefix to search for (must be at least 4 characters long)
|
|
34
|
+
* @returns A list of players that match the prefix
|
|
35
|
+
*/
|
|
36
|
+
getPlayerSearch(prefix: string): Promise<MethodResponse<ProcessedPlayerSearchResponse>>;
|
|
37
|
+
/**
|
|
38
|
+
* Gets statistics for a player
|
|
39
|
+
* @param identifier Username or UUID of the player
|
|
40
|
+
* @param timeframe The timeframe to get the statistics for
|
|
41
|
+
* @param options Additional options including specific game, month, and year
|
|
42
|
+
* @returns The player statistics
|
|
43
|
+
*/
|
|
44
|
+
getStatistics(identifier: string, timeframe: Timeframe.AllTime): Promise<MethodResponse<ProcessedAllGamesResponse>>;
|
|
45
|
+
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.AllTime, options: {
|
|
46
|
+
game: G;
|
|
47
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, false>[G]>>;
|
|
48
|
+
getStatistics(identifier: string, timeframe: Timeframe.Monthly, options?: {
|
|
49
|
+
month?: number;
|
|
50
|
+
year?: number;
|
|
51
|
+
}): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
|
|
52
|
+
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Monthly, options: {
|
|
53
|
+
game: G;
|
|
54
|
+
month?: number;
|
|
55
|
+
year?: number;
|
|
56
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, false>[G]>>;
|
|
57
|
+
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Seasonal, options: {
|
|
58
|
+
game: G;
|
|
59
|
+
season: number;
|
|
60
|
+
}): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
|
|
61
|
+
private _getStatisticsAllTime;
|
|
62
|
+
private _getStatisticsMonthly;
|
|
63
|
+
private _getStatisticsSeasonal;
|
|
64
|
+
getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
|
|
65
|
+
/**
|
|
66
|
+
* `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
|
|
67
|
+
* @param identifier Username or UUID of the player
|
|
68
|
+
* @param game The game to get the statistics for
|
|
69
|
+
* @param season The season to get the statistics for
|
|
70
|
+
* @returns The player's seasonal statistics
|
|
71
|
+
*/
|
|
72
|
+
getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedMonthlyGamesResponse["statistics"][G] | null>>;
|
|
73
|
+
/**
|
|
74
|
+
* `/game/all/{game}` Gets statistics for a game
|
|
75
|
+
* @param timeframe The timeframe to get the statistics for
|
|
76
|
+
* @param game The game to get the statistics for
|
|
77
|
+
* @param options Additional options including specific month and year
|
|
78
|
+
*/
|
|
79
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
|
|
80
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
|
|
81
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
|
|
82
|
+
month?: number;
|
|
83
|
+
year?: number;
|
|
84
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
|
|
85
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Seasonal, game: G, options: {
|
|
86
|
+
season: number;
|
|
87
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Seasonal, true>[G][] | null>>;
|
|
88
|
+
private _getLeaderboardAllTime;
|
|
89
|
+
private _getLeaderboardMonthly;
|
|
90
|
+
private _getLeaderboardSeasonal;
|
|
91
|
+
/**
|
|
92
|
+
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
93
|
+
* @param game The game to get the statistics for
|
|
94
|
+
* @param season The season to get the statistics for
|
|
95
|
+
* @returns The seasonal statistics for the game
|
|
96
|
+
*/
|
|
97
|
+
getSeasonalLeaderboard<G extends Game>(game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][]>>;
|
|
98
|
+
/**
|
|
99
|
+
* `/global/statistics` Gets global statistics
|
|
100
|
+
* @returns The global statistics
|
|
101
|
+
*/
|
|
102
|
+
getGlobalStatistics(): Promise<MethodResponse<ProcessedGlobalStatisticsResponse>>;
|
|
103
|
+
/**
|
|
104
|
+
* `/game/map/{game}` Gets information about the maps in a game
|
|
105
|
+
* @param game The game to get the maps for (fails for games without maps)
|
|
106
|
+
* @returns A list of maps in the game
|
|
107
|
+
*/
|
|
108
|
+
getGameMaps(game: Game): Promise<MethodResponse<ProcessedMapResponse>>;
|
|
109
|
+
/**
|
|
110
|
+
* `/game/meta/{game}` Gets metadata about a game
|
|
111
|
+
* @param game The game to get the metadata for
|
|
112
|
+
* @returns The metadata for the game
|
|
113
|
+
*/
|
|
114
|
+
getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
|
|
115
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,495 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
+
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);
|
|
38
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
+
function step(op) {
|
|
41
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
43
|
+
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;
|
|
44
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
+
switch (op[0]) {
|
|
46
|
+
case 0: case 1: t = op; break;
|
|
47
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
+
default:
|
|
51
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
+
if (t[2]) _.ops.pop();
|
|
56
|
+
_.trys.pop(); continue;
|
|
57
|
+
}
|
|
58
|
+
op = body.call(thisArg, _);
|
|
59
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
64
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
65
|
+
if (!m) return o;
|
|
66
|
+
var i = m.call(o), r, ar = [], e;
|
|
67
|
+
try {
|
|
68
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
69
|
+
}
|
|
70
|
+
catch (error) { e = { error: error }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e) throw e.error; }
|
|
76
|
+
}
|
|
77
|
+
return ar;
|
|
78
|
+
};
|
|
79
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
80
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81
|
+
};
|
|
82
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
+
var hive_bedrock_data_1 = require("hive-bedrock-data");
|
|
84
|
+
var player_1 = __importDefault(require("./processors/player"));
|
|
85
|
+
var player_search_1 = __importDefault(require("./processors/player_search"));
|
|
86
|
+
var game_1 = require("./processors/game");
|
|
87
|
+
__exportStar(require("./processors/game"), exports);
|
|
88
|
+
__exportStar(require("./processors/global_statistics"), exports);
|
|
89
|
+
__exportStar(require("./processors/map"), exports);
|
|
90
|
+
__exportStar(require("./processors/meta"), exports);
|
|
91
|
+
__exportStar(require("./processors/player"), exports);
|
|
92
|
+
__exportStar(require("./processors/player_search"), exports);
|
|
93
|
+
var HiveAPI = /** @class */ (function () {
|
|
94
|
+
function HiveAPI(options) {
|
|
95
|
+
if (options === void 0) { options = {}; }
|
|
96
|
+
var _a;
|
|
97
|
+
this.options = options;
|
|
98
|
+
this.options = options;
|
|
99
|
+
this.options.apiBaseEndpoint = (_a = this.options.apiBaseEndpoint) !== null && _a !== void 0 ? _a : hive_bedrock_data_1.API_BASE_ENDPOINT;
|
|
100
|
+
}
|
|
101
|
+
HiveAPI.prototype._fetchAPI = function (endpoint) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var url, start, request, meta, response, err_1;
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return __generator(this, function (_c) {
|
|
106
|
+
switch (_c.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
url = this.options.apiBaseEndpoint + endpoint;
|
|
109
|
+
_c.label = 1;
|
|
110
|
+
case 1:
|
|
111
|
+
_c.trys.push([1, 4, , 5]);
|
|
112
|
+
start = performance.now();
|
|
113
|
+
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) }))];
|
|
114
|
+
case 2:
|
|
115
|
+
request = _c.sent();
|
|
116
|
+
if (!request.ok)
|
|
117
|
+
return [2 /*return*/, { data: null, error: { status: request.status } }];
|
|
118
|
+
meta = {
|
|
119
|
+
duration: Math.ceil(performance.now() - start),
|
|
120
|
+
ratelimit: {
|
|
121
|
+
limit: Number(request.headers.get("X-Ratelimit-Limit")),
|
|
122
|
+
remaining: Number(request.headers.get("X-Ratelimit-Remaining")),
|
|
123
|
+
reset: Number(request.headers.get("X-Ratelimit-Reset")),
|
|
124
|
+
},
|
|
125
|
+
retryAfter: Number(request.headers.get("Retry-After")),
|
|
126
|
+
};
|
|
127
|
+
return [4 /*yield*/, request.json()];
|
|
128
|
+
case 3:
|
|
129
|
+
response = _c.sent();
|
|
130
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
131
|
+
case 4:
|
|
132
|
+
err_1 = _c.sent();
|
|
133
|
+
return [2 /*return*/, { data: null, error: { status: 500, message: err_1.message } }];
|
|
134
|
+
case 5: return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* `/game/all/main/{identifier}` Gets information about a player
|
|
141
|
+
* @param identifier Username or UUID of the player
|
|
142
|
+
* @returns The player information
|
|
143
|
+
*/
|
|
144
|
+
HiveAPI.prototype.getPlayer = function (identifier) {
|
|
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("/game/all/main/".concat(identifier))];
|
|
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_1.default)(response);
|
|
155
|
+
if (!data)
|
|
156
|
+
return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player data" }, meta: meta }];
|
|
157
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* `/player/search/{prefix}` Gets a list of players that match the prefix
|
|
164
|
+
* @param prefix The prefix to search for (must be at least 4 characters long)
|
|
165
|
+
* @returns A list of players that match the prefix
|
|
166
|
+
*/
|
|
167
|
+
HiveAPI.prototype.getPlayerSearch = function (prefix) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var _a, response, error, meta, data;
|
|
170
|
+
return __generator(this, function (_b) {
|
|
171
|
+
switch (_b.label) {
|
|
172
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/player/search/".concat(prefix))];
|
|
173
|
+
case 1:
|
|
174
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
175
|
+
if (error)
|
|
176
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
177
|
+
data = (0, player_search_1.default)(response);
|
|
178
|
+
if (!data)
|
|
179
|
+
return [2 /*return*/, { data: null, error: { status: 500, message: "Failed to process player search data" }, meta: meta }];
|
|
180
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
HiveAPI.prototype.getStatistics = function (identifier, timeframe, options) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.AllTime) {
|
|
189
|
+
if (options === null || options === void 0 ? void 0 : options.game) {
|
|
190
|
+
if (!hive_bedrock_data_1.Games[options.game].statistics)
|
|
191
|
+
throw new Error("Statistics are not available for the game: ".concat(options.game));
|
|
192
|
+
return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
|
|
193
|
+
}
|
|
194
|
+
return [2 /*return*/, this._getStatisticsAllTime(identifier)];
|
|
195
|
+
}
|
|
196
|
+
else if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal) {
|
|
197
|
+
if (!(options === null || options === void 0 ? void 0 : options.game))
|
|
198
|
+
throw new Error("Game must be specified for seasonal statistics");
|
|
199
|
+
if (!hive_bedrock_data_1.Games[options.game].statistics)
|
|
200
|
+
throw new Error("Statistics are not available for the game: ".concat(options.game));
|
|
201
|
+
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)];
|
|
202
|
+
}
|
|
203
|
+
if (options === null || options === void 0 ? void 0 : options.game)
|
|
204
|
+
return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
|
|
205
|
+
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)];
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
HiveAPI.prototype._getStatisticsAllTime = function (identifier, game) {
|
|
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/all/".concat(game !== null && game !== void 0 ? game : "all", "/").concat(identifier))];
|
|
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.processGame)(game, hive_bedrock_data_1.Timeframe.AllTime, 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.processGame)(id, hive_bedrock_data_1.Timeframe.AllTime, false, res)) !== null && _b !== void 0 ? _b : null];
|
|
225
|
+
}));
|
|
226
|
+
delete data.main;
|
|
227
|
+
return [2 /*return*/, {
|
|
228
|
+
data: {
|
|
229
|
+
player: (0, player_1.default)(response),
|
|
230
|
+
statistics: data,
|
|
231
|
+
},
|
|
232
|
+
error: null,
|
|
233
|
+
meta: meta,
|
|
234
|
+
}];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
HiveAPI.prototype._getStatisticsMonthly = function (identifier, game, month, year) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
+
var _a, response, error, meta, data;
|
|
242
|
+
return __generator(this, function (_b) {
|
|
243
|
+
switch (_b.label) {
|
|
244
|
+
case 0:
|
|
245
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
246
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
247
|
+
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))];
|
|
248
|
+
case 1:
|
|
249
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
250
|
+
if (error)
|
|
251
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
252
|
+
if (game)
|
|
253
|
+
return [2 /*return*/, { data: (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, false, response), error: null, meta: meta }];
|
|
254
|
+
data = Object.fromEntries(Object.entries(response).map(function (_a) {
|
|
255
|
+
var _b;
|
|
256
|
+
var _c = __read(_a, 2), id = _c[0], res = _c[1];
|
|
257
|
+
return [id, id === "main" ? null : (_b = (0, game_1.processGame)(id, hive_bedrock_data_1.Timeframe.Monthly, false, res)) !== null && _b !== void 0 ? _b : null];
|
|
258
|
+
}));
|
|
259
|
+
delete data.main;
|
|
260
|
+
return [2 /*return*/, {
|
|
261
|
+
data: {
|
|
262
|
+
statistics: data,
|
|
263
|
+
},
|
|
264
|
+
error: null,
|
|
265
|
+
meta: meta,
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
HiveAPI.prototype._getStatisticsSeasonal = function (identifier, game, season) {
|
|
272
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
+
var _a, response, error, meta;
|
|
274
|
+
return __generator(this, function (_b) {
|
|
275
|
+
switch (_b.label) {
|
|
276
|
+
case 0:
|
|
277
|
+
if (!hive_bedrock_data_1.Games[game].statistics)
|
|
278
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
279
|
+
return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season !== null && season !== void 0 ? season : 1))];
|
|
280
|
+
case 1:
|
|
281
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
282
|
+
if (error)
|
|
283
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
284
|
+
return [2 /*return*/, { data: (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var _a, response, error, meta;
|
|
292
|
+
return __generator(this, function (_b) {
|
|
293
|
+
switch (_b.label) {
|
|
294
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/available"))];
|
|
295
|
+
case 1:
|
|
296
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
297
|
+
if (error)
|
|
298
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
299
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
|
|
306
|
+
* @param identifier Username or UUID of the player
|
|
307
|
+
* @param game The game to get the statistics for
|
|
308
|
+
* @param season The season to get the statistics for
|
|
309
|
+
* @returns The player's seasonal statistics
|
|
310
|
+
*/
|
|
311
|
+
HiveAPI.prototype.getSeasonalStatistics = function (identifier_1, game_2) {
|
|
312
|
+
return __awaiter(this, arguments, void 0, function (identifier, game, season) {
|
|
313
|
+
var _a, response, error, meta, data;
|
|
314
|
+
if (season === void 0) { season = 1; }
|
|
315
|
+
return __generator(this, function (_b) {
|
|
316
|
+
switch (_b.label) {
|
|
317
|
+
case 0:
|
|
318
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
319
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
320
|
+
return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season))];
|
|
321
|
+
case 1:
|
|
322
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
323
|
+
if (error)
|
|
324
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
325
|
+
data = (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, response);
|
|
326
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
HiveAPI.prototype.getLeaderboard = function (timeframe, game, options) {
|
|
332
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
333
|
+
return __generator(this, function (_a) {
|
|
334
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
335
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
336
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
|
|
337
|
+
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())];
|
|
338
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal)
|
|
339
|
+
return [2 /*return*/, this._getLeaderboardSeasonal(game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
|
|
340
|
+
return [2 /*return*/, this._getLeaderboardAllTime(game)];
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
// /game/all/{game}
|
|
345
|
+
HiveAPI.prototype._getLeaderboardAllTime = function (game) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
347
|
+
var _a, response, error, meta, data;
|
|
348
|
+
return __generator(this, function (_b) {
|
|
349
|
+
switch (_b.label) {
|
|
350
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/all/".concat(game))];
|
|
351
|
+
case 1:
|
|
352
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
353
|
+
if (error)
|
|
354
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
355
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.AllTime, true, res); });
|
|
356
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
// /game/monthly/{game}/{year}/{month}
|
|
362
|
+
HiveAPI.prototype._getLeaderboardMonthly = function (game, month, year) {
|
|
363
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
364
|
+
var _a, response, error, meta, data;
|
|
365
|
+
return __generator(this, function (_b) {
|
|
366
|
+
switch (_b.label) {
|
|
367
|
+
case 0:
|
|
368
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
369
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
370
|
+
return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/").concat(year, "/").concat(month))];
|
|
371
|
+
case 1:
|
|
372
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
373
|
+
if (error)
|
|
374
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
375
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
|
|
376
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
// /game/season/{game}/season
|
|
382
|
+
HiveAPI.prototype._getLeaderboardSeasonal = function (game_2) {
|
|
383
|
+
return __awaiter(this, arguments, void 0, function (game, season) {
|
|
384
|
+
var _a, response, error, meta, data;
|
|
385
|
+
if (season === void 0) { season = 1; }
|
|
386
|
+
return __generator(this, function (_b) {
|
|
387
|
+
switch (_b.label) {
|
|
388
|
+
case 0:
|
|
389
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
390
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
391
|
+
return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season))];
|
|
392
|
+
case 1:
|
|
393
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
394
|
+
if (error)
|
|
395
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
396
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Seasonal, true, res); });
|
|
397
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
404
|
+
* @param game The game to get the statistics for
|
|
405
|
+
* @param season The season to get the statistics for
|
|
406
|
+
* @returns The seasonal statistics for the game
|
|
407
|
+
*/
|
|
408
|
+
HiveAPI.prototype.getSeasonalLeaderboard = function (game_2) {
|
|
409
|
+
return __awaiter(this, arguments, void 0, function (game, season) {
|
|
410
|
+
var _a, response, error, meta, data;
|
|
411
|
+
if (season === void 0) { season = 1; }
|
|
412
|
+
return __generator(this, function (_b) {
|
|
413
|
+
switch (_b.label) {
|
|
414
|
+
case 0:
|
|
415
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
416
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
417
|
+
return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season !== null && season !== void 0 ? season : 1))];
|
|
418
|
+
case 1:
|
|
419
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
420
|
+
if (error)
|
|
421
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
422
|
+
data = response.map(function (res) { return (0, game_1.processGame)(game, hive_bedrock_data_1.Timeframe.Monthly, true, res); });
|
|
423
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* `/global/statistics` Gets global statistics
|
|
430
|
+
* @returns The global statistics
|
|
431
|
+
*/
|
|
432
|
+
HiveAPI.prototype.getGlobalStatistics = function () {
|
|
433
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
434
|
+
var _a, response, error, meta;
|
|
435
|
+
return __generator(this, function (_b) {
|
|
436
|
+
switch (_b.label) {
|
|
437
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/global/statistics")];
|
|
438
|
+
case 1:
|
|
439
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
440
|
+
if (error)
|
|
441
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
442
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* `/game/map/{game}` Gets information about the maps in a game
|
|
449
|
+
* @param game The game to get the maps for (fails for games without maps)
|
|
450
|
+
* @returns A list of maps in the game
|
|
451
|
+
*/
|
|
452
|
+
HiveAPI.prototype.getGameMaps = function (game) {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
454
|
+
var _a, response, error, meta;
|
|
455
|
+
return __generator(this, function (_b) {
|
|
456
|
+
switch (_b.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
459
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
460
|
+
return [4 /*yield*/, this._fetchAPI("/game/map/".concat(game))];
|
|
461
|
+
case 1:
|
|
462
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
463
|
+
if (error)
|
|
464
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
465
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* `/game/meta/{game}` Gets metadata about a game
|
|
472
|
+
* @param game The game to get the metadata for
|
|
473
|
+
* @returns The metadata for the game
|
|
474
|
+
*/
|
|
475
|
+
HiveAPI.prototype.getGameMetadata = function (game) {
|
|
476
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
477
|
+
var _a, response, error, meta;
|
|
478
|
+
return __generator(this, function (_b) {
|
|
479
|
+
switch (_b.label) {
|
|
480
|
+
case 0:
|
|
481
|
+
if (game && !hive_bedrock_data_1.Games[game].statistics)
|
|
482
|
+
throw new Error("Statistics are not available for the game: ".concat(game));
|
|
483
|
+
return [4 /*yield*/, this._fetchAPI("/game/meta/".concat(game))];
|
|
484
|
+
case 1:
|
|
485
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
486
|
+
if (error)
|
|
487
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
488
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
return HiveAPI;
|
|
494
|
+
}());
|
|
495
|
+
exports.default = HiveAPI;
|