clashofclans.js 3.1.2-dev.cb50d96 → 3.1.3-dev.048e4b9

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.
@@ -75,8 +75,8 @@ class Client extends node_events_1.EventEmitter {
75
75
  }
76
76
  /** Get info about currently running war (normal or friendly) in the clan. */
77
77
  async getClanWar(clanTag, options) {
78
- const { data, maxAge } = await this.rest.getCurrentWar(clanTag, options);
79
- return new struct_1.ClanWar(this, data, { clanTag, maxAge });
78
+ const { data, res } = await this.rest.getCurrentWar(clanTag, options);
79
+ return new struct_1.ClanWar(this, data, { clanTag, maxAge: res.maxAge });
80
80
  }
81
81
  /**
82
82
  * Get info about currently running war in the clan.
@@ -166,8 +166,8 @@ class Client extends node_events_1.EventEmitter {
166
166
  /** Get info about a CWL round by WarTag. */
167
167
  async getClanWarLeagueRound(warTag, options) {
168
168
  const args = typeof warTag === 'string' ? { warTag } : { warTag: warTag.warTag, clanTag: warTag.clanTag };
169
- const { data, maxAge } = await this.rest.getClanWarLeagueRound(args.warTag, options);
170
- return new struct_1.ClanWar(this, data, { warTag: args.warTag, clanTag: args.clanTag, maxAge });
169
+ const { data, res } = await this.rest.getClanWarLeagueRound(args.warTag, options);
170
+ return new struct_1.ClanWar(this, data, { warTag: args.warTag, clanTag: args.clanTag, maxAge: res.maxAge });
171
171
  }
172
172
  /** Get info about a player by tag. */
