clashofclans.js 3.1.3-dev.aa3a114 → 3.1.4-dev.68bb5bc
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/dist/client/Client.js +57 -57
- package/dist/client/PollingClient.js +1 -1
- package/dist/rest/RESTManager.d.ts +30 -30
- package/dist/rest/RESTManager.js +5 -2
- package/dist/rest/RequestHandler.d.ts +4 -3
- package/dist/rest/RequestHandler.js +32 -14
- package/dist/struct/ClanWar.d.ts +0 -3
- package/dist/struct/ClanWar.js +0 -1
- package/dist/types/lib.d.ts +14 -11
- package/package.json +1 -1
package/dist/client/Client.js
CHANGED
|
@@ -49,34 +49,34 @@ class Client extends node_events_1.EventEmitter {
|
|
|
49
49
|
.filter((res) => res.status === 'fulfilled')
|
|
50
50
|
.map((res) => res.value);
|
|
51
51
|
}
|
|
52
|
-
const {
|
|
52
|
+
const { body } = await this.rest.getClans(query, options);
|
|
53
53
|
// @ts-expect-error
|
|
54
|
-
return
|
|
54
|
+
return body.items.map((clan) => new struct_1.Clan(this, clan));
|
|
55
55
|
}
|
|
56
56
|
/** Get info about a clan. */
|
|
57
57
|
async getClan(clanTag, options) {
|
|
58
|
-
const {
|
|
59
|
-
return new struct_1.Clan(this,
|
|
58
|
+
const { body } = await this.rest.getClan(clanTag, options);
|
|
59
|
+
return new struct_1.Clan(this, body);
|
|
60
60
|
}
|
|
61
61
|
/** Get list of clan members. */
|
|
62
62
|
async getClanMembers(clanTag, options) {
|
|
63
|
-
const {
|
|
64
|
-
return
|
|
63
|
+
const { body } = await this.rest.getClanMembers(clanTag, options);
|
|
64
|
+
return body.items.map((entry) => new struct_1.ClanMember(this, entry));
|
|
65
65
|
}
|
|
66
66
|
/** Get capital raid seasons. */
|
|
67
67
|
async getCapitalRaidSeasons(tag, options) {
|
|
68
|
-
const {
|
|
69
|
-
return
|
|
68
|
+
const { body } = await this.rest.getCapitalRaidSeasons(tag, options);
|
|
69
|
+
return body.items.map((entry) => new CapitalRaidSeason_1.CapitalRaidSeason(this, entry));
|
|
70
70
|
}
|
|
71
71
|
/** Get clan war log. */
|
|
72
72
|
async getClanWarLog(clanTag, options) {
|
|
73
|
-
const {
|
|
74
|
-
return
|
|
73
|
+
const { body } = await this.rest.getClanWarLog(clanTag, options);
|
|
74
|
+
return body.items.map((entry) => new struct_1.ClanWarLog(this, entry));
|
|
75
75
|
}
|
|
76
76
|
/** Get info about currently running war (normal or friendly) in the clan. */
|
|
77
77
|
async getClanWar(clanTag, options) {
|
|
78
|
-
const {
|
|
79
|
-
return new struct_1.ClanWar(this,
|
|
78
|
+
const { body } = await this.rest.getCurrentWar(clanTag, options);
|
|
79
|
+
return new struct_1.ClanWar(this, body, { clanTag });
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Get info about currently running war in the clan.
|
|
@@ -92,11 +92,11 @@ class Client extends node_events_1.EventEmitter {
|
|
|
92
92
|
async getCurrentWar(clanTag, options) {
|
|
93
93
|
const args = typeof clanTag === 'string' ? { clanTag } : { clanTag: clanTag.clanTag, round: clanTag.round };
|
|
94
94
|
try {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
95
|
+
const body = await this.getClanWar(args.clanTag, options);
|
|
96
|
+
if (body.state === 'notInWar') {
|
|
97
97
|
return await this.getLeagueWar({ clanTag: args.clanTag, round: args.round }, options);
|
|
98
98
|
}
|
|
99
|
-
return
|
|
99
|
+
return body;
|
|
100
100
|
}
|
|
101
101
|
catch (err) {
|
|
102
102
|
if (err instanceof HTTPError_1.HTTPError && err.status === 403) {
|
|
@@ -119,8 +119,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
119
119
|
async getLeagueWar(clanTag, options) {
|
|
120
120
|
const args = typeof clanTag === 'string' ? { clanTag } : { clanTag: clanTag.clanTag, round: clanTag.round };
|
|
121
121
|
const state = (args.round && Constants_1.CWLRounds[args.round]) ?? 'inWar'; // eslint-disable-line
|
|
122
|
-
const
|
|
123
|
-
const rounds =
|
|
122
|
+
const body = await this.getClanWarLeagueGroup(args.clanTag, options);
|
|
123
|
+
const rounds = body.rounds.filter((round) => !round.warTags.includes('#0'));
|
|
124
124
|
if (!rounds.length)
|
|
125
125
|
return null;
|
|
126
126
|
const num = state === 'preparation' ? -1 : state === 'warEnded' ? -3 : -2;
|
|
@@ -139,8 +139,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
139
139
|
}
|
|
140
140
|
/** Returns active wars (last 2) of the CWL group. */
|
|
141
141
|
async getLeagueWars(clanTag, options) {
|
|
142
|
-
const
|
|
143
|
-
return
|
|
142
|
+
const body = await this.getClanWarLeagueGroup(clanTag, options);
|
|
143
|
+
return body.getCurrentWars(clanTag, options);
|
|
144
144
|
}
|
|
145
145
|
/** Returns active wars (last 2 for CWL) of the clan. */
|
|
146
146
|
async getWars(clanTag, options) {
|
|
@@ -160,19 +160,19 @@ class Client extends node_events_1.EventEmitter {
|
|
|
160
160
|
}
|
|
161
161
|
/** Get info about clan war league. */
|
|
162
162
|
async getClanWarLeagueGroup(clanTag, options) {
|
|
163
|
-
const {
|
|
164
|
-
return new struct_1.ClanWarLeagueGroup(this,
|
|
163
|
+
const { body } = await this.rest.getClanWarLeagueGroup(clanTag, options);
|
|
164
|
+
return new struct_1.ClanWarLeagueGroup(this, body);
|
|
165
165
|
}
|
|
166
166
|
/** Get info about a CWL round by WarTag. */
|
|
167
167
|
async getClanWarLeagueRound(warTag, options) {
|
|
168
168
|
const args = typeof warTag === 'string' ? { warTag } : { warTag: warTag.warTag, clanTag: warTag.clanTag };
|
|
169
|
-
const {
|
|
170
|
-
return new struct_1.ClanWar(this,
|
|
169
|
+
const { body } = await this.rest.getClanWarLeagueRound(args.warTag, options);
|
|
170
|
+
return new struct_1.ClanWar(this, body, { warTag: args.warTag, clanTag: args.clanTag });
|
|
171
171
|
}
|
|
172
172
|
/** Get info about a player by tag. */
|
|
173
173
|
async getPlayer(playerTag, options) {
|
|
174
|
-
const {
|
|
175
|
-
return new struct_1.Player(this,
|
|
174
|
+
const { body } = await this.rest.getPlayer(playerTag, options);
|
|
175
|
+
return new struct_1.Player(this, body);
|
|
176
176
|
}
|
|
177
177
|
/** Get info about some players by their tags (fetches in parallel). */
|
|
178
178
|
async getPlayers(playerTags, options) {
|
|
@@ -182,43 +182,43 @@ class Client extends node_events_1.EventEmitter {
|
|
|
182
182
|
}
|
|
183
183
|
/** Verify Player API token that can be found from the Game settings. */
|
|
184
184
|
async verifyPlayerToken(playerTag, token, options) {
|
|
185
|
-
const {
|
|
186
|
-
return
|
|
185
|
+
const { body } = await this.rest.verifyPlayerToken(playerTag, token, options);
|
|
186
|
+
return body.status === 'ok';
|
|
187
187
|
}
|
|
188
188
|
/** Get a list of Leagues. */
|
|
189
189
|
async getLeagues(options) {
|
|
190
|
-
const {
|
|
191
|
-
return
|
|
190
|
+
const { body } = await this.rest.getLeagues(options);
|
|
191
|
+
return body.items;
|
|
192
192
|
}
|
|
193
193
|
/** Get a list of Leagues. */
|
|
194
194
|
async getBuilderBaseLeagues(options) {
|
|
195
|
-
const {
|
|
196
|
-
return
|
|
195
|
+
const { body } = await this.rest.getBuilderBaseLeagues(options);
|
|
196
|
+
return body.items;
|
|
197
197
|
}
|
|
198
198
|
/** Get a list of Capital Leagues. */
|
|
199
199
|
async getCapitalLeagues(options) {
|
|
200
|
-
const {
|
|
201
|
-
return
|
|
200
|
+
const { body } = await this.rest.getCapitalLeagues(options);
|
|
201
|
+
return body.items;
|
|
202
202
|
}
|
|
203
203
|
/** Get Legend League season Ids. */
|
|
204
204
|
async getLeagueSeasons(options) {
|
|
205
|
-
const {
|
|
206
|
-
return
|
|
205
|
+
const { body } = await this.rest.getLeagueSeasons(Constants_1.LegendLeagueId, options);
|
|
206
|
+
return body.items.map((league) => league.id);
|
|
207
207
|
}
|
|
208
208
|
/** Get Legend League season rankings by season Id. */
|
|
209
209
|
async getSeasonRankings(seasonId, options) {
|
|
210
|
-
const {
|
|
211
|
-
return
|
|
210
|
+
const { body } = await this.rest.getSeasonRankings(Constants_1.LegendLeagueId, seasonId, options);
|
|
211
|
+
return body.items.map((entry) => new struct_1.SeasonRankedPlayer(this, entry));
|
|
212
212
|
}
|
|
213
213
|
/** Get list of Clan War Leagues. */
|
|
214
214
|
async getWarLeagues(options) {
|
|
215
|
-
const {
|
|
216
|
-
return
|
|
215
|
+
const { body } = await this.rest.getWarLeagues(options);
|
|
216
|
+
return body.items;
|
|
217
217
|
}
|
|
218
218
|
/** Get list of Locations. */
|
|
219
219
|
async getLocations(options) {
|
|
220
|
-
const {
|
|
221
|
-
return
|
|
220
|
+
const { body } = await this.rest.getLocations(options);
|
|
221
|
+
return body.items.map((entry) => new struct_1.Location(entry));
|
|
222
222
|
}
|
|
223
223
|
/**
|
|
224
224
|
* Get clan rankings for a specific location.
|
|
@@ -226,8 +226,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
226
226
|
* For global ranking, use `global` as `locationId`.
|
|
227
227
|
*/
|
|
228
228
|
async getClanRanks(locationId, options) {
|
|
229
|
-
const {
|
|
230
|
-
return
|
|
229
|
+
const { body } = await this.rest.getClanRanks(locationId, options);
|
|
230
|
+
return body.items.map((entry) => new struct_1.RankedClan(entry));
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* Get player rankings for a specific location.
|
|
@@ -235,8 +235,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
235
235
|
* For global ranking, use `global` as `locationId`.
|
|
236
236
|
*/
|
|
237
237
|
async getPlayerRanks(locationId, options) {
|
|
238
|
-
const {
|
|
239
|
-
return
|
|
238
|
+
const { body } = await this.rest.getPlayerRanks(locationId, options);
|
|
239
|
+
return body.items.map((entry) => new struct_1.RankedPlayer(this, entry));
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
242
|
* Get clan builder base rankings for a specific location.
|
|
@@ -244,8 +244,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
244
244
|
* For global ranking, use `global` as `locationId`.
|
|
245
245
|
*/
|
|
246
246
|
async getBuilderBaseClanRanks(locationId, options) {
|
|
247
|
-
const {
|
|
248
|
-
return
|
|
247
|
+
const { body } = await this.rest.getBuilderBaseClanRanks(locationId, options);
|
|
248
|
+
return body.items.map((entry) => new struct_1.RankedClan(entry));
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
251
|
* Get player builder base rankings for a specific location.
|
|
@@ -253,8 +253,8 @@ class Client extends node_events_1.EventEmitter {
|
|
|
253
253
|
* For global ranking, use `global` as `locationId`.
|
|
254
254
|
*/
|
|
255
255
|
async getBuilderBasePlayerRanks(locationId, options) {
|
|
256
|
-
const {
|
|
257
|
-
return
|
|
256
|
+
const { body } = await this.rest.getBuilderBasePlayerRanks(locationId, options);
|
|
257
|
+
return body.items.map((entry) => new struct_1.RankedPlayer(this, entry));
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
260
|
* Get clan capital rankings for a specific location.
|
|
@@ -262,23 +262,23 @@ class Client extends node_events_1.EventEmitter {
|
|
|
262
262
|
* For global ranking, use `global` as `locationId`.
|
|
263
263
|
*/
|
|
264
264
|
async getClanCapitalRanks(locationId, options) {
|
|
265
|
-
const {
|
|
266
|
-
return
|
|
265
|
+
const { body } = await this.rest.getClanCapitalRanks(locationId, options);
|
|
266
|
+
return body.items;
|
|
267
267
|
}
|
|
268
268
|
/** Get list of clan labels. */
|
|
269
269
|
async getClanLabels(options) {
|
|
270
|
-
const {
|
|
271
|
-
return
|
|
270
|
+
const { body } = await this.rest.getClanLabels(options);
|
|
271
|
+
return body.items;
|
|
272
272
|
}
|
|
273
273
|
/** Get list of player labels. */
|
|
274
274
|
async getPlayerLabels(options) {
|
|
275
|
-
const {
|
|
276
|
-
return
|
|
275
|
+
const { body } = await this.rest.getPlayerLabels(options);
|
|
276
|
+
return body.items;
|
|
277
277
|
}
|
|
278
278
|
/** Get info about gold pass season. */
|
|
279
279
|
async getGoldPassSeason(options) {
|
|
280
|
-
const {
|
|
281
|
-
return new struct_1.GoldPassSeason(
|
|
280
|
+
const { body } = await this.rest.getGoldPassSeason(options);
|
|
281
|
+
return new struct_1.GoldPassSeason(body);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
exports.Client = Client;
|
|
@@ -155,7 +155,7 @@ class PollingClient extends Client_1.Client {
|
|
|
155
155
|
if (!(this.listenerCount(Constants_1.PollingEvents.MaintenanceStart) && this.listenerCount(Constants_1.PollingEvents.MaintenanceEnd)))
|
|
156
156
|
return;
|
|
157
157
|
try {
|
|
158
|
-
const res = await this.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
|
|
158
|
+
const { res } = await this.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
|
|
159
159
|
if (res.status === 200 && this.inMaintenance) {
|
|
160
160
|
this.inMaintenance = Boolean(false);
|
|
161
161
|
const duration = Date.now() - this._maintenanceStartTime.getTime();
|
|
@@ -53,63 +53,63 @@ export declare class RESTManager extends EventEmitter {
|
|
|
53
53
|
/** Set Clash of Clans API keys. */
|
|
54
54
|
setKeys(keys: string[]): this;
|
|
55
55
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
56
|
-
getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("../types").
|
|
56
|
+
getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("../types").Result<APIClanList>>;
|
|
57
57
|
/** Get info about a clan. */
|
|
58
|
-
getClan(clanTag: string, options?: OverrideOptions): Promise<import("../types").
|
|
58
|
+
getClan(clanTag: string, options?: OverrideOptions): Promise<import("../types").Result<APIClan>>;
|
|
59
59
|
/** Get list of clan members. */
|
|
60
|
-
getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("../types").
|
|
60
|
+
getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("../types").Result<APIClanMemberList>>;
|
|
61
61
|
/** Get clan war log. */
|
|
62
|
-
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("../types").
|
|
62
|
+
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("../types").Result<APIClanWarLog>>;
|
|
63
63
|
/** Get info about currently running war in the clan. */
|
|
64
|
-
getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("../types").
|
|
64
|
+
getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("../types").Result<APIClanWar>>;
|
|
65
65
|
/** Get info about clan war league. */
|
|
66
|
-
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("../types").
|
|
66
|
+
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("../types").Result<APIClanWarLeagueGroup>>;
|
|
67
67
|
/** Get info about a CWL round by WarTag. */
|
|
68
|
-
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("../types").
|
|
68
|
+
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("../types").Result<APIClanWar>>;
|
|
69
69
|
/** Retrieve clan's capital raid seasons. */
|
|
70
|
-
getCapitalRaidSeasons(tag: string, options?: SearchOptions): Promise<import("../types").
|
|
70
|
+
getCapitalRaidSeasons(tag: string, options?: SearchOptions): Promise<import("../types").Result<APICapitalRaidSeasons>>;
|
|
71
71
|
/** Get info about a player by tag. */
|
|
72
|
-
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("../types").
|
|
72
|
+
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("../types").Result<APIPlayer>>;
|
|
73
73
|
/** Verify Player API token that can be found from the Game settings. */
|
|
74
|
-
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("../types").
|
|
74
|
+
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("../types").Result<APIVerifyToken>>;
|
|
75
75
|
/** Get a list of Leagues. */
|
|
76
|
-
getLeagues(options?: SearchOptions): Promise<import("../types").
|
|
76
|
+
getLeagues(options?: SearchOptions): Promise<import("../types").Result<APILeagueList>>;
|
|
77
77
|
/** Get a League info. */
|
|
78
|
-
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").
|
|
78
|
+
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Result<APILeague>>;
|
|
79
79
|
/** Get a list of builder base leagues. */
|
|
80
|
-
getBuilderBaseLeagues(options?: SearchOptions): Promise<import("../types").
|
|
80
|
+
getBuilderBaseLeagues(options?: SearchOptions): Promise<import("../types").Result<APIBuilderBaseLeagueList>>;
|
|
81
81
|
/** Get a builder base league info. */
|
|
82
|
-
getBuilderBaseLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").
|
|
82
|
+
getBuilderBaseLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Result<APIBuilderBaseLeague>>;
|
|
83
83
|
/** Get a list of Capital leagues. */
|
|
84
|
-
getCapitalLeagues(options?: SearchOptions): Promise<import("../types").
|
|
84
|
+
getCapitalLeagues(options?: SearchOptions): Promise<import("../types").Result<APICapitalLeagueList>>;
|
|
85
85
|
/** Get a Capital League info. */
|
|
86
|
-
getCapitalLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").
|
|
86
|
+
getCapitalLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Result<APICapitalLeague>>;
|
|
87
87
|
/** Get Legend League season Ids. */
|
|
88
|
-
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("../types").
|
|
88
|
+
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("../types").Result<APILeagueSeasonList>>;
|
|
89
89
|
/** Get Legend League season rankings by season Id. */
|
|
90
|
-
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("../types").
|
|
90
|
+
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("../types").Result<APIPlayerSeasonRankingList>>;
|
|
91
91
|
/** Get list of Clan War Leagues. */
|
|
92
|
-
getWarLeagues(options?: SearchOptions): Promise<import("../types").
|
|
92
|
+
getWarLeagues(options?: SearchOptions): Promise<import("../types").Result<APIWarLeagueList>>;
|
|
93
93
|
/** Get info about a Clan War League. */
|
|
94
|
-
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("../types").
|
|
94
|
+
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("../types").Result<APIWarLeague>>;
|
|
95
95
|
/** Get list of Locations. */
|
|
96
|
-
getLocations(options?: SearchOptions): Promise<import("../types").
|
|
96
|
+
getLocations(options?: SearchOptions): Promise<import("../types").Result<APILocationList>>;
|
|
97
97
|
/** Get info about a Location. */
|
|
98
|
-
getLocation(locationId: number, options?: OverrideOptions): Promise<import("../types").
|
|
98
|
+
getLocation(locationId: number, options?: OverrideOptions): Promise<import("../types").Result<APILocation>>;
|
|
99
99
|
/** Get clan rankings for a specific location. */
|
|
100
|
-
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").
|
|
100
|
+
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Result<APIClanRankingList>>;
|
|
101
101
|
/** Get player rankings for a specific location. */
|
|
102
|
-
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").
|
|
102
|
+
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Result<APIPlayerRankingList>>;
|
|
103
103
|
/** Get clan builder base rankings for a specific location. */
|
|
104
|
-
getBuilderBaseClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").
|
|
104
|
+
getBuilderBaseClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Result<APIClanBuilderBaseRankingList>>;
|
|
105
105
|
/** Get player builder base rankings for a specific location. */
|
|
106
|
-
getBuilderBasePlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").
|
|
106
|
+
getBuilderBasePlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Result<APIPlayerBuilderBaseRankingList>>;
|
|
107
107
|
/** Get clan capital rankings for a specific location. */
|
|
108
|
-
getClanCapitalRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").
|
|
108
|
+
getClanCapitalRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Result<APIClanCapitalRankingList>>;
|
|
109
109
|
/** Get list of clan labels. */
|
|
110
|
-
getClanLabels(options?: SearchOptions): Promise<import("../types").
|
|
110
|
+
getClanLabels(options?: SearchOptions): Promise<import("../types").Result<APILabelList>>;
|
|
111
111
|
/** Get list of player labels. */
|
|
112
|
-
getPlayerLabels(options?: SearchOptions): Promise<import("../types").
|
|
112
|
+
getPlayerLabels(options?: SearchOptions): Promise<import("../types").Result<APILabelList>>;
|
|
113
113
|
/** Get info about gold pass season. */
|
|
114
|
-
getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").
|
|
114
|
+
getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").Result<APIGoldPassSeason>>;
|
|
115
115
|
}
|
package/dist/rest/RESTManager.js
CHANGED
|
@@ -75,8 +75,11 @@ class RESTManager extends node_events_1.EventEmitter {
|
|
|
75
75
|
}
|
|
76
76
|
/** Verify Player API token that can be found from the Game settings. */
|
|
77
77
|
verifyPlayerToken(playerTag, token, options) {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, {
|
|
79
|
+
body: JSON.stringify({ token }),
|
|
80
|
+
method: 'POST',
|
|
81
|
+
...options
|
|
82
|
+
});
|
|
80
83
|
}
|
|
81
84
|
/** Get a list of Leagues. */
|
|
82
85
|
getLeagues(options) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { LoginOptions, RequestHandlerOptions, RequestOptions,
|
|
3
|
+
import { LoginOptions, RequestHandlerOptions, RequestOptions, Result } from '../types';
|
|
4
4
|
import { IRestEvents } from './RESTManager';
|
|
5
5
|
export interface RequestHandler {
|
|
6
6
|
emit: (<K extends keyof IRestEvents>(event: K, ...args: IRestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, ...args: any[]) => boolean);
|
|
@@ -48,8 +48,9 @@ export declare class RequestHandler extends EventEmitter {
|
|
|
48
48
|
private get _keys();
|
|
49
49
|
private get _key();
|
|
50
50
|
setKeys(keys: string[]): this;
|
|
51
|
-
private get
|
|
52
|
-
request<T>(path: string, options?: RequestOptions): Promise<
|
|
51
|
+
private get credentials();
|
|
52
|
+
request<T>(path: string, options?: RequestOptions): Promise<Result<T>>;
|
|
53
|
+
rawRequest<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
53
54
|
private exec;
|
|
54
55
|
init(options: LoginOptions): Promise<string[]>;
|
|
55
56
|
private reValidateKeys;
|
|
@@ -52,51 +52,67 @@ class RequestHandler extends node_events_1.EventEmitter {
|
|
|
52
52
|
this.keys = keys;
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
|
-
get
|
|
55
|
+
get credentials() {
|
|
56
56
|
return Boolean(this.email && this.password);
|
|
57
57
|
}
|
|
58
58
|
async request(path, options = {}) {
|
|
59
59
|
const cached = this.cached ? (await this.cached.get(path)) ?? null : null;
|
|
60
60
|
if (cached && options.force !== true) {
|
|
61
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
body: cached.body,
|
|
63
|
+
res: { maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 }
|
|
64
|
+
};
|
|
62
65
|
}
|
|
63
66
|
if (!this.throttler || options.ignoreRateLimit)
|
|
64
67
|
return this.exec(path, options);
|
|
65
68
|
await this.throttler.wait();
|
|
66
69
|
return this.exec(path, options);
|
|
67
70
|
}
|
|
71
|
+
async rawRequest(path, options = {}) {
|
|
72
|
+
const cached = this.cached ? (await this.cached.get(path)) ?? null : null;
|
|
73
|
+
if (cached && options.force !== true) {
|
|
74
|
+
return cached.body;
|
|
75
|
+
}
|
|
76
|
+
if (!this.throttler || options.ignoreRateLimit)
|
|
77
|
+
return this.exec(path, options).then((res) => res.body);
|
|
78
|
+
await this.throttler.wait();
|
|
79
|
+
return this.exec(path, options).then((res) => res.body);
|
|
80
|
+
}
|
|
68
81
|
async exec(path, options = {}, retries = 0) {
|
|
69
82
|
try {
|
|
70
83
|
const res = await this.dispatcher.request({
|
|
71
84
|
path: `/v1${path}`,
|
|
72
85
|
body: options.body,
|
|
73
|
-
method: 'GET',
|
|
86
|
+
method: options.method ?? 'GET',
|
|
74
87
|
signal: (0, Util_1.timeoutSignal)(options.restRequestTimeout ?? this.restRequestTimeout),
|
|
75
88
|
headers: { 'Authorization': `Bearer ${this._key}`, 'Content-Type': 'application/json' }
|
|
76
89
|
});
|
|
77
90
|
if (res.statusCode === 504 && retries < (options.retryLimit ?? this.retryLimit)) {
|
|
78
91
|
return await this.exec(path, options, ++retries);
|
|
79
92
|
}
|
|
80
|
-
const
|
|
81
|
-
if (this.
|
|
93
|
+
const body = (await res.body.json());
|
|
94
|
+
if (this.credentials &&
|
|
82
95
|
res.statusCode === 403 &&
|
|
83
|
-
|
|
96
|
+
body?.reason === 'accessDenied.invalidIp' &&
|
|
84
97
|
retries < (options.retryLimit ?? this.retryLimit)) {
|
|
85
|
-
const keys = await this.reValidateKeys().then(() =>
|
|
98
|
+
const keys = await this.reValidateKeys().then(() => this.login());
|
|
86
99
|
if (keys.length)
|
|
87
100
|
return await this.exec(path, options, ++retries);
|
|
88
101
|
}
|
|
89
102
|
const maxAge = Number(res.headers['cache-control']?.split('=')?.[1] ?? 0) * 1000;
|
|
90
|
-
if (res.statusCode === 403 && !
|
|
103
|
+
if (res.statusCode === 403 && !body?.message && this.rejectIfNotValid) {
|
|
91
104
|
throw new HTTPError_1.HTTPError(HTTPError_1.PrivateWarLogError, res.statusCode, path, maxAge);
|
|
92
105
|
}
|
|
93
106
|
if (res.statusCode !== 200 && this.rejectIfNotValid) {
|
|
94
|
-
throw new HTTPError_1.HTTPError(
|
|
107
|
+
throw new HTTPError_1.HTTPError(body, res.statusCode, path, maxAge, options.method);
|
|
95
108
|
}
|
|
96
109
|
if (this.cached && maxAge > 0 && options.cache !== false && res.statusCode === 200) {
|
|
97
|
-
await this.cached.set(path, {
|
|
110
|
+
await this.cached.set(path, { body, ttl: Date.now() + maxAge, status: res.statusCode }, maxAge);
|
|
98
111
|
}
|
|
99
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
body: body,
|
|
114
|
+
res: { maxAge, status: res.statusCode, path, ok: res.statusCode === 200 }
|
|
115
|
+
};
|
|
100
116
|
}
|
|
101
117
|
catch (error) {
|
|
102
118
|
if (error.code === 'UND_ERR_ABORTED' && retries < (options.retryLimit ?? this.retryLimit)) {
|
|
@@ -104,7 +120,10 @@ class RequestHandler extends node_events_1.EventEmitter {
|
|
|
104
120
|
}
|
|
105
121
|
if (this.rejectIfNotValid)
|
|
106
122
|
throw error;
|
|
107
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
body: { message: error.message },
|
|
125
|
+
res: { maxAge: 0, status: 500, path, ok: false }
|
|
126
|
+
};
|
|
108
127
|
}
|
|
109
128
|
}
|
|
110
129
|
async init(options) {
|
|
@@ -115,8 +134,7 @@ class RequestHandler extends node_events_1.EventEmitter {
|
|
|
115
134
|
this.keyCount = Math.min(options.keyCount ?? 1, 10);
|
|
116
135
|
this.password = options.password;
|
|
117
136
|
this.email = options.email;
|
|
118
|
-
|
|
119
|
-
return this.login();
|
|
137
|
+
return this.reValidateKeys().then(() => this.login());
|
|
120
138
|
}
|
|
121
139
|
async reValidateKeys() {
|
|
122
140
|
for (const key of this.keys) {
|
package/dist/struct/ClanWar.d.ts
CHANGED
|
@@ -132,12 +132,9 @@ export declare class ClanWar {
|
|
|
132
132
|
opponent: WarClan;
|
|
133
133
|
/** The war's unique tag. This is `null` unless this is a CWL. */
|
|
134
134
|
warTag: string | null;
|
|
135
|
-
/** Maximum number of milliseconds the results can be cached. */
|
|
136
|
-
maxAge: number;
|
|
137
135
|
constructor(client: Client, data: APIClanWar, extra: {
|
|
138
136
|
clanTag?: string;
|
|
139
137
|
warTag?: string;
|
|
140
|
-
maxAge: number;
|
|
141
138
|
});
|
|
142
139
|
/** Return a {@link ClanWarMember} with the tag provided. */
|
|
143
140
|
getMember(tag: string): ClanWarMember | null;
|
package/dist/struct/ClanWar.js
CHANGED
package/dist/types/lib.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Dispatcher } from 'undici';
|
|
1
2
|
import { BatchThrottler, QueueThrottler } from '../rest/Throttler';
|
|
2
3
|
export interface Store<T = any> {
|
|
3
4
|
set: (key: string, value: T, ttl?: number) => boolean | Promise<boolean>;
|
|
@@ -89,19 +90,21 @@ export interface RequestOptions extends OverrideOptions {
|
|
|
89
90
|
/** The request body. */
|
|
90
91
|
body?: string;
|
|
91
92
|
/** The request method. */
|
|
92
|
-
method?:
|
|
93
|
+
method?: Dispatcher.HttpMethod;
|
|
93
94
|
}
|
|
94
|
-
export interface
|
|
95
|
-
/** Whether the response is ok. */
|
|
96
|
-
ok: boolean;
|
|
95
|
+
export interface Result<T> {
|
|
97
96
|
/** The response body. */
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
body: T;
|
|
98
|
+
res: {
|
|
99
|
+
/** Whether the response is ok. */
|
|
100
|
+
ok: boolean;
|
|
101
|
+
/** Path of the request for this response. */
|
|
102
|
+
path: string;
|
|
103
|
+
/** HTTP status code of this response. */
|
|
104
|
+
status: number;
|
|
105
|
+
/** The maxAge of this response. */
|
|
106
|
+
maxAge: number;
|
|
107
|
+
};
|
|
105
108
|
}
|
|
106
109
|
/**
|
|
107
110
|
* Clan search options for a request.
|
package/package.json
CHANGED