clashofclans.js 3.0.0-dev.392ca4c → 3.0.0-dev.577f128

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +66 -47
  2. package/README.md +12 -8
  3. package/dist/client/Client.d.ts +38 -3
  4. package/dist/client/Client.js +32 -19
  5. package/dist/client/PollingClient.d.ts +107 -34
  6. package/dist/client/PollingClient.js +269 -8
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.js +5 -2
  9. package/dist/index.mjs +5 -2
  10. package/dist/rest/HTTPError.d.ts +0 -4
  11. package/dist/rest/HTTPError.js +1 -5
  12. package/dist/rest/RESTManager.d.ts +46 -5
  13. package/dist/rest/RESTManager.js +55 -30
  14. package/dist/rest/RequestHandler.d.ts +30 -2
  15. package/dist/rest/RequestHandler.js +69 -33
  16. package/dist/struct/CapitalRaidSeason.d.ts +49 -0
  17. package/dist/struct/CapitalRaidSeason.js +40 -0
  18. package/dist/struct/Clan.d.ts +8 -2
  19. package/dist/struct/Clan.js +3 -0
  20. package/dist/struct/ClanCapital.js +1 -1
  21. package/dist/struct/ClanMember.d.ts +3 -1
  22. package/dist/struct/ClanMember.js +1 -0
  23. package/dist/struct/ClanWar.d.ts +15 -3
  24. package/dist/struct/ClanWar.js +26 -15
  25. package/dist/struct/Player.d.ts +4 -2
  26. package/dist/struct/Player.js +1 -0
  27. package/dist/struct/Ranking.d.ts +1 -1
  28. package/dist/struct/Unit.d.ts +0 -2
  29. package/dist/struct/Unit.js +0 -2
  30. package/dist/struct/index.d.ts +2 -0
  31. package/dist/struct/index.js +7 -1
  32. package/dist/types/api.d.ts +93 -0
  33. package/dist/types/index.js +5 -1
  34. package/dist/types/lib.d.ts +4 -4
  35. package/dist/util/Constants.d.ts +38 -3
  36. package/dist/util/Constants.js +25 -6
  37. package/dist/util/Util.js +2 -2
  38. package/dist/util/raw.json +1 -1
  39. package/package.json +6 -59
  40. package/dist/client/EventManager.d.ts +0 -86
  41. package/dist/client/EventManager.js +0 -278
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
+ import { EventEmitter } from 'node:events';
2
3
  import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
3
- import { CWLRounds } from '../util/Constants';
4
+ import { CWLRounds, ClientEvents } from '../util/Constants';
4
5
  import { RESTManager } from '../rest/RESTManager';
5
- import { EventEmitter } from 'events';
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 {};
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Client = void 0;
4
+ const node_events_1 = require("node:events");
4
5
  const Constants_1 = require("../util/Constants");
5
6
  const HTTPError_1 = require("../rest/HTTPError");
6
7
  const RESTManager_1 = require("../rest/RESTManager");
7
- const events_1 = require("events");
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
@@ -14,10 +15,12 @@ const struct_1 = require("../struct");
14
15
  * const client = new Client({ keys: ['***'] });
15
16
  * ```
16
17
  */
17
- class Client extends events_1.EventEmitter {
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 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 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 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
  /**
@@ -140,7 +145,7 @@ class Client extends events_1.EventEmitter {
140
145
  return [await this.getClanWar(clanTag, options)];
141
146
  }
142
147
  try {
143
- return this.getLeagueWars(clanTag, options);
148
+ return await this.getLeagueWars(clanTag, options);
144
149
  }
145
150
  catch (e) {
146
151
  if (e instanceof HTTPError_1.HTTPError && [404].includes(e.status)) {
@@ -151,19 +156,13 @@ class Client extends 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 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 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);
@@ -2,20 +2,101 @@ import { Clan, ClanWar, Player } from '../struct';
2
2
  import { ClientOptions } from '../types';
3
3
  import { PollingEvents } from '../util/Constants';
4
4
  import { Client } from './Client';
5
- import { PollingEventManager } from './EventManager';
6
5
  /**
7
- * Represents Clash of Clans Polling Event Client.
6
+ * Represents a Polling Event Client.
8
7
  * ```js
9
8
  * const { PollingClient } = require('clashofclans.js');
