clashofclans.js 3.1.3-dev.4e06857 → 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.
@@ -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 { data } = await this.rest.getClans(query, options);
52
+ const { body } = await this.rest.getClans(query, options);
53
53
  // @ts-expect-error
54
- return data.items.map((clan) => new struct_1.Clan(this, clan));
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 { data } = await this.rest.getClan(clanTag, options);
59
- return new struct_1.Clan(this, data);
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 { data } = await this.rest.getClanMembers(clanTag, options);
64
- return data.items.map((entry) => new struct_1.ClanMember(this, entry));
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 { data } = await this.rest.getCapitalRaidSeasons(tag, options);
69
- return data.items.map((entry) => new CapitalRaidSeason_1.CapitalRaidSeason(this, entry));
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 { data } = await this.rest.getClanWarLog(clanTag, options);
74
- return data.items.map((entry) => new struct_1.ClanWarLog(this, entry));
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 { data, maxAge } = await this.rest.getCurrentWar(clanTag, options);
79
- return new struct_1.ClanWar(this, data, { clanTag, maxAge });
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 data = await this.getClanWar(args.clanTag, options);
96
- if (data.state === 'notInWar') {
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 data;
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 data = await this.getClanWarLeagueGroup(args.clanTag, options);
123
- const rounds = data.rounds.filter((round) => !round.warTags.includes('#0'));
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 data = await this.getClanWarLeagueGroup(clanTag, options);
143
- return data.getCurrentWars(clanTag, options);
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 { data } = await this.rest.getClanWarLeagueGroup(clanTag, options);
164
- return new struct_1.ClanWarLeagueGroup(this, data);
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 { data, maxAge } = await this.rest.getClanWarLeagueRound(args.warTag, options);
170
- return new struct_1.ClanWar(this, data, { warTag: args.warTag, clanTag: args.clanTag, maxAge });
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 { data } = await this.rest.getPlayer(playerTag, options);
175
- return new struct_1.Player(this, data);
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 { data } = await this.rest.verifyPlayerToken(playerTag, token, options);
186
- return data.status === 'ok';
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 { data } = await this.rest.getLeagues(options);
191
- return data.items;
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 { data } = await this.rest.getBuilderBaseLeagues(options);
196
- return data.items;
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 { data } = await this.rest.getCapitalLeagues(options);
201
- return data.items;
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 { data } = await this.rest.getLeagueSeasons(Constants_1.LegendLeagueId, options);
206
- return data.items.map((league) => league.id);
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 { data } = await this.rest.getSeasonRankings(Constants_1.LegendLeagueId, seasonId, options);
211
- return data.items.map((entry) => new struct_1.SeasonRankedPlayer(this, entry));
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 { data } = await this.rest.getWarLeagues(options);
216
- return data.items;
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 { data } = await this.rest.getLocations(options);
221
- return data.items.map((entry) => new struct_1.Location(entry));
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 { data } = await this.rest.getClanRanks(locationId, options);
230
- return data.items.map((entry) => new struct_1.RankedClan(entry));
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 { data } = await this.rest.getPlayerRanks(locationId, options);
239
- return data.items.map((entry) => new struct_1.RankedPlayer(this, entry));
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 { data } = await this.rest.getBuilderBaseClanRanks(locationId, options);
248
- return data.items.map((entry) => new struct_1.RankedClan(entry));
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 { data } = await this.rest.getBuilderBasePlayerRanks(locationId, options);
257
- return data.items.map((entry) => new struct_1.RankedPlayer(this, entry));
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 { data } = await this.rest.getClanCapitalRanks(locationId, options);
266
- return data.items;
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 { data } = await this.rest.getClanLabels(options);
271
- return data.items;
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 { data } = await this.rest.getPlayerLabels(options);
276
- return data.items;
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 { data } = await this.rest.getGoldPassSeason(options);
281
- return new struct_1.GoldPassSeason(data);
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").Response<APIClanList>>;
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").Response<APIClan>>;
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").Response<APIClanMemberList>>;
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").Response<APIClanWarLog>>;
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").Response<APIClanWar>>;
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").Response<APIClanWarLeagueGroup>>;
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").Response<APIClanWar>>;
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").Response<APICapitalRaidSeasons>>;
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").Response<APIPlayer>>;
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").Response<APIVerifyToken>>;
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").Response<APILeagueList>>;
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").Response<APILeague>>;
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").Response<APIBuilderBaseLeagueList>>;
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").Response<APIBuilderBaseLeague>>;
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").Response<APICapitalLeagueList>>;
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").Response<APICapitalLeague>>;
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").Response<APILeagueSeasonList>>;
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").Response<APIPlayerSeasonRankingList>>;
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").Response<APIWarLeagueList>>;
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").Response<APIWarLeague>>;
94
+ getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("../types").Result<APIWarLeague>>;
95
95
  /** Get list of Locations. */
96
- getLocations(options?: SearchOptions): Promise<import("../types").Response<APILocationList>>;
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").Response<APILocation>>;
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").Response<APIClanRankingList>>;
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").Response<APIPlayerRankingList>>;
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").Response<APIClanBuilderBaseRankingList>>;
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").Response<APIPlayerBuilderBaseRankingList>>;
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").Response<APIClanCapitalRankingList>>;
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").Response<APILabelList>>;
110
+ getClanLabels(options?: SearchOptions): Promise<import("../types").Result<APILabelList>>;
111
111
  /** Get list of player labels. */
112
- getPlayerLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
112
+ getPlayerLabels(options?: SearchOptions): Promise<import("../types").Result<APILabelList>>;
113
113
  /** Get info about gold pass season. */
114
- getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").Response<APIGoldPassSeason>>;
114
+ getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").Result<APIGoldPassSeason>>;
115
115
  }
