diff --git a/package.json b/package.json index a45dd62..928337d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lendry-erp/contracts", - "version": "1.2.23", + "version": "1.2.24", "description": "Protobuf definitions and generated TypeScript types", "type": "commonjs", "main": "./dist/index.js", diff --git a/proto/notifications/notifications.proto b/proto/notifications/notifications.proto new file mode 100644 index 0000000..468ed7d --- /dev/null +++ b/proto/notifications/notifications.proto @@ -0,0 +1,107 @@ +syntax = "proto3"; + +// Указываем пакет для логической изоляции +package notifications.v1; + +// Импортируем стандартные типы Google для работы с датами и произвольным JSON +import "google/protobuf/timestamp.proto"; +import "google/protobuf/struct.proto"; + +// Опции для генерации кода (особенно полезно для Go, если понадобится) +option go_package = "git.lendry.ru/lendry-erp/proto.git/go;pb"; + +// ----------------------------------------------------------------------------- +// Сервис Уведомлений +// ----------------------------------------------------------------------------- +service NotificationService { + // --- Публичные методы (Вызываются из API Gateway от лица клиента) --- + + // Получить список уведомлений пользователя с пагинацией + rpc GetUserNotifications (GetNotificationsRequest) returns (GetNotificationsResponse); + + // Получить количество непрочитанных уведомлений (для бейджика на иконке) + rpc GetUnreadCount (GetUnreadCountRequest) returns (GetUnreadCountResponse); + + // Отметить конкретное уведомление как прочитанное + rpc MarkAsRead (MarkAsReadRequest) returns (MarkAsReadResponse); + + // Отметить все уведомления пользователя как прочитанные + rpc MarkAllAsRead (MarkAllAsReadRequest) returns (MarkAllAsReadResponse); + + + // --- Внутренние методы (Вызываются другими микросервисами: CRM, ERP, Auth) --- + + // Отправить уведомление (CRM/ERP вызывает этот метод, а NestJS уже кидает в RabbitMQ) + rpc SendNotification (SendNotificationRequest) returns (SendNotificationResponse); +} + +// ----------------------------------------------------------------------------- +// Базовые модели +// ----------------------------------------------------------------------------- + +// Структура самого уведомления +message Notification { + string id = 1; + string user_id = 2; + string type = 3; // Например: "SYSTEM_ALERT", "NEW_MESSAGE", "TASK_ASSIGNED" + string title = 4; // Заголовок (опционально) + string text = 5; // Текст уведомления + google.protobuf.Struct payload = 6; // Любая динамическая JSON-нагрузка (например, { "task_id": 123 }) + bool is_read = 7; + google.protobuf.Timestamp created_at = 8; +} + +// ----------------------------------------------------------------------------- +// Запросы и ответы (Requests / Responses) +// ----------------------------------------------------------------------------- + +message GetNotificationsRequest { + string user_id = 1; // ID пользователя запрашивающего данные (Gateway берет это из JWT) + int32 limit = 2; // Для пагинации (например, 20) + int32 offset = 3; // Для пагинации (например, 0) + optional bool unread_only = 4; // Фильтр: получить только непрочитанные +} + +message GetNotificationsResponse { + repeated Notification notifications = 1; // Массив уведомлений + int32 total_count = 2; // Общее количество (для UI пагинации) +} + +message GetUnreadCountRequest { + string user_id = 1; +} + +message GetUnreadCountResponse { + int32 count = 1; +} + +message MarkAsReadRequest { + string user_id = 1; + string notification_id = 2; +} + +message MarkAsReadResponse { + bool success = 1; +} + +message MarkAllAsReadRequest { + string user_id = 1; +} + +message MarkAllAsReadResponse { + bool success = 1; + int32 updated_count = 2; // Сколько уведомлений было обновлено +} + +message SendNotificationRequest { + string user_id = 1; // Кому отправляем (если пусто — можно сделать бродкаст, но лучше отдельный метод) + string type = 2; + string title = 3; + string text = 4; + google.protobuf.Struct payload = 5; // Метаданные для UI (ссылки, ID сущностей) +} + +message SendNotificationResponse { + bool success = 1; + string notification_id = 2; // ID созданного уведомления в Postgres +} \ No newline at end of file diff --git a/src/proto/paths.ts b/src/proto/paths.ts index ca8f98f..2edf46f 100644 --- a/src/proto/paths.ts +++ b/src/proto/paths.ts @@ -11,4 +11,8 @@ export const PROTO_PATHS = { LDAP: join(__dirname, "../../proto/users/ldap.proto"), SEARCH: join(__dirname, "../../proto/search/search.proto"), AUDIT: join(__dirname, "../../proto/admin/audit.proto"), + NOTIFICATIONS: join( + __dirname, + "../../proto/notifications/notifications.proto", + ), } as const;