@push.rocks/smartnetwork 4.4.0 → 4.5.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.
@@ -0,0 +1,98 @@
1
+ import * as plugins from './smartnetwork.plugins.js';
2
+ import * as path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ function getPlatformSuffix() {
5
+ const platform = process.platform;
6
+ const arch = process.arch;
7
+ const platformMap = {
8
+ linux: 'linux',
9
+ darwin: 'macos',
10
+ win32: 'windows',
11
+ };
12
+ const archMap = {
13
+ x64: 'amd64',
14
+ arm64: 'arm64',
15
+ };
16
+ const p = platformMap[platform];
17
+ const a = archMap[arch];
18
+ if (p && a) {
19
+ return `${p}_${a}`;
20
+ }
21
+ return null;
22
+ }
23
+ /**
24
+ * Singleton bridge to the rustnetwork binary.
25
+ * Manages the IPC lifecycle for network diagnostics operations.
26
+ */
27
+ export class RustNetworkBridge {
28
+ static { this.instance = null; }
29
+ static getInstance() {
30
+ if (!RustNetworkBridge.instance) {
31
+ RustNetworkBridge.instance = new RustNetworkBridge();
32
+ }
33
+ return RustNetworkBridge.instance;
34
+ }
35
+ constructor() {
36
+ const packageDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
37
+ const platformSuffix = getPlatformSuffix();
38
+ const localPaths = [];
39
+ // Platform-specific cross-compiled binary
40
+ if (platformSuffix) {
41
+ localPaths.push(path.join(packageDir, 'dist_rust', `rustnetwork_${platformSuffix}`));
42
+ }
43
+ // Native build without suffix
44
+ localPaths.push(path.join(packageDir, 'dist_rust', 'rustnetwork'));
45
+ // Local dev paths
46
+ localPaths.push(path.join(packageDir, 'rust', 'target', 'release', 'rustnetwork'));
47
+ localPaths.push(path.join(packageDir, 'rust', 'target', 'debug', 'rustnetwork'));
48
+ this.bridge = new plugins.smartrust.RustBridge({
49
+ binaryName: 'rustnetwork',
50
+ cliArgs: ['--management'],
51
+ requestTimeoutMs: 30_000,
52
+ readyTimeoutMs: 10_000,
53
+ localPaths,
54
+ searchSystemPath: false,
55
+ });
56
+ }
57
+ /**
58
+ * Spawn the Rust binary and wait for it to be ready.
59
+ */
60
+ async start() {
61
+ const ok = await this.bridge.spawn();
62
+ if (!ok) {
63
+ throw new Error('Failed to spawn rustnetwork binary');
64
+ }
65
+ }
66
+ /**
67
+ * Kill the Rust binary.
68
+ */
69
+ async stop() {
70
+ this.bridge.kill();
71
+ }
72
+ /**
73
+ * Ensure the bridge is running before sending a command.
74
+ */
75
+ async ensureRunning() {
76
+ // The bridge will throw if not spawned — we just call start() if not yet running
77
+ }
78
+ // ===== Command wrappers =====
79
+ async ping(host, count, timeoutMs) {
80
+ return this.bridge.sendCommand('ping', { host, count, timeoutMs });
81
+ }
82
+ async traceroute(host, maxHops, timeoutMs) {
83
+ return this.bridge.sendCommand('traceroute', { host, maxHops, timeoutMs });
84
+ }
85
+ async tcpPortCheck(host, port, timeoutMs) {
86
+ return this.bridge.sendCommand('tcpPortCheck', { host, port, timeoutMs });
87
+ }
88
+ async isLocalPortFree(port) {
89
+ return this.bridge.sendCommand('isLocalPortFree', { port });
90
+ }
91
+ async defaultGateway() {
92
+ return this.bridge.sendCommand('defaultGateway', {});
93
+ }
94
+ async healthPing() {
95
+ return this.bridge.sendCommand('healthPing', {});
96
+ }
97
+ }
98
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZXR3b3JrLmNsYXNzZXMucnVzdGJyaWRnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmV0d29yay5jbGFzc2VzLnJ1c3RicmlkZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSwyQkFBMkIsQ0FBQztBQUNyRCxPQUFPLEtBQUssSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUNsQyxPQUFPLEVBQUUsYUFBYSxFQUFFLE1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MsRUFBRSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsU0FBUyxFQUFFLENBQUMsQ0FBQztJQUM1RSxDQUFDO0lBRU0sS0FBSyxDQUFDLGVBQWUsQ0FDMUIsSUFBWTtRQUVaLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQyxXQUFXLENBQUMsaUJBQWlCLEVBQUUsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDO0lBQzlELENBQUM7SUFFTSxLQUFLLENBQUMsY0FBYztRQUN6QixPQUFPLElBQUksQ0FBQyxNQUFNLENBQUMsV0FBVyxDQUFDLGdCQUFnQixFQUFFLEVBQTJCLENBQUMsQ0FBQztJQUNoRixDQUFDO0lBRU0sS0FBSyxDQUFDLFVBQVU7UUFDckIsT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLFdBQVcsQ0FBQyxZQUFZLEVBQUUsRUFBMkIsQ0FBQyxDQUFDO0lBQzVFLENBQUMifQ==
@@ -1,7 +1,5 @@
1
1
  import * as plugins from './smartnetwork.plugins.js';
2
- /**
3
- * SmartNetwork simplifies actions within the network
4
- */
2
+ import { type IIpIntelligenceResult } from './smartnetwork.classes.ipintelligence.js';
5
3
  /**
6
4
  * Configuration options for SmartNetwork
7
5
  */
@@ -26,6 +24,10 @@ export interface IFindFreePortOptions {
26
24
  /** Array of port numbers to exclude from the search */
27
25
  exclude?: number[];
28
26
  }
