@gearbox-protocol/cli-utils 5.71.6 → 5.72.0

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.
@@ -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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/cli-utils",
3
3
  "description": "Utils for creating cli apps",
4
- "version": "5.71.6",
4
+ "version": "5.72.0",
5
5
  "homepage": "https://gearbox.fi",
6
6
  "keywords": [
7
7
  "gearbox"