clashofclans.js 2.6.1-dev.a42d488 → 2.7.0-dev.31f642e

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.
@@ -34,8 +34,8 @@ export declare class Client extends EventEmitter {
34
34
  login(options: LoginOptions): Promise<string[]>;
35
35
  /** Set Clash of Clans API keys. */
36
36
  setKeys(keys: string[]): this;
37
- /** Search all clans by name and/or filtering the results using various criteria. */
38
- getClans(query: ClanSearchOptions, options?: OverrideOptions): Promise<Clan[]>;
37
+ /** Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel). */
38
+ getClans(query: ClanSearchOptions | string[], options?: OverrideOptions): Promise<Clan[]>;
39
39
  /** Get info about a clan. */
40
40
  getClan(clanTag: string, options?: OverrideOptions): Promise<Clan>;
41
41
  /** Get list of clan members. */
@@ -85,6 +85,8 @@ export declare class Client extends EventEmitter {
85
85
  }, options?: OverrideOptions): Promise<ClanWar>;
86
86
  /** Get info about a player by tag. */
87
87
  getPlayer(playerTag: string, options?: OverrideOptions): Promise<Player>;
88
+ /** Get info about some players by their tags (fetches in parallel). */
89
+ getPlayers(playerTags: string[], options?: OverrideOptions): Promise<Player[]>;
88
90
  /** Verify Player API token that can be found from the Game settings. */
89
91
  verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<boolean>;
90
92
  /** Get list of Leagues. */
@@ -46,8 +46,13 @@ class Client extends events_1.EventEmitter {
46
46
  this.rest.handler.setKeys(keys);
47
47
  return this;
48
48
  }
