@remnawave/backend-contract 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/api/controllers/api-tokens.ts +7 -0
- package/api/controllers/auth.ts +5 -0
- package/api/controllers/hosts.ts +9 -0
- package/api/controllers/inbounds.ts +5 -0
- package/api/controllers/index.ts +9 -0
- package/api/controllers/keygen.ts +5 -0
- package/api/controllers/nodes.ts +14 -0
- package/api/controllers/subscription.ts +6 -0
- package/api/controllers/users.ts +13 -0
- package/api/controllers/xray.ts +6 -0
- package/api/index.ts +2 -0
- package/api/routes.ts +73 -0
- package/build/api/controllers/api-tokens.js +9 -0
- package/build/api/controllers/auth.js +7 -0
- package/build/api/controllers/hosts.js +11 -0
- package/build/api/controllers/inbounds.js +7 -0
- package/build/api/controllers/index.js +25 -0
- package/build/api/controllers/keygen.js +7 -0
- package/build/api/controllers/nodes.js +15 -0
- package/build/api/controllers/subscription.js +8 -0
- package/build/api/controllers/users.js +15 -0
- package/build/api/controllers/xray.js +8 -0
- package/build/api/index.js +18 -0
- package/build/api/routes.js +81 -0
- package/build/commands/api-tokens/create.command.js +19 -0
- package/build/commands/api-tokens/delete.command.js +15 -0
- package/build/commands/api-tokens/find.command.js +13 -0
- package/build/commands/api-tokens/index.js +19 -0
- package/build/commands/auth/index.js +17 -0
- package/build/commands/auth/login.command.js +18 -0
- package/build/commands/hosts/create.command.js +50 -0
- package/build/commands/hosts/delete.command.js +17 -0
- package/build/commands/hosts/index.js +18 -0
- package/build/commands/inbounds/get-inbounds.command.js +13 -0
- package/build/commands/inbounds/index.js +17 -0
- package/build/commands/index.js +25 -0
- package/build/commands/keygen/get-pubkey.command.js +14 -0
- package/build/commands/keygen/index.js +17 -0
- package/build/commands/nodes/create.command.js +36 -0
- package/build/commands/nodes/delete.command.js +17 -0
- package/build/commands/nodes/disable.command.js +16 -0
- package/build/commands/nodes/enable.command.js +16 -0
- package/build/commands/nodes/get-all.command.js +13 -0
- package/build/commands/nodes/get-one.command.js +16 -0
- package/build/commands/nodes/index.js +25 -0
- package/build/commands/nodes/restart-all.command.js +14 -0
- package/build/commands/nodes/restart.command.js +17 -0
- package/build/commands/nodes/update.command.js +38 -0
- package/build/commands/subscription/get-subscription-by-short-uuid.command.js +12 -0
- package/build/commands/subscription/get-subscription-info-by-short-uuid.command.js +28 -0
- package/build/commands/subscription/index.js +18 -0
- package/build/commands/users/create-user.command.js +94 -0
- package/build/commands/users/delete-user.command.js +17 -0
- package/build/commands/users/disable-user.command.ts.js +16 -0
- package/build/commands/users/enable-user.command.js +16 -0
- package/build/commands/users/get-all-users.command.js +23 -0
- package/build/commands/users/get-user-by-short-uuid.command.js +16 -0
- package/build/commands/users/get-user-by-subscription-uuid.command.js +16 -0
- package/build/commands/users/get-user-by-uuid.command.js +16 -0
- package/build/commands/users/index.js +25 -0
- package/build/commands/users/revoke-user-subscription.command.js +16 -0
- package/build/commands/xray/get-config.command.js +14 -0
- package/build/commands/xray/index.js +17 -0
- package/build/constants/errors/errors.js +236 -0
- package/build/constants/errors/index.js +17 -0
- package/build/constants/hosts/alpn.js +9 -0
- package/build/constants/hosts/fingerprints.js +15 -0
- package/build/constants/hosts/index.js +18 -0
- package/build/constants/index.js +22 -0
- package/build/constants/nodes/cycle/cycle.js +8 -0
- package/build/constants/nodes/cycle/index.js +17 -0
- package/build/constants/nodes/index.js +18 -0
- package/build/constants/nodes/status/index.js +17 -0
- package/build/constants/nodes/status/status.constant.js +9 -0
- package/build/constants/roles/index.js +17 -0
- package/build/constants/roles/role.js +7 -0
- package/build/constants/templates/index.js +18 -0
- package/build/constants/templates/template-keys.js +4 -0
- package/build/constants/templates/user-statuses.js +9 -0
- package/build/constants/users/index.js +18 -0
- package/build/constants/users/reset-periods/index.js +17 -0
- package/build/constants/users/reset-periods/reset-periods.constant.js +11 -0
- package/build/constants/users/status/index.js +17 -0
- package/build/constants/users/status/status.constant.js +10 -0
- package/build/index.js +20 -0
- package/build/models/api-tokens.schema.js +12 -0
- package/build/models/auth.schema.js +7 -0
- package/build/models/hosts.schema.js +19 -0
- package/build/models/inbounds.schema.js +9 -0
- package/build/models/index.js +22 -0
- package/build/models/nodes.schema.js +28 -0
- package/build/models/users.schema.js +34 -0
- package/commands/api-tokens/create.command.ts +22 -0
- package/commands/api-tokens/delete.command.ts +18 -0
- package/commands/api-tokens/find.command.ts +13 -0
- package/commands/api-tokens/index.ts +3 -0
- package/commands/auth/index.ts +1 -0
- package/commands/auth/login.command.ts +20 -0
- package/commands/hosts/create.command.ts +52 -0
- package/commands/hosts/delete.command.ts +20 -0
- package/commands/hosts/index.ts +2 -0
- package/commands/inbounds/get-inbounds.command.ts +13 -0
- package/commands/inbounds/index.ts +1 -0
- package/commands/index.ts +9 -0
- package/commands/keygen/get-pubkey.command.ts +14 -0
- package/commands/keygen/index.ts +1 -0
- package/commands/nodes/create.command.ts +39 -0
- package/commands/nodes/delete.command.ts +20 -0
- package/commands/nodes/disable.command.ts +19 -0
- package/commands/nodes/enable.command.ts +19 -0
- package/commands/nodes/get-all.command.ts +13 -0
- package/commands/nodes/get-one.command.ts +19 -0
- package/commands/nodes/index.ts +9 -0
- package/commands/nodes/restart-all.command.ts +13 -0
- package/commands/nodes/restart.command.ts +20 -0
- package/commands/nodes/update.command.ts +41 -0
- package/commands/subscription/get-subscription-by-short-uuid.command.ts +12 -0
- package/commands/subscription/get-subscription-info-by-short-uuid.command.ts +31 -0
- package/commands/subscription/index.ts +2 -0
- package/commands/users/create-user.command.ts +103 -0
- package/commands/users/delete-user.command.ts +19 -0
- package/commands/users/disable-user.command.ts.ts +18 -0
- package/commands/users/enable-user.command.ts +19 -0
- package/commands/users/get-all-users.command.ts +26 -0
- package/commands/users/get-user-by-short-uuid.command.ts +19 -0
- package/commands/users/get-user-by-subscription-uuid.command.ts +19 -0
- package/commands/users/get-user-by-uuid.command.ts +19 -0
- package/commands/users/index.ts +9 -0
- package/commands/users/revoke-user-subscription.command.ts +19 -0
- package/commands/xray/get-config.command.ts +12 -0
- package/commands/xray/index.ts +1 -0
- package/constants/errors/errors.ts +233 -0
- package/constants/errors/index.ts +1 -0
- package/constants/hosts/alpn.ts +8 -0
- package/constants/hosts/fingerprints.ts +14 -0
- package/constants/hosts/index.ts +2 -0
- package/constants/index.ts +6 -0
- package/constants/nodes/cycle/cycle.ts +7 -0
- package/constants/nodes/cycle/index.ts +1 -0
- package/constants/nodes/index.ts +2 -0
- package/constants/nodes/status/index.ts +1 -0
- package/constants/nodes/status/status.constant.ts +8 -0
- package/constants/roles/index.ts +1 -0
- package/constants/roles/role.ts +7 -0
- package/constants/templates/index.ts +2 -0
- package/constants/templates/template-keys.ts +2 -0
- package/constants/templates/user-statuses.ts +6 -0
- package/constants/users/index.ts +2 -0
- package/constants/users/reset-periods/index.ts +1 -0
- package/constants/users/reset-periods/reset-periods.constant.ts +10 -0
- package/constants/users/status/index.ts +1 -0
- package/constants/users/status/status.constant.ts +9 -0
- package/index.ts +4 -0
- package/models/api-tokens.schema.ts +11 -0
- package/models/auth.schema.ts +5 -0
- package/models/hosts.schema.ts +17 -0
- package/models/inbounds.schema.ts +7 -0
- package/models/index.ts +6 -0
- package/models/nodes.schema.ts +28 -0
- package/models/users.schema.ts +38 -0
- package/package.json +16 -0
- package/tsconfig.json +103 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NodesSchema = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
exports.NodesSchema = zod_1.z.object({
|
6
|
+
uuid: zod_1.z.string().uuid(),
|
7
|
+
name: zod_1.z.string(),
|
8
|
+
address: zod_1.z.string(),
|
9
|
+
port: zod_1.z.number().int().nullable(),
|
10
|
+
isConnected: zod_1.z.boolean().default(false),
|
11
|
+
isDisabled: zod_1.z.boolean().default(false),
|
12
|
+
isConnecting: zod_1.z.boolean().default(false),
|
13
|
+
isNodeOnline: zod_1.z.boolean().default(false),
|
14
|
+
isXrayRunning: zod_1.z.boolean().default(false),
|
15
|
+
lastStatusChange: zod_1.z.date().nullable(),
|
16
|
+
lastStatusMessage: zod_1.z.string().nullable(),
|
17
|
+
xrayVersion: zod_1.z.string().nullable(),
|
18
|
+
isTrafficTrackingActive: zod_1.z.boolean().default(false),
|
19
|
+
trafficResetDay: zod_1.z.number().int().nullable(),
|
20
|
+
trafficLimitBytes: zod_1.z.number().nullable(),
|
21
|
+
trafficUsedBytes: zod_1.z.number().nullable(),
|
22
|
+
notifyPercent: zod_1.z.number().int().nullable(),
|
23
|
+
cpuCount: zod_1.z.number().int().nullable(),
|
24
|
+
cpuModel: zod_1.z.string().nullable(),
|
25
|
+
totalRam: zod_1.z.string().nullable(),
|
26
|
+
createdAt: zod_1.z.date(),
|
27
|
+
updatedAt: zod_1.z.date(),
|
28
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UsersSchema = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const constants_1 = require("../constants");
|
6
|
+
const inbounds_schema_1 = require("./inbounds.schema");
|
7
|
+
exports.UsersSchema = zod_1.z.object({
|
8
|
+
uuid: zod_1.z.string().uuid(),
|
9
|
+
subscriptionUuid: zod_1.z.string().uuid(),
|
10
|
+
shortUuid: zod_1.z.string(),
|
11
|
+
username: zod_1.z.string(),
|
12
|
+
status: zod_1.z
|
13
|
+
.enum([constants_1.USERS_STATUS_VALUES[0], ...constants_1.USERS_STATUS_VALUES])
|
14
|
+
.default(constants_1.USERS_STATUS_VALUES[0]),
|
15
|
+
usedTrafficBytes: zod_1.z.number().int().default(0),
|
16
|
+
trafficLimitBytes: zod_1.z.number().int().default(0),
|
17
|
+
trafficLimitStrategy: zod_1.z
|
18
|
+
.enum([constants_1.RESET_PERIODS_VALUES[0], ...constants_1.RESET_PERIODS_VALUES], {
|
19
|
+
description: 'Available reset periods',
|
20
|
+
})
|
21
|
+
.default(constants_1.RESET_PERIODS_VALUES[0]),
|
22
|
+
subLastUserAgent: zod_1.z.nullable(zod_1.z.string()),
|
23
|
+
subLastOpenedAt: zod_1.z.nullable(zod_1.z.date()),
|
24
|
+
expireAt: zod_1.z.date(),
|
25
|
+
onlineAt: zod_1.z.date().nullable(),
|
26
|
+
subRevokedAt: zod_1.z.date().nullable(),
|
27
|
+
lastTrafficResetAt: zod_1.z.date().nullable(),
|
28
|
+
trojanPassword: zod_1.z.string(),
|
29
|
+
vlessUuid: zod_1.z.string().uuid(),
|
30
|
+
ssPassword: zod_1.z.string(),
|
31
|
+
createdAt: zod_1.z.date(),
|
32
|
+
updatedAt: zod_1.z.date(),
|
33
|
+
activeUserInbounds: zod_1.z.array(inbounds_schema_1.InboundsSchema),
|
34
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace CreateApiTokenCommand {
|
5
|
+
export const url = REST_API.API_TOKENS.CREATE;
|
6
|
+
|
7
|
+
export const RequestSchema = z.object({
|
8
|
+
tokenName: z.string(),
|
9
|
+
tokenDescription: z.string().nullable(),
|
10
|
+
});
|
11
|
+
|
12
|
+
export type Request = z.infer<typeof RequestSchema>;
|
13
|
+
|
14
|
+
export const ResponseSchema = z.object({
|
15
|
+
response: z.object({
|
16
|
+
token: z.string(),
|
17
|
+
uuid: z.string(),
|
18
|
+
}),
|
19
|
+
});
|
20
|
+
|
21
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
22
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace DeleteApiTokenCommand {
|
5
|
+
export const url = REST_API.API_TOKENS.DELETE;
|
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: z.boolean(),
|
15
|
+
});
|
16
|
+
|
17
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
18
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { ApiTokensSchema } from '../../models/api-tokens.schema';
|
4
|
+
|
5
|
+
export namespace FindAllApiTokensCommand {
|
6
|
+
export const url = REST_API.API_TOKENS.GET_ALL;
|
7
|
+
|
8
|
+
export const ResponseSchema = z.object({
|
9
|
+
response: z.array(ApiTokensSchema),
|
10
|
+
});
|
11
|
+
|
12
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './login.command';
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
export namespace LoginCommand {
|
4
|
+
export const url = REST_API.AUTH.LOGIN;
|
5
|
+
|
6
|
+
export const RequestSchema = z.object({
|
7
|
+
username: z.string(),
|
8
|
+
password: z.string(),
|
9
|
+
});
|
10
|
+
|
11
|
+
export type Request = z.infer<typeof RequestSchema>;
|
12
|
+
|
13
|
+
export const ResponseSchema = z.object({
|
14
|
+
response: z.object({
|
15
|
+
accessToken: z.string(),
|
16
|
+
}),
|
17
|
+
});
|
18
|
+
|
19
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
20
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { ALPN } from '../../constants/hosts/alpn';
|
4
|
+
import { FINGERPRINTS } from '../../constants/hosts/fingerprints';
|
5
|
+
import { HostsSchema } from '../../models';
|
6
|
+
|
7
|
+
export namespace CreateHostCommand {
|
8
|
+
export const url = REST_API.HOSTS.CREATE;
|
9
|
+
|
10
|
+
export const RequestSchema = HostsSchema.pick({}).extend({
|
11
|
+
inboundUuid: z
|
12
|
+
.string({
|
13
|
+
invalid_type_error: 'Inbound UUID must be a string',
|
14
|
+
})
|
15
|
+
.uuid('Inbound UUID must be a valid UUID'),
|
16
|
+
viewPosition: z
|
17
|
+
.number({
|
18
|
+
invalid_type_error: 'View position must be an integer',
|
19
|
+
})
|
20
|
+
.int()
|
21
|
+
.optional(),
|
22
|
+
remark: z
|
23
|
+
.string({
|
24
|
+
invalid_type_error: 'Remark must be a string',
|
25
|
+
})
|
26
|
+
.max(40, {
|
27
|
+
message: 'Remark must be less than 40 characters',
|
28
|
+
}),
|
29
|
+
address: z.string({
|
30
|
+
invalid_type_error: 'Address must be a string',
|
31
|
+
}),
|
32
|
+
port: z
|
33
|
+
.number({
|
34
|
+
invalid_type_error: 'Port must be an integer',
|
35
|
+
})
|
36
|
+
.int(),
|
37
|
+
path: z.string().optional(),
|
38
|
+
sni: z.string().optional(),
|
39
|
+
host: z.string().optional(),
|
40
|
+
alpn: z.nativeEnum(ALPN).optional(),
|
41
|
+
fingerprint: z.nativeEnum(FINGERPRINTS).optional(),
|
42
|
+
allowInsecure: z.boolean().optional().default(false),
|
43
|
+
isDisabled: z.boolean().optional().default(false),
|
44
|
+
});
|
45
|
+
export type Request = z.infer<typeof RequestSchema>;
|
46
|
+
|
47
|
+
export const ResponseSchema = z.object({
|
48
|
+
response: HostsSchema,
|
49
|
+
});
|
50
|
+
|
51
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
52
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace DeleteHostCommand {
|
5
|
+
export const url = REST_API.HOSTS.DELETE;
|
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: z.object({
|
15
|
+
isDeleted: z.boolean(),
|
16
|
+
}),
|
17
|
+
});
|
18
|
+
|
19
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
20
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { InboundsSchema } from '../../models/inbounds.schema';
|
4
|
+
|
5
|
+
export namespace GetInboundsCommand {
|
6
|
+
export const url = REST_API.INBOUNDS.GET_INBOUNDS;
|
7
|
+
|
8
|
+
export const ResponseSchema = z.object({
|
9
|
+
response: z.array(InboundsSchema.pick({ tag: true, uuid: true })),
|
10
|
+
});
|
11
|
+
|
12
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './get-inbounds.command';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace GetPubKeyCommand {
|
5
|
+
export const url = REST_API.KEYGEN.GET;
|
6
|
+
|
7
|
+
export const ResponseSchema = z.object({
|
8
|
+
response: z.object({
|
9
|
+
pubKey: z.string(),
|
10
|
+
}),
|
11
|
+
});
|
12
|
+
|
13
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
14
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './get-pubkey.command';
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace CreateNodeCommand {
|
6
|
+
export const url = REST_API.NODES.CREATE;
|
7
|
+
|
8
|
+
export const RequestSchema = NodesSchema.pick({}).extend({
|
9
|
+
name: z.string().min(5, 'Name is required'),
|
10
|
+
address: z.string().min(2, 'Address is required'),
|
11
|
+
port: z.number().int().min(1, 'Port is required').optional(),
|
12
|
+
isTrafficTrackingActive: z.boolean().optional().default(false),
|
13
|
+
trafficLimitBytes: z
|
14
|
+
.number()
|
15
|
+
.int()
|
16
|
+
.min(0, 'Traffic limit must be greater than 0')
|
17
|
+
.optional(),
|
18
|
+
notifyPercent: z
|
19
|
+
.number()
|
20
|
+
.int()
|
21
|
+
.min(0, 'Notify percent must be greater than 0')
|
22
|
+
.max(100, 'Notify percent must be less than 100')
|
23
|
+
.optional(),
|
24
|
+
trafficResetDay: z
|
25
|
+
.number()
|
26
|
+
.int()
|
27
|
+
.min(1, 'Traffic reset day must be greater than 0')
|
28
|
+
.max(31, 'Traffic reset day must be less than 31')
|
29
|
+
.optional(),
|
30
|
+
});
|
31
|
+
|
32
|
+
export type Request = z.infer<typeof RequestSchema>;
|
33
|
+
|
34
|
+
export const ResponseSchema = z.object({
|
35
|
+
response: NodesSchema,
|
36
|
+
});
|
37
|
+
|
38
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
39
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace DeleteNodeCommand {
|
5
|
+
export const url = REST_API.NODES.DELETE;
|
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: z.object({
|
15
|
+
isDeleted: z.boolean(),
|
16
|
+
}),
|
17
|
+
});
|
18
|
+
|
19
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
20
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace DisableNodeCommand {
|
6
|
+
export const url = REST_API.NODES.DISABLE;
|
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: NodesSchema,
|
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 { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace EnableNodeCommand {
|
6
|
+
export const url = REST_API.NODES.ENABLE;
|
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: NodesSchema,
|
16
|
+
});
|
17
|
+
|
18
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
19
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace GetAllNodesCommand {
|
6
|
+
export const url = REST_API.NODES.GET_ALL;
|
7
|
+
|
8
|
+
export const ResponseSchema = z.object({
|
9
|
+
response: z.array(NodesSchema),
|
10
|
+
});
|
11
|
+
|
12
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
13
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace GetOneNodeCommand {
|
6
|
+
export const url = REST_API.NODES.GET_ONE;
|
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: NodesSchema,
|
16
|
+
});
|
17
|
+
|
18
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
19
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export * from './create.command';
|
2
|
+
export * from './delete.command';
|
3
|
+
export * from './disable.command';
|
4
|
+
export * from './enable.command';
|
5
|
+
export * from './get-all.command';
|
6
|
+
export * from './get-one.command';
|
7
|
+
export * from './restart-all.command';
|
8
|
+
export * from './restart.command';
|
9
|
+
export * from './update.command';
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
export namespace RestartAllNodesCommand {
|
4
|
+
export const url = REST_API.NODES.RESTART_ALL;
|
5
|
+
|
6
|
+
export const ResponseSchema = z.object({
|
7
|
+
response: z.object({
|
8
|
+
eventSent: z.boolean(),
|
9
|
+
}),
|
10
|
+
});
|
11
|
+
|
12
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
13
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace RestartNodeCommand {
|
5
|
+
export const url = REST_API.NODES.RESTART;
|
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: z.object({
|
15
|
+
eventSent: z.boolean(),
|
16
|
+
}),
|
17
|
+
});
|
18
|
+
|
19
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
20
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { NodesSchema } from '../../models';
|
4
|
+
|
5
|
+
export namespace UpdateNodeCommand {
|
6
|
+
export const url = REST_API.NODES.UPDATE;
|
7
|
+
|
8
|
+
export const RequestSchema = NodesSchema.pick({
|
9
|
+
uuid: true,
|
10
|
+
}).extend({
|
11
|
+
name: z.string().min(5, 'Name is required').optional(),
|
12
|
+
address: z.string().min(2, 'Address is required').optional(),
|
13
|
+
port: z.number().int().min(1, 'Port is required').optional(),
|
14
|
+
isTrafficTrackingActive: z.boolean().optional(),
|
15
|
+
trafficLimitBytes: z
|
16
|
+
.number()
|
17
|
+
.int()
|
18
|
+
.min(0, 'Traffic limit must be greater than 0')
|
19
|
+
.optional(),
|
20
|
+
notifyPercent: z
|
21
|
+
.number()
|
22
|
+
.int()
|
23
|
+
.min(0, 'Notify percent must be greater than 0')
|
24
|
+
.max(100, 'Notify percent must be less than 100')
|
25
|
+
.optional(),
|
26
|
+
trafficResetDay: z
|
27
|
+
.number()
|
28
|
+
.int()
|
29
|
+
.min(1, 'Traffic reset day must be greater than 0')
|
30
|
+
.max(31, 'Traffic reset day must be less than 31')
|
31
|
+
.optional(),
|
32
|
+
});
|
33
|
+
|
34
|
+
export type Request = z.infer<typeof RequestSchema>;
|
35
|
+
|
36
|
+
export const ResponseSchema = z.object({
|
37
|
+
response: NodesSchema,
|
38
|
+
});
|
39
|
+
|
40
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
41
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
|
4
|
+
export namespace GetSubscriptionByShortUuidCommand {
|
5
|
+
export const url = REST_API.SUBSCRIPTION.GET;
|
6
|
+
|
7
|
+
export const RequestSchema = z.object({
|
8
|
+
shortUuid: z.string(),
|
9
|
+
});
|
10
|
+
|
11
|
+
export type Request = z.infer<typeof RequestSchema>;
|
12
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { USERS_STATUS_VALUES } from '../../constants';
|
4
|
+
|
5
|
+
export namespace GetSubscriptionInfoByShortUuidCommand {
|
6
|
+
export const url = REST_API.SUBSCRIPTION.GET_INFO;
|
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: z.object({
|
16
|
+
isFound: z.boolean(),
|
17
|
+
user: z.object({
|
18
|
+
shortUuid: z.string(),
|
19
|
+
daysLeft: z.number(),
|
20
|
+
trafficUsed: z.string(),
|
21
|
+
trafficLimit: z.string(),
|
22
|
+
username: z.string(),
|
23
|
+
expiresAt: z.date(),
|
24
|
+
isActive: z.boolean(),
|
25
|
+
userStatus: z.enum([USERS_STATUS_VALUES[0], ...USERS_STATUS_VALUES]),
|
26
|
+
}),
|
27
|
+
}),
|
28
|
+
});
|
29
|
+
|
30
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
31
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { RESET_PERIODS, USERS_STATUS } from '../../constants';
|
4
|
+
import { InboundsSchema, UsersSchema } from '../../models';
|
5
|
+
|
6
|
+
export namespace CreateUserCommand {
|
7
|
+
export const url = REST_API.USERS.CREATE;
|
8
|
+
|
9
|
+
export const RequestSchema = UsersSchema.pick({}).extend({
|
10
|
+
username: z
|
11
|
+
.string({
|
12
|
+
required_error: 'Username is required',
|
13
|
+
invalid_type_error: 'Username must be a string',
|
14
|
+
})
|
15
|
+
.regex(
|
16
|
+
/^[a-zA-Z0-9_-]+$/,
|
17
|
+
'Username can only contain letters, numbers, underscores and dashes',
|
18
|
+
)
|
19
|
+
.max(32, 'Username must be less than 32 characters')
|
20
|
+
.min(6, 'Username must be at least 6 characters'),
|
21
|
+
status: UsersSchema.shape.status.optional().default(USERS_STATUS.ACTIVE),
|
22
|
+
subscriptionUuid: z
|
23
|
+
.string({
|
24
|
+
invalid_type_error: 'Subscription UUID must be a string',
|
25
|
+
})
|
26
|
+
.uuid('Invalid subscription UUID format')
|
27
|
+
.optional(),
|
28
|
+
shortUuid: z
|
29
|
+
.string({
|
30
|
+
invalid_type_error: 'Short UUID must be a string',
|
31
|
+
})
|
32
|
+
.optional(),
|
33
|
+
trojanPassword: z
|
34
|
+
.string({
|
35
|
+
invalid_type_error: 'Trojan password must be a string',
|
36
|
+
})
|
37
|
+
.min(8, 'Trojan password must be at least 8 characters')
|
38
|
+
.max(32, 'Trojan password must be less than 32 characters')
|
39
|
+
.optional(),
|
40
|
+
vlessUuid: z
|
41
|
+
.string({
|
42
|
+
invalid_type_error: 'Vless UUID must be a string',
|
43
|
+
})
|
44
|
+
.uuid('Invalid Vless UUID format')
|
45
|
+
.optional(),
|
46
|
+
ssPassword: z
|
47
|
+
.string({
|
48
|
+
invalid_type_error: 'SS password must be a string',
|
49
|
+
})
|
50
|
+
.min(8, 'SS password must be at least 8 characters')
|
51
|
+
.max(32, 'SS password must be less than 32 characters')
|
52
|
+
.optional(),
|
53
|
+
trafficLimitBytes: z
|
54
|
+
.number({
|
55
|
+
invalid_type_error: 'Traffic limit must be a number',
|
56
|
+
})
|
57
|
+
.int('Traffic limit must be an integer')
|
58
|
+
.min(0, 'Traffic limit must be greater than 0')
|
59
|
+
.describe('Traffic limit in bytes. 0 - unlimited')
|
60
|
+
.optional(),
|
61
|
+
trafficLimitStrategy: UsersSchema.shape.trafficLimitStrategy
|
62
|
+
.describe('Traffic limit reset strategy')
|
63
|
+
.optional()
|
64
|
+
.default(RESET_PERIODS.NO_RESET)
|
65
|
+
.superRefine((val, ctx) => {
|
66
|
+
if (val && !Object.values(RESET_PERIODS).includes(val)) {
|
67
|
+
ctx.addIssue({
|
68
|
+
code: z.ZodIssueCode.invalid_enum_value,
|
69
|
+
message: 'Invalid traffic limit strategy',
|
70
|
+
path: ['trafficLimitStrategy'],
|
71
|
+
received: val,
|
72
|
+
options: Object.values(RESET_PERIODS),
|
73
|
+
});
|
74
|
+
}
|
75
|
+
}),
|
76
|
+
enabledInbounds: z
|
77
|
+
.array(
|
78
|
+
InboundsSchema.pick({
|
79
|
+
uuid: true,
|
80
|
+
}),
|
81
|
+
{
|
82
|
+
invalid_type_error: 'Enabled inbounds must be an array',
|
83
|
+
},
|
84
|
+
)
|
85
|
+
.optional(),
|
86
|
+
expireAt: z.coerce
|
87
|
+
.date({
|
88
|
+
required_error: 'Expiration date is required',
|
89
|
+
invalid_type_error: 'Invalid expiration date format',
|
90
|
+
})
|
91
|
+
.refine((date) => date > new Date(), {
|
92
|
+
message: 'Expiration date cannot be in the past',
|
93
|
+
}),
|
94
|
+
});
|
95
|
+
|
96
|
+
export type Request = z.infer<typeof RequestSchema>;
|
97
|
+
|
98
|
+
export const ResponseSchema = z.object({
|
99
|
+
response: UsersSchema,
|
100
|
+
});
|
101
|
+
|
102
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
103
|
+
}
|