@flusys/nestjs-notification 7.1.0 → 8.0.0
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.
- package/adapters/index.d.ts +1 -1
- package/adapters/notification.adapter.d.ts +2 -2
- package/config/index.d.ts +3 -3
- package/controllers/index.d.ts +1 -1
- package/controllers/notification.controller.d.ts +4 -4
- package/docs/index.d.ts +1 -1
- package/docs/notification-swagger.config.d.ts +2 -2
- package/dtos/index.d.ts +1 -1
- package/entities/index.d.ts +5 -5
- package/entities/notification-with-company.entity.d.ts +1 -1
- package/fesm/244.js +816 -0
- package/fesm/446.js +939 -0
- package/fesm/adapters/index.js +79 -1
- package/fesm/config/index.js +84 -3
- package/fesm/controllers/index.js +13 -1
- package/fesm/docs/index.js +112 -1
- package/fesm/dtos/index.js +311 -1
- package/fesm/entities/index.js +211 -8
- package/fesm/gateways/index.js +286 -1
- package/fesm/index.js +467 -10
- package/fesm/interfaces/index.js +16 -2
- package/fesm/modules/index.js +269 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +357 -4
- package/gateways/index.d.ts +1 -1
- package/gateways/notification.gateway.d.ts +2 -2
- package/index.d.ts +10 -10
- package/interfaces/index.d.ts +2 -2
- package/interfaces/notification-module.interface.d.ts +3 -3
- package/interfaces/notification.interface.d.ts +1 -1
- package/modules/index.d.ts +1 -1
- package/modules/notification.module.d.ts +2 -2
- package/package.json +33 -44
- package/services/index.d.ts +4 -4
- package/services/notification-config.service.d.ts +3 -3
- package/services/notification-datasource.provider.d.ts +3 -3
- package/services/notification-helper.service.d.ts +5 -5
- package/services/notification.service.d.ts +8 -8
- package/cjs/adapters/index.js +0 -18
- package/cjs/adapters/notification.adapter.js +0 -62
- package/cjs/adapters/notification.adapter.spec.js +0 -73
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -19
- package/cjs/config/notification.constants.js +0 -11
- package/cjs/controllers/index.js +0 -18
- package/cjs/controllers/notification.controller.js +0 -299
- package/cjs/controllers/notification.controller.spec.js +0 -214
- package/cjs/docs/index.js +0 -18
- package/cjs/docs/notification-swagger.config.js +0 -97
- package/cjs/docs/notification-swagger.config.spec.js +0 -68
- package/cjs/dtos/index.js +0 -18
- package/cjs/dtos/notification.dto.js +0 -295
- package/cjs/entities/index.js +0 -48
- package/cjs/entities/index.spec.js +0 -13
- package/cjs/entities/notification-with-company.entity.js +0 -57
- package/cjs/entities/notification.entity.js +0 -112
- package/cjs/gateways/index.js +0 -18
- package/cjs/gateways/notification.gateway.js +0 -172
- package/cjs/gateways/notification.gateway.spec.js +0 -359
- package/cjs/index.js +0 -28
- package/cjs/interfaces/index.js +0 -19
- package/cjs/interfaces/notification-module.interface.js +0 -4
- package/cjs/interfaces/notification.interface.js +0 -4
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/notification.module.js +0 -139
- package/cjs/modules/notification.module.spec.js +0 -152
- package/cjs/services/index.js +0 -21
- package/cjs/services/notification-config.service.js +0 -69
- package/cjs/services/notification-config.service.spec.js +0 -113
- package/cjs/services/notification-datasource.provider.js +0 -133
- package/cjs/services/notification-datasource.provider.spec.js +0 -136
- package/cjs/services/notification-helper.service.js +0 -197
- package/cjs/services/notification-helper.service.spec.js +0 -392
- package/cjs/services/notification.service.js +0 -281
- package/cjs/services/notification.service.spec.js +0 -560
- package/fesm/adapters/notification.adapter.js +0 -52
- package/fesm/adapters/notification.adapter.spec.js +0 -69
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/message-keys.js +0 -9
- package/fesm/config/notification.constants.js +0 -1
- package/fesm/controllers/notification.controller.js +0 -289
- package/fesm/controllers/notification.controller.spec.js +0 -210
- package/fesm/docs/notification-swagger.config.js +0 -87
- package/fesm/docs/notification-swagger.config.spec.js +0 -64
- package/fesm/dtos/notification.dto.js +0 -262
- package/fesm/entities/index.spec.js +0 -9
- package/fesm/entities/notification-with-company.entity.js +0 -47
- package/fesm/entities/notification.entity.js +0 -102
- package/fesm/gateways/notification.gateway.js +0 -162
- package/fesm/gateways/notification.gateway.spec.js +0 -355
- package/fesm/interfaces/notification-module.interface.js +0 -1
- package/fesm/interfaces/notification.interface.js +0 -1
- package/fesm/modules/notification.module.js +0 -129
- package/fesm/modules/notification.module.spec.js +0 -148
- package/fesm/services/notification-config.service.js +0 -59
- package/fesm/services/notification-config.service.spec.js +0 -109
- package/fesm/services/notification-datasource.provider.js +0 -82
- package/fesm/services/notification-datasource.provider.spec.js +0 -132
- package/fesm/services/notification-helper.service.js +0 -187
- package/fesm/services/notification-helper.service.spec.js +0 -388
- package/fesm/services/notification.service.js +0 -271
- package/fesm/services/notification.service.spec.js +0 -556
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { NotificationType } from '@flusys/nestjs-shared/enums';
|
|
24
|
-
import { ApiProperty, ApiPropertyOptional, IntersectionType, OmitType, PartialType } from '@nestjs/swagger';
|
|
25
|
-
import { Expose } from 'class-transformer';
|
|
26
|
-
import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
|
|
27
|
-
let NotificationContentDto = class NotificationContentDto {
|
|
28
|
-
constructor(){
|
|
29
|
-
_define_property(this, "title", void 0);
|
|
30
|
-
_define_property(this, "message", void 0);
|
|
31
|
-
_define_property(this, "type", void 0);
|
|
32
|
-
_define_property(this, "data", void 0);
|
|
33
|
-
_define_property(this, "companyId", void 0);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
_ts_decorate([
|
|
37
|
-
ApiProperty({
|
|
38
|
-
maxLength: 255
|
|
39
|
-
}),
|
|
40
|
-
IsNotEmpty(),
|
|
41
|
-
IsString(),
|
|
42
|
-
MaxLength(255),
|
|
43
|
-
_ts_metadata("design:type", String)
|
|
44
|
-
], NotificationContentDto.prototype, "title", void 0);
|
|
45
|
-
_ts_decorate([
|
|
46
|
-
ApiPropertyOptional(),
|
|
47
|
-
IsOptional(),
|
|
48
|
-
IsString(),
|
|
49
|
-
_ts_metadata("design:type", String)
|
|
50
|
-
], NotificationContentDto.prototype, "message", void 0);
|
|
51
|
-
_ts_decorate([
|
|
52
|
-
ApiPropertyOptional({
|
|
53
|
-
enum: NotificationType,
|
|
54
|
-
default: NotificationType.INFO
|
|
55
|
-
}),
|
|
56
|
-
IsOptional(),
|
|
57
|
-
IsEnum(NotificationType),
|
|
58
|
-
_ts_metadata("design:type", typeof NotificationType === "undefined" ? Object : NotificationType)
|
|
59
|
-
], NotificationContentDto.prototype, "type", void 0);
|
|
60
|
-
_ts_decorate([
|
|
61
|
-
ApiPropertyOptional(),
|
|
62
|
-
IsOptional(),
|
|
63
|
-
IsObject(),
|
|
64
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
65
|
-
], NotificationContentDto.prototype, "data", void 0);
|
|
66
|
-
_ts_decorate([
|
|
67
|
-
ApiPropertyOptional(),
|
|
68
|
-
IsOptional(),
|
|
69
|
-
IsUUID(),
|
|
70
|
-
_ts_metadata("design:type", String)
|
|
71
|
-
], NotificationContentDto.prototype, "companyId", void 0);
|
|
72
|
-
let UserIdDto = class UserIdDto {
|
|
73
|
-
constructor(){
|
|
74
|
-
_define_property(this, "userId", void 0);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
_ts_decorate([
|
|
78
|
-
ApiProperty(),
|
|
79
|
-
IsNotEmpty(),
|
|
80
|
-
IsUUID(),
|
|
81
|
-
_ts_metadata("design:type", String)
|
|
82
|
-
], UserIdDto.prototype, "userId", void 0);
|
|
83
|
-
let UserIdsDto = class UserIdsDto {
|
|
84
|
-
constructor(){
|
|
85
|
-
_define_property(this, "userIds", void 0);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
_ts_decorate([
|
|
89
|
-
ApiProperty({
|
|
90
|
-
type: [
|
|
91
|
-
String
|
|
92
|
-
]
|
|
93
|
-
}),
|
|
94
|
-
IsNotEmpty(),
|
|
95
|
-
IsUUID('4', {
|
|
96
|
-
each: true
|
|
97
|
-
}),
|
|
98
|
-
_ts_metadata("design:type", Array)
|
|
99
|
-
], UserIdsDto.prototype, "userIds", void 0);
|
|
100
|
-
export class CreateNotificationDto extends IntersectionType(UserIdDto, NotificationContentDto) {
|
|
101
|
-
}
|
|
102
|
-
export class UpdateNotificationDto extends PartialType(OmitType(CreateNotificationDto, [
|
|
103
|
-
'userId'
|
|
104
|
-
])) {
|
|
105
|
-
constructor(...args){
|
|
106
|
-
super(...args), _define_property(this, "id", void 0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
_ts_decorate([
|
|
110
|
-
ApiProperty(),
|
|
111
|
-
IsUUID(),
|
|
112
|
-
IsNotEmpty(),
|
|
113
|
-
_ts_metadata("design:type", String)
|
|
114
|
-
], UpdateNotificationDto.prototype, "id", void 0);
|
|
115
|
-
export class MarkReadDto {
|
|
116
|
-
constructor(){
|
|
117
|
-
_define_property(this, "id", void 0);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
_ts_decorate([
|
|
121
|
-
ApiProperty(),
|
|
122
|
-
IsUUID(),
|
|
123
|
-
IsNotEmpty(),
|
|
124
|
-
_ts_metadata("design:type", String)
|
|
125
|
-
], MarkReadDto.prototype, "id", void 0);
|
|
126
|
-
export class NotificationResponseDto {
|
|
127
|
-
constructor(){
|
|
128
|
-
_define_property(this, "id", void 0);
|
|
129
|
-
_define_property(this, "userId", void 0);
|
|
130
|
-
_define_property(this, "type", void 0);
|
|
131
|
-
_define_property(this, "title", void 0);
|
|
132
|
-
_define_property(this, "message", void 0);
|
|
133
|
-
_define_property(this, "data", void 0);
|
|
134
|
-
_define_property(this, "isRead", void 0);
|
|
135
|
-
_define_property(this, "readAt", void 0);
|
|
136
|
-
_define_property(this, "companyId", void 0);
|
|
137
|
-
_define_property(this, "createdAt", void 0);
|
|
138
|
-
_define_property(this, "updatedAt", void 0);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
_ts_decorate([
|
|
142
|
-
Expose(),
|
|
143
|
-
ApiProperty({
|
|
144
|
-
description: 'Unique identifier of the notification',
|
|
145
|
-
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
|
|
146
|
-
}),
|
|
147
|
-
_ts_metadata("design:type", String)
|
|
148
|
-
], NotificationResponseDto.prototype, "id", void 0);
|
|
149
|
-
_ts_decorate([
|
|
150
|
-
Expose(),
|
|
151
|
-
ApiProperty({
|
|
152
|
-
description: 'ID of the user this notification belongs to',
|
|
153
|
-
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
|
|
154
|
-
}),
|
|
155
|
-
_ts_metadata("design:type", String)
|
|
156
|
-
], NotificationResponseDto.prototype, "userId", void 0);
|
|
157
|
-
_ts_decorate([
|
|
158
|
-
Expose(),
|
|
159
|
-
ApiProperty({
|
|
160
|
-
description: 'Category of the notification',
|
|
161
|
-
enum: NotificationType,
|
|
162
|
-
example: NotificationType.SUCCESS
|
|
163
|
-
}),
|
|
164
|
-
_ts_metadata("design:type", typeof NotificationType === "undefined" ? Object : NotificationType)
|
|
165
|
-
], NotificationResponseDto.prototype, "type", void 0);
|
|
166
|
-
_ts_decorate([
|
|
167
|
-
Expose(),
|
|
168
|
-
ApiProperty({
|
|
169
|
-
description: 'Short title of the notification',
|
|
170
|
-
example: 'Your export is ready'
|
|
171
|
-
}),
|
|
172
|
-
_ts_metadata("design:type", String)
|
|
173
|
-
], NotificationResponseDto.prototype, "title", void 0);
|
|
174
|
-
_ts_decorate([
|
|
175
|
-
Expose(),
|
|
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
|
-
}),
|
|
181
|
-
_ts_metadata("design:type", Object)
|
|
182
|
-
], NotificationResponseDto.prototype, "message", void 0);
|
|
183
|
-
_ts_decorate([
|
|
184
|
-
Expose(),
|
|
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
|
-
}),
|
|
195
|
-
_ts_metadata("design:type", Object)
|
|
196
|
-
], NotificationResponseDto.prototype, "data", void 0);
|
|
197
|
-
_ts_decorate([
|
|
198
|
-
Expose(),
|
|
199
|
-
ApiProperty({
|
|
200
|
-
description: 'Whether the user has read this notification',
|
|
201
|
-
example: false
|
|
202
|
-
}),
|
|
203
|
-
_ts_metadata("design:type", Boolean)
|
|
204
|
-
], NotificationResponseDto.prototype, "isRead", void 0);
|
|
205
|
-
_ts_decorate([
|
|
206
|
-
Expose(),
|
|
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
|
-
}),
|
|
214
|
-
_ts_metadata("design:type", Object)
|
|
215
|
-
], NotificationResponseDto.prototype, "readAt", void 0);
|
|
216
|
-
_ts_decorate([
|
|
217
|
-
Expose(),
|
|
218
|
-
ApiPropertyOptional({
|
|
219
|
-
description: 'Company scope for the notification; null for personal notifications',
|
|
220
|
-
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c',
|
|
221
|
-
nullable: true
|
|
222
|
-
}),
|
|
223
|
-
_ts_metadata("design:type", Object)
|
|
224
|
-
], NotificationResponseDto.prototype, "companyId", void 0);
|
|
225
|
-
_ts_decorate([
|
|
226
|
-
Expose(),
|
|
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
|
-
}),
|
|
233
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
234
|
-
], NotificationResponseDto.prototype, "createdAt", void 0);
|
|
235
|
-
_ts_decorate([
|
|
236
|
-
Expose(),
|
|
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
|
-
}),
|
|
243
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
244
|
-
], NotificationResponseDto.prototype, "updatedAt", void 0);
|
|
245
|
-
export class UnreadCountResponseDto {
|
|
246
|
-
constructor(){
|
|
247
|
-
_define_property(this, "count", void 0);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
_ts_decorate([
|
|
251
|
-
Expose(),
|
|
252
|
-
ApiProperty({
|
|
253
|
-
description: 'Total number of unread notifications for the user',
|
|
254
|
-
example: 5,
|
|
255
|
-
minimum: 0
|
|
256
|
-
}),
|
|
257
|
-
_ts_metadata("design:type", Number)
|
|
258
|
-
], UnreadCountResponseDto.prototype, "count", void 0);
|
|
259
|
-
export class SendNotificationDto extends IntersectionType(UserIdDto, NotificationContentDto) {
|
|
260
|
-
}
|
|
261
|
-
export class SendBulkNotificationDto extends IntersectionType(UserIdsDto, NotificationContentDto) {
|
|
262
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { getNotificationEntitiesByConfig, NotificationCoreEntities, NotificationCompanyEntities } from './index';
|
|
2
|
-
describe('getNotificationEntitiesByConfig', ()=>{
|
|
3
|
-
it('returns the core entities when the company feature is disabled', ()=>{
|
|
4
|
-
expect(getNotificationEntitiesByConfig(false)).toBe(NotificationCoreEntities);
|
|
5
|
-
});
|
|
6
|
-
it('returns the company-scoped entities when the company feature is enabled', ()=>{
|
|
7
|
-
expect(getNotificationEntitiesByConfig(true)).toBe(NotificationCompanyEntities);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
24
|
-
import { Notification } from './notification.entity';
|
|
25
|
-
export class NotificationWithCompany extends Notification {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), _define_property(this, "companyId", void 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_ts_decorate([
|
|
31
|
-
Column({
|
|
32
|
-
name: 'company_id',
|
|
33
|
-
type: 'uuid',
|
|
34
|
-
nullable: true
|
|
35
|
-
}),
|
|
36
|
-
_ts_metadata("design:type", Object)
|
|
37
|
-
], NotificationWithCompany.prototype, "companyId", void 0);
|
|
38
|
-
NotificationWithCompany = _ts_decorate([
|
|
39
|
-
Entity({
|
|
40
|
-
name: 'notification'
|
|
41
|
-
}),
|
|
42
|
-
Index([
|
|
43
|
-
'companyId',
|
|
44
|
-
'userId',
|
|
45
|
-
'isRead'
|
|
46
|
-
])
|
|
47
|
-
], NotificationWithCompany);
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { getJsonColumnType } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
25
|
-
import { NotificationType } from '@flusys/nestjs-shared/enums';
|
|
26
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
27
|
-
export class Notification extends Identity {
|
|
28
|
-
constructor(...args){
|
|
29
|
-
super(...args), _define_property(this, "userId", void 0), _define_property(this, "type", void 0), _define_property(this, "title", void 0), _define_property(this, "message", void 0), _define_property(this, "data", void 0), _define_property(this, "isRead", void 0), _define_property(this, "readAt", void 0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
_ts_decorate([
|
|
33
|
-
Column({
|
|
34
|
-
name: 'user_id',
|
|
35
|
-
type: 'uuid',
|
|
36
|
-
nullable: false
|
|
37
|
-
}),
|
|
38
|
-
Index(),
|
|
39
|
-
_ts_metadata("design:type", String)
|
|
40
|
-
], Notification.prototype, "userId", void 0);
|
|
41
|
-
_ts_decorate([
|
|
42
|
-
Column({
|
|
43
|
-
type: 'varchar',
|
|
44
|
-
length: 50,
|
|
45
|
-
nullable: false,
|
|
46
|
-
default: NotificationType.INFO
|
|
47
|
-
}),
|
|
48
|
-
_ts_metadata("design:type", String)
|
|
49
|
-
], Notification.prototype, "type", void 0);
|
|
50
|
-
_ts_decorate([
|
|
51
|
-
Column({
|
|
52
|
-
type: 'varchar',
|
|
53
|
-
length: 255,
|
|
54
|
-
nullable: false
|
|
55
|
-
}),
|
|
56
|
-
_ts_metadata("design:type", String)
|
|
57
|
-
], Notification.prototype, "title", void 0);
|
|
58
|
-
_ts_decorate([
|
|
59
|
-
Column({
|
|
60
|
-
type: 'text',
|
|
61
|
-
nullable: true
|
|
62
|
-
}),
|
|
63
|
-
_ts_metadata("design:type", Object)
|
|
64
|
-
], Notification.prototype, "message", void 0);
|
|
65
|
-
_ts_decorate([
|
|
66
|
-
Column({
|
|
67
|
-
type: getJsonColumnType(),
|
|
68
|
-
nullable: true
|
|
69
|
-
}),
|
|
70
|
-
_ts_metadata("design:type", Object)
|
|
71
|
-
], Notification.prototype, "data", void 0);
|
|
72
|
-
_ts_decorate([
|
|
73
|
-
Column({
|
|
74
|
-
name: 'is_read',
|
|
75
|
-
type: 'boolean',
|
|
76
|
-
nullable: false,
|
|
77
|
-
default: false
|
|
78
|
-
}),
|
|
79
|
-
Index(),
|
|
80
|
-
_ts_metadata("design:type", Boolean)
|
|
81
|
-
], Notification.prototype, "isRead", void 0);
|
|
82
|
-
_ts_decorate([
|
|
83
|
-
Column({
|
|
84
|
-
name: 'read_at',
|
|
85
|
-
type: 'timestamp',
|
|
86
|
-
nullable: true
|
|
87
|
-
}),
|
|
88
|
-
_ts_metadata("design:type", Object)
|
|
89
|
-
], Notification.prototype, "readAt", void 0);
|
|
90
|
-
Notification = _ts_decorate([
|
|
91
|
-
Entity({
|
|
92
|
-
name: 'notification'
|
|
93
|
-
}),
|
|
94
|
-
Index([
|
|
95
|
-
'userId',
|
|
96
|
-
'isRead'
|
|
97
|
-
]),
|
|
98
|
-
Index([
|
|
99
|
-
'userId',
|
|
100
|
-
'createdAt'
|
|
101
|
-
])
|
|
102
|
-
], Notification);
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { Inject } from '@nestjs/common';
|
|
29
|
-
import { JwtService } from '@nestjs/jwt';
|
|
30
|
-
import { WebSocketGateway, WebSocketServer } from '@nestjs/websockets';
|
|
31
|
-
import { Server } from 'socket.io';
|
|
32
|
-
import { NotificationConfigService } from '../services/notification-config.service';
|
|
33
|
-
export class NotificationGateway {
|
|
34
|
-
afterInit() {
|
|
35
|
-
// Gateway initialized
|
|
36
|
-
}
|
|
37
|
-
async handleConnection(client) {
|
|
38
|
-
try {
|
|
39
|
-
const token = this.extractToken(client);
|
|
40
|
-
if (!token) {
|
|
41
|
-
client.disconnect();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const payload = this.verifyToken(token);
|
|
45
|
-
if (!payload) {
|
|
46
|
-
client.disconnect();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const userId = payload.id;
|
|
50
|
-
client.data.userId = userId;
|
|
51
|
-
client.data.companyId = payload.companyId;
|
|
52
|
-
if (!this.connectedUsers.has(userId)) {
|
|
53
|
-
this.connectedUsers.set(userId, new Set());
|
|
54
|
-
}
|
|
55
|
-
this.connectedUsers.get(userId).add(client.id);
|
|
56
|
-
client.join(`user:${userId}`);
|
|
57
|
-
if (payload.companyId) {
|
|
58
|
-
client.join(`company:${payload.companyId}`);
|
|
59
|
-
client.join(`user:${userId}:company:${payload.companyId}`);
|
|
60
|
-
}
|
|
61
|
-
} catch {
|
|
62
|
-
client.disconnect();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
handleDisconnect(client) {
|
|
66
|
-
const userId = client.data.userId;
|
|
67
|
-
if (userId) {
|
|
68
|
-
const sockets = this.connectedUsers.get(userId);
|
|
69
|
-
sockets?.delete(client.id);
|
|
70
|
-
if (sockets?.size === 0) {
|
|
71
|
-
this.connectedUsers.delete(userId);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
emitToUser(userId, event, data) {
|
|
76
|
-
this.server?.to(`user:${userId}`).emit(event, data);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Emit to a user scoped to a specific company session.
|
|
80
|
-
* Uses the combined room `user:{id}:company:{cid}` so only sockets
|
|
81
|
-
* authenticated under that company receive the event — critical for
|
|
82
|
-
* users logged in across multiple companies on different devices.
|
|
83
|
-
* Falls back to all user sockets when companyId is absent.
|
|
84
|
-
*/ emitToUserInCompany(userId, companyId, event, data) {
|
|
85
|
-
if (!this.server) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!companyId) {
|
|
89
|
-
this.emitToUser(userId, event, data);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.server.to(`user:${userId}:company:${companyId}`).emit(event, data);
|
|
93
|
-
}
|
|
94
|
-
emitToCompany(companyId, event, data) {
|
|
95
|
-
this.server?.to(`company:${companyId}`).emit(event, data);
|
|
96
|
-
}
|
|
97
|
-
broadcast(event, data) {
|
|
98
|
-
this.server?.emit(event, data);
|
|
99
|
-
}
|
|
100
|
-
isUserOnline(userId) {
|
|
101
|
-
return this.connectedUsers.has(userId);
|
|
102
|
-
}
|
|
103
|
-
getOnlineUserCount() {
|
|
104
|
-
return this.connectedUsers.size;
|
|
105
|
-
}
|
|
106
|
-
extractToken(client) {
|
|
107
|
-
const authToken = client.handshake.auth?.token;
|
|
108
|
-
if (authToken) return authToken;
|
|
109
|
-
const queryToken = client.handshake.query?.token;
|
|
110
|
-
if (typeof queryToken === 'string') return queryToken;
|
|
111
|
-
const authHeader = client.handshake.headers?.authorization;
|
|
112
|
-
if (authHeader?.startsWith('Bearer ')) {
|
|
113
|
-
return authHeader.substring(7);
|
|
114
|
-
}
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
verifyToken(token) {
|
|
118
|
-
try {
|
|
119
|
-
const secret = this.configService.getJwtSecret();
|
|
120
|
-
if (!secret) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
return this.jwtService.verify(token, {
|
|
124
|
-
secret,
|
|
125
|
-
algorithms: [
|
|
126
|
-
'HS256'
|
|
127
|
-
]
|
|
128
|
-
});
|
|
129
|
-
} catch {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
constructor(configService, jwtService){
|
|
134
|
-
_define_property(this, "configService", void 0);
|
|
135
|
-
_define_property(this, "jwtService", void 0);
|
|
136
|
-
_define_property(this, "connectedUsers", void 0);
|
|
137
|
-
_define_property(this, "server", void 0);
|
|
138
|
-
this.configService = configService;
|
|
139
|
-
this.jwtService = jwtService;
|
|
140
|
-
this.connectedUsers = new Map();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
_ts_decorate([
|
|
144
|
-
WebSocketServer(),
|
|
145
|
-
_ts_metadata("design:type", typeof Server === "undefined" ? Object : Server)
|
|
146
|
-
], NotificationGateway.prototype, "server", void 0);
|
|
147
|
-
NotificationGateway = _ts_decorate([
|
|
148
|
-
WebSocketGateway({
|
|
149
|
-
namespace: '/notifications',
|
|
150
|
-
cors: {
|
|
151
|
-
origin: '*',
|
|
152
|
-
credentials: true
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
_ts_param(0, Inject(NotificationConfigService)),
|
|
156
|
-
_ts_param(1, Inject(JwtService)),
|
|
157
|
-
_ts_metadata("design:type", Function),
|
|
158
|
-
_ts_metadata("design:paramtypes", [
|
|
159
|
-
typeof NotificationConfigService === "undefined" ? Object : NotificationConfigService,
|
|
160
|
-
typeof JwtService === "undefined" ? Object : JwtService
|
|
161
|
-
])
|
|
162
|
-
], NotificationGateway);
|