clashofclans.js 3.3.5-dev.227b0d5 → 3.3.5-dev.560656b
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.
|
@@ -43,6 +43,7 @@ export declare class RequestHandler extends EventEmitter {
|
|
|
43
43
|
private readonly restRequestTimeout;
|
|
44
44
|
private readonly throttler?;
|
|
45
45
|
private readonly cached;
|
|
46
|
+
private readonly onError?;
|
|
46
47
|
private readonly dispatcher;
|
|
47
48
|
constructor(options?: RequestHandlerOptions);
|
|
48
49
|
private get _keys();
|
|
@@ -52,6 +53,7 @@ export declare class RequestHandler extends EventEmitter {
|
|
|
52
53
|
request<T>(path: string, options?: RequestOptions): Promise<Result<T>>;
|
|
53
54
|
rawRequest<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
54
55
|
private exec;
|
|
56
|
+
private dispatch;
|
|
55
57
|
init(options: LoginOptions): Promise<string[]>;
|
|
56
58
|
private reValidateKeys;
|
|
57
59
|
private login;
|
|
@@ -25,6 +25,7 @@ class RequestHandler extends node_events_1.EventEmitter {
|
|
|
25
25
|
constructor(options) {
|
|
26
26
|
super();
|
|
27
27
|
_RequestHandler_keyIndex.set(this, 0); // eslint-disable-line
|
|
28
|
+
this.onError = options?.onError;
|
|
28
29
|
this.keys = options?.keys ?? [];
|
|
29
30
|
this.retryLimit = options?.retryLimit ?? 0;
|
|
30
31
|
this.throttler = options?.throttler ?? null;
|
|
@@ -76,9 +77,15 @@ class RequestHandler extends node_events_1.EventEmitter {
|
|
|
76
77
|
if (!this.throttler || options.ignoreRateLimit)
|
|
77
78
|
return this.exec(path, options).then((res) => res.body);
|
|
78
79
|
await this.throttler.wait();
|
|
79
|
-
|
|
80
|
+
const result = await this.exec(path, options);
|
|
81
|
+
return result.body;
|
|
80
82
|
}
|
|
81
83
|
async exec(path, options = {}, retries = 0) {
|
|
84
|
+
const result = await this.dispatch(path, options, retries);
|
|
85
|
+
this.onError?.({ path, status: result.res.status, body: result.body });
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
async dispatch(path, options = {}, retries = 0) {
|
|
82
89
|
try {
|
|
83
90
|
const res = await this.dispatcher.request({
|
|
84
91
|
path: `/v1${path}`,
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -55,6 +55,11 @@ export interface RequestHandlerOptions extends ClientOptions {
|
|
|
55
55
|
connections?: number;
|
|
56
56
|
/** The amount of concurrent requests to be sent over the single TCP/TLS connection according to RFC7230. Default: 1 */
|
|
57
57
|
pipelining?: number;
|
|
58
|
+
onError?: (args: {
|
|
59
|
+
path: string;
|
|
60
|
+
status: number;
|
|
61
|
+
body: unknown;
|
|
62
|
+
}) => unknown;
|
|
58
63
|
}
|
|
59
64
|
/** Search options for request. */
|
|
60
65
|
export interface SearchOptions extends OverrideOptions {
|
package/dist/util/Util.d.ts
CHANGED
|
@@ -33,12 +33,12 @@ export declare class Util extends null {
|
|
|
33
33
|
static formatDate(date: string): Date;
|
|
34
34
|
/** Returns a string containing a query string suitable for use in a URL. */
|
|
35
35
|
static queryString(options?: SearchOptions | ClanSearchOptions): string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/** Get current
|
|
36
|
+
static getSeasonStart(inputDate: Date): Date;
|
|
37
|
+
static getSeasonEnd(inputDate: Date, forward?: boolean): Date;
|
|
38
|
+
/** Get the current season ID. */
|
|
39
39
|
static getSeasonId(): string;
|
|
40
40
|
/**
|
|
41
|
-
* Get the
|
|
41
|
+
* Get the season start and end timestamp.
|
|
42
42
|
* @param {Date} timestamp - The reference date. Defaults to the current date if not provided.
|
|
43
43
|
* @param {boolean} forward - Whether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.
|
|
44
44
|
*/
|
package/dist/util/Util.js
CHANGED
|
@@ -63,7 +63,7 @@ class Util extends null {
|
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
65
|
static encodeTag(tag) {
|
|
66
|
-
const formatted = this.formatTag(tag).
|
|
66
|
+
const formatted = this.formatTag(tag).slice(1);
|
|
67
67
|
if (!this.isValidTag(formatted)) {
|
|
68
68
|
throw new TypeError(`Failed to encode tag ${formatted}. RegExp matching failed.`);
|
|
69
69
|
}
|
|
@@ -120,12 +120,12 @@ class Util extends null {
|
|
|
120
120
|
}
|
|
121
121
|
return lastMonday;
|
|
122
122
|
}
|
|
123
|
-
/** Get current
|
|
123
|
+
/** Get the current season ID. */
|
|
124
124
|
static getSeasonId() {
|
|
125
|
-
return this.getSeasonEnd(new Date()).toISOString().
|
|
125
|
+
return this.getSeasonEnd(new Date()).toISOString().slice(0, 7);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* Get the
|
|
128
|
+
* Get the season start and end timestamp.
|
|
129
129
|
* @param {Date} timestamp - The reference date. Defaults to the current date if not provided.
|
|
130
130
|
* @param {boolean} forward - Whether to forward to the next month if the returned date is in the past relative to the given timestamp. Defaults to true.
|
|
131
131
|
*/
|
package/dist/util.spec.js
CHANGED
|
@@ -5,7 +5,7 @@ describe('util', () => {
|
|
|
5
5
|
it('should always be UTC', () => {
|
|
6
6
|
expect(new Date().getTimezoneOffset()).toBe(0);
|
|
7
7
|
});
|
|
8
|
-
it('should forward to next month if date is in past', async () => {
|
|
8
|
+
it('should forward to next month if the given date is in the past', async () => {
|
|
9
9
|
const timestamp = new Date('2024-03-25T05:01');
|
|
10
10
|
const { endTime, startTime } = Util_1.Util.getSeason(timestamp);
|
|
11
11
|
const expectedEndTime = new Date('2024-04-29T05:00').toISOString();
|
|
@@ -13,6 +13,14 @@ describe('util', () => {
|
|
|
13
13
|
expect(endTime.toISOString()).toBe(expectedEndTime);
|
|
14
14
|
expect(startTime.toISOString()).toBe(expectedStartTime);
|
|
15
15
|
});
|
|
16
|
+
it('should not forward to next month even if the given date is in the past', async () => {
|
|
17
|
+
const timestamp = new Date('2024-03-25T05:01');
|
|
18
|
+
const { endTime, startTime } = Util_1.Util.getSeason(timestamp, false);
|
|
19
|
+
const expectedEndTime = new Date('2024-03-25T05:00').toISOString();
|
|
20
|
+
const expectedStartTime = new Date('2024-02-26T05:00').toISOString();
|
|
21
|
+
expect(endTime.toISOString()).toBe(expectedEndTime);
|
|
22
|
+
expect(startTime.toISOString()).toBe(expectedStartTime);
|
|
23
|
+
});
|
|
16
24
|
it('should return the correct season against a date', async () => {
|
|
17
25
|
const timestamp = new Date('2024-03-16T05:01');
|
|
18
26
|
const { endTime, startTime } = Util_1.Util.getSeason(timestamp);
|
package/package.json
CHANGED