clashofclans.js 2.3.0 → 2.4.0-dev.eb4c4f5
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 +13 -0
- package/LICENSE +1 -2
- package/dist/client/Client.d.ts +2 -2
- package/dist/rest/HTTPError.d.ts +1 -1
- package/dist/rest/RESTManager.d.ts +27 -27
- package/dist/rest/RequestHandler.d.ts +4 -136
- package/dist/rest/RequestHandler.js +8 -5
- package/dist/struct/Badge.d.ts +8 -7
- package/dist/struct/Badge.js +9 -15
- package/dist/struct/Clan.d.ts +1 -2
- package/dist/struct/ClanMember.d.ts +1 -2
- package/dist/struct/ClanWar.d.ts +8 -1
- package/dist/struct/ClanWar.js +15 -2
- package/dist/struct/ClanWarLeagueGroup.d.ts +1 -2
- package/dist/struct/ClanWarLog.d.ts +0 -2
- package/dist/struct/ClanWarLog.js +0 -2
- package/dist/struct/Icon.d.ts +9 -8
- package/dist/struct/Icon.js +9 -15
- package/dist/struct/Player.d.ts +1 -2
- package/dist/struct/PlayerClan.d.ts +1 -2
- package/dist/types/api.d.ts +351 -0
- package/dist/types/api.js +2 -0
- package/dist/types/index.d.ts +2 -351
- package/dist/types/index.js +12 -0
- package/dist/types/lib.d.ts +139 -0
- package/dist/types/lib.js +2 -0
- package/dist/util/Util.d.ts +2 -1
- package/dist/util/Util.js +15 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
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
|
+
## 2.4.0 (2021-12-28)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- `ClanWar#getClanWarLeagueGroup`, `ClanWar#isCWL` and `ClanWar#isFriendly` are now available. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
10
|
+
- `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))
|
|
11
|
+
- `Icon#fileName` and `Icon#sizes` are now available in `Icon` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
12
|
+
- `Badge#fileName` and `Badge#sizes` are now available in `Badge` class. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
13
|
+
|
|
14
|
+
### Deprecations
|
|
15
|
+
|
|
16
|
+
- `ClanWarMember#previousBestOpponentAttack` has been deprecated. Use `ClanWarAttack#previousBestAttack` instead. ([#87](https://github.com/clashperk/clashofclans.js/pull/87))
|
|
17
|
+
|
|
5
18
|
## 2.3.0 (2021-12-17)
|
|
6
19
|
|
|
7
20
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020 - 2021
|
|
4
|
-
Copyright (c) 2020 - 2021 TheLearneer
|
|
3
|
+
Copyright (c) 2020 - 2021 ClashPerk
|
|
5
4
|
|
|
6
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/client/Client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ClanSearchOptions, SearchOptions, ClientOptions,
|
|
2
|
+
import { ClanSearchOptions, SearchOptions, ClientOptions, LoginOptions, OverrideOptions } from '../types';
|
|
3
3
|
import { EVENTS, CWL_ROUNDS } from '../util/Constants';
|
|
4
4
|
import { RESTManager } from '../rest/RESTManager';
|
|
5
5
|
import { EventManager } from './EventManager';
|
|
@@ -31,7 +31,7 @@ export declare class Client extends EventEmitter {
|
|
|
31
31
|
* client.login({ email: 'developer@email.com', password: '***' });
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
login(options:
|
|
34
|
+
login(options: LoginOptions): Promise<string[]>;
|
|
35
35
|
/** Set Clash of Clans API keys. */
|
|
36
36
|
setKeys(keys: string[]): this;
|
|
37
37
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
package/dist/rest/HTTPError.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class HTTPError extends Error {
|
|
|
8
8
|
* The reason of this errored request.
|
|
9
9
|
*
|
|
10
10
|
* Expected values are `notFound`, `notInWar`, `accessDenied`, `accessDenied.invalidIp`, `privateWarLog`,
|
|
11
|
-
* `badRequest`, `requestThrottled`, `
|
|
11
|
+
* `badRequest`, `requestThrottled`, `inMaintenance`, `requestAborted` and `unknownException`.
|
|
12
12
|
*/
|
|
13
13
|
reason: string;
|
|
14
14
|
/** The HTTP status code of this request. */
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { RequestHandler
|
|
2
|
-
import { APIClan, APIClanList, APIClanMemberList, APIClanRankingList, APIClanVersusRankingList, APIClanWar, APIClanWarLeagueGroup, APIClanWarLog, APIGoldPassSeason, APILabelList, APILeague, APILeagueList, APILeagueSeasonList, APILocation, APILocationList, APIPlayer, APIPlayerRankingList, APIPlayerSeasonRankingList, APIPlayerVersusRankingList, APIVerifyToken, APIWarLeague, APIWarLeagueList } from '../types';
|
|
1
|
+
import { RequestHandler } from './RequestHandler';
|
|
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 } from '../types';
|
|
3
3
|
/** Represents a REST Manager of the client. */
|
|
4
4
|
export declare class RESTManager {
|
|
5
5
|
/** Request Handler for the RESTManager. */
|
|
6
6
|
readonly handler: RequestHandler;
|
|
7
|
-
constructor(options?:
|
|
7
|
+
constructor(options?: RESTOptions);
|
|
8
8
|
/** Search all clans by name and/or filtering the results using various criteria. */
|
|
9
|
-
getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("
|
|
9
|
+
getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("../types").Response<APIClanList>>;
|
|
10
10
|
/** Get info about a clan. */
|
|
11
|
-
getClan(clanTag: string, options?: OverrideOptions): Promise<import("
|
|
11
|
+
getClan(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClan>>;
|
|
12
12
|
/** Get list of clan members. */
|
|
13
|
-
getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("
|
|
13
|
+
getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("../types").Response<APIClanMemberList>>;
|
|
14
14
|
/** Get clan war log. */
|
|
15
|
-
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("
|
|
15
|
+
getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("../types").Response<APIClanWarLog>>;
|
|
16
16
|
/** Get info about currently running war in the clan. */
|
|
17
|
-
getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("
|
|
17
|
+
getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWar>>;
|
|
18
18
|
/** Get info about clan war league. */
|
|
19
|
-
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("
|
|
19
|
+
getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWarLeagueGroup>>;
|
|
20
20
|
/** Get info about a CWL round by WarTag. */
|
|
21
|
-
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("
|
|
21
|
+
getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWar>>;
|
|
22
22
|
/** Get info about a player by tag. */
|
|
23
|
-
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("
|
|
23
|
+
getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIPlayer>>;
|
|
24
24
|
/** Verify Player API token that can be found from the Game settings. */
|
|
25
|
-
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("
|
|
25
|
+
verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("../types").Response<APIVerifyToken>>;
|
|
26
26
|
/** Get list of Leagues. */
|
|
27
|
-
getLeagues(options?: SearchOptions): Promise<import("
|
|
27
|
+
getLeagues(options?: SearchOptions): Promise<import("../types").Response<APILeagueList>>;
|
|
28
28
|
/** Get a League info. */
|
|
29
|
-
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("
|
|
29
|
+
getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Response<APILeague>>;
|
|
30
30
|
/** Get Legend League season Ids. */
|
|
31
|
-
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("
|
|
31
|
+
getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("../types").Response<APILeagueSeasonList>>;
|
|
32
32
|
/** Get Legend League season rankings by season Id. */
|
|
33
|
-
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("
|
|
33
|
+
getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerSeasonRankingList>>;
|
|
34
34
|
/** Get list of Clan War Leagues. */
|
|
35
|
-
getWarLeagues(options?: SearchOptions): Promise<import("
|
|
35
|
+
getWarLeagues(options?: SearchOptions): Promise<import("../types").Response<APIWarLeagueList>>;
|
|
36
36
|
/** Get info about a Clan War League. */
|
|
37
|
-
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("
|
|
37
|
+
getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("../types").Response<APIWarLeague>>;
|
|
38
38
|
/** Get list of Locations. */
|
|
39
|
-
getLocations(options?: SearchOptions): Promise<import("
|
|
39
|
+
getLocations(options?: SearchOptions): Promise<import("../types").Response<APILocationList>>;
|
|
40
40
|
/** Get info about a Location. */
|
|
41
|
-
getLocation(locationId: number, options?: OverrideOptions): Promise<import("
|
|
41
|
+
getLocation(locationId: number, options?: OverrideOptions): Promise<import("../types").Response<APILocation>>;
|
|
42
42
|
/** Get clan rankings for a specific location. */
|
|
43
|
-
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("
|
|
43
|
+
getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanRankingList>>;
|
|
44
44
|
/** Get player rankings for a specific location. */
|
|
45
|
-
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("
|
|
45
|
+
getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerRankingList>>;
|
|
46
46
|
/** Get clan versus rankings for a specific location. */
|
|
47
|
-
getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("
|
|
47
|
+
getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanVersusRankingList>>;
|
|
48
48
|
/** Get player versus rankings for a specific location. */
|
|
49
|
-
getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("
|
|
49
|
+
getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerVersusRankingList>>;
|
|
50
50
|
/** Get list of clan labels. */
|
|
51
|
-
getClanLabels(options?: SearchOptions): Promise<import("
|
|
51
|
+
getClanLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
|
|
52
52
|
/** Get list of player labels. */
|
|
53
|
-
getPlayerLabels(options?: SearchOptions): Promise<import("
|
|
53
|
+
getPlayerLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
|
|
54
54
|
/** Get info about gold pass season. */
|
|
55
|
-
getGoldPassSeason(options?: OverrideOptions): Promise<import("
|
|
55
|
+
getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").Response<APIGoldPassSeason>>;
|
|
56
56
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Keyv from 'keyv';
|
|
1
|
+
import { RESTOptions, Response, RequestOptions, LoginOptions } from '../types';
|
|
3
2
|
/** Represents a Request Handler. */
|
|
4
3
|
export declare class RequestHandler {
|
|
5
4
|
#private;
|
|
@@ -10,17 +9,18 @@ export declare class RequestHandler {
|
|
|
10
9
|
private keyDescription?;
|
|
11
10
|
private keys;
|
|
12
11
|
private readonly baseURL;
|
|
12
|
+
private readonly rejectIfNotValid;
|
|
13
13
|
private readonly retryLimit;
|
|
14
14
|
private readonly restRequestTimeout;
|
|
15
15
|
private readonly throttler?;
|
|
16
16
|
private readonly cached;
|
|
17
|
-
constructor(options?:
|
|
17
|
+
constructor(options?: RESTOptions);
|
|
18
18
|
private get _keys();
|
|
19
19
|
private get _key();
|
|
20
20
|
setKeys(keys: string[]): this;
|
|
21
21
|
request<T>(path: string, options?: RequestOptions): Promise<Response<T>>;
|
|
22
22
|
private exec;
|
|
23
|
-
init(options:
|
|
23
|
+
init(options: LoginOptions): Promise<string[]>;
|
|
24
24
|
private reValidateKeys;
|
|
25
25
|
private login;
|
|
26
26
|
private getKeys;
|
|
@@ -28,135 +28,3 @@ export declare class RequestHandler {
|
|
|
28
28
|
private createKey;
|
|
29
29
|
private getIp;
|
|
30
30
|
}
|
|
31
|
-
/** Options for a client. */
|
|
32
|
-
export interface ClientOptions {
|
|
33
|
-
/** Keys from Clash of Clans API developer site. */
|
|
34
|
-
keys?: string[];
|
|
35
|
-
/** Base URL of the Clash of Clans API. */
|
|
36
|
-
baseURL?: string;
|
|
37
|
-
/**
|
|
38
|
-
* How many times to retry on 5XX errors.
|
|
39
|
-
*/
|
|
40
|
-
retryLimit?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Whether enable or disable internal caching.
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const client = new Client({ cache: true });
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
cache?: boolean | Keyv;
|
|
49
|
-
/** Time to wait before cancelling a REST request, in milliseconds. */
|
|
50
|
-
restRequestTimeout?: number;
|
|
51
|
-
/**
|
|
52
|
-
* Throttler class which handles rate-limit
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* const client = new Client({ throttler: new QueueThrottler(1000 / 10) });
|
|
56
|
-
* ```
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* const client = new Client({ throttler: new BatchThrottler(30) });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
throttler?: QueueThrottler | BatchThrottler;
|
|
63
|
-
}
|
|
64
|
-
/** Search options for request. */
|
|
65
|
-
export interface SearchOptions extends OverrideOptions {
|
|
66
|
-
/** Limit the number of items returned in the response. */
|
|
67
|
-
limit?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Return only items that occur after this marker.
|
|
70
|
-
* Before marker can be found from the response, inside the 'paging' property.
|
|
71
|
-
* Note that only after or before can be specified for a request, not both.
|
|
72
|
-
*/
|
|
73
|
-
after?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Return only items that occur before this marker.
|
|
76
|
-
* Before marker can be found from the response, inside the 'paging' property.
|
|
77
|
-
* Note that only after or before can be specified for a request, not both.
|
|
78
|
-
*/
|
|
79
|
-
before?: string;
|
|
80
|
-
}
|
|
81
|
-
/** Override options for a request. */
|
|
82
|
-
export interface OverrideOptions {
|
|
83
|
-
/** Whether to cache this response. */
|
|
84
|
-
cache?: boolean;
|
|
85
|
-
/** Whether to skip the cache check and request the API. */
|
|
86
|
-
force?: boolean;
|
|
87
|
-
/** How many times to retry on 5XX errors. */
|
|
88
|
-
retryLimit?: string;
|
|
89
|
-
/** Whether to ignore throttlers. */
|
|
90
|
-
ignoreRateLimit?: boolean;
|
|
91
|
-
/** Time to wait before cancelling a REST request, in milliseconds. */
|
|
92
|
-
restRequestTimeout?: number;
|
|
93
|
-
}
|
|
94
|
-
export interface RequestOptions extends OverrideOptions {
|
|
95
|
-
/** The request body. */
|
|
96
|
-
body?: string;
|
|
97
|
-
/** The request method. */
|
|
98
|
-
method?: string;
|
|
99
|
-
}
|
|
100
|
-
export interface Response<T> {
|
|
101
|
-
/** The response body. */
|
|
102
|
-
data: T;
|
|
103
|
-
/** Path of the request for this response. */
|
|
104
|
-
path: string;
|
|
105
|
-
/** HTTP status code of this response. */
|
|
106
|
-
status: number;
|
|
107
|
-
/** The maxAge of this response. */
|
|
108
|
-
maxAge: number;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Clan search options for a request.
|
|
112
|
-
*
|
|
113
|
-
* ::info
|
|
114
|
-
* If name is used as part of search query, it needs to be at least three characters long.
|
|
115
|
-
* Name search parameter is interpreted as wild card search, so it may appear anywhere in the clan name.
|
|
116
|
-
* :::
|
|
117
|
-
*/
|
|
118
|
-
export interface ClanSearchOptions {
|
|
119
|
-
/** Search clans by name. */
|
|
120
|
-
name?: string;
|
|
121
|
-
/** Filter by minimum number of clan members. */
|
|
122
|
-
minMembers?: number;
|
|
123
|
-
/** Filter by maximum number of clan members. */
|
|
124
|
-
maxMembers?: number;
|
|
125
|
-
/** Filter by minimum amount of clan points. */
|
|
126
|
-
minClanPoints?: number;
|
|
127
|
-
/** Filter by minimum clan level. */
|
|
128
|
-
minClanLevel?: number;
|
|
129
|
-
/** Filter by clan war frequency. */
|
|
130
|
-
warFrequency?: string;
|
|
131
|
-
/** Filter by clan location identifier. For list of available locations, refer to getLocations operation. */
|
|
132
|
-
locationId?: string;
|
|
133
|
-
/** Comma separated list of label IDs to use for filtering results. */
|
|
134
|
-
labelIds?: string;
|
|
135
|
-
/** Limit the number of items returned in the response. */
|
|
136
|
-
limit?: number;
|
|
137
|
-
/**
|
|
138
|
-
* Return only items that occur after this marker.
|
|
139
|
-
* Before marker can be found from the response, inside the 'paging' property.
|
|
140
|
-
* Note that only after or before can be specified for a request, not both.
|
|
141
|
-
*/
|
|
142
|
-
after?: string;
|
|
143
|
-
/**
|
|
144
|
-
* Return only items that occur before this marker.
|
|
145
|
-
* Before marker can be found from the response, inside the 'paging' property.
|
|
146
|
-
* Note that only after or before can be specified for a request, not both.
|
|
147
|
-
*/
|
|
148
|
-
before?: string;
|
|
149
|
-
}
|
|
150
|
-
/** Login options for a client. */
|
|
151
|
-
export interface InitOptions {
|
|
152
|
-
/** Developer site email address. */
|
|
153
|
-
email: string;
|
|
154
|
-
/** Developer site password. */
|
|
155
|
-
password: string;
|
|
156
|
-
/** Name of API key(s). */
|
|
157
|
-
keyName?: string;
|
|
158
|
-
/** Number of allowed API keys. */
|
|
159
|
-
keyCount?: number;
|
|
160
|
-
/** Description of API key(s). */
|
|
161
|
-
keyDescription?: string;
|
|
162
|
-
}
|
|
@@ -32,6 +32,7 @@ class RequestHandler {
|
|
|
32
32
|
this.throttler = options?.throttler ?? null;
|
|
33
33
|
this.baseURL = options?.baseURL ?? Constants_1.API_BASE_URL;
|
|
34
34
|
this.restRequestTimeout = options?.restRequestTimeout ?? 0;
|
|
35
|
+
this.rejectIfNotValid = options?.rejectIfNotValid ?? true;
|
|
35
36
|
if (options?.cache instanceof keyv_1.default)
|
|
36
37
|
this.cached = options.cache;
|
|
37
38
|
else
|
|
@@ -52,7 +53,7 @@ class RequestHandler {
|
|
|
52
53
|
async request(path, options = {}) {
|
|
53
54
|
const cached = (await this.cached?.get(path)) ?? null;
|
|
54
55
|
if (cached && options.force !== true) {
|
|
55
|
-
return { data: cached.data, maxAge: cached.ttl - Date.now(), status:
|
|
56
|
+
return { data: cached.data, maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 };
|
|
56
57
|
}
|
|
57
58
|
if (!this.throttler || options.ignoreRateLimit)
|
|
58
59
|
return this.exec(path, options);
|
|
@@ -81,14 +82,16 @@ class RequestHandler {
|
|
|
81
82
|
return this.exec(path, options, ++retries);
|
|
82
83
|
}
|
|
83
84
|
const maxAge = Number(res?.headers.get('cache-control')?.split('=')?.[1] ?? 0) * 1000;
|
|
84
|
-
if (res?.status === 403 && !data?.message)
|
|
85
|
+
if (res?.status === 403 && !data?.message && this.rejectIfNotValid) {
|
|
85
86
|
throw new HTTPError_1.HTTPError(HTTPError_1.PrivateWarLogError, res.status, path, maxAge);
|
|
86
|
-
|
|
87
|
+
}
|
|
88
|
+
if (!res?.ok && this.rejectIfNotValid) {
|
|
87
89
|
throw new HTTPError_1.HTTPError(data, res?.status ?? 504, path, maxAge, options.method);
|
|
90
|
+
}
|
|
88
91
|
if (this.cached && maxAge > 0 && options.cache !== false) {
|
|
89
|
-
await this.cached.set(path, { data, ttl: Date.now() + maxAge }, maxAge);
|
|
92
|
+
await this.cached.set(path, { data, ttl: Date.now() + maxAge, status: res?.status ?? 504 }, maxAge);
|
|
90
93
|
}
|
|
91
|
-
return { data, maxAge, status: res
|
|
94
|
+
return { data, maxAge, status: res?.status ?? 504, path, ok: res?.status === 200 };
|
|
92
95
|
}
|
|
93
96
|
async init(options) {
|
|
94
97
|
if (!(options.email && options.password))
|
package/dist/struct/Badge.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { APIBadge } from '../types';
|
|
2
2
|
/** Represents a Clash of Clans Badge. */
|
|
3
3
|
export declare class Badge {
|
|
4
|
-
private readonly _data;
|
|
5
4
|
/** The default badge URL. */
|
|
6
5
|
url: string;
|
|
7
|
-
constructor(data: APIBadge);
|
|
8
6
|
/** The large badge URL. */
|
|
9
|
-
|
|
7
|
+
large: string;
|
|
10
8
|
/** The medium badge URL. */
|
|
11
|
-
|
|
9
|
+
medium: string;
|
|
12
10
|
/** The small badge URL. */
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
small: string;
|
|
12
|
+
constructor(data: APIBadge);
|
|
13
|
+
/** Get unique file name of this Badge. */
|
|
14
|
+
get fileName(): string;
|
|
15
|
+
/** Sizes of this Badge. */
|
|
16
|
+
get sizes(): string[];
|
|
16
17
|
}
|
package/dist/struct/Badge.js
CHANGED
|
@@ -4,24 +4,18 @@ exports.Badge = void 0;
|
|
|
4
4
|
/** Represents a Clash of Clans Badge. */
|
|
5
5
|
class Badge {
|
|
6
6
|
constructor(data) {
|
|
7
|
-
Object.defineProperty(this, '_data', { value: data });
|
|
8
7
|
this.url = data.large;
|
|
8
|
+
Object.defineProperty(this, 'large', { value: data.large });
|
|
9
|
+
Object.defineProperty(this, 'medium', { value: data.medium });
|
|
10
|
+
Object.defineProperty(this, 'small', { value: data.small });
|
|
9
11
|
}
|
|
10
|
-
/**
|
|
11
|
-
get
|
|
12
|
-
return this._data.large;
|
|
13
|
-
}
|
|
14
|
-
/** The medium badge URL. */
|
|
15
|
-
get medium() {
|
|
16
|
-
return this._data.medium;
|
|
17
|
-
}
|
|
18
|
-
/** The small badge URL. */
|
|
19
|
-
get small() {
|
|
20
|
-
return this._data.small;
|
|
21
|
-
}
|
|
22
|
-
/** Get unique hash of this Badge. */
|
|
23
|
-
get hash() {
|
|
12
|
+
/** Get unique file name of this Badge. */
|
|
13
|
+
get fileName() {
|
|
24
14
|
return this.url.split('/').pop();
|
|
25
15
|
}
|
|
16
|
+
/** Sizes of this Badge. */
|
|
17
|
+
get sizes() {
|
|
18
|
+
return [this.large, this.medium, this.small].map((url) => /\/(\d+)\//g.exec(url)[1]);
|
|
19
|
+
}
|
|
26
20
|
}
|
|
27
21
|
exports.Badge = Badge;
|
package/dist/struct/Clan.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { OverrideOptions } from '../
|
|
1
|
+
import { APIClan, OverrideOptions } from '../types';
|
|
2
2
|
import { ChatLanguage } from './ChatLanguage';
|
|
3
3
|
import { ClanMember } from './ClanMember';
|
|
4
4
|
import { Client } from '../client/Client';
|
|
5
5
|
import { WarLeague } from './WarLeague';
|
|
6
6
|
import type { Player } from './Player';
|
|
7
7
|
import { Location } from './Location';
|
|
8
|
-
import { APIClan } from '../types';
|
|
9
8
|
import { Label } from './Label';
|
|
10
9
|
import { Badge } from './Badge';
|
|
11
10
|
/** Represents a Clan. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { OverrideOptions } from '../
|
|
1
|
+
import { APIClanMember, OverrideOptions } from '../types';
|
|
2
2
|
import { Client } from '../client/Client';
|
|
3
|
-
import { APIClanMember } from '../types';
|
|
4
3
|
import { League } from './League';
|
|
5
4
|
export declare class ClanMember {
|
|
6
5
|
client: Client;
|
package/dist/struct/ClanWar.d.ts
CHANGED
|
@@ -61,6 +61,8 @@ export declare class ClanWarMember {
|
|
|
61
61
|
/**
|
|
62
62
|
* Returns the previous best opponent attack on this village.
|
|
63
63
|
* This is useful for calculating the new stars or destruction for new attacks.
|
|
64
|
+
*
|
|
65
|
+
* @deprecated `order` is affecting this method. Use {@link ClanWarAttack#previousBestAttack} instead.
|
|
64
66
|
*/
|
|
65
67
|
previousBestOpponentAttack(): ClanWarAttack | null;
|
|
66
68
|
}
|
|
@@ -131,7 +133,12 @@ export declare class ClanWar {
|
|
|
131
133
|
getDefenses(defenderTag: string): ClanWarAttack[];
|
|
132
134
|
/** Returns either `friendly`, `cwl` or `normal`. */
|
|
133
135
|
get type(): "friendly" | "cwl" | "normal";
|
|
134
|
-
|
|
136
|
+
/** Whether this is a friendly war. */
|
|
137
|
+
get isFriendly(): boolean;
|
|
138
|
+
/** Whether this is a CWL. */
|
|
139
|
+
get isCWL(): boolean;
|
|
135
140
|
/** Returns the war status, based off the home clan. */
|
|
136
141
|
get status(): "win" | "lose" | "tie" | "pending";
|
|
142
|
+
/** Returns the Clan War League Group. */
|
|
143
|
+
getClanWarLeagueGroup(): Promise<import("./ClanWarLeagueGroup").ClanWarLeagueGroup> | null;
|
|
137
144
|
}
|
package/dist/struct/ClanWar.js
CHANGED
|
@@ -75,6 +75,8 @@ class ClanWarMember {
|
|
|
75
75
|
/**
|
|
76
76
|
* Returns the previous best opponent attack on this village.
|
|
77
77
|
* This is useful for calculating the new stars or destruction for new attacks.
|
|
78
|
+
*
|
|
79
|
+
* @deprecated `order` is affecting this method. Use {@link ClanWarAttack#previousBestAttack} instead.
|
|
78
80
|
*/
|
|
79
81
|
previousBestOpponentAttack() {
|
|
80
82
|
return (
|
|
@@ -170,16 +172,21 @@ class ClanWar {
|
|
|
170
172
|
}
|
|
171
173
|
/** Returns either `friendly`, `cwl` or `normal`. */
|
|
172
174
|
get type() {
|
|
173
|
-
if (this.
|
|
175
|
+
if (this.isFriendly)
|
|
174
176
|
return 'friendly';
|
|
175
177
|
if (this.warTag)
|
|
176
178
|
return 'cwl';
|
|
177
179
|
return 'normal';
|
|
178
180
|
}
|
|
179
|
-
|
|
181
|
+
/** Whether this is a friendly war. */
|
|
182
|
+
get isFriendly() {
|
|
180
183
|
const preparationTime = this.startTime.getTime() - this.preparationStartTime.getTime();
|
|
181
184
|
return Constants_1.FRIENDLY_WAR_PREPARATION_TIMES.includes(preparationTime);
|
|
182
185
|
}
|
|
186
|
+
/** Whether this is a CWL. */
|
|
187
|
+
get isCWL() {
|
|
188
|
+
return typeof this.warTag === 'string';
|
|
189
|
+
}
|
|
183
190
|
/** Returns the war status, based off the home clan. */
|
|
184
191
|
get status() {
|
|
185
192
|
if (this.state === 'preparation')
|
|
@@ -194,5 +201,11 @@ class ClanWar {
|
|
|
194
201
|
}
|
|
195
202
|
return 'lose';
|
|
196
203
|
}
|
|
204
|
+
/** Returns the Clan War League Group. */
|
|
205
|
+
getClanWarLeagueGroup() {
|
|
206
|
+
if (!this.isCWL)
|
|
207
|
+
return null;
|
|
208
|
+
return this.client.getClanWarLeagueGroup(this.clan.tag);
|
|
209
|
+
}
|
|
197
210
|
}
|
|
198
211
|
exports.ClanWar = ClanWar;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { APIClanWarLeagueClan, APIClanWarLeagueClanMember, APIClanWarLeagueGroup, APIClanWarLeagueRound } from '../types';
|
|
2
|
-
import { OverrideOptions } from '../rest/RequestHandler';
|
|
1
|
+
import { APIClanWarLeagueClan, APIClanWarLeagueClanMember, APIClanWarLeagueGroup, APIClanWarLeagueRound, OverrideOptions } from '../types';
|
|
3
2
|
import { Client } from '../client/Client';
|
|
4
3
|
import { ClanWar } from './ClanWar';
|
|
5
4
|
import { Player } from './Player';
|
|
@@ -4,10 +4,8 @@ import { Badge } from './Badge';
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents War Log Clan.
|
|
6
6
|
*
|
|
7
|
-
* :::caution
|
|
8
7
|
* If this is called via {@link ClanWarLog.opponent}, then {@link WarLogClan.attackCount} and {@link WarLogClan.expEarned} will be `null`.
|
|
9
8
|
* For CWL entries {@link WarLogClan.name} and {@link WarLogClan.tag} are `null`.
|
|
10
|
-
* :::
|
|
11
9
|
*/
|
|
12
10
|
export declare class WarLogClan {
|
|
13
11
|
/** The clan's name. This property is `null` CWL entries. */
|
|
@@ -6,10 +6,8 @@ const Badge_1 = require("./Badge");
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents War Log Clan.
|
|
8
8
|
*
|
|
9
|
-
* :::caution
|
|
10
9
|
* If this is called via {@link ClanWarLog.opponent}, then {@link WarLogClan.attackCount} and {@link WarLogClan.expEarned} will be `null`.
|
|
11
10
|
* For CWL entries {@link WarLogClan.name} and {@link WarLogClan.tag} are `null`.
|
|
12
|
-
* :::
|
|
13
11
|
*/
|
|
14
12
|
class WarLogClan {
|
|
15
13
|
constructor(data) {
|
package/dist/struct/Icon.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { APIIcon } from '../types';
|
|
2
2
|
/** Represents a Clash of Clans Icon. */
|
|
3
3
|
export declare class Icon {
|
|
4
|
-
private readonly _data;
|
|
5
4
|
/** The default icon URL. */
|
|
6
5
|
url: string;
|
|
7
|
-
constructor(data: APIIcon);
|
|
8
6
|
/** The medium icon URL. */
|
|
9
|
-
|
|
10
|
-
/** The tiny icon URL. */
|
|
11
|
-
get tiny(): string;
|
|
7
|
+
medium: string;
|
|
12
8
|
/** The small icon URL. */
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
9
|
+
small: string;
|
|
10
|
+
/** The tiny icon URL. */
|
|
11
|
+
tiny: string;
|
|
12
|
+
constructor(data: APIIcon);
|
|
13
|
+
/** Get unique file name of this Icon. */
|
|
14
|
+
get fileName(): string;
|
|
15
|
+
/** Sizes of this Icon. */
|
|
16
|
+
get sizes(): string[];
|
|
16
17
|
}
|
package/dist/struct/Icon.js
CHANGED
|
@@ -4,24 +4,18 @@ exports.Icon = void 0;
|
|
|
4
4
|
/** Represents a Clash of Clans Icon. */
|
|
5
5
|
class Icon {
|
|
6
6
|
constructor(data) {
|
|
7
|
-
Object.defineProperty(this, '_data', { value: data });
|
|
8
7
|
this.url = data.medium ?? data.small;
|
|
8
|
+
Object.defineProperty(this, 'medium', { value: data.medium ?? data.small });
|
|
9
|
+
Object.defineProperty(this, 'tiny', { value: data.tiny ?? data.small });
|
|
10
|
+
Object.defineProperty(this, 'small', { value: data.small });
|
|
9
11
|
}
|
|
10
|
-
/**
|
|
11
|
-
get
|
|
12
|
-
return this._data.medium ?? this._data.small;
|
|
13
|
-
}
|
|
14
|
-
/** The tiny icon URL. */
|
|
15
|
-
get tiny() {
|
|
16
|
-
return this._data.tiny ?? this._data.small;
|
|
17
|
-
}
|
|
18
|
-
/** The small icon URL. */
|
|
19
|
-
get small() {
|
|
20
|
-
return this._data.small;
|
|
21
|
-
}
|
|
22
|
-
/** Get unique hash of this Badge. */
|
|
23
|
-
get hash() {
|
|
12
|
+
/** Get unique file name of this Icon. */
|
|
13
|
+
get fileName() {
|
|
24
14
|
return this.url.split('/').pop();
|
|
25
15
|
}
|
|
16
|
+
/** Sizes of this Icon. */
|
|
17
|
+
get sizes() {
|
|
18
|
+
return [this.medium, this.small, this.tiny].map((url) => /\/(\d+)\//g.exec(url)[1]);
|
|
19
|
+
}
|
|
26
20
|
}
|
|
27
21
|
exports.Icon = Icon;
|
package/dist/struct/Player.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { OverrideOptions } from '../
|
|
1
|
+
import { APIPlayer, OverrideOptions } from '../types';
|
|
2
2
|
import { LegendStatistics } from './LegendStatistics';
|
|
3
3
|
import { Achievement } from './Achievement';
|
|
4
4
|
import { Hero, Spell, Troop } from './Unit';
|
|
5
5
|
import { PlayerClan } from './PlayerClan';
|
|
6
6
|
import { Client } from '../client/Client';
|
|
7
|
-
import { APIPlayer } from '../types';
|
|
8
7
|
import { League } from './League';
|
|
9
8
|
import { Label } from './Label';
|
|
10
9
|
/** Represents a Clash of Clans Player. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { OverrideOptions } from '../
|
|
1
|
+
import { OverrideOptions, APIPlayerClan } from '../types';
|
|
2
2
|
import { Client } from '../client/Client';
|
|
3
|
-
import { APIPlayerClan } from '../types';
|
|
4
3
|
import { Badge } from './Badge';
|
|
5
4
|
/** Represents a Player's clan. */
|
|
6
5
|
export declare class PlayerClan {
|