@remnawave/xtls-sdk 0.0.1 → 0.0.3

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.
Files changed (86) hide show
  1. package/README.md +164 -53
  2. package/build/src/common/errors/handler/handler.errors.d.ts +23 -0
  3. package/build/src/common/errors/handler/handler.errors.d.ts.map +1 -0
  4. package/build/src/common/errors/handler/handler.errors.js +22 -0
  5. package/build/src/common/errors/handler/index.d.ts +2 -0
  6. package/build/src/common/errors/handler/index.d.ts.map +1 -0
  7. package/build/src/common/errors/handler/index.js +17 -0
  8. package/build/src/common/errors/index.d.ts +1 -0
  9. package/build/src/common/errors/index.d.ts.map +1 -1
  10. package/build/src/common/errors/index.js +1 -0
  11. package/build/src/common/utils/create-typed-message/create-typed-message.d.ts +5 -0
  12. package/build/src/common/utils/create-typed-message/create-typed-message.d.ts.map +1 -0
  13. package/build/src/common/utils/create-typed-message/create-typed-message.js +10 -0
  14. package/build/src/common/utils/decode-user/constants/account-types.d.ts +39 -0
  15. package/build/src/common/utils/decode-user/constants/account-types.d.ts.map +1 -0
  16. package/build/src/common/utils/decode-user/constants/account-types.js +59 -0
  17. package/build/src/common/utils/decode-user/constants/index.d.ts +2 -0
  18. package/build/src/common/utils/decode-user/constants/index.d.ts.map +1 -0
  19. package/build/src/common/utils/decode-user/constants/index.js +17 -0
  20. package/build/src/common/utils/decode-user/decode-user.d.ts +37 -0
  21. package/build/src/common/utils/decode-user/decode-user.d.ts.map +1 -0
  22. package/build/src/common/utils/decode-user/decode-user.js +56 -0
  23. package/build/src/common/utils/decode-user/types/account-type-keys.type.d.ts +3 -0
  24. package/build/src/common/utils/decode-user/types/account-type-keys.type.d.ts.map +1 -0
  25. package/build/src/common/utils/decode-user/types/account-type-keys.type.js +2 -0
  26. package/build/src/common/utils/decode-user/types/account-type-mapping.type.d.ts +4 -0
  27. package/build/src/common/utils/decode-user/types/account-type-mapping.type.d.ts.map +1 -0
  28. package/build/src/common/utils/decode-user/types/account-type-mapping.type.js +2 -0
  29. package/build/src/common/utils/decode-user/types/decoded-user.type.d.ts +18 -0
  30. package/build/src/common/utils/decode-user/types/decoded-user.type.d.ts.map +1 -0
  31. package/build/src/common/utils/decode-user/types/decoded-user.type.js +2 -0
  32. package/build/src/common/utils/decode-user/types/index.d.ts +4 -0
  33. package/build/src/common/utils/decode-user/types/index.d.ts.map +1 -0
  34. package/build/src/common/utils/decode-user/types/index.js +19 -0
  35. package/build/src/handler/handler.service.d.ts +108 -0
  36. package/build/src/handler/handler.service.d.ts.map +1 -1
  37. package/build/src/handler/handler.service.js +402 -0
  38. package/build/src/handler/interfaces/add-user/add-http-user.interface.d.ts +8 -0
  39. package/build/src/handler/interfaces/add-user/add-http-user.interface.d.ts.map +1 -0
  40. package/build/src/handler/interfaces/add-user/add-http-user.interface.js +2 -0
  41. package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.d.ts +10 -0
  42. package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.d.ts.map +1 -0
  43. package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.js +2 -0
  44. package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.d.ts +7 -0
  45. package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.d.ts.map +1 -0
  46. package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.js +2 -0
  47. package/build/src/handler/interfaces/add-user/add-socks-user.interface.d.ts +8 -0
  48. package/build/src/handler/interfaces/add-user/add-socks-user.interface.d.ts.map +1 -0
  49. package/build/src/handler/interfaces/add-user/add-socks-user.interface.js +2 -0
  50. package/build/src/handler/interfaces/add-user/add-trojan-user.interface.d.ts +7 -0
  51. package/build/src/handler/interfaces/add-user/add-trojan-user.interface.d.ts.map +1 -0
  52. package/build/src/handler/interfaces/add-user/add-trojan-user.interface.js +2 -0
  53. package/build/src/handler/interfaces/add-user/add-vless-user.interface.d.ts +8 -0
  54. package/build/src/handler/interfaces/add-user/add-vless-user.interface.d.ts.map +1 -0
  55. package/build/src/handler/interfaces/add-user/add-vless-user.interface.js +2 -0
  56. package/build/src/handler/interfaces/add-user/index.d.ts +7 -0
  57. package/build/src/handler/interfaces/add-user/index.d.ts.map +1 -0
  58. package/build/src/handler/interfaces/add-user/index.js +22 -0
  59. package/build/src/handler/interfaces/index.d.ts +2 -0
  60. package/build/src/handler/interfaces/index.d.ts.map +1 -0
  61. package/build/src/handler/interfaces/index.js +17 -0
  62. package/build/src/handler/models/add-user/add-user.response.model.d.ts +5 -0
  63. package/build/src/handler/models/add-user/add-user.response.model.d.ts.map +1 -0
  64. package/build/src/handler/models/add-user/add-user.response.model.js +9 -0
  65. package/build/src/handler/models/add-user/index.d.ts +2 -0
  66. package/build/src/handler/models/add-user/index.d.ts.map +1 -0
  67. package/build/src/handler/models/add-user/index.js +17 -0
  68. package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.d.ts +7 -0
  69. package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.d.ts.map +1 -0
  70. package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.js +10 -0
  71. package/build/src/handler/models/get-inbound-users/index.d.ts +2 -0
  72. package/build/src/handler/models/get-inbound-users/index.d.ts.map +1 -0
  73. package/build/src/handler/models/get-inbound-users/index.js +17 -0
  74. package/build/src/handler/models/index.d.ts +4 -0
  75. package/build/src/handler/models/index.d.ts.map +1 -0
  76. package/build/src/handler/models/index.js +19 -0
  77. package/build/src/handler/models/remove-user/index.d.ts +2 -0
  78. package/build/src/handler/models/remove-user/index.d.ts.map +1 -0
  79. package/build/src/handler/models/remove-user/index.js +17 -0
  80. package/build/src/handler/models/remove-user/remove-user.response.model.d.ts +5 -0
  81. package/build/src/handler/models/remove-user/remove-user.response.model.d.ts.map +1 -0
  82. package/build/src/handler/models/remove-user/remove-user.response.model.js +9 -0
  83. package/build/tests/stats.spec.d.ts +2 -0
  84. package/build/tests/stats.spec.d.ts.map +1 -0
  85. package/build/tests/stats.spec.js +86 -0
  86. package/package.json +43 -4
