Skip to content

Commit e15dfc3

Browse files
committed
test old xray
1 parent 100624f commit e15dfc3

39 files changed

Lines changed: 1248 additions & 2745 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/xtls-sdk",
3-
"version": "0.0.8",
3+
"version": "0.0.8-dev.1.8.6",
44
"description": "A Typescript SDK for XRAY (XTLS) Core GRPC Api",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",
@@ -56,7 +56,7 @@
5656
"ts-proto": "^2.2.7",
5757
"typescript": "^5.6.3"
5858
},
59-
"jest": {
59+
"jest": {
6060
"moduleFileExtensions": [
6161
"js",
6262
"json",
@@ -73,4 +73,4 @@
7373
"coverageDirectory": "./coverage",
7474
"testEnvironment": "node"
7575
}
76-
}
76+
}

scripts/export-protos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as tar from 'tar';
66
import { exec } from 'node:child_process';
77
import { promisify } from 'node:util';
88

9-
const VERSION = '24.11.11';
9+
const VERSION = '1.8.6';
1010
const TEMP_DIR = path.join(__dirname, 'temp-xray-core');
1111
const TARGET_URL = `https://github.com/XTLS/Xray-core/archive/refs/tags/v${VERSION}.tar.gz`;
1212

src/common/utils/decode-user/constants/account-types.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Account as TrojanAccount } from '../../../../xray-protos/proxy/trojan/config';
22
import { Account as VlessAccount } from '../../../../xray-protos/proxy/vless/account';
3-
import { Account as ShadowsocksAccount } from '../../../../xray-protos/proxy/shadowsocks/config';
4-
import { Account as Shadowsocks2022Account } from '../../../../xray-protos/proxy/shadowsocks_2022/config';
5-
import { Account as SocksAccount } from '../../../../xray-protos/proxy/socks/config';
63
import { Account as HttpAccount } from '../../../../xray-protos/proxy/http/config';
74

