@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
package/fesm/244.js ADDED
@@ -0,0 +1,816 @@
1
+ import { Identity } from "@flusys/nestjs-shared/entities";
2
+ import { Column, Entity, Index } from "typeorm";
3
+ import { envConfig } from "@flusys/nestjs-core/config";
4
+ import { WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
5
+ import { Server } from "socket.io";
6
+ import * as __rspack_external__flusys_nestjs_shared_393d2cae from "@flusys/nestjs-shared";
7
+ import * as __rspack_external__flusys_nestjs_shared_classes_6076a329 from "@flusys/nestjs-shared/classes";
8
+ import * as __rspack_external__flusys_nestjs_shared_enums_327421f8 from "@flusys/nestjs-shared/enums";
9
+ import * as __rspack_external__flusys_nestjs_shared_modules_24702bee from "@flusys/nestjs-shared/modules";
10
+ import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
11
+ import * as __rspack_external__nestjs_jwt_50c0e0ae from "@nestjs/jwt";
12
+ import * as __rspack_external__nestjs_core_d7b00a1a from "@nestjs/core";
13
+ export const __rspack_esm_id = 244;
14
+ export const __rspack_esm_ids = [244];
15
+ export const __webpack_modules__ = {
16
+ 360(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
17
+ /**
18
+ * Domain event actions published by the notification module, alongside the CRUD
19
+ * lifecycle actions every ApiService emits.
20
+ */ const NOTIFICATION_EVENT_ACTIONS = {
21
+ SENT: 'sent',
22
+ READ: 'read',
23
+ ALL_READ: 'all-read'
24
+ };
25
+ const NOTIFICATION_EVENT_ENTITIES = {
26
+ NOTIFICATION: 'notification'
27
+ };
28
+ const NOTIFICATION_EVENT_MODULE = 'notification';
29
+
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ }, {
32
+ BA: NOTIFICATION_EVENT_ENTITIES,
33
+ R: NOTIFICATION_EVENT_ACTIONS,
34
+ Wx: NOTIFICATION_EVENT_MODULE
35
+ });
36
+
37
+
38
+ },
39
+ 608(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
40
+ const NOTIFICATION_MODULE_OPTIONS = 'NOTIFICATION_MODULE_OPTIONS';
41
+
42
+ __webpack_require__.d(__webpack_exports__, {
43
+ }, {
44
+ G: NOTIFICATION_MODULE_OPTIONS
45
+ });
46
+
47
+
48
+ },
49
+ 240(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
50
+
51
+ // EXPORTS
52
+ __webpack_require__.d(__webpack_exports__, {
53
+ Notification: () => (/* reexport */ Notification),
54
+ bW: () => (/* reexport */ Notification),
55
+ s_: () => (/* binding */ NotificationCompanyEntities),
56
+ Ms: () => (/* binding */ NotificationCoreEntities),
57
+ NotificationWithCompany: () => (/* reexport */ NotificationWithCompany),
58
+ qC: () => (/* binding */ getNotificationEntitiesByConfig)
59
+ });
60
+
61
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared"
62
+ var nestjs_shared_ = __webpack_require__(422);
63
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-shared/entities"
64
+
65
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/enums"
66
+ var enums_ = __webpack_require__(471);
67
+ ;// CONCATENATED MODULE: external "typeorm"
68
+
69
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/notification.entity.ts
70
+ function _ts_decorate(decorators, target, key, desc) {
71
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
72
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
73
+ r = Reflect.decorate(decorators, target, key, desc);
74
+ } else {
75
+ for(var i = decorators.length - 1; i >= 0; i--){
76
+ if (d = decorators[i]) {
77
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
78
+ }
79
+ }
80
+ }
81
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
82
+ }
83
+ function _ts_metadata(metadataKey, metadataValue) {
84
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
85
+ return Reflect.metadata(metadataKey, metadataValue);
86
+ }
87
+ }
88
+
89
+
90
+
91
+
92
+ class Notification extends Identity {
93
+ userId;
94
+ type;
95
+ title;
96
+ message;
97
+ data;
98
+ isRead;
99
+ readAt;
100
+ }
101
+ _ts_decorate([
102
+ Column({
103
+ name: 'user_id',
104
+ type: 'uuid',
105
+ nullable: false
106
+ }),
107
+ Index(),
108
+ _ts_metadata("design:type", String)
109
+ ], Notification.prototype, "userId", void 0);
110
+ _ts_decorate([
111
+ Column({
112
+ type: 'varchar',
113
+ length: 50,
114
+ nullable: false,
115
+ default: enums_.NotificationType.INFO
116
+ }),
117
+ _ts_metadata("design:type", String)
118
+ ], Notification.prototype, "type", void 0);
119
+ _ts_decorate([
120
+ Column({
121
+ type: 'varchar',
122
+ length: 255,
123
+ nullable: false
124
+ }),
125
+ _ts_metadata("design:type", String)
126
+ ], Notification.prototype, "title", void 0);
127
+ _ts_decorate([
128
+ Column({
129
+ type: 'text',
130
+ nullable: true
131
+ }),
132
+ _ts_metadata("design:type", Object)
133
+ ], Notification.prototype, "message", void 0);
134
+ _ts_decorate([
135
+ Column({
136
+ type: (0,nestjs_shared_.getJsonColumnType)(),
137
+ nullable: true
138
+ }),
139
+ _ts_metadata("design:type", Object)
140
+ ], Notification.prototype, "data", void 0);
141
+ _ts_decorate([
142
+ Column({
143
+ name: 'is_read',
144
+ type: 'boolean',
145
+ nullable: false,
146
+ default: false
147
+ }),
148
+ Index(),
149
+ _ts_metadata("design:type", Boolean)
150
+ ], Notification.prototype, "isRead", void 0);
151
+ _ts_decorate([
152
+ Column({
153
+ name: 'read_at',
154
+ type: 'timestamp',
155
+ nullable: true
156
+ }),
157
+ _ts_metadata("design:type", Object)
158
+ ], Notification.prototype, "readAt", void 0);
159
+ Notification = _ts_decorate([
160
+ Entity({
161
+ name: 'notification'
162
+ }),
163
+ Index([
164
+ 'userId',
165
+ 'isRead'
166
+ ]),
167
+ Index([
168
+ 'userId',
169
+ 'createdAt'
170
+ ])
171
+ ], Notification);
172
+
173
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/notification-with-company.entity.ts
174
+ function notification_with_company_entity_ts_decorate(decorators, target, key, desc) {
175
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
176
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
177
+ r = Reflect.decorate(decorators, target, key, desc);
178
+ } else {
179
+ for(var i = decorators.length - 1; i >= 0; i--){
180
+ if (d = decorators[i]) {
181
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
182
+ }
183
+ }
184
+ }
185
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
186
+ }
187
+ function notification_with_company_entity_ts_metadata(metadataKey, metadataValue) {
188
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
189
+ return Reflect.metadata(metadataKey, metadataValue);
190
+ }
191
+ }
192
+
193
+
194
+ class NotificationWithCompany extends Notification {
195
+ companyId;
196
+ }
197
+ notification_with_company_entity_ts_decorate([
198
+ Column({
199
+ name: 'company_id',
200
+ type: 'uuid',
201
+ nullable: true
202
+ }),
203
+ notification_with_company_entity_ts_metadata("design:type", Object)
204
+ ], NotificationWithCompany.prototype, "companyId", void 0);
205
+ NotificationWithCompany = notification_with_company_entity_ts_decorate([
206
+ Entity({
207
+ name: 'notification'
208
+ }),
209
+ Index([
210
+ 'companyId',
211
+ 'userId',
212
+ 'isRead'
213
+ ])
214
+ ], NotificationWithCompany);
215
+
216
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/index.ts
217
+
218
+
219
+
220
+
221
+ const NotificationCoreEntities = [
222
+ Notification
223
+ ];
224
+ const NotificationCompanyEntities = [
225
+ NotificationWithCompany
226
+ ];
227
+ function getNotificationEntitiesByConfig(enableCompanyFeature) {
228
+ return enableCompanyFeature ? NotificationCompanyEntities : NotificationCoreEntities;
229
+ }
230
+
231
+
232
+
233
+ },
234
+ 31(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
235
+
236
+ // EXPORTS
237
+ __webpack_require__.d(__webpack_exports__, {
238
+ g: () => (/* reexport */ NotificationGateway)
239
+ });
240
+
241
+ ;// CONCATENATED MODULE: external "@flusys/nestjs-core/config"
242
+
243
+ // EXTERNAL MODULE: external "@nestjs/common"
244
+ var common_ = __webpack_require__(157);
245
+ // EXTERNAL MODULE: external "@nestjs/jwt"
246
+ var jwt_ = __webpack_require__(125);
247
+ ;// CONCATENATED MODULE: external "@nestjs/websockets"
248
+
249
+ ;// CONCATENATED MODULE: external "socket.io"
250
+
251
+ // EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-config.service.ts
252
+ var notification_config_service = __webpack_require__(53);
253
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/gateways/notification.gateway.ts
254
+ function _ts_decorate(decorators, target, key, desc) {
255
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
256
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
257
+ r = Reflect.decorate(decorators, target, key, desc);
258
+ } else {
259
+ for(var i = decorators.length - 1; i >= 0; i--){
260
+ if (d = decorators[i]) {
261
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
262
+ }
263
+ }
264
+ }
265
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
266
+ }
267
+ function _ts_metadata(metadataKey, metadataValue) {
268
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
269
+ return Reflect.metadata(metadataKey, metadataValue);
270
+ }
271
+ }
272
+ function _ts_param(paramIndex, decorator) {
273
+ return function(target, key) {
274
+ decorator(target, key, paramIndex);
275
+ };
276
+ }
277
+
278
+
279
+
280
+
281
+
282
+
283
+ class NotificationGateway {
284
+ configService;
285
+ jwtService;
286
+ connectedUsers = new Map();
287
+ server;
288
+ constructor(configService, jwtService){
289
+ this.configService = configService;
290
+ this.jwtService = jwtService;
291
+ }
292
+ afterInit() {
293
+ // Gateway initialized
294
+ }
295
+ async handleConnection(client) {
296
+ try {
297
+ const token = this.extractToken(client);
298
+ if (!token) {
299
+ client.disconnect();
300
+ return;
301
+ }
302
+ const payload = this.verifyToken(token);
303
+ if (!payload) {
304
+ client.disconnect();
305
+ return;
306
+ }
307
+ const userId = payload.id;
308
+ client.data.userId = userId;
309
+ client.data.companyId = payload.companyId;
310
+ if (!this.connectedUsers.has(userId)) {
311
+ this.connectedUsers.set(userId, new Set());
312
+ }
313
+ this.connectedUsers.get(userId).add(client.id);
314
+ client.join(`user:${userId}`);
315
+ if (payload.companyId) {
316
+ client.join(`company:${payload.companyId}`);
317
+ client.join(`user:${userId}:company:${payload.companyId}`);
318
+ }
319
+ } catch {
320
+ client.disconnect();
321
+ }
322
+ }
323
+ handleDisconnect(client) {
324
+ const userId = client.data.userId;
325
+ if (userId) {
326
+ const sockets = this.connectedUsers.get(userId);
327
+ sockets?.delete(client.id);
328
+ if (sockets?.size === 0) {
329
+ this.connectedUsers.delete(userId);
330
+ }
331
+ }
332
+ }
333
+ emitToUser(userId, event, data) {
334
+ this.server?.to(`user:${userId}`).emit(event, data);
335
+ }
336
+ /**
337
+ * Emit to a user scoped to a specific company session.
338
+ * Uses the combined room `user:{id}:company:{cid}` so only sockets
339
+ * authenticated under that company receive the event — critical for
340
+ * users logged in across multiple companies on different devices.
341
+ * Falls back to all user sockets when companyId is absent.
342
+ */ emitToUserInCompany(userId, companyId, event, data) {
343
+ if (!this.server) {
344
+ return;
345
+ }
346
+ if (!companyId) {
347
+ this.emitToUser(userId, event, data);
348
+ return;
349
+ }
350
+ this.server.to(`user:${userId}:company:${companyId}`).emit(event, data);
351
+ }
352
+ emitToCompany(companyId, event, data) {
353
+ this.server?.to(`company:${companyId}`).emit(event, data);
354
+ }
355
+ broadcast(event, data) {
356
+ this.server?.emit(event, data);
357
+ }
358
+ isUserOnline(userId) {
359
+ return this.connectedUsers.has(userId);
360
+ }
361
+ getOnlineUserCount() {
362
+ return this.connectedUsers.size;
363
+ }
364
+ extractToken(client) {
365
+ const authToken = client.handshake.auth?.token;
366
+ if (authToken) return authToken;
367
+ const queryToken = client.handshake.query?.token;
368
+ if (typeof queryToken === 'string') return queryToken;
369
+ const authHeader = client.handshake.headers?.authorization;
370
+ if (authHeader?.startsWith('Bearer ')) {
371
+ return authHeader.substring(7);
372
+ }
373
+ return null;
374
+ }
375
+ verifyToken(token) {
376
+ try {
377
+ const secret = this.configService.getJwtSecret();
378
+ if (!secret) {
379
+ return null;
380
+ }
381
+ return this.jwtService.verify(token, {
382
+ secret,
383
+ algorithms: [
384
+ 'HS256'
385
+ ]
386
+ });
387
+ } catch {
388
+ return null;
389
+ }
390
+ }
391
+ }
392
+ _ts_decorate([
393
+ WebSocketServer(),
394
+ _ts_metadata("design:type", typeof Server === "undefined" ? Object : Server)
395
+ ], NotificationGateway.prototype, "server", void 0);
396
+ NotificationGateway = _ts_decorate([
397
+ WebSocketGateway({
398
+ namespace: '/notifications',
399
+ cors: {
400
+ origin: envConfig.getOrigins(),
401
+ credentials: true
402
+ }
403
+ }),
404
+ _ts_param(0, (0,common_.Inject)(notification_config_service/* .NotificationConfigService */.v)),
405
+ _ts_param(1, (0,common_.Inject)(jwt_.JwtService)),
406
+ _ts_metadata("design:type", Function),
407
+ _ts_metadata("design:paramtypes", [
408
+ typeof notification_config_service/* .NotificationConfigService */.v === "undefined" ? Object : notification_config_service/* .NotificationConfigService */.v,
409
+ typeof jwt_.JwtService === "undefined" ? Object : jwt_.JwtService
410
+ ])
411
+ ], NotificationGateway);
412
+
413
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/gateways/index.ts
414
+
415
+
416
+
417
+ },
418
+ 53(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
419
+ /* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
420
+ /* import */ var _config_notification_constants_js__rspack_import_1 = __webpack_require__(608);
421
+ function _ts_decorate(decorators, target, key, desc) {
422
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
423
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
424
+ r = Reflect.decorate(decorators, target, key, desc);
425
+ } else {
426
+ for(var i = decorators.length - 1; i >= 0; i--){
427
+ if (d = decorators[i]) {
428
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
429
+ }
430
+ }
431
+ }
432
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
433
+ }
434
+ function _ts_metadata(metadataKey, metadataValue) {
435
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
436
+ return Reflect.metadata(metadataKey, metadataValue);
437
+ }
438
+ }
439
+ function _ts_param(paramIndex, decorator) {
440
+ return function(target, key) {
441
+ decorator(target, key, paramIndex);
442
+ };
443
+ }
444
+
445
+
446
+ class NotificationConfigService {
447
+ options;
448
+ constructor(options){
449
+ this.options = options;
450
+ }
451
+ isCompanyFeatureEnabled() {
452
+ return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
453
+ }
454
+ getDatabaseMode() {
455
+ return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
456
+ }
457
+ isMultiTenant() {
458
+ return this.getDatabaseMode() === 'multi-tenant';
459
+ }
460
+ getJwtSecret() {
461
+ return this.options.config?.jwtSecret;
462
+ }
463
+ getOptions() {
464
+ return this.options;
465
+ }
466
+ }
467
+ NotificationConfigService = _ts_decorate([
468
+ (0,_nestjs_common__rspack_import_0.Injectable)(),
469
+ _ts_param(0, (0,_nestjs_common__rspack_import_0.Inject)(_config_notification_constants_js__rspack_import_1/* .NOTIFICATION_MODULE_OPTIONS */.G)),
470
+ _ts_metadata("design:type", Function),
471
+ _ts_metadata("design:paramtypes", [
472
+ typeof NotificationModuleOptions === "undefined" ? Object : NotificationModuleOptions
473
+ ])
474
+ ], NotificationConfigService);
475
+
476
+ __webpack_require__.d(__webpack_exports__, {
477
+ v: () => (NotificationConfigService)
478
+ });
479
+
480
+
481
+ },
482
+ 335(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
483
+
484
+ // EXPORTS
485
+ __webpack_require__.d(__webpack_exports__, {
486
+ M: () => (/* binding */ NotificationDataSourceProvider)
487
+ });
488
+
489
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
490
+ var modules_ = __webpack_require__(236);
491
+ // EXTERNAL MODULE: external "@nestjs/common"
492
+ var common_ = __webpack_require__(157);
493
+ ;// CONCATENATED MODULE: external "@nestjs/core"
494
+
495
+ // EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-config.service.ts
496
+ var notification_config_service = __webpack_require__(53);
497
+ ;// CONCATENATED MODULE: ./projects/nestjs-notification/src/services/notification-datasource.provider.ts
498
+ function _ts_decorate(decorators, target, key, desc) {
499
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
500
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
501
+ r = Reflect.decorate(decorators, target, key, desc);
502
+ } else {
503
+ for(var i = decorators.length - 1; i >= 0; i--){
504
+ if (d = decorators[i]) {
505
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
506
+ }
507
+ }
508
+ }
509
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
510
+ }
511
+ function _ts_metadata(metadataKey, metadataValue) {
512
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
513
+ return Reflect.metadata(metadataKey, metadataValue);
514
+ }
515
+ }
516
+ function _ts_param(paramIndex, decorator) {
517
+ return function(target, key) {
518
+ decorator(target, key, paramIndex);
519
+ };
520
+ }
521
+
522
+
523
+
524
+
525
+ class NotificationDataSourceProvider extends modules_.MultiTenantDataSourceService {
526
+ configService;
527
+ static tenantConnections = new Map();
528
+ static singleDataSource = null;
529
+ static tenantsRegistry = new Map();
530
+ static initialized = false;
531
+ static connectionLocks = new Map();
532
+ static singleConnectionLock = null;
533
+ constructor(configService, request){
534
+ super(NotificationDataSourceProvider.buildParentOptions(configService.getOptions()), request), this.configService = configService;
535
+ }
536
+ static buildParentOptions(options) {
537
+ return {
538
+ bootstrapAppConfig: options.bootstrapAppConfig,
539
+ defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
540
+ tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
541
+ tenants: options.config?.tenants
542
+ };
543
+ }
544
+ getEnableCompanyFeatureForTenant(tenant) {
545
+ return tenant?.enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
546
+ }
547
+ async getNotificationEntities(enableCompanyFeature) {
548
+ const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
549
+ const entities = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 240));
550
+ return enable ? [
551
+ entities.NotificationWithCompany
552
+ ] : [
553
+ entities.Notification
554
+ ];
555
+ }
556
+ async createDataSourceFromConfig(config) {
557
+ const currentTenant = this.getCurrentTenant();
558
+ const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
559
+ const entities = await this.getNotificationEntities(enableCompanyFeature);
560
+ return super.createDataSourceFromConfig(config, entities);
561
+ }
562
+ }
563
+ NotificationDataSourceProvider = _ts_decorate([
564
+ (0,common_.Injectable)({
565
+ scope: common_.Scope.REQUEST
566
+ }),
567
+ _ts_param(0, (0,common_.Inject)(notification_config_service/* .NotificationConfigService */.v)),
568
+ _ts_param(1, (0,common_.Optional)()),
569
+ _ts_param(1, (0,common_.Inject)(__rspack_external__nestjs_core_d7b00a1a.REQUEST)),
570
+ _ts_metadata("design:type", Function),
571
+ _ts_metadata("design:paramtypes", [
572
+ typeof notification_config_service/* .NotificationConfigService */.v === "undefined" ? Object : notification_config_service/* .NotificationConfigService */.v,
573
+ typeof Request === "undefined" ? Object : Request
574
+ ])
575
+ ], NotificationDataSourceProvider);
576
+
577
+
578
+ },
579
+ 487(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
580
+ /* import */ var _flusys_nestjs_shared__rspack_import_0 = __webpack_require__(422);
581
+ /* import */ var _flusys_nestjs_shared_classes__rspack_import_1 = __webpack_require__(937);
582
+ /* import */ var _flusys_nestjs_shared_enums__rspack_import_2 = __webpack_require__(471);
583
+ /* import */ var _flusys_nestjs_shared_modules__rspack_import_3 = __webpack_require__(236);
584
+ /* import */ var _nestjs_common__rspack_import_4 = __webpack_require__(157);
585
+ /* import */ var _config_index_js__rspack_import_9 = __webpack_require__(360);
586
+ /* import */ var _entities_index_js__rspack_import_5 = __webpack_require__(240);
587
+ /* import */ var _gateways_index_js__rspack_import_6 = __webpack_require__(31);
588
+ /* import */ var _notification_config_service_js__rspack_import_7 = __webpack_require__(53);
589
+ /* import */ var _notification_datasource_provider_js__rspack_import_8 = __webpack_require__(335);
590
+ function _ts_decorate(decorators, target, key, desc) {
591
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
592
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
593
+ r = Reflect.decorate(decorators, target, key, desc);
594
+ } else {
595
+ for(var i = decorators.length - 1; i >= 0; i--){
596
+ if (d = decorators[i]) {
597
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
598
+ }
599
+ }
600
+ }
601
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
602
+ }
603
+ function _ts_metadata(metadataKey, metadataValue) {
604
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
605
+ return Reflect.metadata(metadataKey, metadataValue);
606
+ }
607
+ }
608
+ function _ts_param(paramIndex, decorator) {
609
+ return function(target, key) {
610
+ decorator(target, key, paramIndex);
611
+ };
612
+ }
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+ class NotificationHelperService {
624
+ cacheManager;
625
+ utilsService;
626
+ configService;
627
+ dataSourceProvider;
628
+ gateway;
629
+ dataSource = null;
630
+ constructor(cacheManager, utilsService, configService, dataSourceProvider, gateway){
631
+ this.cacheManager = cacheManager;
632
+ this.utilsService = utilsService;
633
+ this.configService = configService;
634
+ this.dataSourceProvider = dataSourceProvider;
635
+ this.gateway = gateway;
636
+ }
637
+ async send(options) {
638
+ const repo = await this.getRepository();
639
+ const entity = this.buildEntity(options.userId, options);
640
+ const saved = await repo.save(entity);
641
+ await this.clearCache();
642
+ this.emitToUser(saved, options.realtime !== false);
643
+ await this.publishSentEvent([
644
+ saved
645
+ ], [
646
+ options.userId
647
+ ]);
648
+ return saved;
649
+ }
650
+ async sendToMany(options) {
651
+ const repo = await this.getRepository();
652
+ const entities = options.userIds.map((userId)=>this.buildEntity(userId, options));
653
+ const saved = await repo.save(entities);
654
+ await this.clearCache();
655
+ if (options.realtime !== false) {
656
+ setImmediate(()=>{
657
+ for (const notification of saved){
658
+ this.emitToUser(notification, true);
659
+ }
660
+ });
661
+ }
662
+ await this.publishSentEvent(saved, options.userIds);
663
+ return saved;
664
+ }
665
+ isUserOnline(userId) {
666
+ return this.gateway?.isUserOnline(userId) ?? false;
667
+ }
668
+ getOnlineUserCount() {
669
+ return this.gateway?.getOnlineUserCount() ?? 0;
670
+ }
671
+ async publishSentEvent(notifications, userIds) {
672
+ await (0,_flusys_nestjs_shared_classes__rspack_import_1.publishDomainEvent)({
673
+ module: _config_index_js__rspack_import_9/* .NOTIFICATION_EVENT_MODULE */.Wx,
674
+ entity: _config_index_js__rspack_import_9/* .NOTIFICATION_EVENT_ENTITIES.NOTIFICATION */.BA.NOTIFICATION,
675
+ action: _config_index_js__rspack_import_9/* .NOTIFICATION_EVENT_ACTIONS.SENT */.R.SENT,
676
+ ids: notifications.map((notification)=>notification.id),
677
+ metadata: {
678
+ recipientCount: userIds.length
679
+ }
680
+ });
681
+ }
682
+ async getDataSource() {
683
+ if (!this.dataSource) {
684
+ this.dataSource = await this.dataSourceProvider.getDataSource();
685
+ }
686
+ return this.dataSource;
687
+ }
688
+ async getRepository() {
689
+ const ds = await this.getDataSource();
690
+ const EntityClass = this.configService.isCompanyFeatureEnabled() ? _entities_index_js__rspack_import_5.NotificationWithCompany : _entities_index_js__rspack_import_5.Notification;
691
+ return ds.getRepository(EntityClass);
692
+ }
693
+ buildEntity(userId, content) {
694
+ const entity = {
695
+ userId,
696
+ type: content.type ?? _flusys_nestjs_shared_enums__rspack_import_2.NotificationType.INFO,
697
+ title: content.title,
698
+ message: content.message ?? null,
699
+ data: content.data ?? null,
700
+ isRead: false
701
+ };
702
+ if (this.configService.isCompanyFeatureEnabled() && content.companyId) {
703
+ entity.companyId = content.companyId;
704
+ }
705
+ return entity;
706
+ }
707
+ emitToUser(notification, realtime) {
708
+ if (!realtime || !this.gateway) {
709
+ return;
710
+ }
711
+ const ext = notification;
712
+ const payload = this.toPayload(notification);
713
+ if (this.configService.isCompanyFeatureEnabled() && ext.companyId) {
714
+ this.gateway.emitToUserInCompany(notification.userId, ext.companyId, 'notification:new', payload);
715
+ } else {
716
+ this.gateway.emitToUser(notification.userId, 'notification:new', payload);
717
+ }
718
+ }
719
+ toPayload(notification) {
720
+ return {
721
+ id: notification.id,
722
+ type: notification.type,
723
+ title: notification.title,
724
+ message: notification.message,
725
+ data: notification.data,
726
+ createdAt: notification.createdAt
727
+ };
728
+ }
729
+ async clearCache() {
730
+ await this.utilsService.clearCache(_config_index_js__rspack_import_9/* .NOTIFICATION_EVENT_ENTITIES.NOTIFICATION */.BA.NOTIFICATION, this.cacheManager);
731
+ }
732
+ }
733
+ _ts_decorate([
734
+ (0,_flusys_nestjs_shared__rspack_import_0.LogAction)({
735
+ action: 'notification.send',
736
+ module: 'notification'
737
+ }),
738
+ _ts_metadata("design:type", Function),
739
+ _ts_metadata("design:paramtypes", [
740
+ typeof INotificationSendOptions === "undefined" ? Object : INotificationSendOptions
741
+ ]),
742
+ _ts_metadata("design:returntype", Promise)
743
+ ], NotificationHelperService.prototype, "send", null);
744
+ _ts_decorate([
745
+ (0,_flusys_nestjs_shared__rspack_import_0.LogAction)({
746
+ action: 'notification.sendToMany',
747
+ module: 'notification'
748
+ }),
749
+ _ts_metadata("design:type", Function),
750
+ _ts_metadata("design:paramtypes", [
751
+ typeof INotificationBulkSendOptions === "undefined" ? Object : INotificationBulkSendOptions
752
+ ]),
753
+ _ts_metadata("design:returntype", Promise)
754
+ ], NotificationHelperService.prototype, "sendToMany", null);
755
+ NotificationHelperService = _ts_decorate([
756
+ (0,_nestjs_common__rspack_import_4.Injectable)(),
757
+ _ts_param(0, (0,_nestjs_common__rspack_import_4.Inject)('CACHE_INSTANCE')),
758
+ _ts_param(1, (0,_nestjs_common__rspack_import_4.Inject)(_flusys_nestjs_shared_modules__rspack_import_3.UtilsService)),
759
+ _ts_param(2, (0,_nestjs_common__rspack_import_4.Inject)(_notification_config_service_js__rspack_import_7/* .NotificationConfigService */.v)),
760
+ _ts_param(3, (0,_nestjs_common__rspack_import_4.Inject)(_notification_datasource_provider_js__rspack_import_8/* .NotificationDataSourceProvider */.M)),
761
+ _ts_param(4, (0,_nestjs_common__rspack_import_4.Optional)()),
762
+ _ts_param(4, (0,_nestjs_common__rspack_import_4.Inject)(_gateways_index_js__rspack_import_6/* .NotificationGateway */.g)),
763
+ _ts_metadata("design:type", Function),
764
+ _ts_metadata("design:paramtypes", [
765
+ typeof _flusys_nestjs_shared_classes__rspack_import_1.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_1.HybridCache,
766
+ typeof _flusys_nestjs_shared_modules__rspack_import_3.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_3.UtilsService,
767
+ typeof _notification_config_service_js__rspack_import_7/* .NotificationConfigService */.v === "undefined" ? Object : _notification_config_service_js__rspack_import_7/* .NotificationConfigService */.v,
768
+ typeof _notification_datasource_provider_js__rspack_import_8/* .NotificationDataSourceProvider */.M === "undefined" ? Object : _notification_datasource_provider_js__rspack_import_8/* .NotificationDataSourceProvider */.M,
769
+ typeof _gateways_index_js__rspack_import_6/* .NotificationGateway */.g === "undefined" ? Object : _gateways_index_js__rspack_import_6/* .NotificationGateway */.g
770
+ ])
771
+ ], NotificationHelperService);
772
+
773
+ __webpack_require__.d(__webpack_exports__, {
774
+ T: () => (NotificationHelperService)
775
+ });
776
+
777
+
778
+ },
779
+ 422(module) {
780
+
781
+ module.exports = __rspack_external__flusys_nestjs_shared_393d2cae;
782
+
783
+
784
+ },
785
+ 937(module) {
786
+
787
+ module.exports = __rspack_external__flusys_nestjs_shared_classes_6076a329;
788
+
789
+
790
+ },
791
+ 471(module) {
792
+
793
+ module.exports = __rspack_external__flusys_nestjs_shared_enums_327421f8;
794
+
795
+
796
+ },
797
+ 236(module) {
798
+
799
+ module.exports = __rspack_external__flusys_nestjs_shared_modules_24702bee;
800
+
801
+
802
+ },
803
+ 157(module) {
804
+
805
+ module.exports = __rspack_external__nestjs_common_a04939da;
806
+
807
+
808
+ },
809
+ 125(module) {
810
+
811
+ module.exports = __rspack_external__nestjs_jwt_50c0e0ae;
812
+
813
+
814
+ },
815
+
816
+ };