hive-bedrock-api 0.1.0-beta.3 → 0.1.0-beta.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
@@ -11,6 +11,15 @@ $ yarn add hive-bedrock-api
11
11
 
12
12
  ## Usage
13
13
 
14
+ ### Fetch Player Infomation
15
+
16
+ ```ts
17
+ import { getPlayerInfo } from "hive-bedrock-api";
18
+
19
+ // Returns player, cosmetics, server statistics and profile infomation
20
+ const { data, error } = await getPlayerInfo("ucdfiddes");
21
+ ```
22
+
14
23
  ### Fetch All-Time Player Statistics
15
24
 
16
25
  ```ts
package/lib/index.d.ts CHANGED
@@ -3,7 +3,8 @@ import getMonthlyLeaderboard from "./methods/getMonthlyLeaderboard";
3
3
  import getAllTimeStats from "./methods/getAllTimeStats";
4
4
  import getAllTimeLeaderboard from "./methods/getAllTimeLeaderboard";
5
5
  import getGlobalStatistics from "./methods/getGlobalStatistics";
6
+ import getPlayerInfo from "./methods/getPlayerInfo";
6
7
  import { AVATAR, RANK } from "./types/API";
7
- export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, AVATAR, RANK, };
8
+ export { getAllTimeStats, getAllTimeLeaderboard, getMonthlyStats, getMonthlyLeaderboard, getGlobalStatistics, getPlayerInfo, AVATAR, RANK, };
8
9
  export * from "./types/GAME_INFO";
9
10
  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.getGlobalStatistics = exports.getMonthlyLeaderboard = exports.getMonthlyStats = exports.getAllTimeLeaderboard = exports.getAllTimeStats = void 0;
20
+ 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"));
@@ -28,5 +28,7 @@ var getAllTimeLeaderboard_1 = __importDefault(require("./methods/getAllTimeLeade
28
28
  exports.getAllTimeLeaderboard = getAllTimeLeaderboard_1.default;
29
29
  var getGlobalStatistics_1 = __importDefault(require("./methods/getGlobalStatistics"));
30
30
  exports.getGlobalStatistics = getGlobalStatistics_1.default;
31
+ var getPlayerInfo_1 = __importDefault(require("./methods/getPlayerInfo"));
32
+ exports.getPlayerInfo = getPlayerInfo_1.default;
31
33
  __exportStar(require("./types/GAME_INFO"), exports);
32
34
  __exportStar(require("./types/GAMES"), exports);
@@ -1,9 +1,13 @@
1
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
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";
3
+ import { USER_MAIN } from "../types/GAMES";
3
4
  import { GAME } from "../types/GAME_INFO";
4
5
  import { MethodResponse } from "../types/METHODS";
5
6
  export declare const API_ROOT = "https://api.playhive.com/v0";
6
7
  export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"all", string>): Promise<MethodResponse<API_REQUEST_ALL>>;
8
+ export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"main", string>): Promise<MethodResponse<{
9
+ main: USER_MAIN;
10
+ }>>;
7
11
  export default function fetchData<G extends GAME>(endpoint: PLAYER_ALLTIME_ENDPOINT<G, string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_ALL>[G]>>;
8
12
  export default function fetchData(endpoint: PLAYER_MONTHLY_ENDPOINT<"all", string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>>>;
9
13
  export default function fetchData<G extends GAME>(endpoint: PLAYER_MONTHLY_ENDPOINT<G, string>): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>[G]>>;
@@ -1,7 +1,7 @@
1
1
  import { BASE_GAME_ALL, GAME_STATS, GAME_STATS_ALL, REQUEST_ALL, USER_MAIN } from "../types/GAMES";
2
2
  import { GAME } from "../types/GAME_INFO";
3
3
  import { MethodResponse } from "../types/METHODS";
4
- export default function getAllTimeStats(playerIndentifier: string): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
4
+ export default function getAllTimeStats(playerIdentifier: string): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
5
5
  player: USER_MAIN;
6
6
  }>;
7
7
  export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
@@ -1,7 +1,7 @@
1
1
  import { BASE_GAME_MONTHLY, GAME_STATS, GAME_STATS_ALL, REQUEST_MONTHLY } from "../types/GAMES";
2
2
  import { GAME } from "../types/GAME_INFO";
3
3
  import { MethodResponse } from "../types/METHODS";
4
- export default function getMonthlyStats(playerIndentifier: string): Promise<MethodResponse<Omit<REQUEST_MONTHLY, "main">>>;
4
+ export default function getMonthlyStats(playerIdentifier: string): Promise<MethodResponse<Omit<REQUEST_MONTHLY, "main">>>;
5
5
  export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_MONTHLY>[G]>>;
6
6
  export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G, options: {
7
7
  year?: number;
@@ -0,0 +1,3 @@
1
+ import { USER_MAIN } from "../types/GAMES";
2
+ import { MethodResponse } from "../types/METHODS";
3
+ export default function getPlayerInfo(playerIdentifier: string): Promise<MethodResponse<USER_MAIN>>;
@@ -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 getPlayerInfo(playerIdentifier) {
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/all/main/".concat(playerIdentifier))];
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.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*/];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.default = getPlayerInfo;
@@ -1,5 +1,5 @@
1
1
  import { GAME } from "./GAME_INFO";
2
- export type PLAYER_ALLTIME_ENDPOINT<G extends GAME | "all", ID extends string> = `/game/all/${G}/${ID}`;
2
+ export type PLAYER_ALLTIME_ENDPOINT<G extends GAME | "all" | "main", ID extends string> = `/game/all/${G}/${ID}`;
3
3
  export type PLAYER_MONTHLY_ENDPOINT<G extends GAME | "all", ID extends string> = `/game/monthly/player/${G}/${ID}`;
4
4
  export type GAME_LB_ALLTIME_ENDPOINT<G extends GAME> = `/game/all/${G}`;
5
5
  export type GAME_LB_MONTHLY_ENDPOINT<G extends GAME> = `/game/monthly/${G}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.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",