3xui-api-client 3.1.0 → 3.1.2

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 CHANGED
@@ -5,6 +5,24 @@ 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
+ ## [3.1.2] - 2026-06-30
9
+
10
+ ### Fixed
11
+ - 🔴 **Session recovery for non-401 stale sessions** ([#10](https://github.com/iamhelitha/3xui-api-client/issues/10)) - Automatic re-login is no longer keyed strictly to HTTP `401`. Some 3x-ui forks reject a stale cookie session with `404` (the auth-gated route falls through to a generic not-found handler when not logged in) or by returning an HTML login page with `200`. The client now treats all three as a lost session and performs one bounded, backed-off forced re-login + retry — reusing the existing `maxLoginRetries` / `loginRetryBackoff` budget. Token auth is unchanged: a `401` still throws a clear "token invalid" error and a `404` surfaces unchanged as a genuine missing resource.
12
+ - 🐛 **`getClientIps(email)` now returns a real array** ([#12](https://github.com/iamhelitha/3xui-api-client/issues/12)) - The legacy panel returns `obj` as a JSON-encoded string (e.g. `'["1.2.3.4"]'`) rather than an actual array. The client now parses it internally so `obj` is always a `string[]` (empty array when the panel has no IP record), matching every other list-returning endpoint. The TypeScript signature is now `Promise<ModernApiResponse<string[]>>`.
13
+
14
+ ### Changed
15
+ - 📖 **`getCPUHistory(bucket)` documentation/types corrected** ([#11](https://github.com/iamhelitha/3xui-api-client/issues/11)) - The previously documented `{ history: [{ timestamp, usage }] }` shape was assumed and never verified. The endpoint actually returns the standard `{ success, msg, obj }` envelope where `obj` is an array of exactly 60 `{ cpu: number; t: number }` points (`cpu` is a plain percentage number, `t` is epoch **seconds**; total span is `60 * bucket` seconds). The TypeScript signature is now `Promise<ModernApiResponse<Array<{ cpu: number; t: number }>>>`. No runtime change — the method already returned the real envelope.
16
+
17
+ ## [3.1.1] - 2026-06-18
18
+
19
+ ### Changed
20
+ - 📜 **License changed from MIT to Apache 2.0** - Adds an explicit patent grant/termination clause and stronger attribution requirements for derivative works.
21
+ - 🔍 Improved npm/GitHub discoverability - expanded `package.json` keywords and a more descriptive package description covering supported protocols (VLESS, VMess, Trojan, Shadowsocks, WireGuard, Reality).
22
+
23
+ ### Fixed
24
+ - 🔴 **CRITICAL**: Removed the broken `index.mjs` ESM wrapper, which crashed with `Cannot find module './index.js'` in Next.js `output: 'standalone'` builds and other bundlers using static file tracing (esbuild, Rollup, Vite SSR). The wrapper's runtime `require('./index.js')` call was invisible to these tracers, so `index.js` was never included in the deployment bundle. `package.json` `exports` now route both `require` and `import` consumers directly to `index.js`, which resolves correctly everywhere since the package already declares `"type": "commonjs"`. The `serverExternalPackages` workaround is no longer needed. Closes [#8](https://github.com/iamhelitha/3xui-api-client/issues/8). Thanks to [@crimsonml](https://github.com/crimsonml) for the detailed report and root-cause analysis.
25
+
8
26
  ## [3.1.0] - 2026-06-15
9
27
 
10
28
  ### Added
package/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Helitha Guruge
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing
141
+ the origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on behalf of Yourself, assuming sole
171
+ responsibility, not on behalf of any other Contributor, and agree
172
+ to indemnify, defend, and hold each Contributor harmless for any
173
+ liability incurred by, or claims asserted against, such Contributor
174
+ by reason of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or comment identical to the comment notice file and is
186
+ included as a "Description" field, but the actual file or comment
187
+ file in this file format.
188
+
189
+ Copyright 2025 Helitha Guruge
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions
201
+ and limitations under the License.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # 3xui-api-client
2
2
 
3
- A Node.js client library for 3x-ui panel API that provides easy-to-use methods for managing your 3x-ui server.
3
+ A Node.js / TypeScript API client for the **3x-ui panel** (Xray-core), with easy-to-use methods for managing inbounds and clients across **VLESS, VMess, Trojan, Shadowsocks, WireGuard,** and **Reality** protocols.
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/3xui-api-client.svg)](https://badge.fury.io/js/3xui-api-client)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/3xui-api-client.svg)](https://www.npmjs.com/package/3xui-api-client)
7
7
  [![GitHub stars](https://img.shields.io/github/stars/iamhelitha/3xui-api-client.svg)](https://github.com/iamhelitha/3xui-api-client)
8
8
  [![Node.js Version](https://img.shields.io/node/v/3xui-api-client.svg)](https://nodejs.org/)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
10
10
  [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/iamhelitha/3xui-api-client/graphs/commit-activity)
11
11
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
12
12
 
@@ -370,7 +370,7 @@ const client = new XuiApiClient({
370
370
 
371
371
  ## License
372
372
 
373
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
373
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
374
374
 
375
375
  ## Support
376
376
 
package/index.d.ts CHANGED
@@ -581,7 +581,14 @@ declare module '3xui-api-client' {
581
581
  deleteClientByEmail(inboundId: number, email: string): Promise<any>;
582
582
  getClientTrafficsByEmail(email: string): Promise<any>;
583
583
  getClientTrafficsById(id: string): Promise<any>;
584
- getClientIps(email: string): Promise<any>;
584
+ /**
585
+ * Get the list of IP addresses recorded for a client.
586
+ *
587
+ * The legacy panel returns `obj` as a JSON-encoded string; this client
588
+ * parses it internally so `obj` is always a real `string[]` (empty when
589
+ * the panel has no IP record for the client).
590
+ */
591
+ getClientIps(email: string): Promise<ModernApiResponse<string[]>>;
585
592
  clearClientIps(email: string): Promise<any>;
586
593
  resetClientTraffic(inboundId: number, email: string): Promise<any>;
587
594
  resetAllTraffics(): Promise<any>;
@@ -595,9 +602,15 @@ declare module '3xui-api-client' {
595
602
  getServerStatus(): Promise<any>;
596
603
  /**
597
604
  * Get CPU usage history.
605
+ *
606
+ * Returns the standard `{ success, msg, obj }` envelope. `obj` is an array
607
+ * of exactly 60 points, each `{ cpu, t }` where `cpu` is the usage
608
+ * percentage (a plain number, no trailing `%`) and `t` is the epoch time in
609
+ * seconds. The total span covered is `60 * bucket` seconds.
610
+ *
598
611
  * @param bucket - Bucket size in seconds. Must be one of: 2, 30, 60, 120, 180, 300 (default: 60)
599
612
  */
600
- getCPUHistory(bucket?: number): Promise<any>;
613
+ getCPUHistory(bucket?: number): Promise<ModernApiResponse<Array<{ cpu: number; t: number }>>>;
601
614
  getXrayVersion(): Promise<any>;
602
615
  getConfigJson(): Promise<any>;
603
616
  /**
package/index.js CHANGED
@@ -409,38 +409,110 @@ class ThreeXUI {
409
409
  data,
410
410
  headers: { ...this._buildRequestHeaders(method), ...extraHeaders }
411
411
  });
412
+
413
+ // Some panels answer a stale/expired session with HTTP 200 plus an
414
+ // HTML login page (a redirect-then-200) instead of an explicit
415
+ // 401/404. For cookie auth, treat that HTML body where JSON was
416
+ // expected as a lost session and recover transparently.
417
+ if (!this.token && this._looksLikeLoginPage(response.data)) {
418
+ return await this._retryAfterRelogin(method, path, data, extraHeaders);
419
+ }
420
+
412
421
  // Reset retry counter on successful request
413
422
  this.loginRetryCount = 0;
414
423
  return response.data;
415
424
  } catch (error) {
416
- if (error.response && error.response.status === 401) {
425
+ if (this._isStaleSessionError(error)) {
417
426
  if (this.token) {
418
- throw new Error('API Token is invalid or expired. Please check your credentials.');
419
- }
420
- // Cookie might have expired, try to login again with retry limit.
421
- // A configurable backoff delay is applied before each re-login to
422
- // avoid burning through the retry budget or tripping login-rate limits
423
- // (e.g. fail2ban) when many instances race to re-authenticate.
424
- if (this.loginRetryCount < this.maxLoginRetries) {
425
- if (this.loginRetryBackoff > 0) {
426
- await new Promise(resolve => setTimeout(resolve, this.loginRetryBackoff));
427
+ // Token auth: a 401 means the token itself is invalid, so
428
+ // retrying will not help. A 404 is a genuine missing
429
+ // resource (the token never goes "stale"), so surface it
430
+ // unchanged.
431
+ if (error.response && error.response.status === 401) {
432
+ throw new Error('API Token is invalid or expired. Please check your credentials.');
427
433
  }
428
- await this._ensureAuthenticated(true); // Force refresh
429
- const response = await this.api.request({
430
- method,
431
- url: path,
432
- data,
433
- headers: { ...this._buildRequestHeaders(method), ...extraHeaders }
434
- });
435
- return response.data;
436
- } else {
437
- throw new Error('Maximum login retry attempts exceeded. Check your credentials.');
434
+ throw error;
438
435
  }
436
+ // Cookie session may have expired. Different 3x-ui versions/forks
437
+ // are inconsistent about the signal (401, 404, or an HTML login
438
+ // page), so we recover the same way for each: one bounded,
439
+ // backed-off forced re-login + retry.
440
+ return await this._retryAfterRelogin(method, path, data, extraHeaders);
439
441
  }
440
442
  throw error;
441
443
  }
442
444
  }
443
445
 
446
+ /**
447
+ * Decide whether an error from an authenticated request indicates a lost
448
+ * cookie session that warrants a forced re-login. Different 3x-ui forks
449
+ * reject a stale session with 401, with 404 (the auth-gated route falls
450
+ * through to a generic not-found handler when not logged in), or by
451
+ * returning an HTML login page where JSON was expected.
452
+ *
453
+ * @param {*} error - Error thrown by the axios request
454
+ * @returns {boolean} True if the error looks like a session failure
455
+ */
456
+ _isStaleSessionError(error) {
457
+ if (!error || !error.response) {
458
+ return false;
459
+ }
460
+ const status = error.response.status;
461
+ if (status === 401 || status === 404) {
462
+ return true;
463
+ }
464
+ return this._looksLikeLoginPage(error.response.data);
465
+ }
466
+
467
+ /**
468
+ * Heuristic for a panel returning its HTML login page in place of the
469
+ * expected JSON envelope. Every authenticated endpoint here returns JSON
470
+ * (or, for getDb, a "SQLite format 3" string), so an HTML document body is
471
+ * itself the anomaly that signals a redirect to the login screen.
472
+ *
473
+ * @param {*} data - Response body
474
+ * @returns {boolean} True if the body looks like an HTML login page
475
+ */
476
+ _looksLikeLoginPage(data) {
477
+ if (typeof data !== 'string') {
478
+ return false;
479
+ }
480
+ const trimmed = data.trim().toLowerCase();
481
+ return trimmed.startsWith('<!doctype html') || trimmed.startsWith('<html');
482
+ }
483
+
484
+ /**
485
+ * Force a fresh login and retry the original request once, honoring the
486
+ * shared retry budget and backoff. Used for cookie-auth session recovery
487
+ * regardless of whether the panel signalled with 401, 404, or a login-page
488
+ * body, so consumers never have to reimplement session recovery themselves.
489
+ *
490
+ * @param {string} method - HTTP method
491
+ * @param {string} path - Request path
492
+ * @param {Object} data - Request body
493
+ * @param {Object} extraHeaders - Additional headers to merge
494
+ * @returns {Promise<*>} The retried response data
495
+ */
496
+ async _retryAfterRelogin(method, path, data, extraHeaders) {
497
+ // Bound the recovery to a single retry budget to avoid login storms
498
+ // (e.g. tripping fail2ban) when many instances race to re-authenticate.
499
+ if (this.loginRetryCount >= this.maxLoginRetries) {
500
+ throw new Error('Maximum login retry attempts exceeded. Check your credentials.');
501
+ }
502
+ if (this.loginRetryBackoff > 0) {
503
+ await new Promise(resolve => setTimeout(resolve, this.loginRetryBackoff));
504
+ }
505
+ await this._ensureAuthenticated(true); // Force refresh
506
+ const response = await this.api.request({
507
+ method,
508
+ url: path,
509
+ data,
510
+ headers: { ...this._buildRequestHeaders(method), ...extraHeaders }
511
+ });
512
+ this.loginRetryCount = 0;
513
+ return response.data;
514
+ }
515
+
444
516
  /**
445
517
  * Build per-request headers, including the JSON content type for POST
446
518
  * bodies and (on cookie-authenticated sessions against newer
@@ -1151,8 +1223,44 @@ class ThreeXUI {
1151
1223
  return this._request('get', `/panel/api/inbounds/getClientTrafficsById/${id}`);
1152
1224
  }
1153
1225
 
1154
- getClientIps(email) {
1155
- return this._request('post', `/panel/api/inbounds/clientIps/${email}`);
1226
+ /**
1227
+ * Get the list of IP addresses recorded for a client.
1228
+ *
1229
+ * The legacy panel returns `obj` as a JSON-encoded string (e.g.
1230
+ * `'["1.2.3.4"]'`) rather than an actual array, unlike every other
1231
+ * list-returning endpoint. We parse it internally so callers get
1232
+ * `obj: string[]` directly. If the panel reports "No IP Record" (or any
1233
+ * non-array/unparseable value), `obj` is normalized to an empty array.
1234
+ *
1235
+ * @param {string} email - Client email
1236
+ * @returns {Promise<{success: boolean, msg: string, obj: string[]}>}
1237
+ */
1238
+ async getClientIps(email) {
1239
+ const response = await this._request('post', `/panel/api/inbounds/clientIps/${email}`);
1240
+ return { ...response, obj: this._parseClientIps(response && response.obj) };
1241
+ }
1242
+
1243
+ /**
1244
+ * Normalize the `obj` field returned by clientIps into a real array of IP
1245
+ * strings. The panel may return a JSON-encoded array string, an already
1246
+ * parsed array, or a placeholder message like "No IP Record".
1247
+ *
1248
+ * @param {*} obj - Raw `obj` value from the clientIps response
1249
+ * @returns {string[]} Parsed list of IP addresses (empty when none)
1250
+ */
1251
+ _parseClientIps(obj) {
1252
+ if (Array.isArray(obj)) {
1253
+ return obj;
1254
+ }
1255
+ if (typeof obj === 'string') {
1256
+ try {
1257
+ const parsed = JSON.parse(obj);
1258
+ return Array.isArray(parsed) ? parsed : [];
1259
+ } catch {
1260
+ return [];
1261
+ }
1262
+ }
1263
+ return [];
1156
1264
  }
1157
1265
 
1158
1266
  clearClientIps(email) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "3xui-api-client",
3
- "version": "3.1.0",
4
- "description": "A Node.js client library for 3x-ui panel API with built-in credential generation, session management, and web integration support",
3
+ "version": "3.1.2",
4
+ "description": "Node.js API client for the 3x-ui panel (VLESS, VMess, Trojan, Shadowsocks, WireGuard, Reality) with automatic session management, credential generation, and full REST API coverage",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./index.d.ts",
10
10
  "require": "./index.js",
11
- "import": "./index.mjs"
11
+ "default": "./index.js"
12
12
  }
13
13
  },
14
14
  "scripts": {
@@ -40,14 +40,27 @@
40
40
  "trojan",
41
41
  "shadowsocks",
42
42
  "wireguard",
43
- "reality"
43
+ "reality",
44
+ "3x-ui-client",
45
+ "3x-ui-api",
46
+ "xui-client",
47
+ "xui-api",
48
+ "xui",
49
+ "vpn-panel",
50
+ "vpn-api",
51
+ "vpn-client",
52
+ "rest-api-client",
53
+ "node",
54
+ "nodejs",
55
+ "typescript",
56
+ "sdk"
44
57
  ],
45
58
  "author": {
46
59
  "name": "Helitha Guruge",
47
60
  "email": "helithalochana@gmail.com",
48
61
  "url": "https://github.com/iamhelitha"
49
62
  },
50
- "license": "MIT",
63
+ "license": "Apache-2.0",
51
64
  "type": "commonjs",
52
65
  "repository": {
53
66
  "type": "git",
@@ -72,7 +85,6 @@
72
85
  ],
73
86
  "files": [
74
87
  "index.js",
75
- "index.mjs",
76
88
  "index.d.ts",
77
89
  "src/",
78
90
  "README.md",
package/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- const ThreeXUI = require('./index.js');
4
-
5
- export default ThreeXUI;