173
173
  async getPlayer(playerTag, options) {
@@ -155,7 +155,7 @@ class PollingClient extends Client_1.Client {
155
155
  if (!(this.listenerCount(Constants_1.PollingEvents.MaintenanceStart) && this.listenerCount(Constants_1.PollingEvents.MaintenanceEnd)))
156
156
  return;
157
157
  try {
158
- const res = await this.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
158
+ const { res } = await this.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
159
159
  if (res.status === 200 && this.inMaintenance) {
160
160
  this.inMaintenance = Boolean(false);
161
161
  const duration = Date.now() - this._maintenanceStartTime.getTime();
@@ -36,8 +36,8 @@ class RequestHandler extends node_events_1.EventEmitter {
36
36
  else
37
37
  this.cached = options?.cache === true ? new Store_1.CacheStore() : null;
38
38
  this.dispatcher = new undici_1.Pool(new URL(this.baseURL).origin, {
39
- connections: 50,
40
- pipelining: 10
39
+ connections: options?.connections ?? null,
40
+ pipelining: options?.pipelining ?? 1
41
41
  });
42
42
  }
43
43
  get _keys() {
@@ -58,7 +58,10 @@ class RequestHandler extends node_events_1.EventEmitter {
58
58
  async request(path, options = {}) {
59
59
  const cached = this.cached ? (await this.cached.get(path)) ?? null : null;
60
60
  if (cached && options.force !== true) {
61
- return { data: cached.data, maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 };
61
+ return {
62
+ data: cached.data,
63
+ res: { maxAge: cached.ttl - Date.now(), status: cached.status, path, ok: cached.status === 200 }
64
+ };
62
65
  }
63
66
  if (!this.throttler || options.ignoreRateLimit)
64
67
  return this.exec(path, options);
@@ -96,7 +99,10 @@ class RequestHandler extends node_events_1.EventEmitter {
96
99
  if (this.cached && maxAge > 0 && options.cache !== false && res.statusCode === 200) {
97
100
  await this.cached.set(path, { data, ttl: Date.now() + maxAge, status: res.statusCode }, maxAge);
98
101
  }
99
- return { data: data, maxAge, status: res.statusCode, path, ok: res.statusCode === 200 };
102
+ return {
103
+ data: data,
104
+ res: { maxAge, status: res.statusCode, path, ok: res.statusCode === 200 }
105
+ };
100
106
  }
101
107
  catch (error) {
102
108
  if (error.code === 'UND_ERR_ABORTED' && retries < (options.retryLimit ?? this.retryLimit)) {
@@ -104,7 +110,10 @@ class RequestHandler extends node_events_1.EventEmitter {
104
110
  }
105
111
  if (this.rejectIfNotValid)
106
112
  throw error;
107
- return { data: { message: error.message }, maxAge: 0, status: 500, path, ok: false };
113
+ return {
114
+ data: { message: error.message },
115
+ res: { maxAge: 0, status: 500, path, ok: false }
116
+ };
108
117
  }
109
118
  }
110
119
  async init(options) {
@@ -46,7 +46,7 @@ export declare class ClanWarLeagueRound {
46
46
  export declare class ClanWarLeagueGroup {
47
47
  private readonly client;
48
48
  /** The CWL group's current war state. */
49
- state: 'preparation' | 'inWar' | 'ended';
49
+ state: 'preparation' | 'inWar' | 'ended' | 'notInWar';
50
50
  /** Season Id of this CWL group. */
51
51
  season: string;
52
52
  /** Returns all participating clans. */
@@ -54,6 +54,8 @@ export declare class ClanWarLeagueGroup {
54
54
  /** An array containing all war tags for each round. */
55
55
  rounds: ClanWarLeagueRound[];
56
56
  constructor(client: Client, data: APIClanWarLeagueGroup);
57
+ /** Whether the clan is not in CWL group. */
58
+ get isNotInWar(): boolean;
57
59
  /** Total number of rounds for this CWL. */
58
60
  get totalRounds(): number;
59
61
  /**
@@ -49,11 +49,16 @@ exports.ClanWarLeagueRound = ClanWarLeagueRound;
49
49
  class ClanWarLeagueGroup {
50
50
  constructor(client, data) {
51
51
  this.client = client;
52
- // @ts-expect-error
53
52
  this.state = data.state;
54
- this.season = data.season;
55
- this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
56
- this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
53
+ if (this.state !== 'notInWar') {
54
+ this.season = data.season;
55
+ this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
56
+ this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
57
+ }
58
+ }
59
+ /** Whether the clan is not in CWL group. */
60
+ get isNotInWar() {
61
+ return this.state === 'notInWar';
57
62
  }
58
63
  /** Total number of rounds for this CWL. */
59
64
  get totalRounds() {
@@ -50,6 +50,10 @@ export interface PollingClientOptions extends ClientOptions {
50
50
  export interface RequestHandlerOptions extends ClientOptions {
51
51
  /** Set this `false` to use `res.ok` property. */
52
52
  rejectIfNotValid?: boolean;
53
+ /** The max number of clients to create. null if no limit. Default null. */
54
+ connections?: number;
55
+ /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to RFC7230. Default: 1 */
56
+ pipelining?: number;
53
57
  }
54
58
  /** Search options for request. */
55
59
  export interface SearchOptions extends OverrideOptions {
@@ -88,16 +92,18 @@ export interface RequestOptions extends OverrideOptions {
88
92
  method?: string;
89
93
  }
90
94
  export interface Response<T> {
91
- /** Whether the response is ok. */
92
- ok: boolean;
93
95
  /** The response body. */
94
96
  data: T;
95
- /** Path of the request for this response. */
96
- path: string;
97
- /** HTTP status code of this response. */
98
- status: number;
99
- /** The maxAge of this response. */
100
- maxAge: number;
97
+ res: {
98
+ /** Whether the response is ok. */
99
+ ok: boolean;
100
+ /** Path of the request for this response. */
101
+ path: string;
102
+ /** HTTP status code of this response. */
103
+ status: number;
104
+ /** The maxAge of this response. */
105
+ maxAge: number;
106
+ };
101
107
  }
102
108
  /**
103
109
  * Clan search options for a request.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.1.2-dev.cb50d96",
3
+ "version": "3.1.3-dev.048e4b9",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
- "author": "SUVAJIT <suvajit.me@gmail.com>",
5
+ "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "exports": {