3xui-api-client 1.0.0 โ 2.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/CHANGELOG.md +73 -3
- package/README.md +19 -150
- package/index.d.ts +415 -108
- package/index.js +472 -32
- package/package.json +24 -9
- package/src/builders/ProtocolBuilders.js +686 -0
- package/src/generators/CredentialGenerator.js +362 -0
- package/src/middleware/WebMiddleware.js +311 -0
- package/src/security/SecurityEnhancer.js +1 -0
- package/src/session/SessionManager.js +493 -0
- package/SECURITY.md +0 -150
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,76 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.0] - 2025-06-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- ๐ฏ **Built-in Credential Generation System** - Automatic generation of random passwords, UUIDs, and client identifiers
|
|
12
|
+
- ๐ง **Advanced Session Management** - Intelligent session caching, automatic renewal, and multi-server support
|
|
13
|
+
- ๐ **Web Integration Support** - Express.js and Next.js middleware for seamless web app integration
|
|
14
|
+
- ๐ก๏ธ **Enhanced Security Framework** - Input validation, security monitoring, and secure headers management
|
|
15
|
+
- ๐ฆ **Modular Architecture** - New `src/` directory structure with specialized modules:
|
|
16
|
+
- `CredentialGenerator.js` - Random credential generation utilities
|
|
17
|
+
- `SessionManager.js` - Advanced session handling and caching
|
|
18
|
+
- `WebMiddleware.js` - Express/Next.js integration helpers
|
|
19
|
+
- `ProtocolBuilders.js` - Automated inbound configuration builders
|
|
20
|
+
- `SecurityEnhancer.js` - Security validation and monitoring
|
|
21
|
+
|
|
22
|
+
### Enhanced
|
|
23
|
+
- ๐ **Improved Authentication** - More robust session handling with automatic recovery
|
|
24
|
+
- ๐ **Better Error Handling** - Enhanced error messages and recovery mechanisms
|
|
25
|
+
- ๐จ **Developer Experience** - Improved TypeScript definitions and code documentation
|
|
26
|
+
- ๐งช **Testing Framework** - Updated test suite with better coverage and reliability
|
|
27
|
+
- ๐ **Documentation** - Comprehensive wiki updates with practical examples
|
|
28
|
+
|
|
29
|
+
### New Features
|
|
30
|
+
- **Credential Generation**:
|
|
31
|
+
- Random password generation with customizable complexity
|
|
32
|
+
- UUID v4 generation for unique client identifiers
|
|
33
|
+
- Secure random string generation for API keys
|
|
34
|
+
- Email-like identifier generation for client management
|
|
35
|
+
|
|
36
|
+
- **Session Management**:
|
|
37
|
+
- Intelligent session caching with TTL support
|
|
38
|
+
- Multi-server session handling
|
|
39
|
+
- Automatic session renewal and cleanup
|
|
40
|
+
- Database-ready session storage format
|
|
41
|
+
|
|
42
|
+
- **Web Integration**:
|
|
43
|
+
- Express.js middleware for route protection
|
|
44
|
+
- Next.js API route helpers
|
|
45
|
+
- Automatic cookie management
|
|
46
|
+
- Request/response transformation utilities
|
|
47
|
+
|
|
48
|
+
- **Protocol Builders**:
|
|
49
|
+
- Automated VLESS configuration generation
|
|
50
|
+
- VMess protocol setup helpers
|
|
51
|
+
- Trojan and Shadowsocks builders
|
|
52
|
+
- Reality and WireGuard configuration support
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
- **Breaking Change**: Enhanced API structure with new module organization
|
|
56
|
+
- **Package Structure**: Moved from monolithic to modular architecture
|
|
57
|
+
- **Dependencies**: Updated to latest stable versions
|
|
58
|
+
- **Configuration**: Improved configuration options and defaults
|
|
59
|
+
|
|
60
|
+
### Security
|
|
61
|
+
- Enhanced input validation and sanitization
|
|
62
|
+
- Improved session security with automatic cleanup
|
|
63
|
+
- Better error handling to prevent information leakage
|
|
64
|
+
- Security monitoring and alerting capabilities
|
|
65
|
+
|
|
66
|
+
### Developer Experience
|
|
67
|
+
- Better TypeScript support with comprehensive type definitions
|
|
68
|
+
- Improved documentation with real-world examples
|
|
69
|
+
- Enhanced testing framework with automated validation
|
|
70
|
+
- ESLint configuration for code quality
|
|
71
|
+
|
|
72
|
+
### Performance
|
|
73
|
+
- Optimized session management with intelligent caching
|
|
74
|
+
- Reduced API call overhead through better request batching
|
|
75
|
+
- Improved memory usage with automatic cleanup
|
|
76
|
+
- Faster authentication flow with session reuse
|
|
77
|
+
|
|
8
78
|
## [1.0.0] - 2025-06-20
|
|
9
79
|
|
|
10
80
|
### Added
|
|
@@ -43,6 +113,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
43
113
|
### Planned
|
|
44
114
|
- GitHub Actions CI/CD pipeline
|
|
45
115
|
- Automated semantic releases
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
116
|
+
- Enhanced unit test coverage
|
|
117
|
+
- Performance benchmarking tools
|
|
118
|
+
- Advanced monitoring and analytics
|
package/README.md
CHANGED
|
@@ -20,6 +20,12 @@ A Node.js client library for 3x-ui panel API that provides easy-to-use methods f
|
|
|
20
20
|
npm install 3xui-api-client
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## Context7 MCP Integration
|
|
24
|
+
|
|
25
|
+
This library can be implemented with the help of [Context7 MCP](https://context7.com/iamhelitha/3xui-api-client). Use the package name `3xui-api-client` to get context and documentation through Context7's Model Context Protocol integration.
|
|
26
|
+
|
|
27
|
+
Learn more about [Context7 MCP](https://context7.com) for enhanced development experience.
|
|
28
|
+
|
|
23
29
|
## Quick Start
|
|
24
30
|
|
|
25
31
|
```javascript
|
|
@@ -153,7 +159,7 @@ const clientConfig = {
|
|
|
153
159
|
settings: JSON.stringify({
|
|
154
160
|
clients: [{
|
|
155
161
|
id: "client-uuid-here",
|
|
156
|
-
email: "
|
|
162
|
+
email: "user23c5n7",
|
|
157
163
|
limitIp: 0,
|
|
158
164
|
totalGB: 0,
|
|
159
165
|
expiryTime: 0,
|
|
@@ -184,7 +190,7 @@ const result = await client.deleteClient(inboundId, clientUUID);
|
|
|
184
190
|
|
|
185
191
|
#### Get Client Traffic by Email
|
|
186
192
|
```javascript
|
|
187
|
-
const traffic = await client.getClientTrafficsByEmail("
|
|
193
|
+
const traffic = await client.getClientTrafficsByEmail("user23c5n7");
|
|
188
194
|
console.log('Client traffic:', traffic);
|
|
189
195
|
```
|
|
190
196
|
|
|
@@ -197,17 +203,17 @@ console.log('Client traffic:', traffic);
|
|
|
197
203
|
#### Manage Client IPs
|
|
198
204
|
```javascript
|
|
199
205
|
// Get client IPs
|
|
200
|
-
const ips = await client.getClientIps("
|
|
206
|
+
const ips = await client.getClientIps("user23c5n7");
|
|
201
207
|
|
|
202
208
|
// Clear client IPs
|
|
203
|
-
const result = await client.clearClientIps("
|
|
209
|
+
const result = await client.clearClientIps("user23c5n7");
|
|
204
210
|
```
|
|
205
211
|
|
|
206
212
|
### Traffic Management (โ
Tested & Working)
|
|
207
213
|
|
|
208
214
|
#### Reset Individual Client Traffic
|
|
209
215
|
```javascript
|
|
210
|
-
const result = await client.resetClientTraffic(inboundId, "
|
|
216
|
+
const result = await client.resetClientTraffic(inboundId, "user23c5n7");
|
|
211
217
|
```
|
|
212
218
|
|
|
213
219
|
#### Reset All Traffic (Global)
|
|
@@ -239,151 +245,16 @@ const result = await client.createBackup();
|
|
|
239
245
|
console.log('Backup created:', result);
|
|
240
246
|
```
|
|
241
247
|
|
|
242
|
-
##
|
|
243
|
-
|
|
244
|
-
### VPN Service Provider
|
|
245
|
-
```javascript
|
|
246
|
-
const ThreeXUI = require('3xui-api-client');
|
|
247
|
-
|
|
248
|
-
class VPNServiceManager {
|
|
249
|
-
constructor() {
|
|
250
|
-
this.client = new ThreeXUI(process.env.XUI_URL, process.env.XUI_USER, process.env.XUI_PASS);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Create new customer account
|
|
254
|
-
async createCustomerAccount(email, dataLimitGB = 50) {
|
|
255
|
-
// 1. Get available inbound
|
|
256
|
-
const inbounds = await this.client.getInbounds();
|
|
257
|
-
const activeInbound = inbounds.obj.find(i => i.enable);
|
|
258
|
-
|
|
259
|
-
// 2. Add client to inbound
|
|
260
|
-
const clientConfig = {
|
|
261
|
-
id: activeInbound.id,
|
|
262
|
-
settings: JSON.stringify({
|
|
263
|
-
clients: [{
|
|
264
|
-
id: this.generateUUID(),
|
|
265
|
-
email: email,
|
|
266
|
-
limitIp: 2,
|
|
267
|
-
totalGB: dataLimitGB,
|
|
268
|
-
expiryTime: Date.now() + (30 * 24 * 60 * 60 * 1000), // 30 days
|
|
269
|
-
enable: true
|
|
270
|
-
}]
|
|
271
|
-
})
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
return await this.client.addClient(clientConfig);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Monthly billing cycle
|
|
278
|
-
async processBillingCycle() {
|
|
279
|
-
const inbounds = await this.client.getInbounds();
|
|
280
|
-
|
|
281
|
-
for (const inbound of inbounds.obj) {
|
|
282
|
-
if (inbound.clientStats) {
|
|
283
|
-
for (const client of inbound.clientStats) {
|
|
284
|
-
// Reset traffic for active subscriptions
|
|
285
|
-
await this.client.resetClientTraffic(inbound.id, client.email);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Monitor usage and send alerts
|
|
292
|
-
async monitorUsage() {
|
|
293
|
-
const onlineClients = await this.client.getOnlineClients();
|
|
294
|
-
|
|
295
|
-
for (const client of onlineClients.obj || []) {
|
|
296
|
-
const traffic = await this.client.getClientTrafficsByEmail(client.email);
|
|
297
|
-
|
|
298
|
-
if (traffic.obj && traffic.obj.total > (40 * 1024 * 1024 * 1024)) { // 40GB
|
|
299
|
-
console.log(`โ ๏ธ Client ${client.email} approaching data limit`);
|
|
300
|
-
// Send notification to customer
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Server Administration
|
|
308
|
-
```javascript
|
|
309
|
-
class ServerAdmin {
|
|
310
|
-
constructor() {
|
|
311
|
-
this.client = new ThreeXUI(process.env.XUI_URL, process.env.XUI_USER, process.env.XUI_PASS);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Daily maintenance
|
|
315
|
-
async dailyMaintenance() {
|
|
316
|
-
// 1. Create backup
|
|
317
|
-
await this.client.createBackup();
|
|
318
|
-
|
|
319
|
-
// 2. Clean up depleted clients
|
|
320
|
-
const inbounds = await this.client.getInbounds();
|
|
321
|
-
for (const inbound of inbounds.obj) {
|
|
322
|
-
await this.client.deleteDepletedClients(inbound.id);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// 3. Generate usage report
|
|
326
|
-
const report = await this.generateUsageReport();
|
|
327
|
-
console.log('Daily Report:', report);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Setup new VPN server
|
|
331
|
-
async setupNewServer(port, protocol = 'vless') {
|
|
332
|
-
const serverConfig = {
|
|
333
|
-
remark: `VPN-Server-${port}`,
|
|
334
|
-
port: port,
|
|
335
|
-
protocol: protocol,
|
|
336
|
-
settings: {
|
|
337
|
-
clients: [],
|
|
338
|
-
decryption: "none",
|
|
339
|
-
fallbacks: []
|
|
340
|
-
},
|
|
341
|
-
streamSettings: {
|
|
342
|
-
network: "tcp",
|
|
343
|
-
security: "reality",
|
|
344
|
-
realitySettings: {
|
|
345
|
-
dest: "google.com:443",
|
|
346
|
-
serverNames: ["google.com"]
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
return await this.client.addInbound(serverConfig);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Real-Time Monitoring Dashboard
|
|
357
|
-
```javascript
|
|
358
|
-
class MonitoringDashboard {
|
|
359
|
-
constructor() {
|
|
360
|
-
this.client = new ThreeXUI(process.env.XUI_URL, process.env.XUI_USER, process.env.XUI_PASS);
|
|
361
|
-
}
|
|
248
|
+
## Documentation
|
|
362
249
|
|
|
363
|
-
|
|
364
|
-
const [inbounds, onlineClients] = await Promise.all([
|
|
365
|
-
this.client.getInbounds(),
|
|
366
|
-
this.client.getOnlineClients()
|
|
367
|
-
]);
|
|
368
|
-
|
|
369
|
-
return {
|
|
370
|
-
totalInbounds: inbounds.obj.length,
|
|
371
|
-
activeInbounds: inbounds.obj.filter(i => i.enable).length,
|
|
372
|
-
totalClients: inbounds.obj.reduce((sum, i) => sum + (i.clientStats?.length || 0), 0),
|
|
373
|
-
onlineClients: onlineClients.obj?.length || 0,
|
|
374
|
-
totalTraffic: inbounds.obj.reduce((sum, i) => sum + i.total, 0)
|
|
375
|
-
};
|
|
376
|
-
}
|
|
250
|
+
For comprehensive guides, examples, and implementation patterns, visit our [Wiki](https://github.com/iamhelitha/3xui-api-client/wiki):
|
|
377
251
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
```
|
|
252
|
+
- ๐ [**Use Cases & Examples**](https://github.com/iamhelitha/3xui-api-client/wiki/Use-Cases) - VPN service provider, server administration, monitoring dashboards
|
|
253
|
+
- ๐ [**Authentication Guide**](https://github.com/iamhelitha/3xui-api-client/wiki/Authentication-Guide) - Secure login and session management
|
|
254
|
+
- ๐ [**Inbound Management**](https://github.com/iamhelitha/3xui-api-client/wiki/Inbound-Management) - Server configuration and setup
|
|
255
|
+
- ๐ฅ [**Client Management**](https://github.com/iamhelitha/3xui-api-client/wiki/Client-Management) - User account operations
|
|
256
|
+
- ๐ [**Traffic Management**](https://github.com/iamhelitha/3xui-api-client/wiki/Traffic-Management) - Usage monitoring and billing
|
|
257
|
+
- โ๏ธ [**System Operations**](https://github.com/iamhelitha/3xui-api-client/wiki/System-Operations) - Backup and maintenance
|
|
387
258
|
|
|
388
259
|
## Error Handling
|
|
389
260
|
|
|
@@ -425,9 +296,7 @@ npm run test:login
|
|
|
425
296
|
npm test
|
|
426
297
|
```
|
|
427
298
|
|
|
428
|
-
## Documentation
|
|
429
299
|
|
|
430
|
-
For detailed guides and examples, visit our [Wiki](https://github.com/iamhelitha/3xui-api-client/wiki).
|
|
431
300
|
|
|
432
301
|
## License
|
|
433
302
|
|