clashofclans.js 2.0.0-dev.0e51540 → 2.0.0-dev.2c5b083
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/CHANGELOG.md +6 -5
- package/README.md +4 -3
- package/dist/client/Client.d.ts +47 -13
- package/dist/client/Client.js +56 -32
- package/dist/client/EventManager.d.ts +13 -13
- package/dist/client/EventManager.js +72 -37
- package/dist/rest/HTTPError.d.ts +17 -1
- package/dist/rest/HTTPError.js +14 -5
- package/dist/rest/RESTManager.d.ts +49 -120
- package/dist/rest/RESTManager.js +25 -1
- package/dist/rest/RequestHandler.d.ts +14 -6
- package/dist/rest/RequestHandler.js +20 -12
- package/dist/rest/Throttler.d.ts +0 -4
- package/dist/struct/Clan.d.ts +2 -1
- package/dist/struct/Clan.js +2 -2
- package/dist/struct/ClanMember.d.ts +2 -1
- package/dist/struct/ClanMember.js +2 -2
- package/dist/struct/ClanWar.d.ts +6 -4
- package/dist/struct/ClanWar.js +17 -3
- package/dist/struct/ClanWarLeagueGroup.d.ts +5 -3
- package/dist/struct/ClanWarLeagueGroup.js +12 -10
- package/dist/struct/ClanWarLog.d.ts +2 -2
- package/dist/struct/ClanWarLog.js +2 -2
- package/dist/struct/Player.d.ts +2 -1
- package/dist/struct/Player.js +7 -5
- package/dist/struct/PlayerClan.d.ts +2 -1
- package/dist/struct/PlayerClan.js +2 -2
- package/dist/struct/Unit.d.ts +37 -4
- package/dist/struct/Unit.js +49 -9
- package/dist/types/index.d.ts +2 -4
- package/dist/util/Util.js +3 -1
- package/dist/util/raw.json +1 -0
- package/package.json +5 -5
|
@@ -2,126 +2,55 @@ import { RequestHandler, SearchOptions, ClanSearchOptions, ClientOptions, Overri
|
|
|
2
2
|
import { APIClan, APIClanList, APIClanMemberList, APIClanRankingList, APIClanVersusRankingList, APIClanWar, APIClanWarLeagueGroup, APIClanWarLog, APIGoldPassSeason, APILabelList, APILeague, APILeagueList, APILeagueSeasonList, APILocation, APILocationList, APIPlayer, APIPlayerRankingList, APIPlayerSeasonRankingList, APIPlayerVersusRankingList, APIVerifyToken, APIWarLeague, APIWarLeagueList } from '../types';
|
|
3
3
|
/** Represents a REST Manager of the client. */
|
|
4
4
|
export declare class RESTManager {
|
|
5
|
+
/** Request Handler for the RESTManager. */
|
|
5
6
|
readonly handler: RequestHandler;
|
|
6
7
|
constructor(options?: ClientOptions);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
status: number;
|
|
56
|
-
}>;
|
|
57
|
-
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<{
|
|
58
|
-
data: APILeague;
|
|
59
|
-
maxAge: number;
|
|
60
|
-
status: number;
|
|
61
|
-
}>;
|
|
62
|
-
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<{
|
|
63
|
-
data: APILeagueSeasonList;
|
|
64
|
-
maxAge: number;
|
|
65
|
-
status: number;
|
|
66
|
-
}>;
|
|
67
|
-
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<{
|
|
68
|
-
data: APIPlayerSeasonRankingList;
|
|
69
|
-
maxAge: number;
|
|
70
|
-
status: number;
|
|
71
|
-
}>;
|
|
72
|
-
getWarLeagues(options?: SearchOptions): Promise<{
|
|
73
|
-
data: APIWarLeagueList;
|
|
74
|
-
maxAge: number;
|
|
75
|
-
status: number;
|
|
76
|
-
}>;
|
|
77
|
-
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<{
|
|
78
|
-
data: APIWarLeague;
|
|
79
|
-
maxAge: number;
|
|
80
|
-
status: number;
|
|
81
|
-
}>;
|
|
82
|
-
getLocations(options?: SearchOptions): Promise<{
|
|
83
|
-
data: APILocationList;
|
|
84
|
-
maxAge: number;
|
|
85
|
-
status: number;
|
|
86
|
-
}>;
|
|
87
|
-
getLocation(locationId: number, options?: OverrideOptions): Promise<{
|
|
88
|
-
data: APILocation;
|
|
89
|
-
maxAge: number;
|
|
90
|
-
status: number;
|
|
91
|
-
}>;
|
|
92
|
-
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<{
|
|
93
|
-
data: APIClanRankingList;
|
|
94
|
-
maxAge: number;
|
|
95
|
-
status: number;
|
|
96
|
-
}>;
|
|
97
|
-
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<{
|
|
98
|
-
data: APIPlayerRankingList;
|
|
99
|
-
maxAge: number;
|
|
100
|
-
status: number;
|
|
101
|
-
}>;
|
|
102
|
-
getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<{
|
|
103
|
-
data: APIClanVersusRankingList;
|
|
104
|
-
maxAge: number;
|
|
105
|
-
status: number;
|
|
106
|
-
}>;
|
|
107
|
-
getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<{
|
|
108
|
-
data: APIPlayerVersusRankingList;
|
|
109
|
-
maxAge: number;
|
|
110
|
-
status: number;
|
|
111
|
-
}>;
|
|
112
|
-
getClanLabels(options?: SearchOptions): Promise<{
|
|
113
|
-
data: APILabelList;
|
|
114
|
-
maxAge: number;
|
|
115
|
-
status: number;
|
|
116
|
-
}>;
|
|
117
|
-
getPlayerLabels(options?: SearchOptions): Promise<{
|
|
118
|
-
data: APILabelList;
|
|
119
|
-
maxAge: number;
|
|
120
|
-
status: number;
|
|
121
|
-
}>;
|
|
122
|
-
getGoldPassSeason(options?: OverrideOptions): Promise<{
|
|
123
|
-
data: APIGoldPassSeason;
|
|
124
|
-
maxAge: number;
|
|
125
|
-
status: number;
|
|
126
|
-
}>;
|
|
8
|
+
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
9
|
+
getClans(options: ClanSearchOptions): Promise<import("./RequestHandler").Response<APIClanList>>;
|
|
10
|
+
/** Get information about a clan. */
|
|
11
|
+
getClan(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClan>>;
|
|
12
|
+
/** Get list of clan members. */
|
|
13
|
+
getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanMemberList>>;
|
|
14
|
+
/** Get clan war log. */
|
|
15
|
+
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanWarLog>>;
|
|
16
|
+
/** Get info about currently running war in the clan. */
|
|
17
|
+
getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
|
|
18
|
+
/** Get information about clan war league. */
|
|
19
|
+
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWarLeagueGroup>>;
|
|
20
|
+
/** Get info about a CWL round by WarTag. */
|
|
21
|
+
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
|
|
22
|
+
/** Get information about a player by tag. */
|
|
23
|
+
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIPlayer>>;
|
|
24
|
+
/** Verify Player API token that can be found from the Game settings. */
|
|
25
|
+
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIVerifyToken>>;
|
|
26
|
+
/** Get list of Leagues. */
|
|
27
|
+
getLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueList>>;
|
|
28
|
+
/** Get a League info. */
|
|
29
|
+
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILeague>>;
|
|
30
|
+
/** Get Legend League season Ids. */
|
|
31
|
+
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueSeasonList>>;
|
|
32
|
+
/** Get Legend League season rankings by season Id. */
|
|
33
|
+
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerSeasonRankingList>>;
|
|
34
|
+
/** Get list of Clan War Leagues. */
|
|
35
|
+
getWarLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APIWarLeagueList>>;
|
|
36
|
+
/** Get info about a Clan War League. */
|
|
37
|
+
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIWarLeague>>;
|
|
38
|
+
/** Get list of Locations. */
|
|
39
|
+
getLocations(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILocationList>>;
|
|
40
|
+
/** Get info about a Location. */
|
|
41
|
+
getLocation(locationId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILocation>>;
|
|
42
|
+
/** Get clan rankings for a specific location. */
|
|
43
|
+
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanRankingList>>;
|
|
44
|
+
/** Get player rankings for a specific location. */
|
|
45
|
+
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerRankingList>>;
|
|
46
|
+
/** Get clan versus rankings for a specific location. */
|
|
47
|
+
getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanVersusRankingList>>;
|
|
48
|
+
/** Get player versus rankings for a specific location. */
|
|
49
|
+
getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerVersusRankingList>>;
|
|
50
|
+
/** Get list of clan labels. */
|
|
51
|
+
getClanLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
|
|
52
|
+
/** Get list of player labels. */
|
|
53
|
+
getPlayerLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
|
|
54
|
+
/** Get info about gold pass season. */
|
|
55
|
+
getGoldPassSeason(options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIGoldPassSeason>>;
|
|
127
56
|
}
|
package/dist/rest/RESTManager.js
CHANGED
|
@@ -8,90 +8,114 @@ class RESTManager {
|
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.handler = new RequestHandler_1.RequestHandler(options);
|
|
10
10
|
}
|
|
11
|
+
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
11
12
|
getClans(options) {
|
|
12
13
|
const query = Util_1.Util.queryString(options);
|
|
13
14
|
return this.handler.request(`/clans?${query}`);
|
|
14
15
|
}
|
|
16
|
+
/** Get information about a clan. */
|
|
15
17
|
getClan(clanTag, options) {
|
|
16
18
|
return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}`, options);
|
|
17
19
|
}
|
|
20
|
+
/** Get list of clan members. */
|
|
18
21
|
getClanMembers(clanTag, options) {
|
|
19
22
|
const query = Util_1.Util.queryString(options);
|
|
20
23
|
return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/members?${query}`, options);
|
|
21
24
|
}
|
|
25
|
+
/** Get clan war log. */
|
|
22
26
|
getClanWarLog(clanTag, options) {
|
|
23
27
|
const query = Util_1.Util.queryString(options);
|
|
24
28
|
return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/warlog?${query}`, options);
|
|
25
29
|
}
|
|
30
|
+
/** Get info about currently running war in the clan. */
|
|
26
31
|
getCurrentWar(clanTag, options) {
|
|
27
32
|
return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/currentwar`, options);
|
|
28
33
|
}
|
|
34
|
+
/** Get information about clan war league. */
|
|
29
35
|
getClanWarLeagueGroup(clanTag, options) {
|
|
30
36
|
return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/currentwar/leaguegroup`, options);
|
|
31
37
|
}
|
|
38
|
+
/** Get info about a CWL round by WarTag. */
|
|
32
39
|
getClanWarLeagueRound(warTag, options) {
|
|
33
40
|
return this.handler.request(`/clanwarleagues/wars/${Util_1.Util.encodeTag(warTag)}`, options);
|
|
34
41
|
}
|
|
42
|
+
/** Get information about a player by tag. */
|
|
35
43
|
getPlayer(playerTag, options) {
|
|
36
44
|
return this.handler.request(`/players/${Util_1.Util.encodeTag(playerTag)}`, options);
|
|
37
45
|
}
|
|
38
|
-
|
|
46
|
+
/** Verify Player API token that can be found from the Game settings. */
|
|
47
|
+
verifyPlayerToken(playerTag, token, options) {
|
|
39
48
|
const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
|
|
40
49
|
return this.handler.request(`/players/${Util_1.Util.encodeTag(playerTag)}/verifytoken`, opts);
|
|
41
50
|
}
|
|
51
|
+
/** Get list of Leagues. */
|
|
42
52
|
getLeagues(options) {
|
|
43
53
|
const query = Util_1.Util.queryString(options);
|
|
44
54
|
return this.handler.request(`/leagues?${query}`, options);
|
|
45
55
|
}
|
|
56
|
+
/** Get a League info. */
|
|
46
57
|
getLeague(leagueId, options) {
|
|
47
58
|
return this.handler.request(`/leagues/${leagueId}`, options);
|
|
48
59
|
}
|
|
60
|
+
/** Get Legend League season Ids. */
|
|
49
61
|
getLeagueSeasons(leagueId, options) {
|
|
50
62
|
const query = Util_1.Util.queryString(options);
|
|
51
63
|
return this.handler.request(`/leagues/${leagueId}/seasons?${query}`, options);
|
|
52
64
|
}
|
|
65
|
+
/** Get Legend League season rankings by season Id. */
|
|
53
66
|
getSeasonRankings(leagueId, seasonId, options) {
|
|
54
67
|
const query = Util_1.Util.queryString(options);
|
|
55
68
|
return this.handler.request(`/leagues/${leagueId}/seasons/${seasonId}?${query}`, options);
|
|
56
69
|
}
|
|
70
|
+
/** Get list of Clan War Leagues. */
|
|
57
71
|
getWarLeagues(options) {
|
|
58
72
|
const query = Util_1.Util.queryString(options);
|
|
59
73
|
return this.handler.request(`/warleagues?${query}`, options);
|
|
60
74
|
}
|
|
75
|
+
/** Get info about a Clan War League. */
|
|
61
76
|
getWarLeague(leagueId, options) {
|
|
62
77
|
return this.handler.request(`/warleagues/${leagueId}`, options);
|
|
63
78
|
}
|
|
79
|
+
/** Get list of Locations. */
|
|
64
80
|
getLocations(options) {
|
|
65
81
|
const query = Util_1.Util.queryString(options);
|
|
66
82
|
return this.handler.request(`/locations?${query}`, options);
|
|
67
83
|
}
|
|
84
|
+
/** Get info about a Location. */
|
|
68
85
|
getLocation(locationId, options) {
|
|
69
86
|
return this.handler.request(`/locations/${locationId}`, options);
|
|
70
87
|
}
|
|
88
|
+
/** Get clan rankings for a specific location. */
|
|
71
89
|
getClanRanks(locationId, options) {
|
|
72
90
|
const query = Util_1.Util.queryString(options);
|
|
73
91
|
return this.handler.request(`/locations/${locationId}/rankings/clans?${query}`, options);
|
|
74
92
|
}
|
|
93
|
+
/** Get player rankings for a specific location. */
|
|
75
94
|
getPlayerRanks(locationId, options) {
|
|
76
95
|
const query = Util_1.Util.queryString(options);
|
|
77
96
|
return this.handler.request(`/locations/${locationId}/rankings/players?${query}`, options);
|
|
78
97
|
}
|
|
98
|
+
/** Get clan versus rankings for a specific location. */
|
|
79
99
|
getVersusClanRanks(locationId, options) {
|
|
80
100
|
const query = Util_1.Util.queryString(options);
|
|
81
101
|
return this.handler.request(`/locations/${locationId}/rankings/clans-versus?${query}`, options);
|
|
82
102
|
}
|
|
103
|
+
/** Get player versus rankings for a specific location. */
|
|
83
104
|
getVersusPlayerRanks(locationId, options) {
|
|
84
105
|
const query = Util_1.Util.queryString(options);
|
|
85
106
|
return this.handler.request(`/locations/${locationId}/rankings/players-versus?${query}`, options);
|
|
86
107
|
}
|
|
108
|
+
/** Get list of clan labels. */
|
|
87
109
|
getClanLabels(options) {
|
|
88
110
|
const query = Util_1.Util.queryString(options);
|
|
89
111
|
return this.handler.request(`/labels/clans?${query}`, options);
|
|
90
112
|
}
|
|
113
|
+
/** Get list of player labels. */
|
|
91
114
|
getPlayerLabels(options) {
|
|
92
115
|
const query = Util_1.Util.queryString(options);
|
|
93
116
|
return this.handler.request(`/labels/players?${query}`, options);
|
|
94
117
|
}
|
|
118
|
+
/** Get info about gold pass season. */
|
|
95
119
|
getGoldPassSeason(options) {
|
|
96
120
|
return this.handler.request('/goldpass/seasons/current', options);
|
|
97
121
|
}
|
|
@@ -11,18 +11,14 @@ export declare class RequestHandler {
|
|
|
11
11
|
private keys;
|
|
12
12
|
private readonly baseURL;
|
|
13
13
|
private readonly retryLimit;
|
|
14
|
-
private readonly cached;
|
|
15
14
|
private readonly restRequestTimeout;
|
|
16
15
|
private readonly throttler?;
|
|
16
|
+
private readonly cached;
|
|
17
17
|
constructor(options?: ClientOptions);
|
|
18
18
|
private get _keys();
|
|
19
19
|
private get _key();
|
|
20
20
|
setKeys(keys: string[]): this;
|
|
21
|
-
request<T>(path: string, options?: RequestOptions): Promise<
|
|
22
|
-
data: T;
|
|
23
|
-
maxAge: number;
|
|
24
|
-
status: number;
|
|
25
|
-
}>;
|
|
21
|
+
request<T>(path: string, options?: RequestOptions): Promise<Response<T>>;
|
|
26
22
|
private exec;
|
|
27
23
|
init(options: InitOptions): Promise<string[]>;
|
|
28
24
|
private reValidateKeys;
|
|
@@ -96,9 +92,21 @@ export interface OverrideOptions {
|
|
|
96
92
|
restRequestTimeout?: number;
|
|
97
93
|
}
|
|
98
94
|
export interface RequestOptions extends OverrideOptions {
|
|
95
|
+
/** The request body. */
|
|
99
96
|
body?: string;
|
|
97
|
+
/** The request method. */
|
|
100
98
|
method?: string;
|
|
101
99
|
}
|
|
100
|
+
export interface Response<T> {
|
|
101
|
+
/** The response body. */
|
|
102
|
+
data: T;
|
|
103
|
+
/** Path of the request for this response. */
|
|
104
|
+
path: string;
|
|
105
|
+
/** HTTP status code of this response. */
|
|
106
|
+
status: number;
|
|
107
|
+
/** The maxAge of this response. */
|
|
108
|
+
maxAge: number;
|
|
109
|
+
}
|
|
102
110
|
/**
|
|
103
111
|
* Clan search options for a request.
|
|
104
112
|
*
|
|
@@ -50,8 +50,9 @@ class RequestHandler {
|
|
|
50
50
|
}
|
|
51
51
|
async request(path, options = {}) {
|
|
52
52
|
const cached = (await this.cached?.get(path)) ?? null;
|
|
53
|
-
if (cached && options.force !== true)
|
|
54
|
-
return { data: cached, maxAge:
|
|
53
|
+
if (cached && options.force !== true) {
|
|
54
|
+
return { data: cached.data, maxAge: cached.ttl - Date.now(), status: 200, path };
|
|
55
|
+
}
|
|
55
56
|
if (!this.throttler || options.ignoreRateLimit)
|
|
56
57
|
return this.exec(path, options);
|
|
57
58
|
await this.throttler.wait();
|
|
@@ -74,15 +75,19 @@ class RequestHandler {
|
|
|
74
75
|
if (!res && retries < (options.retryLimit ?? this.retryLimit))
|
|
75
76
|
return this.exec(path, options, ++retries);
|
|
76
77
|
if (res?.status === 403 && data?.reason === 'accessDenied.invalidIp' && this.email && this.password) {
|
|
77
|
-
await this.login();
|
|
78
|
-
|
|
78
|
+
const keys = await this.reValidateKeys().then(() => this.login());
|
|
79
|
+
if (keys.length)
|
|
80
|
+
return this.exec(path, options, ++retries);
|
|
79
81
|
}
|
|
82
|
+
const maxAge = Number(res?.headers.get('cache-control')?.split('=')?.[1] ?? 0) * 1000;
|
|
83
|
+
if (res?.status === 403 && !data?.message)
|
|
84
|
+
throw new HTTPError_1.HTTPError(HTTPError_1.PrivateWarLogError, res.status, path, maxAge);
|
|
80
85
|
if (!res?.ok)
|
|
81
|
-
throw new HTTPError_1.HTTPError(data, res?.status ?? 504, path, options.method);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return { data, maxAge, status: res.status };
|
|
86
|
+
throw new HTTPError_1.HTTPError(data, res?.status ?? 504, path, maxAge, options.method);
|
|
87
|
+
if (this.cached && maxAge > 0 && options.cache !== false) {
|
|
88
|
+
await this.cached.set(path, { data, ttl: Date.now() + maxAge }, maxAge);
|
|
89
|
+
}
|
|
90
|
+
return { data, maxAge, status: res.status, path };
|
|
86
91
|
}
|
|
87
92
|
async init(options) {
|
|
88
93
|
if (!(options.email && options.password))
|
|
@@ -112,6 +117,7 @@ class RequestHandler {
|
|
|
112
117
|
async login() {
|
|
113
118
|
const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/login`, {
|
|
114
119
|
method: 'POST',
|
|
120
|
+
timeout: 10000,
|
|
115
121
|
headers: { 'Content-Type': 'application/json' },
|
|
116
122
|
body: JSON.stringify({ email: this.email, password: this.password })
|
|
117
123
|
});
|
|
@@ -124,14 +130,14 @@ class RequestHandler {
|
|
|
124
130
|
const ip = await this.getIp();
|
|
125
131
|
const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/list`, {
|
|
126
132
|
method: 'POST',
|
|
133
|
+
timeout: 10000,
|
|
127
134
|
headers: { 'Content-Type': 'application/json', cookie }
|
|
128
135
|
});
|
|
129
136
|
const data = await res.json();
|
|
130
137
|
// Get all available keys from the developer site.
|
|
131
138
|
const keys = (data.keys ?? []);
|
|
132
139
|
// Revoke keys for specified key name but not matching current IP address.
|
|
133
|
-
const
|
|
134
|
-
for (const key of expiredKeys) {
|
|
140
|
+
for (const key of keys.filter((key) => key.name === this.keyName && !key.cidrRanges.includes(ip))) {
|
|
135
141
|
if (!(await this.revokeKey(key.id, cookie)))
|
|
136
142
|
continue;
|
|
137
143
|
const index = keys.findIndex(({ id }) => id === key.id);
|
|
@@ -164,6 +170,7 @@ class RequestHandler {
|
|
|
164
170
|
async revokeKey(keyId, cookie) {
|
|
165
171
|
const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/revoke`, {
|
|
166
172
|
method: 'POST',
|
|
173
|
+
timeout: 10000,
|
|
167
174
|
body: JSON.stringify({ id: keyId }),
|
|
168
175
|
headers: { 'Content-Type': 'application/json', cookie }
|
|
169
176
|
});
|
|
@@ -172,6 +179,7 @@ class RequestHandler {
|
|
|
172
179
|
async createKey(cookie, ip) {
|
|
173
180
|
const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/create`, {
|
|
174
181
|
method: 'POST',
|
|
182
|
+
timeout: 10000,
|
|
175
183
|
headers: { 'Content-Type': 'application/json', cookie },
|
|
176
184
|
body: JSON.stringify({
|
|
177
185
|
cidrRanges: [ip],
|
|
@@ -183,7 +191,7 @@ class RequestHandler {
|
|
|
183
191
|
return data.key;
|
|
184
192
|
}
|
|
185
193
|
async getIp() {
|
|
186
|
-
return (0, node_fetch_1.default)('https://api.ipify.org/').then((res) => res.text());
|
|
194
|
+
return (0, node_fetch_1.default)('https://api.ipify.org/', { timeout: 10000 }).then((res) => res.text());
|
|
187
195
|
}
|
|
188
196
|
}
|
|
189
197
|
exports.RequestHandler = RequestHandler;
|
package/dist/rest/Throttler.d.ts
CHANGED
package/dist/struct/Clan.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OverrideOptions } from '../rest/RequestHandler';
|
|
1
2
|
import { ChatLanguage } from './ChatLanguage';
|
|
2
3
|
import { ClanMember } from './ClanMember';
|
|
3
4
|
import { Client } from '../client/Client';
|
|
@@ -59,5 +60,5 @@ export declare class Clan {
|
|
|
59
60
|
members: ClanMember[];
|
|
60
61
|
constructor(client: Client, data: APIClan);
|
|
61
62
|
/** Get {@link Player} information for every Player in the clan. */
|
|
62
|
-
fetchMembers(): Promise<Player[]>;
|
|
63
|
+
fetchMembers(options?: OverrideOptions): Promise<Player[]>;
|
|
63
64
|
}
|
package/dist/struct/Clan.js
CHANGED
|
@@ -35,8 +35,8 @@ class Clan {
|
|
|
35
35
|
this.members = data.memberList?.map((mem) => new ClanMember_1.ClanMember(this.client, mem)) ?? []; // eslint-disable-line
|
|
36
36
|
}
|
|
37
37
|
/** Get {@link Player} information for every Player in the clan. */
|
|
38
|
-
async fetchMembers() {
|
|
39
|
-
return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ignoreRateLimit: true }))))
|
|
38
|
+
async fetchMembers(options) {
|
|
39
|
+
return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ...options, ignoreRateLimit: true }))))
|
|
40
40
|
.filter((res) => res.status === 'fulfilled')
|
|
41
41
|
.map((res) => res.value);
|
|
42
42
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OverrideOptions } from '../rest/RequestHandler';
|
|
1
2
|
import { Client } from '../client/Client';
|
|
2
3
|
import { APIClanMember } from '../types';
|
|
3
4
|
import { League } from './League';
|
|
@@ -27,5 +28,5 @@ export declare class ClanMember {
|
|
|
27
28
|
received: number;
|
|
28
29
|
constructor(client: Client, data: APIClanMember);
|
|
29
30
|
/** Fetch detailed clan info for the member's clan. */
|
|
30
|
-
fetch(): Promise<import("./Player").Player>;
|
|
31
|
+
fetch(options?: OverrideOptions): Promise<import("./Player").Player>;
|
|
31
32
|
}
|
|
@@ -21,8 +21,8 @@ class ClanMember {
|
|
|
21
21
|
this.received = data.donationsReceived;
|
|
22
22
|
}
|
|
23
23
|
/** Fetch detailed clan info for the member's clan. */
|
|
24
|
-
async fetch() {
|
|
25
|
-
return this.client.getPlayer(this.tag);
|
|
24
|
+
async fetch(options) {
|
|
25
|
+
return this.client.getPlayer(this.tag, options);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.ClanMember = ClanMember;
|
package/dist/struct/ClanWar.d.ts
CHANGED
|
@@ -116,12 +116,12 @@ export declare class ClanWar {
|
|
|
116
116
|
opponent: WarClan;
|
|
117
117
|
/** The war's unique tag. This is `null` unless this is a CWL. */
|
|
118
118
|
warTag: string | null;
|
|
119
|
-
/**
|
|
119
|
+
/** Maximum number of milliseconds the results can be cached. */
|
|
120
120
|
maxAge: number;
|
|
121
121
|
constructor(client: Client, data: APIClanWar, extra: {
|
|
122
122
|
clanTag?: string;
|
|
123
123
|
warTag?: string;
|
|
124
|
-
maxAge
|
|
124
|
+
maxAge: number;
|
|
125
125
|
});
|
|
126
126
|
/** Return a {@link ClanWarMember} with the tag provided. */
|
|
127
127
|
getMember(tag: string): ClanWarMember | null;
|
|
@@ -129,7 +129,9 @@ export declare class ClanWar {
|
|
|
129
129
|
getAttack(attackerTag: string, defenderTag: string): ClanWarAttack | null;
|
|
130
130
|
/** Return a list of {@link ClanWarAttack} for the defenderTag provided. */
|
|
131
131
|
getDefenses(defenderTag: string): ClanWarAttack[];
|
|
132
|
-
/** Returns either `friendly`, `cwl` or `
|
|
133
|
-
get type():
|
|
132
|
+
/** Returns either `friendly`, `cwl` or `normal`. */
|
|
133
|
+
get type(): "friendly" | "cwl" | "normal";
|
|
134
134
|
private get _isFriendly();
|
|
135
|
+
/** Returns the war status, based off the home clan. */
|
|
136
|
+
get status(): "win" | "lose" | "tie" | "pending";
|
|
135
137
|
}
|
package/dist/struct/ClanWar.js
CHANGED
|
@@ -147,7 +147,7 @@ class ClanWar {
|
|
|
147
147
|
}
|
|
148
148
|
this.clan = new WarClan(this, clan);
|
|
149
149
|
this.opponent = new WarClan(this, opponent);
|
|
150
|
-
this.maxAge =
|
|
150
|
+
this.maxAge = extra.maxAge;
|
|
151
151
|
}
|
|
152
152
|
/** Return a {@link ClanWarMember} with the tag provided. */
|
|
153
153
|
getMember(tag) {
|
|
@@ -168,17 +168,31 @@ class ClanWar {
|
|
|
168
168
|
}
|
|
169
169
|
return this.opponent.attacks.filter((atk) => atk.defenderTag === defenderTag);
|
|
170
170
|
}
|
|
171
|
-
/** Returns either `friendly`, `cwl` or `
|
|
171
|
+
/** Returns either `friendly`, `cwl` or `normal`. */
|
|
172
172
|
get type() {
|
|
173
173
|
if (this._isFriendly)
|
|
174
174
|
return 'friendly';
|
|
175
175
|
if (this.warTag)
|
|
176
176
|
return 'cwl';
|
|
177
|
-
return '
|
|
177
|
+
return 'normal';
|
|
178
178
|
}
|
|
179
179
|
get _isFriendly() {
|
|
180
180
|
const preparationTime = this.startTime.getTime() - this.preparationStartTime.getTime();
|
|
181
181
|
return Constants_1.FRIENDLY_WAR_PREPARATION_TIMES.includes(preparationTime);
|
|
182
182
|
}
|
|
183
|
+
/** Returns the war status, based off the home clan. */
|
|
184
|
+
get status() {
|
|
185
|
+
if (this.state === 'preparation')
|
|
186
|
+
return 'pending';
|
|
187
|
+
if (this.clan.stars > this.opponent.stars)
|
|
188
|
+
return 'win';
|
|
189
|
+
if (this.clan.stars === this.opponent.stars) {
|
|
190
|
+
if (this.clan.destruction > this.opponent.destruction)
|
|
191
|
+
return 'win';
|
|
192
|
+
if (this.clan.destruction === this.opponent.destruction)
|
|
193
|
+
return 'tie';
|
|
194
|
+
}
|
|
195
|
+
return 'lose';
|
|
196
|
+
}
|
|
183
197
|
}
|
|
184
198
|
exports.ClanWar = ClanWar;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { APIClanWarLeagueClan, APIClanWarLeagueClanMember, APIClanWarLeagueGroup, APIClanWarLeagueRound } from '../types';
|
|
2
|
+
import { OverrideOptions } from '../rest/RequestHandler';
|
|
2
3
|
import { Client } from '../client/Client';
|
|
3
4
|
import { ClanWar } from './ClanWar';
|
|
4
5
|
import { Player } from './Player';
|
|
@@ -28,7 +29,7 @@ export declare class ClanWarLeagueClan {
|
|
|
28
29
|
members: ClanWarLeagueClanMember[];
|
|
29
30
|
constructor(client: Client, data: APIClanWarLeagueClan);
|
|
30
31
|
/** Get {@link Player} information for every members that are in the CWL group. */
|
|
31
|
-
fetchMembers(): Promise<Player[]>;
|
|
32
|
+
fetchMembers(options?: OverrideOptions): Promise<Player[]>;
|
|
32
33
|
}
|
|
33
34
|
/** Represents a Round of CWL Group. */
|
|
34
35
|
export declare class ClanWarLeagueRound {
|
|
@@ -53,9 +54,10 @@ export declare class ClanWarLeagueGroup {
|
|
|
53
54
|
/**
|
|
54
55
|
* This returns an array of {@link ClanWar} which fetches all wars in parallel.
|
|
55
56
|
* @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
|
|
57
|
+
* @param options Override options for the request.
|
|
56
58
|
*/
|
|
57
|
-
getWars(clanTag?: string): Promise<ClanWar[]>;
|
|
59
|
+
getWars(clanTag?: string, options?: OverrideOptions): Promise<ClanWar[]>;
|
|
58
60
|
private _getCurrentWars;
|
|
59
|
-
/** Returns
|
|
61
|
+
/** Returns the index of the round for this specified warTag. */
|
|
60
62
|
getRoundIndex(warTag: string): number | null;
|
|
61
63
|
}
|
|
@@ -22,8 +22,8 @@ class ClanWarLeagueClan {
|
|
|
22
22
|
this.members = data.members.map((mem) => new ClanWarLeagueClanMember(mem));
|
|
23
23
|
}
|
|
24
24
|
/** Get {@link Player} information for every members that are in the CWL group. */
|
|
25
|
-
async fetchMembers() {
|
|
26
|
-
return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ignoreRateLimit: true }))))
|
|
25
|
+
async fetchMembers(options) {
|
|
26
|
+
return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ...options, ignoreRateLimit: true }))))
|
|
27
27
|
.filter((res) => res.status === 'fulfilled')
|
|
28
28
|
.map((res) => res.value);
|
|
29
29
|
}
|
|
@@ -49,33 +49,35 @@ class ClanWarLeagueGroup {
|
|
|
49
49
|
/**
|
|
50
50
|
* This returns an array of {@link ClanWar} which fetches all wars in parallel.
|
|
51
51
|
* @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
|
|
52
|
+
* @param options Override options for the request.
|
|
52
53
|
*/
|
|
53
|
-
async getWars(clanTag) {
|
|
54
|
+
async getWars(clanTag, options) {
|
|
54
55
|
const rounds = this.rounds.filter((round) => !round.warTags.includes('#0'));
|
|
55
56
|
if (!rounds.length)
|
|
56
57
|
return [];
|
|
57
58
|
const warTags = rounds.map((round) => round.warTags).flat();
|
|
58
|
-
const wars = await Promise.allSettled(warTags.map((warTag) => this.client.getClanWarLeagueRound({ warTag, clanTag }, { ignoreRateLimit: true })));
|
|
59
|
+
const wars = await Promise.allSettled(warTags.map((warTag) => this.client.getClanWarLeagueRound({ warTag, clanTag }, { ...options, ignoreRateLimit: true })));
|
|
59
60
|
return wars
|
|
60
|
-
.filter((res) => res.status === 'fulfilled'
|
|
61
|
+
.filter((res) => res.status === 'fulfilled')
|
|
61
62
|
.map((res) => res.value)
|
|
62
63
|
.filter((war) => (clanTag ? war.clan.tag === clanTag : true));
|
|
63
64
|
}
|
|
64
|
-
async _getCurrentWars(clanTag) {
|
|
65
|
+
async _getCurrentWars(clanTag, options) {
|
|
65
66
|
const rounds = this.rounds.filter((round) => !round.warTags.includes('#0'));
|
|
66
67
|
if (!rounds.length)
|
|
67
68
|
return [];
|
|
68
69
|
const warTags = rounds
|
|
69
70
|
.slice(-2)
|
|
70
71
|
.map((round) => round.warTags)
|
|
71
|
-
.flat()
|
|
72
|
-
|
|
72
|
+
.flat()
|
|
73
|
+
.reverse();
|
|
74
|
+
const wars = await Promise.allSettled(warTags.map((warTag) => this.client.getClanWarLeagueRound({ warTag, clanTag }, { ...options, ignoreRateLimit: true })));
|
|
73
75
|
return wars
|
|
74
|
-
.filter((res) => res.status === 'fulfilled'
|
|
76
|
+
.filter((res) => res.status === 'fulfilled')
|
|
75
77
|
.map((res) => res.value)
|
|
76
78
|
.filter((war) => war.clan.tag === clanTag);
|
|
77
79
|
}
|
|
78
|
-
/** Returns
|
|
80
|
+
/** Returns the index of the round for this specified warTag. */
|
|
79
81
|
getRoundIndex(warTag) {
|
|
80
82
|
return this.rounds.find((round) => round.warTags.includes(warTag))?.round ?? null;
|
|
81
83
|
}
|
|
@@ -49,6 +49,6 @@ export declare class ClanWarLog {
|
|
|
49
49
|
/** The opposition clan. */
|
|
50
50
|
opponent: WarLogClan;
|
|
51
51
|
constructor(client: Client, data: APIClanWarLogEntry);
|
|
52
|
-
/** Returns either `friendly`, `cwl` or `
|
|
53
|
-
get type(): "friendly" | "cwl" | "
|
|
52
|
+
/** Returns either `friendly`, `cwl` or `normal`. */
|
|
53
|
+
get type(): "friendly" | "cwl" | "normal";
|
|
54
54
|
}
|