hive-bedrock-api 1.0.2 → 1.0.4

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/README.md CHANGED
@@ -31,10 +31,7 @@ import { getAllTimeStats, GAME } from "hive-bedrock-api";
31
31
  const { data, player, error } = await getAllTimeStats("ucdfiddes");
32
32
 
33
33
  // Returns multiple specific games
34
- const { data, player, error } = await getAllTimeStats("ucdfiddes", [
35
- GAME.Deathrun,
36
- GAME.TheBridge,
37
- ]);
34
+ const { data, player, error } = await getAllTimeStats("ucdfiddes", [GAME.Deathrun, GAME.TheBridge]);
38
35
 
39
36
  // Returns a single game
40
37
  const { data, error } = await getAllTimeStats("ucdfiddes", GAME.HideAndSeek);
@@ -49,25 +46,22 @@ import { getMonthlyStats, GAME } from "hive-bedrock-api";
49
46
  const { data, error } = await getMonthlyStats("ucdfiddes");
50
47
 
51
48
  // Returns multiple specific games
52
- const { data, error } = await getMonthlyStats("ucdfiddes", [
53
- GAME.Deathrun,
54
- GAME.TheBridge,
55
- ]);
49
+ const { data, error } = await getMonthlyStats("ucdfiddes", [GAME.Deathrun, GAME.TheBridge]);
56
50
 
57
51
  // Returns a single game
58
52
  const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop);
59
53
 
60
54
  // Returns a single game in a previous month (can return muliple games)
61
55
  const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
62
- year: 2023,
63
- month: 1, // January
56
+ year: 2023,
57
+ month: 1, // January
64
58
  });
65
59
 
66
60
  // Same as before, but with a Date object
67
61
  const previousMonth = new Date();
68
62
  previousMonth.setMonth(0); // January
69
63
  const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
70
- date: previousMonth,
64
+ date: previousMonth,
71
65
  });
72
66
  ```
73
67
 
@@ -90,10 +84,10 @@ const { data, error } = await getMonthlyLeaderboard(GAME.TreasureWars);
90
84
 
91
85
  // Returns a single game from a previous month
92
86
  const { data, error } = await getMonthlyLeaderboard(GAME.BlockParty, {
93
- year: 2023,
94
- month: 11, // November
95
- amount: 50,
96
- skip: 20, // Sum of skip and amount must be <=100
87
+ year: 2023,
88
+ month: 11, // November
89
+ amount: 50,
90
+ skip: 20, // Sum of skip and amount must be <=100
97
91
  });
98
92
  ```
99
93
 
@@ -106,14 +100,23 @@ import { getGlobalStatistics } from "hive-bedrock-api";
106
100
  const { data, error } = await getGlobalStatistics();
