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