clashofclans.js 3.0.0-dev.f6ce42f → 3.0.1-dev.e71b7fa
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 +67 -47
- package/README.md +12 -8
- package/dist/client/Client.d.ts +37 -2
- package/dist/client/Client.js +29 -16
- package/dist/client/PollingClient.d.ts +31 -32
- package/dist/client/PollingClient.js +7 -5
- package/dist/index.mjs +4 -1
- package/dist/rest/HTTPError.d.ts +0 -4
- package/dist/rest/HTTPError.js +1 -5
- package/dist/rest/RESTManager.d.ts +45 -4
- package/dist/rest/RESTManager.js +54 -29
- package/dist/rest/RequestHandler.d.ts +30 -2
- package/dist/rest/RequestHandler.js +66 -30
- package/dist/struct/CapitalRaidSeason.d.ts +49 -0
- package/dist/struct/CapitalRaidSeason.js +40 -0
- package/dist/struct/Clan.d.ts +7 -1
- package/dist/struct/Clan.js +3 -0
- package/dist/struct/ClanCapital.js +1 -1
- package/dist/struct/ClanMember.d.ts +3 -1
- package/dist/struct/ClanMember.js +1 -0
- package/dist/struct/ClanWar.d.ts +15 -3
- package/dist/struct/ClanWar.js +26 -15
- package/dist/struct/Player.d.ts +3 -1
- package/dist/struct/Player.js +1 -0
- package/dist/struct/Unit.d.ts +0 -2
- package/dist/struct/Unit.js +2 -4
- package/dist/struct/index.d.ts +2 -0
- package/dist/struct/index.js +2 -0
- package/dist/types/api.d.ts +93 -0
- package/dist/util/Constants.d.ts +60 -3
- package/dist/util/Constants.js +24 -8
- package/dist/util/raw.json +1 -1
- package/package.json +1 -1
package/dist/rest/HTTPError.d.ts
CHANGED
|
@@ -19,10 +19,6 @@ export declare class HTTPError extends Error {
|
|
|
19
19
|
maxAge: number;
|
|
20
20
|
constructor(error: any, status: number, path: string, maxAge: number, method?: string);
|
|
21
21
|
}
|
|
22
|
-
export declare const NotInWarError: {
|
|
23
|
-
message: string;
|
|
24
|
-
reason: string;
|
|
25
|
-
};
|
|
26
22
|
export declare const PrivateWarLogError: {
|
|
27
23
|
message: string;
|
|
28
24
|
reason: string;
|
package/dist/rest/HTTPError.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrivateWarLogError = exports.
|
|
3
|
+
exports.PrivateWarLogError = exports.HTTPError = void 0;
|
|
4
4
|
const messages = {
|
|
5
5
|
500: 'Unknown error happened when handling the request.',
|
|
6
6
|
504: 'The user aborted this request.',
|
|
@@ -32,10 +32,6 @@ class HTTPError extends Error {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
exports.HTTPError = HTTPError;
|
|
35
|
-
exports.NotInWarError = {
|
|
36
|
-
message: 'Clan is not in war at this moment.',
|
|
37
|
-
reason: 'notInWar'
|
|
38
|
-
};
|
|
39
35
|
exports.PrivateWarLogError = {
|
|
40
36
|
message: 'Access denied, clan war log is private.',
|
|
41
37
|
reason: 'privateWarLog'
|
|
@@ -1,10 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
1
3
|
import { Util } from '../util/Util';
|
|
2
|
-
import { APIClan, APIClanList, APIClanMemberList, APIClanRankingList, APIClanVersusRankingList, APIClanWar, APIClanWarLeagueGroup, APIClanWarLog, APIGoldPassSeason, APILabelList, APILeague, APILeagueList, APILeagueSeasonList, APILocation, APILocationList, APIPlayer, APIPlayerRankingList, APIPlayerSeasonRankingList, APIPlayerVersusRankingList, APIVerifyToken, APIWarLeague, APIWarLeagueList, SearchOptions, ClanSearchOptions, RESTOptions, OverrideOptions, LoginOptions } from '../types';
|
|
4
|
+
import { APIClan, APIClanList, APIClanMemberList, APICapitalRaidSeasons, APIClanRankingList, APIClanVersusRankingList, APIClanWar, APIClanWarLeagueGroup, APIClanWarLog, APIGoldPassSeason, APILabelList, APILeague, APILeagueList, APILeagueSeasonList, APILocation, APILocationList, APIPlayer, APIPlayerRankingList, APIPlayerSeasonRankingList, APIPlayerVersusRankingList, APIVerifyToken, APIWarLeague, APIWarLeagueList, SearchOptions, ClanSearchOptions, RESTOptions, OverrideOptions, LoginOptions, APICapitalLeagueList, APICapitalLeague, APIClanCapitalRankingList } from '../types';
|
|
5
|
+
import { RestEvents } from '../util/Constants';
|
|
3
6
|
import { RequestHandler } from './RequestHandler';
|
|
7
|
+
export interface IRestEvents {
|
|
8
|
+
[RestEvents.Error]: [error: unknown];
|
|
9
|
+
[RestEvents.Debug]: [path: string, status: number, message: string];
|
|
10
|
+
[RestEvents.RateLimited]: [path: string, status: number, message: string];
|
|
11
|
+
}
|
|
12
|
+
export interface RESTManager {
|
|
13
|
+
emit: (<K extends keyof IRestEvents>(event: K, ...args: IRestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, ...args: any[]) => boolean);
|
|
14
|
+
off: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
15
|
+
on: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
16
|
+
once: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
17
|
+
removeAllListeners: (<K extends keyof IRestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IRestEvents>) => this);
|
|
18
|
+
/**
|
|
19
|
+
* Emitted for general debugging information.
|
|
20
|
+
* @public
|
|
21
|
+
* @event
|
|
22
|
+
*/
|
|
23
|
+
debug: string;
|
|
24
|
+
/**
|
|
25
|
+
* Emitted when the client encounters an error.
|
|
26
|
+
* @public
|
|
27
|
+
* @event
|
|
28
|
+
*/
|
|
29
|
+
error: string;
|
|
30
|
+
/**
|
|
31
|
+
* Emitted when the client is rate limited.
|
|
32
|
+
* @public
|
|
33
|
+
* @event
|
|
34
|
+
*/
|
|
35
|
+
rateLimited: string;
|
|
36
|
+
}
|
|
4
37
|
/** Represents a REST Manager of the client. */
|
|
5
|
-
export declare class RESTManager {
|
|
38
|
+
export declare class RESTManager extends EventEmitter {
|
|
6
39
|
/** Request Handler for the RESTManager. */
|
|
7
|
-
|
|
40
|
+
requestHandler: RequestHandler;
|
|
8
41
|
constructor(options?: RESTOptions);
|
|
9
42
|
/** Contains various general-purpose utility methods. */
|
|
10
43
|
get util(): typeof Util;
|
|
@@ -33,14 +66,20 @@ export declare class RESTManager {
|
|
|
33
66
|
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWarLeagueGroup>>;
|
|
34
67
|
/** Get info about a CWL round by WarTag. */
|
|
35
68
|
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWar>>;
|
|
69
|
+
/** Retrieve clan's capital raid seasons. */
|
|
70
|
+
getCapitalRaidSeasons(tag: string, options?: OverrideOptions): Promise<import("../types").Response<APICapitalRaidSeasons>>;
|
|
36
71
|
/** Get info about a player by tag. */
|
|
37
72
|
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIPlayer>>;
|
|
38
73
|
/** Verify Player API token that can be found from the Game settings. */
|
|
39
74
|
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("../types").Response<APIVerifyToken>>;
|
|
40
|
-
/** Get list of Leagues. */
|
|
75
|
+
/** Get a list of Leagues. */
|
|
41
76
|
getLeagues(options?: SearchOptions): Promise<import("../types").Response<APILeagueList>>;
|
|
42
77
|
/** Get a League info. */
|
|
43
78
|
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Response<APILeague>>;
|
|
79
|
+
/** Get a list of Capital leagues. */
|
|
80
|
+
getCapitalLeagues(options?: SearchOptions): Promise<import("../types").Response<APICapitalLeagueList>>;
|
|
81
|
+
/** Get a Capital League info. */
|
|
82
|
+
getCapitalLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Response<APICapitalLeague>>;
|
|
44
83
|
/** Get Legend League season Ids. */
|
|
45
84
|
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("../types").Response<APILeagueSeasonList>>;
|
|
46
85
|
/** Get Legend League season rankings by season Id. */
|
|
@@ -61,6 +100,8 @@ export declare class RESTManager {
|
|
|
61
100
|
getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanVersusRankingList>>;
|
|
62
101
|
/** Get player versus rankings for a specific location. */
|
|
63
102
|
getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerVersusRankingList>>;
|
|
103
|
+
/** Get clan capital rankings for a specific location. */
|
|
104
|
+
getClanCapitalRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanCapitalRankingList>>;
|
|
64
105
|
/** Get list of clan labels. */
|
|
65
106
|
getClanLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
|
|
66
107
|
/** Get list of player labels. */
|
package/dist/rest/RESTManager.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RESTManager = void 0;
|
|
4
|
+
const node_events_1 = require("node:events");
|
|
4
5
|
const Util_1 = require("../util/Util");
|
|
6
|
+
const Constants_1 = require("../util/Constants");
|
|
5
7
|
const RequestHandler_1 = require("./RequestHandler");
|
|
6
8
|
/** Represents a REST Manager of the client. */
|
|
7
|
-
class RESTManager {
|
|
9
|
+
class RESTManager extends node_events_1.EventEmitter {
|
|
8
10
|
constructor(options) {
|
|
9
|
-
|
|
11
|
+
super();
|
|
12
|
+
this.requestHandler = new RequestHandler_1.RequestHandler(options)
|
|
13
|
+
.on(Constants_1.RestEvents.Debug, this.emit.bind(this, Constants_1.RestEvents.Debug))
|
|
14
|
+
.on(Constants_1.RestEvents.Error, this.emit.bind(this, Constants_1.RestEvents.Error))
|
|
15
|
+
.on(Constants_1.RestEvents.RateLimited, this.emit.bind(this, Constants_1.RestEvents.RateLimited));
|
|
10
16
|
}
|
|
11
17
|
/** Contains various general-purpose utility methods. */
|
|
12
18
|
get util() {
|
|
@@ -21,122 +27,141 @@ class RESTManager {
|
|
|
21
27
|
* ```
|
|
22
28
|
*/
|
|
23
29
|
login(options) {
|
|
24
|
-
return this.
|
|
30
|
+
return this.requestHandler.init(options);
|
|
25
31
|
}
|
|
26
32
|
/** Set Clash of Clans API keys. */
|
|
27
33
|
setKeys(keys) {
|
|
28
|
-
this.
|
|
34
|
+
this.requestHandler.setKeys(keys);
|
|
29
35
|
return this;
|
|
30
36
|
}
|
|
31
37
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
32
38
|
getClans(query, options) {
|
|
33
|
-
return this.
|
|
39
|
+
return this.requestHandler.request(`/clans${Util_1.Util.queryString(query)}`, options);
|
|
34
40
|
}
|
|
35
41
|
/** Get info about a clan. */
|
|
36
42
|
getClan(clanTag, options) {
|
|
37
|
-
return this.
|
|
43
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}`, options);
|
|
38
44
|
}
|
|
39
45
|
/** Get list of clan members. */
|
|
40
46
|
getClanMembers(clanTag, options) {
|
|
41
47
|
const query = Util_1.Util.queryString(options);
|
|
42
|
-
return this.
|
|
48
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members${query}`, options);
|
|
43
49
|
}
|
|
44
50
|
/** Get clan war log. */
|
|
45
51
|
getClanWarLog(clanTag, options) {
|
|
46
52
|
const query = Util_1.Util.queryString(options);
|
|
47
|
-
return this.
|
|
53
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog${query}`, options);
|
|
48
54
|
}
|
|
49
55
|
/** Get info about currently running war in the clan. */
|
|
50
56
|
getCurrentWar(clanTag, options) {
|
|
51
|
-
return this.
|
|
57
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar`, options);
|
|
52
58
|
}
|
|
53
59
|
/** Get info about clan war league. */
|
|
54
60
|
getClanWarLeagueGroup(clanTag, options) {
|
|
55
|
-
return this.
|
|
61
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/currentwar/leaguegroup`, options);
|
|
56
62
|
}
|
|
57
63
|
/** Get info about a CWL round by WarTag. */
|
|
58
64
|
getClanWarLeagueRound(warTag, options) {
|
|
59
|
-
return this.
|
|
65
|
+
return this.requestHandler.request(`/clanwarleagues/wars/${Util_1.Util.encodeURI(warTag)}`, options);
|
|
66
|
+
}
|
|
67
|
+
/** Retrieve clan's capital raid seasons. */
|
|
68
|
+
getCapitalRaidSeasons(tag, options) {
|
|
69
|
+
const query = Util_1.Util.queryString(options);
|
|
70
|
+
return this.requestHandler.request(`/clans/${Util_1.Util.encodeURI(tag)}/capitalraidseasons${query}`, options);
|
|
60
71
|
}
|
|
61
72
|
/** Get info about a player by tag. */
|
|
62
73
|
getPlayer(playerTag, options) {
|
|
63
|
-
return this.
|
|
74
|
+
return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}`, options);
|
|
64
75
|
}
|
|
65
76
|
/** Verify Player API token that can be found from the Game settings. */
|
|
66
77
|
verifyPlayerToken(playerTag, token, options) {
|
|
67
78
|
const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
|
|
68
|
-
return this.
|
|
79
|
+
return this.requestHandler.request(`/players/${Util_1.Util.encodeURI(playerTag)}/verifytoken`, opts);
|
|
69
80
|
}
|
|
70
|
-
/** Get list of Leagues. */
|
|
81
|
+
/** Get a list of Leagues. */
|
|
71
82
|
getLeagues(options) {
|
|
72
83
|
const query = Util_1.Util.queryString(options);
|
|
73
|
-
return this.
|
|
84
|
+
return this.requestHandler.request(`/leagues${query}`, options);
|
|
74
85
|
}
|
|
75
86
|
/** Get a League info. */
|
|
76
87
|
getLeague(leagueId, options) {
|
|
77
|
-
return this.
|
|
88
|
+
return this.requestHandler.request(`/leagues/${leagueId}`, options);
|
|
89
|
+
}
|
|
90
|
+
/** Get a list of Capital leagues. */
|
|
91
|
+
getCapitalLeagues(options) {
|
|
92
|
+
const query = Util_1.Util.queryString(options);
|
|
93
|
+
return this.requestHandler.request(`/capitalleagues${query}`, options);
|
|
94
|
+
}
|
|
95
|
+
/** Get a Capital League info. */
|
|
96
|
+
getCapitalLeague(leagueId, options) {
|
|
97
|
+
return this.requestHandler.request(`/capitalleagues/${leagueId}`, options);
|
|
78
98
|
}
|
|
79
99
|
/** Get Legend League season Ids. */
|
|
80
100
|
getLeagueSeasons(leagueId, options) {
|
|
81
101
|
const query = Util_1.Util.queryString(options);
|
|
82
|
-
return this.
|
|
102
|
+
return this.requestHandler.request(`/leagues/${leagueId}/seasons${query}`, options);
|
|
83
103
|
}
|
|
84
104
|
/** Get Legend League season rankings by season Id. */
|
|
85
105
|
getSeasonRankings(leagueId, seasonId, options) {
|
|
86
106
|
const query = Util_1.Util.queryString(options);
|
|
87
|
-
return this.
|
|
107
|
+
return this.requestHandler.request(`/leagues/${leagueId}/seasons/${seasonId}${query}`, options);
|
|
88
108
|
}
|
|
89
109
|
/** Get list of Clan War Leagues. */
|
|
90
110
|
getWarLeagues(options) {
|
|
91
111
|
const query = Util_1.Util.queryString(options);
|
|
92
|
-
return this.
|
|
112
|
+
return this.requestHandler.request(`/warleagues${query}`, options);
|
|
93
113
|
}
|
|
94
114
|
/** Get info about a Clan War League. */
|
|
95
115
|
getWarLeague(leagueId, options) {
|
|
96
|
-
return this.
|
|
116
|
+
return this.requestHandler.request(`/warleagues/${leagueId}`, options);
|
|
97
117
|
}
|
|
98
118
|
/** Get list of Locations. */
|
|
99
119
|
getLocations(options) {
|
|
100
120
|
const query = Util_1.Util.queryString(options);
|
|
101
|
-
return this.
|
|
121
|
+
return this.requestHandler.request(`/locations${query}`, options);
|
|
102
122
|
}
|
|
103
123
|
/** Get info about a Location. */
|
|
104
124
|
getLocation(locationId, options) {
|
|
105
|
-
return this.
|
|
125
|
+
return this.requestHandler.request(`/locations/${locationId}`, options);
|
|
106
126
|
}
|
|
107
127
|
/** Get clan rankings for a specific location. */
|
|
108
128
|
getClanRanks(locationId, options) {
|
|
109
129
|
const query = Util_1.Util.queryString(options);
|
|
110
|
-
return this.
|
|
130
|
+
return this.requestHandler.request(`/locations/${locationId}/rankings/clans${query}`, options);
|
|
111
131
|
}
|
|
112
132
|
/** Get player rankings for a specific location. */
|
|
113
133
|
getPlayerRanks(locationId, options) {
|
|
114
134
|
const query = Util_1.Util.queryString(options);
|
|
115
|
-
return this.
|
|
135
|
+
return this.requestHandler.request(`/locations/${locationId}/rankings/players${query}`, options);
|
|
116
136
|
}
|
|
117
137
|
/** Get clan versus rankings for a specific location. */
|
|
118
138
|
getVersusClanRanks(locationId, options) {
|
|
119
139
|
const query = Util_1.Util.queryString(options);
|
|
120
|
-
return this.
|
|
140
|
+
return this.requestHandler.request(`/locations/${locationId}/rankings/clans-versus${query}`, options);
|
|
121
141
|
}
|
|
122
142
|
/** Get player versus rankings for a specific location. */
|
|
123
143
|
getVersusPlayerRanks(locationId, options) {
|
|
124
144
|
const query = Util_1.Util.queryString(options);
|
|
125
|
-
return this.
|
|
145
|
+
return this.requestHandler.request(`/locations/${locationId}/rankings/players-versus${query}`, options);
|
|
146
|
+
}
|
|
147
|
+
/** Get clan capital rankings for a specific location. */
|
|
148
|
+
getClanCapitalRanks(locationId, options) {
|
|
149
|
+
const query = Util_1.Util.queryString(options);
|
|
150
|
+
return this.requestHandler.request(`/locations/${locationId}/rankings/capitals${query}`, options);
|
|
126
151
|
}
|
|
127
152
|
/** Get list of clan labels. */
|
|
128
153
|
getClanLabels(options) {
|
|
129
154
|
const query = Util_1.Util.queryString(options);
|
|
130
|
-
return this.
|
|
155
|
+
return this.requestHandler.request(`/labels/clans${query}`, options);
|
|
131
156
|
}
|
|
132
157
|
/** Get list of player labels. */
|
|
133
158
|
getPlayerLabels(options) {
|
|
134
159
|
const query = Util_1.Util.queryString(options);
|
|
135
|
-
return this.
|
|
160
|
+
return this.requestHandler.request(`/labels/players${query}`, options);
|
|
136
161
|
}
|
|
137
162
|
/** Get info about gold pass season. */
|
|
138
163
|
getGoldPassSeason(options) {
|
|
139
|
-
return this.
|
|
164
|
+
return this.requestHandler.request('/goldpass/seasons/current', options);
|
|
140
165
|
}
|
|
141
166
|
}
|
|
142
167
|
exports.RESTManager = RESTManager;
|
|
@@ -1,6 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
1
3
|
import { Response, RequestOptions, LoginOptions, RequestHandlerOptions } from '../types';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
+
import { IRestEvents } from './RESTManager';
|
|
5
|
+
export interface RequestHandler {
|
|
6
|
+
emit: (<K extends keyof IRestEvents>(event: K, ...args: IRestEvents[K]) => boolean) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, ...args: any[]) => boolean);
|
|
7
|
+
off: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
8
|
+
on: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
9
|
+
once: (<K extends keyof IRestEvents>(event: K, listener: (...args: IRestEvents[K]) => void) => this) & (<S extends string | symbol>(event: Exclude<S, keyof IRestEvents>, listener: (...args: any[]) => void) => this);
|
|
10
|
+
removeAllListeners: (<K extends keyof IRestEvents>(event?: K) => this) & (<S extends string | symbol>(event?: Exclude<S, keyof IRestEvents>) => this);
|
|
11
|
+
/**
|
|
12
|
+
* Emitted for general debugging information.
|
|
13
|
+
* @public
|
|
14
|
+
* @event
|
|
15
|
+
*/
|
|
16
|
+
debug: string;
|
|
17
|
+
/**
|
|
18
|
+
* Emitted when the client encounters an error.
|
|
19
|
+
* @public
|
|
20
|
+
* @event
|
|
21
|
+
*/
|
|
22
|
+
error: string;
|
|
23
|
+
/**
|
|
24
|
+
* Emitted when the client is rate limited.
|
|
25
|
+
* @public
|
|
26
|
+
* @event
|
|
27
|
+
*/
|
|
28
|
+
rateLimited: string;
|
|
29
|
+
}
|
|
30
|
+
/** Represents the class that manages handlers for endpoints. */
|
|
31
|
+
export declare class RequestHandler extends EventEmitter {
|
|
4
32
|
#private;
|
|
5
33
|
private email;
|
|
6
34
|
private password;
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
26
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
27
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
@@ -17,15 +40,17 @@ var _RequestHandler_keyIndex;
|
|
|
17
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
41
|
exports.RequestHandler = void 0;
|
|
19
42
|
const node_https_1 = __importDefault(require("node:https"));
|
|
20
|
-
const
|
|
43
|
+
const node_events_1 = require("node:events");
|
|
44
|
+
const node_fetch_1 = __importStar(require("node-fetch"));
|
|
21
45
|
const Constants_1 = require("../util/Constants");
|
|
22
46
|
const Store_1 = require("../util/Store");
|
|
23
47
|
const HTTPError_1 = require("./HTTPError");
|
|
24
48
|
const IP_REGEX = /\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/g;
|
|
25
49
|
const agent = new node_https_1.default.Agent({ keepAlive: true });
|
|
26
|
-
/** Represents
|
|
27
|
-
class RequestHandler {
|
|
50
|
+
/** Represents the class that manages handlers for endpoints. */
|
|
51
|
+
class RequestHandler extends node_events_1.EventEmitter {
|
|
28
52
|
constructor(options) {
|
|
53
|
+
super();
|
|
29
54
|
_RequestHandler_keyIndex.set(this, 0); // eslint-disable-line
|
|
30
55
|
this.keys = options?.keys ?? [];
|
|
31
56
|
this.retryLimit = options?.retryLimit ?? 0;
|
|
@@ -64,35 +89,46 @@ class RequestHandler {
|
|
|
64
89
|
return this.exec(path, options);
|
|
65
90
|
}
|
|
66
91
|
async exec(path, options = {}, retries = 0) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
try {
|
|
93
|
+
const res = await (0, node_fetch_1.default)(`${this.baseURL}${path}`, {
|
|
94
|
+
agent,
|
|
95
|
+
body: options.body,
|
|
96
|
+
method: options.method,
|
|
97
|
+
timeout: options.restRequestTimeout ?? this.restRequestTimeout,
|
|
98
|
+
headers: { 'Authorization': `Bearer ${this._key}`, 'Content-Type': 'application/json' }
|
|
99
|
+
});
|
|
100
|
+
if (res.status === 504 && retries < (options.retryLimit ?? this.retryLimit)) {
|
|
101
|
+
return await this.exec(path, options, ++retries);
|
|
102
|
+
}
|
|
103
|
+
const data = await res.json();
|
|
104
|
+
if (this.creds &&
|
|
105
|
+
res.status === 403 &&
|
|
106
|
+
data.reason === 'accessDenied.invalidIp' &&
|
|
107
|
+
retries < (options.retryLimit ?? this.retryLimit)) {
|
|
108
|
+
const keys = await this.reValidateKeys().then(() => () => this.login());
|
|
109
|
+
if (keys.length)
|
|
110
|
+
return await this.exec(path, options, ++retries);
|
|
111
|
+
}
|
|
112
|
+
const maxAge = Number(res.headers.get('cache-control')?.split('=')?.[1] ?? 0) * 1000;
|
|
113
|
+
if (res.status === 403 && !data?.message && this.rejectIfNotValid) {
|
|
114
|
+
throw new HTTPError_1.HTTPError(HTTPError_1.PrivateWarLogError, res.status, path, maxAge);
|
|
115
|
+
}
|
|
116
|
+
if (!res.ok && this.rejectIfNotValid) {
|
|
117
|
+
throw new HTTPError_1.HTTPError(data, res.status, path, maxAge, options.method);
|
|
118
|
+
}
|
|
119
|
+
if (this.cached && maxAge > 0 && options.cache !== false && res.ok) {
|
|
120
|
+
await this.cached.set(path, { data, ttl: Date.now() + maxAge, status: res.status }, maxAge);
|
|
121
|
+
}
|
|
122
|
+
return { data, maxAge, status: res.status, path, ok: res.status === 200 };
|
|
91
123
|
}
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error instanceof node_fetch_1.FetchError && error.type === 'request-timeout' && retries < (options.retryLimit ?? this.retryLimit)) {
|
|
126
|
+
return this.exec(path, options, ++retries);
|
|
127
|
+
}
|
|
128
|
+
if (this.rejectIfNotValid)
|
|
129
|
+
throw error;
|
|
130
|
+
return { data: { message: error.message }, maxAge: 0, status: 500, path, ok: false };
|
|
94
131
|
}
|
|
95
|
-
return { data, maxAge, status: res?.status ?? 504, path, ok: res?.status === 200 };
|
|
96
132
|
}
|
|
97
133
|
async init(options) {
|
|
98
134
|
if (!(options.email && options.password))
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Client } from '../client/Client';
|
|
2
|
+
import { APICapitalRaidSeason, APICapitalRaidSeasonAttackLog, APICapitalRaidSeasonDefenseLog, APICapitalRaidSeasonMember, OverrideOptions } from '../types';
|
|
3
|
+
import { Player } from './Player';
|
|
4
|
+
export declare class CapitalRaidSeasonMember {
|
|
5
|
+
/** The player's tag. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** The player's name. */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** The number of attacks the player has made. */
|
|
10
|
+
attacks: number;
|
|
11
|
+
/** The number of attacks the player can make. */
|
|
12
|
+
attackLimit: number;
|
|
13
|
+
/** The number of bonus attacks the player can make. */
|
|
14
|
+
bonusAttackLimit: number;
|
|
15
|
+
/** The number of capital resources the player has looted. */
|
|
16
|
+
capitalResourcesLooted: number;
|
|
17
|
+
constructor(data: APICapitalRaidSeasonMember);
|
|
18
|
+
}
|
|
19
|
+
/** Represents a Capital Raid Season. */
|
|
20
|
+
export declare class CapitalRaidSeason {
|
|
21
|
+
private readonly client;
|
|
22
|
+
/** The state of the raid season. */
|
|
23
|
+
state: 'ongoing' | 'ended';
|
|
24
|
+
/** The start time of the raid season. */
|
|
25
|
+
startTime: Date;
|
|
26
|
+
/** The end time of the raid season. */
|
|
27
|
+
endTime: Date;
|
|
28
|
+
/** The total loot collected from the capital. */
|
|
29
|
+
capitalTotalLoot: number;
|
|
30
|
+
/** The number of raids completed. */
|
|
31
|
+
raidsCompleted: number;
|
|
32
|
+
/** The total number of attacks. */
|
|
33
|
+
totalAttacks: number;
|
|
34
|
+
/** The number of enemy districts destroyed. */
|
|
35
|
+
enemyDistrictsDestroyed: number;
|
|
36
|
+
/** The offensive reward. */
|
|
37
|
+
offensiveReward: number;
|
|
38
|
+
/** The defensive reward. */
|
|
39
|
+
defensiveReward: number;
|
|
40
|
+
/** The members of the raid season. */
|
|
41
|
+
members: APICapitalRaidSeasonMember[];
|
|
42
|
+
/** The attack log of the raid season. */
|
|
43
|
+
attackLog: APICapitalRaidSeasonAttackLog[];
|
|
44
|
+
/** The defense log of the raid season. */
|
|
45
|
+
defenseLog: APICapitalRaidSeasonDefenseLog[];
|
|
46
|
+
constructor(client: Client, data: APICapitalRaidSeason);
|
|
47
|
+
/** Get {@link Player} info for every Player in the clan. */
|
|
48
|
+
fetchMembers(options?: OverrideOptions): Promise<Player[]>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CapitalRaidSeason = exports.CapitalRaidSeasonMember = void 0;
|
|
4
|
+
const Util_1 = require("../util/Util");
|
|
5
|
+
class CapitalRaidSeasonMember {
|
|
6
|
+
constructor(data) {
|
|
7
|
+
this.tag = data.tag;
|
|
8
|
+
this.name = data.name;
|
|
9
|
+
this.attacks = data.attacks;
|
|
10
|
+
this.attackLimit = data.attackLimit;
|
|
11
|
+
this.bonusAttackLimit = data.bonusAttackLimit;
|
|
12
|
+
this.capitalResourcesLooted = data.capitalResourcesLooted;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CapitalRaidSeasonMember = CapitalRaidSeasonMember;
|
|
16
|
+
/** Represents a Capital Raid Season. */
|
|
17
|
+
class CapitalRaidSeason {
|
|
18
|
+
constructor(client, data) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
this.state = data.state;
|
|
21
|
+
this.startTime = Util_1.Util.formatDate(data.startTime);
|
|
22
|
+
this.endTime = Util_1.Util.formatDate(data.endTime);
|
|
23
|
+
this.capitalTotalLoot = data.capitalTotalLoot;
|
|
24
|
+
this.raidsCompleted = data.raidsCompleted;
|
|
25
|
+
this.totalAttacks = data.totalAttacks;
|
|
26
|
+
this.enemyDistrictsDestroyed = data.enemyDistrictsDestroyed;
|
|
27
|
+
this.offensiveReward = data.offensiveReward;
|
|
28
|
+
this.defensiveReward = data.defensiveReward;
|
|
29
|
+
this.attackLog = data.attackLog;
|
|
30
|
+
this.defenseLog = data.defenseLog;
|
|
31
|
+
this.members = (data.members ?? []).map((member) => new CapitalRaidSeasonMember(member));
|
|
32
|
+
}
|
|
33
|
+
/** Get {@link Player} info for every Player in the clan. */
|
|
34
|
+
async fetchMembers(options) {
|
|
35
|
+
return (await Promise.allSettled(this.members.map((m) => this.client.getPlayer(m.tag, { ...options, ignoreRateLimit: true }))))
|
|
36
|
+
.filter((res) => res.status === 'fulfilled')
|
|
37
|
+
.map((res) => res.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.CapitalRaidSeason = CapitalRaidSeason;
|
package/dist/struct/Clan.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIClan, OverrideOptions } from '../types';
|
|
1
|
+
import { APICapitalLeague, APIClan, OverrideOptions } from '../types';
|
|
2
2
|
import { Client } from '../client/Client';
|
|
3
3
|
import { ChatLanguage } from './ChatLanguage';
|
|
4
4
|
import { ClanMember } from './ClanMember';
|
|
@@ -29,6 +29,8 @@ export declare class Clan {
|
|
|
29
29
|
level: number;
|
|
30
30
|
/** The clan's trophy count. */
|
|
31
31
|
points: number;
|
|
32
|
+
/** The clan's capital points. */
|
|
33
|
+
capitalPoints: number;
|
|
32
34
|
/** The clan's versus trophy count. */
|
|
33
35
|
versusPoints: number;
|
|
34
36
|
/** The minimum trophies required to apply to this clan. */
|
|
@@ -57,6 +59,10 @@ export declare class Clan {
|
|
|
57
59
|
labels: Label[];
|
|
58
60
|
/** The clan's Clan Capital information */
|
|
59
61
|
clanCapital: ClanCapital | null;
|
|
62
|
+
/** The clan's capital league. */
|
|
63
|
+
capitalLeague?: APICapitalLeague;
|
|
64
|
+
/** Whether the clan is family friendly. */
|
|
65
|
+
isFamilyFriendly: boolean;
|
|
60
66
|
/**
|
|
61
67
|
* List of clan members.
|
|
62
68
|
* - This property returns empty array for {@link Client.getClans} method.
|
package/dist/struct/Clan.js
CHANGED
|
@@ -35,6 +35,9 @@ class Clan {
|
|
|
35
35
|
this.memberCount = data.members;
|
|
36
36
|
this.labels = data.labels.map((label) => new Label_1.Label(label));
|
|
37
37
|
this.clanCapital = Object.keys(data.clanCapital).length > 0 ? new ClanCapital_1.ClanCapital(data.clanCapital) : null;
|
|
38
|
+
this.isFamilyFriendly = data.isFamilyFriendly;
|
|
39
|
+
this.capitalPoints = data.clanCapitalPoints;
|
|
40
|
+
this.capitalLeague = data.capitalLeague;
|
|
38
41
|
this.members = data.memberList?.map((mem) => new ClanMember_1.ClanMember(this.client, mem)) ?? []; // eslint-disable-line
|
|
39
42
|
}
|
|
40
43
|
/** Get {@link Player} info for every Player in the clan. */
|
|
@@ -4,7 +4,7 @@ exports.ClanCapital = void 0;
|
|
|
4
4
|
class ClanCapital {
|
|
5
5
|
constructor(data) {
|
|
6
6
|
this.capitalHallLevel = data.capitalHallLevel ?? null;
|
|
7
|
-
this.districts = data.districts
|
|
7
|
+
this.districts = data.districts ?? null;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.ClanCapital = ClanCapital;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIClanMember, OverrideOptions } from '../types';
|
|
1
|
+
import { APIClanMember, APIPlayerHouse, OverrideOptions } from '../types';
|
|
2
2
|
import { Client } from '../client/Client';
|
|
3
3
|
import { League } from './League';
|
|
4
4
|
export declare class ClanMember {
|
|
@@ -25,6 +25,8 @@ export declare class ClanMember {
|
|
|
25
25
|
donations: number;
|
|
26
26
|
/** The member's donation received count for this season. */
|
|
27
27
|
received: number;
|
|
28
|
+
/** The member's player house details. */
|
|
29
|
+
playerHouse?: APIPlayerHouse | null;
|
|
28
30
|
constructor(client: Client, data: APIClanMember);
|
|
29
31
|
/** Whether this clan member is in the clan. */
|
|
30
32
|
get isMember(): boolean;
|
|
@@ -18,6 +18,7 @@ class ClanMember {
|
|
|
18
18
|
this.clanRank = data.clanRank;
|
|
19
19
|
this.previousClanRank = data.previousClanRank;
|
|
20
20
|
this.donations = data.donations;
|
|
21
|
+
this.playerHouse = data.playerHouse ?? null;
|
|
21
22
|
this.received = data.donationsReceived;
|
|
22
23
|
}
|
|
23
24
|
/** Whether this clan member is in the clan. */
|