hive-bedrock-api 1.0.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +37 -41
  2. package/lib/helpers/fetchEndpoint.d.ts +3 -0
  3. package/lib/{methods/fetchData.js → helpers/fetchEndpoint.js} +18 -14
  4. package/lib/helpers/isGame.d.ts +2 -0
  5. package/lib/helpers/isGame.js +7 -0
  6. package/lib/helpers/toPoint.d.ts +1 -0
  7. package/lib/helpers/toPoint.js +6 -0
  8. package/lib/index.d.ts +9 -9
  9. package/lib/index.js +13 -31
  10. package/lib/methods/getAllTimeLeaderboard.d.ts +4 -5
  11. package/lib/methods/getAllTimeLeaderboard.js +25 -19
  12. package/lib/methods/getAllTimeStatistics.d.ts +9 -0
  13. package/lib/methods/getAllTimeStatistics.js +180 -0
  14. package/lib/methods/getGlobalStatistics.d.ts +3 -3
  15. package/lib/methods/getGlobalStatistics.js +7 -30
  16. package/lib/methods/getMaps.d.ts +3 -4
  17. package/lib/methods/getMaps.js +17 -38
  18. package/lib/methods/getMetadata.d.ts +3 -0
  19. package/lib/methods/{getPlayerInfo.js → getMetadata.js} +20 -18
  20. package/lib/methods/getMonthlyLeaderboard.d.ts +9 -11
  21. package/lib/methods/getMonthlyLeaderboard.js +28 -56
  22. package/lib/methods/getMonthlyStatistics.d.ts +10 -0
  23. package/lib/methods/getMonthlyStatistics.js +154 -0
  24. package/lib/methods/getPlayerInfomation.d.ts +3 -0
  25. package/lib/methods/{getGameMetadata.js → getPlayerInfomation.js} +15 -21
  26. package/lib/processors/index.d.ts +7 -0
  27. package/lib/processors/index.js +116 -0
  28. package/lib/types/output.d.ts +67 -0
  29. package/lib/types/{GAMES.js → output.js} +1 -1
  30. package/lib/types/types.d.ts +21 -0
  31. package/package.json +7 -8
  32. package/lib/format/gameFormat.d.ts +0 -30
  33. package/lib/format/gameFormat.js +0 -164
  34. package/lib/methods/calculateLevel.d.ts +0 -2
  35. package/lib/methods/calculateLevel.js +0 -45
  36. package/lib/methods/fetchData.d.ts +0 -25
  37. package/lib/methods/getAllTimeStats.d.ts +0 -13
  38. package/lib/methods/getAllTimeStats.js +0 -186
  39. package/lib/methods/getGameMetadata.d.ts +0 -4
  40. package/lib/methods/getMonthlyStats.d.ts +0 -15
  41. package/lib/methods/getMonthlyStats.js +0 -192
  42. package/lib/methods/getPlayerInfo.d.ts +0 -4
  43. package/lib/types/API.d.ts +0 -224
  44. package/lib/types/API.js +0 -37
  45. package/lib/types/ENDPOINTS.d.ts +0 -11
  46. package/lib/types/GAMES.d.ts +0 -85
  47. package/lib/types/GAME_INFO.d.ts +0 -26
  48. package/lib/types/GAME_INFO.js +0 -113
  49. package/lib/types/METHODS.d.ts +0 -8
  50. package/lib/types/METHODS.js +0 -2
  51. /package/lib/types/{ENDPOINTS.js → types.js} +0 -0