@@ -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
- const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
79
- return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, opts);
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, Response } from '../types';
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 creds();
52
- request<T>(path: string, options?: RequestOptions): Promise<Response<T>>;
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;
@@ -36,8 +36,8 @@ class RequestHandler extends node_events_1.EventEmitter {
36
36
  else
37
37
  this.cached = options?.cache === true ? new Store_1.CacheStore() : null;
38
38
  this.dispatcher = new undici_1.Pool(new URL(this.baseURL).origin, {
39
- connections: 50,
40
- pipelining: 10
39
+ connections: options?.connections ?? null,
40
+ pipelining: options?.pipelining ?? 1
41
41
  });
42
42
  }
43
43
  get _keys() {
@@ -52,51 +52,67 @@ class RequestHandler extends node_events_1.EventEmitter {
52
52
  this.keys = keys;
53
53
  return this;
54
54
  }
55
- get creds() {
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 { data: cached.data, maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 };
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 data = (await res.body.json());
81
- if (this.creds &&
93
+ const body = (await res.body.json());
94
+ if (this.credentials &&
82
95
  res.statusCode === 403 &&
83
- data?.reason === 'accessDenied.invalidIp' &&
96
+ body?.reason === 'accessDenied.invalidIp' &&
84
97
  retries < (options.retryLimit ?? this.retryLimit)) {
85
- const keys = await this.reValidateKeys().then(() => () => this.login());
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 && !data?.message && this.rejectIfNotValid) {
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(data, res.statusCode, path, maxAge, options.method);
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, { data, ttl: Date.now() + maxAge, status: res.statusCode }, maxAge);
110
+ await this.cached.set(path, { body, ttl: Date.now() + maxAge, status: res.statusCode }, maxAge);
98
111
  }
99
- return { data: data, maxAge, status: res.statusCode, path, ok: res.statusCode === 200 };
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 { data: { message: error.message }, maxAge: 0, status: 500, path, ok: false };
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
- await this.reValidateKeys();
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) {
@@ -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;
@@ -164,7 +164,6 @@ class ClanWar {
164
164
  this.clan = new WarClan(this, clan);
165
165
  this.opponent = new WarClan(this, opponent);
166
166
  }
167
- this.maxAge = extra.maxAge;
168
167
  }
169
168
  /** Return a {@link ClanWarMember} with the tag provided. */
170
169
  getMember(tag) {
@@ -46,7 +46,7 @@ export declare class ClanWarLeagueRound {
46
46
  export declare class ClanWarLeagueGroup {
47
47
  private readonly client;
48
48
  /** The CWL group's current war state. */
49
- state: 'preparation' | 'inWar' | 'ended';
49
+ state: 'preparation' | 'inWar' | 'ended' | 'notInWar';
50
50
  /** Season Id of this CWL group. */
51
51
  season: string;
52
52
  /** Returns all participating clans. */
@@ -54,6 +54,8 @@ export declare class ClanWarLeagueGroup {
54
54
  /** An array containing all war tags for each round. */
55
55
  rounds: ClanWarLeagueRound[];
56
56
  constructor(client: Client, data: APIClanWarLeagueGroup);
57
+ /** Whether the clan is not in CWL group. */
58
+ get isNotInWar(): boolean;
57
59
  /** Total number of rounds for this CWL. */
58
60
  get totalRounds(): number;
59
61
  /**
@@ -49,11 +49,16 @@ exports.ClanWarLeagueRound = ClanWarLeagueRound;
49
49
  class ClanWarLeagueGroup {
50
50
  constructor(client, data) {
51
51
  this.client = client;
52
- // @ts-expect-error
53
52
  this.state = data.state;
54
- this.season = data.season;
55
- this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
56
- this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
53
+ if (this.state !== 'notInWar') {
54
+ this.season = data.season;
55
+ this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
56
+ this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
57
+ }
58
+ }
59
+ /** Whether the clan is not in CWL group. */
60
+ get isNotInWar() {
61
+ return this.state === 'notInWar';
57
62
  }
58
63
  /** Total number of rounds for this CWL. */
59
64
  get totalRounds() {
@@ -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>;
@@ -50,6 +51,10 @@ export interface PollingClientOptions extends ClientOptions {
50
51
  export interface RequestHandlerOptions extends ClientOptions {
51
52
  /** Set this `false` to use `res.ok` property. */
52
53
  rejectIfNotValid?: boolean;
54
+ /** The max number of clients to create. null if no limit. Default null. */
55
+ connections?: number;
56
+ /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to RFC7230. Default: 1 */
57
+ pipelining?: number;
53
58
  }
54
59
  /** Search options for request. */
55
60
  export interface SearchOptions extends OverrideOptions {
@@ -85,19 +90,21 @@ export interface RequestOptions extends OverrideOptions {
85
90
  /** The request body. */
86
91
  body?: string;
87
92
  /** The request method. */
88
- method?: string;
93
+ method?: Dispatcher.HttpMethod;
89
94
  }
90
- export interface Response<T> {
91
- /** Whether the response is ok. */
92
- ok: boolean;
95
+ export interface Result<T> {
93
96
  /** The response body. */
94
- data: T;
95
- /** Path of the request for this response. */
96
- path: string;
97
- /** HTTP status code of this response. */
98
- status: number;
99
- /** The maxAge of this response. */
100
- maxAge: number;
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
+ };
101
108
  }
102
109
  /**
103
110
  * Clan search options for a request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.1.3-dev.4e06857",
3
+ "version": "3.1.4-dev.68bb5bc",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",