@remnawave/backend-contract 0.0.4 → 0.0.6
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/api/controllers/users.ts +1 -0
- package/api/routes.ts +1 -0
- package/build/api/controllers/users.js +1 -0
- package/build/api/routes.js +1 -0
- package/build/commands/users/get-all-users.command.js +3 -1
- package/build/commands/users/index.js +1 -0
- package/build/commands/users/update-user.command.js +58 -0
- package/build/constants/errors/errors.js +5 -0
- package/commands/users/get-all-users.command.ts +6 -1
- package/commands/users/index.ts +1 -0
- package/commands/users/update-user.command.ts +64 -0
- package/constants/errors/errors.ts +5 -0
- package/package.json +1 -1
package/api/controllers/users.ts
CHANGED
package/api/routes.ts
CHANGED
@@ -55,6 +55,7 @@ export const REST_API = {
|
|
55
55
|
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.ENABLE_USER}/${uuid}`,
|
56
56
|
DELETE_USER: (uuid: string) =>
|
57
57
|
`${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DELETE_USER}/${uuid}`,
|
58
|
+
UPDATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.UPDATE}`,
|
58
59
|
},
|
59
60
|
SUBSCRIPTION: {
|
60
61
|
GET: (shortUuid: string) =>
|
package/build/api/routes.js
CHANGED
@@ -76,6 +76,7 @@ exports.REST_API = {
|
|
76
76
|
DISABLE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DISABLE_USER}/${uuid}`,
|
77
77
|
ENABLE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.ENABLE_USER}/${uuid}`,
|
78
78
|
DELETE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DELETE_USER}/${uuid}`,
|
79
|
+
UPDATE: `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.UPDATE}`,
|
79
80
|
},
|
80
81
|
SUBSCRIPTION: {
|
81
82
|
GET: (shortUuid) => `${exports.ROOT}/${CONTROLLERS.SUBSCRIPTION_CONTROLLER}/${CONTROLLERS.SUBSCRIPTION_ROUTES.GET}/${shortUuid}`,
|
@@ -39,7 +39,9 @@ var GetAllUsersCommand;
|
|
39
39
|
});
|
40
40
|
GetAllUsersCommand.ResponseSchema = zod_1.z.object({
|
41
41
|
response: zod_1.z.object({
|
42
|
-
users: zod_1.z.array(users_schema_1.UsersSchema
|
42
|
+
users: zod_1.z.array(users_schema_1.UsersSchema.extend({
|
43
|
+
totalUsedBytes: zod_1.z.string(),
|
44
|
+
})),
|
43
45
|
total: zod_1.z.number(),
|
44
46
|
}),
|
45
47
|
});
|
@@ -23,3 +23,4 @@ __exportStar(require("./get-user-by-short-uuid.command"), exports);
|
|
23
23
|
__exportStar(require("./get-user-by-subscription-uuid.command"), exports);
|
24
24
|
__exportStar(require("./get-user-by-uuid.command"), exports);
|
25
25
|
__exportStar(require("./revoke-user-subscription.command"), exports);
|
26
|
+
__exportStar(require("./update-user.command"), exports);
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UpdateUserCommand = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const api_1 = require("../../api");
|
6
|
+
const constants_1 = require("../../constants");
|
7
|
+
const models_1 = require("../../models");
|
8
|
+
var UpdateUserCommand;
|
9
|
+
(function (UpdateUserCommand) {
|
10
|
+
UpdateUserCommand.url = api_1.REST_API.USERS.UPDATE;
|
11
|
+
UpdateUserCommand.RequestSchema = models_1.UsersSchema.pick({
|
12
|
+
uuid: true,
|
13
|
+
}).extend({
|
14
|
+
status: models_1.UsersSchema.shape.status.optional(),
|
15
|
+
trafficLimitBytes: zod_1.z
|
16
|
+
.number({
|
17
|
+
invalid_type_error: 'Traffic limit must be a number',
|
18
|
+
})
|
19
|
+
.int('Traffic limit must be an integer')
|
20
|
+
.min(0, 'Traffic limit must be greater than 0')
|
21
|
+
.describe('Traffic limit in bytes. 0 - unlimited')
|
22
|
+
.optional(),
|
23
|
+
trafficLimitStrategy: models_1.UsersSchema.shape.trafficLimitStrategy
|
24
|
+
.describe('Traffic limit reset strategy')
|
25
|
+
.optional()
|
26
|
+
.default(constants_1.RESET_PERIODS.NO_RESET)
|
27
|
+
.superRefine((val, ctx) => {
|
28
|
+
if (val && !Object.values(constants_1.RESET_PERIODS).includes(val)) {
|
29
|
+
ctx.addIssue({
|
30
|
+
code: zod_1.z.ZodIssueCode.invalid_enum_value,
|
31
|
+
message: 'Invalid traffic limit strategy',
|
32
|
+
path: ['trafficLimitStrategy'],
|
33
|
+
received: val,
|
34
|
+
options: Object.values(constants_1.RESET_PERIODS),
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}),
|
38
|
+
enabledInbounds: zod_1.z
|
39
|
+
.array(models_1.InboundsSchema.pick({
|
40
|
+
uuid: true,
|
41
|
+
}), {
|
42
|
+
invalid_type_error: 'Enabled inbounds must be an array',
|
43
|
+
})
|
44
|
+
.optional(),
|
45
|
+
expireAt: zod_1.z.coerce
|
46
|
+
.date({
|
47
|
+
required_error: 'Expiration date is required',
|
48
|
+
invalid_type_error: 'Invalid expiration date format',
|
49
|
+
})
|
50
|
+
.refine((date) => date > new Date(), {
|
51
|
+
message: 'Expiration date cannot be in the past',
|
52
|
+
})
|
53
|
+
.optional(),
|
54
|
+
});
|
55
|
+
UpdateUserCommand.ResponseSchema = zod_1.z.object({
|
56
|
+
response: models_1.UsersSchema,
|
57
|
+
});
|
58
|
+
})(UpdateUserCommand || (exports.UpdateUserCommand = UpdateUserCommand = {}));
|
@@ -47,7 +47,12 @@ export namespace GetAllUsersCommand {
|
|
47
47
|
|
48
48
|
export const ResponseSchema = z.object({
|
49
49
|
response: z.object({
|
50
|
-
users: z.array(
|
50
|
+
users: z.array(
|
51
|
+
UsersSchema.extend({
|
52
|
+
totalUsedBytes: z.string(),
|
53
|
+
}),
|
54
|
+
),
|
55
|
+
|
51
56
|
total: z.number(),
|
52
57
|
}),
|
53
58
|
});
|
package/commands/users/index.ts
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { REST_API } from '../../api';
|
3
|
+
import { RESET_PERIODS } from '../../constants';
|
4
|
+
import { InboundsSchema, UsersSchema } from '../../models';
|
5
|
+
|
6
|
+
export namespace UpdateUserCommand {
|
7
|
+
export const url = REST_API.USERS.UPDATE;
|
8
|
+
|
9
|
+
export const RequestSchema = UsersSchema.pick({
|
10
|
+
uuid: true,
|
11
|
+
}).extend({
|
12
|
+
status: UsersSchema.shape.status.optional(),
|
13
|
+
trafficLimitBytes: z
|
14
|
+
.number({
|
15
|
+
invalid_type_error: 'Traffic limit must be a number',
|
16
|
+
})
|
17
|
+
.int('Traffic limit must be an integer')
|
18
|
+
.min(0, 'Traffic limit must be greater than 0')
|
19
|
+
.describe('Traffic limit in bytes. 0 - unlimited')
|
20
|
+
.optional(),
|
21
|
+
trafficLimitStrategy: UsersSchema.shape.trafficLimitStrategy
|
22
|
+
.describe('Traffic limit reset strategy')
|
23
|
+
.optional()
|
24
|
+
.default(RESET_PERIODS.NO_RESET)
|
25
|
+
.superRefine((val, ctx) => {
|
26
|
+
if (val && !Object.values(RESET_PERIODS).includes(val)) {
|
27
|
+
ctx.addIssue({
|
28
|
+
code: z.ZodIssueCode.invalid_enum_value,
|
29
|
+
message: 'Invalid traffic limit strategy',
|
30
|
+
path: ['trafficLimitStrategy'],
|
31
|
+
received: val,
|
32
|
+
options: Object.values(RESET_PERIODS),
|
33
|
+
});
|
34
|
+
}
|
35
|
+
}),
|
36
|
+
enabledInbounds: z
|
37
|
+
.array(
|
38
|
+
InboundsSchema.pick({
|
39
|
+
uuid: true,
|
40
|
+
}),
|
41
|
+
{
|
42
|
+
invalid_type_error: 'Enabled inbounds must be an array',
|
43
|
+
},
|
44
|
+
)
|
45
|
+
.optional(),
|
46
|
+
expireAt: z.coerce
|
47
|
+
.date({
|
48
|
+
required_error: 'Expiration date is required',
|
49
|
+
invalid_type_error: 'Invalid expiration date format',
|
50
|
+
})
|
51
|
+
.refine((date) => date > new Date(), {
|
52
|
+
message: 'Expiration date cannot be in the past',
|
53
|
+
})
|
54
|
+
.optional(),
|
55
|
+
});
|
56
|
+
|
57
|
+
export type Request = z.infer<typeof RequestSchema>;
|
58
|
+
|
59
|
+
export const ResponseSchema = z.object({
|
60
|
+
response: UsersSchema,
|
61
|
+
});
|
62
|
+
|
63
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
64
|
+
}
|