10
- * const client = new PollingClient({ keys: ['***'] });
9
+ * const pollingClient = new PollingClient({ keys: ['***'] });
11
10
  * ```
12
11
  */
13
12
  export declare class PollingClient extends Client {
14
- /** Polling Event Manager for the client. */
15
- pollingEvents: PollingEventManager;
13
+ private readonly _clanTags;
14
+ private readonly _playerTags;
15
+ private readonly _warTags;
16
+ private readonly _clans;
17
+ private readonly _players;
18
+ private readonly _wars;
19
+ private readonly _pollingEvents;
20
+ inMaintenance: boolean;
21
+ private _maintenanceStartTime;
16
22
  constructor(options?: ClientOptions);
17
- /** Whether the API is in maintenance break. */
18
- get inMaintenance(): any;
23
+ /** Initialize the PollingEvent Manager to start pulling the data by polling api. */
24
+ init(): Promise<string[]>;
25
+ /** Add clan tags to clan polling events. */
26
+ addClans(tags: string[] | string): this;
27
+ /** Delete clan tags from clan polling events. */
28
+ deleteClans(tags: string[] | string): this;
29
+ /** Add player tags for player polling events. */
30
+ addPlayers(tags: string[] | string): this;
31
+ /** Delete player tags from player polling events. */
32
+ deletePlayers(tags: string[] | string): this;
33
+ /** Add clan tags for war polling events. */
34
+ addWars(tags: string[] | string): this;
35
+ /** Delete clan tags from war polling events. */
36
+ deleteWars(tags: string[] | string): this;
37
+ /**
38
+ * Set your own custom clan polling event.
39
+ *
40
+ * In order to emit the custom polling event, you must have this filter function that returns a boolean.
41
+ *
42
+ * @example
43
+ * ```js
44
+ * client.addClans(['#2PP', '#8QU8J9LP']);
45
+ *
46
+ * client.setClanEvent({
47
+ * name: 'clanMemberUpdate',
48
+ * filter: (oldClan, newClan) => {
49
+ * return oldClan.memberCount !== newClan.memberCount;
50
+ * }
51
+ * });
52
+ *
53
+ * client.on('clanMemberUpdate', (oldClan, newClan) => {
54
+ * console.log(oldClan.memberCount, newClan.memberCount);
55
+ * });
56
+ *
57
+ * (async function () {
58
+ * await client.init();
59
+ * })();
60
+ * ```
61
+ * @returns
62
+ */
63
+ setClanEvent(event: {
64
+ name: string;
65
+ filter: (oldClan: Clan, newClan: Clan) => boolean;
66
+ }): this;
67
+ /**
68
+ * Set your own custom war event.
69
+ *
70
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
71
+ */
72
+ setWarEvent(event: {
73
+ name: string;
74
+ filter: (oldWar: ClanWar, newWar: ClanWar) => boolean;
75
+ }): this;
76
+ /**
77
+ * Set your own custom player event.
78
+ *
79
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
80
+ */
81
+ setPlayerEvent(event: {
82
+ name: string;
83
+ filter: (oldPlayer: Player, newPlayer: Player) => boolean;
84
+ }): this;
85
+ private maintenanceHandler;
86
+ private seasonEndHandler;
87
+ private clanUpdateHandler;
88
+ private playerUpdateHandler;
89
+ private warUpdateHandler;
90
+ private runClanUpdate;
91
+ private runPlayerUpdate;
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);
19
100
  /**
20
101
  * Emits when a new season starts.
21
102
  *
@@ -27,13 +108,13 @@ export declare class PollingClient extends Client {
27
108
  * @public
28
109
  * @event
29
110
  */
30
- private static newSeasonStart;
111
+ newSeasonStart: string;
31
112
  /**
32
113
  * Emits when maintenance break starts in the API.
33
114
  * @public
34
115
  * @event
35
116
  */
36
- private static maintenanceStart;
117
+ maintenanceStart: string;
37
118
  /**
38
119
  * Emits when maintenance break ends in the API.
39
120
  *
@@ -45,39 +126,31 @@ export declare class PollingClient extends Client {
45
126
  * @public
46
127
  * @event
47
128
  */
48
- private static maintenanceEnd;
49
- /** @internal */
50
- on<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
51
- /** @internal */
52
- on<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
53
- /** @internal */ on<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
54
- /** @internal */
55
- once<K extends keyof ClientPollingEvents>(event: K, listeners: (...args: ClientPollingEvents[K]) => void): this;
56
- /** @internal */
57
- once<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: CustomEvents[S]) => void): this;
58
- /** @internal */ once<S extends string | symbol>(event: Exclude<S, keyof ClientPollingEvents>, listeners: (...args: any[]) => void): this;
59
- /** @internal */
60
- emit<K extends keyof ClientPollingEvents>(event: K, ...args: ClientPollingEvents[K]): boolean;
61
- /** @internal */
62
- emit<S extends keyof CustomEvents>(event: Exclude<S, keyof ClientPollingEvents>, ...args: CustomEvents[S]): this;
63
- /** @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;
64
142
  }
65
- interface ClientPollingEvents {
66
- [PollingEvents.NewSeasonStart]: [id: string];
67
- [PollingEvents.MaintenanceStart]: [];
68
- [PollingEvents.MaintenanceEnd]: [duration: number];
143
+ interface IPollingEvents {
69
144
  [PollingEvents.ClanLoopStart]: [];
70
145
  [PollingEvents.ClanLoopEnd]: [];
71
146
  [PollingEvents.PlayerLoopStart]: [];
72
147
  [PollingEvents.PlayerLoopEnd]: [];
73
148
  [PollingEvents.WarLoopStart]: [];
74
149
  [PollingEvents.WarLoopEnd]: [];
150
+ [PollingEvents.NewSeasonStart]: [id: string];
151
+ [PollingEvents.MaintenanceStart]: [];
152
+ [PollingEvents.MaintenanceEnd]: [duration: number];
75
153
  [PollingEvents.Error]: [error: unknown];
76
154
  [PollingEvents.Debug]: [path: string, status: string, message: string];
77
155
  }
78
- interface CustomEvents {
79
- [key: `clan${string}`]: [oldClan: Clan, newClan: Clan];
80
- [key: `war${string}`]: [oldWar: ClanWar, newWar: ClanWar];
81
- [key: `player${string}`]: [oldPlayer: Player, newPlayer: Player];
82
- }
83
156
  export {};