27
+ /**
28
+ * SmartNetwork simplifies actions within the network.
29
+ * Uses a Rust binary for system-dependent operations (ping, traceroute, port scanning, gateway detection).
30
+ */
29
31
  export declare class SmartNetwork {
30
32
  /** Static registry for external plugins */
31
33
  static pluginsRegistry: Map<string, any>;
@@ -35,10 +37,25 @@ export declare class SmartNetwork {
35
37
  static unregisterPlugin(name: string): void;
36
38
  private options;
37
39
  private cache;
40
+ private rustBridge;
41
+ private bridgeStarted;
42
+ private ipIntelligence;
38
43
  constructor(options?: SmartNetworkOptions);
39
44
  /**
40
- * get network speed
41
- * @param opts optional speed test parameters
45
+ * Start the Rust binary bridge. Must be called before using ping, traceroute,
46
+ * port scanning, or gateway operations. Safe to call multiple times.
47
+ */
48
+ start(): Promise<void>;
49
+ /**
50
+ * Stop the Rust binary bridge.
51
+ */
52
+ stop(): Promise<void>;
53
+ /**
54
+ * Ensure the Rust bridge is running before sending commands.
55
+ */
56
+ private ensureBridge;
57
+ /**
58
+ * Get network speed via Cloudflare speed test (pure TS, no Rust needed).
42
59
  */
43
60
  getSpeed(opts?: {
44
61
  parallelStreams?: number;
@@ -67,36 +84,16 @@ export declare class SmartNetwork {
67
84
  timeout?: number;
68
85
  count?: number;
69
86
  }): Promise<any>;
70
- /**
71
- * returns a promise with a boolean answer
72
- * note: false also resolves with false as argument
73
- * @param port
74
- */
75
87
  /**
76
88
  * Check if a local port is unused (both IPv4 and IPv6)
77
89
  */
78
90
  isLocalPortUnused(port: number): Promise<boolean>;
79
91
  /**
80
92
  * Find the first available port within a given range
81
- * @param startPort The start of the port range (inclusive)
82
- * @param endPort The end of the port range (inclusive)
83
- * @param options Optional configuration for port selection behavior
84
- * @returns The first available port number (or random if options.randomize is true), or null if no ports are available
85
93
  */
86
94
  findFreePort(startPort: number, endPort: number, options?: IFindFreePortOptions): Promise<number | null>;
87
- /**
88
- * checks wether a remote port is available
89
- * @param domainArg
90
- */
91
- /**
92
- * Check if a remote port is available
93
- * @param target host or "host:port"
94
- * @param opts options including port, protocol (only tcp), retries and timeout
95
- */
96
95
  /**
97
96
  * Check if a remote port is available
98
- * @param target host or "host:port"
99
- * @param portOrOpts either a port number (deprecated) or options object
100
97
  */
101
98
  isRemotePortAvailable(target: string, portOrOpts?: number | {
102
99
  port?: number;
@@ -105,22 +102,25 @@ export declare class SmartNetwork {
105
102
  retries?: number;
106
103
  }): Promise<boolean>;
107
104
  /**
108
- * List network interfaces (gateways)
105
+ * List network interfaces (gateways) — pure TS, no Rust needed.
109
106
  */
110
107
  getGateways(): Promise<Record<string, plugins.os.NetworkInterfaceInfo[]>>;
108
+ /**
109
+ * Get the default gateway interface and its addresses.
110
+ */
111
111
  getDefaultGateway(): Promise<{
112
112
  ipv4: plugins.os.NetworkInterfaceInfo;
113
113
  ipv6: plugins.os.NetworkInterfaceInfo;
114
- }>;
114
+ } | null>;
115
115
  /**
116
- * Lookup public IPv4 and IPv6
116
+ * Lookup public IPv4 and IPv6 — pure TS, no Rust needed.
117
117
  */
118
118
  getPublicIps(): Promise<{
119
119
  v4: string | null;
120
120
  v6: string | null;
121
121
  }>;
122
122
  /**
123
- * Resolve DNS records (A, AAAA, MX)
123
+ * Resolve DNS records (A, AAAA, MX) — uses smartdns, no Rust needed.
124
124
  */
125
125
  resolveDns(host: string): Promise<{
126
126
  A: string[];
@@ -131,23 +131,29 @@ export declare class SmartNetwork {
131
131
  }[];
132
132
  }>;
133
133
  /**
134
- * Perform a simple HTTP/HTTPS endpoint health check
134
+ * Perform a simple HTTP/HTTPS endpoint health check — pure TS.
135
135
  */
136
136
  checkEndpoint(urlString: string, opts?: {
137
137
  timeout?: number;
138
+ rejectUnauthorized?: boolean;
138
139
  }): Promise<{
139
140
  status: number;
140
141
  headers: Record<string, string>;
141
142
  rtt: number;
142
143
  }>;
143
144
  /**
144
- * Perform a traceroute: hop-by-hop latency using the system traceroute tool.
145
- * Falls back to a single-hop stub if traceroute is unavailable or errors.
145
+ * Perform a traceroute: hop-by-hop latency using the Rust binary.
146
146
  */
147
147
  traceroute(host: string, opts?: {
148
148
  maxHops?: number;
149
149
  timeout?: number;
150
150
  }): Promise<Hop[]>;
151
+ /**
152
+ * Get IP intelligence: ASN, organization, geolocation, and RDAP registration data.
153
+ * Combines RDAP (RIRs), Team Cymru DNS, and MaxMind GeoLite2 — all run in parallel.
154
+ * Pure TS, no Rust needed.
155
+ */
156
+ getIpIntelligence(ip: string): Promise<IIpIntelligenceResult>;
151
157
  /**
152
158
  * Internal caching helper
153
159
  */