3xui-api-client 1.0.0 → 2.1.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/index.d.ts CHANGED
@@ -1,8 +1,28 @@
1
+ // Type definitions for 3xui-api-client v2.0.0
2
+
1
3
  declare module '3xui-api-client' {
2
- export interface ThreeXUIResponse<T = any> {
4
+ import { AxiosInstance } from 'axios';
5
+
6
+ // ===========================================
7
+ // CORE INTERFACES
8
+ // ===========================================
9
+
10
+ export interface ThreeXUIOptions {
11
+ sessionManager?: SessionManager | SessionConfig;
12
+ autoGenerateCredentials?: boolean;
13
+ timeout?: number;
14
+ maxRequestsPerMinute?: number;
15
+ maxLoginAttemptsPerHour?: number;
16
+ isDevelopment?: boolean;
17
+ enableCSP?: boolean;
18
+ userAgent?: string;
19
+ }
20
+
21
+ export interface LoginResponse {
3
22
  success: boolean;
4
- msg: string;
5
- obj: T | null;
23
+ fromCache?: boolean;
24
+ headers?: any;
25
+ data: any;
6
26
  }
7
27
 
8
28
  export interface InboundConfig {
@@ -11,8 +31,8 @@ declare module '3xui-api-client' {
11
31
  protocol: string;
12
32
  settings: any;
13
33
  streamSettings?: any;
14
- sniffing?: any;
15
- allocate?: any;
34
+ listen?: string;
35
+ enable?: boolean;
16
36
  }
17
37
 
18
38
  export interface ClientConfig {
@@ -20,90 +40,398 @@ declare module '3xui-api-client' {
20
40
  settings: string;
21
41
  }
22
42
 
23
- export interface ClientData {
24
- id: string;
25
- email: string;
43
+ // ===========================================
44
+ // CREDENTIAL GENERATION INTERFACES
45
+ // ===========================================
46
+
47
+ export interface CredentialOptions {
48
+ email?: string;
49
+ passwordLength?: number;
50
+ level?: number;
51
+ alterId?: number;
52
+ flow?: string;
53
+ method?: string;
54
+ username?: string;
26
55
  limitIp?: number;
27
56
  totalGB?: number;
28
57
  expiryTime?: number;
29
58
  enable?: boolean;
30
- tgId?: string;
31
59
  subId?: string;
60
+ allowedIPs?: string[];
61
+ keepAlive?: number;
32
62
  }
33
63
 
34
- export interface InboundData {
35
- id: number;
36
- up: number;
37
- down: number;
38
- total: number;
39
- remark: string;
40
- enable: boolean;
41
- expiryTime: number;
42
- clientStats: ClientTrafficData[] | null;
43
- listen: string;
44
- port: number;
45
- protocol: string;
46
- settings: string;
47
- streamSettings: string;
48
- tag: string;
49
- sniffing: string;
50
- allocate: string;
64
+ export interface VLESSCredentials {
65
+ id: string;
66
+ email: string;
67
+ flow: string;
68
+ encryption: string;
51
69
  }
52
70
 
53
- export interface ClientTrafficData {
54
- id: number;
55
- inboundId: number;
56
- enable: boolean;
71
+ export interface VMESSCredentials {
72
+ id: string;
57
73
  email: string;
58
- up: number;
59
- down: number;
60
- expiryTime: number;
61
- total: number;
62
- reset: number;
74
+ level: number;
75
+ alterId: number;
63
76
  }
64
77
 
65
- export interface OnlineClientData {
78
+ export interface TrojanCredentials {
79
+ password: string;
66
80
  email: string;
67
- ip: string;
68
- connectedAt: string;
81
+ level: number;
69
82
  }
70
83
 
71
- export interface LoginResponse {
72
- success: boolean;
73
- headers: any;
74
- data: any;
84
+ export interface ShadowsocksCredentials {
85
+ method: string;
86
+ password: string;
87
+ email: string;
75
88
  }
76
89
 
90
+ export interface WireGuardCredentials {
91
+ privateKey: string;
92
+ publicKey: string;
93
+ allowedIPs: string[];
94
+ keepAlive: number;
95
+ }
96
+
97
+ export interface SocksCredentials {
98
+ user: string;
99
+ pass: string;
100
+ email: string;
101
+ }
102
+
103
+ export interface ValidationResult {
104
+ valid: boolean;
105
+ errors: string[];
106
+ }
107
+
108
+ export interface WireGuardKeys {
109
+ privateKey: string;
110
+ publicKey: string;
111
+ generateClientConfig: (allowedIPs?: string[]) => any;
112
+ }
113
+
114
+ export interface RealityKeys {
115
+ privateKey: string;
116
+ publicKey: string;
117
+ generateRealityConfig: (dest?: string, serverNames?: string[]) => any;
118
+ }
119
+
120
+ // ===========================================
121
+ // SESSION MANAGEMENT INTERFACES
122
+ // ===========================================
123
+
124
+ export interface SessionConfig {
125
+ sessionTTL?: number;
126
+ autoRefresh?: boolean;
127
+ refreshThreshold?: number;
128
+ store?: SessionStore;
129
+ redis?: any;
130
+ redisOptions?: any;
131
+ database?: any;
132
+ databaseOptions?: any;
133
+ customHandler?: any;
134
+ }
135
+
136
+ export interface SessionStore {
137
+ get(key: string): Promise<any>;
138
+ set(key: string, value: any, ttl?: number): Promise<void>;
139
+ delete(key: string): Promise<void>;
140
+ clear(): Promise<void>;
141
+ exists(key: string): Promise<boolean>;
142
+ }
143
+
144
+ export interface SessionManager {
145
+ generateSessionKey(baseURL: string, username: string): string;
146
+ storeSession(baseURL: string, username: string, sessionData: any): Promise<string>;
147
+ getSession(baseURL: string, username: string): Promise<any>;
148
+ hasValidSession(baseURL: string, username: string): Promise<boolean>;
149
+ shouldRefreshSession(session: any): boolean;
150
+ deleteSession(baseURL: string, username: string): Promise<void>;
151
+ clearAllSessions(): Promise<void>;
152
+ getStats(): Promise<any>;
153
+ }
154
+
155
+ // ===========================================
156
+ // WEB MIDDLEWARE INTERFACES
157
+ // ===========================================
158
+
159
+ export interface ExpressMiddlewareConfig {
160
+ baseURL: string;
161
+ username: string;
162
+ password: string;
163
+ sessionManager?: SessionManager;
164
+ sessionKey?: string;
165
+ }
166
+
167
+ export interface NextJSConfig {
168
+ baseURL: string;
169
+ username: string;
170
+ password: string;
171
+ sessionManager?: SessionManager;
172
+ }
173
+
174
+ export interface ReactHookMethods {
175
+ generateCredentials(protocol: string, options?: CredentialOptions): Promise<any>;
176
+ addClientWithCredentials(inboundId: number, protocol: string, options?: CredentialOptions): Promise<any>;
177
+ getInbounds(): Promise<any[]>;
178
+ getClientTraffic(email: string): Promise<any>;
179
+ }
180
+
181
+ // ===========================================
182
+ // PROTOCOL BUILDER INTERFACES
183
+ // ===========================================
184
+
185
+ export interface BuilderConfig {
186
+ protocol: string;
187
+ settings: any;
188
+ streamSettings?: any;
189
+ remark?: string;
190
+ port?: number;
191
+ listen?: string;
192
+ enable?: boolean;
193
+ }
194
+
195
+ export interface TLSOptions {
196
+ serverName?: string;
197
+ certificates?: any[];
198
+ certFile?: string;
199
+ keyFile?: string;
200
+ }
201
+
202
+ export interface RealityOptions {
203
+ keys?: RealityKeys;
204
+ dest?: string;
205
+ serverNames?: string[];
206
+ shortIds?: string[];
207
+ }
208
+
209
+ export interface WebSocketOptions {
210
+ path?: string;
211
+ headers?: Record<string, string>;
212
+ }
213
+
214
+ export interface HTTP2Options {
215
+ path?: string;
216
+ host?: string[];
217
+ }
218
+
219
+ export interface GRPCOptions {
220
+ serviceName?: string;
221
+ }
222
+
223
+ // ===========================================
224
+ // MAIN CLASS
225
+ // ===========================================
226
+
77
227
  export default class ThreeXUI {
78
- constructor(baseURL: string, username: string, password: string);
228
+ constructor(baseURL: string, username: string, password: string, options?: ThreeXUIOptions);
79
229
 
80
230
  // Authentication
81
- login(): Promise<LoginResponse>;
82
-
83
- // Inbound Management
84
- getInbounds(): Promise<ThreeXUIResponse<InboundData[]>>;
85
- getInbound(id: number): Promise<ThreeXUIResponse<InboundData>>;
86
- addInbound(inboundConfig: InboundConfig): Promise<ThreeXUIResponse<any>>;
87
- updateInbound(id: number, inboundConfig: Partial<InboundConfig>): Promise<ThreeXUIResponse<any>>;
88
- deleteInbound(id: number): Promise<ThreeXUIResponse<number>>;
89
-
90
- // Client Management
91
- addClient(clientConfig: ClientConfig): Promise<ThreeXUIResponse<null>>;
92
- updateClient(clientId: string, clientConfig: ClientConfig): Promise<ThreeXUIResponse<null>>;
93
- deleteClient(inboundId: number, clientId: string): Promise<ThreeXUIResponse<null>>;
94
- getClientTrafficsByEmail(email: string): Promise<ThreeXUIResponse<ClientTrafficData>>;
95
- getClientTrafficsById(id: string): Promise<ThreeXUIResponse<ClientTrafficData[]>>;
96
- getClientIps(email: string): Promise<ThreeXUIResponse<string>>;
97
- clearClientIps(email: string): Promise<ThreeXUIResponse<null>>;
98
-
99
- // Traffic Management
100
- resetClientTraffic(inboundId: number, email: string): Promise<ThreeXUIResponse<null>>;
101
- resetAllTraffics(): Promise<ThreeXUIResponse<null>>;
102
- resetAllClientTraffics(inboundId: number): Promise<ThreeXUIResponse<null>>;
103
- deleteDepletedClients(inboundId: number): Promise<ThreeXUIResponse<null>>;
231
+ login(forceRefresh?: boolean): Promise<LoginResponse>;
232
+ logout(): Promise<void>;
233
+
234
+ // Credential Generation Methods
235
+ generateCredentials(protocol: string, options?: CredentialOptions): VLESSCredentials | VMESSCredentials | TrojanCredentials | ShadowsocksCredentials | WireGuardCredentials | SocksCredentials;
236
+ generateUUID(secure?: boolean): string;
237
+ generatePassword(length?: number, options?: any): string;
238
+ generateBulkCredentials(protocol: string, count: number, options?: CredentialOptions): any[];
239
+ getShadowsocksCiphers(): string[];
240
+ getRecommendedShadowsocksCipher(): string;
241
+ generateWireGuardKeys(): WireGuardKeys;
242
+ generateRealityKeys(): RealityKeys;
243
+ generatePort(min?: number, max?: number): number;
244
+ validateCredentials(credentials: any, protocol: string): ValidationResult;
104
245
 
105
- // System Operations
106
- getOnlineClients(): Promise<ThreeXUIResponse<OnlineClientData[]>>;
107
- createBackup(): Promise<ThreeXUIResponse<string>>;
246
+ // Security helpers
247
+ getSecurityStats(): any;
248
+ clearBlockedIPs(): void;
249
+ validateCredentialStrength(credential: string, type: 'password' | 'uuid' | 'port'): { isValid: boolean; issues: string[]; strength: 'weak' | 'medium' | 'strong' };
250
+ generateSecureToken(): string;
251
+ setDevelopmentMode(enabled: boolean): void;
252
+
253
+ // Enhanced Client Management
254
+ addClientWithCredentials(inboundId: number, protocol: string, options?: CredentialOptions): Promise<any>;
255
+ updateClientWithCredentials(clientId: string, inboundId: number, options?: CredentialOptions): Promise<any>;
256
+
257
+ // Session Management
258
+ getSessionStats(): Promise<any>;
259
+ clearAllSessions(): Promise<void>;
260
+ isSessionValid(): Promise<boolean>;
261
+
262
+ // Original API Methods
263
+ getInbounds(): Promise<any>;
264
+ getInbound(id: number): Promise<any>;
265
+ addInbound(inboundConfig: InboundConfig): Promise<any>;
266
+ deleteInbound(id: number): Promise<any>;
267
+ updateInbound(id: number, inboundConfig: InboundConfig): Promise<any>;
268
+ addClient(clientConfig: ClientConfig): Promise<any>;
269
+ deleteClient(inboundId: number, clientId: string): Promise<any>;
270
+ updateClient(clientId: string, clientConfig: ClientConfig): Promise<any>;
271
+ getClientTrafficsByEmail(email: string): Promise<any>;
272
+ getClientTrafficsById(id: number): Promise<any>;
273
+ getClientIps(email: string): Promise<any>;
274
+ clearClientIps(email: string): Promise<any>;
275
+ resetClientTraffic(inboundId: number, email: string): Promise<any>;
276
+ resetAllTraffics(): Promise<any>;
277
+ resetAllClientTraffics(inboundId: number): Promise<any>;
278
+ deleteDepletedClients(inboundId: number): Promise<any>;
279
+ getOnlineClients(): Promise<any>;
280
+ createBackup(): Promise<any>;
281
+
282
+ // Static exports
283
+ static CredentialGenerator: typeof CredentialGenerator;
284
+ static SessionManager: typeof SessionManager;
285
+ static createSessionManager: (options?: SessionConfig) => SessionManager;
286
+ }
287
+
288
+ // ===========================================
289
+ // CREDENTIAL GENERATOR CLASS
290
+ // ===========================================
291
+
292
+ export class CredentialGenerator {
293
+ static generateUUID(): string;
294
+ static generateSecureUUID(): string;
295
+ static generatePassword(length?: number, options?: any): string;
296
+ static generateShadowsocks2022PSK(method?: string): string;
297
+ static generateWireGuardKeys(): WireGuardKeys;
298
+ static generateRealityKeys(): RealityKeys;
299
+ static generateUsername(prefix?: string): string;
300
+ static getRecommendedShadowsocksCipher(): string;
301
+ static getShadowsocksCipherMethods(): string[];
302
+ static generatePort(min?: number, max?: number): number;
303
+ static generateRealityShortId(): string;
304
+ static generateForProtocol(protocol: string, options?: CredentialOptions): any;
305
+ static generateBulk(protocol: string, count: number, options?: CredentialOptions): any[];
306
+ static validateCredentials(credentials: any, protocol: string): ValidationResult;
307
+ }
308
+
309
+ // ===========================================
310
+ // SESSION MANAGEMENT CLASSES
311
+ // ===========================================
312
+
313
+ export class SessionStore {
314
+ get(key: string): Promise<any>;
315
+ set(key: string, value: any, ttl?: number): Promise<void>;
316
+ delete(key: string): Promise<void>;
317
+ clear(): Promise<void>;
318
+ exists(key: string): Promise<boolean>;
319
+ }
320
+
321
+ export class MemorySessionStore extends SessionStore {
322
+ constructor();
323
+ getStats(): any;
324
+ }
325
+
326
+ export class RedisSessionStore extends SessionStore {
327
+ constructor(redisClient: any, options?: any);
328
+ }
329
+
330
+ export class DatabaseSessionStore extends SessionStore {
331
+ constructor(database: any, options?: any);
332
+ cleanupExpired(): Promise<number>;
333
+ static getCreateTableSQL(tableName?: string): string;
334
+ }
335
+
336
+ export class CustomSessionHandler {
337
+ constructor(handlers: any);
338
+ validate(key: string): Promise<boolean>;
339
+ }
340
+
341
+ export function createSessionManager(options?: SessionConfig): SessionManager;
342
+ export function createMemoryStore(): MemorySessionStore;
343
+ export function createRedisStore(redisClient: any, options?: any): RedisSessionStore;
344
+ export function createDatabaseStore(database: any, options?: any): DatabaseSessionStore;
345
+ export function createCustomHandler(handlers: any): CustomSessionHandler;
346
+
347
+ // ===========================================
348
+ // WEB MIDDLEWARE EXPORTS
349
+ // ===========================================
350
+
351
+ export function createExpressMiddleware(config: ExpressMiddlewareConfig): any;
352
+ export function withThreeXUI(config: NextJSConfig, handler: any): any;
353
+ export function createReactHook(apiEndpoint?: string): ReactHookMethods;
354
+ export function createNextjsRoutes(config: NextJSConfig): any;
355
+
356
+ export const SessionConfig: {
357
+ memory(): SessionConfig;
358
+ redis(redisClient: any, options?: any): SessionConfig;
359
+ database(database: any, options?: any): SessionConfig;
360
+ custom(handlers: any): SessionConfig;
361
+ };
362
+
363
+ // ===========================================
364
+ // PROTOCOL BUILDERS
365
+ // ===========================================
366
+
367
+ export class BaseBuilder {
368
+ constructor();
369
+ remark(remark: string): this;
370
+ port(port: number): this;
371
+ randomPort(min?: number, max?: number): this;
372
+ listen(listen?: string): this;
373
+ enable(enabled?: boolean): this;
374
+ build(): BuilderConfig;
108
375
  }
109
- }
376
+
377
+ export class VLESSBuilder extends BaseBuilder {
378
+ addClient(options?: CredentialOptions): this;
379
+ network(network: string): this;
380
+ tls(options?: TLSOptions): this;
381
+ reality(options?: RealityOptions): this;
382
+ websocket(options?: WebSocketOptions): this;
383
+ http2(options?: HTTP2Options): this;
384
+ grpc(options?: GRPCOptions): this;
385
+ flow(flow: string): this;
386
+ }
387
+
388
+ export class VMESSBuilder extends BaseBuilder {
389
+ addClient(options?: CredentialOptions): this;
390
+ network(network: string): this;
391
+ tls(options?: TLSOptions): this;
392
+ websocket(options?: WebSocketOptions): this;
393
+ }
394
+
395
+ export class TrojanBuilder extends BaseBuilder {
396
+ addClient(options?: CredentialOptions): this;
397
+ tls(options?: TLSOptions): this;
398
+ fallbacks(fallbacks: any[]): this;
399
+ }
400
+
401
+ export class ShadowsocksBuilder extends BaseBuilder {
402
+ method(method: string): this;
403
+ password(password?: string): this;
404
+ generatePassword(length?: number): this;
405
+ network(network: string): this;
406
+ }
407
+
408
+ export class WireGuardBuilder extends BaseBuilder {
409
+ serverKeys(keys?: WireGuardKeys): this;
410
+ address(addresses: string | string[]): this;
411
+ addPeer(options?: any): this;
412
+ mtu(mtu: number): this;
413
+ }
414
+
415
+ export class ProtocolBuilder {
416
+ static vless(): VLESSBuilder;
417
+ static vmess(): VMESSBuilder;
418
+ static trojan(): TrojanBuilder;
419
+ static shadowsocks(): ShadowsocksBuilder;
420
+ static wireguard(): WireGuardBuilder;
421
+ static templates: {
422
+ vlessReality(options?: any): BuilderConfig;
423
+ vmessWsTls(options?: any): BuilderConfig;
424
+ trojanTls(options?: any): BuilderConfig;
425
+ shadowsocks(options?: any): BuilderConfig;
426
+ };
427
+ }
428
+
429
+ // Optional: expose security helpers for advanced users
430
+ export const SecurityEnhancer: {
431
+ InputValidator: any;
432
+ SecureHeaders: any;
433
+ SecurityMonitor: any;
434
+ CredentialSecurity: any;
435
+ ErrorSecurity: any;
436
+ };
437
+ }