85
export const ACCOUNT_TYPES = {
@@ -22,30 +19,6 @@ export const ACCOUNT_TYPES = {
2219
encryption: acc.encryption,
2320
}),
2421
},
25-
[ShadowsocksAccount.$type]: {
26-
decoder: ShadowsocksAccount,
27-
protocol: 'shadowsocks',
28-
getCredentials: (acc: ShadowsocksAccount): Omit<ShadowsocksAccount, '$type'> => ({
29-
password: acc.password,
30-
cipherType: acc.cipherType,
31-
ivCheck: acc.ivCheck,
32-
}),
33-
},
34-
[Shadowsocks2022Account.$type]: {
35-
decoder: Shadowsocks2022Account,
36-
protocol: 'shadowsocks2022',
37-
getCredentials: (acc: Shadowsocks2022Account): Omit<Shadowsocks2022Account, '$type'> => ({
38-
key: acc.key,
39-
}),
40-
},
41-
[SocksAccount.$type]: {
42-
decoder: SocksAccount,
43-
protocol: 'socks',
44-
getCredentials: (acc: SocksAccount): Omit<SocksAccount, '$type'> => ({
45-
username: acc.username,
46-
password: acc.password,
47-
}),
48-
},
4922
[HttpAccount.$type]: {
5023
decoder: HttpAccount,
5124
protocol: 'http',
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { AccountTypeMapping } from './account-type-mapping.type';
22
import { Account as TrojanAccount } from '../../../../xray-protos/proxy/trojan/config';
33
import { Account as VlessAccount } from '../../../../xray-protos/proxy/vless/account';
4-
import { Account as ShadowsocksAccount } from '../../../../xray-protos/proxy/shadowsocks/config';
5-
import { Account as Shadowsocks2022Account } from '../../../../xray-protos/proxy/shadowsocks_2022/config';
64
import { Account as SocksAccount } from '../../../../xray-protos/proxy/socks/config';
75
import { Account as HttpAccount } from '../../../../xray-protos/proxy/http/config';
86

@@ -13,7 +11,5 @@ export interface DecodedUser {
1311
trojan?: Omit<TrojanAccount, '$type'>;
1412
vless?: Omit<VlessAccount, '$type'>;
1513
http?: Omit<HttpAccount, '$type'>;
16-
shadowsocks?: Omit<ShadowsocksAccount, '$type'>;
17-
shadowsocks2022?: Omit<Shadowsocks2022Account, '$type'>;
1814
socks?: Omit<SocksAccount, '$type'>;
1915
}

src/handler/handler.service.ts

Lines changed: 2 additions & 228 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,10 @@ import { User } from '../xray-protos/common/protocol/user';
99
import createTypedMessage from '../common/utils/create-typed-message/create-typed-message';
1010
import { ISdkResponse } from '../common/types/sdk-response';
1111
import { HANDLER_ERRORS } from '../common/errors';
12-
import { AddUserResponseModel, GetInboundUsersResponseModel } from './models';
13-
import {
14-
IAddHttpUser,
15-
IAddShadowsocks2022User,
16-
IAddShadowsocksUser,
17-
IAddSocksUser,
18-
IAddTrojanUser,
19-
IAddVlessUser,
20-
} from './interfaces';
12+
import { AddUserResponseModel } from './models';
13+
import { IAddHttpUser, IAddTrojanUser, IAddVlessUser } from './interfaces';
2114
import { Account as TrojanAccount } from '../xray-protos/proxy/trojan/config';
2215
import { Account as VlessAccount } from '../xray-protos/proxy/vless/account';
23-
import { Account as ShadowsocksAccount } from '../xray-protos/proxy/shadowsocks/config';
24-
import { Account as Shadowsocks2022Account } from '../xray-protos/proxy/shadowsocks_2022/config';
25-
import { Account as SocksAccount } from '../xray-protos/proxy/socks/config';
2616
import { Account as HttpAccount } from '../xray-protos/proxy/http/config';
2717
import { RemoveUserResponseModel } from './models/remove-user/remove-user.response.model';
2818

@@ -36,47 +26,6 @@ export class HandlerService {
3626
this.client = createClient(HandlerServiceDefinition, channel);
3727
}
3828

39-
/**
40-
* Retrieves all users from a specified inbound handler.
41-
* This method fetches user information including their credentials and metadata from the Xray server.
42-
*
43-
* @param {string} tag - The tag identifying the inbound handler to query
44-
* @returns {Promise<ISdkResponse<GetInboundUsersResponseModel>>} A promise that resolves to:
45-
* - On success: An object with `isOk: true` and `data` containing an array of decoded user information
46-
* - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
47-
*
48-
* @example
49-
* ```typescript
50-
* const handler = new HandlerService(channel);
51-
* const response = await handler.getInboundUsers('Personal');
52-
*
53-
* if (response.isOk) {
54-
* console.log(response.data.users); // Array of DecodedUser objects
55-
* } else {
56-
* console.error(response.message); // Error message
57-
* }
58-
* ```
59-
*/
60-
public async getInboundUsers(tag: string): Promise<ISdkResponse<GetInboundUsersResponseModel>> {
61-
try {
62-
const response = await this.client.getInboundUsers({ tag });
63-
64-
return {
65-
isOk: true,
66-
data: new GetInboundUsersResponseModel(response.users),
67-
};
68-
} catch (error) {
69-
let message = '';
70-
if (error instanceof Error) {
71-
message = error.message;
72-
}
73-
return {
74-
isOk: false,
75-
...HANDLER_ERRORS.GET_ALL_USERS_ERROR(message),
76-
};
77-
}
78-
}
79-
8029
/**
8130
* Adds a new Trojan user to a specified inbound handler.
8231
*
@@ -173,154 +122,6 @@ export class HandlerService {
173122
}
174123
}
175124

176-
/**
177-
* Adds a new Shadowsocks user to a specified inbound handler.
178-
*
179-
* @param {IAddShadowsocksUser} data - The user data containing tag, username, password, cipher type, IV check and level
180-
* @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
181-
* - On success: An object with `isOk: true` and `data.success` indicating if user was added
182-
* - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
183-
*/
184-
public async addShadowsocksUser(
185-
data: IAddShadowsocksUser,
186-
): Promise<ISdkResponse<AddUserResponseModel>> {
187-
try {
188-
const response = await this.client.alterInbound({
189-
tag: data.tag,
190-
operation: createTypedMessage(AddUserOperation, {
191-
user: User.create({
192-
email: data.username,
193-
level: data.level,
194-
account: createTypedMessage(ShadowsocksAccount, {
195-
password: data.password,
196-
cipherType: data.cipherType,
197-
ivCheck: data.ivCheck,
198-
}),
199-
}),
200-
}),
201-
});
202-
203-
return {
204-
isOk: true,
205-
data: new AddUserResponseModel(true),
206-
};
207-
} catch (error) {
208-
let message = '';
209-
if (error instanceof Error) {
210-
message = error.message;
211-
}
212-
213-
if (message.includes('already exists')) {
214-
return {
215-
isOk: true,
216-
data: new AddUserResponseModel(false),
217-
};
218-
}
219-
220-
return {
221-
isOk: false,
222-
...HANDLER_ERRORS.ADD_USER_ERROR(message),
223-
};
224-
}
225-
}
226-
227-
/**
228-
* Adds a new Shadowsocks 2022 user to a specified inbound handler.
229-
*
230-
* @param {IAddShadowsocks2022User} data - The user data containing tag, username, key and level
231-
* @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
232-
* - On success: An object with `isOk: true` and `data.success` indicating if user was added
233-
* - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
234-
*/
235-
public async addShadowsocks2022User(
236-
data: IAddShadowsocks2022User,
237-
): Promise<ISdkResponse<AddUserResponseModel>> {
238-
try {
239-
const response = await this.client.alterInbound({
240-
tag: data.tag,
241-
operation: createTypedMessage(AddUserOperation, {
242-
user: User.create({
243-
email: data.username,
244-
level: data.level,
245-
account: createTypedMessage(Shadowsocks2022Account, {
246-
key: data.key,
247-
}),
248-
}),
249-
}),
250-
});
251-
252-
return {
253-
isOk: true,
254-
data: new AddUserResponseModel(true),
255-
};
256-
} catch (error) {
257-
let message = '';
258-
if (error instanceof Error) {
259-
message = error.message;
260-
}
261-
262-
if (message.includes('already exists')) {
263-
return {
264-
isOk: true,
265-
data: new AddUserResponseModel(false),
266-
};
267-
}
268-
269-
return {
270-
isOk: false,
271-
...HANDLER_ERRORS.ADD_USER_ERROR(message),
272-
};
273-
}
274-
}
275-
276-
/**
277-
* Adds a new SOCKS user to a specified inbound handler.
278-
*
279-
* @param {IAddSocksUser} data - The user data containing tag, username, SOCKS username, SOCKS password and level
280-
* @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
281-
* - On success: An object with `isOk: true` and `data.success` indicating if user was added
282-
* - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
283-
*/
284-
public async addSocksUser(data: IAddSocksUser): Promise<ISdkResponse<AddUserResponseModel>> {
285-
try {
286-
const response = await this.client.alterInbound({
287-
tag: data.tag,
288-
operation: createTypedMessage(AddUserOperation, {
289-
user: User.create({
290-
email: data.username,
291-
level: data.level,
292-
account: createTypedMessage(SocksAccount, {
293-
username: data.socks_username,
294-
password: data.socks_password,
295-
}),
296-
}),
297-
}),
298-
});
299-
300-
return {
301-
isOk: true,
302-
data: new AddUserResponseModel(true),
303-
};
304-
} catch (error) {
305-
let message = '';
306-
if (error instanceof Error) {
307-
message = error.message;
308-
}
309-
310-
if (message.includes('already exists')) {
311-
return {
312-
isOk: true,
313-
data: new AddUserResponseModel(false),
314-
};
315-
}
316-
317-
return {
318-
isOk: false,
319-
...HANDLER_ERRORS.ADD_USER_ERROR(message),
320-
};
321-
}
322-
}
323-
324125
/**
325126
* Adds a new HTTP user to a specified inbound handler.
326127
*
@@ -411,31 +212,4 @@ export class HandlerService {
411212
};
412213
}
413214
}
414-
415-
/**
416-
* Gets the count of users in a specified inbound handler.
417-
*
418-
* @param {string} tag - The tag identifying the inbound handler
419-
* @returns {Promise<ISdkResponse<number>>} A promise that resolves to:
420-
* - On success: An object with `isOk: true` and `data` containing the user count
421-
* - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
422-
*/
423-
public async getInboundUsersCount(tag: string): Promise<ISdkResponse<number>> {
424-
try {
425-
const response = await this.client.getInboundUsersCount({ tag });
426-
return {
427-
isOk: true,
428-
data: response.count,
429-
};
430-
} catch (error) {
431-
let message = '';
432-
if (error instanceof Error) {
433-
message = error.message;
434-
}
435-
return {
436-
isOk: false,
437-
...HANDLER_ERRORS.GET_INBOUND_USERS_COUNT_ERROR(message),
438-
};
439-
}
440-
}
441215
}

src/handler/models/get-inbound-users/get-inbound-users.response.model.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/handler/models/get-inbound-users/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/handler/models/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './get-inbound-users';
21
export * from './add-user';
32
export * from './remove-user';

0 commit comments

Comments
 (0)