clashofclans.js 2.5.1-dev.63736bf → 2.5.2-dev.12b59ce
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 +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/rest/HTTPError.js +1 -1
- package/dist/rest/RequestHandler.js +3 -3
- package/dist/struct/ClanWar.js +1 -1
- package/dist/types/lib.d.ts +7 -2
- package/dist/util/Store.d.ts +28 -0
- package/dist/util/Store.js +43 -0
- package/package.json +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.5.2 (2022-01-23)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- Fix `ClanWar#attacksPerMembers` property ([#97](https://github.com/clashperk/clashofclans.js/pull/97))
|
|
10
|
+
- Bump `node-fetch` from 2.6.6 to 2.6.7 ([#96](https://github.com/clashperk/clashofclans.js/pull/96))
|
|
11
|
+
|
|
5
12
|
## 2.5.1 (2022-01-11)
|
|
6
13
|
|
|
7
14
|
### Bug Fixes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/rest/HTTPError.js
CHANGED
|
@@ -11,7 +11,7 @@ const messages = {
|
|
|
11
11
|
403: 'Access denied, either because of missing/incorrect credentials or used API token does not grant access to the requested resource.'
|
|
12
12
|
};
|
|
13
13
|
const reasons = {
|
|
14
|
-
503: '
|
|
14
|
+
503: 'inMaintenance',
|
|
15
15
|
429: 'requestThrottled',
|
|
16
16
|
400: 'badRequest',
|
|
17
17
|
403: 'accessDenied',
|
|
@@ -18,9 +18,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.RequestHandler = void 0;
|
|
19
19
|
const Constants_1 = require("../util/Constants");
|
|
20
20
|
const HTTPError_1 = require("./HTTPError");
|
|
21
|
+
const Store_1 = require("../util/Store");
|
|
21
22
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
22
23
|
const https_1 = __importDefault(require("https"));
|
|
23
|
-
const keyv_1 = __importDefault(require("keyv"));
|
|
24
24
|
const IP_REGEX = /\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/g;
|
|
25
25
|
const agent = new https_1.default.Agent({ keepAlive: true });
|
|
26
26
|
/** Represents a Request Handler. */
|
|
@@ -33,10 +33,10 @@ class RequestHandler {
|
|
|
33
33
|
this.baseURL = options?.baseURL ?? Constants_1.API_BASE_URL;
|
|
34
34
|
this.restRequestTimeout = options?.restRequestTimeout ?? 0;
|
|
35
35
|
this.rejectIfNotValid = options?.rejectIfNotValid ?? true;
|
|
36
|
-
if (options?.cache
|
|
36
|
+
if (typeof options?.cache === 'object')
|
|
37
37
|
this.cached = options.cache;
|
|
38
38
|
else
|
|
39
|
-
this.cached = options?.cache ? new
|
|
39
|
+
this.cached = options?.cache === true ? new Store_1.CacheStore() : null;
|
|
40
40
|
}
|
|
41
41
|
get _keys() {
|
|
42
42
|
return Array.isArray(this.keys) ? this.keys : [this.keys];
|
package/dist/struct/ClanWar.js
CHANGED
|
@@ -136,7 +136,7 @@ class ClanWar {
|
|
|
136
136
|
// @ts-expect-error
|
|
137
137
|
this.state = data.state;
|
|
138
138
|
this.teamSize = data.teamSize;
|
|
139
|
-
this.attacksPerMember = data.attacksPerMember ?? extra.warTag ? 1 : 2;
|
|
139
|
+
this.attacksPerMember = data.attacksPerMember ?? (extra.warTag ? 1 : 2);
|
|
140
140
|
this.preparationStartTime = client.util.formatDate(data.preparationStartTime);
|
|
141
141
|
this.startTime = client.util.formatDate(data.startTime);
|
|
142
142
|
this.endTime = client.util.formatDate(data.endTime);
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { QueueThrottler, BatchThrottler } from '../rest/Throttler';
|
|
2
|
-
|
|
2
|
+
export interface Store<T = any> {
|
|
3
|
+
set(key: string, value: T, ttl?: number): boolean | Promise<boolean>;
|
|
4
|
+
get(key: string): T | null | Promise<T | null>;
|
|
5
|
+
delete(key: string): boolean | Promise<boolean>;
|
|
6
|
+
clear(): void | Promise<void>;
|
|
7
|
+
}
|
|
3
8
|
/** Options for a Client. */
|
|
4
9
|
export interface ClientOptions {
|
|
5
10
|
/** Keys from Clash of Clans API developer site. */
|
|
@@ -17,7 +22,7 @@ export interface ClientOptions {
|
|
|
17
22
|
* const client = new Client({ cache: true });
|
|
18
23
|
* ```
|
|
19
24
|
*/
|
|
20
|
-
cache?: boolean |
|
|
25
|
+
cache?: boolean | Store;
|
|
21
26
|
/** Time to wait before cancelling a REST request, in milliseconds. */
|
|
22
27
|
restRequestTimeout?: number;
|
|
23
28
|
/**
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Store } from '../types';
|
|
2
|
+
export interface CacheOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How frequently to remove data from cache that are older than the lifetime/ttl (in milliseconds, 0 for never)
|
|
5
|
+
*
|
|
6
|
+
* To prevent high CPU usage, set a higher value (30-60 seconds recommended)
|
|
7
|
+
*
|
|
8
|
+
* @default 120000 (2 minutes)
|
|
9
|
+
*/
|
|
10
|
+
sweepInterval?: number;
|
|
11
|
+
/**
|
|
12
|
+
* How long a data should stay in the cache until it is considered sweepable (in milliseconds, 0 for forever)
|
|
13
|
+
*
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
ttl?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class CacheStore<T = any> implements Store<T> {
|
|
19
|
+
private readonly ttl;
|
|
20
|
+
private readonly sweepInterval?;
|
|
21
|
+
private readonly store;
|
|
22
|
+
constructor(options?: CacheOptions);
|
|
23
|
+
private _sweep;
|
|
24
|
+
set(key: string, value: T, ttl?: number): boolean;
|
|
25
|
+
get(key: string): T | null;
|
|
26
|
+
delete(key: string): boolean;
|
|
27
|
+
clear(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheStore = void 0;
|
|
4
|
+
class CacheStore {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.store = new Map();
|
|
7
|
+
this.ttl = options?.ttl ?? 0;
|
|
8
|
+
this.sweepInterval = options?.sweepInterval ?? 2 * 60 * 1000;
|
|
9
|
+
if (this.sweepInterval > 0)
|
|
10
|
+
this._sweep(); // sweep expired cache
|
|
11
|
+
}
|
|
12
|
+
_sweep() {
|
|
13
|
+
setInterval(() => {
|
|
14
|
+
for (const cache of this.store.values()) {
|
|
15
|
+
if (cache.expires > 0 && Date.now() > cache.expires) {
|
|
16
|
+
this.store.delete(cache.key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, Math.max(this.sweepInterval, 30 * 1000));
|
|
20
|
+
}
|
|
21
|
+
set(key, value, ttl = 0) {
|
|
22
|
+
const expires = ttl > 0 ? Date.now() + ttl : this.ttl > 0 ? Date.now() + this.ttl : 0;
|
|
23
|
+
this.store.set(key, { value, expires, key });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
get(key) {
|
|
27
|
+
const data = this.store.get(key);
|
|
28
|
+
if (!data)
|
|
29
|
+
return null;
|
|
30
|
+
if (data.expires > 0 && Date.now() > data.expires) {
|
|
31
|
+
this.store.delete(key);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return data.value;
|
|
35
|
+
}
|
|
36
|
+
delete(key) {
|
|
37
|
+
return this.store.delete(key);
|
|
38
|
+
}
|
|
39
|
+
clear() {
|
|
40
|
+
return this.store.clear();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.CacheStore = CacheStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clashofclans.js",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2-dev.12b59ce",
|
|
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",
|
|
@@ -93,11 +93,9 @@
|
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"
|
|
97
|
-
"node-fetch": "^2.6.1"
|
|
96
|
+
"node-fetch": "^2.6.7"
|
|
98
97
|
},
|
|
99
98
|
"devDependencies": {
|
|
100
|
-
"@types/keyv": "^3.1.3",
|
|
101
99
|
"@types/node": "^16.10.3",
|
|
102
100
|
"@types/node-fetch": "^2.5.12",
|
|
103
101
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|