x3ui-api 1.0.7-1 → 1.0.9-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 CHANGED
@@ -29,8 +29,7 @@ const X3UIClient = require('x3ui-api');
29
29
 
30
30
  // Initialize client
31
31
  const client = new X3UIClient({
32
- baseURL: 'http://your-x3ui-panel.com:54321',
33
- parseJSONSettings: true // Default: true - automatically parse JSON settings
32
+ baseURL: 'http://your-x3ui-panel.com:54321'
34
33
  });
35
34
 
36
35
  // Login to panel
@@ -315,7 +314,6 @@ async function manageInbounds() {
315
314
  new X3UIClient({
316
315
  baseURL: string, // Required: URL to your x3ui panel
317
316
  token?: string, // Optional: Authentication token (if already logged in)
318
- parseJSONSettings?: boolean // Optional: Auto-parse JSON settings (default: true)
319
317
  })
320
318
  ```
321
319
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3ui-api",
3
- "version": "1.0.7-1",
3
+ "version": "1.0.9-1",
4
4
  "description": "API client for x3ui panel",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -7,7 +7,6 @@ module.exports = class X3UIClient {
7
7
 
8
8
  constructor(config) {
9
9
  this.config = config;
10
- this.config.parseJSONSettings ??= true;
11
10
  this.client = axios.create({
12
11
  baseURL: config.baseURL,
13
12
  headers: config.token ? {
@@ -44,7 +43,7 @@ module.exports = class X3UIClient {
44
43
  }
45
44
 
46
45
  async getSystemStats() {
47
- if(!this.isAuthed) {
46
+ if (!this.isAuthed) {
48
47
  await this.login();
49
48
  }
50
49
  const response = await this.client.post('/server/status');
@@ -70,24 +69,19 @@ module.exports = class X3UIClient {
70
69
  * }>>}
71
70
  */
72
71
  async getInbounds() {
73
- if(!this.isAuthed) {
72
+ if (!this.isAuthed) {
74
73
  await this.login();
75
74
  }
76
75
  const response = await this.client.get('/panel/api/inbounds/list');
77
76
  let inbounds = response.data.obj;
78
- if (this.parseJSONSettings) {
79
- inbounds = inbounds.map(inbound => this.parseInbound(inbound));
80
- }
81
- return inbounds;
77
+ return inbounds.map(inbound => this.parseInbound(inbound));
82
78
  }
83
79
 
84
80
  parseInbound(inbound) {
85
- if (this.parseJSONSettings) {
86
- inbound.settings = inbound.settings && inbound.settings.length > 0 ? JSON.parse(inbound.settings) : {};
87
- inbound.streamSettings = inbound.streamSettings && inbound.streamSettings.length > 0 ? JSON.parse(inbound.streamSettings) : {};
88
- inbound.sniffing = inbound.sniffing && inbound.sniffing.length > 0 ? JSON.parse(inbound.sniffing) : {};
89
- inbound.allocate = inbound.allocate && inbound.allocate.length > 0 ? JSON.parse(inbound.allocate) : {};
90
- }
81
+ inbound.settings = inbound.settings && inbound.settings.length > 0 ? JSON.parse(inbound.settings) : {};
82
+ inbound.streamSettings = inbound.streamSettings && inbound.streamSettings.length > 0 ? JSON.parse(inbound.streamSettings) : {};
83
+ inbound.sniffing = inbound.sniffing && inbound.sniffing.length > 0 ? JSON.parse(inbound.sniffing) : {};
84
+ inbound.allocate = inbound.allocate && inbound.allocate.length > 0 ? JSON.parse(inbound.allocate) : {};
91
85
  return inbound;
92
86
  }
93
87
 
@@ -118,12 +112,12 @@ module.exports = class X3UIClient {
118
112
  * @returns {Promise<void>}
119
113
  */
120
114
  async addInbound(config) {
121
- if(!this.isAuthed) {
115
+ if (!this.isAuthed) {
122
116
  await this.login();
123
117
  }
124
118
  config = this.stringifyInbound(config);
125
119
  const response = await this.client.post('/panel/api/inbounds/add', config);
126
- if(!response.data.success)
120
+ if (!response.data.success)
127
121
  throw new Error(response.data.msg);
128
122
  return this.parseInbound(response.data.obj);
129
123
  }
@@ -135,12 +129,12 @@ module.exports = class X3UIClient {
135
129
  * @returns {Promise<void>}
136
130
  */
137
131
  async updateInbound(id, config) {
138
- if(!this.isAuthed) {
132
+ if (!this.isAuthed) {
139
133
  await this.login();
140
134
  }
141
135
  config = this.stringifyInbound(config);
142
136
  const response = await this.client.post(`/panel/api/inbounds/update/${id}`, config);
143
- if(!response.data.success)
137
+ if (!response.data.success)
144
138
  throw new Error(response.data.msg);
145
139
  return this.parseInbound(response.data.obj);
146
140
  }
@@ -151,7 +145,7 @@ module.exports = class X3UIClient {
151
145
  * @returns {Promise<void>}
152
146
  */
153
147
  async deleteInbound(id) {
154
- if(!this.isAuthed) {
148
+ if (!this.isAuthed) {
155
149
  await this.login();
156
150
  }
157
151
  await this.client.post(`/panel/api/inbounds/del/${id}`);
@@ -162,7 +156,7 @@ module.exports = class X3UIClient {
162
156
  * @returns {Promise<{privateKey: string, publicKey: string}>} New X25519 key pair
163
157
  */
164
158
  async getNewX25519Cert() {
165
- if(!this.isAuthed) {
159
+ if (!this.isAuthed) {
166
160
  await this.login();
167
161
  }
168
162
  const response = await this.client.post('/server/getNewX25519Cert');
package/src/index.d.ts CHANGED
@@ -9,7 +9,6 @@ export default X3UIClient;
9
9
  export interface X3UIConfig {
10
10
  baseURL: string;
11
11
  token?: string;
12
- parseJSONSettings?: boolean;
13
12
  username?: string;
14
13
  password?: string;
15
14
  }
@@ -65,6 +65,13 @@ export default class VmessBuilder {
65
65
  */
66
66
  getClientLink(clientIndex?: number, host?: string): string;
67
67
 
68
+ /**
69
+ * Get connection link for a client
70
+ * @param email Email of the client
71
+ * @param host Optional host address (defaults to listenIP or 'localhost')
72
+ */
73
+ getClientLinkByEmail(email: string, host?: string): string;
74
+
68
75
  /**
69
76
  * Generate a random port number
70
77
  */
@@ -130,6 +130,14 @@ module.exports = class VmessBuilder {
130
130
  return client.getLink(host || this.listenIP || 'localhost', port || this.port);
131
131
  }
132
132
 
133
+ getClientLinkByEmail(email, host) {
134
+ const client = this.clients.find(client => client.email === email);
135
+ if (!client) {
136
+ throw new Error('Client not found');
137
+ }
138
+ return client.getLink(host || this.listenIP || 'localhost', this.port);
139
+ }
140
+
133
141
  generateRandomPort() {
134
142
  return Math.floor(Math.random() * (65535 - 1024) + 1024);
135
143
  }
@@ -87,6 +87,13 @@ export default class WireguardBuilder {
87
87
  * @returns A formatted connection link string
88
88
  */
89
89
  getClientLink(clientIndex?: number, host?: string, port?: number): string;
90
+
91
+ /**
92
+ * Get connection link for a client
93
+ * @param email Email of the client
94
+ * @param host Optional host address (defaults to listenIP or 'localhost')
95
+ */
96
+ getClientLinkByEmail(email: string, host?: string): string;
90
97
 
91
98
  /**
92
99
  * Generates a configuration file for a client.
@@ -132,6 +132,14 @@ module.exports = class WireguardBuilder {
132
132
  return client.getLink(host || this.listenIP || 'localhost', port || this.port);
133
133
  }
134
134
 
135
+ getClientLinkByEmail(email, host) {
136
+ const client = this.clients.find(client => client.email === email);
137
+ if (!client) {
138
+ throw new Error('Client not found');
139
+ }
140
+ return client.getLink(host || this.listenIP || 'localhost', this.port);
141
+ }
142
+
135
143
  getClientConfig(clientIndex = 0, host, port) {
136
144
  if (clientIndex < 0 || clientIndex >= this.clients.length) {
137
145
  throw new Error('Invalid client index');