107
101
  ```
108
102
 
103
+ ### Fetch Maps
104
+
105
+ ```ts
106
+ import { getMaps, GAME } from "hive-bedrock-api";
107
+
108
+ // Returns data for a specific game's currently active maps
109
+ const { data, error } = await getMaps(GAME.TreasureWars);
110
+ ```
111
+
109
112
  ## API Response Changes
110
113
 
111
114
  Different API responses are edited by the wrapper to provide more data:
112
115
 
113
- - Game responses have a new value "id" showing the parent game
114
- - "first_played" values are converted into a Date object
115
- - A new value for "losses" is provided
116
- - A new value for "kdr" is provided
117
- - "xp" is converted and a "level" is provided
116
+ - Game responses have a new value "id" showing the parent game
117
+ - "first_played" values are converted into a Date object
118
+ - A new value for "losses" is provided
119
+ - A new value for "kdr" is provided
120
+ - "xp" is converted and a "level" is provided
118
121
 
119
122
  See [API.md](docs/API.md#game-statistics-types) for specific fields and their corresponding types per game.
package/lib/index.d.ts CHANGED
@@ -4,7 +4,8 @@ import getAllTimeStats from "./methods/getAllTimeStats";
4
4
  import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
5
5
  import getGlobalStatistics from "./methods/getGlobalStatistics";
6
6
  import getPlayerInfo from "./methods/getPlayerInfo";
7
- import { AVATAR, RANK } from "./types/API";
8
- export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, getPlayerInfo, AVATAR, RANK, };
7
+ import getMaps from "./methods/getMaps";
8
+ 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, };
9
10
  export * from "./types/GAME_INFO";
10
11
  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.getPlayerInfo = exports.getGlobalStatistics = exports.getMonthlyLeaderboard = exports.getMonthlyStats = exports.getAllTimeLeaderboard = exports.getAllTimeStats = void 0;
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;
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"));
@@ -30,5 +30,11 @@ var getGlobalStatistics_1 = __importDefault(require("./methods/getGlobalStatisti
30
30
  exports.getGlobalStatistics = getGlobalStatistics_1.default;
31
31
  var getPlayerInfo_1 = __importDefault(require("./methods/getPlayerInfo"));
32
32
  exports.getPlayerInfo = getPlayerInfo_1.default;
33
+ var getMaps_1 = __importDefault(require("./methods/getMaps"));
34
+ exports.getMaps = getMaps_1.default;
35
+ var API_1 = require("./types/API");
36
+ Object.defineProperty(exports, "RANK", { enumerable: true, get: function () { return API_1.RANK; } });
37
+ Object.defineProperty(exports, "MAP_SEASON", { enumerable: true, get: function () { return API_1.MAP_SEASON; } });
38
+ Object.defineProperty(exports, "MAP_VARIANT", { enumerable: true, get: function () { return API_1.MAP_VARIANT; } });
33
39
  __exportStar(require("./types/GAME_INFO"), exports);
34
40
  __exportStar(require("./types/GAMES"), exports);
@@ -1,5 +1,5 @@
1
- import { API_BASE_GAME_ALL, API_BASE_GAME_MONTHLY, API_GAME_STATS, API_GLOBAL_STATISTICS, API_REQUEST_ALL, API_REQUEST_LB } from "../types/API";
2
- import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MONTHLY_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_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";
3
3
  import { USER_MAIN } from "../types/GAMES";
4
4
  import { GAME } from "../types/GAME_INFO";
5
5
  import { MethodResponse } from "../types/METHODS";
@@ -21,3 +21,4 @@ export default function fetchData<G extends GAME>(endpoint: GAME_LB_MONTHLY_ENDP
21
21
  export default function fetchData<G extends GAME>(endpoint: PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
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
+ export default function fetchData<G extends GAME>(endpoint: GAME_MAPS_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_MAP[]>>;
@@ -2,7 +2,7 @@ import { Options } from "../types/API";
2
2
  import { BASE_GAME_ALL, GAME_STATS, GAME_STATS_ALL, REQUEST_ALL, USER_MAIN } from "../types/GAMES";
3
3
  import { GAME } from "../types/GAME_INFO";
4
4
  import { MethodResponse } from "../types/METHODS";
5
- export default function getAllTimeStats(playerIdentifier: string, options?: Options): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
5
+ export default function getAllTimeStats(playerIdentifier: string): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
6
6
  player: USER_MAIN;
7
7
  }>;
8
8
  export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G, options?: Options): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
@@ -0,0 +1,4 @@
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[]>>;
@@ -0,0 +1,101 @@
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 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
+ ];
67
+ function getMaps(game, options) {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var _a, data, error, err_1;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
72
+ case 0:
73
+ if (!VALID_GAMES.includes(game))
74
+ return [2 /*return*/, {
75
+ data: null,
76
+ error: {
77
+ message: "This game does not support this endpoint as it only has one map.",
78
+ },
79
+ }];
80
+ _b.label = 1;
81
+ case 1:
82
+ _b.trys.push([1, 3, , 4]);
83
+ return [4 /*yield*/, (0, fetchData_1.default)("/game/map/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
84
+ case 2:
85
+ _a = _b.sent(), data = _a.data, error = _a.error;
86
+ if (error || !data)
87
+ return [2 /*return*/, {
88
+ data: null,
89
+ error: __assign({ message: "Failed to fetch data." }, error),
90
+ }];
91
+ return [2 /*return*/, { data: data, error: null }];
92
+ case 3:
93
+ err_1 = _b.sent();
94
+ console.error(err_1);
95
+ return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
96
+ case 4: return [2 /*return*/];
97
+ }
98
+ });
99
+ });
100
+ }
101
+ exports.default = getMaps;
@@ -14,7 +14,36 @@ export interface API_ERROR {
14
14
  export interface Options {
15
15
  fetch?: FetchOptions;
16
16
  }
17
- export type RANK = "REGULAR" | "PLUS" | "YOUTUBER" | "STREAMER" | "TIKTOK" | "VIP" | "HELPER" | "MODERATOR" | "HIVE_TEAM" | "STAFF_MANAGER" | "COMMUNITY_MANAGER" | "OWNER";
17
+ export declare enum MAP_SEASON {
18
+ None = "NO_SEASON",
19
+ Winter = "WINTERFEST",
20
+ Spring = "SPRING",
21
+ Summer = "SUMMER",
22
+ Halloween = "HALLOWEEN",
23
+ Autumn = "AUTUMN"
24
+ }
25
+ export declare enum MAP_VARIANT {
26
+ Regular = "REGULAR",
27
+ Duos = "DUOS",
28
+ Trios = "TRIOS",
29
+ Squads = "SQUADS",
30
+ Mega = "MEGA",
31
+ Royale = "ROYALE"
32
+ }
33
+ export declare enum RANK {
34
+ Regular = "REGULAR",
35
+ Plus = "PLUS",
36
+ Youtuber = "YOUTUBER",
37
+ Streamer = "STREAMER",
38
+ Tiktok = "TIKTOK",
39
+ VIP = "VIP",
40
+ Helper = "HELPER",
41
+ Moderator = "MODERATOR",
42
+ Hive = "HIVE_TEAM",
43
+ StaffManager = "STAFF_MANAGER",
44
+ CommunityManager = "COMMUNITY_MANAGER",
45
+ Owner = "OWNER"
46
+ }
18
47
  export type API_REQUEST_ALL = {
19
48
  [G in GAME]: API_GAME_STATS_ALL<G>;
20
49
  } & {
@@ -53,6 +82,12 @@ export interface API_GLOBAL_STATISTICS {
53
82
  main: number;
54
83
  };
55
84
  }
85
+ export interface API_MAP {
86
+ name: string;
87
+ season: MAP_SEASON;
88
+ variant: MAP_VARIANT;
89
+ image: string;
90
+ }
56
91
  export interface API_BASE_GAME_ALL {
57
92
  UUID: string;
58
93
  xp: number;
@@ -93,6 +128,9 @@ export interface API_USER_MAIN {
93
128
  equipped_avatar: AVATAR | null;
94
129
  quest_count: number;
95
130
  paid_ranks: RANK[];
131
+ pets: string[];
132
+ mounts: string[];
133
+ hats: string[];
96
134
  }
97
135
  export interface API_GAME_HIDE {
98
136
  deaths: number;
package/lib/types/API.js CHANGED
@@ -1,3 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RANK = exports.MAP_VARIANT = exports.MAP_SEASON = void 0;
3
4
  var GAME_INFO_1 = require("./GAME_INFO");
5
+ var MAP_SEASON;
6
+ (function (MAP_SEASON) {
7
+ MAP_SEASON["None"] = "NO_SEASON";
8
+ MAP_SEASON["Winter"] = "WINTERFEST";
9
+ MAP_SEASON["Spring"] = "SPRING";
10
+ MAP_SEASON["Summer"] = "SUMMER";
11
+ MAP_SEASON["Halloween"] = "HALLOWEEN";
12
+ MAP_SEASON["Autumn"] = "AUTUMN";
13
+ })(MAP_SEASON || (exports.MAP_SEASON = MAP_SEASON = {}));
14
+ var MAP_VARIANT;
15
+ (function (MAP_VARIANT) {
16
+ MAP_VARIANT["Regular"] = "REGULAR";
17
+ MAP_VARIANT["Duos"] = "DUOS";
18
+ MAP_VARIANT["Trios"] = "TRIOS";
19
+ MAP_VARIANT["Squads"] = "SQUADS";
20
+ MAP_VARIANT["Mega"] = "MEGA";
21
+ MAP_VARIANT["Royale"] = "ROYALE";
22
+ })(MAP_VARIANT || (exports.MAP_VARIANT = MAP_VARIANT = {}));
23
+ var RANK;
24
+ (function (RANK) {
25
+ RANK["Regular"] = "REGULAR";
26
+ RANK["Plus"] = "PLUS";
27
+ RANK["Youtuber"] = "YOUTUBER";
28
+ RANK["Streamer"] = "STREAMER";
29
+ RANK["Tiktok"] = "TIKTOK";
30
+ RANK["VIP"] = "VIP";
31
+ RANK["Helper"] = "HELPER";
32
+ RANK["Moderator"] = "MODERATOR";
33
+ RANK["Hive"] = "HIVE_TEAM";
34
+ RANK["StaffManager"] = "STAFF_MANAGER";
35
+ RANK["CommunityManager"] = "COMMUNITY_MANAGER";
36
+ RANK["Owner"] = "OWNER";
37
+ })(RANK || (exports.RANK = RANK = {}));
@@ -6,4 +6,5 @@ export type GAME_LB_MONTHLY_ENDPOINT<G extends GAME> = `/game/monthly/${G}`;
6
6
  export type PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G extends GAME, ID extends string, Y extends number, M extends number, A extends number, S extends number> = `/game/monthly/player/${G}/${ID}/${Y}/${M}/${A}/${S}`;
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
- 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;
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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",