clashofclans.js 2.4.0 → 2.5.0-dev.597dedf
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 +12 -5
- package/dist/client/Client.d.ts +2 -2
- package/dist/rest/RESTManager.d.ts +40 -26
- package/dist/rest/RESTManager.js +34 -14
- package/dist/rest/RequestHandler.d.ts +2 -142
- package/dist/rest/RequestHandler.js +2 -2
- package/dist/struct/Clan.d.ts +1 -2
- package/dist/struct/ClanMember.d.ts +1 -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/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 +4 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { QueueThrottler, BatchThrottler } from '../rest/Throttler';
|
|
2
|
+
import Keyv from 'keyv';
|
|
3
|
+
/** Options for a Client. */
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
/** Keys from Clash of Clans API developer site. */
|
|
6
|
+
keys?: string[];
|
|
7
|
+
/** Base URL of the Clash of Clans API. */
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
/**
|
|
10
|
+
* How many times to retry on 5XX errors.
|
|
11
|
+
*/
|
|
12
|
+
retryLimit?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether enable or disable internal caching.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const client = new Client({ cache: true });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
cache?: boolean | Keyv;
|
|
21
|
+
/** Time to wait before cancelling a REST request, in milliseconds. */
|
|
22
|
+
restRequestTimeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Throttler class which handles rate-limit
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const client = new Client({ throttler: new QueueThrottler(1000 / 10) });
|
|
28
|
+
* ```
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const client = new Client({ throttler: new BatchThrottler(30) });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
throttler?: QueueThrottler | BatchThrottler;
|
|
35
|
+
}
|
|
36
|
+
/** Options for a RESTManager. */
|
|
37
|
+
export interface RESTOptions extends ClientOptions {
|
|
38
|
+
/** Set this `false` to use `res.ok` property. */
|
|
39
|
+
rejectIfNotValid?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Search options for request. */
|
|
42
|
+
export interface SearchOptions extends OverrideOptions {
|
|
43
|
+
/** Limit the number of items returned in the response. */
|
|
44
|
+
limit?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Return only items that occur after this marker.
|
|
47
|
+
* Before marker can be found from the response, inside the 'paging' property.
|
|
48
|
+
* Note that only after or before can be specified for a request, not both.
|
|
49
|
+
*/
|
|
50
|
+
after?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Return only items that occur before this marker.
|
|
53
|
+
* Before marker can be found from the response, inside the 'paging' property.
|
|
54
|
+
* Note that only after or before can be specified for a request, not both.
|
|
55
|
+
*/
|
|
56
|
+
before?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Override options for a request. */
|
|
59
|
+
export interface OverrideOptions {
|
|
60
|
+
/** Whether to cache this response. */
|
|
61
|
+
cache?: boolean;
|
|
62
|
+
/** Whether to skip the cache check and request the API. */
|
|
63
|
+
force?: boolean;
|
|
64
|
+
/** How many times to retry on 5XX errors. */
|
|
65
|
+
retryLimit?: string;
|
|
66
|
+
/** Whether to ignore throttlers. */
|
|
67
|
+
ignoreRateLimit?: boolean;
|
|
68
|
+
/** Time to wait before cancelling a REST request, in milliseconds. */
|
|
69
|
+
restRequestTimeout?: number;
|
|
70
|
+
}
|
|
71
|
+
export interface RequestOptions extends OverrideOptions {
|
|
72
|
+
/** The request body. */
|
|
73
|
+
body?: string;
|
|
74
|
+
/** The request method. */
|
|
75
|
+
method?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface Response<T> {
|
|
78
|
+
/** Whether the response is ok. */
|
|
79
|
+
ok: boolean;
|
|
80
|
+
/** The response body. */
|
|
81
|
+
data: T;
|
|
82
|
+
/** Path of the request for this response. */
|
|
83
|
+
path: string;
|
|
84
|
+
/** HTTP status code of this response. */
|
|
85
|
+
status: number;
|
|
86
|
+
/** The maxAge of this response. */
|
|
87
|
+
maxAge: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Clan search options for a request.
|
|
91
|
+
*
|
|
92
|
+
* If name is used as part of search query, it needs to be at least three characters long.
|
|
93
|
+
* Name search parameter is interpreted as wild card search, so it may appear anywhere in the clan name.
|
|
94
|
+
*/
|
|
95
|
+
export interface ClanSearchOptions {
|
|
96
|
+
/** Search clans by name. */
|
|
97
|
+
name?: string;
|
|
98
|
+
/** Filter by minimum number of clan members. */
|
|
99
|
+
minMembers?: number;
|
|
100
|
+
/** Filter by maximum number of clan members. */
|
|
101
|
+
maxMembers?: number;
|
|
102
|
+
/** Filter by minimum amount of clan points. */
|
|
103
|
+
minClanPoints?: number;
|
|
104
|
+
/** Filter by minimum clan level. */
|
|
105
|
+
minClanLevel?: number;
|
|
106
|
+
/** Filter by clan war frequency. */
|
|
107
|
+
warFrequency?: string;
|
|
108
|
+
/** Filter by clan location identifier. For list of available locations, refer to getLocations operation. */
|
|
109
|
+
locationId?: string;
|
|
110
|
+
/** Comma separated list of label IDs to use for filtering results. */
|
|
111
|
+
labelIds?: string;
|
|
112
|
+
/** Limit the number of items returned in the response. */
|
|
113
|
+
limit?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Return only items that occur after this marker.
|
|
116
|
+
* Before marker can be found from the response, inside the 'paging' property.
|
|
117
|
+
* Note that only after or before can be specified for a request, not both.
|
|
118
|
+
*/
|
|
119
|
+
after?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Return only items that occur before this marker.
|
|
122
|
+
* Before marker can be found from the response, inside the 'paging' property.
|
|
123
|
+
* Note that only after or before can be specified for a request, not both.
|
|
124
|
+
*/
|
|
125
|
+
before?: string;
|
|
126
|
+
}
|
|
127
|
+
/** Login options for a client. */
|
|
128
|
+
export interface LoginOptions {
|
|
129
|
+
/** Developer site email address. */
|
|
130
|
+
email: string;
|
|
131
|
+
/** Developer site password. */
|
|
132
|
+
password: string;
|
|
133
|
+
/** Name of API key(s). */
|
|
134
|
+
keyName?: string;
|
|
135
|
+
/** Number of allowed API keys. */
|
|
136
|
+
keyCount?: number;
|
|
137
|
+
/** Description of API key(s). */
|
|
138
|
+
keyDescription?: string;
|
|
139
|
+
}
|
package/dist/util/Util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ClanSearchOptions, SearchOptions } from '../types';
|
|
1
2
|
/** Contains various general-purpose utility methods. */
|
|
2
3
|
export declare class Util extends null {
|
|
3
4
|
/**
|
|
@@ -30,7 +31,7 @@ export declare class Util extends null {
|
|
|
30
31
|
/** Converts API Date to JavaScript Date. */
|
|
31
32
|
static formatDate(date: string): Date;
|
|
32
33
|
/** Returns a string containing a query string suitable for use in a URL. */
|
|
33
|
-
static queryString(options?:
|
|
34
|
+
static queryString(options?: SearchOptions | ClanSearchOptions): string;
|
|
34
35
|
private static getSeasonEnd;
|
|
35
36
|
/** Get current trophy season Id. */
|
|
36
37
|
static getSeasonId(): string;
|
package/dist/util/Util.js
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Util = void 0;
|
|
4
4
|
const TAG_CHARACTERS = '0289PYLQGRJCUV';
|
|
5
|
+
const params = [
|
|
6
|
+
'name',
|
|
7
|
+
'minMembers',
|
|
8
|
+
'maxMembers',
|
|
9
|
+
'minClanPoints',
|
|
10
|
+
'minClanLevel',
|
|
11
|
+
'warFrequency',
|
|
12
|
+
'locationId',
|
|
13
|
+
'labelIds',
|
|
14
|
+
'limit',
|
|
15
|
+
'after',
|
|
16
|
+
'before'
|
|
17
|
+
];
|
|
5
18
|
/** Contains various general-purpose utility methods. */
|
|
6
19
|
class Util extends null {
|
|
7
20
|
/**
|
|
@@ -62,10 +75,8 @@ class Util extends null {
|
|
|
62
75
|
}
|
|
63
76
|
/** Returns a string containing a query string suitable for use in a URL. */
|
|
64
77
|
static queryString(options = {}) {
|
|
65
|
-
const query = new URLSearchParams(options);
|
|
66
|
-
|
|
67
|
-
query.delete(key);
|
|
68
|
-
return query.toString();
|
|
78
|
+
const query = new URLSearchParams(Object.entries(options).filter(([key]) => params.includes(key))).toString();
|
|
79
|
+
return query.length ? `?${query}` : query;
|
|
69
80
|
}
|
|
70
81
|
static getSeasonEnd(month, year, autoFix = true) {
|
|
71
82
|
const now = new Date();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clashofclans.js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-dev.597dedf",
|
|
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",
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"keywords": [
|
|
23
23
|
"clash-of-clans-api",
|
|
24
24
|
"clash-of-clans",
|
|
25
|
-
"clash-api"
|
|
25
|
+
"clash-api",
|
|
26
|
+
"supercell",
|
|
27
|
+
"coc"
|
|
26
28
|
],
|
|
27
29
|
"bugs": {
|
|
28
30
|
"url": "https://github.com/clashperk/clashofclans.js/issues"
|