@flusys/nestjs-notification 7.0.2 → 8.0.0-beta.1

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.
Files changed (103) hide show
  1. package/adapters/index.d.ts +1 -1
  2. package/adapters/notification.adapter.d.ts +2 -2
  3. package/config/index.d.ts +3 -3
  4. package/controllers/index.d.ts +1 -1
  5. package/controllers/notification.controller.d.ts +4 -4
  6. package/docs/index.d.ts +1 -1
  7. package/docs/notification-swagger.config.d.ts +2 -2
  8. package/dtos/index.d.ts +1 -1
  9. package/entities/index.d.ts +5 -5
  10. package/entities/notification-with-company.entity.d.ts +1 -1
  11. package/fesm/244.js +816 -0
  12. package/fesm/446.js +939 -0
  13. package/fesm/adapters/index.js +79 -1
  14. package/fesm/config/index.js +84 -3
  15. package/fesm/controllers/index.js +13 -1
  16. package/fesm/docs/index.js +112 -1
  17. package/fesm/dtos/index.js +311 -1
  18. package/fesm/entities/index.js +211 -8
  19. package/fesm/gateways/index.js +286 -1
  20. package/fesm/index.js +467 -10
  21. package/fesm/interfaces/index.js +16 -2
  22. package/fesm/modules/index.js +269 -1
  23. package/fesm/runtime.js +85 -0
  24. package/fesm/services/index.js +357 -4
  25. package/gateways/index.d.ts +1 -1
  26. package/gateways/notification.gateway.d.ts +2 -2
  27. package/index.d.ts +10 -10
  28. package/interfaces/index.d.ts +2 -2
  29. package/interfaces/notification-module.interface.d.ts +3 -3
  30. package/interfaces/notification.interface.d.ts +1 -1
  31. package/modules/index.d.ts +1 -1
  32. package/modules/notification.module.d.ts +2 -2
  33. package/package.json +33 -44
  34. package/services/index.d.ts +4 -4
  35. package/services/notification-config.service.d.ts +3 -3
  36. package/services/notification-datasource.provider.d.ts +3 -3
  37. package/services/notification-helper.service.d.ts +5 -5
  38. package/services/notification.service.d.ts +8 -8
  39. package/cjs/adapters/index.js +0 -18
  40. package/cjs/adapters/notification.adapter.js +0 -62
  41. package/cjs/adapters/notification.adapter.spec.js +0 -73
  42. package/cjs/config/event-actions.js +0 -33
  43. package/cjs/config/index.js +0 -20
  44. package/cjs/config/message-keys.js +0 -19
  45. package/cjs/config/notification.constants.js +0 -11
  46. package/cjs/controllers/index.js +0 -18
  47. package/cjs/controllers/notification.controller.js +0 -299
  48. package/cjs/controllers/notification.controller.spec.js +0 -214
  49. package/cjs/docs/index.js +0 -18
  50. package/cjs/docs/notification-swagger.config.js +0 -97
  51. package/cjs/docs/notification-swagger.config.spec.js +0 -68
  52. package/cjs/dtos/index.js +0 -18
  53. package/cjs/dtos/notification.dto.js +0 -295
  54. package/cjs/entities/index.js +0 -48
  55. package/cjs/entities/index.spec.js +0 -13
  56. package/cjs/entities/notification-with-company.entity.js +0 -57
  57. package/cjs/entities/notification.entity.js +0 -112
  58. package/cjs/gateways/index.js +0 -18
  59. package/cjs/gateways/notification.gateway.js +0 -172
  60. package/cjs/gateways/notification.gateway.spec.js +0 -359
  61. package/cjs/index.js +0 -28
  62. package/cjs/interfaces/index.js +0 -19
  63. package/cjs/interfaces/notification-module.interface.js +0 -4
  64. package/cjs/interfaces/notification.interface.js +0 -4
  65. package/cjs/modules/index.js +0 -18
  66. package/cjs/modules/notification.module.js +0 -139
  67. package/cjs/modules/notification.module.spec.js +0 -152
  68. package/cjs/services/index.js +0 -21
  69. package/cjs/services/notification-config.service.js +0 -69
  70. package/cjs/services/notification-config.service.spec.js +0 -113
  71. package/cjs/services/notification-datasource.provider.js +0 -133
  72. package/cjs/services/notification-datasource.provider.spec.js +0 -136
  73. package/cjs/services/notification-helper.service.js +0 -197
  74. package/cjs/services/notification-helper.service.spec.js +0 -392
  75. package/cjs/services/notification.service.js +0 -281
  76. package/cjs/services/notification.service.spec.js +0 -560
  77. package/fesm/adapters/notification.adapter.js +0 -52
  78. package/fesm/adapters/notification.adapter.spec.js +0 -69
  79. package/fesm/config/event-actions.js +0 -12
  80. package/fesm/config/message-keys.js +0 -9
  81. package/fesm/config/notification.constants.js +0 -1
  82. package/fesm/controllers/notification.controller.js +0 -289
  83. package/fesm/controllers/notification.controller.spec.js +0 -210
  84. package/fesm/docs/notification-swagger.config.js +0 -87
  85. package/fesm/docs/notification-swagger.config.spec.js +0 -64
  86. package/fesm/dtos/notification.dto.js +0 -262
  87. package/fesm/entities/index.spec.js +0 -9
  88. package/fesm/entities/notification-with-company.entity.js +0 -47
  89. package/fesm/entities/notification.entity.js +0 -102
  90. package/fesm/gateways/notification.gateway.js +0 -162
  91. package/fesm/gateways/notification.gateway.spec.js +0 -355
  92. package/fesm/interfaces/notification-module.interface.js +0 -1
  93. package/fesm/interfaces/notification.interface.js +0 -1
  94. package/fesm/modules/notification.module.js +0 -129
  95. package/fesm/modules/notification.module.spec.js +0 -148
  96. package/fesm/services/notification-config.service.js +0 -59
  97. package/fesm/services/notification-config.service.spec.js +0 -109
  98. package/fesm/services/notification-datasource.provider.js +0 -82
  99. package/fesm/services/notification-datasource.provider.spec.js +0 -132
  100. package/fesm/services/notification-helper.service.js +0 -187
  101. package/fesm/services/notification-helper.service.spec.js +0 -388
  102. package/fesm/services/notification.service.js +0 -271
  103. package/fesm/services/notification.service.spec.js +0 -556
