@gibme/mikrotik 2.0.5 → 3.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.
package/dist/index.d.ts CHANGED
@@ -1,24 +1,9 @@
1
- import SSH, { AbortController, AbortSignal } from '@gibme/ssh';
2
- import { BandwidthTest, Response } from './types';
1
+ import SSH from '@gibme/ssh';
3
2
  import Cache from '@gibme/cache/memory';
3
+ import { AbortController, AbortSignal } from 'abort-controller';
4
4
  export { AbortController, AbortSignal };
5
5
  export type { ConnectConfig } from '@gibme/ssh';
6
- export type Direction = BandwidthTest.Direction;
7
- export type Protocol = BandwidthTest.Protocol;
8
- export type Status = BandwidthTest.Status;
9
- export type Update = BandwidthTest.Update;
10
- export type Options = BandwidthTest.Options;
11
- export type Address = Response.Address;
12
- export type Interface = Response.Interface;
13
- export type Tunnel = Response.Tunnel;
14
- export type Route = Response.Route;
15
- export type RouteCount = Response.RouteCount;
16
- export type Ping = Response.Ping;
17
- export type Traceroute = Response.Traceroute;
18
- export type RouterBoard = Response.Routerboard;
19
- export type Resource = Response.Resource;
20
- export type Health = Response.Health;
21
- export default class Mikrotik extends SSH {
6
+ export declare class Mikrotik extends SSH {
22
7
  protected static cache: Cache;
23
8
  /**
24
9
  * Retrieves the routes in the routing table
@@ -27,19 +12,19 @@ export default class Mikrotik extends SSH {
27
12
  * @param vrf
28
13
  * @param active_only
29
14
  */
30
- get_ip_routes(min_distance?: number, vrf?: string, active_only?: boolean): Promise<Route[]>;
15
+ get_ip_routes(min_distance?: number, vrf?: string, active_only?: boolean): Promise<Mikrotik.Response.Route[]>;
31
16
  /**
32
17
  * Retrieves the IP addresses active on the system
33
18
  *
34
19
  * @param active_only
35
20
  */
36
- get_ip_addresses(active_only?: boolean): Promise<Address[]>;
21
+ get_ip_addresses(active_only?: boolean): Promise<Mikrotik.Response.Address[]>;
37
22
  /**
38
23
  * Retrieves the interfaces active on the system
39
24
  *
40
25
  * @param active_only
41
26
  */
42
- get_interfaces(active_only?: boolean): Promise<Interface[]>;
27
+ get_interfaces(active_only?: boolean): Promise<Mikrotik.Response.Interface[]>;
43
28
  /**
44
29
  * For all device IP addresses, counts the routes that exit (either directly or tunneled)
45
30
  * the device using each IP address
@@ -47,7 +32,7 @@ export default class Mikrotik extends SSH {
47
32
  * @param min_distance
48
33
  * @param vrf
49
34
  */
50
- get_route_counts(min_distance?: number, vrf?: string): Promise<Record<string, RouteCount>>;
35
+ get_route_counts(min_distance?: number, vrf?: string): Promise<Record<string, Mikrotik.Response.Route.Count>>;
51
36
  /**
52
37
  * Executes a bandwidth test
53
38
  *
@@ -60,25 +45,25 @@ export default class Mikrotik extends SSH {
60
45
  * @param password
61
46
  * @param options
62
47
  */
63
- bandwidth_test(target: string, username: string, password: string, options?: Partial<Options>): Promise<Update>;
48
+ bandwidth_test(target: string, username: string, password: string, options?: Partial<Mikrotik.BandwidthTest.Options>): Promise<Mikrotik.BandwidthTest.Update>;
64
49
  /**
65
50
  * Pings the target IP address from the source IP address (if supplied)
66
51
  *
67
52
  * @param target
68
53
  * @param source
69
54
  */
70
- ping(target: string, source?: string): Promise<Ping>;
55
+ ping(target: string, source?: string): Promise<Mikrotik.Response.Ping>;
71
56
  /**
72
57
  * Performs a traceroute to the target IP address from the source IP address (if supplied)
73
58
  *
74
59
  * @param target
75
60
  * @param source
76
61
  */
77
- traceroute(target: string, source?: string): Promise<Traceroute[]>;
62
+ traceroute(target: string, source?: string): Promise<Mikrotik.Response.Traceroute[]>;
78
63
  /**
79
64
  * Fetches routerboard information from the device
80
65
  */
81
- routerboard(): Promise<Response.Routerboard>;
66
+ routerboard(): Promise<Mikrotik.Response.Routerboard>;
82
67
  /**
83
68
  * Fetches the identity of the device
84
69
  */
@@ -86,7 +71,7 @@ export default class Mikrotik extends SSH {
86
71
  /**
87
72
  * Fetches the resource information of the device
88
73
  */
89
- resource(): Promise<Response.Resource>;
74
+ resource(): Promise<Mikrotik.Response.Resource>;
90
75
  /**
91
76
  * Fetches the current RouterOS version
92
77
  */
@@ -102,7 +87,7 @@ export default class Mikrotik extends SSH {
102
87
  /**
103
88
  * Fetches the current health information
104
89
  */
105
- health(): Promise<Response.Health>;
90
+ health(): Promise<Mikrotik.Response.V6.Health | Mikrotik.Response.V7.Health>;
106
91
  /**
107
92
  * Executes a command with expected terse response and parses it accordingly
108
93
  *
@@ -118,3 +103,266 @@ export default class Mikrotik extends SSH {
118
103
  */
119
104
  kvs<Type extends object = any>(command: string): Promise<Type>;
120
105
  }
106
+ export declare namespace Mikrotik {
107
+ namespace BandwidthTest {
108
+ type Direction = 'both' | 'transmit' | 'receive';
109
+ type Protocol = 'udp' | 'tcp';
110
+ type Status = 'running' | 'connecting' | 'done testing' | 'authentication_failed' | 'queued';
111
+ /**
112
+ * Class that helps with processing a "frame" of the Bandwidth Test response
113
+ */
114
+ class Frame {
115
+ readonly buffer: Buffer;
116
+ private parsed?;
117
+ constructor(buffer: Buffer);
118
+ parse(): Record<string, string>;
119
+ }
120
+ interface DirectionStats {
121
+ current: number;
122
+ shortAverage: number;
123
+ totalAverage: number;
124
+ size: number;
125
+ }
126
+ interface Update {
127
+ status: Status;
128
+ duration: number;
129
+ transmit?: DirectionStats;
130
+ receive?: DirectionStats;
131
+ lostPackets?: number;
132
+ randomData: boolean;
133
+ direction: Direction;
134
+ connectionCount: number;
135
+ localCPULoad: number;
136
+ remoteCPULoad: number;
137
+ }
138
+ interface Options {
139
+ duration: number;
140
+ direction: Direction;
141
+ protocol: Protocol;
142
+ random_data: boolean;
143
+ callback: (frame: Update) => void;
144
+ timeout: number;
145
+ signal: AbortSignal;
146
+ /**
147
+ * In Megabits
148
+ */
149
+ local_tx_speed: number;
150
+ /**
151
+ * In Megabits
152
+ */
153
+ remote_tx_speed: number;
154
+ }
155
+ }
156
+ type YesNo = 'yes' | 'no';
157
+ type Comment = {
158
+ comment?: string;
159
+ };
160
+ namespace Response {
161
+ namespace Command {
162
+ type Route = Comment & {
163
+ 'dst-address': string;
164
+ gateway: string;
165
+ distance: string;
166
+ scope: string;
167
+ target_scope: string;
168
+ 'routing-table'?: string;
169
+ 'routing-mark'?: string;
170
+ 'bgp-as-path'?: string;
171
+ 'bgp-origin'?: string;
172
+ 'bgp-local-pref'?: string;
173
+ 'received-from'?: string;
174
+ 'check-gateway'?: string;
175
+ 'suppress-hw-offload'?: string;
176
+ 'blackhole'?: string;
177
+ 'immediate-gw'?: string;
178
+ reachable?: string;
179
+ 'gateway-status'?: string;
180
+ };
181
+ type Address = Comment & {
182
+ address: string;
183
+ network: string;
184
+ interface: string;
185
+ 'actual-interface': string;
186
+ };
187
+ type Interface = Comment & {
188
+ name: string;
189
+ type: string;
190
+ mtu: string;
191
+ 'default-name'?: string;
192
+ 'actual-mtu': string;
193
+ 'mac-address'?: string;
194
+ 'link-downs'?: string;
195
+ l2mtu?: string;
196
+ };
197
+ type Tunnel = Omit<Interface, 'type'> & Comment & {
198
+ 'local-address': string;
199
+ 'remote-address': string;
200
+ 'clamp-tcp-mss': YesNo;
201
+ 'dont-fragment': YesNo;
202
+ 'allow-fast-path': YesNo;
203
+ };
204
+ type Routerboard = {
205
+ routerboard: YesNo;
206
+ 'board-name': string;
207
+ model: string;
208
+ 'serial-number': string;
209
+ 'firmware-type': string;
210
+ 'factory-firmware': string;
211
+ 'current-firmware': string;
212
+ 'upgrade-firmware': string;
213
+ };
214
+ type Identity = {
215
+ name: string;
216
+ };
217
+ type Resource = {
218
+ uptime: string;
219
+ version: string;
220
+ 'build-time': string;
221
+ 'factory-software': string;
222
+ 'free-memory': string;
223
+ 'total-memory': string;
224
+ cpu: string;
225
+ 'cpu-count': string;
226
+ 'cpu-frequency': string;
227
+ 'cpu-load': string;
228
+ 'free-hdd-space': string;
229
+ 'total-hdd-space': string;
230
+ 'architecture-name': string;
231
+ 'board-name': string;
232
+ platform: string;
233
+ 'write-sect-since-reboot'?: string;
234
+ 'write-sect-total'?: string;
235
+ 'bad-blocks'?: string;
236
+ };
237
+ namespace V6 {
238
+ type Health = {
239
+ voltage: string;
240
+ current: string;
241
+ temperature: string;
242
+ 'power-consumption': string;
243
+ 'psu-voltage'?: string;
244
+ 'psu1-voltage'?: string;
245
+ 'psu2-voltage'?: string;
246
+ };
247
+ }
248
+ }
249
+ type includesAddress = {
250
+ includes(ipaddress: string): boolean;
251
+ };
252
+ type Address = includesAddress & Comment & {
253
+ ipaddress: string;
254
+ network: string;
255
+ cidr: number;
256
+ iface: string;
257
+ };
258
+ type Interface = Comment & {
259
+ name: string;
260
+ type: string;
261
+ local_address?: string;
262
+ remote_address?: string;
263
+ };
264
+ type Tunnel = Interface & {
265
+ parent: Address;
266
+ };
267
+ type Route = includesAddress & Comment & {
268
+ network: string;
269
+ cidr: number;
270
+ distance: number;
271
+ scope: number;
272
+ vrf: string;
273
+ preferred_source?: string;
274
+ gateway?: string;
275
+ iface?: string;
276
+ tunnel?: Tunnel;
277
+ target_scope?: number;
278
+ };
279
+ namespace Route {
280
+ type Count = {
281
+ interface: string;
282
+ count: number;
283
+ active: boolean;
284
+ };
285
+ }
286
+ type Ping = {
287
+ target: string;
288
+ latency: number;
289
+ source?: string;
290
+ };
291
+ type Traceroute = {
292
+ hop: number;
293
+ loss: number;
294
+ sent: number;
295
+ last: number;
296
+ average: number;
297
+ best: number;
298
+ worst: number;
299
+ timeout: boolean;
300
+ address?: string;
301
+ hostname?: string;
302
+ };
303
+ type Routerboard = {
304
+ routerboard: boolean;
305
+ board_name: string;
306
+ model: string;
307
+ serial_number: string;
308
+ firmware_type: string;
309
+ factory_firmware: string;
310
+ current_firmware: string;
311
+ upgrade_firmware: string;
312
+ };
313
+ type Resource = {
314
+ uptime: string;
315
+ version: string;
316
+ build_time: Date;
317
+ factory_sofware: string;
318
+ free_memory: string;
319
+ total_memory: string;
320
+ cpu: string;
321
+ cpu_count: number;
322
+ cpu_frequency: number;
323
+ cpu_load: number;
324
+ hdd_space: {
325
+ free: string;
326
+ total: string;
327
+ };
328
+ architecture_name: string;
329
+ board_name: string;
330
+ platform: string;
331
+ lts?: boolean;
332
+ stable?: boolean;
333
+ testing?: boolean;
334
+ development?: boolean;
335
+ nvram?: {
336
+ write_since_reboot: number;
337
+ write_total: number;
338
+ bad_blocks: number;
339
+ };
340
+ };
341
+ namespace V6 {
342
+ type Health = {
343
+ voltage: number;
344
+ current: number;
345
+ temperature: number;
346
+ power_consumption: number;
347
+ psu_voltage?: number;
348
+ psu1_voltage?: number;
349
+ psu2_voltage?: number;
350
+ };
351
+ }
352
+ namespace V7 {
353
+ type Health = {
354
+ cpu_temperature: number;
355
+ sfp_temperature: number;
356
+ switch_temperature: number;
357
+ fan_state: string;
358
+ fan1_speed: number;
359
+ fan2_speed: number;
360
+ board_temperature1: number;
361
+ board_temperature2: number;
362
+ psu1_state: string;
363
+ psu2_state: string;
364
+ };
365
+ }
366
+ }
367
+ }
368
+ export default Mikrotik;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright (c) 2024, Brandon Lehmann <brandonlehmann@gmail.com>
2
+ // Copyright (c) 2024-2025, Brandon Lehmann <brandonlehmann@gmail.com>
3
3
  //
4
4
  // Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  // of this software and associated documentation files (the "Software"), to deal
@@ -18,29 +18,6 @@
18
18
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
20
  // SOFTWARE.
21
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- var desc = Object.getOwnPropertyDescriptor(m, k);
24
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
25
- desc = { enumerable: true, get: function() { return m[k]; } };
26
- }
27
- Object.defineProperty(o, k2, desc);
28
- }) : (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- o[k2] = m[k];
31
- }));
32
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
33
- Object.defineProperty(o, "default", { enumerable: true, value: v });
34
- }) : function(o, v) {
35
- o["default"] = v;
36
- });
37
- var __importStar = (this && this.__importStar) || function (mod) {
38
- if (mod && mod.__esModule) return mod;
39
- var result = {};
40
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
41
- __setModuleDefault(result, mod);
42
- return result;
43
- };
44
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
45
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
46
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -54,15 +31,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
54
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
32
  };