@@ -1,4 +1,3 @@
1
- import { API_MAP, Options } from "../types/API";
2
- import { GAME } from "../types/GAME_INFO";
3
- import { MethodResponse } from "../types/METHODS";
4
- export default function getMaps(game: GAME, options?: Options): Promise<MethodResponse<API_MAP[]>>;
1
+ import { Game, MapMetadata } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ export default function getMaps<G extends Game>(game_id: G, options?: Options): Promise<APIResponse<MapMetadata[]>>;
@@ -50,51 +50,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var GAME_INFO_1 = require("../types/GAME_INFO");
54
- var fetchData_1 = __importDefault(require("./fetchData"));
55
- var VALID_GAMES = [
56
- GAME_INFO_1.GAME.BlockDrop,
57
- GAME_INFO_1.GAME.CaptureTheFlag,
58
- GAME_INFO_1.GAME.DeathRun,
59
- GAME_INFO_1.GAME.Gravity,
60
- GAME_INFO_1.GAME.GroundWars,
61
- GAME_INFO_1.GAME.HideAndSeek,
62
- GAME_INFO_1.GAME.MurderMystery,
63
- GAME_INFO_1.GAME.Skywars,
64
- GAME_INFO_1.GAME.SurvivalGames,
65
- GAME_INFO_1.GAME.TreasureWars,
66
- GAME_INFO_1.GAME.TheBridge,
67
- ];
68
- function getMaps(game, options) {
53
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
54
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
55
+ function getMaps(game_id, options) {
69
56
  return __awaiter(this, void 0, void 0, function () {
70
- var _a, data, error, err_1;
71
- return __generator(this, function (_b) {
72
- switch (_b.label) {
57
+ var response, data;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
73
60
  case 0:
74
- if (!VALID_GAMES.includes(game))
61
+ if (!(0, isGame_1.default)(game_id))
75
62
  return [2 /*return*/, {
76
- data: null,
63
+ status: 404,
77
64
  error: {
78
- message: "This game does not support this endpoint as it only has one map.",
65
+ code: 404,
66
+ message: "Game not found.",
79
67
  },
80
- }];
81
- _b.label = 1;
82
- case 1:
83
- _b.trys.push([1, 3, , 4]);
84
- return [4 /*yield*/, (0, fetchData_1.default)("/game/map/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
85
- case 2:
86
- _a = _b.sent(), data = _a.data, error = _a.error;
87
- if (error || !data)
88
- return [2 /*return*/, {
89
68
  data: null,
90
- error: __assign({ message: "Failed to fetch data." }, error),
91
69
  }];
92
- return [2 /*return*/, { data: data, error: null }];
93
- case 3:
94
- err_1 = _b.sent();
95
- console.error(err_1);
96
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
97
- case 4: return [2 /*return*/];
70
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/map/".concat(game_id), options === null || options === void 0 ? void 0 : options.init)];
71
+ case 1:
72
+ response = _a.sent();
73
+ if (response.error)
74
+ return [2 /*return*/, response];
75
+ data = response.data;
76
+ return [2 /*return*/, __assign(__assign({}, response), { data: data })];
98
77
  }
99
78
  });
100
79
  });
@@ -0,0 +1,3 @@
1
+ import { Game, GameMetadata } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ export default function getMetdata<G extends Game>(game_id: G, options?: Options): Promise<APIResponse<GameMetadata>>;
@@ -50,30 +50,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var fetchData_1 = __importDefault(require("./fetchData"));
54
- function getPlayerInfo(playerIdentifier, options) {
53
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
54
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
55
+ function getMetdata(game_id, options) {
55
56
  return __awaiter(this, void 0, void 0, function () {
56
- var _a, data, error, err_1;
57
- return __generator(this, function (_b) {
58
- switch (_b.label) {
57
+ var response, data;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
59
60
  case 0:
60
- _b.trys.push([0, 2, , 3]);
61
- return [4 /*yield*/, (0, fetchData_1.default)("/game/all/main/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
62
- case 1:
63
- _a = _b.sent(), data = _a.data, error = _a.error;
64
- if (error || !data)
61
+ if (!(0, isGame_1.default)(game_id))
65
62
  return [2 /*return*/, {
63
+ status: 404,
64
+ error: {
65
+ code: 404,
66
+ message: "Game not found.",
67
+ },
66
68
  data: null,
67
- error: __assign({ message: "Failed to fetch data." }, error),
68
69
  }];
69
- return [2 /*return*/, { data: data.main, error: null }];
70
- case 2:
71
- err_1 = _b.sent();
72
- console.error(err_1);
73
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
74
- case 3: return [2 /*return*/];
70
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/meta/".concat(game_id), options === null || options === void 0 ? void 0 : options.init)];
71
+ case 1:
72
+ response = _a.sent();
73
+ if (response.error)
74
+ return [2 /*return*/, response];
75
+ data = response.data;
76
+ return [2 /*return*/, __assign(__assign({}, response), { data: data })];
75
77
  }
76
78
  });
77
79
  });
78
80
  }
79
- exports.default = getPlayerInfo;
81
+ exports.default = getMetdata;
@@ -1,13 +1,11 @@
1
- import { Options } from "../types/API";
2
- import { LB_STATS } from "../types/GAMES";
3
- import { GAME } from "../types/GAME_INFO";
4
- import { MethodResponse } from "../types/METHODS";
5
- interface OptionsType extends Options {
6
- year?: number;
7
- month?: number;
8
- date?: Date;
9
- skip?: number;
10
- amount?: number;
1
+ import { Game, Timeframe } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ import { LeaderboardResponse } from "../types/output";
4
+ interface MonthlyOptions extends Options {
5
+ month: number;
6
+ year: number;
7
+ amount: number;
8
+ skip: number;
11
9
  }
12
- export default function getMonthlyLeaderboard<G extends GAME>(game: G, options?: OptionsType): Promise<MethodResponse<LB_STATS<G>[]>>;
10
+ export default function getMonthlyLeaderboard<G extends Game>(game_id: G, options?: Partial<MonthlyOptions>): Promise<APIResponse<LeaderboardResponse<G, Timeframe.Monthly>>>;
13
11
  export {};
@@ -50,67 +50,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var gameFormat_1 = require("../format/gameFormat");
54
- var fetchData_1 = __importDefault(require("./fetchData"));
55
- function getMonthlyLeaderboard(game, options) {
56
- var _a, _b, _c, _d;
53
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
54
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
55
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
56
+ var processors_1 = __importDefault(require("../processors"));
57
+ function getMonthlyLeaderboard(game_id, options) {
57
58
  return __awaiter(this, void 0, void 0, function () {
58
- var _e, data, error, gameData, err_1, year, month, amount, skip, _f, data, error, gameData, err_2;
59
- return __generator(this, function (_g) {
60
- switch (_g.label) {
59
+ var current_date, endpoint, response, response_data, processors;
60
+ var _a, _b, _c, _d;
61
+ return __generator(this, function (_e) {
62
+ switch (_e.label) {
61
63
  case 0:
62
- if (!(!(options === null || options === void 0 ? void 0 : options.year) &&
63
- !(options === null || options === void 0 ? void 0 : options.amount) &&
64
- !(options === null || options === void 0 ? void 0 : options.month) &&
65
- !(options === null || options === void 0 ? void 0 : options.skip) &&
66
- !(options === null || options === void 0 ? void 0 : options.date))) return [3 /*break*/, 5];
67
- _g.label = 1;
68
- case 1:
69
- _g.trys.push([1, 3, , 4]);
70
- return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
71
- case 2:
72
- _e = _g.sent(), data = _e.data, error = _e.error;
73
- if (error || !data)
64
+ if (!(0, isGame_1.default)(game_id))
74
65
  return [2 /*return*/, {
66
+ status: 404,
67
+ error: {
68
+ code: 404,
69
+ message: "Game not found.",
70
+ },
75
71
  data: null,
76
- error: __assign({ message: "Failed to fetch data." }, error),
77
72
  }];
78
- gameData = (0, gameFormat_1.gameFormatArray)(game, data);
79
- return [2 /*return*/, { data: gameData, error: null }];
80
- case 3:
81
- err_1 = _g.sent();
82
- console.error(err_1);
83
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
84
- case 4: return [3 /*break*/, 9];
85
- case 5:
86
- year = (_a = options.year) !== null && _a !== void 0 ? _a : new Date().getFullYear();
87
- month = (_b = options.month) !== null && _b !== void 0 ? _b : new Date().getMonth() + 1;
88
- amount = (_c = options.amount) !== null && _c !== void 0 ? _c : 100;
89
- skip = (_d = options.skip) !== null && _d !== void 0 ? _d : 0;
90
- if (options.date) {
91
- year = options.date.getFullYear();
92
- month = options.date.getMonth() + 1;
93
- }
94
- _g.label = 6;
95
- case 6:
96
- _g.trys.push([6, 8, , 9]);
97
- return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/".concat(game, "/").concat(year, "/").concat(month, "/").concat(amount, "/").concat(skip), options === null || options === void 0 ? void 0 : options.fetch)];
98
- case 7:
99
- _f = _g.sent(), data = _f.data, error = _f.error;
100
- if (error || !data)
101
- return [2 /*return*/, {
102
- data: null,
103
- error: __assign({ message: "Failed to fetch data." }, error),
104
- }];
105
- if (!Array.isArray(data))
106
- data = Object.values(data);
107
- gameData = (0, gameFormat_1.gameFormatArray)(game, data);
108
- return [2 /*return*/, { data: gameData, error: null }];
109
- case 8:
110
- err_2 = _g.sent();
111
- console.error(err_2);
112
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
113
- case 9: return [2 /*return*/];
73
+ current_date = new Date();
74
+ endpoint = "/game/monthly/".concat(game_id, "/").concat((_a = options === null || options === void 0 ? void 0 : options.year) !== null && _a !== void 0 ? _a : current_date.getFullYear(), "/").concat((_b = options === null || options === void 0 ? void 0 : options.month) !== null && _b !== void 0 ? _b : current_date.getMonth() + 1, "/").concat((_c = options === null || options === void 0 ? void 0 : options.amount) !== null && _c !== void 0 ? _c : 100, "/").concat((_d = options === null || options === void 0 ? void 0 : options.skip) !== null && _d !== void 0 ? _d : 0);
75
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)(endpoint, options === null || options === void 0 ? void 0 : options.init)];
76
+ case 1:
77
+ response = _e.sent();
78
+ if (response.error)
79
+ return [2 /*return*/, response];
80
+ response_data = Object.values(response.data);
81
+ processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.Monthly);
82
+ response_data.forEach(function (statistics) {
83
+ return processors.forEach(function (processor) { return processor(statistics); });
84
+ });
85
+ return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
114
86
  }
115
87
  });
116
88
  });
@@ -0,0 +1,10 @@
1
+ import { Game, Timeframe } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ import { AllGameStatistics, StatisticsResponse } from "../types/output";
4
+ interface MonthlyOptions extends Options {
5
+ month: number;
6
+ year: number;
7
+ }
8
+ export default function getMonthlyStatistics(identifier: string, options?: MonthlyOptions): Promise<APIResponse<AllGameStatistics<Timeframe.Monthly>>>;
9
+ export default function getMonthlyStatistics<G extends Game>(identifier: string, game_id: G, options?: MonthlyOptions): Promise<APIResponse<StatisticsResponse<G, Timeframe.Monthly>>>;
10
+ export {};
@@ -0,0 +1,154 @@
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;
24
+ return g = { next: verb(0), "throw": verb(1), "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 __values = (this && this.__values) || function(o) {
50
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
+ if (m) return m.call(o);
52
+ if (o && typeof o.length === "number") return {
53
+ next: function () {
54
+ if (o && i >= o.length) o = void 0;
55
+ return { value: o && o[i++], done: !o };
56
+ }
57
+ };
58
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
+ };
60
+ var __read = (this && this.__read) || function (o, n) {
61
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
62
+ if (!m) return o;
63
+ var i = m.call(o), r, ar = [], e;
64
+ try {
65
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
+ }
67
+ catch (error) { e = { error: error }; }
68
+ finally {
69
+ try {
70
+ if (r && !r.done && (m = i["return"])) m.call(i);
71
+ }
72
+ finally { if (e) throw e.error; }
73
+ }
74
+ return ar;
75
+ };
76
+ var __importDefault = (this && this.__importDefault) || function (mod) {
77
+ return (mod && mod.__esModule) ? mod : { "default": mod };
78
+ };
79
+ Object.defineProperty(exports, "__esModule", { value: true });
80
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
81
+ var isGame_1 = __importDefault(require("../helpers/isGame"));
82
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
83
+ var processors_1 = __importDefault(require("../processors"));
84
+ function getMonthlyStatistics(identifier, game_or_options, options) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var game_id, method_options, current_date, endpoint, response, games, output, _loop_1, games_1, games_1_1, _a, g, stats, response_data, processors;
87
+ var e_1, _b;
88
+ var _c, _d;
89
+ return __generator(this, function (_e) {
90
+ switch (_e.label) {
91
+ case 0:
92
+ game_id = "all";
93
+ method_options = game_or_options;
94
+ if (typeof game_or_options === "string") {
95
+ game_id = game_or_options;
96
+ method_options = options;
97
+ }
98
+ if (!(0, isGame_1.default)(game_id) && game_id !== "all")
99
+ return [2 /*return*/, {
100
+ status: 404,
101
+ error: {
102
+ code: 404,
103
+ message: "Game not found.",
104
+ },
105
+ data: null,
106
+ }];
107
+ current_date = new Date();
108
+ endpoint = "/game/monthly/player/".concat(game_id, "/").concat(identifier, "/").concat((_c = options === null || options === void 0 ? void 0 : options.year) !== null && _c !== void 0 ? _c : current_date.getFullYear(), "/").concat((_d = options === null || options === void 0 ? void 0 : options.month) !== null && _d !== void 0 ? _d : current_date.getMonth() + 1);
109
+ return [4 /*yield*/, (0, fetchEndpoint_1.default)(endpoint, method_options === null || method_options === void 0 ? void 0 : method_options.init)];
110
+ case 1:
111
+ response = _e.sent();
112
+ if (response.error)
113
+ return [2 /*return*/, response];
114
+ if (game_id === "all") {
115
+ games = Object.entries(response.data);
116
+ output = {};
117
+ _loop_1 = function (g, stats) {
118
+ if ((0, isGame_1.default)(g)) {
119
+ if (Array.isArray(stats) ||
120
+ typeof stats.played === "undefined") {
121
+ output[g] = null;
122
+ return "continue";
123
+ }
124
+ var processors_2 = (0, processors_1.default)(g, hive_bedrock_data_1.Timeframe.Monthly);
125
+ processors_2.forEach(function (processor) { return processor(stats); });
126
+ output[g] = stats;
127
+ }
128
+ };
129
+ try {
130
+ for (games_1 = __values(games), games_1_1 = games_1.next(); !games_1_1.done; games_1_1 = games_1.next()) {
131
+ _a = __read(games_1_1.value, 2), g = _a[0], stats = _a[1];
132
+ _loop_1(g, stats);
133
+ }
134
+ }
135
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
136
+ finally {
137
+ try {
138
+ if (games_1_1 && !games_1_1.done && (_b = games_1.return)) _b.call(games_1);
139
+ }
140
+ finally { if (e_1) throw e_1.error; }
141
+ }
142
+ return [2 /*return*/, __assign(__assign({}, response), { data: output })];
143
+ }
144
+ response_data = response.data;
145
+ if (Array.isArray(response_data))
146
+ return [2 /*return*/, __assign(__assign({}, response), { status: 404, data: null, error: { code: 404, message: "Not Found" } })];
147
+ processors = (0, processors_1.default)(game_id, hive_bedrock_data_1.Timeframe.Monthly);
148
+ processors.forEach(function (processor) { return processor(response_data); });
149
+ return [2 /*return*/, __assign(__assign({}, response), { data: response_data, error: null })];
150
+ }
151
+ });
152
+ });
153
+ }
154
+ exports.default = getMonthlyStatistics;
@@ -0,0 +1,3 @@
1
+ import { PlayerMetadata } from "hive-bedrock-data";
2
+ import { APIResponse, Options } from "../types/types";
3
+ export default function getPlayerInfomation(identifier: string, options?: Options): Promise<APIResponse<PlayerMetadata>>;
@@ -50,30 +50,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var fetchData_1 = __importDefault(require("./fetchData"));
54
- function getGameMetadata(game, options) {
53
+ var fetchEndpoint_1 = __importDefault(require("../helpers/fetchEndpoint"));
54
+ var processors_1 = require("../processors");
55
+ function getPlayerInfomation(identifier, options) {
55
56
  return __awaiter(this, void 0, void 0, function () {
56
- var _a, data, error, err_1;
57
- return __generator(this, function (_b) {
58
- switch (_b.label) {
59
- case 0:
60
- _b.trys.push([0, 2, , 3]);
61
- return [4 /*yield*/, (0, fetchData_1.default)("/game/meta/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
57
+ var response, player, processors;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0: return [4 /*yield*/, (0, fetchEndpoint_1.default)("/game/all/main/".concat(identifier), options === null || options === void 0 ? void 0 : options.init)];
62
61
  case 1:
63
- _a = _b.sent(), data = _a.data, error = _a.error;
64
- if (error || !data)
65
- return [2 /*return*/, {
66
- data: null,
67
- error: __assign({ message: "Failed to fetch data." }, error),
68
- }];
69
- return [2 /*return*/, { data: data, error: null }];
70
- case 2:
71
- err_1 = _b.sent();
72
- console.error(err_1);
73
- return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
74
- case 3: return [2 /*return*/];
62
+ response = _a.sent();
63
+ if (response.error)
64
+ return [2 /*return*/, response];
65
+ player = response.data.main;
66
+ processors = (0, processors_1.getPlayerProcessors)();
67
+ processors.forEach(function (processor) { return processor(player); });
68
+ return [2 /*return*/, __assign(__assign({}, response), { data: player })];
75
69
  }
76
70
  });
77
71
  });
78
72
  }
79
- exports.default = getGameMetadata;
73
+ exports.default = getPlayerInfomation;
@@ -0,0 +1,7 @@
1
+ import { Game, Timeframe } from "hive-bedrock-data";
2
+ export default function getProcessors(game: Game, timeframe: Timeframe): ((stats: {
3
+ [key: string]: any;
4
+ }) => void)[];
5
+ export declare function getPlayerProcessors(): ((player: {
6
+ [key: string]: any;
7
+ }) => void)[];
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getPlayerProcessors = void 0;
23
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
24
+ var toPoint_1 = __importDefault(require("../helpers/toPoint"));
25
+ function getProcessors(game, timeframe) {
26
+ return [
27
+ // Append game id
28
+ function (s) { return (s.id = game); },
29
+ // Fix inconsistant bridge keys
30
+ function (s) {
31
+ return game === hive_bedrock_data_1.Game.TheBridge && timeframe === hive_bedrock_data_1.Timeframe.Monthly
32
+ ? Object.keys(s)
33
+ .filter(function (key) { return key.startsWith("m_solo_"); })
34
+ .forEach(function (key) {
35
+ s[key.replace(/m_solo_/, "")] = s[key];
36
+ delete s[key];
37
+ })
38
+ : null;
39
+ },
40
+ // Calculate current level
41
+ function (s) {
42
+ var _a;
43
+ return "xp" in s && timeframe === hive_bedrock_data_1.Timeframe.AllTime
44
+ ? (s.level = (_a = (0, hive_bedrock_data_1.calculateLevelFromXP)(s.xp, game)) !== null && _a !== void 0 ? _a : 0)
45
+ : null;
46
+ },
47
+ // Calculate kill/death ratio
48
+ function (s) {
49
+ var _a, _b;
50
+ return "kills" in s && "deaths" in s
51
+ ? (s.kdr = (0, toPoint_1.default)(((_a = s.kills) !== null && _a !== void 0 ? _a : 0) / ((_b = s.deaths) !== null && _b !== void 0 ? _b : 0), 2))
52
+ : null;
53
+ },
54
+ // Calculate kill/death ratio - hide
55
+ function (s) {
56
+ var _a, _b;
57
+ return "hider_kills" in s && "deaths" in s
58
+ ? (s.kdr = (0, toPoint_1.default)(((_a = s.hider_kills) !== null && _a !== void 0 ? _a : 0) / ((_b = s.deaths) !== null && _b !== void 0 ? _b : 0), 2))
59
+ : null;
60
+ },
61
+ // Calculate kill/death ratio - murder
62
+ function (s) {
63
+ var _a, _b;
64
+ return "murders" in s && "deaths" in s
65
+ ? (s.kdr = (0, toPoint_1.default)(((_a = s.murders) !== null && _a !== void 0 ? _a : 0) / ((_b = s.deaths) !== null && _b !== void 0 ? _b : 0), 2))
66
+ : null;
67
+ },
68
+ // Total ratings for build
69
+ function (s) {
70
+ return game === hive_bedrock_data_1.Game.JustBuild
71
+ ? Object.keys(s)
72
+ .filter(function (key) { return key.startsWith("rating_"); })
73
+ .forEach(function (key) {
74
+ var _a;
75
+ return (s.total_ratings =
76
+ ((_a = s.total_ratings) !== null && _a !== void 0 ? _a : 0) + s[key]);
77
+ })
78
+ : null;
79
+ },
80
+ // Append losses
81
+ function (s) {
82
+ return "played" in s && "victories" in s
83
+ ? (s.losses = s.played - s.victories)
84
+ : null;
85
+ },
86
+ // Calculate win percentage
87
+ function (s) {
88
+ return "played" in s && "victories" in s
89
+ ? (s.win_percentage = s.played > 0 ? s.victories / s.played : 0)
90
+ : null;
91
+ },
92
+ // Remove NaN
93
+ function (s) {
94
+ return Object.entries(s).forEach(function (_a) {
95
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
96
+ return isNaN(value) && typeof value === "number" ? delete s[key] : null;
97
+ });
98
+ },
99
+ ];
100
+ }
101
+ exports.default = getProcessors;
102
+ function getPlayerProcessors() {
103
+ return [
104
+ function (p) { var _a; return ((_a = p.daily_login_streak) !== null && _a !== void 0 ? _a : (p.daily_login_streak = 0)); },
105
+ function (p) { var _a; return ((_a = p.longest_daily_login_streak) !== null && _a !== void 0 ? _a : (p.longest_daily_login_streak = 0)); },
106
+ function (p) { var _a; return ((_a = p.quest_count) !== null && _a !== void 0 ? _a : (p.quest_count = 0)); },
107
+ function (p) { var _a; return ((_a = p.friend_count) !== null && _a !== void 0 ? _a : (p.friend_count = 0)); },
108
+ function (p) { var _a; return ((_a = p.hub_title_unlocked) !== null && _a !== void 0 ? _a : (p.hub_title_unlocked = [])); },
109
+ function (p) { var _a; return ((_a = p.avatar_unlocked) !== null && _a !== void 0 ? _a : (p.avatar_unlocked = [])); },
110
+ function (p) { var _a; return ((_a = p.costume_unlocked) !== null && _a !== void 0 ? _a : (p.costume_unlocked = [])); },
111
+ function (p) { var _a; return ((_a = p.equipped_hub_title) !== null && _a !== void 0 ? _a : (p.equipped_hub_title = null)); },
112
+ function (p) { var _a; return ((_a = p.equipped_avatar) !== null && _a !== void 0 ? _a : (p.equipped_avatar = null)); },
113
+ function (p) { var _a; return ((_a = p.equipped_costume) !== null && _a !== void 0 ? _a : (p.equipped_costume = null)); },
114
+ ];
115
+ }
116
+ exports.getPlayerProcessors = getPlayerProcessors;