@@ -0,0 +1,18 @@
1
+ import { Account as TrojanAccount } from '../../../../xray-protos/proxy/trojan/config';
2
+ 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';
6
+ import { Account as HttpAccount } from '../../../../xray-protos/proxy/http/config';
7
+ export interface DecodedUser {
8
+ username: string;
9
+ level: number;
10
+ protocol: string;
11
+ trojan?: Omit<TrojanAccount, '$type'>;
12
+ vless?: Omit<VlessAccount, '$type'>;
13
+ http?: Omit<HttpAccount, '$type'>;
14
+ shadowsocks?: Omit<ShadowsocksAccount, '$type'>;
15
+ shadowsocks2022?: Omit<Shadowsocks2022Account, '$type'>;
16
+ socks?: Omit<SocksAccount, '$type'>;
17
+ }
18
+ //# sourceMappingURL=decoded-user.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoded-user.type.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/types/decoded-user.type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,uDAAuD,CAAC;AAC1G,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAEnF,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACtC,KAAK,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IAChD,eAAe,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './account-type-keys.type';
2
+ export * from './account-type-mapping.type';
3
+ export * from './decoded-user.type';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./account-type-keys.type"), exports);
18
+ __exportStar(require("./account-type-mapping.type"), exports);
19
+ __exportStar(require("./decoded-user.type"), exports);
@@ -1 +1,109 @@
1
+ import { Channel } from 'nice-grpc';
2
+ import { ISdkResponse } from '../common/types/sdk-response';
3
+ import { AddUserResponseModel, GetInboundUsersResponseModel } from './models';
4
+ import { IAddHttpUser, IAddShadowsocks2022User, IAddShadowsocksUser, IAddSocksUser, IAddTrojanUser, IAddVlessUser } from './interfaces';
5
+ import { RemoveUserResponseModel } from './models/remove-user/remove-user.response.model';
6
+ /**
7
+ * Service for managing Xray inbound handlers and their users
8
+ */
9
+ export declare class HandlerService {
10
+ private readonly channel;
11
+ private readonly client;
12
+ constructor(channel: Channel);
13
+ /**
14
+ * Retrieves all users from a specified inbound handler.
15
+ * This method fetches user information including their credentials and metadata from the Xray server.
16
+ *
17
+ * @param {string} tag - The tag identifying the inbound handler to query
18
+ * @returns {Promise<ISdkResponse<GetInboundUsersResponseModel>>} A promise that resolves to:
19
+ * - On success: An object with `isOk: true` and `data` containing an array of decoded user information
20
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const handler = new HandlerService(channel);
25
+ * const response = await handler.getInboundUsers('Personal');
26
+ *
27
+ * if (response.isOk) {
28
+ * console.log(response.data.users); // Array of DecodedUser objects
29
+ * } else {
30
+ * console.error(response.message); // Error message
31
+ * }
32
+ * ```
33
+ */
34
+ getInboundUsers(tag: string): Promise<ISdkResponse<GetInboundUsersResponseModel>>;
35
+ /**
36
+ * Adds a new Trojan user to a specified inbound handler.
37
+ *
38
+ * @param {IAddTrojanUser} data - The user data containing tag, username, password and level
39
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
40
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
41
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
42
+ */
43
+ addTrojanUser(data: IAddTrojanUser): Promise<ISdkResponse<AddUserResponseModel>>;
44
+ /**
45
+ * Adds a new VLESS user to a specified inbound handler.
46
+ *
47
+ * @param {IAddVlessUser} data - The user data containing tag, username, UUID, flow and level
48
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
49
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
50
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
51
+ */
52
+ addVlessUser(data: IAddVlessUser): Promise<ISdkResponse<AddUserResponseModel>>;
53
+ /**
54
+ * Adds a new Shadowsocks user to a specified inbound handler.
55
+ *
56
+ * @param {IAddShadowsocksUser} data - The user data containing tag, username, password, cipher type, IV check and level
57
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
58
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
59
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
60
+ */
61
+ addShadowsocksUser(data: IAddShadowsocksUser): Promise<ISdkResponse<AddUserResponseModel>>;
62
+ /**
63
+ * Adds a new Shadowsocks 2022 user to a specified inbound handler.
64
+ *
65
+ * @param {IAddShadowsocks2022User} data - The user data containing tag, username, key and level
66
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
67
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
68
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
69
+ */
70
+ addShadowsocks2022User(data: IAddShadowsocks2022User): Promise<ISdkResponse<AddUserResponseModel>>;
71
+ /**
72
+ * Adds a new SOCKS user to a specified inbound handler.
73
+ *
74
+ * @param {IAddSocksUser} data - The user data containing tag, username, SOCKS username, SOCKS password and level
75
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
76
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
77
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
78
+ */
79
+ addSocksUser(data: IAddSocksUser): Promise<ISdkResponse<AddUserResponseModel>>;
80
+ /**
81
+ * Adds a new HTTP user to a specified inbound handler.
82
+ *
83
+ * @param {IAddHttpUser} data - The user data containing tag, username, HTTP username, HTTP password and level
84
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
85
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
86
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
87
+ */
88
+ addHttpUser(data: IAddHttpUser): Promise<ISdkResponse<AddUserResponseModel>>;
89
+ /**
90
+ * Removes a user from a specified inbound handler.
91
+ *
92
+ * @param {string} tag - The tag identifying the inbound handler
93
+ * @param {string} username - The username/email of the user to remove
94
+ * @returns {Promise<ISdkResponse<RemoveUserResponseModel>>} A promise that resolves to:
95
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was removed
96
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
97
+ */
98
+ removeUser(tag: string, username: string): Promise<ISdkResponse<RemoveUserResponseModel>>;
99
+ /**
100
+ * Gets the count of users in a specified inbound handler.
101
+ *
102
+ * @param {string} tag - The tag identifying the inbound handler
103
+ * @returns {Promise<ISdkResponse<number>>} A promise that resolves to:
104
+ * - On success: An object with `isOk: true` and `data` containing the user count
105
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
106
+ */
107
+ getInboundUsersCount(tag: string): Promise<ISdkResponse<number>>;
108
+ }
1
109
  //# sourceMappingURL=handler.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.service.d.ts","sourceRoot":"","sources":["../../../src/handler/handler.service.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"handler.service.d.ts","sourceRoot":"","sources":["../../../src/handler/handler.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,WAAW,CAAC;AASlD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EACH,YAAY,EACZ,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,aAAa,EAChB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,iDAAiD,CAAC;AAE1F;;GAEG;AACH,qBAAa,cAAc;IAGX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAEjB,OAAO,EAAE,OAAO;IAI7C;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,4BAA4B,CAAC,CAAC;IAoB9F;;;;;;;OAOG;IACU,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAuC7F;;;;;;;OAOG;IACU,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAyC3F;;;;;;;OAOG;IACU,kBAAkB,CAC3B,IAAI,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAyC9C;;;;;;;OAOG;IACU,sBAAsB,CAC/B,IAAI,EAAE,uBAAuB,GAC9B,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAuC9C;;;;;;;OAOG;IACU,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAwC3F;;;;;;;OAOG;IACU,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IAwCzF;;;;;;;;OAQG;IACU,UAAU,CACnB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC;IA+BjD;;;;;;;OAOG;IACU,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;CAkBhF"}
