clashofclans.js 2.3.0 → 2.4.0-dev.e127930

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,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 csuvajit
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
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { ClanSearchOptions, SearchOptions, ClientOptions, InitOptions, OverrideOptions } from '../rest/RequestHandler';
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: InitOptions): Promise<string[]>;
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. */
@@ -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`, `serviceUnavailable`, `requestAborted` and `unknownException`.
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,70 @@
1
- import { RequestHandler, SearchOptions, ClanSearchOptions, ClientOptions, OverrideOptions } 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 } from '../types';
1
+ import { RequestHandler } from './RequestHandler';
2
+ import { Util } from '../util/Util';
3
+ 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';
3
4
  /** Represents a REST Manager of the client. */
4
5
  export declare class RESTManager {
5
6
  /** Request Handler for the RESTManager. */
6
7
  readonly handler: RequestHandler;
7
- constructor(options?: ClientOptions);
8
+ constructor(options?: RESTOptions);
9
+ /** Contains various general-purpose utility methods. */
10
+ get util(): typeof Util;
11
+ /**
12
+ * Initialize the client to create keys.
13
+ * @example
14
+ * ```
15
+ * const rest = new RESTManager();
16
+ * rest.login({ email: 'developer@email.com', password: '***' });
17
+ * ```
18
+ */
19
+ login(options: LoginOptions): Promise<string[]>;
20
+ /** Set Clash of Clans API keys. */
21
+ setKeys(keys: string[]): this;
8
22
  /** Search all clans by name and/or filtering the results using various criteria. */
9
- getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanList>>;
23
+ getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<import("../types").Response<APIClanList>>;
10
24
  /** Get info about a clan. */
11
- getClan(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClan>>;
25
+ getClan(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClan>>;
12
26
  /** Get list of clan members. */
13
- getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanMemberList>>;
27
+ getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("../types").Response<APIClanMemberList>>;
14
28
  /** Get clan war log. */
15
- getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanWarLog>>;
29
+ getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("../types").Response<APIClanWarLog>>;
16
30
  /** Get info about currently running war in the clan. */
17
- getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
31
+ getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWar>>;
18
32
  /** Get info about clan war league. */
19
- getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWarLeagueGroup>>;
33
+ getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWarLeagueGroup>>;
20
34
  /** Get info about a CWL round by WarTag. */
21
- getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
35
+ getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIClanWar>>;
22
36
  /** Get info about a player by tag. */
23
- getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIPlayer>>;
37
+ getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("../types").Response<APIPlayer>>;
24
38
  /** Verify Player API token that can be found from the Game settings. */
25
- verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIVerifyToken>>;
39
+ verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("../types").Response<APIVerifyToken>>;
26
40
  /** Get list of Leagues. */
27
- getLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueList>>;
41
+ getLeagues(options?: SearchOptions): Promise<import("../types").Response<APILeagueList>>;
28
42
  /** Get a League info. */
29
- getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILeague>>;
43
+ getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("../types").Response<APILeague>>;
30
44
  /** Get Legend League season Ids. */
31
- getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueSeasonList>>;
45
+ getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("../types").Response<APILeagueSeasonList>>;
32
46
  /** Get Legend League season rankings by season Id. */
33
- getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerSeasonRankingList>>;
47
+ getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerSeasonRankingList>>;
34
48
  /** Get list of Clan War Leagues. */
35
- getWarLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APIWarLeagueList>>;
49
+ getWarLeagues(options?: SearchOptions): Promise<import("../types").Response<APIWarLeagueList>>;
36
50
  /** Get info about a Clan War League. */
37
- getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIWarLeague>>;
51
+ getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("../types").Response<APIWarLeague>>;
38
52
  /** Get list of Locations. */
39
- getLocations(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILocationList>>;
53
+ getLocations(options?: SearchOptions): Promise<import("../types").Response<APILocationList>>;
40
54
  /** Get info about a Location. */
41
- getLocation(locationId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILocation>>;
55
+ getLocation(locationId: number, options?: OverrideOptions): Promise<import("../types").Response<APILocation>>;
42
56
  /** Get clan rankings for a specific location. */
43
- getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanRankingList>>;
57
+ getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanRankingList>>;
44
58
  /** Get player rankings for a specific location. */
45
- getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerRankingList>>;
59
+ getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerRankingList>>;
46
60
  /** Get clan versus rankings for a specific location. */
47
- getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanVersusRankingList>>;
61
+ getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIClanVersusRankingList>>;
48
62
  /** Get player versus rankings for a specific location. */
49
- getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerVersusRankingList>>;
63
+ getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("../types").Response<APIPlayerVersusRankingList>>;
50
64
  /** Get list of clan labels. */
51
- getClanLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
65
+ getClanLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
52
66
  /** Get list of player labels. */
53
- getPlayerLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
67
+ getPlayerLabels(options?: SearchOptions): Promise<import("../types").Response<APILabelList>>;
54
68
  /** Get info about gold pass season. */
55
- getGoldPassSeason(options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIGoldPassSeason>>;
69
+ getGoldPassSeason(options?: OverrideOptions): Promise<import("../types").Response<APIGoldPassSeason>>;
56
70
  }
@@ -8,9 +8,29 @@ class RESTManager {
8
8
  constructor(options) {
9
9
  this.handler = new RequestHandler_1.RequestHandler(options);
10
10
  }
11
+ /** Contains various general-purpose utility methods. */
12
+ get util() {
13
+ return Util_1.Util;
14
+ }
15
+ /**
16
+ * Initialize the client to create keys.
17
+ * @example
18
+ * ```
19
+ * const rest = new RESTManager();
20
+ * rest.login({ email: 'developer@email.com', password: '***' });
21
+ * ```
22
+ */
23
+ login(options) {
24
+ return this.handler.init(options);
25
+ }
26
+ /** Set Clash of Clans API keys. */
27
+ setKeys(keys) {
28
+ this.handler.setKeys(keys);
29
+ return this;
30
+ }
11
31
  /** Search all clans by name and/or filtering the results using various criteria. */
12
32
  getClans(query, options) {
13
- return this.handler.request(`/clans?${Util_1.Util.queryString(query)}`, options);
33
+ return this.handler.request(`/clans${Util_1.Util.queryString(query)}`, options);
14
34
  }
15
35
  /** Get info about a clan. */
16
36
  getClan(clanTag, options) {
@@ -19,12 +39,12 @@ class RESTManager {
19
39
  /** Get list of clan members. */
20
40
  getClanMembers(clanTag, options) {
21
41
  const query = Util_1.Util.queryString(options);
22
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members?${query}`, options);
42
+ return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/members${query}`, options);
23
43
  }
24
44
  /** Get clan war log. */
25
45
  getClanWarLog(clanTag, options) {
26
46
  const query = Util_1.Util.queryString(options);
27
- return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog?${query}`, options);
47
+ return this.handler.request(`/clans/${Util_1.Util.encodeURI(clanTag)}/warlog${query}`, options);
28
48
  }
