pingflux 1.0.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.
Files changed (49) hide show
  1. package/dist/core/emitter.d.ts +44 -0
  2. package/dist/core/emitter.d.ts.map +1 -0
  3. package/dist/core/emitter.js +58 -0
  4. package/dist/core/emitter.js.map +1 -0
  5. package/dist/core/monitor.d.ts +47 -0
  6. package/dist/core/monitor.d.ts.map +1 -0
  7. package/dist/core/monitor.js +156 -0
  8. package/dist/core/monitor.js.map +1 -0
  9. package/dist/index.d.ts +63 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +79 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/interfaces/index.d.ts +92 -0
  14. package/dist/interfaces/index.d.ts.map +1 -0
  15. package/dist/interfaces/index.js +3 -0
  16. package/dist/interfaces/index.js.map +1 -0
  17. package/dist/probes/dns.d.ts +17 -0
  18. package/dist/probes/dns.d.ts.map +1 -0
  19. package/dist/probes/dns.js +86 -0
  20. package/dist/probes/dns.js.map +1 -0
  21. package/dist/probes/http.d.ts +17 -0
  22. package/dist/probes/http.d.ts.map +1 -0
  23. package/dist/probes/http.js +117 -0
  24. package/dist/probes/http.js.map +1 -0
  25. package/dist/probes/ping.d.ts +21 -0
  26. package/dist/probes/ping.d.ts.map +1 -0
  27. package/dist/probes/ping.js +37 -0
  28. package/dist/probes/ping.js.map +1 -0
  29. package/dist/probes/tcp.d.ts +14 -0
  30. package/dist/probes/tcp.d.ts.map +1 -0
  31. package/dist/probes/tcp.js +115 -0
  32. package/dist/probes/tcp.js.map +1 -0
  33. package/dist/probes/udp.d.ts +19 -0
  34. package/dist/probes/udp.d.ts.map +1 -0
  35. package/dist/probes/udp.js +135 -0
  36. package/dist/probes/udp.js.map +1 -0
  37. package/dist/utils/latency.d.ts +14 -0
  38. package/dist/utils/latency.d.ts.map +1 -0
  39. package/dist/utils/latency.js +19 -0
  40. package/dist/utils/latency.js.map +1 -0
  41. package/dist/utils/probes/ping.d.ts +24 -0
  42. package/dist/utils/probes/ping.d.ts.map +1 -0
  43. package/dist/utils/probes/ping.js +218 -0
  44. package/dist/utils/probes/ping.js.map +1 -0
  45. package/dist/utils/timer.d.ts +13 -0
  46. package/dist/utils/timer.d.ts.map +1 -0
  47. package/dist/utils/timer.js +19 -0
  48. package/dist/utils/timer.js.map +1 -0
  49. package/package.json +47 -0
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.dnsProbe = dnsProbe;
37
+ const dns = __importStar(require("dns"));
38
+ const timer_1 = require("../utils/timer");
39
+ /**
40
+ * Probe a host via DNS resolution.
41
+ * Attempts A record lookup first, then AAAA, then CNAME as a final fallback.
42
+ * Resolves `ok: true` if any record type is found.
43
+ *
44
+ * Note: only A, AAAA, and CNAME record types are checked.
45
+ * Hosts with exclusively MX, TXT, or other record types will resolve as `ok: false`.
46
+ *
47
+ * @param url - Hostname to resolve, optionally with a port suffix (e.g. `"example.com"` or `"example.com:53"`).
48
+ *
49
+ * @example
50
+ * const result = await dnsProbe("example.com");
51
+ * console.log(result.ok, result.latency);
52
+ */
53
+ function dnsProbe(url) {
54
+ return new Promise((resolve) => {
55
+ const host = url.split(":")[0];
56
+ const stop = (0, timer_1.startTimer)();
57
+ dns.resolve4(host, (err4, v4) => {
58
+ if (!err4 && v4.length > 0) {
59
+ resolve({ ok: true, latency: stop(), protocol: "dns", target: url, timestamp: Date.now() });
60
+ return;
61
+ }
62
+ dns.resolve6(host, (err6, v6) => {
63
+ if (!err6 && v6.length > 0) {
64
+ resolve({ ok: true, latency: stop(), protocol: "dns", target: url, timestamp: Date.now() });
65
+ return;
66
+ }
67
+ dns.resolveCname(host, (errCname, cnames) => {
68
+ const latency = stop();
69
+ if (!errCname && cnames.length > 0) {
70
+ resolve({ ok: true, latency, protocol: "dns", target: url, timestamp: Date.now() });
71
+ return;
72
+ }
73
+ resolve({
74
+ ok: false,
75
+ latency: null,
76
+ error: err4?.message ?? err6?.message ?? errCname?.message ?? "No records found",
77
+ protocol: "dns",
78
+ target: url,
79
+ timestamp: Date.now(),
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
85
+ }
86
+ //# sourceMappingURL=dns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dns.js","sourceRoot":"","sources":["../../src/probes/dns.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,4BAmCC;AArDD,yCAA2B;AAE3B,0CAA4C;AAE5C;;;;;;;;;;;;;GAaG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,OAAO,IAA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C,GAAG,EAAE,EAAE,CAAC,CAAC;wBACpF,OAAO;oBACT,CAAC;oBACD,OAAO,CAAC;wBACN,EAAE,EAAE,KAAK;wBACT,OAAO,EAAE,IAAI;wBACb,KAAK,EAAE,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI,QAAQ,EAAE,OAAO,IAAI,kBAAkB;wBAChF,QAAQ,EAAE,KAAK;wBACf,MAAM,EAAE,GAAG;wBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;qBACtB,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { ProbeResult, Protocol } from "../interfaces";
2
+ /**
3
+ * Probe a host via HTTP or HTTPS GET request.
4
+ * Resolves `ok: true` if the response status code is less than 400.
5
+ * Automatically strips any existing protocol prefix from `url` before parsing
6
+ * to avoid double-prefixing (e.g. passing `"https://example.com"` with protocol `"https"` is safe).
7
+ *
8
+ * @param url - Target URL or hostname, with or without protocol prefix
9
+ * (e.g. `"example.com"`, `"example.com/health"`, or `"https://example.com/health"`).
10
+ * @param protocol - Must be `"http"` or `"https"`. Determines the transport and default port.
11
+ *
12
+ * @example
13
+ * const result = await httpProbe("example.com/health", "https");
14
+ * console.log(result.ok, result.latency);
15
+ */
16
+ export declare function httpProbe(url: string, protocol: Protocol): Promise<ProbeResult>;
17
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/probes/http.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAkE/E"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.httpProbe = httpProbe;
37
+ const http = __importStar(require("http"));
38
+ const https = __importStar(require("https"));
39
+ const url_1 = require("url");
40
+ const timer_1 = require("../utils/timer");
41
+ /**
42
+ * Probe a host via HTTP or HTTPS GET request.
43
+ * Resolves `ok: true` if the response status code is less than 400.
44
+ * Automatically strips any existing protocol prefix from `url` before parsing
45
+ * to avoid double-prefixing (e.g. passing `"https://example.com"` with protocol `"https"` is safe).
46
+ *
47
+ * @param url - Target URL or hostname, with or without protocol prefix
48
+ * (e.g. `"example.com"`, `"example.com/health"`, or `"https://example.com/health"`).
49
+ * @param protocol - Must be `"http"` or `"https"`. Determines the transport and default port.
50
+ *
51
+ * @example
52
+ * const result = await httpProbe("example.com/health", "https");
53
+ * console.log(result.ok, result.latency);
54
+ */
55
+ function httpProbe(url, protocol) {
56
+ return new Promise((resolve) => {
57
+ const stop = (0, timer_1.startTimer)();
58
+ const lib = protocol === "https" ? https : http;
59
+ const stripped = url.replace(/^https?:\/\//i, "");
60
+ let parsedUrl;
61
+ try {
62
+ parsedUrl = new url_1.URL(`${protocol}://${stripped}`);
63
+ }
64
+ catch {
65
+ resolve({
66
+ ok: false,
67
+ latency: null,
68
+ error: "Invalid URL format",
69
+ protocol,
70
+ target: url,
71
+ timestamp: Date.now(),
72
+ });
73
+ return;
74
+ }
75
+ const options = {
76
+ hostname: parsedUrl.hostname,
77
+ port: parsedUrl.port || (protocol === "https" ? 443 : 80),
78
+ path: parsedUrl.pathname + parsedUrl.search,
79
+ method: "GET",
80
+ timeout: 10000,
81
+ };
82
+ const req = lib.request(options, (res) => {
83
+ const latency = stop();
84
+ res.resume();
85
+ resolve({
86
+ ok: res.statusCode !== undefined && res.statusCode < 400,
87
+ latency,
88
+ protocol,
89
+ target: url,
90
+ timestamp: Date.now(),
91
+ });
92
+ });
93
+ req.on("timeout", () => {
94
+ req.destroy();
95
+ resolve({
96
+ ok: false,
97
+ latency: null,
98
+ error: "Request timeout",
99
+ protocol,
100
+ target: url,
101
+ timestamp: Date.now(),
102
+ });
103
+ });
104
+ req.on("error", (err) => {
105
+ resolve({
106
+ ok: false,
107
+ latency: null,
108
+ error: err.message,
109
+ protocol,
110
+ target: url,
111
+ timestamp: Date.now(),
112
+ });
113
+ });
114
+ req.end();
115
+ });
116
+ }
117
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/probes/http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,8BAkE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,MAAM,EAAE,CAAC;YACb,OAAO,CAAC;gBACN,EAAE,EAAE,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,GAAG,CAAC,UAAU,GAAG,GAAG;gBACxD,OAAO;gBACP,QAAQ;gBACR,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YACrB,GAAG,CAAC,OAAO,EAAE,CAAC;YACd,OAAO,CAAC;gBACN,EAAE,EAAE,KAAK;gBACT,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,iBAAiB;gBACxB,QAAQ;gBACR,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACtB,OAAO,CAAC;gBACN,EAAE,EAAE,KAAK;gBACT,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,GAAG,CAAC,OAAO;gBAClB,QAAQ;gBACR,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { ProbeResult } from "../interfaces";
2
+ /**
3
+ * Probe a host via raw ICMP echo request (ping).
4
+ * Internally uses a Worker thread to avoid blocking the event loop.
5
+ *
6
+ * Requires elevated privileges:
7
+ * - Linux: root or `CAP_NET_RAW` capability (`sudo setcap cap_net_raw+ep node`)
8
+ * - macOS: root
9
+ * - Windows: Administrator
10
+ *
11
+ * Note: `url` must be a plain IPv4 address — hostname resolution is not performed.
12
+ *
13
+ * @param url - Target IPv4 address, optionally with port suffix (port is ignored).
14
+ * IPv6 addresses in bracket notation are also parsed (e.g. `"[::1]"`).
15
+ *
16
+ * @example
17
+ * const result = await pingProbe("1.1.1.1");
18
+ * console.log(result.ok, result.latency);
19
+ */
20
+ export declare function pingProbe(url: string): Promise<ProbeResult>;
21
+ //# sourceMappingURL=ping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/probes/ping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAcjE"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pingProbe = pingProbe;
4
+ const ping_1 = require("../utils/probes/ping");
5
+ /**
6
+ * Probe a host via raw ICMP echo request (ping).
7
+ * Internally uses a Worker thread to avoid blocking the event loop.
8
+ *
9
+ * Requires elevated privileges:
10
+ * - Linux: root or `CAP_NET_RAW` capability (`sudo setcap cap_net_raw+ep node`)
11
+ * - macOS: root
12
+ * - Windows: Administrator
13
+ *
14
+ * Note: `url` must be a plain IPv4 address — hostname resolution is not performed.
15
+ *
16
+ * @param url - Target IPv4 address, optionally with port suffix (port is ignored).
17
+ * IPv6 addresses in bracket notation are also parsed (e.g. `"[::1]"`).
18
+ *
19
+ * @example
20
+ * const result = await pingProbe("1.1.1.1");
21
+ * console.log(result.ok, result.latency);
22
+ */
23
+ async function pingProbe(url) {
24
+ const host = url.startsWith("[") ? url.slice(1, url.indexOf("]")) : url.split(":")[0];
25
+ const id = (Math.floor(Math.random() * 0xfffe) + 1) & 0xffff;
26
+ const seq = (Math.floor(Math.random() * 0xfffe) + 1) & 0xffff;
27
+ const result = await (0, ping_1.rawPing)(host, id, seq);
28
+ return {
29
+ ok: result.ok,
30
+ latency: result.latency,
31
+ error: result.error,
32
+ protocol: "ping",
33
+ target: url,
34
+ timestamp: Date.now(),
35
+ };
36
+ }
37
+ //# sourceMappingURL=ping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ping.js","sourceRoot":"","sources":["../../src/probes/ping.ts"],"names":[],"mappings":";;AAqBA,8BAcC;AAlCD,+CAA+C;AAE/C;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,SAAS,CAAC,GAAW;IACzC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IAC7D,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IAC9D,MAAM,MAAM,GAAG,MAAM,IAAA,cAAO,EAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;IAE5C,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,GAAG;QACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { ProbeResult } from "../interfaces";
2
+ /**
3
+ * Probe a host via TCP connection attempt.
4
+ * Resolves `ok: true` if the connection is established successfully.
5
+ * The socket is immediately destroyed after a successful connect — no data is sent.
6
+ *
7
+ * @param url - Target in `"host:port"` format (e.g. `"example.com:443"` or `"1.2.3.4:80"`).
8
+ *
9
+ * @example
10
+ * const result = await tcpProbe("example.com:443");
11
+ * console.log(result.ok, result.latency);
12
+ */
13
+ export declare function tcpProbe(url: string): Promise<ProbeResult>;
14
+ //# sourceMappingURL=tcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp.d.ts","sourceRoot":"","sources":["../../src/probes/tcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAsE1D"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.tcpProbe = tcpProbe;
37
+ const net = __importStar(require("net"));
38
+ const timer_1 = require("../utils/timer");
39
+ /**
40
+ * Probe a host via TCP connection attempt.
41
+ * Resolves `ok: true` if the connection is established successfully.
42
+ * The socket is immediately destroyed after a successful connect — no data is sent.
43
+ *
44
+ * @param url - Target in `"host:port"` format (e.g. `"example.com:443"` or `"1.2.3.4:80"`).
45
+ *
46
+ * @example
47
+ * const result = await tcpProbe("example.com:443");
48
+ * console.log(result.ok, result.latency);
49
+ */
50
+ function tcpProbe(url) {
51
+ return new Promise((resolve) => {
52
+ const [host, portStr] = url.split(":");
53
+ const port = parseInt(portStr, 10);
54
+ if (!host || isNaN(port)) {
55
+ resolve({
56
+ ok: false,
57
+ latency: null,
58
+ error: "Invalid host:port format",
59
+ protocol: "tcp",
60
+ target: url,
61
+ timestamp: Date.now(),
62
+ });
63
+ return;
64
+ }
65
+ const stop = (0, timer_1.startTimer)();
66
+ const socket = new net.Socket();
67
+ let resolved = false;
68
+ const cleanup = () => {
69
+ if (!socket.destroyed)
70
+ socket.destroy();
71
+ };
72
+ socket.setTimeout(10000);
73
+ socket.connect(port, host, () => {
74
+ const latency = stop();
75
+ resolved = true;
76
+ cleanup();
77
+ resolve({
78
+ ok: true,
79
+ latency,
80
+ protocol: "tcp",
81
+ target: url,
82
+ timestamp: Date.now(),
83
+ });
84
+ });
85
+ socket.on("timeout", () => {
86
+ if (!resolved) {
87
+ resolved = true;
88
+ cleanup();
89
+ resolve({
90
+ ok: false,
91
+ latency: null,
92
+ error: "TCP connection timeout",
93
+ protocol: "tcp",
94
+ target: url,
95
+ timestamp: Date.now(),
96
+ });
97
+ }
98
+ });
99
+ socket.on("error", (err) => {
100
+ if (!resolved) {
101
+ resolved = true;
102
+ cleanup();
103
+ resolve({
104
+ ok: false,
105
+ latency: null,
106
+ error: err.message,
107
+ protocol: "tcp",
108
+ target: url,
109
+ timestamp: Date.now(),
110
+ });
111
+ }
112
+ });
113
+ });
114
+ }
115
+ //# sourceMappingURL=tcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp.js","sourceRoot":"","sources":["../../src/probes/tcp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,4BAsEC;AArFD,yCAA2B;AAE3B,0CAA4C;AAE5C;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC;gBACN,EAAE,EAAE,KAAK;gBACT,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,0BAA0B;gBACjC,QAAQ,EAAE,KAAK;gBACf,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,MAAM,IAAI,GAAG,IAAA,kBAAU,GAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChC,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,SAAS;gBAAE,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1C,CAAC,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,C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
2
+ /**
3
+ * Probe a host via UDP by sending a small packet and waiting for any response.
4
+ * Resolves `ok: true` only if a response packet is received within the timeout window.
5
+ *
6
+ * Note: UDP is connectionless — most servers do not reply to arbitrary packets.
7
+ * A timeout (`ok: false`) does not necessarily mean the host is down; it may simply
8
+ * mean the server ignored the probe. This probe is most useful for services that
9
+ * explicitly echo UDP packets (e.g. custom health-check endpoints, DNS on port 53).
10
+ * For DNS specifically, use the `dns` protocol instead.
11
+ *
12
+ * @param url - Target in `"host:port"` format (e.g. `"1.2.3.4:9000"`).
13
+ *
14
+ * @example
15
+ * const result = await udpProbe("1.2.3.4:9000");
16
+ * console.log(result.ok, result.latency);
17
+ */
18
+ export declare function udpProbe(url: string): Promise<ProbeResult>;
19
+ //# sourceMappingURL=udp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/probes/udp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAqF1D"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.udpProbe = udpProbe;
37
+ const dgram = __importStar(require("dgram"));
38
+ const timer_1 = require("../utils/timer");
39
+ /**
40
+ * Probe a host via UDP by sending a small packet and waiting for any response.
41
+ * Resolves `ok: true` only if a response packet is received within the timeout window.
42
+ *
43
+ * Note: UDP is connectionless — most servers do not reply to arbitrary packets.
44
+ * A timeout (`ok: false`) does not necessarily mean the host is down; it may simply
45
+ * mean the server ignored the probe. This probe is most useful for services that
46
+ * explicitly echo UDP packets (e.g. custom health-check endpoints, DNS on port 53).
47
+ * For DNS specifically, use the `dns` protocol instead.
48
+ *
49
+ * @param url - Target in `"host:port"` format (e.g. `"1.2.3.4:9000"`).
50
+ *
51
+ * @example
52
+ * const result = await udpProbe("1.2.3.4:9000");
53
+ * console.log(result.ok, result.latency);
54
+ */
55
+ function udpProbe(url) {
56
+ return new Promise((resolve) => {
57
+ const [host, portStr] = url.split(":");
58
+ const port = parseInt(portStr, 10);
59
+ if (!host || isNaN(port)) {
60
+ resolve({
61
+ ok: false,
62
+ latency: null,
63
+ error: "Invalid host:port format",
64
+ protocol: "udp",
65
+ target: url,
66
+ timestamp: Date.now(),
67
+ });
68
+ return;
69
+ }
70
+ const client = dgram.createSocket("udp4");
71
+ const stop = (0, timer_1.startTimer)();
72
+ const message = Buffer.from("ping");
73
+ let resolved = false;
74
+ const timeout = setTimeout(() => {
75
+ if (!resolved) {
76
+ resolved = true;
77
+ client.close();
78
+ resolve({
79
+ ok: false,
80
+ latency: null,
81
+ error: "UDP timeout — no response received",
82
+ protocol: "udp",
83
+ target: url,
84
+ timestamp: Date.now(),
85
+ });
86
+ }
87
+ }, 5000);
88
+ client.on("message", () => {
89
+ if (!resolved) {
90
+ const latency = stop();
91
+ resolved = true;
92
+ clearTimeout(timeout);
93
+ client.close();
94
+ resolve({
95
+ ok: true,
96
+ latency,
97
+ protocol: "udp",
98
+ target: url,
99
+ timestamp: Date.now(),
100
+ });
101
+ }
102
+ });
103
+ client.on("error", (err) => {
104
+ if (!resolved) {
105
+ resolved = true;
106
+ clearTimeout(timeout);
107
+ client.close();
108
+ resolve({
109
+ ok: false,
110
+ latency: null,
111
+ error: err.message,
112
+ protocol: "udp",
113
+ target: url,
114
+ timestamp: Date.now(),
115
+ });
116
+ }
117
+ });
118
+ client.send(message, 0, message.length, port, host, (err) => {
119
+ if (err && !resolved) {
120
+ resolved = true;
121
+ clearTimeout(timeout);
122
+ client.close();
123
+ resolve({
124
+ ok: false,
125
+ latency: null,
126
+ error: err.message,
127
+ protocol: "udp",
128
+ target: url,
129
+ timestamp: Date.now(),
130
+ });
131
+ }
132
+ });
133
+ });
134
+ }
135
+ //# sourceMappingURL=udp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"udp.js","sourceRoot":"","sources":["../../src/probes/udp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,4BAqFC;AAzGD,6CAA+B;AAE/B,0CAA4C;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC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the given threshold.
3
+ *
4
+ * @param latency - Measured latency in milliseconds.
5
+ * @param threshold - Maximum acceptable latency in milliseconds. Default: `1000`.
6
+ * @returns `true` if `latency` is strictly greater than `threshold`.
7
+ *
8
+ * @example
9
+ * isSlowLatency(1200, 1000); // true
10
+ * isSlowLatency(800, 1000); // false
11
+ * isSlowLatency(1000, 1000); // false — equal is not slow
12
+ */
13
+ export declare function isSlowLatency(latency: number, threshold?: number): boolean;
14
+ //# sourceMappingURL=latency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"latency.d.ts","sourceRoot":"","sources":["../../src/utils/latency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAEhF"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSlowLatency = isSlowLatency;
4
+ /**
5
+ * Determine whether a measured latency exceeds the given threshold.
6
+ *
7
+ * @param latency - Measured latency in milliseconds.
8
+ * @param threshold - Maximum acceptable latency in milliseconds. Default: `1000`.
9
+ * @returns `true` if `latency` is strictly greater than `threshold`.
10
+ *
11
+ * @example
12
+ * isSlowLatency(1200, 1000); // true
13
+ * isSlowLatency(800, 1000); // false
14
+ * isSlowLatency(1000, 1000); // false — equal is not slow
15
+ */
16
+ function isSlowLatency(latency, threshold = 1000) {
17
+ return latency > threshold;
18
+ }
19
+ //# sourceMappingURL=latency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"latency.js","sourceRoot":"","sources":["../../src/utils/latency.ts"],"names":[],"mappings":";;AAYA,sCAEC;AAdD;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,OAAe,EAAE,YAAoB,IAAI;IACrE,OAAO,OAAO,GAAG,SAAS,CAAC;AAC7B,CAAC"}