@flusys/nestjs-notification 5.1.1 → 5.1.2

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.
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "NotificationController", {
9
9
  }
10
10
  });
11
11
  const _classes = require("@flusys/nestjs-shared/classes");
12
- const _config = require("../config");
13
12
  const _decorators = require("@flusys/nestjs-shared/decorators");
14
13
  const _dtos = require("@flusys/nestjs-shared/dtos");
15
14
  const _guards = require("@flusys/nestjs-shared/guards");
@@ -17,6 +16,7 @@ const _interfaces = require("@flusys/nestjs-shared/interfaces");
17
16
  const _common = require("@nestjs/common");
18
17
  const _swagger = require("@nestjs/swagger");
19
18
  const _classtransformer = require("class-transformer");
19
+ const _config = require("../config");
20
20
  const _dtos1 = require("../dtos");
21
21
  const _notificationhelperservice = require("../services/notification-helper.service");
22
22
  const _notificationservice = require("../services/notification.service");
@@ -93,11 +93,14 @@ let NotificationController = class NotificationController extends (0, _classes.c
93
93
  }) {
94
94
  async markAsRead(dto, user) {
95
95
  const notification = await this.service.markAsRead(dto.id, user);
96
+ const plainOptions = {
97
+ excludeExtraneousValues: true
98
+ };
96
99
  return {
97
100
  success: true,
98
101
  message: 'Notification marked as read',
99
102
  messageKey: _config.NOTIFICATION_MESSAGES.MARK_READ_SUCCESS,
100
- data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification)
103
+ data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification, plainOptions)
101
104
  };
102
105
  }
103
106
  async markAllAsRead(user) {
@@ -131,11 +134,14 @@ let NotificationController = class NotificationController extends (0, _classes.c
131
134
  data: dto.data,
132
135
  companyId: dto.companyId
133
136
  });
137
+ const plainOptions = {
138
+ excludeExtraneousValues: true
139
+ };
134
140
  return {
135
141
  success: true,
136
142
  message: 'Notification sent successfully',
137
143
  messageKey: _config.NOTIFICATION_MESSAGES.SEND_SUCCESS,
138
- data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification)
144
+ data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification, plainOptions)
139
145
  };
140
146
  }
141
147
  async sendBulkNotification(dto) {
@@ -147,6 +153,9 @@ let NotificationController = class NotificationController extends (0, _classes.c
147
153
  data: dto.data,
148
154
  companyId: dto.companyId
149
155
  });
