@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
package/fesm/entities/index.js
CHANGED
|
@@ -1,14 +1,217 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
export const
|
|
1
|
+
import { Identity } from "@flusys/nestjs-shared/entities";
|
|
2
|
+
import { Column, Entity, Index } from "typeorm";
|
|
3
|
+
import * as __rspack_external__flusys_nestjs_shared_393d2cae from "@flusys/nestjs-shared";
|
|
4
|
+
import * as __rspack_external__flusys_nestjs_shared_enums_327421f8 from "@flusys/nestjs-shared/enums";
|
|
5
|
+
export const __rspack_esm_id = 604;
|
|
6
|
+
export const __rspack_esm_ids = [604];
|
|
7
|
+
export const __webpack_modules__ = {
|
|
8
|
+
240(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
9
|
+
|
|
10
|
+
// EXPORTS
|
|
11
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
12
|
+
Notification: () => (/* reexport */ Notification),
|
|
13
|
+
bW: () => (/* reexport */ Notification),
|
|
14
|
+
s_: () => (/* binding */ NotificationCompanyEntities),
|
|
15
|
+
Ms: () => (/* binding */ NotificationCoreEntities),
|
|
16
|
+
NotificationWithCompany: () => (/* reexport */ NotificationWithCompany),
|
|
17
|
+
qC: () => (/* binding */ getNotificationEntitiesByConfig)
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared"
|
|
21
|
+
var nestjs_shared_ = __webpack_require__(422);
|
|
22
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/entities"
|
|
23
|
+
|
|
24
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/enums"
|
|
25
|
+
var enums_ = __webpack_require__(471);
|
|
26
|
+
;// CONCATENATED MODULE: external "typeorm"
|
|
27
|
+
|
|
28
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/notification.entity.ts
|
|
29
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
30
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
31
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
32
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
33
|
+
} else {
|
|
34
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
35
|
+
if (d = decorators[i]) {
|
|
36
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
|
+
}
|
|
42
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
43
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
44
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Notification extends Identity {
|
|
52
|
+
userId;
|
|
53
|
+
type;
|
|
54
|
+
title;
|
|
55
|
+
message;
|
|
56
|
+
data;
|
|
57
|
+
isRead;
|
|
58
|
+
readAt;
|
|
59
|
+
}
|
|
60
|
+
_ts_decorate([
|
|
61
|
+
Column({
|
|
62
|
+
name: 'user_id',
|
|
63
|
+
type: 'uuid',
|
|
64
|
+
nullable: false
|
|
65
|
+
}),
|
|
66
|
+
Index(),
|
|
67
|
+
_ts_metadata("design:type", String)
|
|
68
|
+
], Notification.prototype, "userId", void 0);
|
|
69
|
+
_ts_decorate([
|
|
70
|
+
Column({
|
|
71
|
+
type: 'varchar',
|
|
72
|
+
length: 50,
|
|
73
|
+
nullable: false,
|
|
74
|
+
default: enums_.NotificationType.INFO
|
|
75
|
+
}),
|
|
76
|
+
_ts_metadata("design:type", String)
|
|
77
|
+
], Notification.prototype, "type", void 0);
|
|
78
|
+
_ts_decorate([
|
|
79
|
+
Column({
|
|
80
|
+
type: 'varchar',
|
|
81
|
+
length: 255,
|
|
82
|
+
nullable: false
|
|
83
|
+
}),
|
|
84
|
+
_ts_metadata("design:type", String)
|
|
85
|
+
], Notification.prototype, "title", void 0);
|
|
86
|
+
_ts_decorate([
|
|
87
|
+
Column({
|
|
88
|
+
type: 'text',
|
|
89
|
+
nullable: true
|
|
90
|
+
}),
|
|
91
|
+
_ts_metadata("design:type", Object)
|
|
92
|
+
], Notification.prototype, "message", void 0);
|
|
93
|
+
_ts_decorate([
|
|
94
|
+
Column({
|
|
95
|
+
type: (0,nestjs_shared_.getJsonColumnType)(),
|
|
96
|
+
nullable: true
|
|
97
|
+
}),
|
|
98
|
+
_ts_metadata("design:type", Object)
|
|
99
|
+
], Notification.prototype, "data", void 0);
|
|
100
|
+
_ts_decorate([
|
|
101
|
+
Column({
|
|
102
|
+
name: 'is_read',
|
|
103
|
+
type: 'boolean',
|
|
104
|
+
nullable: false,
|
|
105
|
+
default: false
|
|
106
|
+
}),
|
|
107
|
+
Index(),
|
|
108
|
+
_ts_metadata("design:type", Boolean)
|
|
109
|
+
], Notification.prototype, "isRead", void 0);
|
|
110
|
+
_ts_decorate([
|
|
111
|
+
Column({
|
|
112
|
+
name: 'read_at',
|
|
113
|
+
type: 'timestamp',
|
|
114
|
+
nullable: true
|
|
115
|
+
}),
|
|
116
|
+
_ts_metadata("design:type", Object)
|
|
117
|
+
], Notification.prototype, "readAt", void 0);
|
|
118
|
+
Notification = _ts_decorate([
|
|
119
|
+
Entity({
|
|
120
|
+
name: 'notification'
|
|
121
|
+
}),
|
|
122
|
+
Index([
|
|
123
|
+
'userId',
|
|
124
|
+
'isRead'
|
|
125
|
+
]),
|
|
126
|
+
Index([
|
|
127
|
+
'userId',
|
|
128
|
+
'createdAt'
|
|
129
|
+
])
|
|
130
|
+
], Notification);
|
|
131
|
+
|
|
132
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/notification-with-company.entity.ts
|
|
133
|
+
function notification_with_company_entity_ts_decorate(decorators, target, key, desc) {
|
|
134
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
135
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
136
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
137
|
+
} else {
|
|
138
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
139
|
+
if (d = decorators[i]) {
|
|
140
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
145
|
+
}
|
|
146
|
+
function notification_with_company_entity_ts_metadata(metadataKey, metadataValue) {
|
|
147
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
148
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class NotificationWithCompany extends Notification {
|
|
154
|
+
companyId;
|
|
155
|
+
}
|
|
156
|
+
notification_with_company_entity_ts_decorate([
|
|
157
|
+
Column({
|
|
158
|
+
name: 'company_id',
|
|
159
|
+
type: 'uuid',
|
|
160
|
+
nullable: true
|
|
161
|
+
}),
|
|
162
|
+
notification_with_company_entity_ts_metadata("design:type", Object)
|
|
163
|
+
], NotificationWithCompany.prototype, "companyId", void 0);
|
|
164
|
+
NotificationWithCompany = notification_with_company_entity_ts_decorate([
|
|
165
|
+
Entity({
|
|
166
|
+
name: 'notification'
|
|
167
|
+
}),
|
|
168
|
+
Index([
|
|
169
|
+
'companyId',
|
|
170
|
+
'userId',
|
|
171
|
+
'isRead'
|
|
172
|
+
])
|
|
173
|
+
], NotificationWithCompany);
|
|
174
|
+
|
|
175
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/entities/index.ts
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
const NotificationCoreEntities = [
|
|
6
181
|
Notification
|
|
7
182
|
];
|
|
8
|
-
|
|
183
|
+
const NotificationCompanyEntities = [
|
|
9
184
|
NotificationWithCompany
|
|
10
185
|
];
|
|
11
|
-
|
|
186
|
+
function getNotificationEntitiesByConfig(enableCompanyFeature) {
|
|
12
187
|
return enableCompanyFeature ? NotificationCompanyEntities : NotificationCoreEntities;
|
|
13
188
|
}
|
|
14
|
-
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
},
|
|
193
|
+
422(module) {
|
|
194
|
+
|
|
195
|
+
module.exports = __rspack_external__flusys_nestjs_shared_393d2cae;
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
},
|
|
199
|
+
471(module) {
|
|
200
|
+
|
|
201
|
+
module.exports = __rspack_external__flusys_nestjs_shared_enums_327421f8;
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
};
|
|
207
|
+
import { __webpack_require__ } from '../runtime.js';
|
|
208
|
+
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
|
|
209
|
+
import * as __rspack_chunk_1 from './index.js';
|
|
210
|
+
__webpack_require__.C(__rspack_chunk_1);
|
|
211
|
+
var __webpack_exports__ = __webpack_exec__(240);var __webpack_exports__Notification = __webpack_exports__.Notification;
|
|
212
|
+
var __webpack_exports__NotificationBase = __webpack_exports__.bW;
|
|
213
|
+
var __webpack_exports__NotificationCompanyEntities = __webpack_exports__.s_;
|
|
214
|
+
var __webpack_exports__NotificationCoreEntities = __webpack_exports__.Ms;
|
|
215
|
+
var __webpack_exports__NotificationWithCompany = __webpack_exports__.NotificationWithCompany;
|
|
216
|
+
var __webpack_exports__getNotificationEntitiesByConfig = __webpack_exports__.qC;
|
|
217
|
+
export { __webpack_exports__Notification as Notification, __webpack_exports__NotificationBase as NotificationBase, __webpack_exports__NotificationCompanyEntities as NotificationCompanyEntities, __webpack_exports__NotificationCoreEntities as NotificationCoreEntities, __webpack_exports__NotificationWithCompany as NotificationWithCompany, __webpack_exports__getNotificationEntitiesByConfig as getNotificationEntitiesByConfig };
|
package/fesm/gateways/index.js
CHANGED
|
@@ -1 +1,286 @@
|
|
|
1
|
-
|
|
1
|
+
import { envConfig } from "@flusys/nestjs-core/config";
|
|
2
|
+
import { WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
|
|
3
|
+
import { Server } from "socket.io";
|
|
4
|
+
import * as __rspack_external__nestjs_common_a04939da from "@nestjs/common";
|
|
5
|
+
import * as __rspack_external__nestjs_jwt_50c0e0ae from "@nestjs/jwt";
|
|
6
|
+
export const __rspack_esm_id = 856;
|
|
7
|
+
export const __rspack_esm_ids = [856];
|
|
8
|
+
export const __webpack_modules__ = {
|
|
9
|
+
608(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
10
|
+
const NOTIFICATION_MODULE_OPTIONS = 'NOTIFICATION_MODULE_OPTIONS';
|
|
11
|
+
|
|
12
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
13
|
+
}, {
|
|
14
|
+
G: NOTIFICATION_MODULE_OPTIONS
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
},
|
|
19
|
+
31(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
20
|
+
|
|
21
|
+
// EXPORTS
|
|
22
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
23
|
+
g: () => (/* reexport */ NotificationGateway)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-core/config"
|
|
27
|
+
|
|
28
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
29
|
+
var common_ = __webpack_require__(157);
|
|
30
|
+
// EXTERNAL MODULE: external "@nestjs/jwt"
|
|
31
|
+
var jwt_ = __webpack_require__(125);
|
|
32
|
+
;// CONCATENATED MODULE: external "@nestjs/websockets"
|
|
33
|
+
|
|
34
|
+
;// CONCATENATED MODULE: external "socket.io"
|
|
35
|
+
|
|
36
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-config.service.ts
|
|
37
|
+
var notification_config_service = __webpack_require__(53);
|
|
38
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/gateways/notification.gateway.ts
|
|
39
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
40
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
42
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
43
|
+
} else {
|
|
44
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
45
|
+
if (d = decorators[i]) {
|
|
46
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
51
|
+
}
|
|
52
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
53
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
54
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function _ts_param(paramIndex, decorator) {
|
|
58
|
+
return function(target, key) {
|
|
59
|
+
decorator(target, key, paramIndex);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class NotificationGateway {
|
|
69
|
+
configService;
|
|
70
|
+
jwtService;
|
|
71
|
+
connectedUsers = new Map();
|
|
72
|
+
server;
|
|
73
|
+
constructor(configService, jwtService){
|
|
74
|
+
this.configService = configService;
|
|
75
|
+
this.jwtService = jwtService;
|
|
76
|
+
}
|
|
77
|
+
afterInit() {
|
|
78
|
+
// Gateway initialized
|
|
79
|
+
}
|
|
80
|
+
async handleConnection(client) {
|
|
81
|
+
try {
|
|
82
|
+
const token = this.extractToken(client);
|
|
83
|
+
if (!token) {
|
|
84
|
+
client.disconnect();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const payload = this.verifyToken(token);
|
|
88
|
+
if (!payload) {
|
|
89
|
+
client.disconnect();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const userId = payload.id;
|
|
93
|
+
client.data.userId = userId;
|
|
94
|
+
client.data.companyId = payload.companyId;
|
|
95
|
+
if (!this.connectedUsers.has(userId)) {
|
|
96
|
+
this.connectedUsers.set(userId, new Set());
|
|
97
|
+
}
|
|
98
|
+
this.connectedUsers.get(userId).add(client.id);
|
|
99
|
+
client.join(`user:${userId}`);
|
|
100
|
+
if (payload.companyId) {
|
|
101
|
+
client.join(`company:${payload.companyId}`);
|
|
102
|
+
client.join(`user:${userId}:company:${payload.companyId}`);
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
client.disconnect();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
handleDisconnect(client) {
|
|
109
|
+
const userId = client.data.userId;
|
|
110
|
+
if (userId) {
|
|
111
|
+
const sockets = this.connectedUsers.get(userId);
|
|
112
|
+
sockets?.delete(client.id);
|
|
113
|
+
if (sockets?.size === 0) {
|
|
114
|
+
this.connectedUsers.delete(userId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
emitToUser(userId, event, data) {
|
|
119
|
+
this.server?.to(`user:${userId}`).emit(event, data);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Emit to a user scoped to a specific company session.
|
|
123
|
+
* Uses the combined room `user:{id}:company:{cid}` so only sockets
|
|
124
|
+
* authenticated under that company receive the event — critical for
|
|
125
|
+
* users logged in across multiple companies on different devices.
|
|
126
|
+
* Falls back to all user sockets when companyId is absent.
|
|
127
|
+
*/ emitToUserInCompany(userId, companyId, event, data) {
|
|
128
|
+
if (!this.server) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!companyId) {
|
|
132
|
+
this.emitToUser(userId, event, data);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.server.to(`user:${userId}:company:${companyId}`).emit(event, data);
|
|
136
|
+
}
|
|
137
|
+
emitToCompany(companyId, event, data) {
|
|
138
|
+
this.server?.to(`company:${companyId}`).emit(event, data);
|
|
139
|
+
}
|
|
140
|
+
broadcast(event, data) {
|
|
141
|
+
this.server?.emit(event, data);
|
|
142
|
+
}
|
|
143
|
+
isUserOnline(userId) {
|
|
144
|
+
return this.connectedUsers.has(userId);
|
|
145
|
+
}
|
|
146
|
+
getOnlineUserCount() {
|
|
147
|
+
return this.connectedUsers.size;
|
|
148
|
+
}
|
|
149
|
+
extractToken(client) {
|
|
150
|
+
const authToken = client.handshake.auth?.token;
|
|
151
|
+
if (authToken) return authToken;
|
|
152
|
+
const queryToken = client.handshake.query?.token;
|
|
153
|
+
if (typeof queryToken === 'string') return queryToken;
|
|
154
|
+
const authHeader = client.handshake.headers?.authorization;
|
|
155
|
+
if (authHeader?.startsWith('Bearer ')) {
|
|
156
|
+
return authHeader.substring(7);
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
verifyToken(token) {
|
|
161
|
+
try {
|
|
162
|
+
const secret = this.configService.getJwtSecret();
|
|
163
|
+
if (!secret) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return this.jwtService.verify(token, {
|
|
167
|
+
secret,
|
|
168
|
+
algorithms: [
|
|
169
|
+
'HS256'
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
_ts_decorate([
|
|
178
|
+
WebSocketServer(),
|
|
179
|
+
_ts_metadata("design:type", typeof Server === "undefined" ? Object : Server)
|
|
180
|
+
], NotificationGateway.prototype, "server", void 0);
|
|
181
|
+
NotificationGateway = _ts_decorate([
|
|
182
|
+
WebSocketGateway({
|
|
183
|
+
namespace: '/notifications',
|
|
184
|
+
cors: {
|
|
185
|
+
origin: envConfig.getOrigins(),
|
|
186
|
+
credentials: true
|
|
187
|
+
}
|
|
188
|
+
}),
|
|
189
|
+
_ts_param(0, (0,common_.Inject)(notification_config_service/* .NotificationConfigService */.v)),
|
|
190
|
+
_ts_param(1, (0,common_.Inject)(jwt_.JwtService)),
|
|
191
|
+
_ts_metadata("design:type", Function),
|
|
192
|
+
_ts_metadata("design:paramtypes", [
|
|
193
|
+
typeof notification_config_service/* .NotificationConfigService */.v === "undefined" ? Object : notification_config_service/* .NotificationConfigService */.v,
|
|
194
|
+
typeof jwt_.JwtService === "undefined" ? Object : jwt_.JwtService
|
|
195
|
+
])
|
|
196
|
+
], NotificationGateway);
|
|
197
|
+
|
|
198
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/gateways/index.ts
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
},
|
|
203
|
+
53(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
204
|
+
/* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(157);
|
|
205
|
+
/* import */ var _config_notification_constants_js__rspack_import_1 = __webpack_require__(608);
|
|
206
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
207
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
208
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
209
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
210
|
+
} else {
|
|
211
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
212
|
+
if (d = decorators[i]) {
|
|
213
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
218
|
+
}
|
|
219
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
220
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
221
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function _ts_param(paramIndex, decorator) {
|
|
225
|
+
return function(target, key) {
|
|
226
|
+
decorator(target, key, paramIndex);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class NotificationConfigService {
|
|
232
|
+
options;
|
|
233
|
+
constructor(options){
|
|
234
|
+
this.options = options;
|
|
235
|
+
}
|
|
236
|
+
isCompanyFeatureEnabled() {
|
|
237
|
+
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
238
|
+
}
|
|
239
|
+
getDatabaseMode() {
|
|
240
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
241
|
+
}
|
|
242
|
+
isMultiTenant() {
|
|
243
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
244
|
+
}
|
|
245
|
+
getJwtSecret() {
|
|
246
|
+
return this.options.config?.jwtSecret;
|
|
247
|
+
}
|
|
248
|
+
getOptions() {
|
|
249
|
+
return this.options;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
NotificationConfigService = _ts_decorate([
|
|
253
|
+
(0,_nestjs_common__rspack_import_0.Injectable)(),
|
|
254
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_0.Inject)(_config_notification_constants_js__rspack_import_1/* .NOTIFICATION_MODULE_OPTIONS */.G)),
|
|
255
|
+
_ts_metadata("design:type", Function),
|
|
256
|
+
_ts_metadata("design:paramtypes", [
|
|
257
|
+
typeof NotificationModuleOptions === "undefined" ? Object : NotificationModuleOptions
|
|
258
|
+
])
|
|
259
|
+
], NotificationConfigService);
|
|
260
|
+
|
|
261
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
262
|
+
v: () => (NotificationConfigService)
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
},
|
|
267
|
+
157(module) {
|
|
268
|
+
|
|
269
|
+
module.exports = __rspack_external__nestjs_common_a04939da;
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
},
|
|
273
|
+
125(module) {
|
|
274
|
+
|
|
275
|
+
module.exports = __rspack_external__nestjs_jwt_50c0e0ae;
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
};
|
|
281
|
+
import { __webpack_require__ } from '../runtime.js';
|
|
282
|
+
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
|
|
283
|
+
import * as __rspack_chunk_1 from './index.js';
|
|
284
|
+
__webpack_require__.C(__rspack_chunk_1);
|
|
285
|
+
var __webpack_exports__ = __webpack_exec__(31);var __webpack_exports__NotificationGateway = __webpack_exports__.g;
|
|
286
|
+
export { __webpack_exports__NotificationGateway as NotificationGateway };
|