@@ -1 +1,403 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HandlerService = void 0;
7
+ const nice_grpc_1 = require("nice-grpc");
8
+ const command_1 = require("../xray-protos/app/proxyman/command/command");
9
+ const user_1 = require("../xray-protos/common/protocol/user");
10
+ const create_typed_message_1 = __importDefault(require("../common/utils/create-typed-message/create-typed-message"));
11
+ const errors_1 = require("../common/errors");
12
+ const models_1 = require("./models");
13
+ const config_1 = require("../xray-protos/proxy/trojan/config");
14
+ const account_1 = require("../xray-protos/proxy/vless/account");
15
+ const config_2 = require("../xray-protos/proxy/shadowsocks/config");
16
+ const config_3 = require("../xray-protos/proxy/shadowsocks_2022/config");
17
+ const config_4 = require("../xray-protos/proxy/socks/config");
18
+ const config_5 = require("../xray-protos/proxy/http/config");
19
+ const remove_user_response_model_1 = require("./models/remove-user/remove-user.response.model");
20
+ /**
21
+ * Service for managing Xray inbound handlers and their users
22
+ */
23
+ class HandlerService {
24
+ constructor(channel) {
25
+ this.channel = channel;
26
+ this.client = (0, nice_grpc_1.createClient)(command_1.HandlerServiceDefinition, channel);
27
+ }
28
+ /**
29
+ * Retrieves all users from a specified inbound handler.
30
+ * This method fetches user information including their credentials and metadata from the Xray server.
31
+ *
32
+ * @param {string} tag - The tag identifying the inbound handler to query
33
+ * @returns {Promise<ISdkResponse<GetInboundUsersResponseModel>>} A promise that resolves to:
34
+ * - On success: An object with `isOk: true` and `data` containing an array of decoded user information
35
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const handler = new HandlerService(channel);
40
+ * const response = await handler.getInboundUsers('Personal');
41
+ *
42
+ * if (response.isOk) {
43
+ * console.log(response.data.users); // Array of DecodedUser objects
44
+ * } else {
45
+ * console.error(response.message); // Error message
46
+ * }
47
+ * ```
48
+ */
49
+ async getInboundUsers(tag) {
50
+ try {
51
+ const response = await this.client.getInboundUsers({ tag });
52
+ return {
53
+ isOk: true,
54
+ data: new models_1.GetInboundUsersResponseModel(response.users),
55
+ };
56
+ }
57
+ catch (error) {
58
+ let message = '';
59
+ if (error instanceof Error) {
60
+ message = error.message;
61
+ }
62
+ return {
63
+ isOk: false,
64
+ ...errors_1.HANDLER_ERRORS.GET_ALL_USERS_ERROR(message),
65
+ };
66
+ }
67
+ }
68
+ /**
69
+ * Adds a new Trojan user to a specified inbound handler.
70
+ *
71
+ * @param {IAddTrojanUser} data - The user data containing tag, username, password and level
72
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
73
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
74
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
75
+ */
76
+ async addTrojanUser(data) {
77
+ try {
78
+ const response = await this.client.alterInbound({
79
+ tag: data.tag,
80
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
81
+ user: user_1.User.create({
82
+ email: data.username,
83
+ level: data.level,
84
+ account: (0, create_typed_message_1.default)(config_1.Account, {
85
+ password: data.password,
86
+ }),
87
+ }),
88
+ }),
89
+ });
90
+ return {
91
+ isOk: true,
92
+ data: new models_1.AddUserResponseModel(true),
93
+ };
94
+ }
95
+ catch (error) {
96
+ let message = '';
97
+ if (error instanceof Error) {
98
+ message = error.message;
99
+ }
100
+ if (message.includes('already exists')) {
101
+ return {
102
+ isOk: true,
103
+ data: new models_1.AddUserResponseModel(false),
104
+ };
105
+ }
106
+ return {
107
+ isOk: false,
108
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
109
+ };
110
+ }
111
+ }
112
+ /**
113
+ * Adds a new VLESS user to a specified inbound handler.
114
+ *
115
+ * @param {IAddVlessUser} data - The user data containing tag, username, UUID, flow and level
116
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
117
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
118
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
119
+ */
120
+ async addVlessUser(data) {
121
+ try {
122
+ const response = await this.client.alterInbound({
123
+ tag: data.tag,
124
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
125
+ user: user_1.User.create({
126
+ email: data.username,
127
+ level: data.level,
128
+ account: (0, create_typed_message_1.default)(account_1.Account, {
129
+ id: data.uuid,
130
+ flow: data.flow,
131
+ encryption: 'none',
132
+ }),
133
+ }),
134
+ }),
135
+ });
136
+ return {
137
+ isOk: true,
138
+ data: new models_1.AddUserResponseModel(true),
139
+ };
140
+ }
141
+ catch (error) {
142
+ let message = '';
143
+ if (error instanceof Error) {
144
+ message = error.message;
145
+ }
146
+ if (message.includes('already exists')) {
147
+ return {
148
+ isOk: true,
149
+ data: new models_1.AddUserResponseModel(false),
150
+ };
151
+ }
152
+ return {
153
+ isOk: false,
154
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
155
+ };
156
+ }
157
+ }
158
+ /**
159
+ * Adds a new Shadowsocks user to a specified inbound handler.
160
+ *
161
+ * @param {IAddShadowsocksUser} data - The user data containing tag, username, password, cipher type, IV check and level
162
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
163
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
164
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
165
+ */
166
+ async addShadowsocksUser(data) {
167
+ try {
168
+ const response = await this.client.alterInbound({
169
+ tag: data.tag,
170
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
171
+ user: user_1.User.create({
172
+ email: data.username,
173
+ level: data.level,
174
+ account: (0, create_typed_message_1.default)(config_2.Account, {
175
+ password: data.password,
176
+ cipherType: data.cipherType,
177
+ ivCheck: data.ivCheck,
178
+ }),
179
+ }),
180
+ }),
181
+ });
182
+ return {
183
+ isOk: true,
184
+ data: new models_1.AddUserResponseModel(true),
185
+ };
186
+ }
187
+ catch (error) {
188
+ let message = '';
189
+ if (error instanceof Error) {
190
+ message = error.message;
191
+ }
192
+ if (message.includes('already exists')) {
193
+ return {
194
+ isOk: true,
195
+ data: new models_1.AddUserResponseModel(false),
196
+ };
197
+ }
198
+ return {
199
+ isOk: false,
200
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
201
+ };
202
+ }
203
+ }
204
+ /**
205
+ * Adds a new Shadowsocks 2022 user to a specified inbound handler.
206
+ *
207
+ * @param {IAddShadowsocks2022User} data - The user data containing tag, username, key and level
208
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
209
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
210
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
211
+ */
212
+ async addShadowsocks2022User(data) {
213
+ try {
214
+ const response = await this.client.alterInbound({
215
+ tag: data.tag,
216
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
217
+ user: user_1.User.create({
218
+ email: data.username,
219
+ level: data.level,
220
+ account: (0, create_typed_message_1.default)(config_3.Account, {
221
+ key: data.key,
222
+ }),
223
+ }),
224
+ }),
225
+ });
226
+ return {
227
+ isOk: true,
228
+ data: new models_1.AddUserResponseModel(true),
229
+ };
230
+ }
231
+ catch (error) {
232
+ let message = '';
233
+ if (error instanceof Error) {
234
+ message = error.message;
235
+ }
236
+ if (message.includes('already exists')) {
237
+ return {
238
+ isOk: true,
239
+ data: new models_1.AddUserResponseModel(false),
240
+ };
241
+ }
242
+ return {
243
+ isOk: false,
244
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
245
+ };
246
+ }
247
+ }
248
+ /**
249
+ * Adds a new SOCKS user to a specified inbound handler.
250
+ *
251
+ * @param {IAddSocksUser} data - The user data containing tag, username, SOCKS username, SOCKS password and level
252
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
253
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
254
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
255
+ */
256
+ async addSocksUser(data) {
257
+ try {
258
+ const response = await this.client.alterInbound({
259
+ tag: data.tag,
260
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
261
+ user: user_1.User.create({
262
+ email: data.username,
263
+ level: data.level,
264
+ account: (0, create_typed_message_1.default)(config_4.Account, {
265
+ username: data.socks_username,
266
+ password: data.socks_password,
267
+ }),
268
+ }),
269
+ }),
270
+ });
271
+ return {
272
+ isOk: true,
273
+ data: new models_1.AddUserResponseModel(true),
274
+ };
275
+ }
276
+ catch (error) {
277
+ let message = '';
278
+ if (error instanceof Error) {
279
+ message = error.message;
280
+ }
281
+ if (message.includes('already exists')) {
282
+ return {
283
+ isOk: true,
284
+ data: new models_1.AddUserResponseModel(false),
285
+ };
286
+ }
287
+ return {
288
+ isOk: false,
289
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
290
+ };
291
+ }
292
+ }
293
+ /**
294
+ * Adds a new HTTP user to a specified inbound handler.
295
+ *
296
+ * @param {IAddHttpUser} data - The user data containing tag, username, HTTP username, HTTP password and level
297
+ * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to:
298
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was added
299
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
300
+ */
301
+ async addHttpUser(data) {
302
+ try {
303
+ const response = await this.client.alterInbound({
304
+ tag: data.tag,
305
+ operation: (0, create_typed_message_1.default)(command_1.AddUserOperation, {
306
+ user: user_1.User.create({
307
+ email: data.username,
308
+ level: data.level,
309
+ account: (0, create_typed_message_1.default)(config_5.Account, {
310
+ username: data.http_username,
311
+ password: data.http_password,
312
+ }),
313
+ }),
314
+ }),
315
+ });
316
+ return {
317
+ isOk: true,
318
+ data: new models_1.AddUserResponseModel(true),
319
+ };
320
+ }
321
+ catch (error) {
322
+ let message = '';
323
+ if (error instanceof Error) {
324
+ message = error.message;
325
+ }
326
+ if (message.includes('already exists')) {
327
+ return {
328
+ isOk: true,
329
+ data: new models_1.AddUserResponseModel(false),
330
+ };
331
+ }
332
+ return {
333
+ isOk: false,
334
+ ...errors_1.HANDLER_ERRORS.ADD_USER_ERROR(message),
335
+ };
336
+ }
337
+ }
338
+ /**
339
+ * Removes a user from a specified inbound handler.
340
+ *
341
+ * @param {string} tag - The tag identifying the inbound handler
342
+ * @param {string} username - The username/email of the user to remove
343
+ * @returns {Promise<ISdkResponse<RemoveUserResponseModel>>} A promise that resolves to:
344
+ * - On success: An object with `isOk: true` and `data.success` indicating if user was removed
345
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
346
+ */
347
+ async removeUser(tag, username) {
348
+ try {
349
+ const response = await this.client.alterInbound({
350
+ tag: tag,
351
+ operation: (0, create_typed_message_1.default)(command_1.RemoveUserOperation, { email: username }),
352
+ });
353
+ return {
354
+ isOk: true,
355
+ data: new remove_user_response_model_1.RemoveUserResponseModel(true),
356
+ };
357
+ }
358
+ catch (error) {
359
+ let message = '';
360
+ if (error instanceof Error) {
361
+ message = error.message;
362
+ }
363
+ if (message.includes('not found')) {
364
+ return {
365
+ isOk: true,
366
+ data: new remove_user_response_model_1.RemoveUserResponseModel(false),
367
+ };
368
+ }
369
+ return {
370
+ isOk: false,
371
+ ...errors_1.HANDLER_ERRORS.REMOVE_USER_ERROR(message),
372
+ };
373
+ }
374
+ }
375
+ /**
376
+ * Gets the count of users in a specified inbound handler.
377
+ *
378
+ * @param {string} tag - The tag identifying the inbound handler
379
+ * @returns {Promise<ISdkResponse<number>>} A promise that resolves to:
380
+ * - On success: An object with `isOk: true` and `data` containing the user count
381
+ * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS
382
+ */
383
+ async getInboundUsersCount(tag) {
384
+ try {
385
+ const response = await this.client.getInboundUsersCount({ tag });
386
+ return {
387
+ isOk: true,
388
+ data: response.count,
389
+ };
390
+ }
391
+ catch (error) {
392
+ let message = '';
393
+ if (error instanceof Error) {
394
+ message = error.message;
395
+ }
396
+ return {
397
+ isOk: false,
398
+ ...errors_1.HANDLER_ERRORS.GET_INBOUND_USERS_COUNT_ERROR(message),
399
+ };
400
+ }
401
+ }
402
+ }
403
+ exports.HandlerService = HandlerService;
@@ -0,0 +1,8 @@
1
+ export interface IAddHttpUser {
2
+ tag: string;
3
+ username: string;
4
+ level: number;
5
+ http_username: string;
6
+ http_password: string;
7
+ }
8
+ //# sourceMappingURL=add-http-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-http-user.interface.d.ts","sourceRoot":"","sources":["../../../../../src/handler/interfaces/add-user/add-http-user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { CipherType } from '../../../xray-protos/proxy/shadowsocks/config';
2
+ export interface IAddShadowsocksUser {
3
+ tag: string;
4
+ username: string;
5
+ level: number;
6
+ password: string;
7
+ cipherType: CipherType;
8
+ ivCheck: boolean;
9
+ }
10
+ //# sourceMappingURL=add-shadowsocks-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-shadowsocks-user.interface.d.ts","sourceRoot":"","sources":["../../../../../src/handler/interfaces/add-user/add-shadowsocks-user.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAE3E,MAAM,WAAW,mBAAmB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface IAddShadowsocks2022User {
2
+ username: string;
3
+ level: number;
4
+ key: string;
5
+ tag: string;
6
+ }
7
+ //# sourceMappingURL=add-shadowsocks2022-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-shadowsocks2022-user.interface.d.ts","sourceRoot":"","sources":["../../../../../src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface IAddSocksUser {
2
+ username: string;
3
+ level: number;
4
+ socks_username: string;
5
+ socks_password: string;
6
+ tag: string;
7
+ }
8
+ //# sourceMappingURL=add-socks-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-socks-user.interface.d.ts","sourceRoot":"","sources":["../../../../../src/handler/interfaces/add-user/add-socks-user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface IAddTrojanUser {
2
+ username: string;
3
+ level: number;
4
+ password: string;
5
+ tag: string;
6
+ }
7
+ //# sourceMappingURL=add-trojan-user.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-trojan-user.interface.d.ts","sourceRoot":"","sources":["../../../../../src/handler/interfaces/add-user/add-trojan-user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACf"}