clashofclans.js 2.8.2 → 3.0.0-dev.29c3270

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.
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RESTManager = void 0;
4
- const RequestHandler_1 = require("./RequestHandler");
4
+ const node_events_1 = require("node:events");
5
5
  const Util_1 = require("../util/Util");
6
+ const Constants_1 = require("../util/Constants");
7
+ const RequestHandler_1 = require("./RequestHandler");
6
8
  /** Represents a REST Manager of the client. */
7
- class RESTManager {
9
+ class RESTManager extends node_events_1.EventEmitter {
8
10
  constructor(options) {
9
- this.handler = new RequestHandler_1.RequestHandler(options);
11
+ super();
12
+ this.requestHandler = new RequestHandler_1.RequestHandler(options)
13
+ .on(Constants_1.RestEvents.Debug, this.emit.bind(this, Constants_1.RestEvents.Debug))
14
+ .on(Constants_1.RestEvents.Error, this.emit.bind(this, Constants_1.RestEvents.Error))
15
+ .on(Constants_1.RestEvents.RateLimited, this.emit.bind(this, Constants_1.RestEvents.RateLimited));
10
16
  }
11
17
  /** Contains various general-purpose utility methods. */
12
18
  get util() {
@@ -21,122 +27,122 @@ class RESTManager {
21
27
  * ```
22
28
  */
23
29
  login(options) {
24
- return this.handler.init(options);
30
+ return this.requestHandler.init(options);
25
31
  }
26
32
  /** Set Clash of Clans API keys. */
27
33
  setKeys(keys) {
28
- this.handler.setKeys(keys);
34
+ this.requestHandler.setKeys(keys);
29
35
  return this;
30
36
  }
31
37
  /** Search all clans by name and/or filtering the results using various criteria. */
32
38
  getClans(query, options) {
33
- return this.handler.request(`/clans${Util_1.Util.queryString(query)}`, options);
39
+ return this.requestHandler.request(`/clans${Util_1.Util.queryString(query)}`, options);
34
40
  }
35
41
  /** Get info about a clan. */
36
42
  getClan(clanTag, options) {
37
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}`, options);
43
+ return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}`, options);
38
44
  }
39
45
  /** Get list of clan members. */
40
46
  getClanMembers(clanTag, options) {
41
47
  const query = Util_1.Util.queryString(options);
42
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members${query}`, options);
48
+ return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members${query}`, options);
43
49
  }
44
50
  /** Get clan war log. */
45
51
  getClanWarLog(clanTag, options) {
46
52
  const query = Util_1.Util.queryString(options);
47
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog${query}`, options);
53
+ return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog${query}`, options);
48
54
  }
49
55
  /** Get info about currently running war in the clan. */
50
56
  getCurrentWar(clanTag, options) {
51
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar`, options);
57
+ return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar`, options);
52
58
  }
53
59
  /** Get info about clan war league. */
54
60
  getClanWarLeagueGroup(clanTag, options) {
55
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar/leaguegroup`, options);
61
+ return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar/leaguegroup`, options);
56
62
  }
57
63
  /** Get info about a CWL round by WarTag. */
58
64
  getClanWarLeagueRound(warTag, options) {
59
- return this.handler.request(`/clanwarleagues/wars/${Util_1.Util.encodeURI(warTag)}`, options);
65
+ return this.requestHandler.request(`/clanwarleagues/wars/${Util_1.Util.encodeURI(warTag)}`, options);
60
66
  }
61
67
  /** Get info about a player by tag. */
62
68
  getPlayer(playerTag, options) {
63
- return this.handler.request(`/players/${Util_1.Util.encodeURI(playerTag)}`, options);
69
+ return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}`, options);
64
70
  }
65
71
  /** Verify Player API token that can be found from the Game settings. */
66
72
  verifyPlayerToken(playerTag, token, options) {
67
73
  const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
68
- return this.handler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, opts);
74
+ return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, opts);
69
75
  }
70
76
  /** Get list of Leagues. */
71
77
  getLeagues(options) {
72
78
  const query = Util_1.Util.queryString(options);
73
- return this.handler.request(`/leagues${query}`, options);
79
+ return this.requestHandler.request(`/leagues${query}`, options);
74
80
  }
75
81
  /** Get a League info. */
76
82
  getLeague(leagueId, options) {
77
- return this.handler.request(`/leagues/${leagueId}`, options);
83
+ return this.requestHandler.request(`/leagues/${leagueId}`, options);
78
84
  }
