@remnawave/backend-contract 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,28 +8,22 @@ var CreateNodeCommand;
8
8
  (function (CreateNodeCommand) {
9
9
  CreateNodeCommand.url = api_1.REST_API.NODES.CREATE;
10
10
  CreateNodeCommand.TSQ_url = CreateNodeCommand.url;
11
- CreateNodeCommand.RequestSchema = models_1.NodesSchema.pick({}).extend({
11
+ CreateNodeCommand.RequestSchema = zod_1.z.object({
12
12
  name: zod_1.z.string().min(5, 'Name is required'),
13
13
  address: zod_1.z.string().min(2, 'Address is required'),
14
14
  port: zod_1.z.number().int().min(1, 'Port is required').optional(),
15
15
  isTrafficTrackingActive: zod_1.z.boolean().optional().default(false),
16
- trafficLimitBytes: zod_1.z
17
- .number()
18
- .int()
19
- .min(0, 'Traffic limit must be greater than 0')
20
- .optional(),
21
- notifyPercent: zod_1.z
16
+ trafficLimitBytes: zod_1.z.optional(zod_1.z.number().int().min(0, 'Traffic limit must be greater than 0')),
17
+ notifyPercent: zod_1.z.optional(zod_1.z
22
18
  .number()
23
19
  .int()
24
20
  .min(0, 'Notify percent must be greater than 0')
25
- .max(100, 'Notify percent must be less than 100')
26
- .optional(),
27
- trafficResetDay: zod_1.z
21
+ .max(100, 'Notify percent must be less than 100')),
22
+ trafficResetDay: zod_1.z.optional(zod_1.z
28
23
  .number()
29
24
  .int()
30
25
  .min(1, 'Traffic reset day must be greater than 0')
31
- .max(31, 'Traffic reset day must be less than 31')
32
- .optional(),
26
+ .max(31, 'Traffic reset day must be less than 31')),
33
27
  });
34
28
  CreateNodeCommand.ResponseSchema = zod_1.z.object({
35
29
  response: models_1.NodesSchema,
@@ -10,7 +10,8 @@ var UpdateNodeCommand;
10
10
  UpdateNodeCommand.TSQ_url = UpdateNodeCommand.url;
11
11
  UpdateNodeCommand.RequestSchema = models_1.NodesSchema.pick({
12
12
  uuid: true,
13
- }).extend({
13
+ })
14
+ .extend({
14
15
  name: zod_1.z.optional(zod_1.z.string().min(5, 'Min. 5 characters')),
15
16
  address: zod_1.z.optional(zod_1.z.string().min(2, 'Min. 2 characters')),
16
17
  port: zod_1.z.optional(zod_1.z.number()),
@@ -24,6 +25,17 @@ var UpdateNodeCommand;
24
25
  .number()
25
26
  .min(1, 'Traffic reset day must be greater than 0')
26
27
  .max(31, 'Traffic reset day must be less than 31')),
28
+ })
29
+ .refine((data) => {
30
+ if (data.isTrafficTrackingActive) {
31
+ return (data.trafficLimitBytes != null &&
32
+ data.notifyPercent != null &&
33
+ data.trafficResetDay != null);
34
+ }
35
+ return true;
36
+ }, {
37
+ message: 'Traffic tracking fields are required when isTrafficTrackingActive is true',
38
+ path: ['trafficLimitBytes', 'notifyPercent', 'trafficResetDay'],
27
39
  });
28
40
  UpdateNodeCommand.ResponseSchema = zod_1.z.object({
29
41
  response: models_1.NodesSchema,
@@ -6,28 +6,28 @@ export namespace CreateNodeCommand {
6
6
  export const url = REST_API.NODES.CREATE;
7
7
  export const TSQ_url = url;
8
8
 
9
- export const RequestSchema = NodesSchema.pick({}).extend({
9
+ export const RequestSchema = z.object({
10
10
  name: z.string().min(5, 'Name is required'),
11
11
  address: z.string().min(2, 'Address is required'),
12
12
  port: z.number().int().min(1, 'Port is required').optional(),
13
13
  isTrafficTrackingActive: z.boolean().optional().default(false),
14
- trafficLimitBytes: z
15
- .number()
16
- .int()
17
- .min(0, 'Traffic limit must be greater than 0')
18
- .optional(),
19
- notifyPercent: z
20
- .number()
21
- .int()
22
- .min(0, 'Notify percent must be greater than 0')
23
- .max(100, 'Notify percent must be less than 100')
24
- .optional(),
25
- trafficResetDay: z
26
- .number()
27
- .int()
28
- .min(1, 'Traffic reset day must be greater than 0')
29
- .max(31, 'Traffic reset day must be less than 31')
30
- .optional(),
14
+ trafficLimitBytes: z.optional(
15
+ z.number().int().min(0, 'Traffic limit must be greater than 0'),
16
+ ),
17
+ notifyPercent: z.optional(
18
+ 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
+ ),
24
+ trafficResetDay: z.optional(
25
+ z
26
+ .number()
27
+ .int()
28
+ .min(1, 'Traffic reset day must be greater than 0')
29
+ .max(31, 'Traffic reset day must be less than 31'),
30
+ ),
31
31
  });
32
32
 
33
33
  export type Request = z.infer<typeof RequestSchema>;
@@ -8,25 +8,45 @@ export namespace UpdateNodeCommand {
8
8
 
9
9
  export const RequestSchema = NodesSchema.pick({
10
10
  uuid: true,
11
- }).extend({
12
- name: z.optional(z.string().min(5, 'Min. 5 characters')),
13
- address: z.optional(z.string().min(2, 'Min. 2 characters')),
14
- port: z.optional(z.number()),
15
- isTrafficTrackingActive: z.optional(z.boolean()),
16
- trafficLimitBytes: z.optional(z.number().min(0, 'Traffic limit must be greater than 0')),
17
- notifyPercent: z.optional(
18
- z
19
- .number()
20
- .min(0, 'Notify percent must be greater than 0')
21
- .max(100, 'Notify percent must be less than 100'),
22
- ),
23
- trafficResetDay: z.optional(
24
- z
25
- .number()
26
- .min(1, 'Traffic reset day must be greater than 0')
27
- .max(31, 'Traffic reset day must be less than 31'),
28
- ),
29
- });
11
+ })
12
+ .extend({
13
+ name: z.optional(z.string().min(5, 'Min. 5 characters')),
14
+ address: z.optional(z.string().min(2, 'Min. 2 characters')),
15
+ port: z.optional(z.number()),
16
+ isTrafficTrackingActive: z.optional(z.boolean()),
17
+ trafficLimitBytes: z.optional(
18
+ z.number().min(0, 'Traffic limit must be greater than 0'),
19
+ ),
20
+ notifyPercent: z.optional(
21
+ z
22
+ .number()
23
+ .min(0, 'Notify percent must be greater than 0')
24
+ .max(100, 'Notify percent must be less than 100'),
25
+ ),
26
+ trafficResetDay: z.optional(
27
+ z
28
+ .number()
29
+ .min(1, 'Traffic reset day must be greater than 0')
30
+ .max(31, 'Traffic reset day must be less than 31'),
31
+ ),
32
+ })
33
+ .refine(
34
+ (data) => {
35
+ if (data.isTrafficTrackingActive) {
36
+ return (
37
+ data.trafficLimitBytes != null &&
38
+ data.notifyPercent != null &&
39
+ data.trafficResetDay != null
40
+ );
41
+ }
42
+ return true;
43
+ },
44
+ {
45
+ message:
46
+ 'Traffic tracking fields are required when isTrafficTrackingActive is true',
47
+ path: ['trafficLimitBytes', 'notifyPercent', 'trafficResetDay'],
48
+ },
49
+ );
30
50
 
31
51
  export type Request = z.infer<typeof RequestSchema>;
32
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/backend-contract",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "A contract library for Remnawave",
5
5
  "main": "index.js",
6
6
  "scripts": {