@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.
- package/README.md +164 -53
- 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/build/tests/stats.spec.d.ts +2 -0
- package/build/tests/stats.spec.d.ts.map +1 -0
- package/build/tests/stats.spec.js +86 -0
- package/package.json +43 -4
package/README.md
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
# XTLS
|
|
1
|
+
# XTLS SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
4
5
|
|
|
5
|
-
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+

|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
A TypeScript SDK for interacting with XRAY (XTLS) Core via gRPC API. This package provides a type-safe interface for managing and monitoring your XRAY server, including statistics, user management, and connection information.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- 🔒 Type-safe API interactions
|
|
22
|
+
- 📊 Comprehensive statistics monitoring
|
|
23
|
+
- 👥 User management capabilities
|
|
24
|
+
- 🔄 Connection monitoring
|
|
25
|
+
- ⚡ Async/Promise-based API
|
|
26
|
+
- 📝 Detailed error handling
|
|
6
27
|
|
|
7
28
|
## Installation
|
|
8
29
|
|
|
@@ -10,95 +31,185 @@ This package provides a simple and type-safe way to retrieve various statistics
|
|
|
10
31
|
npm install @remnawave/xtls-sdk
|
|
11
32
|
# or
|
|
12
33
|
yarn add @remnawave/xtls-sdk
|
|
34
|
+
# or
|
|
35
|
+
pnpm add @remnawave/xtls-sdk
|
|
13
36
|
```
|
|
14
37
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Basic Setup
|
|
38
|
+
## Quick Start
|
|
18
39
|
|
|
19
40
|
```typescript
|
|
20
41
|
import { XtlsApi } from '@remnawave/xtls-sdk';
|
|
21
42
|
|
|
22
|
-
//
|
|
23
|
-
const
|
|
43
|
+
// Initialize the API client
|
|
44
|
+
const api = new XtlsApi('127.0.0.1', '10085');
|
|
45
|
+
|
|
46
|
+
// Example: Get system statistics
|
|
47
|
+
const stats = await api.stats.getSysStats();
|
|
48
|
+
if (stats.isOk) {
|
|
49
|
+
console.log('System Stats:', stats.data);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Core Features
|
|
54
|
+
|
|
55
|
+
### Statistics Management
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// System Statistics
|
|
59
|
+
const sysStats = await api.stats.getSysStats();
|
|
60
|
+
|
|
61
|
+
// User Statistics
|
|
62
|
+
const userStats = await api.stats.getUserStats('username');
|
|
63
|
+
const allUsers = await api.stats.getAllUsersStats();
|
|
64
|
+
const isOnline = await api.stats.getUserOnlineStatus('username');
|
|
65
|
+
|
|
66
|
+
// Traffic Statistics
|
|
67
|
+
const inbounds = await api.stats.getAllInboundsStats();
|
|
68
|
+
const outbounds = await api.stats.getAllOutboundsStats();
|
|
24
69
|
```
|
|
25
70
|
|
|
26
|
-
###
|
|
71
|
+
### Response Handling
|
|
27
72
|
|
|
28
|
-
|
|
73
|
+
All API methods return a standardized response format:
|
|
29
74
|
|
|
30
75
|
```typescript
|
|
31
|
-
|
|
76
|
+
interface ISdkResponse<T> {
|
|
77
|
+
isOk: boolean;
|
|
78
|
+
data?: T;
|
|
79
|
+
message?: string;
|
|
80
|
+
code?: string;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Example usage:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const response = await api.stats.getSysStats();
|
|
32
88
|
|
|
33
89
|
if (response.isOk) {
|
|
34
|
-
|
|
90
|
+
// Success case
|
|
91
|
+
console.log('Stats:', response.data);
|
|
35
92
|
} else {
|
|
36
|
-
|
|
93
|
+
// Error case
|
|
94
|
+
console.error(`Error ${response.code}: ${response.message}`);
|
|
37
95
|
}
|
|
38
96
|
```
|
|
39
97
|
|
|
40
|
-
|
|
98
|
+
### Reset Options
|
|
99
|
+
|
|
100
|
+
Many methods support statistics reset functionality:
|
|
41
101
|
|
|
42
102
|
```typescript
|
|
43
|
-
// Get stats
|
|
44
|
-
const
|
|
103
|
+
// Get stats and reset counters
|
|
104
|
+
const stats = await api.stats.getUserStats('username', true);
|
|
105
|
+
```
|
|
45
106
|
|
|
46
|
-
|
|
47
|
-
const userStats = await xtlsApi.stats.getUserStats('username123');
|
|
107
|
+
## API Reference
|
|
48
108
|
|
|
49
|
-
|
|
50
|
-
const onlineStatus = await xtlsApi.stats.getUserOnlineStatus('username123');
|
|
51
|
-
```
|
|
109
|
+
### XtlsApi
|
|
52
110
|
|
|
53
|
-
|
|
111
|
+
Main client class for interacting with the XRAY server.
|
|
54
112
|
|
|
55
113
|
```typescript
|
|
56
|
-
|
|
57
|
-
|
|
114
|
+
const api = new XtlsApi(ip: string, port: string);
|
|
115
|
+
```
|
|
58
116
|
|
|
59
|
-
|
|
60
|
-
const inbound = await xtlsApi.stats.getInboundStats('http_in');
|
|
117
|
+
### HandlerService
|
|
61
118
|
|
|
62
|
-
|
|
63
|
-
const outbounds = await xtlsApi.stats.getAllOutboundsStats();
|
|
119
|
+
Service for managing inbound handlers and their users.
|
|
64
120
|
|
|
65
|
-
|
|
66
|
-
const outbound = await xtlsApi.stats.getOutboundStats('http_out');
|
|
67
|
-
```
|
|
121
|
+
#### User Management Methods
|
|
68
122
|
|
|
69
|
-
|
|
123
|
+
| Method | Description | Parameters |
|
|
124
|
+
| ------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
|
|
125
|
+
| `getInboundUsers(tag: string)` | Get all users from an inbound | `tag`: Inbound handler tag |
|
|
126
|
+
| `getInboundUsersCount(tag: string)` | Get count of users in an inbound | `tag`: Inbound handler tag |
|
|
127
|
+
| `removeUser(tag: string, username: string)` | Remove a user from an inbound | `tag`: Inbound handler tag<br>`username`: User to remove |
|
|
70
128
|
|
|
71
|
-
|
|
129
|
+
#### Add User Methods
|
|
130
|
+
|
|
131
|
+
| Method | Description | Parameters |
|
|
132
|
+
| ------------------------------------------------------- | ------------------------- | ---------------------------------------------------------------- |
|
|
133
|
+
| `addTrojanUser(data: IAddTrojanUser)` | Add Trojan user | `data`: { tag, username, password, level } |
|
|
134
|
+
| `addVlessUser(data: IAddVlessUser)` | Add VLESS user | `data`: { tag, username, uuid, flow, level } |
|
|
135
|
+
| `addShadowsocksUser(data: IAddShadowsocksUser)` | Add Shadowsocks user | `data`: { tag, username, password, cipherType, ivCheck, level } |
|
|
136
|
+
| `addShadowsocks2022User(data: IAddShadowsocks2022User)` | Add Shadowsocks 2022 user | `data`: { tag, username, key, level } |
|
|
137
|
+
| `addSocksUser(data: IAddSocksUser)` | Add SOCKS user | `data`: { tag, username, socks_username, socks_password, level } |
|
|
138
|
+
| `addHttpUser(data: IAddHttpUser)` | Add HTTP user | `data`: { tag, username, http_username, http_password, level } |
|
|
139
|
+
|
|
140
|
+
Example usage:
|
|
72
141
|
|
|
73
142
|
```typescript
|
|
74
|
-
// Get
|
|
75
|
-
const
|
|
143
|
+
// Get all users in an inbound
|
|
144
|
+
const users = await api.handler.getInboundUsers('main-inbound');
|
|
145
|
+
if (users.isOk) {
|
|
146
|
+
console.log('Users:', users.data.users);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Add a new Trojan user
|
|
150
|
+
const newUser = await api.handler.addTrojanUser({
|
|
151
|
+
tag: 'main-inbound',
|
|
152
|
+
username: 'user@example.com',
|
|
153
|
+
password: 'secure-password',
|
|
154
|
+
level: 0,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Remove a user
|
|
158
|
+
const removed = await api.handler.removeUser('main-inbound', 'user@example.com');
|
|
159
|
+
|
|
160
|
+
// Get user count
|
|
161
|
+
const count = await api.handler.getInboundUsersCount('main-inbound');
|
|
162
|
+
if (count.isOk) {
|
|
163
|
+
console.log('Total users:', count.data);
|
|
164
|
+
}
|
|
76
165
|
```
|
|
77
166
|
|
|
78
|
-
|
|
167
|
+
### StatsService
|
|
79
168
|
|
|
80
|
-
|
|
169
|
+
Statistics management service.
|
|
81
170
|
|
|
82
|
-
|
|
171
|
+
| Method | Description | Parameters |
|
|
172
|
+
| ----------------------------------------------------- | -------------------------------- | ---------------------------------------------------------------- |
|
|
173
|
+
| `getSysStats()` | Get system statistics | None |
|
|
174
|
+
| `getAllUsersStats(reset?: boolean)` | Get all users' statistics | `reset`: Reset stats after retrieval |
|
|
175
|
+
| `getUserStats(username: string, reset?: boolean)` | Get specific user statistics | `username`: Target user<br>`reset`: Reset stats after retrieval |
|
|
176
|
+
| `getUserOnlineStatus(username: string)` | Check user online status | `username`: Target user |
|
|
177
|
+
| `getAllInboundsStats(reset?: boolean)` | Get all inbound statistics | `reset`: Reset stats after retrieval |
|
|
178
|
+
| `getInboundStats(inbound: string, reset?: boolean)` | Get specific inbound statistics | `inbound`: Inbound tag<br>`reset`: Reset stats after retrieval |
|
|
179
|
+
| `getAllOutboundsStats(reset?: boolean)` | Get all outbound statistics | `reset`: Reset stats after retrieval |
|
|
180
|
+
| `getOutboundStats(outbound: string, reset?: boolean)` | Get specific outbound statistics | `outbound`: Outbound tag<br>`reset`: Reset stats after retrieval |
|
|
83
181
|
|
|
84
|
-
|
|
182
|
+
## Error Handling
|
|
183
|
+
|
|
184
|
+
The SDK provides detailed error information through the response object:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
try {
|
|
188
|
+
const response = await api.stats.getUserStats('username');
|
|
189
|
+
if (!response.isOk) {
|
|
190
|
+
console.error(`Operation failed: ${response.message}`);
|
|
191
|
+
console.error(`Error code: ${response.code}`);
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error('Unexpected error:', error);
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
# Contributors
|
|
85
199
|
|
|
86
|
-
|
|
87
|
-
- `getAllUsersStats(reset?: boolean)`: Get statistics for all users
|
|
88
|
-
- `getUserStats(username: string, reset?: boolean)`: Get statistics for a specific user
|
|
89
|
-
- `getUserOnlineStatus(username: string)`: Check if a user is currently online
|
|
90
|
-
- `getAllInboundsStats(reset?: boolean)`: Get statistics for all inbound connections
|
|
91
|
-
- `getInboundStats(inbound: string, reset?: boolean)`: Get statistics for a specific inbound connection
|
|
92
|
-
- `getAllOutboundsStats(reset?: boolean)`: Get statistics for all outbound connections
|
|
93
|
-
- `getOutboundStats(outbound: string, reset?: boolean)`: Get statistics for a specific outbound connection
|
|
200
|
+
We ❤️🔥 contributors! If you'd like to contribute, please check out our [Contributing Guidelines](CONTRIBUTING.md) and feel free to submit a pull request or open an issue.
|
|
94
201
|
|
|
95
|
-
|
|
202
|
+
Check [open issues](https://github.com/remnawave/xtls-sdk/issues) to help the progress of this project.
|
|
96
203
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
204
|
+
<p align="center">
|
|
205
|
+
Thanks to the all contributors who have helped improve XTLS SDK:
|
|
206
|
+
</p>
|
|
207
|
+
<p align="center">
|
|
208
|
+
<a href="https://github.com/remnawave/xtls-sdk/graphs/contributors">
|
|
209
|
+
<img src="https://contrib.rocks/image?repo=remnawave/xtls-sdk" />
|
|
210
|
+
</a>
|
|
211
|
+
</p>
|
|
101
212
|
|
|
102
213
|
## License
|
|
103
214
|
|
|
104
|
-
MIT
|
|
215
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -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"}
|