iris-relay 1.0.0 → 1.1.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.
package/dist/watch.js ADDED
@@ -0,0 +1,70 @@
1
+ import { relay } from "./relay.js";
2
+ import { relayError } from "./format.js";
3
+ /**
4
+ * Watch for uncaught exceptions and unhandled rejections.
5
+ * Sends crash reports to Telegram before the process exits.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { watchProcess } from "iris-relay";
10
+ * watchProcess(); // done — crashes get reported
11
+ * ```
12
+ */
13
+ export function watchProcess(config) {
14
+ process.on("uncaughtException", async (err) => {
15
+ console.error("[iris-relay] Uncaught Exception:", err);
16
+ try {
17
+ await relayError(err, config);
18
+ }
19
+ catch { /* don't throw during crash handler */ }
20
+ process.exit(1);
21
+ });
22
+ process.on("unhandledRejection", async (reason) => {
23
+ console.error("[iris-relay] Unhandled Rejection:", reason);
24
+ try {
25
+ const err = reason instanceof Error ? reason : new Error(String(reason));
26
+ await relayError(err, config);
27
+ }
28
+ catch { /* don't throw during crash handler */ }
29
+ });
30
+ // Notify on graceful shutdown
31
+ const signals = ["SIGINT", "SIGTERM"];
32
+ for (const signal of signals) {
33
+ process.on(signal, async () => {
34
+ try {
35
+ await relay(`⚠️ Process received ${signal} — shutting down`, config);
36
+ }
37
+ catch { /* best effort */ }
38
+ process.exit(0);
39
+ });
40
+ }
41
+ }
42
+ /**
43
+ * Start sending periodic heartbeat messages.
44
+ * Returns a cleanup function to stop the heartbeat.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { startHeartbeat } from "iris-relay";
49
+ *
50
+ * const stop = startHeartbeat({ interval: 60000, app: "my-api" });
51
+ * // Later: stop();
52
+ * ```
53
+ */
54
+ export function startHeartbeat(options, config) {
55
+ const interval = options?.interval ?? 60_000;
56
+ const app = options?.app ?? "Service";
57
+ const msg = options?.message ?? `💓 Heartbeat — <b>${app}</b> is alive`;
58
+ const id = setInterval(async () => {
59
+ try {
60
+ await relay(msg, { parseMode: "HTML", silent: true, ...config });
61
+ }
62
+ catch (err) {
63
+ console.error("[iris-relay] Heartbeat failed:", err);
64
+ }
65
+ }, interval);
66
+ // Don't prevent process from exiting
67
+ id.unref();
68
+ return () => clearInterval(id);
69
+ }
70
+ //# sourceMappingURL=watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.js","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB;IAC7C,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC;YACD,MAAM,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC,CAAC,sCAAsC,CAAC,CAAC;QAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAC9C,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YACzE,MAAM,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC,CAAC,sCAAsC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,8BAA8B;IAC9B,MAAM,O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ight, zero-dependency Telegram message relay",
3
+ "version": "1.1.0",
4
+ "description": "Lightweight Telegram message relay — dev tool for notifications, crash alerts, deploy pings, and more",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "iris-relay": "./dist/cli.js"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -19,7 +22,12 @@
19
22
  "relay",
20
23
  "bot",
21
24
  "message",
22
- "notification"
25
+ "notification",
26
+ "devtool",
27
+ "crash-reporter",
28
+ "deploy",
29
+ "heartbeat",
30
+ "monitoring"
23
31
  ],
24
32
  "author": "",
25
33
  "license": "MIT",
@@ -27,14 +35,14 @@
27
35
  "node": ">=18"
28
36
  },
29
37
  "sideEffects": false,
38
+ "dependencies": {
39
+ "dotenv": "^17.3.1"
40
+ },
30
41
  "devDependencies": {
31
42
  "@types/node": "^25.3.5",
32
43
  "tsx": "^4.21.0",
33
44
  "typescript": "^5.9.3"
34
45
  },
35
- "dependencies": {
36
- "dotenv": "^17.3.1"
37
- },
38
46
  "scripts": {
39
47
  "build": "tsc",
40
48
  "test": "tsx test.ts"