156
+ const plainOptions = {
157
+ excludeExtraneousValues: true
158
+ };
150
159
  return {
151
160
  success: true,
152
161
  message: `${notifications.length} notifications sent successfully`,
@@ -154,7 +163,7 @@ let NotificationController = class NotificationController extends (0, _classes.c
154
163
  messageVariables: {
155
164
  count: notifications.length
156
165
  },
157
- data: notifications.map((n)=>(0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, n)),
166
+ data: notifications.map((n)=>(0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, n, plainOptions)),
158
167
  meta: {
159
168
  count: notifications.length,
160
169
  total: dto.userIds.length
@@ -31,10 +31,10 @@ _export(exports, {
31
31
  return UpdateNotificationDto;
32
32
  }
33
33
  });
34
+ const _enums = require("@flusys/nestjs-shared/enums");
34
35
  const _swagger = require("@nestjs/swagger");
35
36
  const _classtransformer = require("class-transformer");
36
37
  const _classvalidator = require("class-validator");
37
- const _enums = require("@flusys/nestjs-shared/enums");
38
38
  function _define_property(obj, key, value) {
39
39
  if (key in obj) {
40
40
  Object.defineProperty(obj, key, {
@@ -173,59 +173,106 @@ let NotificationResponseDto = class NotificationResponseDto {
173
173
  };
174
174
  _ts_decorate([
175
175
  (0, _classtransformer.Expose)(),
176
- (0, _swagger.ApiProperty)(),
176
+ (0, _swagger.ApiProperty)({
177
+ description: 'Unique identifier of the notification',
178
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
179
+ }),
177
180
  _ts_metadata("design:type", String)
178
181
  ], NotificationResponseDto.prototype, "id", void 0);
179
182
  _ts_decorate([
180
183
  (0, _classtransformer.Expose)(),
181
- (0, _swagger.ApiProperty)(),
184
+ (0, _swagger.ApiProperty)({
185
+ description: 'ID of the user this notification belongs to',
186
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
187
+ }),
182
188
  _ts_metadata("design:type", String)
183
189
  ], NotificationResponseDto.prototype, "userId", void 0);
184
190
  _ts_decorate([
185
191
  (0, _classtransformer.Expose)(),
186
192
  (0, _swagger.ApiProperty)({
187
- enum: _enums.NotificationType
193
+ description: 'Category of the notification',
194
+ enum: _enums.NotificationType,
195
+ example: _enums.NotificationType.SUCCESS
188
196
  }),
189
- _ts_metadata("design:type", String)
197
+ _ts_metadata("design:type", typeof _enums.NotificationType === "undefined" ? Object : _enums.NotificationType)
190
198
  ], NotificationResponseDto.prototype, "type", void 0);
191
199
  _ts_decorate([
192
200
  (0, _classtransformer.Expose)(),
193
- (0, _swagger.ApiProperty)(),
201
+ (0, _swagger.ApiProperty)({
202
+ description: 'Short title of the notification',
203
+ example: 'Your export is ready'
204
+ }),
194
205
  _ts_metadata("design:type", String)
195
206
  ], NotificationResponseDto.prototype, "title", void 0);
196
207
  _ts_decorate([
197
208
  (0, _classtransformer.Expose)(),
198
- (0, _swagger.ApiPropertyOptional)(),
209
+ (0, _swagger.ApiPropertyOptional)({
210
+ description: 'Optional longer body text for the notification',
211
+ example: 'Your CSV export has finished processing and is ready to download.',
212
+ nullable: true
213
+ }),
199
214
  _ts_metadata("design:type", Object)
200
215
  ], NotificationResponseDto.prototype, "message", void 0);
201
216
  _ts_decorate([
202
217
  (0, _classtransformer.Expose)(),
203
- (0, _swagger.ApiPropertyOptional)(),
218
+ (0, _swagger.ApiPropertyOptional)({
219
+ description: 'Arbitrary JSON payload attached to the notification',
220
+ type: 'object',
221
+ additionalProperties: true,
222
+ nullable: true,
223
+ example: {
224
+ exportId: 'abc123',
225
+ fileUrl: 'https://cdn.example.com/export.csv'
226
+ }
227
+ }),
204
228
  _ts_metadata("design:type", Object)
205
229
  ], NotificationResponseDto.prototype, "data", void 0);
206
230
  _ts_decorate([
207
231
  (0, _classtransformer.Expose)(),
208
- (0, _swagger.ApiProperty)(),
232
+ (0, _swagger.ApiProperty)({
233
+ description: 'Whether the user has read this notification',
234
+ example: false
235
+ }),
209
236
  _ts_metadata("design:type", Boolean)
210
237
  ], NotificationResponseDto.prototype, "isRead", void 0);
211
238
  _ts_decorate([
212
239
  (0, _classtransformer.Expose)(),
213
- (0, _swagger.ApiPropertyOptional)(),
240
+ (0, _swagger.ApiPropertyOptional)({
241
+ description: 'Timestamp when the notification was marked as read; null if unread',
242
+ type: 'string',
243
+ format: 'date-time',
244
+ nullable: true,
245
+ example: '2024-03-15T10:30:00.000Z'
246
+ }),
214
247
  _ts_metadata("design:type", Object)
215
248
  ], NotificationResponseDto.prototype, "readAt", void 0);
216
249
  _ts_decorate([
217
250
  (0, _classtransformer.Expose)(),
218
- (0, _swagger.ApiPropertyOptional)(),
251
+ (0, _swagger.ApiPropertyOptional)({
252
+ description: 'Company scope for the notification; null for personal notifications',
253
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c',
254
+ nullable: true
255
+ }),
219
256
  _ts_metadata("design:type", Object)
220
257
  ], NotificationResponseDto.prototype, "companyId", void 0);
221
258
  _ts_decorate([
222
259
  (0, _classtransformer.Expose)(),
223
- (0, _swagger.ApiProperty)(),
260
+ (0, _swagger.ApiProperty)({
261
+ description: 'Timestamp when the notification was created',
262
+ type: 'string',
263
+ format: 'date-time',
264
+ example: '2024-03-15T10:00:00.000Z'
265
+ }),
224
266
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
225
267
  ], NotificationResponseDto.prototype, "createdAt", void 0);
226
268
  _ts_decorate([
227
269
  (0, _classtransformer.Expose)(),
228
- (0, _swagger.ApiProperty)(),
270
+ (0, _swagger.ApiProperty)({
271
+ description: 'Timestamp when the notification was last updated',
272
+ type: 'string',
273
+ format: 'date-time',
274
+ example: '2024-03-15T10:30:00.000Z'
275
+ }),
229
276
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
230
277
  ], NotificationResponseDto.prototype, "updatedAt", void 0);
231
278
  let UnreadCountResponseDto = class UnreadCountResponseDto {
@@ -235,7 +282,11 @@ let UnreadCountResponseDto = class UnreadCountResponseDto {
235
282
  };
236
283
  _ts_decorate([
237
284
  (0, _classtransformer.Expose)(),
238
- (0, _swagger.ApiProperty)(),
285
+ (0, _swagger.ApiProperty)({
286
+ description: 'Total number of unread notifications for the user',
287
+ example: 5,
288
+ minimum: 0
289
+ }),
239
290
  _ts_metadata("design:type", Number)
240
291
  ], UnreadCountResponseDto.prototype, "count", void 0);
241
292
  let SendNotificationDto = class SendNotificationDto extends (0, _swagger.IntersectionType)(UserIdDto, NotificationContentDto) {
@@ -25,7 +25,7 @@ export declare class MarkReadDto {
25
25
  export declare class NotificationResponseDto {
26
26
  id: string;
27
27
  userId: string;
28
- type: string;
28
+ type: NotificationType;
29
29
  title: string;
30
30
  message?: string | null;
31
31
  data?: Record<string, unknown> | null;
@@ -26,7 +26,6 @@ function _ts_param(paramIndex, decorator) {
26
26
  };
27
27
  }
28
28
  import { createApiController, NOTIFICATION_PERMISSIONS } from '@flusys/nestjs-shared/classes';
29
- import { NOTIFICATION_MESSAGES } from '../config';
30
29
  import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
31
30
  import { BulkResponseDto, MessageResponseDto, SingleResponseDto } from '@flusys/nestjs-shared/dtos';
32
31
  import { JwtAuthGuard, PermissionGuard } from '@flusys/nestjs-shared/guards';
@@ -34,6 +33,7 @@ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
34
33
  import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common';
35
34
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
36
35
  import { plainToInstance } from 'class-transformer';
36
+ import { NOTIFICATION_MESSAGES } from '../config';
37
37
  import { CreateNotificationDto, MarkReadDto, NotificationResponseDto, SendBulkNotificationDto, SendNotificationDto, UpdateNotificationDto } from '../dtos';
38
38
  import { NotificationHelperService } from '../services/notification-helper.service';
39
39
  import { NotificationService } from '../services/notification.service';
@@ -83,11 +83,14 @@ export class NotificationController extends createApiController(CreateNotificati
83
83
  }) {
84
84
  async markAsRead(dto, user) {
85
85
  const notification = await this.service.markAsRead(dto.id, user);
86
+ const plainOptions = {
87
+ excludeExtraneousValues: true
88
+ };
86
89
  return {
87
90
  success: true,
88
91
  message: 'Notification marked as read',
89
92
  messageKey: NOTIFICATION_MESSAGES.MARK_READ_SUCCESS,
90
- data: plainToInstance(NotificationResponseDto, notification)
93
+ data: plainToInstance(NotificationResponseDto, notification, plainOptions)
91
94
  };
92
95
  }
93
96
  async markAllAsRead(user) {
@@ -121,11 +124,14 @@ export class NotificationController extends createApiController(CreateNotificati
121
124
  data: dto.data,
122
125
  companyId: dto.companyId
123
126
  });
127
+ const plainOptions = {
128
+ excludeExtraneousValues: true
129
+ };
124
130
  return {
125
131
  success: true,
126
132
  message: 'Notification sent successfully',
127
133
  messageKey: NOTIFICATION_MESSAGES.SEND_SUCCESS,
128
- data: plainToInstance(NotificationResponseDto, notification)
134
+ data: plainToInstance(NotificationResponseDto, notification, plainOptions)
129
135
  };
130
136
  }
131
137
  async sendBulkNotification(dto) {
@@ -137,6 +143,9 @@ export class NotificationController extends createApiController(CreateNotificati
137
143
  data: dto.data,
138
144
  companyId: dto.companyId
139
145
  });
146
+ const plainOptions = {
147
+ excludeExtraneousValues: true
148
+ };
140
149
  return {
141
150
  success: true,
142
151
  message: `${notifications.length} notifications sent successfully`,
@@ -144,7 +153,7 @@ export class NotificationController extends createApiController(CreateNotificati
144
153
  messageVariables: {
145
154
  count: notifications.length
146
155
  },
147
- data: notifications.map((n)=>plainToInstance(NotificationResponseDto, n)),
156
+ data: notifications.map((n)=>plainToInstance(NotificationResponseDto, n, plainOptions)),
148
157
  meta: {
149
158
  count: notifications.length,
150
159
  total: dto.userIds.length
@@ -20,10 +20,10 @@ function _ts_decorate(decorators, target, key, desc) {
20
20
  function _ts_metadata(k, v) {
21
21
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
22
  }
23
+ import { NotificationType } from '@flusys/nestjs-shared/enums';
23
24
  import { ApiProperty, ApiPropertyOptional, IntersectionType, OmitType, PartialType } from '@nestjs/swagger';
24
25
  import { Expose } from 'class-transformer';
25
26
  import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
26
- import { NotificationType } from '@flusys/nestjs-shared/enums';
27
27
  let NotificationContentDto = class NotificationContentDto {
28
28
  constructor(){
29
29
  _define_property(this, "title", void 0);
@@ -140,59 +140,106 @@ export class NotificationResponseDto {
140
140
  }
141
141
  _ts_decorate([
142
142
  Expose(),
143
- ApiProperty(),
143
+ ApiProperty({
144
+ description: 'Unique identifier of the notification',
145
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
146
+ }),
144
147
  _ts_metadata("design:type", String)
145
148
  ], NotificationResponseDto.prototype, "id", void 0);
146
149
  _ts_decorate([
147
150
  Expose(),
148
- ApiProperty(),
151
+ ApiProperty({
152
+ description: 'ID of the user this notification belongs to',
153
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
154
+ }),
149
155
  _ts_metadata("design:type", String)
150
156
  ], NotificationResponseDto.prototype, "userId", void 0);
151
157
  _ts_decorate([
152
158
  Expose(),
153
159
  ApiProperty({
154
- enum: NotificationType
160
+ description: 'Category of the notification',
161
+ enum: NotificationType,
162
+ example: NotificationType.SUCCESS
155
163
  }),
156
- _ts_metadata("design:type", String)
164
+ _ts_metadata("design:type", typeof NotificationType === "undefined" ? Object : NotificationType)
157
165
  ], NotificationResponseDto.prototype, "type", void 0);
158
166
  _ts_decorate([
159
167
  Expose(),
160
- ApiProperty(),
168
+ ApiProperty({
169
+ description: 'Short title of the notification',
170
+ example: 'Your export is ready'
171
+ }),
161
172
  _ts_metadata("design:type", String)
162
173
  ], NotificationResponseDto.prototype, "title", void 0);
163
174
  _ts_decorate([
164
175
  Expose(),
165
- ApiPropertyOptional(),
176
+ ApiPropertyOptional({
177
+ description: 'Optional longer body text for the notification',
178
+ example: 'Your CSV export has finished processing and is ready to download.',
179
+ nullable: true
180
+ }),
166
181
  _ts_metadata("design:type", Object)
167
182
  ], NotificationResponseDto.prototype, "message", void 0);
168
183
  _ts_decorate([
169
184
  Expose(),
170
- ApiPropertyOptional(),
185
+ ApiPropertyOptional({
186
+ description: 'Arbitrary JSON payload attached to the notification',
187
+ type: 'object',
188
+ additionalProperties: true,
189
+ nullable: true,
190
+ example: {
191
+ exportId: 'abc123',
192
+ fileUrl: 'https://cdn.example.com/export.csv'
193
+ }
194
+ }),
171
195
  _ts_metadata("design:type", Object)
172
196
  ], NotificationResponseDto.prototype, "data", void 0);
173
197
  _ts_decorate([
174
198
  Expose(),
175
- ApiProperty(),
199
+ ApiProperty({
200
+ description: 'Whether the user has read this notification',
201
+ example: false
202
+ }),
176
203
  _ts_metadata("design:type", Boolean)
177
204
  ], NotificationResponseDto.prototype, "isRead", void 0);
178
205
  _ts_decorate([
179
206
  Expose(),
180
- ApiPropertyOptional(),
207
+ ApiPropertyOptional({
208
+ description: 'Timestamp when the notification was marked as read; null if unread',
209
+ type: 'string',
210
+ format: 'date-time',
211
+ nullable: true,
212
+ example: '2024-03-15T10:30:00.000Z'
213
+ }),
181
214
  _ts_metadata("design:type", Object)
182
215
  ], NotificationResponseDto.prototype, "readAt", void 0);
183
216
  _ts_decorate([
184
217
  Expose(),
185
- ApiPropertyOptional(),
218
+ ApiPropertyOptional({
219
+ description: 'Company scope for the notification; null for personal notifications',
220
+ example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c',
221
+ nullable: true
222
+ }),
186
223
  _ts_metadata("design:type", Object)
187
224
  ], NotificationResponseDto.prototype, "companyId", void 0);
188
225
  _ts_decorate([
189
226
  Expose(),
190
- ApiProperty(),
227
+ ApiProperty({
228
+ description: 'Timestamp when the notification was created',
229
+ type: 'string',
230
+ format: 'date-time',
231
+ example: '2024-03-15T10:00:00.000Z'
232
+ }),
191
233
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
192
234
  ], NotificationResponseDto.prototype, "createdAt", void 0);
193
235
  _ts_decorate([
194
236
  Expose(),
195
- ApiProperty(),
237
+ ApiProperty({
238
+ description: 'Timestamp when the notification was last updated',
239
+ type: 'string',
240
+ format: 'date-time',
241
+ example: '2024-03-15T10:30:00.000Z'
242
+ }),
196
243
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
197
244
  ], NotificationResponseDto.prototype, "updatedAt", void 0);
198
245
  export class UnreadCountResponseDto {
@@ -202,7 +249,11 @@ export class UnreadCountResponseDto {
202
249
  }
203
250
  _ts_decorate([
204
251
  Expose(),
205
- ApiProperty(),
252
+ ApiProperty({
253
+ description: 'Total number of unread notifications for the user',
254
+ example: 5,
255
+ minimum: 0
256
+ }),
206
257
  _ts_metadata("design:type", Number)
207
258
  ], UnreadCountResponseDto.prototype, "count", void 0);
208
259
  export class SendNotificationDto extends IntersectionType(UserIdDto, NotificationContentDto) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-notification",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Notification module with real-time Socket.IO support",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -92,8 +92,8 @@
92
92
  "express": "^4.18.0"
93
93
  },
94
94
  "dependencies": {
95
- "@flusys/nestjs-core": "5.1.1",
96
- "@flusys/nestjs-shared": "5.1.1",
95
+ "@flusys/nestjs-core": "5.1.2",
96
+ "@flusys/nestjs-shared": "5.1.2",
97
97
  "jsonwebtoken": "^9.0.0"
98
98
  }
99
99
  }