56
33
  Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.AbortSignal = exports.AbortController = void 0;
58
- const ssh_1 = __importStar(require("@gibme/ssh"));
59
- Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return ssh_1.AbortController; } });
60
- Object.defineProperty(exports, "AbortSignal", { enumerable: true, get: function () { return ssh_1.AbortSignal; } });
61
- const types_1 = require("./types");
34
+ exports.Mikrotik = exports.AbortSignal = exports.AbortController = void 0;
35
+ const ssh_1 = __importDefault(require("@gibme/ssh"));
62
36
  const ip_address_1 = require("ip-address");
63
37
  const memory_1 = __importDefault(require("@gibme/cache/memory"));
64
38
  const dns_1 = require("dns");
65
39
  const semver_1 = require("semver");
40
+ const abort_controller_1 = require("abort-controller");
41
+ Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return abort_controller_1.AbortController; } });
42
+ Object.defineProperty(exports, "AbortSignal", { enumerable: true, get: function () { return abort_controller_1.AbortSignal; } });
66
43
  /** @ignore */
67
44
  const toVersion = (version) => (0, semver_1.valid)((0, semver_1.coerce)(version)) || version;
68
45
  /** @ignore */
@@ -292,14 +269,12 @@ class Mikrotik extends ssh_1.default {
292
269
  bandwidth_test(target_1, username_1, password_1) {
293
270
  return __awaiter(this, arguments, void 0, function* (target, username, password, options = {}) {
294
271
  var _a;
295
- // eslint-disable-next-line @typescript-eslint/no-this-alias
296
- const $ = this;
297
272
  const sleep = (timeout) => __awaiter(this, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, timeout)); });
298
- const controller = new ssh_1.AbortController();
273
+ const controller = new abort_controller_1.AbortController();
299
274
  (_a = options.signal) !== null && _a !== void 0 ? _a : (options.signal = controller.signal);
300
275
  // eslint-disable-next-line no-async-promise-executor
301
276
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
302
- var _a, _b, _c, _d, _e;
277
+ var _a, _b, _c, _d, _e, _f;
303
278
  (_a = options.duration) !== null && _a !== void 0 ? _a : (options.duration = 15);
304
279
  (_b = options.direction) !== null && _b !== void 0 ? _b : (options.direction = 'both');
305
280
  (_c = options.protocol) !== null && _c !== void 0 ? _c : (options.protocol = 'udp');
@@ -357,7 +332,7 @@ class Mikrotik extends ssh_1.default {
357
332
  */
358
333
  function handleStream(buffer) {
359
334
  return __awaiter(this, void 0, void 0, function* () {
360
- const frame = new types_1.BandwidthTest.Frame(buffer).parse();
335
+ const frame = new Mikrotik.BandwidthTest.Frame(buffer).parse();
361
336
  const result = {
362
337
  status: frame.status,
363
338
  duration: parseInt(frame.duration) || 0,
@@ -389,10 +364,8 @@ class Mikrotik extends ssh_1.default {
389
364
  case 'done testing':
390
365
  if (options.callback)
391
366
  options.callback(result);
392
- $.off('stream', handleStream);
393
367
  return resolve(result);
394
368
  case 'authentication_failed':
395
- $.off('stream', handleStream);
396
369
  return reject(new Error('Authentication Failed'));
397
370
  case 'connecting':
398
371
  case 'running':
@@ -403,9 +376,7 @@ class Mikrotik extends ssh_1.default {
403
376
  }
404
377
  });
405
378
  }
406
- this.on('stream', handleStream);
407
379
  const cleanup = () => __awaiter(this, void 0, void 0, function* () {
408
- this.off('stream', handleStream);
409
380
  yield Mikrotik.cache.del(target);
410
381
  });
411
382
  yield Mikrotik.cache.set(target, target, options.duration); // set our mutex
@@ -419,21 +390,21 @@ class Mikrotik extends ssh_1.default {
419
390
  if (options.remote_tx_speed) {
420
391
  command += ` remote-tx-speed=${options.remote_tx_speed}M`;
421
392
  }
422
- yield this.stream(command, {
423
- separator: '\r\n\r\n',
424
- signal: options.signal
393
+ const stream = yield this.stream(command, { separator: '\r\n\r\n' });
394
+ (_f = options.signal) === null || _f === void 0 ? void 0 : _f.addEventListener('abort', () => {
395
+ stream.abort();
425
396
  });
426
- this.once('stream_complete', () => __awaiter(this, void 0, void 0, function* () {
397
+ stream.on('data', handleStream);
398
+ stream.on('completed', () => __awaiter(this, void 0, void 0, function* () {
427
399
  yield cleanup();
428
400
  }));
429
- this.once('stream_cancelled', () => __awaiter(this, void 0, void 0, function* () {
401
+ stream.on('cancelled', () => __awaiter(this, void 0, void 0, function* () {
430
402
  yield cleanup();
431
403
  return reject(new Error('Bandwidth Test Cancelled'));
432
404
  }));
433
405
  if (options.timeout) {
434
406
  setTimeout(() => {
435
- var _a;
436
- (_a = options.signal) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('abort'));
407
+ stream.abort();
437
408
  }, options.timeout);
438
409
  }
439
410
  }));
@@ -499,11 +470,16 @@ class Mikrotik extends ssh_1.default {
499
470
  const results = [];
500
471
  const resolveDNS = (ip) => __awaiter(this, void 0, void 0, function* () {
501
472
  return new Promise(resolve => {
502
- (0, dns_1.reverse)(ip, (error, addresses) => {
503
- if (error)
504
- return resolve([ip, undefined]);
505
- return resolve([ip, addresses.shift()]);
506
- });
473
+ try {
474
+ (0, dns_1.reverse)(ip, (error, addresses) => {
475
+ if (error)
476
+ return resolve([ip, undefined]);
477
+ return resolve([ip, addresses.shift()]);
478
+ });
479
+ }
480
+ catch (_a) {
481
+ return resolve([ip, undefined]);
482
+ }
507
483
  });
508
484
  });
509
485
  for (const [hop, address, loss, sent, last, avg, best, worst] of response) {
@@ -636,8 +612,8 @@ class Mikrotik extends ssh_1.default {
636
612
  health() {
637
613
  return __awaiter(this, void 0, void 0, function* () {
638
614
  const { major } = yield this.semantic_version();
639
- const result = {};
640
615
  if (major === 6) {
616
+ const result = {};
641
617
  const response = yield this.kvs('/system health print');
642
618
  result.voltage = parseFloat(response.voltage) || 0;
643
619
  result.current = parseFloat(response.current) || 0;
@@ -655,30 +631,41 @@ class Mikrotik extends ssh_1.default {
655
631
  return result;
656
632
  }
657
633
  else if (major === 7) {
634
+ const result = {};
658
635
  const response = yield this.terse('/system health print terse');
659
- for (const { name, value, type } of response) {
636
+ for (const { name, value } of response) {
660
637
  const num = parseFloat(value) || 0;
661
638
  switch (name) {
662
- case 'voltage':
663
- result.voltage = num;
639
+ case 'cpu-temperature':
640
+ result.cpu_temperature = num;
664
641
  break;
665
- case 'temperature':
666
- result.temperature = num;
642
+ case 'sfp-temperature':
643
+ result.sfp_temperature = num;
667
644
  break;
668
- case 'power-consumption':
669
- result.power_consumption = num;
645
+ case 'switch-temperature':
646
+ result.switch_temperature = num;
670
647
  break;
671
- case 'current':
672
- result.current = type === 'A' ? num * 1000 : num;
648
+ case 'fan-state':
649
+ result.fan_state = value;
673
650
  break;
674
- case 'psu-voltage':
675
- result.psu_voltage = num;
651
+ case 'fan1-speed':
652
+ result.fan1_speed = num;
676
653
  break;
677
- case 'psu1-voltage':
678
- result.psu1_voltage = num;
654
+ case 'fan2-speed':
655
+ result.fan2_speed = num;
656
+ break;
657
+ case 'board-temperature1':
658
+ result.board_temperature1 = num;
659
+ break;
660
+ case 'board-temperature2':
661
+ result.board_temperature2 = num;
662
+ break;
663
+ case 'psu1-state':
664
+ result.psu1_state = value;
665
+ break;
666
+ case 'psu2-state':
667
+ result.psu2_state = value;
679
668
  break;
680
- case 'psu2-voltage':
681
- result.psu2_voltage = num;
682
669
  }
683
670
  }
684
671
  return result;
@@ -782,8 +769,40 @@ class Mikrotik extends ssh_1.default {
782
769
  });
783
770
  }
784
771
  }
772
+ exports.Mikrotik = Mikrotik;
785
773
  Mikrotik.cache = new memory_1.default({
786
774
  stdTTL: 15,
787
775
  checkperiod: 17
788
776
  });
777
+ (function (Mikrotik) {
778
+ let BandwidthTest;
779
+ (function (BandwidthTest) {
780
+ /**
781
+ * Class that helps with processing a "frame" of the Bandwidth Test response
782
+ */
783
+ class Frame {
784
+ // eslint-disable-next-line no-useless-constructor
785
+ constructor(buffer) {
786
+ this.buffer = buffer;
787
+ }
788
+ parse() {
789
+ if (!this.parsed) {
790
+ this.parsed = {};
791
+ const records = this.buffer.toString('utf8').trim()
792
+ .split('\n')
793
+ .map(line => line.trim())
794
+ .map(line => line.split(':', 2)
795
+ .map(elem => elem.trim()));
796
+ for (const [key, value] of records) {
797
+ if (key.length === 0)
798
+ continue;
799
+ this.parsed[key.toLowerCase()] = value;
800
+ }
801
+ }
802
+ return this.parsed;
803
+ }
804
+ }
805
+ BandwidthTest.Frame = Frame;
806
+ })(BandwidthTest = Mikrotik.BandwidthTest || (Mikrotik.BandwidthTest = {}));
807
+ })(Mikrotik || (exports.Mikrotik = Mikrotik = {}));
789
808
  exports.default = Mikrotik;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gibme/mikrotik",
3
- "version": "2.0.5",
3
+ "version": "3.0.0",
4
4
  "description": "A simple mikrotik helper/wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://gibme-npm.github.io/mikrotik/",
32
32
  "engines": {
33
- "node": ">=16"
33
+ "node": ">=18"
34
34
  },
35
35
  "engineStrict": true,
36
36
  "author": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/mocha": "^10.0.6",
42
- "@types/node": "^20.11.7",
42
+ "@types/node": "^22.15.17",
43
43
  "@typescript-eslint/eslint-plugin": "^6.19.1",
44
44
  "@typescript-eslint/parser": "^6.19.1",
45
45
  "dotenv": "^16.4.5",
@@ -51,14 +51,15 @@
51
51
  "eslint-plugin-promise": "^6.1.1",
52
52
  "mocha": "^10.2.0",
53
53
  "ts-node": "^10.9.2",
54
- "typedoc": "^0.25.7",
55
- "typescript": "^5.3.3"
54
+ "typedoc": "^0.28.4",
55
+ "typescript": "^5.8.3"
56
56
  },
57
57
  "dependencies": {
58
- "@gibme/cache": "^1.1.5",
59
- "@gibme/ssh": "^2.0.0",
58
+ "@gibme/cache": "^2.0.0",
59
+ "@gibme/ssh": "^3.0.1",
60
60
  "@types/jsbn": "^1.2.33",
61
- "ip-address": "^9.0.5",
62
- "semver": "^7.6.2"
61
+ "abort-controller": "^3.0.0",
62
+ "ip-address": "^10.0.1",
63
+ "semver": "^7.7.1"
63
64
  }
64
65
  }
package/dist/types.d.ts DELETED
@@ -1,246 +0,0 @@
1
- import type { AbortSignal } from 'abort-controller';
2
- export declare namespace BandwidthTest {
3
- export type Direction = 'both' | 'transmit' | 'receive';
4
- export type Protocol = 'udp' | 'tcp';
5
- export type Status = 'running' | 'connecting' | 'done testing' | 'authentication_failed' | 'queued';
6
- /**
7
- * Class that helps with processing a "frame" of the Bandwidth Test response
8
- */
9
- export class Frame {
10
- readonly buffer: Buffer;
11
- private parsed?;
12
- constructor(buffer: Buffer);
13
- parse(): Record<string, string>;
14
- }
15
- interface DirectionStats {
16
- current: number;
17
- shortAverage: number;
18
- totalAverage: number;
19
- size: number;
20
- }
21
- export interface Update {
22
- status: Status;
23
- duration: number;
24
- transmit?: DirectionStats;
25
- receive?: DirectionStats;
26
- lostPackets?: number;
27
- randomData: boolean;
28
- direction: Direction;
29
- connectionCount: number;
30
- localCPULoad: number;
31
- remoteCPULoad: number;
32
- }
33
- export interface Options {
34
- duration: number;
35
- direction: Direction;
36
- protocol: Protocol;
37
- random_data: boolean;
38
- callback: (frame: Update) => void;
39
- timeout: number;
40
- signal: AbortSignal;
41
- /**
42
- * In Megabits
43
- */
44
- local_tx_speed: number;
45
- /**
46
- * In Megabits
47
- */
48
- remote_tx_speed: number;
49
- }
50
- export {};
51
- }
52
- export declare namespace CommandResponses {
53
- type YesNo = 'yes' | 'no';
54
- interface Comment {
55
- comment?: string;
56
- }
57
- interface Route extends Comment {
58
- 'dst-address': string;
59
- gateway: string;
60
- distance: string;
61
- scope: string;
62
- target_scope: string;
63
- 'routing-table'?: string;
64
- 'routing-mark'?: string;
65
- 'bgp-as-path'?: string;
66
- 'bgp-origin'?: string;
67
- 'bgp-local-pref'?: string;
68
- 'received-from'?: string;
69
- 'check-gateway'?: string;
70
- 'suppress-hw-offload'?: string;
71
- 'blackhole'?: string;
72
- 'immediate-gw'?: string;
73
- reachable?: string;
74
- 'gateway-status'?: string;
75
- }
76
- interface Address extends Comment {
77
- address: string;
78
- network: string;
79
- interface: string;
80
- 'actual-interface': string;
81
- }
82
- interface Interface extends Comment {
83
- name: string;
84
- type: string;
85
- mtu: string;
86
- 'default-name'?: string;
87
- 'actual-mtu': string;
88
- 'mac-address'?: string;
89
- 'link-downs'?: string;
90
- l2mtu?: string;
91
- }
92
- interface TunnelInterface extends Omit<Interface, 'type'>, Comment {
93
- 'local-address': string;
94
- 'remote-address': string;
95
- 'clamp-tcp-mss': YesNo;
96
- 'dont-fragment': YesNo;
97
- 'allow-fast-path': YesNo;
98
- }
99
- interface Routeboard {
100
- routerboard: YesNo;
101
- 'board-name': string;
102
- model: string;
103
- 'serial-number': string;
104
- 'firmware-type': string;
105
- 'factory-firmware': string;
106
- 'current-firmware': string;
107
- 'upgrade-firmware': string;
108
- }
109
- interface Identity {
110
- name: string;
111
- }
112
- interface Resource {
113
- uptime: string;
114
- version: string;
115
- 'build-time': string;
116
- 'factory-software': string;
117
- 'free-memory': string;
118
- 'total-memory': string;
119
- cpu: string;
120
- 'cpu-count': string;
121
- 'cpu-frequency': string;
122
- 'cpu-load': string;
123
- 'free-hdd-space': string;
124
- 'total-hdd-space': string;
125
- 'architecture-name': string;
126
- 'board-name': string;
127
- platform: string;
128
- 'write-sect-since-reboot'?: string;
129
- 'write-sect-total'?: string;
130
- 'bad-blocks'?: string;
131
- }
132
- interface Health {
133
- voltage: string;
134
- current: string;
135
- temperature: string;
136
- 'power-consumption': string;
137
- 'psu-voltage'?: string;
138
- 'psu1-voltage'?: string;
139
- 'psu2-voltage'?: string;
140
- }
141
- }
142
- export declare namespace Response {
143
- interface includesAddress {
144
- includes(ipaddress: string): boolean;
145
- }
146
- interface Comment {
147
- comment?: string;
148
- }
149
- export interface Address extends includesAddress, Comment {
150
- ipaddress: string;
151
- network: string;
152
- cidr: number;
153
- iface: string;
154
- }
155
- export interface Interface extends Comment {
156
- name: string;
157
- type: string;
158
- local_address?: string;
159
- remote_address?: string;
160
- }
161
- export interface Tunnel extends Interface {
162
- parent: Address;
163
- }
164
- export interface Route extends includesAddress, Comment {
165
- network: string;
166
- cidr: number;
167
- distance: number;
168
- scope: number;
169
- vrf: string;
170
- preferred_source?: string;
171
- gateway?: string;
172
- iface?: string;
173
- tunnel?: Tunnel;
174
- target_scope?: number;
175
- }
176
- export interface RouteCount {
177
- interface: string;
178
- count: number;
179
- active: boolean;
180
- }
181
- export interface Ping {
182
- target: string;
183
- latency: number;
184
- source?: string;
185
- }
186
- export interface Traceroute {
187
- hop: number;
188
- loss: number;
189
- sent: number;
190
- last: number;
191
- average: number;
192
- best: number;
193
- worst: number;
194
- timeout: boolean;
195
- address?: string;
196
- hostname?: string;
197
- }
198
- export interface Routerboard {
199
- routerboard: boolean;
200
- board_name: string;
201
- model: string;
202
- serial_number: string;
203
- firmware_type: string;
204
- factory_firmware: string;
205
- current_firmware: string;
206
- upgrade_firmware: string;
207
- }
208
- export interface Resource {
209
- uptime: string;
210
- version: string;
211
- build_time: Date;
212
- factory_sofware: string;
213
- free_memory: string;
214
- total_memory: string;
215
- cpu: string;
216
- cpu_count: number;
217
- cpu_frequency: number;
218
- cpu_load: number;
219
- hdd_space: {
220
- free: string;
221
- total: string;
222
- };
223
- architecture_name: string;
224
- board_name: string;
225
- platform: string;
226
- lts?: boolean;
227
- stable?: boolean;
228
- testing?: boolean;
229
- development?: boolean;
230
- nvram?: {
231
- write_since_reboot: number;
232
- write_total: number;
233
- bad_blocks: number;
234
- };
235
- }
236
- export interface Health {
237
- voltage: number;
238
- current: number;
239
- temperature: number;
240
- power_consumption: number;
241
- psu_voltage?: number;
242
- psu1_voltage?: number;
243
- psu2_voltage?: number;
244
- }
245
- export {};
246
- }
package/dist/types.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- // Copyright (c) 2024, Brandon Lehmann <brandonlehmann@gmail.com>
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal
6
- // in the Software without restriction, including without limitation the rights
7
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- // copies of the Software, and to permit persons to whom the Software is
9
- // furnished to do so, subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in all
12
- // copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- // SOFTWARE.
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.BandwidthTest = void 0;
23
- var BandwidthTest;
24
- (function (BandwidthTest) {
25
- /**
26
- * Class that helps with processing a "frame" of the Bandwidth Test response
27
- */
28
- class Frame {
29
- // eslint-disable-next-line no-useless-constructor
30
- constructor(buffer) {
31
- this.buffer = buffer;
32
- }
33
- parse() {
34
- if (!this.parsed) {
35
- this.parsed = {};
36
- const records = this.buffer.toString('utf8').trim()
37
- .split('\n')
38
- .map(line => line.trim())
39
- .map(line => line.split(':', 2)
40
- .map(elem => elem.trim()));
41
- for (const [key, value] of records) {
42
- if (key.length === 0)
43
- continue;
44
- this.parsed[key.toLowerCase()] = value;
45
- }
46
- }
47
- return this.parsed;
48
- }
49
- }
50
- BandwidthTest.Frame = Frame;
51
- })(BandwidthTest || (exports.BandwidthTest = BandwidthTest = {}));