@gearbox-protocol/cli-utils 5.71.7 → 5.72.1
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.
|
@@ -13,7 +13,7 @@ export declare class NotificationsService implements INotificationService {
|
|
|
13
13
|
#private;
|
|
14
14
|
constructor(options: NotificationsServiceOptions, logger?: ILogger);
|
|
15
15
|
registerRecipient(address: Address, options: NotificationConfig): void;
|
|
16
|
-
signl(message: string): void;
|
|
16
|
+
signl(message: string, dedupeKey?: string): void;
|
|
17
17
|
alert(msg: NotificationLike): void;
|
|
18
18
|
notify(msg: NotificationLike): void;
|
|
19
19
|
}
|
|
@@ -27,8 +27,8 @@ export class NotificationsService {
|
|
|
27
27
|
this.#notifiers.upsert(address, notifier);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
signl(message) {
|
|
31
|
-
this.#signlNotifier?.alert(message);
|
|
30
|
+
signl(message, dedupeKey) {
|
|
31
|
+
this.#signlNotifier?.alert(message, dedupeKey);
|
|
32
32
|
}
|
|
33
33
|
alert(msg) {
|
|
34
34
|
this.#notify(msg, "alert");
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ILogger } from "@gearbox-protocol/sdk";
|
|
2
2
|
import type { SignlConfig } from "./schema.js";
|
|
3
|
+
import type { ThrottleFn } from "./types.js";
|
|
3
4
|
export type SignlServiceOptions = SignlConfig & {
|
|
4
5
|
retryInterval?: number;
|
|
5
6
|
retryCount?: number;
|
|
7
|
+
throttleFn?: ThrottleFn;
|
|
6
8
|
};
|
|
7
9
|
export default class SignlNotifier {
|
|
8
10
|
#private;
|
|
9
11
|
constructor(opts: SignlServiceOptions, logger?: ILogger);
|
|
10
|
-
alert(message: string): void;
|
|
12
|
+
alert(message: string, dedupeKey?: string): void;
|
|
11
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { withRetry } from "viem";
|
|
2
|
+
import { ThrottleManager } from "./ThrottleManager.js";
|
|
2
3
|
const DEFAULT_RETRY_INTERVAL = 1000;
|
|
3
4
|
const DEFAULT_RETRY_COUNT = 5;
|
|
4
5
|
export default class SignlNotifier {
|
|
@@ -7,18 +8,24 @@ export default class SignlNotifier {
|
|
|
7
8
|
#teamId;
|
|
8
9
|
#retryInterval;
|
|
9
10
|
#retryCount;
|
|
11
|
+
#throttleManager = new ThrottleManager();
|
|
12
|
+
#throttleFn;
|
|
10
13
|
constructor(opts, logger) {
|
|
11
14
|
this.#apiKey = opts.apiKey;
|
|
12
15
|
this.#teamId = opts.teamId;
|
|
13
16
|
this.#retryInterval = opts.retryInterval ?? DEFAULT_RETRY_INTERVAL;
|
|
14
17
|
this.#retryCount = opts.retryCount ?? DEFAULT_RETRY_COUNT;
|
|
15
18
|
this.#logger = logger;
|
|
19
|
+
this.#throttleFn = opts.throttleFn;
|
|
16
20
|
this.#logger?.info(opts, "signl notifier configured");
|
|
17
21
|
}
|
|
18
|
-
alert(message) {
|
|
19
|
-
void this.#sendAlert(message).catch(e => this.#logger?.error(e));
|
|
22
|
+
alert(message, dedupeKey) {
|
|
23
|
+
void this.#sendAlert(message, dedupeKey).catch(e => this.#logger?.error(e));
|
|
20
24
|
}
|
|
21
|
-
async #sendAlert(message) {
|
|
25
|
+
async #sendAlert(message, dedupeKey) {
|
|
26
|
+
if (dedupeKey && !this.#throttleManager.canSend(dedupeKey)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
22
29
|
const text = message.slice(0, 64); // it's to be shown in mobile notifications anyways
|
|
23
30
|
this.#logger?.debug("sending signl alert");
|
|
24
31
|
await withRetry(async () => {
|
|
@@ -44,5 +51,8 @@ export default class SignlNotifier {
|
|
|
44
51
|
throw new Error(`signl api error ${resp.status}: ${resp.statusText}`);
|
|
45
52
|
}
|
|
46
53
|
}, { delay: this.#retryInterval, retryCount: this.#retryCount });
|
|
54
|
+
if (dedupeKey) {
|
|
55
|
+
this.#throttleManager.onSent(dedupeKey, this.#throttleFn);
|
|
56
|
+
}
|
|
47
57
|
}
|
|
48
58
|
}
|
|
@@ -56,9 +56,12 @@ export interface INotificationService {
|
|
|
56
56
|
/**
|
|
57
57
|
* Send an alert to Signl
|
|
58
58
|
* @param message
|
|
59
|
+
* @param dedupeKey
|
|
60
|
+
* Messages with the same dedupe key will be throttled to avoid spam
|
|
61
|
+
* If not provided, the message will not be throttled
|
|
59
62
|
* @returns
|
|
60
63
|
*/
|
|
61
|
-
signl: (message: string) => void;
|
|
64
|
+
signl: (message: string, dedupeKey?: string) => void;
|
|
62
65
|
/**
|
|
63
66
|
* Sends high priority notification
|
|
64
67
|
* @param message
|