clashofclans.js 3.5.1 → 3.5.3-dev.96712e2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,11 @@ export declare class Util extends null {
49
49
  startTime: Date;
50
50
  seasonId: string;
51
51
  };
52
+ static getSeasonById(seasonId: string): {
53
+ startTime: Date;
54
+ endTime: Date;
55
+ seasonId: string;
56
+ };
52
57
  static allSettled<T>(values: Promise<T>[]): Promise<T[]>;
53
58
  static delay(ms: number): Promise<unknown>;
54
59
  }
package/dist/util/Util.js CHANGED
@@ -160,6 +160,41 @@ class Util extends null {
160
160
  const seasonId = `${year}-${String(month).padStart(2, '0')}`;
161
161
  return { startTime, endTime, seasonId };
162
162
  }
163
+ static getSeasonById(seasonId) {
164
+ // Handle the fixed September 2025 season
165
+ if (seasonId === '2025-09') {
166
+ return {
167
+ startTime: new Date('2025-08-25T05:00:00.000Z'),
168
+ endTime: new Date('2025-10-06T05:00:00.000Z'),
169
+ seasonId
170
+ };
171
+ }
172
+ const date = new Date(seasonId);
173
+ const targetYear = date.getUTCFullYear();
174
+ const targetMonth = date.getUTCMonth() + 1; // 1..12
175
+ const referenceDate = new Date('2025-10-06T05:00:00.000Z');
176
+ // Only handle the post-6 Oct seasons with 28-day intervals
177
+ const refYear = referenceDate.getUTCFullYear();
178
+ const refMonthIndex = referenceDate.getUTCMonth(); // 0-based
179
+ const totalMonthsTarget = targetYear * 12 + (targetMonth - 1);
180
+ const totalMonthsRef = refYear * 12 + refMonthIndex;
181
+ const seasonsPassed = totalMonthsTarget - totalMonthsRef;
182
+ if (seasonsPassed < 0) {
183
+ // Before 6th Oct, compute using old last-Monday rule
184
+ const tempDate = new Date(Date.UTC(targetYear, targetMonth, 0)); // last day of month
185
+ const lastMonday = new Date(tempDate);
186
+ lastMonday.setUTCDate(lastMonday.getUTCDate() - ((tempDate.getUTCDay() + 6) % 7));
187
+ lastMonday.setUTCHours(5, 0, 0, 0);
188
+ const startTime = this.getSeasonStart(lastMonday);
189
+ const endTime = lastMonday;
190
+ return { startTime, endTime, seasonId };
191
+ }
192
+ // After 6 Oct 2025, 28-day seasons
193
+ const seasonDuration = 28 * 24 * 60 * 60 * 1000;
194
+ const startTime = new Date(referenceDate.getTime() + seasonsPassed * seasonDuration);
195
+ const endTime = new Date(startTime.getTime() + seasonDuration);
196
+ return { startTime, endTime, seasonId };
197
+ }
163
198
  static async allSettled(values) {
164
199
  return (await Promise.allSettled(values))
165
200
  .filter((res) => res.status === 'fulfilled')
package/dist/util.spec.js CHANGED
@@ -84,4 +84,60 @@ describe('util', () => {
84
84
  expect(endTime.toISOString()).toBe(expectedEndTime);
85
85
  expect(seasonId).toBe('2026-02');
86
86
  });
87
+ it('should pass Aug 2025 (seasonId)', async () => {
88
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2025-08');
89
+ const expectedStartTime = new Date('2025-07-28T05:00').toISOString();
90
+ const expectedEndTime = new Date('2025-08-25T05:00').toISOString();
91
+ expect(startTime.toISOString()).toBe(expectedStartTime);
92
+ expect(endTime.toISOString()).toBe(expectedEndTime);
93
+ expect(seasonId).toBe('2025-08');
94
+ });
95
+ it('should pass March 2024 (seasonId)', async () => {
96
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2024-03');
97
+ const expectedEndTime = new Date('2024-03-25T05:00').toISOString();
98
+ const expectedStartTime = new Date('2024-02-26T05:00').toISOString();
99
+ expect(endTime.toISOString()).toBe(expectedEndTime);
100
+ expect(startTime.toISOString()).toBe(expectedStartTime);
101
+ expect(seasonId).toBe('2024-03');
102
+ });
103
+ it('should pass Sep 2025 (seasonId)', async () => {
104
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2025-09');
105
+ const expectedStartTime = new Date('2025-08-25T05:00').toISOString();
106
+ const expectedEndTime = new Date('2025-10-06T05:00').toISOString();
107
+ expect(startTime.toISOString()).toBe(expectedStartTime);
108
+ expect(endTime.toISOString()).toBe(expectedEndTime);
109
+ expect(seasonId).toBe('2025-09');
110
+ });
111
+ it('should pass October 2025 (seasonId)', async () => {
112
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2025-10');
113
+ const expectedStartTime = new Date('2025-10-06T05:00').toISOString();
114
+ const expectedEndTime = new Date('2025-11-03T05:00').toISOString();
115
+ expect(startTime.toISOString()).toBe(expectedStartTime);
116
+ expect(endTime.toISOString()).toBe(expectedEndTime);
117
+ expect(seasonId).toBe('2025-10');
118
+ });
119
+ it('should pass Dec 2025 (seasonId)', async () => {
120
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2025-12');
121
+ const expectedStartTime = new Date('2025-12-01T05:00').toISOString();
122
+ const expectedEndTime = new Date('2025-12-29T05:00').toISOString();
123
+ expect(startTime.toISOString()).toBe(expectedStartTime);
124
+ expect(endTime.toISOString()).toBe(expectedEndTime);
125
+ expect(seasonId).toBe('2025-12');
126
+ });
127
+ it('should pass Jan 2026 (seasonId)', async () => {
128
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2026-01');
129
+ const expectedStartTime = new Date('2025-12-29T05:00').toISOString();
130
+ const expectedEndTime = new Date('2026-01-26T05:00').toISOString();
131
+ expect(startTime.toISOString()).toBe(expectedStartTime);
132
+ expect(endTime.toISOString()).toBe(expectedEndTime);
133
+ expect(seasonId).toBe('2026-01');
134
+ });
135
+ it('should pass Feb 2026 (seasonId)', async () => {
136
+ const { endTime, startTime, seasonId } = Util_1.Util.getSeasonById('2026-02');
137
+ const expectedStartTime = new Date('2026-01-26T05:00').toISOString();
138
+ const expectedEndTime = new Date('2026-02-23T05:00').toISOString();
139
+ expect(startTime.toISOString()).toBe(expectedStartTime);
140
+ expect(endTime.toISOString()).toBe(expectedEndTime);
141
+ expect(seasonId).toBe('2026-02');
142
+ });
87
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.5.1",
3
+ "version": "3.5.3-dev.96712e2",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",
@@ -73,4 +73,4 @@
73
73
  "engines": {
74
74
  "node": ">=18.x"
75
75
  }
76
- }
76
+ }
package/CHANGELOG.md DELETED
@@ -1,173 +0,0 @@
1
- # Changelog
2
-
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
-
5
- ## 3.1.3 (24-12-2023)
6
-
7
- ### Features
8
-
9
- - Town Hall 16 updates.
10
- - Removed deprecated builder base properties.
11
-
12
- ## 3.1.3 (13-08-2023)
13
-
14
- ### Features
15
-
16
- - Switched to `undici` from `node-fetch` for better performance.
17
-
18
- ## 3.1.0 (2023-07-28)
19
-
20
- ### Features
21
-
22
- - Builder base update and new troop levels.
23
-
24
- ## 3.0.2 (2023-01-15)
25
-
26
- ### Bug Fixes
27
-
28
- - Conflict with the same name of builder base and home base troops. (#123)
29
- - Fix the issue with the `Client#getLeagueWar()` method.
30
- - Typings and documentation for clan capital.
31
- - Fix the issue with the `Clan#clanCapital` property.
32
-
33
- ### Features
34
-
35
- - Added `Client#getCapitalRaidSeasons()` method.
36
- - Added `Client#getCapitalLeagues()` method.
37
- - Added `Client#getClanCapitalRanks()` method.
38
- - Added new Super Troops in raw.json file.
39
-
40
- ### Breaking Changes
41
-
42
- - Using PascalCase instead of SCREAMING_SNAKE_CASE ([#115](https://github.com/clashperk/clashofclans.js/pull/115))
43
- - `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))
44
-
45
- ## 2.8.0 (2022-07-22)
46
-
47
- ### Features
48
-
49
- - Better Throttler with JS generator function. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
50
- - Updated raw data from game files. ([#111](https://github.com/clashperk/clashofclans.js/pull/111))
51
- - New method Util#parseArmyLink has been added. ([#110](https://github.com/clashperk/clashofclans.js/pull/110))
52
-
53
- ## 2.7.0 (2022-05-22)
54
-
55
- ### Features
56
-
57
- - Some useful QOL methods have been added. ([#106](https://github.com/clashperk/clashofclans.js/pull/106))
58
-
59
- ## 2.6.1 (2022-02-03)
60
-
61
- ### Bug Fixes
62
-
63
- - New value and typings `notInWar` added for `ClanWarLeagueGroup#state` ([#101](https://github.com/clashperk/clashofclans.js/pull/101))
64
- - Throw error if `Util.formatTag` / `Util.parseTag` is called with invalid argument ([#102](https://github.com/clashperk/clashofclans.js/pull/101))
65
-
66
- ## 2.6.0 (2022-01-29)
67
-
68
- ## Features
69
-
70
- - Replaced Keyv with customizable cache store ([#99](https://github.com/clashperk/clashofclans.js/pull/99))
71
- - Guide for [Internal Caching](https://clashofclans.js.org/guide/internal-caching)
72
-
73
- ## 2.5.2 (2022-01-23)
74
-
75
- ### Bug Fixes
76
-
77
- - Fix `ClanWar#attacksPerMembers` property ([#97](https://github.com/clashperk/clashofclans.js/pull/97))
78
- - Bump `node-fetch` from 2.6.6 to 2.6.7 ([#96](https://github.com/clashperk/clashofclans.js/pull/96))
79
-
80
- ## 2.5.1 (2022-01-11)
81
-
82
- ### Bug Fixes
83
-
84
- - Typings for `ClanWarLeagueGroup#state` property. ([#94](https://github.com/clashperk/clashofclans.js/pull/94))
85
-
86
- ## 2.5.0 (2021-12-30)
87
-
88
- ### Bug Fixes
89
-
90
- - Fix caching issue with unnecessary/invalid query params. ([#91](https://github.com/clashperk/clashofclans.js/pull/91))
91
- - Added necessary methods to `RESTManager` class. ([#92](https://github.com/clashperk/clashofclans.js/pull/92))
92
-
93
- ## 2.4.0 (2021-12-28)
94
-
95
- ### Features
96
-
97
- - `ClanWar#getClanWarLeagueGroup`, `ClanWar#isCWL` and `ClanWar#isFriendly` are now available. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
98
- - `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))
99
- - `Icon#fileName` and `Icon#sizes` are now available in `Icon` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
100
- - `Badge#fileName` and `Badge#sizes` are now available in `Badge` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
101
-
102
- ### Deprecations
103
-
104
- - `ClanWarMember#previousBestOpponentAttack` has been deprecated. Use `ClanWarAttack#previousBestAttack` instead. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
105
-
106
- ## 2.3.0 (2021-12-17)
107
-
108
- ### Features
109
-
110
- - BigInt literals issue fixed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
111
- - Some Utility methods renamed. ([#84](https://github.com/clashperk/clashofclans.js/pull/84))
112
- - `Util.encodeTag()` to `Util.encodeURI()`
113
- - `Util.encodeTagToId()` to `Util.encodeTag()`
114
- - `Util.decodeIdToTag()` to `Util.decodeTag()`
115
- - Added `dps`, `resourceType`, `trainingTime` and `regenerationTime` to the `Unit` class. ([#85](https://github.com/clashperk/clashofclans.js/pull/85))
116
-
117
- ## 2.2.0 (2021-12-16)
118
-
119
- ### Bug Fixes
120
-
121
- - 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))
122
- - Season end time utility method. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
123
- - Updated raw files for new Troops. ([#82](https://github.com/clashperk/clashofclans.js/pull/82)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/95cf3001059fd3ede9262e249814178631660d5b))
124
-
125
- ### Features
126
-
127
- - 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))
128
-
129
- ## 2.1.0 (2021-12-06)
130
-
131
- ### Bug Fixes
132
-
133
- - Consistency of `ClanWar.attacksPerMember` property. ([#75](https://github.com/clashperk/clashofclans.js/pull/75)) ([6e23d2f](https://github.com/clashperk/clashofclans.js/commit/6e23d2fe0373f56268ffa55d5ac2807c9a2dc2fc))
134
-
135
- ### Features
136
-
137
- - 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))
138
-
139
- - `Util.formatTag(tag: string): string`
140
- - `Util.formatDate(date: string): Date`
141
- - `Util.isValidTag(tag: string): boolean`
142
- - `Util.encodeTagToId(tag: string): string` (Removed on 2.3.0)
143
- - `Util.decodeIdToTag(id: string): string` (Removed on 2.3.0)
144
-
145
- - 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))
146
-
147
- ## 2.0.2 (2021-11-30)
148
-
149
- ### Bug Fixes
150
-
151
- - 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))
152
- - `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))
153
- - `SeasonRankedPlayer` class for legend league ranking. ([#73](https://github.com/clashperk/clashofclans.js/pull/73)) ([ba82327](https://github.com/clashperk/clashofclans.js/commit/ba8232740f4ca9af2bcc7971aca3574612ef25b6))
154
-
155
- ## 2.0.1 (2021-11-27)
156
-
157
- ### Bug Fixes
158
-
159
- - IP retrieval method and Event Loop ([#70](https://github.com/clashperk/clashofclans.js/issues/70)) ([82b84ba](https://github.com/clashperk/clashofclans.js/commit/82b84ba5d96505c43b75e53aa07f547ef0b77778))
160
-
161
- ## 2.0.0 (2021-11-26)
162
-
163
- This new version is a complete TypeScript rewrite to convert everything from plain (literal JSON) objects to class (constructor) objects and support a lot more features.
164
-
165
- ### Features
166
-
167
- - HTTP Request Request Retries ([#26](https://github.com/clashperk/clashofclans.js/issues/26)) ([94585f3](https://github.com/clashperk/clashofclans.js/commit/94585f3a84a7175b2d07872f9eb9e42372b95e12))
168
- - Event Manager and Custom Events ([#37](https://github.com/clashperk/clashofclans.js/issues/37)) ([5027ae6](https://github.com/clashperk/clashofclans.js/commit/5027ae663a8e07175e17384c7e5706f4a1a7afb4))
169
- - Email Password Login ([#31](https://github.com/clashperk/clashofclans.js/issues/31)) ([4153cd3](https://github.com/clashperk/clashofclans.js/commit/4153cd37ea0e1c71550b9e892105b84d5a407e23))
170
- - Queue Throttler and Batch Throttler ([#34](https://github.com/clashperk/clashofclans.js/issues/34)) ([3a8f051](https://github.com/clashperk/clashofclans.js/commit/3a8f051552e93b98f89bc7d524acdecddf242718))
171
- - Override Request Options ([#36](https://github.com/clashperk/clashofclans.js/issues/36)) ([42d7fdd](https://github.com/clashperk/clashofclans.js/commit/42d7fdd36262cc46f23b731f8cffb9daea19d3b0))
172
- - Internal Caching Options ([#53](https://github.com/clashperk/clashofclans.js/issues/53)) ([984451d](https://github.com/clashperk/clashofclans.js/commit/30ea3240c11866008d0dae514468c0fdbb34ffd0))
173
- - Additional Properties for Player Units ([#65](https://github.com/clashperk/clashofclans.js/pull/65)) ([aa1696](https://github.com/clashperk/clashofclans.js/commit/aa1696243d96d4fed0250b4282c60522a6482343))