@@ -1,214 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _enums = require("@flusys/nestjs-shared/enums");
6
- const _loggedusermock = require("@test-utils/mocks/logged-user.mock");
7
- const _notificationcontroller = require("./notification.controller");
8
- const _config = require("../config");
9
- function buildNotification(overrides = {}) {
10
- return {
11
- id: 'notif-1',
12
- userId: 'user-uuid-1',
13
- type: _enums.NotificationType.INFO,
14
- title: 'Title',
15
- message: 'Message',
16
- data: null,
17
- isRead: false,
18
- readAt: null,
19
- createdAt: new Date(),
20
- updatedAt: new Date(),
21
- ...overrides
22
- };
23
- }
24
- describe('NotificationController', ()=>{
25
- let controller;
26
- let mockService;
27
- let mockHelper;
28
- beforeEach(()=>{
29
- mockService = {
30
- markAsRead: jest.fn(),
31
- markAllAsRead: jest.fn(),
32
- getUnreadCount: jest.fn(),
33
- insert: jest.fn(),
34
- insertMany: jest.fn(),
35
- findById: jest.fn(),
36
- findByIds: jest.fn(),
37
- update: jest.fn(),
38
- updateMany: jest.fn(),
39
- bulkUpsert: jest.fn(),
40
- getAll: jest.fn(),
41
- delete: jest.fn()
42
- };
43
- mockHelper = {
44
- send: jest.fn(),
45
- sendToMany: jest.fn(),
46
- isUserOnline: jest.fn(),
47
- getOnlineUserCount: jest.fn()
48
- };
49
- controller = new _notificationcontroller.NotificationController(mockService, mockHelper);
50
- });
51
- describe('markAsRead', ()=>{
52
- it('marks the notification as read and returns the mapped response', async ()=>{
53
- const user = (0, _loggedusermock.buildMockUser)();
54
- const notification = buildNotification({
55
- isRead: true
56
- });
57
- mockService.markAsRead.mockResolvedValue(notification);
58
- const result = await controller.markAsRead({
59
- id: 'notif-1'
60
- }, user);
61
- expect(mockService.markAsRead).toHaveBeenCalledWith('notif-1', user);
62
- expect(result.success).toBe(true);
63
- expect(result.messageKey).toBe(_config.NOTIFICATION_MESSAGES.MARK_READ_SUCCESS);
64
- expect(result.data?.id).toBe('notif-1');
65
- expect(result.data?.isRead).toBe(true);
66
- });
67
- it('propagates a not-found error from the service', async ()=>{
68
- mockService.markAsRead.mockRejectedValue(new Error(_config.NOTIFICATION_MESSAGES.NOT_FOUND));
69
- await expect(controller.markAsRead({
70
- id: 'missing'
71
- }, (0, _loggedusermock.buildMockUser)())).rejects.toThrow();
72
- });
73
- });
74
- describe('markAllAsRead', ()=>{
75
- it('returns the count of notifications marked as read', async ()=>{
76
- mockService.markAllAsRead.mockResolvedValue(3);
77
- const result = await controller.markAllAsRead((0, _loggedusermock.buildMockUser)());
78
- expect(result.success).toBe(true);
79
- expect(result.messageKey).toBe(_config.NOTIFICATION_MESSAGES.MARK_ALL_READ_SUCCESS);
80
- expect(result.messageVariables).toEqual({
81
- count: 3
82
- });
83
- expect(result.message).toBe('3 notifications marked as read');
84
- });
85
- it('handles a user with zero unread notifications gracefully', async ()=>{
86
- mockService.markAllAsRead.mockResolvedValue(0);
87
- const result = await controller.markAllAsRead((0, _loggedusermock.buildMockUser)());
88
- expect(result.messageVariables).toEqual({
89
- count: 0
90
- });
91
- expect(result.message).toBe('0 notifications marked as read');
92
- });
93
- });
94
- describe('getUnreadCount', ()=>{
95
- it('returns the unread count wrapped in a single response', async ()=>{
96
- mockService.getUnreadCount.mockResolvedValue(5);
97
- const result = await controller.getUnreadCount((0, _loggedusermock.buildMockUser)());
98
- expect(result.success).toBe(true);
99
- expect(result.messageKey).toBe(_config.NOTIFICATION_MESSAGES.UNREAD_COUNT_SUCCESS);
100
- expect(result.data).toEqual({
101
- count: 5
102
- });
103
- });
104
- it('returns zero for a user with no unread notifications', async ()=>{
105
- mockService.getUnreadCount.mockResolvedValue(0);
106
- const result = await controller.getUnreadCount((0, _loggedusermock.buildMockUser)());
107
- expect(result.data).toEqual({
108
- count: 0
109
- });
110
- });
111
- });
112
- describe('sendNotification', ()=>{
113
- it('sends a notification via the helper service and returns the mapped response', async ()=>{
114
- const notification = buildNotification({
115
- id: 'notif-2'
116
- });
117
- mockHelper.send.mockResolvedValue(notification);
118
- const result = await controller.sendNotification({
119
- userId: 'user-uuid-1',
120
- title: 'Hello',
121
- message: 'World'
122
- });
123
- expect(mockHelper.send).toHaveBeenCalledWith({
124
- userId: 'user-uuid-1',
125
- title: 'Hello',
126
- message: 'World',
127
- type: undefined,
128
- data: undefined,
129
- companyId: undefined
130
- });
131
- expect(result.success).toBe(true);
132
- expect(result.messageKey).toBe(_config.NOTIFICATION_MESSAGES.SEND_SUCCESS);
133
- expect(result.data?.id).toBe('notif-2');
134
- });
135
- it('propagates errors from the helper service', async ()=>{
136
- mockHelper.send.mockRejectedValue(new Error('db down'));
137
- await expect(controller.sendNotification({
138
- userId: 'user-1',
139
- title: 'X'
140
- })).rejects.toThrow('db down');
141
- });
142
- });
143
- describe('sendBulkNotification', ()=>{
144
- it('sends notifications to multiple users and returns bulk meta', async ()=>{
145
- const notifications = [
146
- buildNotification({
147
- id: 'n1',
148
- userId: 'user-1'
149
- }),
150
- buildNotification({
151
- id: 'n2',
152
- userId: 'user-2'
153
- })
154
- ];
155
- mockHelper.sendToMany.mockResolvedValue(notifications);
156
- const result = await controller.sendBulkNotification({
157
- userIds: [
158
- 'user-1',
159
- 'user-2'
160
- ],
161
- title: 'Broadcast'
162
- });
163
- expect(mockHelper.sendToMany).toHaveBeenCalledWith({
164
- userIds: [
165
- 'user-1',
166
- 'user-2'
167
- ],
168
- title: 'Broadcast',
169
- message: undefined,
170
- type: undefined,
171
- data: undefined,
172
- companyId: undefined
173
- });
174
- expect(result.success).toBe(true);
175
- expect(result.messageKey).toBe(_config.NOTIFICATION_MESSAGES.BROADCAST_SUCCESS);
176
- expect(result.data).toHaveLength(2);
177
- expect(result.meta).toEqual({
178
- count: 2,
179
- total: 2
180
- });
181
- });
182
- it('reports a mismatch between requested and sent counts in the meta', async ()=>{
183
- mockHelper.sendToMany.mockResolvedValue([
184
- buildNotification({
185
- id: 'n1'
186
- })
187
- ]);
188
- const result = await controller.sendBulkNotification({
189
- userIds: [
190
- 'user-1',
191
- 'user-2',
192
- 'user-3'
193
- ],
194
- title: 'Partial broadcast'
195
- });
196
- expect(result.meta).toEqual({
197
- count: 1,
198
- total: 3
199
- });
200
- });
201
- it('handles an empty userIds bulk send without throwing', async ()=>{
202
- mockHelper.sendToMany.mockResolvedValue([]);
203
- const result = await controller.sendBulkNotification({
204
- userIds: [],
205
- title: 'Nobody'
206
- });
207
- expect(result.data).toEqual([]);
208
- expect(result.meta).toEqual({
209
- count: 0,
210
- total: 0
211
- });
212
- });
213
- });
214
- });
package/cjs/docs/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./notification-swagger.config"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
13
- }
14
- });
15
- }
16
- });
17
- return from;
18
- }
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "notificationSwaggerConfig", {
6
- enumerable: true,
7
- get: function() {
8
- return notificationSwaggerConfig;
9
- }
10
- });
11
- /** Schema properties to exclude when company feature is disabled */ const COMPANY_SCHEMA_EXCLUSIONS = [
12
- {
13
- schemaName: 'NotificationResponseDto',
14
- properties: [
15
- 'companyId'
16
- ]
17
- },
18
- {
19
- schemaName: 'CreateNotificationDto',
20
- properties: [
21
- 'companyId'
22
- ]
23
- },
24
- {
25
- schemaName: 'SendNotificationDto',
26
- properties: [
27
- 'companyId'
28
- ]
29
- },
30
- {
31
- schemaName: 'SendBulkNotificationDto',
32
- properties: [
33
- 'companyId'
34
- ]
35
- },
36
- {
37
- schemaName: 'UpdateNotificationDto',
38
- properties: [
39
- 'companyId'
40
- ]
41
- }
42
- ];
43
- function notificationSwaggerConfig(bootstrapConfig) {
44
- const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
45
- const isMultiTenant = bootstrapConfig?.databaseMode === 'multi-tenant';
46
- const multiTenantNote = isMultiTenant ? `\n> **Multi-Tenant Mode**: Include \`x-tenant-id\` header to target a specific tenant database.\n` : '';
47
- return {
48
- title: 'Notification API',
49
- description: `
50
- ## Notification API
51
- ${multiTenantNote}
52
- Real-time notification system with WebSocket support.
53
-
54
- ### Features
55
- - Push notifications to users
56
- - Mark notifications as read
57
- - Unread count tracking
58
- - Real-time delivery via WebSocket
59
- - Bulk notification sending
60
-
61
- ### Endpoints
62
-
63
- #### User Notifications
64
- - \`POST /notification/get-all\` - Get user's notifications (paginated, sorted by newest)
65
- - \`POST /notification/get/:id\` - Get single notification
66
- - \`POST /notification/mark-read\` - Mark notification as read
67
- - \`POST /notification/mark-all-read\` - Mark all notifications as read
68
- - \`POST /notification/unread-count\` - Get unread notification count
69
-
70
- #### Admin/System
71
- - \`POST /notification/send\` - Send notification to a user
72
- - \`POST /notification/send-bulk\` - Send notification to multiple users
73
-
74
- ### WebSocket Events
75
-
76
- Connect to WebSocket with JWT authentication:
77
- \`\`\`
78
- ws://localhost:2002/notification?token=<jwt>
79
- \`\`\`
80
-
81
- **Events:**
82
- - \`notification:new\` - New notification received
83
- - \`notification:read\` - Notification marked as read
84
- - \`notification:read-all\` - All notifications marked as read
85
-
86
- ### Notification Types
87
- - \`info\` - General information
88
- - \`success\` - Success message
89
- - \`warning\` - Warning message
90
- - \`error\` - Error message
91
- `,
92
- version: '1.0',
93
- path: 'api/docs/notification',
94
- bearerAuth: true,
95
- excludeSchemaProperties: enableCompanyFeature ? undefined : COMPANY_SCHEMA_EXCLUSIONS
96
- };
97
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _notificationswaggerconfig = require("./notification-swagger.config");
6
- describe('notificationSwaggerConfig', ()=>{
7
- it('should default to company feature enabled and single-database mode when no config is given', ()=>{
8
- const config = (0, _notificationswaggerconfig.notificationSwaggerConfig)();
9
- expect(config.title).toBe('Notification API');
10
- expect(config.path).toBe('api/docs/notification');
11
- expect(config.bearerAuth).toBe(true);
12
- expect(config.excludeSchemaProperties).toBeUndefined();
13
- expect(config.description).not.toContain('Multi-Tenant Mode');
14
- });
15
- it('should exclude companyId schema properties across all notification DTOs when the company feature is disabled', ()=>{
16
- const config = (0, _notificationswaggerconfig.notificationSwaggerConfig)({
17
- enableCompanyFeature: false
18
- });
19
- expect(config.excludeSchemaProperties).toEqual([
20
- {
21
- schemaName: 'NotificationResponseDto',
22
- properties: [
23
- 'companyId'
24
- ]
25
- },
26
- {
27
- schemaName: 'CreateNotificationDto',
28
- properties: [
29
- 'companyId'
30
- ]
31
- },
32
- {
33
- schemaName: 'SendNotificationDto',
34
- properties: [
35
- 'companyId'
36
- ]
37
- },
38
- {
39
- schemaName: 'SendBulkNotificationDto',
40
- properties: [
41
- 'companyId'
42
- ]
43
- },
44
- {
45
- schemaName: 'UpdateNotificationDto',
46
- properties: [
47
- 'companyId'
48
- ]
49
- }
50
- ]);
51
- });
52
- it('should not exclude any schema properties when the company feature is enabled', ()=>{
53
- const config = (0, _notificationswaggerconfig.notificationSwaggerConfig)({
54
- enableCompanyFeature: true
55
- });
56
- expect(config.excludeSchemaProperties).toBeUndefined();
57
- });
58
- it('should mention multi-tenant mode in the description only for multi-tenant database mode', ()=>{
59
- const multiTenant = (0, _notificationswaggerconfig.notificationSwaggerConfig)({
60
- databaseMode: 'multi-tenant'
61
- });
62
- const single = (0, _notificationswaggerconfig.notificationSwaggerConfig)({
63
- databaseMode: 'single'
64
- });
65
- expect(multiTenant.description).toContain('Multi-Tenant Mode');
66
- expect(single.description).not.toContain('Multi-Tenant Mode');
67
- });
68
- });
package/cjs/dtos/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./notification.dto"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
13
- }
14
- });
15
- }
16
- });
17
- return from;
18
- }