79
85
  /** Get Legend League season Ids. */
80
86
  getLeagueSeasons(leagueId, options) {
81
87
  const query = Util_1.Util.queryString(options);
82
- return this.handler.request(`/leagues/${leagueId}/seasons${query}`, options);
88
+ return this.requestHandler.request(`/leagues/${leagueId}/seasons${query}`, options);
83
89
  }
84
90
  /** Get Legend League season rankings by season Id. */
85
91
  getSeasonRankings(leagueId, seasonId, options) {
86
92
  const query = Util_1.Util.queryString(options);
87
- return this.handler.request(`/leagues/${leagueId}/seasons/${seasonId}${query}`, options);
93
+ return this.requestHandler.request(`/leagues/${leagueId}/seasons/${seasonId}${query}`, options);
88
94
  }
89
95
  /** Get list of Clan War Leagues. */
90
96
  getWarLeagues(options) {
91
97
  const query = Util_1.Util.queryString(options);
92
- return this.handler.request(`/warleagues${query}`, options);
98
+ return this.requestHandler.request(`/warleagues${query}`, options);
93
99
  }
94
100
  /** Get info about a Clan War League. */
95
101
  getWarLeague(leagueId, options) {
96
- return this.handler.request(`/warleagues/${leagueId}`, options);
102
+ return this.requestHandler.request(`/warleagues/${leagueId}`, options);
97
103
  }
98
104
  /** Get list of Locations. */
99
105
  getLocations(options) {
100
106
  const query = Util_1.Util.queryString(options);
101
- return this.handler.request(`/locations${query}`, options);
107
+ return this.requestHandler.request(`/locations${query}`, options);
102
108
  }
103
109
  /** Get info about a Location. */
104
110
  getLocation(locationId, options) {
105
- return this.handler.request(`/locations/${locationId}`, options);
111
+ return this.requestHandler.request(`/locations/${locationId}`, options);
106
112
  }
107
113
  /** Get clan rankings for a specific location. */
108
114
  getClanRanks(locationId, options) {
109
115
  const query = Util_1.Util.queryString(options);
110
- return this.handler.request(`/locations/${locationId}/rankings/clans${query}`, options);
116
+ return this.requestHandler.request(`/locations/${locationId}/rankings/clans${query}`, options);
111
117
  }
112
118
  /** Get player rankings for a specific location. */
113
119
  getPlayerRanks(locationId, options) {
114
120
  const query = Util_1.Util.queryString(options);
115
- return this.handler.request(`/locations/${locationId}/rankings/players${query}`, options);
121
+ return this.requestHandler.request(`/locations/${locationId}/rankings/players${query}`, options);
116
122
  }
117
123
  /** Get clan versus rankings for a specific location. */
118
124
  getVersusClanRanks(locationId, options) {
119
125
  const query = Util_1.Util.queryString(options);
120
- return this.handler.request(`/locations/${locationId}/rankings/clans-versus${query}`, options);
126
+ return this.requestHandler.request(`/locations/${locationId}/rankings/clans-versus${query}`, options);
121
127
  }
122
128
  /** Get player versus rankings for a specific location. */
123
129
  getVersusPlayerRanks(locationId, options) {
124
130
  const query = Util_1.Util.queryString(options);
125
- return this.handler.request(`/locations/${locationId}/rankings/players-versus${query}`, options);
131
+ return this.requestHandler.request(`/locations/${locationId}/rankings/players-versus${query}`, options);
126
132
  }
127
133
  /** Get list of clan labels. */
128
134
  getClanLabels(options) {
129
135
  const query = Util_1.Util.queryString(options);
130
- return this.handler.request(`/labels/clans${query}`, options);
136
+ return this.requestHandler.request(`/labels/clans${query}`, options);
131
137
  }
132
138
  /** Get list of player labels. */
133
139
  getPlayerLabels(options) {
134
140
  const query = Util_1.Util.queryString(options);
135
- return this.handler.request(`/labels/players${query}`, options);
141
+ return this.requestHandler.request(`/labels/players${query}`, options);
136
142
  }
137
143
  /** Get info about gold pass season. */
138
144
  getGoldPassSeason(options) {
139
- return this.handler.request('/goldpass/seasons/current', options);
145
+ return this.requestHandler.request('/goldpass/seasons/current', options);
140
146
  }
141
147
  }