49
- /** Search all clans by name and/or filtering the results using various criteria. */
49
+ /** Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel). */
50
50
  async getClans(query, options) {
51
+ if (Array.isArray(query)) {
52
+ return (await Promise.allSettled(query.map((tag) => this.getClan(tag, options))))
53
+ .filter((res) => res.status === 'fulfilled')
54
+ .map((res) => res.value);
55
+ }
51
56
  const { data } = await this.rest.getClans(query, options);
52
57
  // @ts-expect-error
53
58
  return data.items.map((clan) => new struct_1.Clan(this, clan));
@@ -170,6 +175,12 @@ class Client extends events_1.EventEmitter {
170
175
  const { data } = await this.rest.getPlayer(playerTag, options);
171
176
  return new struct_1.Player(this, data);
172
177
  }
178
+ /** Get info about some players by their tags (fetches in parallel). */
179
+ async getPlayers(playerTags, options) {
180
+ return (await Promise.allSettled(playerTags.map((tag) => this.getPlayer(tag, options))))
181
+ .filter((res) => res.status === 'fulfilled')
182
+ .map((res) => res.value);
183
+ }
173
184
  /** Verify Player API token that can be found from the Game settings. */
174
185
  async verifyPlayerToken(playerTag, token, options) {
175
186
  const { data } = await this.rest.verifyPlayerToken(playerTag, token, options);
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod;
4
+ export const API_BASE_URL = mod.API_BASE_URL;
5
+ export const Achievement = mod.Achievement;
6
+ export const BUILDER_TROOPS = mod.BUILDER_TROOPS;
7
+ export const Badge = mod.Badge;
8
+ export const BatchThrottler = mod.BatchThrottler;
9
+ export const CWL_ROUNDS = mod.CWL_ROUNDS;
10
+ export const CacheStore = mod.CacheStore;
11
+ export const ChatLanguage = mod.ChatLanguage;
12
+ export const Clan = mod.Clan;
13
+ export const ClanMember = mod.ClanMember;
14
+ export const ClanWar = mod.ClanWar;
15
+ export const ClanWarAttack = mod.ClanWarAttack;
16
+ export const ClanWarLeagueClan = mod.ClanWarLeagueClan;
17
+ export const ClanWarLeagueClanMember = mod.ClanWarLeagueClanMember;
18
+ export const ClanWarLeagueGroup = mod.ClanWarLeagueGroup;
19
+ export const ClanWarLeagueRound = mod.ClanWarLeagueRound;
20
+ export const ClanWarLog = mod.ClanWarLog;
21
+ export const ClanWarMember = mod.ClanWarMember;
22
+ export const Client = mod.Client;
23
+ export const DARK_ELIXIR_SPELLS = mod.DARK_ELIXIR_SPELLS;
24
+ export const DARK_ELIXIR_TROOPS = mod.DARK_ELIXIR_TROOPS;
25
+ export const DEV_SITE_API_BASE_URL = mod.DEV_SITE_API_BASE_URL;
26
+ export const ELIXIR_SPELLS = mod.ELIXIR_SPELLS;
27
+ export const ELIXIR_TROOPS = mod.ELIXIR_TROOPS;
28
+ export const EVENTS = mod.EVENTS;
29
+ export const EventManager = mod.EventManager;
30
+ export const FRIENDLY_WAR_PREPARATION_TIMES = mod.FRIENDLY_WAR_PREPARATION_TIMES;
31
+ export const GoldPassSeason = mod.GoldPassSeason;
32
+ export const HEROES = mod.HEROES;
33
+ export const HERO_PETS = mod.HERO_PETS;
34
+ export const HOME_TROOPS = mod.HOME_TROOPS;
35
+ export const HTTPError = mod.HTTPError;
36
+ export const Hero = mod.Hero;
37
+ export const Icon = mod.Icon;
38
+ export const LEAGUES = mod.LEAGUES;
39
+ export const LEGEND_LEAGUE_ID = mod.LEGEND_LEAGUE_ID;
40
+ export const Label = mod.Label;
41
+ export const League = mod.League;
42
+ export const LegendStatistics = mod.LegendStatistics;
43
+ export const Location = mod.Location;
44
+ export const NotInWarError = mod.NotInWarError;
45
+ export const Player = mod.Player;
46
+ export const PlayerClan = mod.PlayerClan;
47
+ export const PrivateWarLogError = mod.PrivateWarLogError;
48
+ export const QueueThrottler = mod.QueueThrottler;
49
+ export const RESTManager = mod.RESTManager;
50
+ export const RankedClan = mod.RankedClan;
51
+ export const RankedPlayer = mod.RankedPlayer;
52
+ export const RequestHandler = mod.RequestHandler;
53
+ export const SIEGE_MACHINES = mod.SIEGE_MACHINES;
54
+ export const SPELLS = mod.SPELLS;
55
+ export const SUPER_TROOPS = mod.SUPER_TROOPS;
56
+ export const Season = mod.Season;
57
+ export const SeasonRankedPlayer = mod.SeasonRankedPlayer;
58
+ export const Spell = mod.Spell;
59
+ export const Troop = mod.Troop;
60
+ export const UNRANKED_LEAGUE_DATA = mod.UNRANKED_LEAGUE_DATA;
61
+ export const Unit = mod.Unit;
62
+ export const Util = mod.Util;
63
+ export const WAR_LEAGUES = mod.WAR_LEAGUES;
64
+ export const WarClan = mod.WarClan;
65
+ export const WarLeague = mod.WarLeague;
66
+ export const WarLogClan = mod.WarLogClan;
@@ -32,6 +32,8 @@ export declare class Clan {
32
32
  versusPoints: number;
33
33
  /** The minimum trophies required to apply to this clan. */
34
34
  requiredTrophies: number;
35
+ /** The minimum versus trophies required to apply to this clan. */
36
+ requiredVersusTrophies: number | null;
35
37
  /** The minimum hall level required to apply to this clan. */
36
38
  requiredTownHallLevel: number | null;
37
39
  /** The frequency for when this clan goes to war. */
@@ -23,6 +23,7 @@ class Clan {
23
23
  this.versusPoints = data.clanVersusPoints;
24
24
  this.requiredTrophies = data.requiredTrophies;
25
25
  this.requiredTownHallLevel = data.requiredTownhallLevel ?? null;
26
+ this.requiredVersusTrophies = data.requiredVersusTrophies ?? null;
26
27
  this.warFrequency = data.warFrequency;
27
28
  this.warWinStreak = data.warWinStreak;
28
29
  this.warWins = data.warWins;
@@ -26,6 +26,10 @@ export declare class ClanMember {
26
26
  /** The member's donation received count for this season. */
27
27
  received: number;
28
28
  constructor(client: Client, data: APIClanMember);
29
+ get isMember(): boolean;
30
+ get isElder(): boolean;
31
+ get isCoLeader(): boolean;
32
+ get isLeader(): boolean;
29
33
  /** Fetch detailed clan info for the member's clan. */
30
34
  fetch(options?: OverrideOptions): Promise<import("./Player").Player>;
31
35
  }
@@ -20,6 +20,18 @@ class ClanMember {
20
20
  this.donations = data.donations;
21
21
  this.received = data.donationsReceived;
22
22
  }
23
+ get isMember() {
24
+ return this.role === 'member';
25
+ }
26
+ get isElder() {
27
+ return this.role === 'elder';
28
+ }
29
+ get isCoLeader() {
30
+ return this.role === 'coLeader';
31
+ }
32
+ get isLeader() {
33
+ return this.role === 'leader';
34
+ }
23
35
  /** Fetch detailed clan info for the member's clan. */
24
36
  async fetch(options) {
25
37
  return this.client.getPlayer(this.tag, options);
@@ -135,12 +135,17 @@ export declare class ClanWar {
135
135
  getAttack(attackerTag: string, defenderTag: string): ClanWarAttack | null;
136
136
  /** Return a list of {@link ClanWarAttack} for the defenderTag provided. */
137
137
  getDefenses(defenderTag: string): ClanWarAttack[];
138
+ get isBattleDay(): boolean;
139
+ get isPreparationDay(): boolean;
140
+ get isWarEnded(): boolean;
138
141
  /** Returns either `friendly`, `cwl` or `normal`. */
139
142
  get type(): "friendly" | "cwl" | "normal";
140
143
  /** Whether this is a friendly war. */
141
144
  get isFriendly(): boolean;
142
145
  /** Whether this is a CWL. */
143
146
  get isCWL(): boolean;
147
+ /** Whether this is a normal war. */
148
+ get isNormal(): boolean;
144
149
  /** Returns the war status, based off the home clan. */
145
150
  get status(): "win" | "lose" | "tie" | "pending";
146
151
  /** Returns the Clan War League Group. */
@@ -178,6 +178,15 @@ class ClanWar {
178
178
  }
179
179
  return this.opponent.attacks.filter((atk) => atk.defenderTag === defenderTag);
180
180
  }
181
+ get isBattleDay() {
182
+ return this.state === 'inWar';
183
+ }
184
+ get isPreparationDay() {
185
+ return this.state === 'preparation';
186
+ }
187
+ get isWarEnded() {
188
+ return this.state === 'warEnded';
189
+ }
181
190
  /** Returns either `friendly`, `cwl` or `normal`. */
182
191
  get type() {
183
192
  if (this.isFriendly)
@@ -195,6 +204,10 @@ class ClanWar {
195
204
  get isCWL() {
196
205
  return typeof this.warTag === 'string';
197
206
  }
207
+ /** Whether this is a normal war. */
208
+ get isNormal() {
209
+ return !this.isCWL && !this.isFriendly;
210
+ }
198
211
  /** Returns the war status, based off the home clan. */
199
212
  get status() {
200
213
  if (this.state === 'preparation')
@@ -54,6 +54,7 @@ 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
+ get totalRounds(): number;
57
58
  /**
58
59
  * This returns an array of {@link ClanWar} which fetches all wars in parallel.
59
60
  * @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
@@ -55,6 +55,9 @@ class ClanWarLeagueGroup {
55
55
  this.clans = data.clans.map((clan) => new ClanWarLeagueClan(client, clan));
56
56
  this.rounds = data.rounds.map((round, i) => new ClanWarLeagueRound(round, i));
57
57
  }
58
+ get totalRounds() {
59
+ return this.clans.length - 1;
60
+ }
58
61
  /**
59
62
  * This returns an array of {@link ClanWar} which fetches all wars in parallel.
60
63
  * @param clanTag Optional clan tag. If present, this will only return wars which belong to this clan.
@@ -51,4 +51,7 @@ export declare class ClanWarLog {
51
51
  constructor(client: Client, data: APIClanWarLogEntry);
52
52
  /** Returns either `friendly`, `cwl` or `normal`. */
53
53
  get type(): "friendly" | "cwl" | "normal";
54
+ get isFriendly(): boolean;
55
+ get isCWL(): boolean;
56
+ get isNormal(): boolean;
54
57
  }
@@ -44,5 +44,14 @@ class ClanWarLog {
44
44
  return 'cwl';
45
45
  return 'normal';
46
46
  }
47
+ get isFriendly() {
48
+ return this.type === 'friendly';
49
+ }
50
+ get isCWL() {
51
+ return this.type === 'cwl';
52
+ }
53
+ get isNormal() {
54
+ return this.type === 'normal';
55
+ }
47
56
  }
48
57
  exports.ClanWarLog = ClanWarLog;
@@ -62,6 +62,11 @@ export declare class Player {
62
62
  /** An array of player's heroes (both home base and build base). */
63
63
  heroes: Hero[];
64
64
  constructor(client: Client, data: APIPlayer);
65
+ get inClan(): boolean;
66
+ get isMember(): boolean | null;
67
+ get isLeader(): boolean | null;
68
+ get isCoLeader(): boolean | null;
69
+ get isElder(): boolean | null;
65
70
  /** Fetch detailed clan info for the player's clan. */
66
71
  fetchClan(options?: OverrideOptions): Promise<import("./Clan").Clan | null>;
67
72
  /** An array of the player's home base troops. */
@@ -40,6 +40,21 @@ class Player {
40
40
  this.spells = data.spells.map((unit) => new Unit_1.Spell(data, unit));
41
41
  this.heroes = data.heroes.map((unit) => new Unit_1.Hero(data, unit));
42
42
  }
43
+ get inClan() {
44
+ return this.clan !== null;
45
+ }
46
+ get isMember() {
47
+ return this.clan ? this.role === 'member' : null;
48
+ }
49
+ get isLeader() {
50
+ return this.clan ? this.role === 'leader' : null;
51
+ }
52
+ get isCoLeader() {
53
+ return this.clan ? this.role === 'coLeader' : null;
54
+ }
55
+ get isElder() {
56
+ return this.clan ? this.role === 'elder' : null;
57
+ }
43
58
  /** Fetch detailed clan info for the player's clan. */
44
59
  async fetchClan(options) {
45
60
  if (!this.clan)
@@ -46,6 +46,7 @@ export interface APIClan {
46
46
  clanVersusPoints: number;
47
47
  requiredTrophies: number;
48
48
  requiredTownhallLevel?: number;
49
+ requiredVersusTrophies?: number;
49
50
  warFrequency: 'always' | 'moreThanOncePerWeek' | 'oncePerWeek' | 'lessThanOncePerWeek' | 'never' | 'unknown';
50
51
  warWinStreak: number;
51
52
  warWins: number;
@@ -175,6 +176,7 @@ export interface APIPlayer {
175
176
  versusTrophies?: number;
176
177
  bestVersusTrophies?: number;
177
178
  versusBattleWins?: number;
179
+ versusBattleWinCount?: number;
178
180
  donations: number;
179
181
  donationsReceived: number;
180
182
  role?: string;
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "2.6.1-dev.a42d488",
3
+ "version": "2.7.0-dev.31f642e",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "SUVAJIT <suvajit.me@gmail.com>",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
- "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
9
13
  "scripts": {
10
- "build": "tsc",
14
+ "build": "tsc && gen-esm-wrapper dist/index.js dist/index.mjs",
11
15
  "prepare": "rimraf dist && npm run build",
12
16
  "test": "eslint --ext .ts --ignore-path .gitignore .",
13
17
  "lint": "eslint --fix --ext .ts --ignore-path .gitignore ."
@@ -104,6 +108,7 @@
104
108
  "eslint-config-marine": "^9.0.6",
105
109
  "eslint-config-prettier": "^8.3.0",
106
110
  "eslint-plugin-prettier": "^4.0.0",
111
+ "gen-esm-wrapper": "^1.1.3",
107
112
  "prettier": "^2.4.1",
108
113
  "rimraf": "^3.0.2",
109
114
  "typescript": "^4.5.2"