29
49
  /** Get info about currently running war in the clan. */
30
50
  getCurrentWar(clanTag, options) {
@@ -50,7 +70,7 @@ class RESTManager {
50
70
  /** Get list of Leagues. */
51
71
  getLeagues(options) {
52
72
  const query = Util_1.Util.queryString(options);
53
- return this.handler.request(`/leagues?${query}`, options);
73
+ return this.handler.request(`/leagues${query}`, options);
54
74
  }
55
75
  /** Get a League info. */
56
76
  getLeague(leagueId, options) {
@@ -59,17 +79,17 @@ class RESTManager {
59
79
  /** Get Legend League season Ids. */
60
80
  getLeagueSeasons(leagueId, options) {
61
81
  const query = Util_1.Util.queryString(options);
62
- return this.handler.request(`/leagues/${leagueId}/seasons?${query}`, options);
82
+ return this.handler.request(`/leagues/${leagueId}/seasons${query}`, options);
63
83
  }
64
84
  /** Get Legend League season rankings by season Id. */
65
85
  getSeasonRankings(leagueId, seasonId, options) {
66
86
  const query = Util_1.Util.queryString(options);
67
- return this.handler.request(`/leagues/${leagueId}/seasons/${seasonId}?${query}`, options);
87
+ return this.handler.request(`/leagues/${leagueId}/seasons/${seasonId}${query}`, options);
68
88
  }
69
89
  /** Get list of Clan War Leagues. */
70
90
  getWarLeagues(options) {
71
91
  const query = Util_1.Util.queryString(options);
72
- return this.handler.request(`/warleagues?${query}`, options);
92
+ return this.handler.request(`/warleagues${query}`, options);
73
93
  }
74
94
  /** Get info about a Clan War League. */
75
95
  getWarLeague(leagueId, options) {
@@ -78,7 +98,7 @@ class RESTManager {
78
98
  /** Get list of Locations. */
79
99
  getLocations(options) {
80
100
  const query = Util_1.Util.queryString(options);
81
- return this.handler.request(`/locations?${query}`, options);
101
+ return this.handler.request(`/locations${query}`, options);
82
102
  }
83
103
  /** Get info about a Location. */
84
104
  getLocation(locationId, options) {
@@ -87,32 +107,32 @@ class RESTManager {
87
107
  /** Get clan rankings for a specific location. */
88
108
  getClanRanks(locationId, options) {
89
109
  const query = Util_1.Util.queryString(options);
90
- return this.handler.request(`/locations/${locationId}/rankings/clans?${query}`, options);
110
+ return this.handler.request(`/locations/${locationId}/rankings/clans${query}`, options);
91
111
  }
92
112
  /** Get player rankings for a specific location. */
93
113
  getPlayerRanks(locationId, options) {
94
114
  const query = Util_1.Util.queryString(options);
95
- return this.handler.request(`/locations/${locationId}/rankings/players?${query}`, options);
115
+ return this.handler.request(`/locations/${locationId}/rankings/players${query}`, options);
96
116
  }
97
117
  /** Get clan versus rankings for a specific location. */
98
118
  getVersusClanRanks(locationId, options) {
99
119
  const query = Util_1.Util.queryString(options);
100
- return this.handler.request(`/locations/${locationId}/rankings/clans-versus?${query}`, options);
120
+ return this.handler.request(`/locations/${locationId}/rankings/clans-versus${query}`, options);
101
121
  }
102
122
  /** Get player versus rankings for a specific location. */
103
123
  getVersusPlayerRanks(locationId, options) {
104
124
  const query = Util_1.Util.queryString(options);
105
- return this.handler.request(`/locations/${locationId}/rankings/players-versus?${query}`, options);
125
+ return this.handler.request(`/locations/${locationId}/rankings/players-versus${query}`, options);
106
126
  }
107
127
  /** Get list of clan labels. */
108
128
  getClanLabels(options) {
109
129
  const query = Util_1.Util.queryString(options);
110
- return this.handler.request(`/labels/clans?${query}`, options);
130
+ return this.handler.request(`/labels/clans${query}`, options);
111
131
  }
112
132
  /** Get list of player labels. */
113
133
  getPlayerLabels(options) {
114
134
  const query = Util_1.Util.queryString(options);
115
- return this.handler.request(`/labels/players?${query}`, options);
135
+ return this.handler.request(`/labels/players${query}`, options);
116
136
  }
117
137
  /** Get info about gold pass season. */
118
138
  getGoldPassSeason(options) {
@@ -1,5 +1,4 @@
1
- import { QueueThrottler, BatchThrottler } from './Throttler';
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?: ClientOptions);
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: InitOptions): Promise<string[]>;
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: 200, path };
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
- if (!res?.ok)
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.status, path };
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))
@@ -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
- get large(): string;
7
+ large: string;
10
8
  /** The medium badge URL. */
11
- get medium(): string;
9
+ medium: string;
12
10
  /** The small badge URL. */
13
- get small(): string;
14
- /** Get unique hash of this Badge. */
15
- get hash(): string;
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
  }
@@ -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
- /** The large badge URL. */
11
- get large() {
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;
@@ -1,11 +1,10 @@
1
- import { OverrideOptions } from '../rest/RequestHandler';
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 '../rest/RequestHandler';
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;
@@ -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
- private get _isFriendly();
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
  }
@@ -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._isFriendly)
175
+ if (this.isFriendly)
174
176
  return 'friendly';
175
177
  if (this.warTag)
176
178
  return 'cwl';
177
179
  return 'normal';
178
180
  }
179
- get _isFriendly() {
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';