@remnawave/xtls-sdk 0.0.1 → 0.0.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/build/src/common/errors/handler/handler.errors.d.ts +23 -0
- package/build/src/common/errors/handler/handler.errors.d.ts.map +1 -0
- package/build/src/common/errors/handler/handler.errors.js +22 -0
- package/build/src/common/errors/handler/index.d.ts +2 -0
- package/build/src/common/errors/handler/index.d.ts.map +1 -0
- package/build/src/common/errors/handler/index.js +17 -0
- package/build/src/common/errors/index.d.ts +1 -0
- package/build/src/common/errors/index.d.ts.map +1 -1
- package/build/src/common/errors/index.js +1 -0
- package/build/src/common/utils/create-typed-message/create-typed-message.d.ts +5 -0
- package/build/src/common/utils/create-typed-message/create-typed-message.d.ts.map +1 -0
- package/build/src/common/utils/create-typed-message/create-typed-message.js +10 -0
- package/build/src/common/utils/decode-user/constants/account-types.d.ts +39 -0
- package/build/src/common/utils/decode-user/constants/account-types.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/constants/account-types.js +59 -0
- package/build/src/common/utils/decode-user/constants/index.d.ts +2 -0
- package/build/src/common/utils/decode-user/constants/index.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/constants/index.js +17 -0
- package/build/src/common/utils/decode-user/decode-user.d.ts +37 -0
- package/build/src/common/utils/decode-user/decode-user.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/decode-user.js +56 -0
- package/build/src/common/utils/decode-user/types/account-type-keys.type.d.ts +3 -0
- package/build/src/common/utils/decode-user/types/account-type-keys.type.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/types/account-type-keys.type.js +2 -0
- package/build/src/common/utils/decode-user/types/account-type-mapping.type.d.ts +4 -0
- package/build/src/common/utils/decode-user/types/account-type-mapping.type.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/types/account-type-mapping.type.js +2 -0
- package/build/src/common/utils/decode-user/types/decoded-user.type.d.ts +18 -0
- package/build/src/common/utils/decode-user/types/decoded-user.type.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/types/decoded-user.type.js +2 -0
- package/build/src/common/utils/decode-user/types/index.d.ts +4 -0
- package/build/src/common/utils/decode-user/types/index.d.ts.map +1 -0
- package/build/src/common/utils/decode-user/types/index.js +19 -0
- package/build/src/handler/handler.service.d.ts +108 -0
- package/build/src/handler/handler.service.d.ts.map +1 -1
- package/build/src/handler/handler.service.js +402 -0
- package/build/src/handler/interfaces/add-user/add-http-user.interface.d.ts +8 -0
- package/build/src/handler/interfaces/add-user/add-http-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-http-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.d.ts +10 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.d.ts +7 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/add-socks-user.interface.d.ts +8 -0
- package/build/src/handler/interfaces/add-user/add-socks-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-socks-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/add-trojan-user.interface.d.ts +7 -0
- package/build/src/handler/interfaces/add-user/add-trojan-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-trojan-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/add-vless-user.interface.d.ts +8 -0
- package/build/src/handler/interfaces/add-user/add-vless-user.interface.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/add-vless-user.interface.js +2 -0
- package/build/src/handler/interfaces/add-user/index.d.ts +7 -0
- package/build/src/handler/interfaces/add-user/index.d.ts.map +1 -0
- package/build/src/handler/interfaces/add-user/index.js +22 -0
- package/build/src/handler/interfaces/index.d.ts +2 -0
- package/build/src/handler/interfaces/index.d.ts.map +1 -0
- package/build/src/handler/interfaces/index.js +17 -0
- package/build/src/handler/models/add-user/add-user.response.model.d.ts +5 -0
- package/build/src/handler/models/add-user/add-user.response.model.d.ts.map +1 -0
- package/build/src/handler/models/add-user/add-user.response.model.js +9 -0
- package/build/src/handler/models/add-user/index.d.ts +2 -0
- package/build/src/handler/models/add-user/index.d.ts.map +1 -0
- package/build/src/handler/models/add-user/index.js +17 -0
- package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.d.ts +7 -0
- package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.d.ts.map +1 -0
- package/build/src/handler/models/get-inbound-users/get-inbound-users.response.model.js +10 -0
- package/build/src/handler/models/get-inbound-users/index.d.ts +2 -0
- package/build/src/handler/models/get-inbound-users/index.d.ts.map +1 -0
- package/build/src/handler/models/get-inbound-users/index.js +17 -0
- package/build/src/handler/models/index.d.ts +4 -0
- package/build/src/handler/models/index.d.ts.map +1 -0
- package/build/src/handler/models/index.js +19 -0
- package/build/src/handler/models/remove-user/index.d.ts +2 -0
- package/build/src/handler/models/remove-user/index.d.ts.map +1 -0
- package/build/src/handler/models/remove-user/index.js +17 -0
- package/build/src/handler/models/remove-user/remove-user.response.model.d.ts +5 -0
- package/build/src/handler/models/remove-user/remove-user.response.model.d.ts.map +1 -0
- package/build/src/handler/models/remove-user/remove-user.response.model.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const HANDLER_ERRORS: {
|
|
2
|
+
readonly UNKNOWN_ERROR: {
|
|
3
|
+
readonly code: "A001";
|
|
4
|
+
readonly message: "Unexpected error";
|
|
5
|
+
};
|
|
6
|
+
readonly GET_ALL_USERS_ERROR: (message: string) => {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
readonly ADD_USER_ERROR: (message: string) => {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
readonly REMOVE_USER_ERROR: (message: string) => {
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
readonly GET_INBOUND_USERS_COUNT_ERROR: (message: string) => {
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=handler.errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.errors.d.ts","sourceRoot":"","sources":["../../../../../src/common/errors/handler/handler.errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;4CAEQ,MAAM;;;;uCAIX,MAAM;;;;0CAIH,MAAM;;;;sDAIM,MAAM;;;;CAIzC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HANDLER_ERRORS = void 0;
|
|
4
|
+
exports.HANDLER_ERRORS = {
|
|
5
|
+
UNKNOWN_ERROR: { code: 'A001', message: 'Unexpected error' },
|
|
6
|
+
GET_ALL_USERS_ERROR: (message) => ({
|
|
7
|
+
code: 'A002',
|
|
8
|
+
message: `Error getting all users: ${message}`,
|
|
9
|
+
}),
|
|
10
|
+
ADD_USER_ERROR: (message) => ({
|
|
11
|
+
code: 'A003',
|
|
12
|
+
message: `Error adding user: ${message}`,
|
|
13
|
+
}),
|
|
14
|
+
REMOVE_USER_ERROR: (message) => ({
|
|
15
|
+
code: 'A004',
|
|
16
|
+
message: `Error removing user: ${message}`,
|
|
17
|
+
}),
|
|
18
|
+
GET_INBOUND_USERS_COUNT_ERROR: (message) => ({
|
|
19
|
+
code: 'A005',
|
|
20
|
+
message: `Error getting inbound users count: ${message}`,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/common/errors/handler/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./handler.errors"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TypedMessage } from '../../../xray-protos/common/serial/typed_message';
|
|
2
|
+
import { MessageFns } from '../../../xray-protos/common/serial/typed_message';
|
|
3
|
+
declare function createTypedMessage<T extends MessageFns<unknown, string>>(proto: T, data: Parameters<T['create']>[0]): TypedMessage;
|
|
4
|
+
export default createTypedMessage;
|
|
5
|
+
//# sourceMappingURL=create-typed-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-typed-message.d.ts","sourceRoot":"","sources":["../../../../../src/common/utils/create-typed-message/create-typed-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAE9E,iBAAS,kBAAkB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,EAC7D,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GACjC,YAAY,CAKd;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typed_message_1 = require("../../../xray-protos/common/serial/typed_message");
|
|
4
|
+
function createTypedMessage(proto, data) {
|
|
5
|
+
return typed_message_1.TypedMessage.create({
|
|
6
|
+
type: proto.$type,
|
|
7
|
+
value: proto.encode(proto.create(data)).finish(),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
exports.default = createTypedMessage;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 declare const ACCOUNT_TYPES: {
|
|
8
|
+
readonly "xray.proxy.trojan.Account": {
|
|
9
|
+
readonly decoder: import("../../../../xray-protos/proxy/trojan/config").MessageFns<TrojanAccount, "xray.proxy.trojan.Account">;
|
|
10
|
+
readonly protocol: "trojan";
|
|
11
|
+
readonly getCredentials: (acc: TrojanAccount) => Omit<TrojanAccount, "$type">;
|
|
12
|
+
};
|
|
13
|
+
readonly "xray.proxy.vless.Account": {
|
|
14
|
+
readonly decoder: import("../../../../xray-protos/proxy/vless/account").MessageFns<VlessAccount, "xray.proxy.vless.Account">;
|
|
15
|
+
readonly protocol: "vless";
|
|
16
|
+
readonly getCredentials: (acc: VlessAccount) => Omit<VlessAccount, "$type">;
|
|
17
|
+
};
|
|
18
|
+
readonly "xray.proxy.shadowsocks.Account": {
|
|
19
|
+
readonly decoder: import("../../../../xray-protos/proxy/shadowsocks/config").MessageFns<ShadowsocksAccount, "xray.proxy.shadowsocks.Account">;
|
|
20
|
+
readonly protocol: "shadowsocks";
|
|
21
|
+
readonly getCredentials: (acc: ShadowsocksAccount) => Omit<ShadowsocksAccount, "$type">;
|
|
22
|
+
};
|
|
23
|
+
readonly "xray.proxy.shadowsocks_2022.Account": {
|
|
24
|
+
readonly decoder: import("../../../../xray-protos/proxy/shadowsocks_2022/config").MessageFns<Shadowsocks2022Account, "xray.proxy.shadowsocks_2022.Account">;
|
|
25
|
+
readonly protocol: "shadowsocks2022";
|
|
26
|
+
readonly getCredentials: (acc: Shadowsocks2022Account) => Omit<Shadowsocks2022Account, "$type">;
|
|
27
|
+
};
|
|
28
|
+
readonly "xray.proxy.socks.Account": {
|
|
29
|
+
readonly decoder: import("../../../../xray-protos/proxy/socks/config").MessageFns<SocksAccount, "xray.proxy.socks.Account">;
|
|
30
|
+
readonly protocol: "socks";
|
|
31
|
+
readonly getCredentials: (acc: SocksAccount) => Omit<SocksAccount, "$type">;
|
|
32
|
+
};
|
|
33
|
+
readonly "xray.proxy.http.Account": {
|
|
34
|
+
readonly decoder: import("../../../../xray-protos/proxy/http/config").MessageFns<HttpAccount, "xray.proxy.http.Account">;
|
|
35
|
+
readonly protocol: "http";
|
|
36
|
+
readonly getCredentials: (acc: HttpAccount) => Omit<HttpAccount, "$type">;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=account-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-types.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/constants/account-types.ts"],"names":[],"mappings":"AAAA,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,eAAO,MAAM,aAAa;;;;uCAII,aAAa,KAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC;;;;;uCAO5C,YAAY,KAAG,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC;;;;;uCAS1C,kBAAkB,KAAG,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC;;;;;uCAStD,sBAAsB,KAAG,IAAI,CAAC,sBAAsB,EAAE,OAAO,CAAC;;;;;uCAO9D,YAAY,KAAG,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC;;;;;uCAQ1C,WAAW,KAAG,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC;;CAK5D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACCOUNT_TYPES = void 0;
|
|
4
|
+
const config_1 = require("../../../../xray-protos/proxy/trojan/config");
|
|
5
|
+
const account_1 = require("../../../../xray-protos/proxy/vless/account");
|
|
6
|
+
const config_2 = require("../../../../xray-protos/proxy/shadowsocks/config");
|
|
7
|
+
const config_3 = require("../../../../xray-protos/proxy/shadowsocks_2022/config");
|
|
8
|
+
const config_4 = require("../../../../xray-protos/proxy/socks/config");
|
|
9
|
+
const config_5 = require("../../../../xray-protos/proxy/http/config");
|
|
10
|
+
exports.ACCOUNT_TYPES = {
|
|
11
|
+
[config_1.Account.$type]: {
|
|
12
|
+
decoder: config_1.Account,
|
|
13
|
+
protocol: 'trojan',
|
|
14
|
+
getCredentials: (acc) => ({
|
|
15
|
+
password: acc.password,
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
[account_1.Account.$type]: {
|
|
19
|
+
decoder: account_1.Account,
|
|
20
|
+
protocol: 'vless',
|
|
21
|
+
getCredentials: (acc) => ({
|
|
22
|
+
id: acc.id,
|
|
23
|
+
flow: acc.flow,
|
|
24
|
+
encryption: acc.encryption,
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
[config_2.Account.$type]: {
|
|
28
|
+
decoder: config_2.Account,
|
|
29
|
+
protocol: 'shadowsocks',
|
|
30
|
+
getCredentials: (acc) => ({
|
|
31
|
+
password: acc.password,
|
|
32
|
+
cipherType: acc.cipherType,
|
|
33
|
+
ivCheck: acc.ivCheck,
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
[config_3.Account.$type]: {
|
|
37
|
+
decoder: config_3.Account,
|
|
38
|
+
protocol: 'shadowsocks2022',
|
|
39
|
+
getCredentials: (acc) => ({
|
|
40
|
+
key: acc.key,
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
[config_4.Account.$type]: {
|
|
44
|
+
decoder: config_4.Account,
|
|
45
|
+
protocol: 'socks',
|
|
46
|
+
getCredentials: (acc) => ({
|
|
47
|
+
username: acc.username,
|
|
48
|
+
password: acc.password,
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
[config_5.Account.$type]: {
|
|
52
|
+
decoder: config_5.Account,
|
|
53
|
+
protocol: 'http',
|
|
54
|
+
getCredentials: (acc) => ({
|
|
55
|
+
username: acc.username,
|
|
56
|
+
password: acc.password,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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-types"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { User } from '../../../xray-protos/common/protocol/user';
|
|
2
|
+
import { DecodedUser } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Decodes a User object into a DecodedUser with credentials and metadata.
|
|
5
|
+
* The function extracts account credentials based on the account type and protocol.
|
|
6
|
+
*
|
|
7
|
+
* @param user - The User object to decode, containing account information including:
|
|
8
|
+
* - email: User's email address used as username
|
|
9
|
+
* - level: User's permission level
|
|
10
|
+
* - account: Object containing account type and encoded credentials
|
|
11
|
+
* @returns DecodedUser object containing:
|
|
12
|
+
* - Protocol-specific credentials decoded from the account value
|
|
13
|
+
* - Protocol identifier
|
|
14
|
+
* - Username (from email)
|
|
15
|
+
* - Permission level
|
|
16
|
+
* @throws Error if user object is missing account information
|
|
17
|
+
* @throws Error if account type is not recognized
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const user = {
|
|
21
|
+
* email: "user@example.com",
|
|
22
|
+
* level: 1,
|
|
23
|
+
* account: {
|
|
24
|
+
* type: "standard",
|
|
25
|
+
* value: Buffer.from("...") // Encoded credentials
|
|
26
|
+
* }
|
|
27
|
+
* };
|
|
28
|
+
* const decoded = decodeUser(user);
|
|
29
|
+
* // Returns: {
|
|
30
|
+
* // standard: { ... decoded credentials ... },
|
|
31
|
+
* // protocol: "standard",
|
|
32
|
+
* // username: "user@example.com",
|
|
33
|
+
* // level: 1
|
|
34
|
+
* // }
|
|
35
|
+
*/
|
|
36
|
+
export declare const decodeUser: (user: User) => DecodedUser;
|
|
37
|
+
//# sourceMappingURL=decode-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-user.d.ts","sourceRoot":"","sources":["../../../../../src/common/utils/decode-user/decode-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,2CAA2C,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,UAAU,SAAU,IAAI,KAAG,WAoBvC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeUser = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Decodes a User object into a DecodedUser with credentials and metadata.
|
|
7
|
+
* The function extracts account credentials based on the account type and protocol.
|
|
8
|
+
*
|
|
9
|
+
* @param user - The User object to decode, containing account information including:
|
|
10
|
+
* - email: User's email address used as username
|
|
11
|
+
* - level: User's permission level
|
|
12
|
+
* - account: Object containing account type and encoded credentials
|
|
13
|
+
* @returns DecodedUser object containing:
|
|
14
|
+
* - Protocol-specific credentials decoded from the account value
|
|
15
|
+
* - Protocol identifier
|
|
16
|
+
* - Username (from email)
|
|
17
|
+
* - Permission level
|
|
18
|
+
* @throws Error if user object is missing account information
|
|
19
|
+
* @throws Error if account type is not recognized
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const user = {
|
|
23
|
+
* email: "user@example.com",
|
|
24
|
+
* level: 1,
|
|
25
|
+
* account: {
|
|
26
|
+
* type: "standard",
|
|
27
|
+
* value: Buffer.from("...") // Encoded credentials
|
|
28
|
+
* }
|
|
29
|
+
* };
|
|
30
|
+
* const decoded = decodeUser(user);
|
|
31
|
+
* // Returns: {
|
|
32
|
+
* // standard: { ... decoded credentials ... },
|
|
33
|
+
* // protocol: "standard",
|
|
34
|
+
* // username: "user@example.com",
|
|
35
|
+
* // level: 1
|
|
36
|
+
* // }
|
|
37
|
+
*/
|
|
38
|
+
const decodeUser = (user) => {
|
|
39
|
+
if (!user?.account) {
|
|
40
|
+
throw new Error('Invalid user object: missing account');
|
|
41
|
+
}
|
|
42
|
+
const accountType = user.account.type;
|
|
43
|
+
const accountConfig = constants_1.ACCOUNT_TYPES[accountType];
|
|
44
|
+
if (!accountConfig) {
|
|
45
|
+
throw new Error(`Unknown account type: ${accountType}`);
|
|
46
|
+
}
|
|
47
|
+
const accountBuffer = Buffer.from(user.account.value);
|
|
48
|
+
const decodedAccount = accountConfig.decoder.decode(accountBuffer);
|
|
49
|
+
return {
|
|
50
|
+
[accountConfig.protocol]: accountConfig.getCredentials(decodedAccount),
|
|
51
|
+
protocol: accountConfig.protocol,
|
|
52
|
+
username: user.email,
|
|
53
|
+
level: user.level,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.decodeUser = decodeUser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-type-keys.type.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/types/account-type-keys.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-type-mapping.type.d.ts","sourceRoot":"","sources":["../../../../../../src/common/utils/decode-user/types/account-type-mapping.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,MAAM,kBAAkB,GAAG,UAAU,CACvC,CAAC,OAAO,aAAa,CAAC,CAAC,gBAAgB,CAAC,CAAC,gBAAgB,CAAC,CAC7D,CAAC"}
|
|
@@ -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 @@
|
|
|
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"}
|