142
148
  exports.RESTManager = RESTManager;
@@ -1,6 +1,34 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'node:events';
1
3
  import { Response, RequestOptions, LoginOptions, RequestHandlerOptions } from '../types';
2
- /** Represents a Request Handler. */
3
- export declare class RequestHandler {
4
+ import { IRestEvents } from './RESTManager';
5
+ export interface RequestHandler {
6
+ emit: (<K extends keyof IRestEvents>(event: K, ...args: IRestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, ...args: any[]) => boolean);
7
+ off: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
8
+ on: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
9
+ once: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
10
+ removeAllListeners: (<K extends keyof IRestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IRestEvents>) => this);
11
+ /**
12
+ * Emitted for general debugging information.
13
+ * @public
14
+ * @event
15
+ */
16
+ debug: string;
17
+ /**
18
+ * Emitted when the client encounters an error.
19
+ * @public
20
+ * @event
21
+ */
22
+ error: string;
23
+ /**
24
+ * Emitted when the client is rate limited.
25
+ * @public
26
+ * @event
27
+ */
28
+ rateLimited: string;
29
+ }
30
+ /** Represents the class that manages handlers for endpoints. */
31
+ export declare class RequestHandler extends EventEmitter {
4
32
  #private;
5
33
  private email;
6
34
  private password;
@@ -16,21 +16,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  var _RequestHandler_keyIndex;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.RequestHandler = void 0;
19
+ const node_https_1 = __importDefault(require("node:https"));
20
+ const node_events_1 = require("node:events");
21
+ const node_fetch_1 = __importDefault(require("node-fetch"));
19
22
  const Constants_1 = require("../util/Constants");
20
- const HTTPError_1 = require("./HTTPError");
21
23
  const Store_1 = require("../util/Store");
22
- const node_fetch_1 = __importDefault(require("node-fetch"));
23
- const https_1 = __importDefault(require("https"));
24
+ const HTTPError_1 = require("./HTTPError");
24
25
  const IP_REGEX = /\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/g;
25
- const agent = new https_1.default.Agent({ keepAlive: true });
26
- /** Represents a Request Handler. */
27
- class RequestHandler {
26
+ const agent = new node_https_1.default.Agent({ keepAlive: true });
27
+ /** Represents the class that manages handlers for endpoints. */
28
+ class RequestHandler extends node_events_1.EventEmitter {
28
29
  constructor(options) {
30
+ super();
29
31
  _RequestHandler_keyIndex.set(this, 0); // eslint-disable-line
30
32
  this.keys = options?.keys ?? [];
31
33
  this.retryLimit = options?.retryLimit ?? 0;
32
34
  this.throttler = options?.throttler ?? null;
33
- this.baseURL = options?.baseURL ?? Constants_1.API_BASE_URL;
35
+ this.baseURL = options?.baseURL ?? Constants_1.APIBaseURL;
34
36
  this.restRequestTimeout = options?.restRequestTimeout ?? 0;
35
37
  this.rejectIfNotValid = options?.rejectIfNotValid ?? true;
36
38
  if (typeof options?.cache === 'object')
@@ -89,6 +91,10 @@ class RequestHandler {
89
91
  if (!res?.ok && this.rejectIfNotValid) {
90
92
  throw new HTTPError_1.HTTPError(data, res?.status ?? 504, path, maxAge, options.method);
91
93
  }
94
+ if (res?.status === 429) {
95
+ this.emit(Constants_1.RestEvents.RateLimited, path, res.status, options.method);
96
+ }
97
+ this.emit(Constants_1.RestEvents.Debug, path, res?.status ?? 504, options.method);
92
98
  if (this.cached && maxAge > 0 && options.cache !== false && res?.ok) {
93
99
  await this.cached.set(path, { data, ttl: Date.now() + maxAge, status: res.status }, maxAge);
94
100
  }
@@ -120,7 +126,7 @@ class RequestHandler {
120
126
  }
121
127
  }
122
128
  async login() {
123
- const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/login`, {
129
+ const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/login`, {
124
130
  method: 'POST',
125
131
  timeout: 10000,
126
132
  headers: { 'Content-Type': 'application/json' },
@@ -135,7 +141,7 @@ class RequestHandler {
135
141
  return this.getKeys(res.headers.get('set-cookie'), ip);
136
142
  }
137
143
  async getKeys(cookie, ip) {
138
- const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/list`, {
144
+ const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/list`, {
139
145
  method: 'POST',
140
146
  timeout: 10000,
141
147
  headers: { 'Content-Type': 'application/json', cookie }
@@ -177,7 +183,7 @@ class RequestHandler {
177
183
  return this.keys;
178
184
  }
179
185
  async revokeKey(keyId, cookie) {
180
- const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/revoke`, {
186
+ const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/revoke`, {
181
187
  method: 'POST',
182
188
  timeout: 10000,
183
189
  body: JSON.stringify({ id: keyId }),
@@ -186,7 +192,7 @@ class RequestHandler {
186
192
  return res.ok;
187
193
  }
188
194
  async createKey(cookie, ip) {
189
- const res = await (0, node_fetch_1.default)(`${Constants_1.DEV_SITE_API_BASE_URL}/apikey/create`, {
195
+ const res = await (0, node_fetch_1.default)(`${Constants_1.DevSiteAPIBaseURL}/apikey/create`, {
190
196
  method: 'POST',
191
197
  timeout: 10000,
192
198
  headers: { 'Content-Type': 'application/json', cookie },
@@ -1,7 +1,7 @@
1
1
  import { APIClan, OverrideOptions } from '../types';
2
+ import { Client } from '../client/Client';
2
3
  import { ChatLanguage } from './ChatLanguage';
3
4
  import { ClanMember } from './ClanMember';
4
- import { Client } from '../client/Client';
5
5
  import { WarLeague } from './WarLeague';
6
6
  import type { Player } from './Player';
7
7
  import { Location } from './Location';
@@ -12,7 +12,7 @@ class ClanMember {
12
12
  this.role = data.role.replace('admin', 'elder');
13
13
  this.expLevel = data.expLevel;
14
14
  // eslint-disable-next-line
15
- this.league = new League_1.League(data.league ?? Constants_1.UNRANKED_LEAGUE_DATA);
15
+ this.league = new League_1.League(data.league ?? Constants_1.UnrankedLeagueData);
16
16
  this.trophies = data.trophies;
17
17
  this.versusTrophies = data.versusTrophies ?? null;
18
18
  this.clanRank = data.clanRank;
@@ -201,7 +201,7 @@ class ClanWar {
201
201
  /** Whether this is a friendly war. */
202
202
  get isFriendly() {
203
203
  const preparationTime = this.startTime.getTime() - this.preparationStartTime.getTime();
204
- return Constants_1.FRIENDLY_WAR_PREPARATION_TIMES.includes(preparationTime);
204
+ return Constants_1.FriendlyWarPreparationTimes.includes(preparationTime);
205
205
  }
206
206
  /** Whether this is a CWL. */
207
207
  get isCWL() {
@@ -12,7 +12,7 @@ class League {
12
12
  }
13
13
  /** Position of this League. Starting from 0 (Un-ranked) */
14
14
  get position() {
15
- return Constants_1.LEAGUES.indexOf(this.id);
15
+ return Constants_1.Leagues.indexOf(this.id);
16
16
  }
17
17
  }
18
18
  exports.League = League;
@@ -1,9 +1,9 @@
1
1
  import { APIPlayer, OverrideOptions } from '../types';
2
+ import { Client } from '../client/Client';
2
3
  import { LegendStatistics } from './LegendStatistics';
3
4
  import { Achievement } from './Achievement';
4
5
  import { Hero, Spell, Troop } from './Unit';
5
6
  import { PlayerClan } from './PlayerClan';
6
- import { Client } from '../client/Client';
7
7
  import { League } from './League';
8
8
  import { Label } from './Label';
9
9
  /** Represents a Clash of Clans Player. */
@@ -33,7 +33,7 @@ class Player {
33
33
  this.role = data.role?.replace('admin', 'elder') ?? null;
34
34
  this.warOptedIn = data.warPreference ? data.warPreference === 'in' : null;
35
35
  this.clan = data.clan ? new PlayerClan_1.PlayerClan(client, data.clan) : null;
36
- this.league = new League_1.League(data.league ?? Constants_1.UNRANKED_LEAGUE_DATA);
36
+ this.league = new League_1.League(data.league ?? Constants_1.UnrankedLeagueData);
37
37
  this.legendStatistics = data.legendStatistics ? new LegendStatistics_1.LegendStatistics(data.legendStatistics) : null;
38
38
  this.achievements = data.achievements.map((data) => new Achievement_1.Achievement(data));
39
39
  this.labels = data.labels.map((data) => new Label_1.Label(data));
@@ -70,32 +70,32 @@ class Player {
70
70
  /** An array of the player's home base troops. */
71
71
  get homeTroops() {
72
72
  return this.troops
73
- .filter((entry) => Constants_1.HOME_TROOPS.includes(entry.name))
74
- .sort((a, b) => Constants_1.HOME_TROOPS.indexOf(a.name) - Constants_1.HOME_TROOPS.indexOf(b.name));
73
+ .filter((entry) => entry.village === 'home' && Constants_1.HomeTroops.includes(entry.name))
74
+ .sort((a, b) => Constants_1.HomeTroops.indexOf(a.name) - Constants_1.HomeTroops.indexOf(b.name));
75
75
  }
76
76
  /** An array of the player's builder base troops. */
77
77
  get builderTroops() {
78
78
  return this.troops
79
- .filter((entry) => Constants_1.BUILDER_TROOPS.includes(entry.name))
80
- .sort((a, b) => Constants_1.BUILDER_TROOPS.indexOf(a.name) - Constants_1.BUILDER_TROOPS.indexOf(b.name));
79
+ .filter((entry) => entry.village === 'builderBase' && Constants_1.BuilderTroops.includes(entry.name))
80
+ .sort((a, b) => Constants_1.BuilderTroops.indexOf(a.name) - Constants_1.BuilderTroops.indexOf(b.name));
81
81
  }
82
82
  /** An array of the player's super troops. */
83
83
  get superTroops() {
84
84
  return this.troops
85
- .filter((entry) => Constants_1.SUPER_TROOPS.includes(entry.name))
86
- .sort((a, b) => Constants_1.SUPER_TROOPS.indexOf(a.name) - Constants_1.SUPER_TROOPS.indexOf(b.name));
85
+ .filter((entry) => entry.village === 'home' && Constants_1.SuperTroops.includes(entry.name))
86
+ .sort((a, b) => Constants_1.SuperTroops.indexOf(a.name) - Constants_1.SuperTroops.indexOf(b.name));
87
87
  }
88
88
  /** An array of the player's hero pets. */
89
89
  get heroPets() {
90
90
  return this.troops
91
- .filter((entry) => Constants_1.HERO_PETS.includes(entry.name))
92
- .sort((a, b) => Constants_1.HERO_PETS.indexOf(a.name) - Constants_1.HERO_PETS.indexOf(b.name));
91
+ .filter((entry) => entry.village === 'home' && Constants_1.HeroPets.includes(entry.name))
92
+ .sort((a, b) => Constants_1.HeroPets.indexOf(a.name) - Constants_1.HeroPets.indexOf(b.name));
93
93
  }
94
94
  /** An array of the player's siege machines. */
95
95
  get siegeMachines() {
96
96
  return this.troops
97
- .filter((entry) => Constants_1.SIEGE_MACHINES.includes(entry.name))
98
- .sort((a, b) => Constants_1.SIEGE_MACHINES.indexOf(a.name) - Constants_1.SIEGE_MACHINES.indexOf(b.name));
97
+ .filter((entry) => entry.village === 'home' && Constants_1.SiegeMachines.includes(entry.name))
98
+ .sort((a, b) => Constants_1.SiegeMachines.indexOf(a.name) - Constants_1.SiegeMachines.indexOf(b.name));
99
99
  }
100
100
  /** Get player's formatted link to open player in-game. */
101
101
  get shareLink() {
@@ -1,6 +1,6 @@
1
1
  import { APIClanRanking, APIClanVersusRanking, APIPlayerRanking, APIPlayerVersusRanking } from '../types';
2
- import { PlayerClan } from './PlayerClan';
3
2
  import { Client } from '../client/Client';
3
+ import { PlayerClan } from './PlayerClan';
4
4
  import { Location } from './Location';
5
5
  import { League } from './League';
6
6
  import { Badge } from './Badge';
@@ -46,7 +46,7 @@ class RankedPlayer {
46
46
  // @ts-expect-error
47
47
  this.clan = data.clan ? new PlayerClan_1.PlayerClan(client, data.clan) : null;
48
48
  // @ts-expect-error
49
- this.league = data.trophies ? new League_1.League(data.league ?? Constants_1.UNRANKED_LEAGUE_DATA) : null; // eslint-disable-line
49
+ this.league = data.trophies ? new League_1.League(data.league ?? Constants_1.UnrankedLeagueData) : null; // eslint-disable-line
50
50
  }
51
51
  /** Get player's formatted link to open player in-game. */
52
52
  get shareLink() {
@@ -10,14 +10,14 @@ class Unit {
10
10
  this.level = unit.level;
11
11
  this.maxLevel = unit.maxLevel;
12
12
  this.village = unit.village;
13
- const rawSuperUnit = Constants_1.RAW_DATA.RAW_SUPER_UNITS.find((unit) => unit.name === this.name && this.isHomeBase);
14
- const rawUnit = Constants_1.RAW_DATA.RAW_UNITS.find((unit) => unit.name === this.name && unit.village === this.village);
13
+ const rawSuperUnit = Constants_1.RawData.RawSuperUnits.find((unit) => unit.name === this.name && this.isHomeBase);
14
+ const rawUnit = Constants_1.RawData.RawUnits.find((unit) => unit.name === this.name && unit.village === this.village);
15
15
  if (rawSuperUnit) {
16
16
  this.id = rawSuperUnit.id;
17
17
  this.housingSpace = rawSuperUnit.housingSpace;
18
18
  this.originalName = rawSuperUnit.original;
19
19
  this.minOriginalLevel = rawSuperUnit.minOriginalLevel;
20
- const original = Constants_1.RAW_DATA.RAW_UNITS.find((unit) => unit.village === 'home' && unit.name === rawSuperUnit.original);
20
+ const original = Constants_1.RawData.RawUnits.find((unit) => unit.village === 'home' && unit.name === rawSuperUnit.original);
21
21
  this.unlockHallLevel = original.levels.findIndex((level) => level >= rawSuperUnit.minOriginalLevel) + 1;
22
22
  this.unlockCost = original.unlock.cost;
23
23
  this.unlockTime = original.unlock.time;
@@ -87,7 +87,7 @@ class Troop extends Unit {
87
87
  }
88
88
  /** Whether this troop is a Super Troop. */
89
89
  get isSuperTroop() {
90
- return this.isActive || (this.isHomeBase && Constants_1.SUPER_TROOPS.includes(this.name));
90
+ return this.isActive || (this.isHomeBase && Constants_1.SuperTroops.includes(this.name));
91
91
  }
92
92
  }
93
93
  exports.Troop = Troop;
@@ -10,7 +10,7 @@ class WarLeague {
10
10
  }
11
11
  /** Position of this War League. Starting from 0 (Unranked) */
12
12
  get position() {
13
- return Constants_1.WAR_LEAGUES.indexOf(this.id);
13
+ return Constants_1.WarLeagues.indexOf(this.id);
14
14
  }
15
15
  }
16
16
  exports.WarLeague = WarLeague;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,9 +1,9 @@
1
1
  import { QueueThrottler, BatchThrottler } from '../rest/Throttler';
2
2
  export interface Store<T = any> {
3
- set(key: string, value: T, ttl?: number): boolean | Promise<boolean>;
4
- get(key: string): T | null | Promise<T | null>;
5
- delete(key: string): boolean | Promise<boolean>;
6
- clear(): void | Promise<void>;
3
+ set: (key: string, value: T, ttl?: number) => boolean | Promise<boolean>;
4
+ get: (key: string) => T | null | Promise<T | null>;
5
+ delete: (key: string) => boolean | Promise<boolean>;
6
+ clear: () => void | Promise<void>;
7
7
  }
8
8
  /** Options for a {@link Client} */
9
9
  export interface ClientOptions {
@@ -1,17 +1,17 @@
1
- export declare const API_BASE_URL = "https://api.clashofclans.com/v1";
2
- export declare const DEV_SITE_API_BASE_URL = "https://developer.clashofclans.com/api";
3
- export declare const ELIXIR_TROOPS: string[];
4
- export declare const DARK_ELIXIR_TROOPS: string[];
5
- export declare const HOME_TROOPS: string[];
6
- export declare const SIEGE_MACHINES: string[];
7
- export declare const SUPER_TROOPS: string[];
8
- export declare const ELIXIR_SPELLS: string[];
9
- export declare const DARK_ELIXIR_SPELLS: string[];
10
- export declare const SPELLS: string[];
11
- export declare const BUILDER_TROOPS: string[];
12
- export declare const HEROES: string[];
13
- export declare const HERO_PETS: string[];
14
- export declare const UNRANKED_LEAGUE_DATA: {
1
+ export declare const APIBaseURL = "https://api.clashofclans.com/v1";
2
+ export declare const DevSiteAPIBaseURL = "https://developer.clashofclans.com/api";
3
+ export declare const ElixirTroops: string[];
4
+ export declare const DarkElixirTroops: string[];
5
+ export declare const HomeTroops: string[];
6
+ export declare const SiegeMachines: string[];
7
+ export declare const SuperTroops: string[];
8
+ export declare const ElixirSpells: string[];
9
+ export declare const DarkElixirSpells: string[];
10
+ export declare const Spells: string[];
11
+ export declare const BuilderTroops: string[];
12
+ export declare const Heroes: string[];
13
+ export declare const HeroPets: string[];
14
+ export declare const UnrankedLeagueData: {
15
15
  id: number;
16
16
  name: string;
17
17
  iconUrls: {
@@ -19,30 +19,39 @@ export declare const UNRANKED_LEAGUE_DATA: {
19
19
  tiny: string;
20
20
  };
21
21
  };
22
- export declare const LEGEND_LEAGUE_ID = 29000022;
23
- export declare const LEAGUES: number[];
24
- export declare const WAR_LEAGUES: number[];
25
- export declare const FRIENDLY_WAR_PREPARATION_TIMES: readonly [number, number, number, number, number, number, number, number, number, number, number, number];
26
- export declare const EVENTS: {
27
- readonly NEW_SEASON_START: "newSeasonStart";
28
- readonly CLAN_LOOP_START: "clanLoopStart";
29
- readonly CLAN_LOOP_END: "clanLoopEnd";
30
- readonly PLAYER_LOOP_START: "playerLoopStart";
31
- readonly PLAYER_LOOP_END: "playerLoopEnd";
32
- readonly WAR_LOOP_START: "warLoopEnd";
33
- readonly WAR_LOOP_END: "warLoopEnd";
34
- readonly MAINTENANCE_START: "maintenanceStart";
35
- readonly MAINTENANCE_END: "maintenanceEnd";
36
- readonly ERROR: "error";
37
- readonly DEBUG: "debug";
22
+ export declare const LegendLeagueId = 29000022;
23
+ export declare const Leagues: number[];
24
+ export declare const WarLeagues: number[];
25
+ export declare const FriendlyWarPreparationTimes: readonly [number, number, number, number, number, number, number, number, number, number, number, number];
26
+ export declare const PollingEvents: {
27
+ readonly ClanLoopStart: "clanLoopStart";
28
+ readonly ClanLoopEnd: "clanLoopEnd";
29
+ readonly PlayerLoopStart: "playerLoopStart";
30
+ readonly PlayerLoopEnd: "playerLoopEnd";
31
+ readonly WarLoopStart: "warLoopEnd";
32
+ readonly WarLoopEnd: "warLoopEnd";
33
+ readonly NewSeasonStart: "newSeasonStart";
34
+ readonly MaintenanceStart: "maintenanceStart";
35
+ readonly MaintenanceEnd: "maintenanceEnd";
36
+ readonly Error: "error";
37
+ readonly Debug: "debug";
38
38
  };
39
- export declare const CWL_ROUNDS: {
40
- readonly PREVIOUS_ROUND: "warEnded";
41
- readonly CURRENT_ROUND: "inWar";
42
- readonly NEXT_ROUND: "preparation";
39
+ export declare const ClientEvents: {
40
+ readonly Error: "error";
41
+ readonly Debug: "debug";
43
42
  };
44
- export declare const RAW_DATA: {
45
- RAW_UNITS: {
43
+ export declare const RestEvents: {
44
+ readonly Error: "error";
45
+ readonly Debug: "debug";
46
+ readonly RateLimited: "rateLimited";
47
+ };
48
+ export declare const CWLRounds: {
49
+ readonly PreviousRound: "warEnded";
50
+ readonly CurrentRound: "inWar";
51
+ readonly NextRound: "preparation";
52
+ };
53
+ export declare const RawData: {
54
+ RawUnits: {
46
55
  id: number;
47
56
  name: string;
48
57
  housingSpace: number;
@@ -69,7 +78,7 @@ export declare const RAW_DATA: {
69
78
  seasonal: boolean;
70
79
  levels: number[];
71
80
  }[];
72
- RAW_SUPER_UNITS: {
81
+ RawSuperUnits: {
73
82
  name: string;
74
83
  id: number;
75
84
  original: string;