clashofclans.js 3.0.0-dev.f6ce42f → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,121 +2,140 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## 3.0.0 (11-01-2023)
6
+
7
+ ### Bug Fixes
8
+
9
+ - Conflict with the same name of builder base and home base troops. (#123)
10
+ - Fix the issue with the `Client#getLeagueWar()` method.
11
+ - Typings and documentation for clan capital.
12
+
13
+ ### Features
14
+
15
+ - Added `Client#getCapitalRaidSeasons()` method.
16
+ - Added `Client#getCapitalLeagues()` method.
17
+ - Added `Client#getClanCapitalRanks()` method.
18
+
19
+ ### Breaking Changes
20
+
21
+ - Using PascalCase instead of SCREAMING_SNAKE_CASE ([#115](https://github.com/clashperk/clashofclans.js/pull/115))
22
+ - `Client#events` and `EventManager` have been removed in favor of `PollingClient` ([#117](https://github.com/clashperk/clashofclans.js/pull/117), [#127](https://github.com/clashperk/clashofclans.js/pull/127))
23
+
5
24
  ## 2.8.0 (2022-07-22)
6
25
 
7
26
  ### Features
8
27
 
9
- - Better Throttler with JS generator function. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
10
- - Updated raw data from game files. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
11
- - New method Util#parseArmyLink has been added. ([#110](https://github.com/clashperk/clashofclans.js/pull/110))
28
+ - Better Throttler with JS generator function. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
29
+ - Updated raw data from game files. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
30
+ - New method Util#parseArmyLink has been added. ([#110](https://github.com/clashperk/clashofclans.js/pull/110))
12
31
 
13
32
  ## 2.7.0 (2022-05-22)
14
33
 
15
34
  ### Features
16
35
 
17
- - Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
36
+ - Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
18
37
 
19
38
  ## 2.6.1 (2022-02-03)
20
39
 
21
40
  ### Bug Fixes
22
41
 
23
- - New value and typings `notInWar` added for `ClanWarLeagueGroup#state` ([#101](https://github.com/clashperk/clashofclans.js/pull/101))
24
- - Throw error if `Util.formatTag` / `Util.parseTag` is called with invalid argument ([#102](https://github.com/clashperk/clashofclans.js/pull/101))
42
+ - New value and typings `notInWar` added for `ClanWarLeagueGroup#state` ([#101](https://github.com/clashperk/clashofclans.js/pull/101))
43
+ - Throw error if `Util.formatTag` / `Util.parseTag` is called with invalid argument ([#102](https://github.com/clashperk/clashofclans.js/pull/101))
25
44
 
26
45
  ## 2.6.0 (2022-01-29)
27
46
 
28
47
  ## Features
29
48
 
30
- - Replaced Keyv with customizable cache store ([#99](https://github.com/clashperk/clashofclans.js/pull/99))
31
- - Guide for [Internal Caching](https://clashofclans.js.org/guide/internal-caching)
49
+ - Replaced Keyv with customizable cache store ([#99](https://github.com/clashperk/clashofclans.js/pull/99))
50
+ - Guide for [Internal Caching](https://clashofclans.js.org/guide/internal-caching)
32
51
 
33
52
  ## 2.5.2 (2022-01-23)
34
53
 
35
54
  ### Bug Fixes
36
55
 
37
- - Fix `ClanWar#attacksPerMembers` property ([#97](https://github.com/clashperk/clashofclans.js/pull/97))
38
- - Bump `node-fetch` from 2.6.6 to 2.6.7 ([#96](https://github.com/clashperk/clashofclans.js/pull/96))
56
+ - Fix `ClanWar#attacksPerMembers` property ([#97](https://github.com/clashperk/clashofclans.js/pull/97))
57
+ - Bump `node-fetch` from 2.6.6 to 2.6.7 ([#96](https://github.com/clashperk/clashofclans.js/pull/96))
39
58
 
40
59
  ## 2.5.1 (2022-01-11)
41
60
 
42
61
  ### Bug Fixes
43
62
 
44
- - Typings for `ClanWarLeagueGroup#state` property. ([#94](https://github.com/clashperk/clashofclans.js/pull/94))
63
+ - Typings for `ClanWarLeagueGroup#state` property. ([#94](https://github.com/clashperk/clashofclans.js/pull/94))
45
64
 
46
65
  ## 2.5.0 (2021-12-30)
47
66
 
48
67
  ### Bug Fixes
49
68
 
50
- - Fix caching issue with unnecessary/invalid query params. ([#91](https://github.com/clashperk/clashofclans.js/pull/91))
51
- - Added necessary methods to `RESTManager` class. ([#92](https://github.com/clashperk/clashofclans.js/pull/92))
69
+ - Fix caching issue with unnecessary/invalid query params. ([#91](https://github.com/clashperk/clashofclans.js/pull/91))
70
+ - Added necessary methods to `RESTManager` class. ([#92](https://github.com/clashperk/clashofclans.js/pull/92))
52
71
 
53
72
  ## 2.4.0 (2021-12-28)
54
73
 
55
74
  ### Features
56
75
 
57
- - `ClanWar#getClanWarLeagueGroup`, `ClanWar#isCWL` and `ClanWar#isFriendly` are now available. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
58
- - `RESTOptions#rejectIfNotValid` added to perform `res.ok` operations over `RESTManager` methods. [Know more?](https://clashofclans.js.org/guide/access-raw-data#easy-access) ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
59
- - `Icon#fileName` and `Icon#sizes` are now available in `Icon` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
60
- - `Badge#fileName` and `Badge#sizes` are now available in `Badge` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
76
+ - `ClanWar#getClanWarLeagueGroup`, `ClanWar#isCWL` and `ClanWar#isFriendly` are now available. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
77
+ - `RESTOptions#rejectIfNotValid` added to perform `res.ok` operations over `RESTManager` methods. [Know more?](https://clashofclans.js.org/guide/access-raw-data#easy-access) ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
78
+ - `Icon#fileName` and `Icon#sizes` are now available in `Icon` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
79
+ - `Badge#fileName` and `Badge#sizes` are now available in `Badge` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
61
80
 
62
81
  ### Deprecations
63
82
 
64
- - `ClanWarMember#previousBestOpponentAttack` has been deprecated. Use `ClanWarAttack#previousBestAttack` instead. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
83
+ - `ClanWarMember#previousBestOpponentAttack` has been deprecated. Use `ClanWarAttack#previousBestAttack` instead. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
65
84
 
66
85
  ## 2.3.0 (2021-12-17)
67
86
 
68
87
  ### Features
69
88
 
70
- - BigInt literals issue fixed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
71
- - Some Utility methods renamed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
72
- - `Util.encodeTag()` to `Util.encodeURI()`
73
- - `Util.encodeTagToId()` to `Util.encodeTag()`
74
- - `Util.decodeIdToTag()` to `Util.decodeTag()`
75
- - Added `dps`, `resourceType`, `trainingTime` and `regenerationTime` to the `Unit` class. ([#85](https://github.com/clashperk/clashofclans.js/pull/85))
89
+ - BigInt literals issue fixed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
90
+ - Some Utility methods renamed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
91
+ - `Util.encodeTag()` to `Util.encodeURI()`
92
+ - `Util.encodeTagToId()` to `Util.encodeTag()`
93
+ - `Util.decodeIdToTag()` to `Util.decodeTag()`
94
+ - Added `dps`, `resourceType`, `trainingTime` and `regenerationTime` to the `Unit` class. ([#85](https://github.com/clashperk/clashofclans.js/pull/85))
76
95
 
77
96
  ## 2.2.0 (2021-12-16)
78
97
 
79
98
  ### Bug Fixes
80
99
 
81
- - Show units as per in-game orders. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
82
- - Season end time utility method. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
83
- - Updated raw files for new Troops. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
100
+ - Show units as per in-game orders. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
101
+ - Season end time utility method. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
102
+ - Updated raw files for new Troops. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
84
103
 
85
104
  ### Features
86
105
 
87
- - Added `seasonal`, `boostable` and `isLoaded` property to `Unit` class. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
106
+ - Added `seasonal`, `boostable` and `isLoaded` property to `Unit` class. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
88
107
 
89
108
  ## 2.1.0 (2021-12-06)
90
109
 
91
110
  ### Bug Fixes
92
111
 
93
- - Consistency of `ClanWar.attacksPerMember` property. ([#75](https://github.com/clashperk/clashofclans.js/pull/75)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/6e23d2fe0373f56268ffa55d5ac2807c9a2dc2fc))
112
+ - Consistency of `ClanWar.attacksPerMember` property. ([#75](https://github.com/clashperk/clashofclans.js/pull/75)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/6e23d2fe0373f56268ffa55d5ac2807c9a2dc2fc))
94
113
 
95
114
  ### Features
96
115
 
97
- - More utility methods added to `Util` class. ([#76](https://github.com/clashperk/clashofclans.js/pull/76)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/ff4111530d6293ef1fc54aa916436130fc30a09c))
116
+ - More utility methods added to `Util` class. ([#76](https://github.com/clashperk/clashofclans.js/pull/76)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/ff4111530d6293ef1fc54aa916436130fc30a09c))
98
117
 
99
- - `Util.formatTag(tag: string): string`
100
- - `Util.formatDate(date: string): Date`
101
- - `Util.isValidTag(tag: string): boolean`
102
- - `Util.encodeTagToId(tag: string): string` (Removed on 2.3.0)
103
- - `Util.decodeIdToTag(id: string): string` (Removed on 2.3.0)
118
+ - `Util.formatTag(tag: string): string`
119
+ - `Util.formatDate(date: string): Date`
120
+ - `Util.isValidTag(tag: string): boolean`
121
+ - `Util.encodeTagToId(tag: string): string` (Removed on 2.3.0)
122
+ - `Util.decodeIdToTag(id: string): string` (Removed on 2.3.0)
104
123
 
105
- - Support of async/await for custom events ([#79](https://github.com/clashperk/clashofclans.js/pull/79)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/a23db3786bcca44b8547c70f27773bdb1216f990))
124
+ - Support of async/await for custom events ([#79](https://github.com/clashperk/clashofclans.js/pull/79)) ([ff41115](https://github.com/clashperk/clashofclans.js/commit/a23db3786bcca44b8547c70f27773bdb1216f990))
106
125
 
107
126
  ## 2.0.2 (2021-11-30)
108
127
 
109
128
  ### Bug Fixes
110
129
 
111
- - Return `null` for `RankedPlayer.clan` if they are not in the clan. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
112
- - `OverrideOptions` added for `Client#getClans` and `RESTManager#getClans` ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
113
- - `SeasonRankedPlayer` class for legend league ranking. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
130
+ - Return `null` for `RankedPlayer.clan` if they are not in the clan. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
131
+ - `OverrideOptions` added for `Client#getClans` and `RESTManager#getClans` ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
132
+ - `SeasonRankedPlayer` class for legend league ranking. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
114
133
 
115
134
  ## 2.0.1 (2021-11-27)
116
135
 
117
136
  ### Bug Fixes
118
137
 
119
- - IP retrieval method and Event Loop ([#70](https://github.com/clashperk/clashofclans.js/issues/70)) ([82b84ba](https://github.com/clashperk/clashofclans.js/commit/82b84ba5d96505c43b75e53aa07f547ef0b77778))
138
+ - IP retrieval method and Event Loop ([#70](https://github.com/clashperk/clashofclans.js/issues/70)) ([82b84ba](https://github.com/clashperk/clashofclans.js/commit/82b84ba5d96505c43b75e53aa07f547ef0b77778))
120
139
 
121
140
  ## 2.0.0 (2021-11-26)
122
141
 
@@ -124,10 +143,10 @@ This new version is a complete TypeScript rewrite to convert everything from pla
124
143
 
125
144
  ### Features
126
145
 
127
- - HTTP Request Request Retries ([#26](https://github.com/clashperk/clashofclans.js/issues/26)) ([94585f3](https://github.com/clashperk/clashofclans.js/commit/94585f3a84a7175b2d07872f9eb9e42372b95e12))
128
- - Event Manager and Custom Events ([#37](https://github.com/clashperk/clashofclans.js/issues/37)) ([5027ae6](https://github.com/clashperk/clashofclans.js/commit/5027ae663a8e07175e17384c7e5706f4a1a7afb4))
129
- - Email Password Login ([#31](https://github.com/clashperk/clashofclans.js/issues/31)) ([4153cd3](https://github.com/clashperk/clashofclans.js/commit/4153cd37ea0e1c71550b9e892105b84d5a407e23))
130
- - Queue Throttler and Batch Throttler ([#34](https://github.com/clashperk/clashofclans.js/issues/34)) ([3a8f051](https://github.com/clashperk/clashofclans.js/commit/3a8f051552e93b98f89bc7d524acdecddf242718))
131
- - Override Request Options ([#36](https://github.com/clashperk/clashofclans.js/issues/36)) ([42d7fdd](https://github.com/clashperk/clashofclans.js/commit/42d7fdd36262cc46f23b731f8cffb9daea19d3b0))
132
- - Internal Caching Options ([#53](https://github.com/clashperk/clashofclans.js/issues/53)) ([984451d](https://github.com/clashperk/clashofclans.js/commit/30ea3240c11866008d0dae514468c0fdbb34ffd0))
133
- - Additional Properties for Player Units ([#65](https://github.com/clashperk/clashofclans.js/pull/65)) ([aa1696](https://github.com/clashperk/clashofclans.js/commit/aa1696243d96d4fed0250b4282c60522a6482343))
146
+ - HTTP Request Request Retries ([#26](https://github.com/clashperk/clashofclans.js/issues/26)) ([94585f3](https://github.com/clashperk/clashofclans.js/commit/94585f3a84a7175b2d07872f9eb9e42372b95e12))
147
+ - Event Manager and Custom Events ([#37](https://github.com/clashperk/clashofclans.js/issues/37)) ([5027ae6](https://github.com/clashperk/clashofclans.js/commit/5027ae663a8e07175e17384c7e5706f4a1a7afb4))
148
+ - Email Password Login ([#31](https://github.com/clashperk/clashofclans.js/issues/31)) ([4153cd3](https://github.com/clashperk/clashofclans.js/commit/4153cd37ea0e1c71550b9e892105b84d5a407e23))
149
+ - Queue Throttler and Batch Throttler ([#34](https://github.com/clashperk/clashofclans.js/issues/34)) ([3a8f051](https://github.com/clashperk/clashofclans.js/commit/3a8f051552e93b98f89bc7d524acdecddf242718))
150
+ - Override Request Options ([#36](https://github.com/clashperk/clashofclans.js/issues/36)) ([42d7fdd](https://github.com/clashperk/clashofclans.js/commit/42d7fdd36262cc46f23b731f8cffb9daea19d3b0))
151
+ - Internal Caching Options ([#53](https://github.com/clashperk/clashofclans.js/issues/53)) ([984451d](https://github.com/clashperk/clashofclans.js/commit/30ea3240c11866008d0dae514468c0fdbb34ffd0))
152
+ - Additional Properties for Player Units ([#65](https://github.com/clashperk/clashofclans.js/pull/65)) ([aa1696](https://github.com/clashperk/clashofclans.js/commit/aa1696243d96d4fed0250b4282c60522a6482343))
package/README.md CHANGED
@@ -25,6 +25,7 @@
25
25
  ```js
26
26
  const { Client } = require('clashofclans.js');
27
27
  const client = new Client();
28
+ // const client = new Client({ keys: [], cache: true, retryLimit: 2, restRequestTimeout: 5000 });
28
29
 
29
30
  (async function () {
30
31
  await client.login({ email: 'developer@email.com', password: '***' });
@@ -34,32 +35,35 @@ const client = new Client();
34
35
  })();
35
36
  ```
36
37
 
37
- ### Custom Event
38
+ ### Custom Polling Event
39
+
40
+ > **Warning** <br />
41
+ > Events are neither real-time nor supported by the API. They are polled frequently and compared with the cached data. If there is a difference, the event is emitted.
38
42
 
39
43
  ```js
40
- const { Client, BatchThrottler } = require('clashofclans.js');
41
- const client = new Client({
44
+ const { PollingClient, BatchThrottler } = require('clashofclans.js');
45
+ const pollingClient = new PollingClient({
42
46
  cache: true,
43
47
  retryLimit: 1,
44
48
  restRequestTimeout: 5000,
45
49
  throttler: new BatchThrottler(20)
46
50
  });
47
51
 
48
- client.events.addClans(['#8QU8J9LP', '#8P2QG08P']);
49
- client.events.setClanEvent({
52
+ pollingClient.addClans(['#8QU8J9LP', '#8P2QG08P']);
53
+ pollingClient.setClanEvent({
50
54
  name: 'clanDescriptionChange',
51
55
  filter: (oldClan, newClan) => {
52
56
  return oldClan.description !== newClan.description;
53
57
  }
54
58
  });
55
59
 
56
- client.on('clanDescriptionChange', (oldClan, newClan) => {
60
+ pollingClient.on('clanDescriptionChange', (oldClan, newClan) => {
57
61
  console.log(oldClan.description, newClan.description);
58
62
  });
59
63
 
60
64
  (async function () {
61
- await client.login({ email: 'developer@email.com', password: '***' });
62
- await client.events.init();
65
+ await pollingClient.login({ email: 'developer@email.com', password: '***' });
66
+ await pollingClient.init();
63
67
  })();
64
68
  ```
65
69
 
@@ -1,10 +1,34 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'node:events';
3
3
  import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
4
- import { CWLRounds } from '../util/Constants';
4
+ import { CWLRounds, ClientEvents } from '../util/Constants';
5
5
  import { RESTManager } from '../rest/RESTManager';
6
6
  import { Util } from '../util/Util';
7
7
  import { Clan, ClanMember, ClanWar, ClanWarLog, League, Location, Player, WarLeague, RankedClan, RankedPlayer, Label, SeasonRankedPlayer, GoldPassSeason, ClanWarLeagueGroup } from '../struct';
8
+ import { CapitalRaidSeason } from '../struct/CapitalRaidSeason';
9
+ interface IClientEvents {
10
+ [ClientEvents.Error]: [error: unknown];
11
+ [ClientEvents.Debug]: [path: string, status: string, message: string];
12
+ }
13
+ export interface Client {
14
+ emit: (<K extends keyof IClientEvents>(event: K, ...args: IClientEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, ...args: any[]) => boolean);
15
+ off: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
16
+ on: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
17
+ once: (<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IClientEvents>, listener: (...args: any[]) => void) => this);
18
+ removeAllListeners: (<K extends keyof IClientEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IClientEvents>) => this);
19
+ /**
20
+ * Emitted for general debugging information.
21
+ * @public
22
+ * @event
23
+ */
24
+ debug: string;
25
+ /**
26
+ * Emitted when the client encounters an error.
27
+ * @public
28
+ * @event
29
+ */
30
+ error: string;
31
+ }
8
32
  /**
9
33
  * Represents Clash of Clans API Client.
10
34
  * ```js
@@ -35,6 +59,8 @@ export declare class Client extends EventEmitter {
35
59
  getClan(clanTag: string, options?: OverrideOptions): Promise<Clan>;
36
60
  /** Get list of clan members. */
37
61
  getClanMembers(clanTag: string, options?: SearchOptions): Promise<ClanMember[]>;
62
+ /** Get capital raid seasons. */
63
+ getCapitalRaidSeasons(tag: string, options?: SearchOptions): Promise<CapitalRaidSeason[]>;
38
64
  /** Get clan war log. */
39
65
  getClanWarLog(clanTag: string, options?: SearchOptions): Promise<ClanWarLog[]>;
40
66
  /** Get info about currently running war (normal or friendly) in the clan. */
@@ -86,8 +112,10 @@ export declare class Client extends EventEmitter {
86
112
  getPlayers(playerTags: string[], options?: OverrideOptions): Promise<Player[]>;
87
113
  /** Verify Player API token that can be found from the Game settings. */
88
114
  verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<boolean>;
89
- /** Get list of Leagues. */
115
+ /** Get a list of Leagues. */
90
116
  getLeagues(options?: SearchOptions): Promise<League[]>;
117
+ /** Get a list of Capital Leagues. */
118
+ getCapitalLeagues(options?: SearchOptions): Promise<import("../types").APICapitalLeague[]>;
91
119
  /** Get Legend League season Ids. */
92
120
  getLeagueSeasons(options?: SearchOptions): Promise<string[]>;
93
121
  /** Get Legend League season rankings by season Id. */
@@ -120,6 +148,12 @@ export declare class Client extends EventEmitter {
120
148
  * For global ranking, use `global` as `locationId`.
121
149
  */
122
150
  getVersusPlayerRanks(locationId: number | 'global', options?: SearchOptions): Promise<RankedPlayer[]>;
151
+ /**
152
+ * Get clan capital rankings for a specific location.
153
+ *
154
+ * For global ranking, use `global` as `locationId`.
155
+ */
156
+ getClanCapitalRanks(locationId: number | 'global', options?: SearchOptions): Promise<import("../types").APIClanCapitalRanking[]>;
123
157
  /** Get list of clan labels. */
124
158
  getClanLabels(options?: SearchOptions): Promise<Label[]>;
125
159
  /** Get list of player labels. */
@@ -127,3 +161,4 @@ export declare class Client extends EventEmitter {
127
161
  /** Get info about gold pass season. */
128
162
  getGoldPassSeason(options?: OverrideOptions): Promise<GoldPassSeason>;
129
163
  }
164
+ export {};
@@ -7,6 +7,7 @@ const HTTPError_1 = require("../rest/HTTPError");
7
7
  const RESTManager_1 = require("../rest/RESTManager");
8
8
  const Util_1 = require("../util/Util");
9
9
  const struct_1 = require("../struct");
10
+ const CapitalRaidSeason_1 = require("../struct/CapitalRaidSeason");
10
11
  /**
11
12
  * Represents Clash of Clans API Client.
12
13
  * ```js
@@ -17,7 +18,9 @@ const struct_1 = require("../struct");
17
18
  class Client extends node_events_1.EventEmitter {
18
19
  constructor(options) {
19
20
  super();
20
- this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true });
21
+ this.rest = new RESTManager_1.RESTManager({ ...options, rejectIfNotValid: true })
22
+ .on(Constants_1.RestEvents.Debug, this.emit.bind(this, Constants_1.RestEvents.Debug))
23
+ .on(Constants_1.RestEvents.Error, this.emit.bind(this, Constants_1.RestEvents.Error));
21
24
  }
22
25
  /** Contains various general-purpose utility methods. */
23
26
  get util() {
@@ -32,11 +35,11 @@ class Client extends node_events_1.EventEmitter {
32
35
  * ```
33
36
  */
34
37
  login(options) {
35
- return this.rest.handler.init(options);
38
+ return this.rest.requestHandler.init(options);
36
39
  }
37
40
  /** Set Clash of Clans API keys. */
38
41
  setKeys(keys) {
39
- this.rest.handler.setKeys(keys);
42
+ this.rest.requestHandler.setKeys(keys);
40
43
  return this;
41
44
  }
42
45
  /** Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel). */
@@ -60,6 +63,11 @@ class Client extends node_events_1.EventEmitter {
60
63
  const { data } = await this.rest.getClanMembers(clanTag, options);
61
64
  return data.items.map((entry) => new struct_1.ClanMember(this, entry));
62
65
  }
66
+ /** Get capital raid seasons. */
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));
70
+ }
63
71
  /** Get clan war log. */
64
72
  async getClanWarLog(clanTag, options) {
65
73
  const { data } = await this.rest.getClanWarLog(clanTag, options);
@@ -67,10 +75,7 @@ class Client extends node_events_1.EventEmitter {
67
75
  }
68
76
  /** Get info about currently running war (normal or friendly) in the clan. */
69
77
  async getClanWar(clanTag, options) {
70
- const { data, maxAge, path, status } = await this.rest.getCurrentWar(clanTag, options);
71
- if (data.state === 'notInWar') {
72
- throw new HTTPError_1.HTTPError(HTTPError_1.NotInWarError, status, path, maxAge);
73
- }
78
+ const { data, maxAge } = await this.rest.getCurrentWar(clanTag, options);
74
79
  return new struct_1.ClanWar(this, data, { clanTag, maxAge });
75
80
  }
76
81
  /**
@@ -151,19 +156,13 @@ class Client extends node_events_1.EventEmitter {
151
156
  }
152
157
  /** Get info about clan war league. */
153
158
  async getClanWarLeagueGroup(clanTag, options) {
154
- const { data, status, path, maxAge } = await this.rest.getClanWarLeagueGroup(clanTag, options);
155
- if (data.state === 'notInWar') {
156
- throw new HTTPError_1.HTTPError(HTTPError_1.NotInWarError, status, path, maxAge);
157
- }
159
+ const { data } = await this.rest.getClanWarLeagueGroup(clanTag, options);
158
160
  return new struct_1.ClanWarLeagueGroup(this, data);
159
161
  }
160
162
  /** Get info about a CWL round by WarTag. */
161
163
  async getClanWarLeagueRound(warTag, options) {
162
164
  const args = typeof warTag === 'string' ? { warTag } : { warTag: warTag.warTag, clanTag: warTag.clanTag };
163
- const { data, maxAge, status, path } = await this.rest.getClanWarLeagueRound(args.warTag, options);
164
- if (data.state === 'notInWar') {
165
- throw new HTTPError_1.HTTPError(HTTPError_1.NotInWarError, status, path, maxAge);
166
- }
165
+ const { data, maxAge } = await this.rest.getClanWarLeagueRound(args.warTag, options);
167
166
  return new struct_1.ClanWar(this, data, { warTag: args.warTag, clanTag: args.clanTag, maxAge });
168
167
  }
169
168
  /** Get info about a player by tag. */
@@ -182,11 +181,16 @@ class Client extends node_events_1.EventEmitter {
182
181
  const { data } = await this.rest.verifyPlayerToken(playerTag, token, options);
183
182
  return data.status === 'ok';
184
183
  }
185
- /** Get list of Leagues. */
184
+ /** Get a list of Leagues. */
186
185
  async getLeagues(options) {
187
186
  const { data } = await this.rest.getLeagues(options);
188
187
  return data.items.map((entry) => new struct_1.League(entry));
189
188
  }
189
+ /** Get a list of Capital Leagues. */
190
+ async getCapitalLeagues(options) {
191
+ const { data } = await this.rest.getCapitalLeagues(options);
192
+ return data.items;
193
+ }
190
194
  /** Get Legend League season Ids. */
191
195
  async getLeagueSeasons(options) {
192
196
  const { data } = await this.rest.getLeagueSeasons(Constants_1.LegendLeagueId, options);
@@ -243,6 +247,15 @@ class Client extends node_events_1.EventEmitter {
243
247
  const { data } = await this.rest.getVersusPlayerRanks(locationId, options);
244
248
  return data.items.map((entry) => new struct_1.RankedPlayer(this, entry));
245
249
  }
250
+ /**
251
+ * Get clan capital rankings for a specific location.
252
+ *
253
+ * For global ranking, use `global` as `locationId`.
254
+ */
255
+ async getClanCapitalRanks(locationId, options) {
256
+ const { data } = await this.rest.getClanCapitalRanks(locationId, options);
257
+ return data.items;
258
+ }
246
259
  /** Get list of clan labels. */
247
260
  async getClanLabels(options) {
248
261
  const { data } = await this.rest.getClanLabels(options);
@@ -3,10 +3,10 @@ import { ClientOptions } from '../types';
3
3
  import { PollingEvents } from '../util/Constants';
4
4
  import { Client } from './Client';
5
5
  /**
6
- * Represents Clash of Clans Polling Event Client.
6
+ * Represents a Polling Event Client.
7
7
  * ```js
8
8
  * const { PollingClient } = require('clashofclans.js');
9
- * const client = new PollingClient({ keys: ['***'] });
9
+ * const pollingClient = new PollingClient({ keys: ['***'] });
10
10
  * ```
11
11
  */
12
12
  export declare class PollingClient extends Client {
@@ -41,9 +41,9 @@ export declare class PollingClient extends Client {
41
41
  *
42
42
  * @example
43
43
  * ```js
44
- * client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
44
+ * client.addClans(['#2PP', '#8QU8J9LP']);
45
45
  *
46
- * client.pollingEvents.setClanEvent({
46
+ * client.setClanEvent({
47
47
  * name: 'clanMemberUpdate',
48
48
  * filter: (oldClan, newClan) => {
49
49
  * return oldClan.memberCount !== newClan.memberCount;
@@ -55,7 +55,7 @@ export declare class PollingClient extends Client {
55
55
  * });
56
56
  *
57
57
  * (async function () {
58
- * await client.pollingEvents.init();
58
+ * await client.init();
59
59
  * })();
60
60
  * ```
61
61
  * @returns
@@ -90,6 +90,13 @@ export declare class PollingClient extends Client {
90
90
  private runClanUpdate;
91
91
  private runPlayerUpdate;
92
92
  private runWarUpdate;
93
+ }
94
+ export interface PollingClient {
95
+ emit: (<K extends keyof IPollingEvents>(event: K, ...args: IPollingEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, ...args: any[]) => boolean);
96
+ off: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
97
+ on: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
98
+ once: (<K extends keyof IPollingEvents>(event: K, listener: (...args: IPollingEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => this);
99
+ removeAllListeners: (<K extends keyof IPollingEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IPollingEvents>) => this);
93
100
  /**
94
101
  * Emits when a new season starts.
95
102
  *
@@ -101,13 +108,13 @@ export declare class PollingClient extends Client {
101
108
  * @public
102
109
  * @event
103
110
  */
104
- private static newSeasonStart;
111
+ newSeasonStart: string;
105
112
  /**
106
113
  * Emits when maintenance break starts in the API.
107
114
  * @public
108
115
  * @event
109
116
  */
110
- private static maintenanceStart;
117
+ maintenanceStart: string;
111
118
  /**
112
119
  * Emits when maintenance break ends in the API.
113
120
  *
@@ -119,39 +126,31 @@ export declare class PollingClient extends Client {
119
126
  * @public
120
127
  * @event
121
128
  */
122
- private static maintenanceEnd;
123
- /** @internal */
124
- on<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
125
- /** @internal */
126
- on<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
127
- /** @internal */ on<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
128
- /** @internal */
129
- once<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
130
- /** @internal */
131
- once<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
132
- /** @internal */ once<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
133
- /** @internal */
134
- emit<K extends keyof ClientPollingEvents>(event: K, ...args: ClientPollingEvents[K]): boolean;
135
- /** @internal */
136
- emit<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, ...args: CustomEvents[S]): this;
137
- /** @internal */ emit<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, ...args: any[]): boolean;
129
+ maintenanceEnd: string;
130
+ /**
131
+ * Emitted for general debugging information.
132
+ * @public
133
+ * @event
134
+ */
135
+ debug: string;
136
+ /**
137
+ * Emitted when the client encounters an error.
138
+ * @public
139
+ * @event
140
+ */
141
+ error: string;
138
142
  }
139
- interface ClientPollingEvents {
140
- [PollingEvents.NewSeasonStart]: [id: string];
141
- [PollingEvents.MaintenanceStart]: [];
142
- [PollingEvents.MaintenanceEnd]: [duration: number];
143
+ interface IPollingEvents {
143
144
  [PollingEvents.ClanLoopStart]: [];
144
145
  [PollingEvents.ClanLoopEnd]: [];
145
146
  [PollingEvents.PlayerLoopStart]: [];
146
147
  [PollingEvents.PlayerLoopEnd]: [];
147
148
  [PollingEvents.WarLoopStart]: [];
148
149
  [PollingEvents.WarLoopEnd]: [];
150
+ [PollingEvents.NewSeasonStart]: [id: string];
151
+ [PollingEvents.MaintenanceStart]: [];
152
+ [PollingEvents.MaintenanceEnd]: [duration: number];
149
153
  [PollingEvents.Error]: [error: unknown];
150
154
  [PollingEvents.Debug]: [path: string, status: string, message: string];
151
155
  }
152
- interface CustomEvents {
153
- [key: `clan${string}`]: [oldClan: Clan, newClan: Clan];
154
- [key: `war${string}`]: [oldWar: ClanWar, newWar: ClanWar];
155
- [key: `player${string}`]: [oldPlayer: Player, newPlayer: Player];
156
- }
157
156
  export {};
@@ -5,10 +5,10 @@ const HTTPError_1 = require("../rest/HTTPError");
5
5
  const Constants_1 = require("../util/Constants");
6
6
  const Client_1 = require("./Client");
7
7
  /**
8
- * Represents Clash of Clans Polling Event Client.
8
+ * Represents a Polling Event Client.
9
9
  * ```js
10
10
  * const { PollingClient } = require('clashofclans.js');
11
- * const client = new PollingClient({ keys: ['***'] });
11
+ * const pollingClient = new PollingClient({ keys: ['***'] });
12
12
  * ```
13
13
  */
14
14
  class PollingClient extends Client_1.Client {
@@ -93,9 +93,9 @@ class PollingClient extends Client_1.Client {
93
93
  *
94
94
  * @example
95
95
  * ```js
96
- * client.pollingEvents.addClans(['#2PP', '#8QU8J9LP']);
96
+ * client.addClans(['#2PP', '#8QU8J9LP']);
97
97
  *
98
- * client.pollingEvents.setClanEvent({
98
+ * client.setClanEvent({
99
99
  * name: 'clanMemberUpdate',
100
100
  * filter: (oldClan, newClan) => {
101
101
  * return oldClan.memberCount !== newClan.memberCount;
@@ -107,7 +107,7 @@ class PollingClient extends Client_1.Client {
107
107
  * });
108
108
  *
109
109
  * (async function () {
110
- * await client.pollingEvents.init();
110
+ * await client.init();
111
111
  * })();
112
112
  * ```
113
113
  * @returns
@@ -148,6 +148,8 @@ class PollingClient extends Client_1.Client {
148
148
  }
149
149
  async maintenanceHandler() {
150
150
  setTimeout(this.maintenanceHandler.bind(this), 10000).unref();
151
+ if (!(this.listenerCount(Constants_1.PollingEvents.MaintenanceStart) && this.listenerCount(Constants_1.PollingEvents.MaintenanceEnd)))
152
+ return;
151
153
  try {
152
154
  const res = await this.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
153
155
  if (res.status === 200 && this.inMaintenance) {
package/dist/index.mjs CHANGED
@@ -8,8 +8,11 @@ export const BatchThrottler = mod.BatchThrottler;
8
8
  export const BuilderTroops = mod.BuilderTroops;
9
9
  export const CWLRounds = mod.CWLRounds;
10
10
  export const CacheStore = mod.CacheStore;
11
+ export const CapitalRaidSeason = mod.CapitalRaidSeason;
12
+ export const CapitalRaidSeasonMember = mod.CapitalRaidSeasonMember;
11
13
  export const ChatLanguage = mod.ChatLanguage;
12
14
  export const Clan = mod.Clan;
15
+ export const ClanCapital = mod.ClanCapital;
13
16
  export const ClanMember = mod.ClanMember;
14
17
  export const ClanWar = mod.ClanWar;
15
18
  export const ClanWarAttack = mod.ClanWarAttack;
@@ -20,6 +23,7 @@ export const ClanWarLeagueRound = mod.ClanWarLeagueRound;
20
23
  export const ClanWarLog = mod.ClanWarLog;
21
24
  export const ClanWarMember = mod.ClanWarMember;
22
25
  export const Client = mod.Client;
26
+ export const ClientEvents = mod.ClientEvents;
23
27
  export const DarkElixirSpells = mod.DarkElixirSpells;
24
28
  export const DarkElixirTroops = mod.DarkElixirTroops;
25
29
  export const DevSiteAPIBaseURL = mod.DevSiteAPIBaseURL;
@@ -39,7 +43,6 @@ export const Leagues = mod.Leagues;
39
43
  export const LegendLeagueId = mod.LegendLeagueId;
40
44
  export const LegendStatistics = mod.LegendStatistics;
41
45
  export const Location = mod.Location;
42
- export const NotInWarError = mod.NotInWarError;
43
46
  export const Player = mod.Player;
44
47
  export const PlayerClan = mod.PlayerClan;
45
48
  export const PollingClient = mod.PollingClient;