@push.rocks/smartnetwork 4.3.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
  */
@@ -23,7 +21,13 @@ export interface Hop {
23
21
  export interface IFindFreePortOptions {
24
22
  /** If true, selects a random available port within the range instead of the first one */
25
23
  randomize?: boolean;
24
+ /** Array of port numbers to exclude from the search */
25
+ exclude?: number[];
26
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
+ */
27
31
  export declare class SmartNetwork {
28
32
  /** Static registry for external plugins */
29
33
  static pluginsRegistry: Map<string, any>;
@@ -33,10 +37,25 @@ export declare class SmartNetwork {
33
37
  static unregisterPlugin(name: string): void;
34
38
  private options;
35
39
  private cache;
40
+ private rustBridge;
41
+ private bridgeStarted;
42
+ private ipIntelligence;
36
43
  constructor(options?: SmartNetworkOptions);
37
44
  /**
38
- * get network speed
39
- * @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).
40
59
  */
41
60
  getSpeed(opts?: {
42
61
  parallelStreams?: number;
@@ -65,36 +84,16 @@ export declare class SmartNetwork {
65
84
  timeout?: number;
66
85
  count?: number;
67
86
  }): Promise<any>;
68
- /**
69
- * returns a promise with a boolean answer
70
- * note: false also resolves with false as argument
71
- * @param port
72
- */
73
87
  /**
74
88
  * Check if a local port is unused (both IPv4 and IPv6)
75
89
  */
76
90
  isLocalPortUnused(port: number): Promise<boolean>;
77
91
  /**
78
92
  * Find the first available port within a given range
79
- * @param startPort The start of the port range (inclusive)
80
- * @param endPort The end of the port range (inclusive)
81
- * @param options Optional configuration for port selection behavior
82
- * @returns The first available port number (or random if options.randomize is true), or null if no ports are available
83
93
  */
84
94
  findFreePort(startPort: number, endPort: number, options?: IFindFreePortOptions): Promise<number | null>;
85
- /**
86
- * checks wether a remote port is available
87
- * @param domainArg
88
- */
89
- /**
90
- * Check if a remote port is available
91
- * @param target host or "host:port"
92
- * @param opts options including port, protocol (only tcp), retries and timeout
93
- */
94
95
  /**
95
96
  * Check if a remote port is available
96
- * @param target host or "host:port"
97
- * @param portOrOpts either a port number (deprecated) or options object
98
97
  */
99
98
  isRemotePortAvailable(target: string, portOrOpts?: number | {
100
99
  port?: number;
@@ -103,22 +102,25 @@ export declare class SmartNetwork {
103
102
  retries?: number;
104
103
  }): Promise<boolean>;
105
104
  /**
106
- * List network interfaces (gateways)
105
+ * List network interfaces (gateways) — pure TS, no Rust needed.
107
106
  */
108
107
  getGateways(): Promise<Record<string, plugins.os.NetworkInterfaceInfo[]>>;
108
+ /**
109
+ * Get the default gateway interface and its addresses.
110
+ */
109
111
  getDefaultGateway(): Promise<{
110
112
  ipv4: plugins.os.NetworkInterfaceInfo;
111
113
  ipv6: plugins.os.NetworkInterfaceInfo;
112
- }>;
114
+ } | null>;
113
115
  /**
114
- * Lookup public IPv4 and IPv6
116
+ * Lookup public IPv4 and IPv6 — pure TS, no Rust needed.
115
117
  */
116
118
  getPublicIps(): Promise<{
117
119
  v4: string | null;
118
120
  v6: string | null;
119
121
  }>;
120
122
  /**
121
- * Resolve DNS records (A, AAAA, MX)
123
+ * Resolve DNS records (A, AAAA, MX) — uses smartdns, no Rust needed.
122
124
  */
123
125
  resolveDns(host: string): Promise<{
124
126
  A: string[];
@@ -129,23 +131,29 @@ export declare class SmartNetwork {
129
131
  }[];
130
132
  }>;
131
133
  /**
132
- * Perform a simple HTTP/HTTPS endpoint health check
134
+ * Perform a simple HTTP/HTTPS endpoint health check — pure TS.
133
135
  */
134
136
  checkEndpoint(urlString: string, opts?: {
135
137
  timeout?: number;
138
+ rejectUnauthorized?: boolean;
136
139
  }): Promise<{
137
140
  status: number;
138
141
  headers: Record<string, string>;
139
142
  rtt: number;
140
143
  }>;
141
144
  /**
142
- * Perform a traceroute: hop-by-hop latency using the system traceroute tool.
143
- * 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.
144
146
  */
145
147
  traceroute(host: string, opts?: {
146
148
  maxHops?: number;
147
149
  timeout?: number;
148
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>;
149
157
  /**
150
158
  * Internal caching helper
151
159
  */