rosinterface 1.0.0 → 1.0.1
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/README.md +252 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# RosInterface
|
|
2
|
+
|
|
3
|
+
> **Enterprise-Grade MikroTik RouterOS API Client for Node.js**
|
|
4
|
+
> High-performance, **Offline-First** and **Type-Safe** framework for modern network automation.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/rosinterface)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## English Documentation
|
|
12
|
+
|
|
13
|
+
**RosInterface** is designed for **ISPs and mission-critical environments**.
|
|
14
|
+
It focuses on **connection stability**, **router hardware protection**, and **efficient data access**, even under unstable network conditions.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### ✨ Key Features
|
|
19
|
+
|
|
20
|
+
- **🛡️ Hardware Protection**
|
|
21
|
+
Built-in **Rate Limiter** with intelligent backoff to prevent RouterOS CPU saturation.
|
|
22
|
+
|
|
23
|
+
- **🔌 Offline-First Architecture**
|
|
24
|
+
Commands marked with `.persistent()` are automatically queued if the router is offline and synchronized once connectivity is restored.
|
|
25
|
+
|
|
26
|
+
- **🧠 Smart Caching**
|
|
27
|
+
Read operations are cached for **5 seconds (TTL)** to reduce redundant API calls and router load.
|
|
28
|
+
|
|
29
|
+
- **🔍 Source-Side Filtering**
|
|
30
|
+
Use `.findBy()` and `.findOne()` to filter data **directly on the router**, minimizing bandwidth and latency.
|
|
31
|
+
|
|
32
|
+
- **🌊 Fluent API**
|
|
33
|
+
Chainable, expressive syntax for clean and maintainable automation code.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### ✨ Important Considerations
|
|
41
|
+
|
|
42
|
+
#### 📄 Environment Variables (.env)
|
|
43
|
+
|
|
44
|
+
Create a `.env` file in the root directory of your project:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
MIKROTIK_HOST=ROUTER_IP
|
|
48
|
+
MIKROTIK_USER=admin
|
|
49
|
+
MIKROTIK_PASSWORD=your_password
|
|
50
|
+
MIKROTIK_PORT=8729
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> ⚠️ **Security Notice**
|
|
54
|
+
> The `allowInsecureConfig` flag is a **critical** security measure in RosInterface.
|
|
55
|
+
> Prevents accidental exposure of credentials or use of unencrypted protocols in production.
|
|
56
|
+
>
|
|
57
|
+
> Use **only in controlled, local or test environments**.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### 🛠 Usage Examples
|
|
63
|
+
|
|
64
|
+
#### 1️⃣ Basic Connection
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { MikrotikClient } from 'rosinterface';
|
|
68
|
+
|
|
69
|
+
const client = new MikrotikClient({
|
|
70
|
+
host: 'IP_DEL_ROUTER',
|
|
71
|
+
user: 'admin',
|
|
72
|
+
password: 'password',
|
|
73
|
+
useTLS: false, // ⚠️ Test only
|
|
74
|
+
rateLimit: 50,
|
|
75
|
+
allowInsecureConfig: true // ⚠️ Never in production or release
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await client.connect();
|
|
79
|
+
```
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
#### 2️⃣ Recommended connection (Production/Release)
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { MikrotikClient } from 'rosinterface';
|
|
88
|
+
import 'dotenv/config';
|
|
89
|
+
|
|
90
|
+
const client = new MikrotikClient({
|
|
91
|
+
host: process.env.MIKROTIK_HOST,
|
|
92
|
+
user: process.env.MIKROTIK_USER,
|
|
93
|
+
password: process.env.MIKROTIK_PASSWORD,
|
|
94
|
+
port: Number(process.env.MIKROTIK_PORT) || 8729,
|
|
95
|
+
useTLS: true,
|
|
96
|
+
rateLimit: 50
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await client.connect();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
#### 2️⃣ Optimized Read (select + findOne)
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const user = await client.command('/ppp/secret')
|
|
110
|
+
.select(['name', 'profile', 'last-logged-out'])
|
|
111
|
+
.findOne({ name: 'john_doe' });
|
|
112
|
+
|
|
113
|
+
console.log(`User: ${user?.name}, Profile: ${user?.profile}`);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
#### 3️⃣ Resilience with Persistence (Offline-Safe)
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const result = await client.command('/ppp/secret')
|
|
122
|
+
.persistent()
|
|
123
|
+
.add({
|
|
124
|
+
name: 'new_user',
|
|
125
|
+
password: 'securePassword123',
|
|
126
|
+
profile: 'default'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (result === 'QUEUED_OFFLINE') {
|
|
130
|
+
console.log('Router unreachable. Task stored and will sync automatically.');
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 📕 Documentación en Español
|
|
137
|
+
|
|
138
|
+
**RosInterface** está diseñado para **ISPs y entornos críticos**.
|
|
139
|
+
Su objetivo es garantizar **estabilidad de conexión**, **protección del hardware MikroTik** y **consultas eficientes**, incluso con enlaces inestables.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### ✨ Características Principales
|
|
144
|
+
|
|
145
|
+
- **🛡️ Protección del Hardware**
|
|
146
|
+
Limitador de tasa integrado con retroceso inteligente para evitar saturación de CPU.
|
|
147
|
+
|
|
148
|
+
- **🔌 Arquitectura Offline-First**
|
|
149
|
+
Los comandos con `.persistent()` se guardan en cola si el router no está disponible y se ejecutan automáticamente al reconectar.
|
|
150
|
+
|
|
151
|
+
- **🧠 Caché Inteligente**
|
|
152
|
+
Consultas con TTL de **5 segundos**, reduciendo llamadas innecesarias.
|
|
153
|
+
|
|
154
|
+
- **🔍 Filtrado en Origen**
|
|
155
|
+
`.findBy()` y `.findOne()` filtran directamente en RouterOS sin descargar tablas completas.
|
|
156
|
+
|
|
157
|
+
- **🌊 API Fluida**
|
|
158
|
+
Sintaxis encadenable y clara.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### ✨ Consideraciones Importantes
|
|
163
|
+
|
|
164
|
+
#### 📄 Variables de Entorno (.env)
|
|
165
|
+
|
|
166
|
+
Crea un archivo `.env` en el directorio raíz de tu proyecto:
|
|
167
|
+
|
|
168
|
+
```text
|
|
169
|
+
MIKROTIK_HOST=IP_DEL_ROUTER
|
|
170
|
+
MIKROTIK_USER=admin
|
|
171
|
+
MIKROTIK_PASSWORD=tu_contraseña
|
|
172
|
+
MIKROTIK_PORT=8729
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
> ⚠️ **Aviso de Seguridad**
|
|
176
|
+
> La bandera `allowInsecureConfig` es una medida de seguridad **crítica** en RosInterface.
|
|
177
|
+
> Previene la exposición accidental de credenciales o el uso de protocolos no cifrados en producción.
|
|
178
|
+
>
|
|
179
|
+
> Úsala **solo en entornos controlados, locales o de prueba**.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### 🛠 Ejemplos de Uso
|
|
184
|
+
|
|
185
|
+
#### 1️⃣ Conexión rápida (solo pruebas)
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { MikrotikClient } from 'rosinterface';
|
|
189
|
+
|
|
190
|
+
const client = new MikrotikClient({
|
|
191
|
+
host: 'IP_DEL_ROUTER',
|
|
192
|
+
user: 'admin',
|
|
193
|
+
password: 'password',
|
|
194
|
+
useTLS: false, // ⚠️ Solo pruebas
|
|
195
|
+
rateLimit: 50,
|
|
196
|
+
allowInsecureConfig: true // ⚠️ Nunca en producción
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
await client.connect();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
#### 2️⃣ Conexión Recomendada (Producción)
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { MikrotikClient } from 'rosinterface';
|
|
208
|
+
import 'dotenv/config';
|
|
209
|
+
|
|
210
|
+
const client = new MikrotikClient({
|
|
211
|
+
host: process.env.MIKROTIK_HOST,
|
|
212
|
+
user: process.env.MIKROTIK_USER,
|
|
213
|
+
password: process.env.MIKROTIK_PASSWORD,
|
|
214
|
+
port: Number(process.env.MIKROTIK_PORT) || 8729,
|
|
215
|
+
useTLS: true,
|
|
216
|
+
rateLimit: 50
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
await client.connect();
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
#### 3️⃣ Lectura Optimizada
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
const user = await client.command('/ppp/secret')
|
|
228
|
+
.select(['name', 'profile', 'last-logged-out'])
|
|
229
|
+
.findOne({ name: 'john_doe' });
|
|
230
|
+
|
|
231
|
+
console.log(`User: ${user?.name}, Profile: ${user?.profile}`);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
#### 4️⃣ Persistencia Offline
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
const result = await client.command('/ppp/secret')
|
|
240
|
+
.persistent()
|
|
241
|
+
.add({
|
|
242
|
+
name: 'new_user',
|
|
243
|
+
password: 'securePassword123',
|
|
244
|
+
profile: 'default'
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (result === 'QUEUED_OFFLINE') {
|
|
248
|
+
console.log('Router unreachable. Task stored and will sync automatically.');
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rosinterface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "High-performance, Offline-First Mikrotik RouterOS API Client for Enterprise.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"author": "
|
|
7
|
+
"author": "McBlockier",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"mikrotik",
|
|
@@ -39,4 +39,4 @@
|
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=14.0.0"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|