hive-bedrock-api 0.1.0-beta.7 → 1.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.
- package/README.md +13 -2
- package/lib/format/gameFormat.js +24 -0
- package/lib/methods/fetchData.d.ts +15 -10
- package/lib/methods/fetchData.js +6 -2
- package/lib/methods/getAllTimeLeaderboard.d.ts +2 -1
- package/lib/methods/getAllTimeLeaderboard.js +2 -2
- package/lib/methods/getAllTimeStats.d.ts +4 -3
- package/lib/methods/getAllTimeStats.js +4 -4
- package/lib/methods/getGlobalStatistics.d.ts +2 -2
- package/lib/methods/getGlobalStatistics.js +2 -2
- package/lib/methods/getMonthlyLeaderboard.d.ts +6 -3
- package/lib/methods/getMonthlyLeaderboard.js +7 -3
- package/lib/methods/getMonthlyStats.d.ts +7 -4
- package/lib/methods/getMonthlyStats.js +6 -5
- package/lib/methods/getPlayerInfo.d.ts +2 -1
- package/lib/methods/getPlayerInfo.js +2 -2
- package/lib/types/API.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@ $ yarn add hive-bedrock-api
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
+
See [API.md](docs/API.md) for detailed documentation.
|
|
15
|
+
|
|
14
16
|
### Fetch Player Infomation
|
|
15
17
|
|
|
16
18
|
```ts
|
|
@@ -60,6 +62,13 @@ const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
|
|
|
60
62
|
year: 2023,
|
|
61
63
|
month: 1, // January
|
|
62
64
|
});
|
|
65
|
+
|
|
66
|
+
// Same as before, but with a Date object
|
|
67
|
+
const previousMonth = new Date();
|
|
68
|
+
previousMonth.setMonth(0); // January
|
|
69
|
+
const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
|
|
70
|
+
date: previousMonth,
|
|
71
|
+
});
|
|
63
72
|
```
|
|
64
73
|
|
|
65
74
|
### Fetch All-Time Leaderboard
|
|
@@ -67,7 +76,7 @@ const { data, error } = await getMonthlyStats("ucdfiddes", GAME.BlockDrop, {
|
|
|
67
76
|
```ts
|
|
68
77
|
import { getAllTimeLeaderboard, GAME } from "hive-bedrock-api";
|
|
69
78
|
|
|
70
|
-
// Returns
|
|
79
|
+
// Returns a single game
|
|
71
80
|
const { data, error } = await getAllTimeLeaderboard(GAME.TreasureWars);
|
|
72
81
|
```
|
|
73
82
|
|
|
@@ -76,7 +85,7 @@ const { data, error } = await getAllTimeLeaderboard(GAME.TreasureWars);
|
|
|
76
85
|
```ts
|
|
77
86
|
import { getMonthlyLeaderboard, GAME } from "hive-bedrock-api";
|
|
78
87
|
|
|
79
|
-
// Returns
|
|
88
|
+
// Returns a single game
|
|
80
89
|
const { data, error } = await getMonthlyLeaderboard(GAME.TreasureWars);
|
|
81
90
|
|
|
82
91
|
// Returns a single game from a previous month
|
|
@@ -106,3 +115,5 @@ Different API responses are edited by the wrapper to provide more data:
|
|
|
106
115
|
- A new value for "losses" is provided
|
|
107
116
|
- A new value for "kdr" is provided
|
|
108
117
|
- "xp" is converted and a "level" is provided
|
|
118
|
+
|
|
119
|
+
See [API.md](docs/API.md#game-statistics-types) for specific fields and their corresponding types per game.
|
package/lib/format/gameFormat.js
CHANGED
|
@@ -58,6 +58,8 @@ exports.formats = (_a = {
|
|
|
58
58
|
if ("played" in game && "victories" in game) {
|
|
59
59
|
game.losses = (_b = (_a = game.played) !== null && _a !== void 0 ? _a : 0 - game.victories) !== null && _b !== void 0 ? _b : 0;
|
|
60
60
|
game.win_percentage = game.victories / game.played;
|
|
61
|
+
if (isNaN(game.win_percentage))
|
|
62
|
+
game.win_percentage = 0;
|
|
61
63
|
}
|
|
62
64
|
if ("kills" in game && "deaths" in game)
|
|
63
65
|
game.kdr = parseFloat(((_d = (_c = game.kills) !== null && _c !== void 0 ? _c : 0 / game.deaths) !== null && _d !== void 0 ? _d : 0).toFixed(2));
|
|
@@ -106,6 +108,28 @@ exports.formats = (_a = {
|
|
|
106
108
|
return game;
|
|
107
109
|
},
|
|
108
110
|
_a[GAME_INFO_1.GAME.TheBridge] = function (game) {
|
|
111
|
+
if (!game)
|
|
112
|
+
return null;
|
|
113
|
+
if ("m_solo_deaths" in game) {
|
|
114
|
+
game.deaths = game.m_solo_deaths;
|
|
115
|
+
delete game.m_solo_deaths;
|
|
116
|
+
}
|
|
117
|
+
if ("m_solo_goals" in game) {
|
|
118
|
+
game.goals = game.m_solo_goals;
|
|
119
|
+
delete game.m_solo_goals;
|
|
120
|
+
}
|
|
121
|
+
if ("m_solo_kills" in game) {
|
|
122
|
+
game.kills = game.m_solo_kills;
|
|
123
|
+
delete game.m_solo_kills;
|
|
124
|
+
}
|
|
125
|
+
if ("m_solo_played" in game) {
|
|
126
|
+
game.played = game.m_solo_played;
|
|
127
|
+
delete game.m_solo_played;
|
|
128
|
+
}
|
|
129
|
+
if ("m_solo_victories" in game) {
|
|
130
|
+
game.victories = game.m_solo_victories;
|
|
131
|
+
delete game.m_solo_victories;
|
|
132
|
+
}
|
|
109
133
|
return game;
|
|
110
134
|
},
|
|
111
135
|
_a);
|
|
@@ -3,16 +3,21 @@ import { GAME_LB_ALLTIME_ENDPOINT, GAME_LB_MONTHLY_ENDPOINT, GAME_LB_SPECIFIC_MO
|
|
|
3
3
|
import { USER_MAIN } from "../types/GAMES";
|
|
4
4
|
import { GAME } from "../types/GAME_INFO";
|
|
5
5
|
import { MethodResponse } from "../types/METHODS";
|
|
6
|
+
export interface FetchOptions {
|
|
7
|
+
headers: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
export declare const API_ROOT = "https://api.playhive.com/v0";
|
|
7
|
-
export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"all", string
|
|
8
|
-
export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"main", string
|
|
12
|
+
export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"all", string>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_ALL>>;
|
|
13
|
+
export default function fetchData(endpoint: PLAYER_ALLTIME_ENDPOINT<"main", string>, options?: FetchOptions): Promise<MethodResponse<{
|
|
9
14
|
main: USER_MAIN;
|
|
10
15
|
}>>;
|
|
11
|
-
export default function fetchData<G extends GAME>(endpoint: PLAYER_ALLTIME_ENDPOINT<G, string
|
|
12
|
-
export default function fetchData(endpoint: PLAYER_MONTHLY_ENDPOINT<"all", string
|
|
13
|
-
export default function fetchData<G extends GAME>(endpoint: PLAYER_MONTHLY_ENDPOINT<G, string
|
|
14
|
-
export default function fetchData<G extends GAME>(endpoint: GAME_LB_ALLTIME_ENDPOINT<G
|
|
15
|
-
export default function fetchData<G extends GAME>(endpoint: GAME_LB_MONTHLY_ENDPOINT<G
|
|
16
|
-
export default function fetchData<G extends GAME>(endpoint: PLAYER_LB_SPECIFIC_MONTHLY_ENDPOINT<G, string, number, number, number, number
|
|
17
|
-
export default function fetchData<G extends GAME>(endpoint: GAME_LB_SPECIFIC_MONTHLY_ENDPOINT<G, number, number, number, number
|
|
18
|
-
export default function fetchData(endpoint: GLOBAL_STATISTICS_ENDPOINT): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
|
|
16
|
+
export default function fetchData<G extends GAME>(endpoint: PLAYER_ALLTIME_ENDPOINT<G, string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_ALL>[G]>>;
|
|
17
|
+
export default function fetchData(endpoint: PLAYER_MONTHLY_ENDPOINT<"all", string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>>>;
|
|
18
|
+
export default function fetchData<G extends GAME>(endpoint: PLAYER_MONTHLY_ENDPOINT<G, string>, options?: FetchOptions): Promise<MethodResponse<API_GAME_STATS<API_BASE_GAME_MONTHLY>[G]>>;
|
|
19
|
+
export default function fetchData<G extends GAME>(endpoint: GAME_LB_ALLTIME_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
|
|
20
|
+
export default function fetchData<G extends GAME>(endpoint: GAME_LB_MONTHLY_ENDPOINT<G>, options?: FetchOptions): Promise<MethodResponse<API_REQUEST_LB<G>>>;
|
|
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
|
+
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
|
+
export default function fetchData(endpoint: GLOBAL_STATISTICS_ENDPOINT, options?: FetchOptions): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
|
package/lib/methods/fetchData.js
CHANGED
|
@@ -38,14 +38,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.API_ROOT = void 0;
|
|
40
40
|
exports.API_ROOT = "https://api.playhive.com/v0";
|
|
41
|
-
function fetchData(endpoint) {
|
|
41
|
+
function fetchData(endpoint, options) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
43
|
var request, response, err_1;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
45
|
switch (_a.label) {
|
|
46
46
|
case 0:
|
|
47
47
|
_a.trys.push([0, 3, , 4]);
|
|
48
|
-
return [4 /*yield*/, fetch(exports.API_ROOT + endpoint
|
|
48
|
+
return [4 /*yield*/, fetch(exports.API_ROOT + endpoint, {
|
|
49
|
+
headers: (options === null || options === void 0 ? void 0 : options.headers)
|
|
50
|
+
? new Headers(options === null || options === void 0 ? void 0 : options.headers)
|
|
51
|
+
: undefined,
|
|
52
|
+
})];
|
|
49
53
|
case 1:
|
|
50
54
|
request = _a.sent();
|
|
51
55
|
if (!request.ok)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { Options } from "../types/API";
|
|
1
2
|
import { LB_STATS } from "../types/GAMES";
|
|
2
3
|
import { GAME } from "../types/GAME_INFO";
|
|
3
4
|
import { MethodResponse } from "../types/METHODS";
|
|
4
|
-
export default function getAllTimeLeaderboard<G extends GAME>(game: G): Promise<MethodResponse<LB_STATS<G>[]>>;
|
|
5
|
+
export default function getAllTimeLeaderboard<G extends GAME>(game: G, options?: Options): Promise<MethodResponse<LB_STATS<G>[]>>;
|
|
@@ -52,14 +52,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var gameFormat_1 = require("../format/gameFormat");
|
|
54
54
|
var fetchData_1 = __importDefault(require("./fetchData"));
|
|
55
|
-
function getAllTimeLeaderboard(game) {
|
|
55
|
+
function getAllTimeLeaderboard(game, options) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
57
57
|
var _a, data, error, gameData, err_1;
|
|
58
58
|
return __generator(this, function (_b) {
|
|
59
59
|
switch (_b.label) {
|
|
60
60
|
case 0:
|
|
61
61
|
_b.trys.push([0, 2, , 3]);
|
|
62
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game))];
|
|
62
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
63
63
|
case 1:
|
|
64
64
|
_a = _b.sent(), data = _a.data, error = _a.error;
|
|
65
65
|
if (error || !data)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { Options } from "../types/API";
|
|
1
2
|
import { BASE_GAME_ALL, GAME_STATS, GAME_STATS_ALL, REQUEST_ALL, USER_MAIN } from "../types/GAMES";
|
|
2
3
|
import { GAME } from "../types/GAME_INFO";
|
|
3
4
|
import { MethodResponse } from "../types/METHODS";
|
|
4
|
-
export default function getAllTimeStats(playerIdentifier: string): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
|
|
5
|
+
export default function getAllTimeStats(playerIdentifier: string, options?: Options): Promise<MethodResponse<Omit<REQUEST_ALL, "main">> & {
|
|
5
6
|
player: USER_MAIN;
|
|
6
7
|
}>;
|
|
7
|
-
export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
|
|
8
|
-
export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G[]): Promise<MethodResponse<{
|
|
8
|
+
export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G, options?: Options): Promise<MethodResponse<GAME_STATS<BASE_GAME_ALL>[G]>>;
|
|
9
|
+
export default function getAllTimeStats<G extends GAME>(playerIdentifier: string, game: G[], options?: Options): Promise<MethodResponse<{
|
|
9
10
|
[M in G]: GAME_STATS_ALL<M>;
|
|
10
11
|
}> & {
|
|
11
12
|
player: USER_MAIN;
|
|
@@ -92,7 +92,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
92
92
|
var gameFormat_1 = __importStar(require("../format/gameFormat"));
|
|
93
93
|
var GAME_INFO_1 = require("../types/GAME_INFO");
|
|
94
94
|
var fetchData_1 = __importDefault(require("./fetchData"));
|
|
95
|
-
function getAllTimeStats(playerIdentifier, game) {
|
|
95
|
+
function getAllTimeStats(playerIdentifier, game, options) {
|
|
96
96
|
return __awaiter(this, void 0, void 0, function () {
|
|
97
97
|
var _a, data, error, gameData, filteredGamesEntries, filteredGames, err_1, _b, data, error, gameData, err_2, _c, data, error, gameData, FILTER_GAMES_1, filteredGamesEntries, filteredGames, err_3;
|
|
98
98
|
var _d;
|
|
@@ -103,7 +103,7 @@ function getAllTimeStats(playerIdentifier, game) {
|
|
|
103
103
|
_e.label = 1;
|
|
104
104
|
case 1:
|
|
105
105
|
_e.trys.push([1, 3, , 4]);
|
|
106
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier))];
|
|
106
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
107
107
|
case 2:
|
|
108
108
|
_a = _e.sent(), data = _a.data, error = _a.error;
|
|
109
109
|
if (error || !data)
|
|
@@ -131,7 +131,7 @@ function getAllTimeStats(playerIdentifier, game) {
|
|
|
131
131
|
_e.label = 5;
|
|
132
132
|
case 5:
|
|
133
133
|
_e.trys.push([5, 7, , 8]);
|
|
134
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game, "/").concat(playerIdentifier))];
|
|
134
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/".concat(game, "/").concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
135
135
|
case 6:
|
|
136
136
|
_b = _e.sent(), data = _b.data, error = _b.error;
|
|
137
137
|
if (error || !data)
|
|
@@ -150,7 +150,7 @@ function getAllTimeStats(playerIdentifier, game) {
|
|
|
150
150
|
_e.label = 9;
|
|
151
151
|
case 9:
|
|
152
152
|
_e.trys.push([9, 11, , 12]);
|
|
153
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier))];
|
|
153
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
154
154
|
case 10:
|
|
155
155
|
_c = _e.sent(), data = _c.data, error = _c.error;
|
|
156
156
|
if (error || !data)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { API_GLOBAL_STATISTICS } from "../types/API";
|
|
1
|
+
import { API_GLOBAL_STATISTICS, Options } from "../types/API";
|
|
2
2
|
import { MethodResponse } from "../types/METHODS";
|
|
3
|
-
export default function getGlobalStatistics(): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
|
|
3
|
+
export default function getGlobalStatistics(options?: Options): Promise<MethodResponse<API_GLOBAL_STATISTICS>>;
|
|
@@ -51,14 +51,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var fetchData_1 = __importDefault(require("./fetchData"));
|
|
54
|
-
function getGlobalStatistics() {
|
|
54
|
+
function getGlobalStatistics(options) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
56
|
var _a, data, error, err_1;
|
|
57
57
|
return __generator(this, function (_b) {
|
|
58
58
|
switch (_b.label) {
|
|
59
59
|
case 0:
|
|
60
60
|
_b.trys.push([0, 2, , 3]);
|
|
61
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/global/statistics")];
|
|
61
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/global/statistics", options === null || options === void 0 ? void 0 : options.fetch)];
|
|
62
62
|
case 1:
|
|
63
63
|
_a = _b.sent(), data = _a.data, error = _a.error;
|
|
64
64
|
if (error || !data)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { Options } from "../types/API";
|
|
1
2
|
import { LB_STATS } from "../types/GAMES";
|
|
2
3
|
import { GAME } from "../types/GAME_INFO";
|
|
3
4
|
import { MethodResponse } from "../types/METHODS";
|
|
4
|
-
|
|
5
|
-
export default function getMonthlyLeaderboard<G extends GAME>(game: G, options: {
|
|
5
|
+
interface OptionsType extends Options {
|
|
6
6
|
year?: number;
|
|
7
7
|
month?: number;
|
|
8
8
|
date?: Date;
|
|
9
9
|
skip?: number;
|
|
10
10
|
amount?: number;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
|
+
export default function getMonthlyLeaderboard<G extends GAME>(game: G, options?: Options): Promise<MethodResponse<LB_STATS<G>[]>>;
|
|
13
|
+
export default function getMonthlyLeaderboard<G extends GAME>(game: G, options: OptionsType): Promise<MethodResponse<LB_STATS<G>[]>>;
|
|
14
|
+
export {};
|
|
@@ -59,11 +59,15 @@ function getMonthlyLeaderboard(game, options) {
|
|
|
59
59
|
return __generator(this, function (_g) {
|
|
60
60
|
switch (_g.label) {
|
|
61
61
|
case 0:
|
|
62
|
-
if (
|
|
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];
|
|
63
67
|
_g.label = 1;
|
|
64
68
|
case 1:
|
|
65
69
|
_g.trys.push([1, 3, , 4]);
|
|
66
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/".concat(game))];
|
|
70
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/".concat(game), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
67
71
|
case 2:
|
|
68
72
|
_e = _g.sent(), data = _e.data, error = _e.error;
|
|
69
73
|
if (error || !data)
|
|
@@ -90,7 +94,7 @@ function getMonthlyLeaderboard(game, options) {
|
|
|
90
94
|
_g.label = 6;
|
|
91
95
|
case 6:
|
|
92
96
|
_g.trys.push([6, 8, , 9]);
|
|
93
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/".concat(game, "/").concat(year, "/").concat(month, "/").concat(amount, "/").concat(skip))];
|
|
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)];
|
|
94
98
|
case 7:
|
|
95
99
|
_f = _g.sent(), data = _f.data, error = _f.error;
|
|
96
100
|
if (error || !data)
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { Options } from "../types/API";
|
|
1
2
|
import { BASE_GAME_MONTHLY, GAME_STATS, GAME_STATS_ALL, REQUEST_MONTHLY } from "../types/GAMES";
|
|
2
3
|
import { GAME } from "../types/GAME_INFO";
|
|
3
4
|
import { MethodResponse } from "../types/METHODS";
|
|
4
|
-
|
|
5
|
-
export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_MONTHLY>[G]>>;
|
|
6
|
-
export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G, options: {
|
|
5
|
+
interface OptionsType extends Options {
|
|
7
6
|
year?: number;
|
|
8
7
|
month?: number;
|
|
9
8
|
date?: Date;
|
|
10
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export default function getMonthlyStats(playerIdentifier: string): Promise<MethodResponse<Omit<REQUEST_MONTHLY, "main">>>;
|
|
11
|
+
export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G): Promise<MethodResponse<GAME_STATS<BASE_GAME_MONTHLY>[G]>>;
|
|
12
|
+
export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G, options: OptionsType): Promise<MethodResponse<GAME_STATS<BASE_GAME_MONTHLY>[G]>>;
|
|
11
13
|
export default function getMonthlyStats<G extends GAME>(playerIdentifier: string, game: G[]): Promise<MethodResponse<{
|
|
12
14
|
[M in G]: GAME_STATS_ALL<M>;
|
|
13
15
|
}>>;
|
|
16
|
+
export {};
|
|
@@ -81,7 +81,7 @@ function getMonthlyStats(playerIdentifier, game, options) {
|
|
|
81
81
|
_j.label = 1;
|
|
82
82
|
case 1:
|
|
83
83
|
_j.trys.push([1, 3, , 4]);
|
|
84
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/all/".concat(playerIdentifier))];
|
|
84
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
85
85
|
case 2:
|
|
86
86
|
_c = _j.sent(), data = _c.data, error = _c.error;
|
|
87
87
|
if (error || !data)
|
|
@@ -101,7 +101,8 @@ function getMonthlyStats(playerIdentifier, game, options) {
|
|
|
101
101
|
console.error(err_1);
|
|
102
102
|
return [2 /*return*/, { data: null, error: { message: "Failed to fetch data." } }];
|
|
103
103
|
case 4:
|
|
104
|
-
if (!(options
|
|
104
|
+
if (!(((options === null || options === void 0 ? void 0 : options.year) || (options === null || options === void 0 ? void 0 : options.month) || (options === null || options === void 0 ? void 0 : options.date)) &&
|
|
105
|
+
typeof game === "string")) return [3 /*break*/, 8];
|
|
105
106
|
year = (_a = options.year) !== null && _a !== void 0 ? _a : new Date().getFullYear();
|
|
106
107
|
month = (_b = options.month) !== null && _b !== void 0 ? _b : new Date().getMonth() + 1;
|
|
107
108
|
if (options.date) {
|
|
@@ -111,7 +112,7 @@ function getMonthlyStats(playerIdentifier, game, options) {
|
|
|
111
112
|
_j.label = 5;
|
|
112
113
|
case 5:
|
|
113
114
|
_j.trys.push([5, 7, , 8]);
|
|
114
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/".concat(game, "/").concat(playerIdentifier, "/").concat(year, "/").concat(month))];
|
|
115
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/".concat(game, "/").concat(playerIdentifier, "/").concat(year, "/").concat(month), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
115
116
|
case 6:
|
|
116
117
|
_d = _j.sent(), data = _d.data, error = _d.error;
|
|
117
118
|
if (error || !data)
|
|
@@ -135,7 +136,7 @@ function getMonthlyStats(playerIdentifier, game, options) {
|
|
|
135
136
|
_j.label = 9;
|
|
136
137
|
case 9:
|
|
137
138
|
_j.trys.push([9, 11, , 12]);
|
|
138
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/".concat(game, "/").concat(playerIdentifier))];
|
|
139
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/".concat(game, "/").concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
139
140
|
case 10:
|
|
140
141
|
_e = _j.sent(), data = _e.data, error = _e.error;
|
|
141
142
|
if (error || !data)
|
|
@@ -159,7 +160,7 @@ function getMonthlyStats(playerIdentifier, game, options) {
|
|
|
159
160
|
_j.label = 13;
|
|
160
161
|
case 13:
|
|
161
162
|
_j.trys.push([13, 15, , 16]);
|
|
162
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/all/".concat(playerIdentifier))];
|
|
163
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/monthly/player/all/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
163
164
|
case 14:
|
|
164
165
|
_f = _j.sent(), data = _f.data, error = _f.error;
|
|
165
166
|
if (error || !data)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Options } from "../types/API";
|
|
1
2
|
import { USER_MAIN } from "../types/GAMES";
|
|
2
3
|
import { MethodResponse } from "../types/METHODS";
|
|
3
|
-
export default function getPlayerInfo(playerIdentifier: string): Promise<MethodResponse<USER_MAIN>>;
|
|
4
|
+
export default function getPlayerInfo(playerIdentifier: string, options?: Options): Promise<MethodResponse<USER_MAIN>>;
|
|
@@ -51,14 +51,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var fetchData_1 = __importDefault(require("./fetchData"));
|
|
54
|
-
function getPlayerInfo(playerIdentifier) {
|
|
54
|
+
function getPlayerInfo(playerIdentifier, options) {
|
|
55
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
56
|
var _a, data, error, err_1;
|
|
57
57
|
return __generator(this, function (_b) {
|
|
58
58
|
switch (_b.label) {
|
|
59
59
|
case 0:
|
|
60
60
|
_b.trys.push([0, 2, , 3]);
|
|
61
|
-
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/main/".concat(playerIdentifier))];
|
|
61
|
+
return [4 /*yield*/, (0, fetchData_1.default)("/game/all/main/".concat(playerIdentifier), options === null || options === void 0 ? void 0 : options.fetch)];
|
|
62
62
|
case 1:
|
|
63
63
|
_a = _b.sent(), data = _a.data, error = _a.error;
|
|
64
64
|
if (error || !data)
|
package/lib/types/API.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetchOptions } from "../methods/fetchData";
|
|
1
2
|
import { GAME } from "./GAME_INFO";
|
|
2
3
|
export interface API_ERROR {
|
|
3
4
|
request?: {
|
|
@@ -10,6 +11,9 @@ export interface API_ERROR {
|
|
|
10
11
|
};
|
|
11
12
|
error?: any;
|
|
12
13
|
}
|
|
14
|
+
export interface Options {
|
|
15
|
+
fetch?: FetchOptions;
|
|
16
|
+
}
|
|
13
17
|
export type RANK = "REGULAR" | "PLUS" | "YOUTUBER" | "STREAMER" | "TIKTOK" | "VIP" | "HELPER" | "MODERATOR" | "HIVE_TEAM" | "STAFF_MANAGER" | "COMMUNITY_MANAGER" | "OWNER";
|
|
14
18
|
export type API_REQUEST_ALL = {
|
|
15
19
|
[G in GAME]: API_GAME_STATS_ALL<G>;
|