Skip to content

Commit c35ace5

Browse files
committed
feat: add tags support to nodes
- Updated Nodes model and related schemas to include tags as an array. - Enhanced create and update node commands to validate and handle tags. - Introduced new API routes for fetching node tags. - Updated service and repository methods to support tag retrieval and filtering. - Modified response models to include tags in node data. - Adjusted metrics providers to incorporate tags in metrics reporting.
1 parent 585c998 commit c35ace5

26 files changed

+181
-13
lines changed

libs/contract/api/controllers/nodes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ export const NODES_ROUTES = {
2424
USAGE_BY_RANGE_USER: (uuid: string) => `usage/${uuid}/users/range`,
2525
USAGE_REALTIME: 'usage/realtime',
2626
},
27+
28+
TAGS: {
29+
GET: 'tags',
30+
},
2731
} as const;

libs/contract/api/routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export const REST_API = {
4747
UPDATE: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.UPDATE}`,
4848
DELETE: (uuid: string) =>
4949
`${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.DELETE(uuid)}`,
50+
TAGS: {
51+
GET: `${ROOT}/${CONTROLLERS.NODES_CONTROLLER}/${CONTROLLERS.NODES_ROUTES.TAGS.GET}`,
52+
},
5053

5154
ACTIONS: {
5255
ENABLE: (uuid: string) =>

libs/contract/commands/nodes/create.command.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ export namespace CreateNodeCommand {
6060
}),
6161

6262
providerUuid: z.optional(z.nullable(z.string().uuid())),
63+
tags: z.optional(
64+
z
65+
.array(
66+
z
67+
.string()
68+
.regex(
69+
/^[A-Z0-9_:]+$/,
70+
'Tag can only contain uppercase letters, numbers, underscores and colons',
71+
)
72+
.max(36, 'Each tag must be less than 36 characters'),
73+
)
74+
.max(10, 'Maximum 10 tags'),
75+
),
6376
});
6477

6578
export type Request = z.infer<typeof RequestSchema>;

libs/contract/commands/nodes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './delete.command';
44
export * from './get-all.command';
55
export * from './get-one.command';
66
export * from './stats';
7+
export * from './tags';
78
export * from './update.command';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { z } from 'zod';
2+
3+
import { getEndpointDetails } from '../../../constants';
4+
import { REST_API, NODES_ROUTES } from '../../../api';
5+
6+
export namespace GetAllNodesTagsCommand {
7+
export const url = REST_API.NODES.TAGS.GET;
8+
export const TSQ_url = url;
9+
10+
export const endpointDetails = getEndpointDetails(
11+
NODES_ROUTES.TAGS.GET,
12+
'get',
13+
'Get all existing nodes tags',
14+
);
15+
16+
export const ResponseSchema = z.object({
17+
response: z.object({
18+
tags: z.array(z.string()),
19+
}),
20+
});
21+
22+
export type Response = z.infer<typeof ResponseSchema>;
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './get-all-nodes-tags.command';

libs/contract/commands/nodes/update.command.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ export namespace UpdateNodeCommand {
5454
.optional(),
5555

5656
providerUuid: z.optional(z.nullable(z.string().uuid())),
57+
tags: z.optional(
58+
z
59+
.array(
60+
z
61+
.string()
62+
.regex(
63+
/^[A-Z0-9_:]+$/,
64+
'Tag can only contain uppercase letters, numbers, underscores and colons',
65+
)
66+
.max(36, 'Each tag must be less than 36 characters'),
67+
)
68+
.max(10, 'Maximum 10 tags'),
69+
),
5770
});
5871

5972
export type Request = z.infer<typeof RequestSchema>;

libs/contract/models/nodes.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const NodesSchema = z.object({
3333
viewPosition: z.number().int(),
3434
countryCode: z.string(),
3535
consumptionMultiplier: z.number(),
36+
tags: z.array(z.string()),
3637

3738
cpuCount: z.nullable(z.number().int()),
3839
cpuModel: z.nullable(z.string()),

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "2.3.11",
3+
"version": "2.3.14",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "public"."nodes" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];

0 commit comments

Comments
 (0)