hive-bedrock-api 1.0.6 → 1.0.8

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.
@@ -36,8 +36,6 @@ var calculateLevel_1 = __importDefault(require("../methods/calculateLevel"));
36
36
  var GAME_INFO_1 = require("../types/GAME_INFO");
37
37
  exports.formats = (_a = {
38
38
  main: function (player) {
39
- if ("first_played" in player)
40
- player.first_played = new Date(player.first_played * 1000);
41
39
  return player;
42
40
  },
43
41
  default: function (gameType, game) {
@@ -53,8 +51,6 @@ exports.formats = (_a = {
53
51
  else
54
52
  return null;
55
53
  }
56
- if ("first_played" in game)
57
- game.first_played = new Date(game.first_played * 1000);
58
54
  if ("played" in game && "victories" in game) {
59
55
  game.losses = ((_a = game.played) !== null && _a !== void 0 ? _a : 0) - ((_b = game.victories) !== null && _b !== void 0 ? _b : 0);
60
56
  game.win_percentage = game.victories / game.played;
package/lib/index.d.ts CHANGED
@@ -5,7 +5,8 @@ import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
5
5
  import getGlobalStatistics from "./methods/getGlobalStatistics";
6
6
  import getPlayerInfo from "./methods/getPlayerInfo";
7
7
  import getMaps from "./methods/getMaps";
8
+ import getGameMetadata from "./methods/getGameMetadata";
8
9
  import { AVATAR, RANK, MAP_SEASON, MAP_VARIANT } from "./types/API";
9
- export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, getPlayerInfo, getMaps, AVATAR, RANK, MAP_SEASON, MAP_VARIANT, };
10
+ export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, getPlayerInfo, getMaps, getGameMetadata, AVATAR, RANK, MAP_SEASON, MAP_VARIANT, };
10
11
  export * from "./types/GAME_INFO";
11
12
  export * from "./types/GAMES";
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MAP_VARIANT = exports.MAP_SEASON = exports.RANK = exports.getMaps = exports.getPlayerInfo = exports.getGlobalStatistics = exports.getMonthlyLeaderboard = exports.getMonthlyStats = exports.getAllTimeLeaderboard = exports.getAllTimeStats = void 0;
20
+ exports.MAP_VARIANT = exports.MAP_SEASON = exports.RANK = exports.getGameMetadata = exports.getMaps = exports.getPlayerInfo = exports.getGlobalStatistics = exports.getMonthlyLeaderboard = exports.getMonthlyStats = exports.getAllTimeLeaderboard = exports.getAllTimeStats = void 0;
21
21
  var getMonthlyStats_1 = __importDefault(require("./methods/getMonthlyStats"));
22
22
  exports.getMonthlyStats = getMonthlyStats_1.default;
23
23
  var getMonthlyLeaderboard_1 = __importDefault(require("./methods/getMonthlyLeaderboard"));
@@ -32,6 +32,8 @@ var getPlayerInfo_1 = __importDefault(require("./methods/getPlayerInfo"));
32
32
  exports.getPlayerInfo = getPlayerInfo_1.default;
33
33
  var getMaps_1 = __importDefault(require("./methods/getMaps"));
34
34
  exports.getMaps = getMaps_1.default;
35
+ var getGameMetadata_1 = __importDefault(require("./methods/getGameMetadata"));
36
+ exports.getGameMetadata = getGameMetadata_1.default;
35
37
  var API_1 = require("./types/API");
36
38
  Object.defineProperty(exports, "RANK", { enumerable: true, get: function () { return API_1.RANK; } });
37
39
  Object.defineProperty(exports, "MAP_SEASON", { enumerable: true, get: function () { return API_1.MAP_SEASON; } });
@@ -1,5 +1,5 @@
1
- import { API_BASE_GAME_ALL, API_BASE_GAME_MONTHLY, API_GAME_STATS, API_GLOBAL_STATISTICS, API_MAP, API_REQUEST_ALL, API_REQUEST_LB } from "../types/API";
2
- import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MONTHLY_ENDPOINT, GAME_MAPS_ENDPOINT, GLOBAL_STATISTICS_ENDPOINT, PLAYER_ALLTIME_ENDPOINT, PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT, PLAYER_MONTHLY_ENDPOINT } from "../types/ENDPOINTS";
1
+ import { API_BASE_GAME_ALL, API_BASE_GAME_MONTHLY, API_GAME_STATS, API_GLOBAL_STATISTICS, API_MAP, API_METADATA, API_REQUEST_ALL, API_REQUEST_LB } from "../types/API";
2
+ import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MONTHLY_ENDPOINT, GAME_MAPS_ENDPOINT, GAME_METADATA_ENDPOINT, GLOBAL_STATISTICS_ENDPOINT, PLAYER_ALLTIME_ENDPOINT, PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT, PLAYER_MONTHLY_ENDPOINT } from "../types/ENDPOINTS";
3
3
  import { USER_MAIN } from "../types/GAMES";
4
4
  import { GAME } from "../types/GAME_INFO";
5
5
  import { MethodResponse } from "../types/METHODS";
@@ -22,3 +22,4 @@ export default function fetchData<G extends GAME>(endpoint: PLAYER_LB_SPECIFIC_M
22
22
  export default function fetchData<G extends GAME>(endpoint: GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<G, number, number, number, number>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
23
23
  export default function fetchData(endpoint: GLOBAL_STATISTICS_ENDPOINT, options?: FetchOptions): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
24
24
  export default function fetchData<G extends GAME>(endpoint: GAME_MAPS_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_MAP[]>>;
25
+ export default function fetchData<G extends GAME>(endpoint: GAME_METADATA_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_METADATA>>;
@@ -0,0 +1,4 @@
1
+ import { API_METADATA, Options } from "../types/API";
2
+ import { GAME } from "../types/GAME_INFO";
3
+ import { MethodResponse } from "../types/METHODS";
4
+ export default function getGameMetadata(game: GAME, options?: Options): Promise<MethodResponse<API_METADATA>>;
@@ -0,0 +1,79 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var fetchData_1 = __importDefault(require("./fetchData"));
54
+ function getGameMetadata(game, options) {
55
+ 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)];
62
+ 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*/];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.default = getGameMetadata;
@@ -63,6 +63,7 @@ var VALID_GAMES = [
63
63
  GAME_INFO_1.GAME.Skywars,
64
64
  GAME_INFO_1.GAME.SurvivalGames,
65
65
  GAME_INFO_1.GAME.TreasureWars,
66
+ GAME_INFO_1.GAME.TheBridge,
66
67
  ];
67
68
  function getMaps(game, options) {
68
69
  return __awaiter(this, void 0, void 0, function () {
@@ -88,6 +88,16 @@ export interface API_MAP {
88
88
  variant: MAP_VARIANT;
89
89
  image: string;
90
90
  }
91
+ export interface API_METADATA {
92
+ name: string;
93
+ shortName: string;
94
+ maxLevel: number;
95
+ allowPrestiging: boolean;
96
+ maxPrestige: number;
97
+ experienceToLevel: {
98
+ [xp: string]: number;
99
+ };
100
+ }
91
101
  export interface API_BASE_GAME_ALL {
92
102
  UUID: string;
93
103
  xp: number;
@@ -7,4 +7,5 @@ export type PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G extends GAME, ID extends strin
7
7
  export type GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<G extends GAME, Y extends number, M extends number, A extends number, S extends number> = `/game/monthly/${G}/${Y}/${M}/${A}/${S}`;
8
8
  export type GLOBAL_STATISTICS_ENDPOINT = `/global/statistics`;
9
9
  export type GAME_MAPS_ENDPOINT<G extends GAME> = `/game/map/${G}`;
10
- export type ENDPOINTS<G extends GAME> = PLAYER_ALLTIME_ENDPOINT<"all", string> | PLAYER_ALLTIME_ENDPOINT<G, string> | PLAYER_MONTHLY_ENDPOINT<"all", string> | PLAYER_MONTHLY_ENDPOINT<G, string> | GAME_LB_ALLTIME_ENDPOINT<G> | GAME_LB_MONTHLY_ENDPOINT<G> | PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number> | GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<GAME, number, number, number, number> | GLOBAL_STATISTICS_ENDPOINT | GAME_MAPS_ENDPOINT<G>;
10
+ export type GAME_METADATA_ENDPOINT<G extends GAME> = `/game/meta/${G}`;
11
+ export type ENDPOINTS<G extends GAME> = PLAYER_ALLTIME_ENDPOINT<"all", string> | PLAYER_ALLTIME_ENDPOINT<G, string> | PLAYER_MONTHLY_ENDPOINT<"all", string> | PLAYER_MONTHLY_ENDPOINT<G, string> | GAME_LB_ALLTIME_ENDPOINT<G> | GAME_LB_MONTHLY_ENDPOINT<G> | PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number> | GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<GAME, number, number, number, number> | GLOBAL_STATISTICS_ENDPOINT | GAME_MAPS_ENDPOINT<G> | GAME_METADATA_ENDPOINT<G>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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",