@remnawave/backend-contract 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. package/api/controllers/api-tokens.ts +7 -0
  2. package/api/controllers/auth.ts +5 -0
  3. package/api/controllers/hosts.ts +9 -0
  4. package/api/controllers/inbounds.ts +5 -0
  5. package/api/controllers/index.ts +9 -0
  6. package/api/controllers/keygen.ts +5 -0
  7. package/api/controllers/nodes.ts +14 -0
  8. package/api/controllers/subscription.ts +6 -0
  9. package/api/controllers/users.ts +13 -0
  10. package/api/controllers/xray.ts +6 -0
  11. package/api/index.ts +2 -0
  12. package/api/routes.ts +73 -0
  13. package/build/api/controllers/api-tokens.js +9 -0
  14. package/build/api/controllers/auth.js +7 -0
  15. package/build/api/controllers/hosts.js +11 -0
  16. package/build/api/controllers/inbounds.js +7 -0
  17. package/build/api/controllers/index.js +25 -0
  18. package/build/api/controllers/keygen.js +7 -0
  19. package/build/api/controllers/nodes.js +15 -0
  20. package/build/api/controllers/subscription.js +8 -0
  21. package/build/api/controllers/users.js +15 -0
  22. package/build/api/controllers/xray.js +8 -0
  23. package/build/api/index.js +18 -0
  24. package/build/api/routes.js +81 -0
  25. package/build/commands/api-tokens/create.command.js +19 -0
  26. package/build/commands/api-tokens/delete.command.js +15 -0
  27. package/build/commands/api-tokens/find.command.js +13 -0
  28. package/build/commands/api-tokens/index.js +19 -0
  29. package/build/commands/auth/index.js +17 -0
  30. package/build/commands/auth/login.command.js +18 -0
  31. package/build/commands/hosts/create.command.js +50 -0
  32. package/build/commands/hosts/delete.command.js +17 -0
  33. package/build/commands/hosts/index.js +18 -0
  34. package/build/commands/inbounds/get-inbounds.command.js +13 -0
  35. package/build/commands/inbounds/index.js +17 -0
  36. package/build/commands/index.js +25 -0
  37. package/build/commands/keygen/get-pubkey.command.js +14 -0
  38. package/build/commands/keygen/index.js +17 -0
  39. package/build/commands/nodes/create.command.js +36 -0
  40. package/build/commands/nodes/delete.command.js +17 -0
  41. package/build/commands/nodes/disable.command.js +16 -0
  42. package/build/commands/nodes/enable.command.js +16 -0
  43. package/build/commands/nodes/get-all.command.js +13 -0
  44. package/build/commands/nodes/get-one.command.js +16 -0
  45. package/build/commands/nodes/index.js +25 -0
  46. package/build/commands/nodes/restart-all.command.js +14 -0
  47. package/build/commands/nodes/restart.command.js +17 -0
  48. package/build/commands/nodes/update.command.js +38 -0
  49. package/build/commands/subscription/get-subscription-by-short-uuid.command.js +12 -0
  50. package/build/commands/subscription/get-subscription-info-by-short-uuid.command.js +28 -0
  51. package/build/commands/subscription/index.js +18 -0
  52. package/build/commands/users/create-user.command.js +94 -0
  53. package/build/commands/users/delete-user.command.js +17 -0
  54. package/build/commands/users/disable-user.command.ts.js +16 -0
  55. package/build/commands/users/enable-user.command.js +16 -0
  56. package/build/commands/users/get-all-users.command.js +23 -0
  57. package/build/commands/users/get-user-by-short-uuid.command.js +16 -0
  58. package/build/commands/users/get-user-by-subscription-uuid.command.js +16 -0
  59. package/build/commands/users/get-user-by-uuid.command.js +16 -0
  60. package/build/commands/users/index.js +25 -0
  61. package/build/commands/users/revoke-user-subscription.command.js +16 -0
  62. package/build/commands/xray/get-config.command.js +14 -0
  63. package/build/commands/xray/index.js +17 -0
  64. package/build/constants/errors/errors.js +236 -0
  65. package/build/constants/errors/index.js +17 -0
  66. package/build/constants/hosts/alpn.js +9 -0
  67. package/build/constants/hosts/fingerprints.js +15 -0
  68. package/build/constants/hosts/index.js +18 -0
  69. package/build/constants/index.js +22 -0
  70. package/build/constants/nodes/cycle/cycle.js +8 -0
  71. package/build/constants/nodes/cycle/index.js +17 -0
  72. package/build/constants/nodes/index.js +18 -0
  73. package/build/constants/nodes/status/index.js +17 -0
  74. package/build/constants/nodes/status/status.constant.js +9 -0
  75. package/build/constants/roles/index.js +17 -0
  76. package/build/constants/roles/role.js +7 -0
  77. package/build/constants/templates/index.js +18 -0
  78. package/build/constants/templates/template-keys.js +4 -0
  79. package/build/constants/templates/user-statuses.js +9 -0
  80. package/build/constants/users/index.js +18 -0
  81. package/build/constants/users/reset-periods/index.js +17 -0
  82. package/build/constants/users/reset-periods/reset-periods.constant.js +11 -0
  83. package/build/constants/users/status/index.js +17 -0
  84. package/build/constants/users/status/status.constant.js +10 -0
  85. package/build/index.js +20 -0
  86. package/build/models/api-tokens.schema.js +12 -0
  87. package/build/models/auth.schema.js +7 -0
  88. package/build/models/hosts.schema.js +19 -0
  89. package/build/models/inbounds.schema.js +9 -0
  90. package/build/models/index.js +22 -0
  91. package/build/models/nodes.schema.js +28 -0
  92. package/build/models/users.schema.js +34 -0
  93. package/commands/api-tokens/create.command.ts +22 -0
  94. package/commands/api-tokens/delete.command.ts +18 -0
  95. package/commands/api-tokens/find.command.ts +13 -0
  96. package/commands/api-tokens/index.ts +3 -0
  97. package/commands/auth/index.ts +1 -0
  98. package/commands/auth/login.command.ts +20 -0
  99. package/commands/hosts/create.command.ts +52 -0
  100. package/commands/hosts/delete.command.ts +20 -0
  101. package/commands/hosts/index.ts +2 -0
  102. package/commands/inbounds/get-inbounds.command.ts +13 -0
  103. package/commands/inbounds/index.ts +1 -0
  104. package/commands/index.ts +9 -0
  105. package/commands/keygen/get-pubkey.command.ts +14 -0
  106. package/commands/keygen/index.ts +1 -0
  107. package/commands/nodes/create.command.ts +39 -0
  108. package/commands/nodes/delete.command.ts +20 -0
  109. package/commands/nodes/disable.command.ts +19 -0
  110. package/commands/nodes/enable.command.ts +19 -0
  111. package/commands/nodes/get-all.command.ts +13 -0
  112. package/commands/nodes/get-one.command.ts +19 -0
  113. package/commands/nodes/index.ts +9 -0
  114. package/commands/nodes/restart-all.command.ts +13 -0
  115. package/commands/nodes/restart.command.ts +20 -0
  116. package/commands/nodes/update.command.ts +41 -0
  117. package/commands/subscription/get-subscription-by-short-uuid.command.ts +12 -0
  118. package/commands/subscription/get-subscription-info-by-short-uuid.command.ts +31 -0
  119. package/commands/subscription/index.ts +2 -0
  120. package/commands/users/create-user.command.ts +103 -0
  121. package/commands/users/delete-user.command.ts +19 -0
  122. package/commands/users/disable-user.command.ts.ts +18 -0
  123. package/commands/users/enable-user.command.ts +19 -0
  124. package/commands/users/get-all-users.command.ts +26 -0
  125. package/commands/users/get-user-by-short-uuid.command.ts +19 -0
  126. package/commands/users/get-user-by-subscription-uuid.command.ts +19 -0
  127. package/commands/users/get-user-by-uuid.command.ts +19 -0
  128. package/commands/users/index.ts +9 -0
  129. package/commands/users/revoke-user-subscription.command.ts +19 -0
  130. package/commands/xray/get-config.command.ts +12 -0
  131. package/commands/xray/index.ts +1 -0
  132. package/constants/errors/errors.ts +233 -0
  133. package/constants/errors/index.ts +1 -0
  134. package/constants/hosts/alpn.ts +8 -0
  135. package/constants/hosts/fingerprints.ts +14 -0
  136. package/constants/hosts/index.ts +2 -0
  137. package/constants/index.ts +6 -0
  138. package/constants/nodes/cycle/cycle.ts +7 -0
  139. package/constants/nodes/cycle/index.ts +1 -0
  140. package/constants/nodes/index.ts +2 -0
  141. package/constants/nodes/status/index.ts +1 -0
  142. package/constants/nodes/status/status.constant.ts +8 -0
  143. package/constants/roles/index.ts +1 -0
  144. package/constants/roles/role.ts +7 -0
  145. package/constants/templates/index.ts +2 -0
  146. package/constants/templates/template-keys.ts +2 -0
  147. package/constants/templates/user-statuses.ts +6 -0
  148. package/constants/users/index.ts +2 -0
  149. package/constants/users/reset-periods/index.ts +1 -0
  150. package/constants/users/reset-periods/reset-periods.constant.ts +10 -0
  151. package/constants/users/status/index.ts +1 -0
  152. package/constants/users/status/status.constant.ts +9 -0
  153. package/index.ts +4 -0
  154. package/models/api-tokens.schema.ts +11 -0
  155. package/models/auth.schema.ts +5 -0
  156. package/models/hosts.schema.ts +17 -0
  157. package/models/inbounds.schema.ts +7 -0
  158. package/models/index.ts +6 -0
  159. package/models/nodes.schema.ts +28 -0
  160. package/models/users.schema.ts +38 -0
  161. package/package.json +16 -0
  162. package/tsconfig.json +103 -0
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ export namespace DeleteUserCommand {
4
+ export const url = REST_API.USERS.DELETE_USER;
5
+
6
+ export const RequestSchema = z.object({
7
+ uuid: z.string().uuid(),
8
+ });
9
+
10
+ export type Request = z.infer<typeof RequestSchema>;
11
+
12
+ export const ResponseSchema = z.object({
13
+ response: z.object({
14
+ isDeleted: z.boolean(),
15
+ }),
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+ export namespace DisableUserCommand {
5
+ export const url = REST_API.USERS.DISABLE_USER;
6
+
7
+ export const RequestSchema = z.object({
8
+ uuid: z.string().uuid(),
9
+ });
10
+
11
+ export type Request = z.infer<typeof RequestSchema>;
12
+
13
+ export const ResponseSchema = z.object({
14
+ response: UsersSchema,
15
+ });
16
+
17
+ export type Response = z.infer<typeof ResponseSchema>;
18
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace EnableUserCommand {
6
+ export const url = REST_API.USERS.ENABLE_USER;
7
+
8
+ export const RequestSchema = z.object({
9
+ uuid: z.string().uuid(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ response: UsersSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace GetAllUsersCommand {
6
+ export const url = REST_API.USERS.GET_ALL;
7
+
8
+ export const RequestQuerySchema = z.object({
9
+ limit: z
10
+ .string()
11
+ .default('10')
12
+ .transform((val) => parseInt(val)),
13
+ offset: z
14
+ .string()
15
+ .default('0')
16
+ .transform((val) => parseInt(val)),
17
+ });
18
+
19
+ export type RequestQuery = z.infer<typeof RequestQuerySchema>;
20
+
21
+ export const ResponseSchema = z.object({
22
+ response: z.array(UsersSchema),
23
+ });
24
+
25
+ export type Response = z.infer<typeof ResponseSchema>;
26
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace GetUserByShortUuidCommand {
6
+ export const url = REST_API.USERS.GET_BY_SHORT_UUID;
7
+
8
+ export const RequestSchema = z.object({
9
+ shortUuid: z.string(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ response: UsersSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace GetUserBySubscriptionUuidCommand {
6
+ export const url = REST_API.USERS.GET_BY_SUBSCRIPTION_UUID;
7
+
8
+ export const RequestSchema = z.object({
9
+ subscriptionUuid: z.string(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ response: UsersSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace GetUserByUuidCommand {
6
+ export const url = REST_API.USERS.GET_BY_UUID;
7
+
8
+ export const RequestSchema = z.object({
9
+ uuid: z.string().uuid(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ response: UsersSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,9 @@
1
+ export * from './create-user.command';
2
+ export * from './delete-user.command';
3
+ export * from './disable-user.command.ts';
4
+ export * from './enable-user.command';
5
+ export * from './get-all-users.command';
6
+ export * from './get-user-by-short-uuid.command';
7
+ export * from './get-user-by-subscription-uuid.command';
8
+ export * from './get-user-by-uuid.command';
9
+ export * from './revoke-user-subscription.command';
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ import { UsersSchema } from '../../models/users.schema';
4
+
5
+ export namespace RevokeUserSubscriptionCommand {
6
+ export const url = REST_API.USERS.REVOKE_SUBSCRIPTION;
7
+
8
+ export const RequestSchema = z.object({
9
+ uuid: z.string().uuid(),
10
+ });
11
+
12
+ export type Request = z.infer<typeof RequestSchema>;
13
+
14
+ export const ResponseSchema = z.object({
15
+ response: UsersSchema,
16
+ });
17
+
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ import { REST_API } from '../../api';
3
+ export namespace GetXrayConfigCommand {
4
+ export const url = REST_API.XRAY.GET_CONFIG;
5
+ export const ResponseSchema = z.object({
6
+ response: z.object({
7
+ config: z.record(z.any()),
8
+ }),
9
+ });
10
+
11
+ export type Response = z.infer<typeof ResponseSchema>;
12
+ }
@@ -0,0 +1 @@
1
+ export * from './get-config.command';
@@ -0,0 +1,233 @@
1
+ export const ERRORS = {
2
+ INTERNAL_SERVER_ERROR: { code: 'A001', message: 'Server error', httpCode: 500 },
3
+ LOGIN_ERROR: { code: 'A002', message: 'Login error', httpCode: 500 },
4
+ UNAUTHORIZED: { code: 'A003', message: 'Unauthorized', httpCode: 401 },
5
+ FORBIDDEN_ROLE_ERROR: { code: 'A004', message: 'Forbidden role error', httpCode: 403 },
6
+ CREATE_API_TOKEN_ERROR: { code: 'A005', message: 'Create API token error', httpCode: 500 },
7
+ DELETE_API_TOKEN_ERROR: { code: 'A006', message: 'Delete API token error', httpCode: 500 },
8
+ REQUESTED_TOKEN_NOT_FOUND: {
9
+ code: 'A007',
10
+ message: 'Requested token not found',
11
+ httpCode: 404,
12
+ },
13
+ FIND_ALL_API_TOKENS_ERROR: {
14
+ code: 'A008',
15
+ message: 'Find all API tokens error',
16
+ httpCode: 500,
17
+ },
18
+ GET_PUBLIC_KEY_ERROR: {
19
+ code: 'A009',
20
+ message: 'Get public key error',
21
+ httpCode: 500,
22
+ },
23
+ ENABLE_NODE_ERROR: {
24
+ code: 'A010',
25
+ message: 'Enable node error',
26
+ httpCode: 500,
27
+ },
28
+ NODE_NOT_FOUND: {
29
+ code: 'A011',
30
+ message: 'Node not found',
31
+ httpCode: 404,
32
+ },
33
+ CONFIG_NOT_FOUND: {
34
+ code: 'A012',
35
+ message: 'Configuration not found',
36
+ httpCode: 404,
37
+ },
38
+ UPDATE_CONFIG_ERROR: {
39
+ code: 'A013',
40
+ message: 'Error updating configuration',
41
+ httpCode: 500,
42
+ },
43
+ GET_CONFIG_ERROR: {
44
+ code: 'A014',
45
+ message: 'Error retrieving configuration',
46
+ httpCode: 500,
47
+ },
48
+ DELETE_MANY_INBOUNDS_ERROR: {
49
+ code: 'A015',
50
+ message: 'Delete many inbounds error',
51
+ httpCode: 500,
52
+ },
53
+ CREATE_MANY_INBOUNDS_ERROR: {
54
+ code: 'A016',
55
+ message: 'Create many inbounds error',
56
+ httpCode: 500,
57
+ },
58
+ FIND_ALL_INBOUNDS_ERROR: {
59
+ code: 'A017',
60
+ message: 'Find all inbounds error',
61
+ httpCode: 500,
62
+ },
63
+ CREATE_USER_ERROR: {
64
+ code: 'A018',
65
+ message: 'Failed to create user',
66
+ httpCode: 500,
67
+ },
68
+ USER_USERNAME_ALREADY_EXISTS: {
69
+ code: 'A019',
70
+ message: 'User username already exists',
71
+ httpCode: 400,
72
+ },
73
+ USER_SHORT_UUID_ALREADY_EXISTS: {
74
+ code: 'A020',
75
+ message: 'User short UUID already exists',
76
+ httpCode: 400,
77
+ },
78
+ USER_SUBSCRIPTION_UUID_ALREADY_EXISTS: {
79
+ code: 'A021',
80
+ message: 'User subscription UUID already exists',
81
+ httpCode: 400,
82
+ },
83
+ CREATE_USER_WITH_INBOUNDS_ERROR: {
84
+ code: 'A022',
85
+ message: 'User creation successful, but inbound creation failed. User not created.',
86
+ httpCode: 500,
87
+ },
88
+ CANT_GET_CREATED_USER_WITH_INBOUNDS: {
89
+ code: 'A023',
90
+ message: 'User creation successful, but failed to get created user with inbounds.',
91
+ httpCode: 500,
92
+ },
93
+ GET_ALL_USERS_ERROR: {
94
+ code: 'A024',
95
+ message: 'Get all users error',
96
+ httpCode: 500,
97
+ },
98
+ USER_NOT_FOUND: {
99
+ code: 'A025',
100
+ message: 'User not found',
101
+ httpCode: 404,
102
+ },
103
+ GET_USER_BY_ERROR: {
104
+ code: 'A026',
105
+ message: 'Get user by error',
106
+ httpCode: 500,
107
+ },
108
+ REVOKE_USER_SUBSCRIPTION_ERROR: {
109
+ code: 'A027',
110
+ message: 'Revoke user subscription error',
111
+ httpCode: 500,
112
+ },
113
+ DISABLE_USER_ERROR: {
114
+ code: 'A028',
115
+ message: 'Disable user error',
116
+ httpCode: 500,
117
+ },
118
+ USER_ALREADY_DISABLED: {
119
+ code: 'A029',
120
+ message: 'User already disabled',
121
+ httpCode: 400,
122
+ },
123
+ USER_ALREADY_ENABLED: {
124
+ code: 'A030',
125
+ message: 'User already enabled',
126
+ httpCode: 400,
127
+ },
128
+ ENABLE_USER_ERROR: {
129
+ code: 'A031',
130
+ message: 'Enable user error',
131
+ httpCode: 500,
132
+ },
133
+ CREATE_NODE_ERROR: {
134
+ code: 'A032',
135
+ message: 'Create node error',
136
+ httpCode: 500,
137
+ },
138
+ NODE_NAME_ALREADY_EXISTS: {
139
+ code: 'A033',
140
+ message: 'Node name already exists',
141
+ httpCode: 400,
142
+ },
143
+ NODE_ADDRESS_ALREADY_EXISTS: {
144
+ code: 'A034',
145
+ message: 'Node address already exists',
146
+ httpCode: 400,
147
+ },
148
+ NODE_ERROR_WITH_MSG: {
149
+ code: 'N001',
150
+ message: '',
151
+ httpCode: 500,
152
+ withMessage: (message: string) => ({
153
+ code: 'N001',
154
+ message,
155
+ httpCode: 500,
156
+ }),
157
+ },
158
+ NODE_ERROR_500_WITH_MSG: {
159
+ code: 'N002',
160
+ message: '',
161
+ httpCode: 500,
162
+ withMessage: (message: string) => ({
163
+ code: 'N002',
164
+ message,
165
+ httpCode: 500,
166
+ }),
167
+ },
168
+ RESTART_NODE_ERROR: {
169
+ code: 'A035',
170
+ message: 'Restart node error',
171
+ httpCode: 500,
172
+ },
173
+ GET_CONFIG_WITH_USERS_ERROR: {
174
+ code: 'A036',
175
+ message: 'Get config with users error',
176
+ httpCode: 500,
177
+ },
178
+ DELETE_USER_ERROR: {
179
+ code: 'A037',
180
+ message: 'Delete user error',
181
+ httpCode: 500,
182
+ },
183
+ UPDATE_NODE_ERROR: {
184
+ code: 'A038',
185
+ message: 'Update node error',
186
+ httpCode: 500,
187
+ },
188
+ UPDATE_USER_ERROR: {
189
+ code: 'A039',
190
+ message: 'Update user error',
191
+ httpCode: 500,
192
+ },
193
+ INCREMENT_USED_TRAFFIC_ERROR: {
194
+ code: 'A040',
195
+ message: 'Increment used traffic error',
196
+ httpCode: 500,
197
+ },
198
+ GET_ALL_NODES_ERROR: {
199
+ code: 'A041',
200
+ message: 'Get all nodes error',
201
+ httpCode: 500,
202
+ },
203
+ GET_ONE_NODE_ERROR: {
204
+ code: 'A042',
205
+ message: 'Get one node error',
206
+ httpCode: 500,
207
+ },
208
+ DELETE_NODE_ERROR: {
209
+ code: 'A043',
210
+ message: 'Delete node error',
211
+ httpCode: 500,
212
+ },
213
+ CREATE_HOST_ERROR: {
214
+ code: 'A044',
215
+ message: 'Create host error',
216
+ httpCode: 500,
217
+ },
218
+ HOST_REMARK_ALREADY_EXISTS: {
219
+ code: 'A045',
220
+ message: 'Host remark already exists',
221
+ httpCode: 400,
222
+ },
223
+ HOST_NOT_FOUND: {
224
+ code: 'A046',
225
+ message: 'Host not found',
226
+ httpCode: 404,
227
+ },
228
+ DELETE_HOST_ERROR: {
229
+ code: 'A047',
230
+ message: 'Delete host error',
231
+ httpCode: 500,
232
+ },
233
+ } as const;
@@ -0,0 +1 @@
1
+ export * from './errors';
@@ -0,0 +1,8 @@
1
+ export const ALPN = {
2
+ HTTP_1_1: 'http/1.1',
3
+ H2: 'h2',
4
+ H_COMBINED: 'h2,http/1.1',
5
+ } as const;
6
+
7
+ export type TAlpn = [keyof typeof ALPN][number];
8
+ export const ALPN_VALUES = Object.values(ALPN);
@@ -0,0 +1,14 @@
1
+ export const FINGERPRINTS = {
2
+ CHROME: 'chrome',
3
+ FIREFOX: 'firefox',
4
+ SAFARI: 'safari',
5
+ IOS: 'ios',
6
+ ANDROID: 'android',
7
+ EDGE: 'edge',
8
+ QQ: 'qq',
9
+ RANDOM: 'random',
10
+ RANDOMIZED: 'randomized',
11
+ } as const;
12
+
13
+ export type TFingerprints = [keyof typeof FINGERPRINTS][number];
14
+ export const FINGERPRINTS_VALUES = Object.values(FINGERPRINTS);
@@ -0,0 +1,2 @@
1
+ export * from './alpn';
2
+ export * from './fingerprints';
@@ -0,0 +1,6 @@
1
+ export * from './errors';
2
+ export * from './hosts';
3
+ export * from './nodes';
4
+ export * from './roles';
5
+ export * from './templates';
6
+ export * from './users';
@@ -0,0 +1,7 @@
1
+ export const NODES_CYCLE = {
2
+ MONTH: 'MONTH',
3
+ YEAR: 'YEAR',
4
+ } as const;
5
+
6
+ export type TNodesCycle = [keyof typeof NODES_CYCLE][number];
7
+ export const NODES_CYCLE_VALUES = Object.values(NODES_CYCLE);
@@ -0,0 +1 @@
1
+ export * from './cycle';
@@ -0,0 +1,2 @@
1
+ export * from './status';
2
+ export * from './cycle';
@@ -0,0 +1 @@
1
+ export * from './status.constant';
@@ -0,0 +1,8 @@
1
+ export const NODES_STATUS = {
2
+ CONNECTED: 'CONNECTED',
3
+ DISCONNECTED: 'DISCONNECTED',
4
+ DISABLED: 'DISABLED',
5
+ } as const;
6
+
7
+ export type TNodesStatus = [keyof typeof NODES_STATUS][number];
8
+ export const NODES_STATUS_VALUES = Object.values(NODES_STATUS);
@@ -0,0 +1 @@
1
+ export * from './role';
@@ -0,0 +1,7 @@
1
+ export const ROLE = {
2
+ ADMIN: 'ADMIN',
3
+ API: 'API',
4
+ } as const;
5
+
6
+ export type TRole = typeof ROLE;
7
+ export type TRolesKeys = (typeof ROLE)[keyof typeof ROLE];
@@ -0,0 +1,2 @@
1
+ export * from './template-keys';
2
+ export * from './user-statuses';
@@ -0,0 +1,2 @@
1
+ export const TEMPLATE_KEYS = ['DAYS_LEFT', 'TRAFFIC_USED', 'TRAFFIC_LEFT', 'STATUS'] as const;
2
+ export type TemplateKeys = (typeof TEMPLATE_KEYS)[number];
@@ -0,0 +1,6 @@
1
+ export const USER_STATUSES_TEMPLATE = {
2
+ ACTIVE: ' ✅ Active',
3
+ EXPIRED: ' ⚠️ Expired',
4
+ DISABLED: '❌ Disabled',
5
+ LIMITED: '🔴 Limited',
6
+ } as const;
@@ -0,0 +1,2 @@
1
+ export * from './reset-periods';
2
+ export * from './status';
@@ -0,0 +1 @@
1
+ export * from './reset-periods.constant';
@@ -0,0 +1,10 @@
1
+ export const RESET_PERIODS = {
2
+ NO_RESET: 'NO_RESET',
3
+ DAY: 'DAY',
4
+ WEEK: 'WEEK',
5
+ MONTH: 'MONTH',
6
+ YEAR: 'YEAR',
7
+ } as const;
8
+
9
+ export type TResetPeriods = [keyof typeof RESET_PERIODS][number];
10
+ export const RESET_PERIODS_VALUES = Object.values(RESET_PERIODS);
@@ -0,0 +1 @@
1
+ export * from './status.constant';
@@ -0,0 +1,9 @@
1
+ export const USERS_STATUS = {
2
+ ACTIVE: 'ACTIVE',
3
+ DISABLED: 'DISABLED',
4
+ LIMITED: 'LIMITED',
5
+ EXPIRED: 'EXPIRED',
6
+ } as const;
7
+
8
+ export type TUsersStatus = [keyof typeof USERS_STATUS][number];
9
+ export const USERS_STATUS_VALUES = Object.values(USERS_STATUS);
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './api';
2
+ export * from './commands';
3
+ export * from './constants';
4
+ export * from './models';
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+
3
+ export const ApiTokensSchema = z.object({
4
+ uuid: z.string().uuid(),
5
+ token: z.string(),
6
+ tokenName: z.string(),
7
+ tokenDescription: z.nullable(z.string()),
8
+
9
+ createdAt: z.date(),
10
+ updatedAt: z.date(),
11
+ });
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+
3
+ export const AuthSchema = z.object({
4
+ hash: z.string(),
5
+ });
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+
3
+ export const HostsSchema = z.object({
4
+ uuid: z.string().uuid(),
5
+ inboundUuid: z.string().uuid(),
6
+ viewPosition: z.number().int(),
7
+ remark: z.string(),
8
+ address: z.string(),
9
+ port: z.number().int(),
10
+ path: z.string().nullable(),
11
+ sni: z.string().nullable(),
12
+ host: z.string().nullable(),
13
+ alpn: z.string().nullable(),
14
+ fingerprint: z.string().nullable(),
15
+ allowInsecure: z.boolean().default(false),
16
+ isDisabled: z.boolean().default(false),
17
+ });
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+
3
+ export const InboundsSchema = z.object({
4
+ uuid: z.string().uuid(),
5
+ tag: z.string(),
6
+ type: z.string(),
7
+ });
@@ -0,0 +1,6 @@
1
+ export * from './api-tokens.schema';
2
+ export * from './auth.schema';
3
+ export * from './hosts.schema';
4
+ export * from './inbounds.schema';
5
+ export * from './nodes.schema';
6
+ export * from './users.schema';
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+
3
+ export const NodesSchema = z.object({
4
+ uuid: z.string().uuid(),
5
+ name: z.string(),
6
+ address: z.string(),
7
+ port: z.number().int().nullable(),
8
+ isConnected: z.boolean().default(false),
9
+ isDisabled: z.boolean().default(false),
10
+ isConnecting: z.boolean().default(false),
11
+ isNodeOnline: z.boolean().default(false),
12
+ isXrayRunning: z.boolean().default(false),
13
+ lastStatusChange: z.date().nullable(),
14
+ lastStatusMessage: z.string().nullable(),
15
+ xrayVersion: z.string().nullable(),
16
+ isTrafficTrackingActive: z.boolean().default(false),
17
+ trafficResetDay: z.number().int().nullable(),
18
+ trafficLimitBytes: z.number().nullable(),
19
+ trafficUsedBytes: z.number().nullable(),
20
+ notifyPercent: z.number().int().nullable(),
21
+
22
+ cpuCount: z.number().int().nullable(),
23
+ cpuModel: z.string().nullable(),
24
+ totalRam: z.string().nullable(),
25
+
26
+ createdAt: z.date(),
27
+ updatedAt: z.date(),
28
+ });