@flusys/nestjs-notification 3.0.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.
- package/README.md +998 -0
- package/adapters/index.d.ts +1 -0
- package/adapters/notification.adapter.d.ts +10 -0
- package/cjs/adapters/index.js +18 -0
- package/cjs/adapters/notification.adapter.js +79 -0
- package/cjs/config/index.js +18 -0
- package/cjs/config/notification.constants.js +11 -0
- package/cjs/controllers/index.js +18 -0
- package/cjs/controllers/notification.controller.js +278 -0
- package/cjs/docs/index.js +18 -0
- package/cjs/docs/notification-swagger.config.js +61 -0
- package/cjs/dtos/index.js +18 -0
- package/cjs/dtos/notification.dto.js +244 -0
- package/cjs/entities/index.js +48 -0
- package/cjs/entities/notification-with-company.entity.js +57 -0
- package/cjs/entities/notification.entity.js +111 -0
- package/cjs/gateways/index.js +18 -0
- package/cjs/gateways/notification.gateway.js +226 -0
- package/cjs/index.js +28 -0
- package/cjs/interfaces/index.js +19 -0
- package/cjs/interfaces/notification-module.interface.js +4 -0
- package/cjs/interfaces/notification.interface.js +4 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/modules/notification.module.js +139 -0
- package/cjs/services/index.js +21 -0
- package/cjs/services/notification-config.service.js +72 -0
- package/cjs/services/notification-datasource.provider.js +174 -0
- package/cjs/services/notification-helper.service.js +186 -0
- package/cjs/services/notification.service.js +220 -0
- package/config/index.d.ts +1 -0
- package/config/notification.constants.d.ts +1 -0
- package/controllers/index.d.ts +1 -0
- package/controllers/notification.controller.d.ts +26 -0
- package/docs/index.d.ts +1 -0
- package/docs/notification-swagger.config.d.ts +2 -0
- package/dtos/index.d.ts +1 -0
- package/dtos/notification.dto.d.ts +47 -0
- package/entities/index.d.ts +8 -0
- package/entities/notification-with-company.entity.d.ts +4 -0
- package/entities/notification.entity.d.ts +10 -0
- package/fesm/adapters/index.js +1 -0
- package/fesm/adapters/notification.adapter.js +69 -0
- package/fesm/config/index.js +1 -0
- package/fesm/config/notification.constants.js +1 -0
- package/fesm/controllers/index.js +1 -0
- package/fesm/controllers/notification.controller.js +268 -0
- package/fesm/docs/index.js +1 -0
- package/fesm/docs/notification-swagger.config.js +51 -0
- package/fesm/dtos/index.js +1 -0
- package/fesm/dtos/notification.dto.js +211 -0
- package/fesm/entities/index.js +14 -0
- package/fesm/entities/notification-with-company.entity.js +47 -0
- package/fesm/entities/notification.entity.js +101 -0
- package/fesm/gateways/index.js +1 -0
- package/fesm/gateways/notification.gateway.js +175 -0
- package/fesm/index.js +20 -0
- package/fesm/interfaces/index.js +2 -0
- package/fesm/interfaces/notification-module.interface.js +1 -0
- package/fesm/interfaces/notification.interface.js +1 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/modules/notification.module.js +129 -0
- package/fesm/services/index.js +4 -0
- package/fesm/services/notification-config.service.js +62 -0
- package/fesm/services/notification-datasource.provider.js +123 -0
- package/fesm/services/notification-helper.service.js +176 -0
- package/fesm/services/notification.service.js +210 -0
- package/gateways/index.d.ts +1 -0
- package/gateways/notification.gateway.d.ts +21 -0
- package/index.d.ts +10 -0
- package/interfaces/index.d.ts +2 -0
- package/interfaces/notification-module.interface.d.ts +20 -0
- package/interfaces/notification.interface.d.ts +19 -0
- package/modules/index.d.ts +1 -0
- package/modules/notification.module.d.ts +8 -0
- package/package.json +98 -0
- package/services/index.d.ts +4 -0
- package/services/notification-config.service.d.ts +13 -0
- package/services/notification-datasource.provider.d.ts +23 -0
- package/services/notification-helper.service.d.ts +44 -0
- package/services/notification.service.d.ts +35 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NotificationGateway", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NotificationGateway;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _websockets = require("@nestjs/websockets");
|
|
13
|
+
const _socketio = require("socket.io");
|
|
14
|
+
const _jsonwebtoken = /*#__PURE__*/ _interop_require_wildcard(require("jsonwebtoken"));
|
|
15
|
+
const _notificationconfigservice = require("../services/notification-config.service");
|
|
16
|
+
function _define_property(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
30
|
+
if (typeof WeakMap !== "function") return null;
|
|
31
|
+
var cacheBabelInterop = new WeakMap();
|
|
32
|
+
var cacheNodeInterop = new WeakMap();
|
|
33
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
34
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
+
})(nodeInterop);
|
|
36
|
+
}
|
|
37
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
+
return {
|
|
43
|
+
default: obj
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
+
if (cache && cache.has(obj)) {
|
|
48
|
+
return cache.get(obj);
|
|
49
|
+
}
|
|
50
|
+
var newObj = {
|
|
51
|
+
__proto__: null
|
|
52
|
+
};
|
|
53
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
+
for(var key in obj){
|
|
55
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
+
if (desc && (desc.get || desc.set)) {
|
|
58
|
+
Object.defineProperty(newObj, key, desc);
|
|
59
|
+
} else {
|
|
60
|
+
newObj[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
newObj.default = obj;
|
|
65
|
+
if (cache) {
|
|
66
|
+
cache.set(obj, newObj);
|
|
67
|
+
}
|
|
68
|
+
return newObj;
|
|
69
|
+
}
|
|
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") r = Reflect.decorate(decorators, target, key, desc);
|
|
73
|
+
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;
|
|
74
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
75
|
+
}
|
|
76
|
+
function _ts_metadata(k, v) {
|
|
77
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
78
|
+
}
|
|
79
|
+
function _ts_param(paramIndex, decorator) {
|
|
80
|
+
return function(target, key) {
|
|
81
|
+
decorator(target, key, paramIndex);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
let NotificationGateway = class NotificationGateway {
|
|
85
|
+
afterInit() {
|
|
86
|
+
this.logger.log('Notification WebSocket Gateway initialized');
|
|
87
|
+
}
|
|
88
|
+
async handleConnection(client) {
|
|
89
|
+
try {
|
|
90
|
+
const token = this.extractToken(client);
|
|
91
|
+
if (!token) {
|
|
92
|
+
this.logger.warn(`Client ${client.id} connection rejected: No token provided`);
|
|
93
|
+
client.disconnect();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const payload = this.verifyToken(token);
|
|
97
|
+
if (!payload) {
|
|
98
|
+
this.logger.warn(`Client ${client.id} connection rejected: Invalid token`);
|
|
99
|
+
client.disconnect();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const userId = payload.id;
|
|
103
|
+
client.data.userId = userId;
|
|
104
|
+
client.data.companyId = payload.companyId;
|
|
105
|
+
if (!this.connectedUsers.has(userId)) {
|
|
106
|
+
this.connectedUsers.set(userId, new Set());
|
|
107
|
+
}
|
|
108
|
+
this.connectedUsers.get(userId).add(client.id);
|
|
109
|
+
client.join(`user:${userId}`);
|
|
110
|
+
if (payload.companyId) {
|
|
111
|
+
client.join(`company:${payload.companyId}`);
|
|
112
|
+
}
|
|
113
|
+
this.logger.log(`Client ${client.id} connected for user ${userId}`);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
this.logger.error(`Client ${client.id} connection error: ${error}`);
|
|
116
|
+
client.disconnect();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
handleDisconnect(client) {
|
|
120
|
+
const userId = client.data.userId;
|
|
121
|
+
if (userId) {
|
|
122
|
+
const sockets = this.connectedUsers.get(userId);
|
|
123
|
+
sockets?.delete(client.id);
|
|
124
|
+
if (sockets?.size === 0) {
|
|
125
|
+
this.connectedUsers.delete(userId);
|
|
126
|
+
}
|
|
127
|
+
this.logger.log(`Client ${client.id} disconnected for user ${userId}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
emitToUser(userId, event, data) {
|
|
131
|
+
this.server.to(`user:${userId}`).emit(event, data);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Emit to a specific user only on sockets connected with a specific company.
|
|
135
|
+
* This is crucial for multi-company scenarios where a user may be logged in
|
|
136
|
+
* with different companies on different devices.
|
|
137
|
+
*
|
|
138
|
+
* @param userId - The user ID
|
|
139
|
+
* @param companyId - The company ID (if null/undefined, emits to all user's sockets)
|
|
140
|
+
* @param event - The event name
|
|
141
|
+
* @param data - The payload
|
|
142
|
+
*/ emitToUserInCompany(userId, companyId, event, data) {
|
|
143
|
+
if (!companyId) {
|
|
144
|
+
// No company context - emit to all user's sockets
|
|
145
|
+
this.emitToUser(userId, event, data);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// Get all sockets in the user's room
|
|
149
|
+
const userRoom = `user:${userId}`;
|
|
150
|
+
const sockets = this.server.sockets.adapter.rooms.get(userRoom);
|
|
151
|
+
if (!sockets) {
|
|
152
|
+
this.logger.debug(`No sockets found for user ${userId}`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Emit only to sockets that match the company context
|
|
156
|
+
for (const socketId of sockets){
|
|
157
|
+
const socket = this.server.sockets.sockets.get(socketId);
|
|
158
|
+
if (socket && socket.data.companyId === companyId) {
|
|
159
|
+
socket.emit(event, data);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
emitToCompany(companyId, event, data) {
|
|
164
|
+
this.server.to(`company:${companyId}`).emit(event, data);
|
|
165
|
+
}
|
|
166
|
+
broadcast(event, data) {
|
|
167
|
+
this.server.emit(event, data);
|
|
168
|
+
}
|
|
169
|
+
isUserOnline(userId) {
|
|
170
|
+
return this.connectedUsers.has(userId);
|
|
171
|
+
}
|
|
172
|
+
getOnlineUserCount() {
|
|
173
|
+
return this.connectedUsers.size;
|
|
174
|
+
}
|
|
175
|
+
extractToken(client) {
|
|
176
|
+
const authToken = client.handshake.auth?.token;
|
|
177
|
+
if (authToken) return authToken;
|
|
178
|
+
const queryToken = client.handshake.query?.token;
|
|
179
|
+
if (typeof queryToken === 'string') return queryToken;
|
|
180
|
+
const authHeader = client.handshake.headers?.authorization;
|
|
181
|
+
if (authHeader?.startsWith('Bearer ')) {
|
|
182
|
+
return authHeader.substring(7);
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
verifyToken(token) {
|
|
187
|
+
try {
|
|
188
|
+
const secret = this.configService.getJwtSecret();
|
|
189
|
+
if (!secret) {
|
|
190
|
+
this.logger.error('No JWT secret configured for WebSocket authentication');
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return _jsonwebtoken.verify(token, secret);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
this.logger.warn(`Token verification failed: ${error}`);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
constructor(configService){
|
|
200
|
+
_define_property(this, "configService", void 0);
|
|
201
|
+
_define_property(this, "logger", void 0);
|
|
202
|
+
_define_property(this, "connectedUsers", void 0);
|
|
203
|
+
_define_property(this, "server", void 0);
|
|
204
|
+
this.configService = configService;
|
|
205
|
+
this.logger = new _common.Logger(NotificationGateway.name);
|
|
206
|
+
this.connectedUsers = new Map();
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
_ts_decorate([
|
|
210
|
+
(0, _websockets.WebSocketServer)(),
|
|
211
|
+
_ts_metadata("design:type", typeof _socketio.Server === "undefined" ? Object : _socketio.Server)
|
|
212
|
+
], NotificationGateway.prototype, "server", void 0);
|
|
213
|
+
NotificationGateway = _ts_decorate([
|
|
214
|
+
(0, _websockets.WebSocketGateway)({
|
|
215
|
+
namespace: '/notifications',
|
|
216
|
+
cors: {
|
|
217
|
+
origin: '*',
|
|
218
|
+
credentials: true
|
|
219
|
+
}
|
|
220
|
+
}),
|
|
221
|
+
_ts_param(0, (0, _common.Inject)(_notificationconfigservice.NotificationConfigService)),
|
|
222
|
+
_ts_metadata("design:type", Function),
|
|
223
|
+
_ts_metadata("design:paramtypes", [
|
|
224
|
+
typeof _notificationconfigservice.NotificationConfigService === "undefined" ? Object : _notificationconfigservice.NotificationConfigService
|
|
225
|
+
])
|
|
226
|
+
], NotificationGateway);
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Adapters
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
_export_star(require("./adapters"), exports);
|
|
7
|
+
_export_star(require("./config"), exports);
|
|
8
|
+
_export_star(require("./controllers"), exports);
|
|
9
|
+
_export_star(require("./docs"), exports);
|
|
10
|
+
_export_star(require("./dtos"), exports);
|
|
11
|
+
_export_star(require("./entities"), exports);
|
|
12
|
+
_export_star(require("./gateways"), exports);
|
|
13
|
+
_export_star(require("./interfaces"), exports);
|
|
14
|
+
_export_star(require("./modules"), exports);
|
|
15
|
+
_export_star(require("./services"), exports);
|
|
16
|
+
function _export_star(from, to) {
|
|
17
|
+
Object.keys(from).forEach(function(k) {
|
|
18
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
19
|
+
Object.defineProperty(to, k, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return from[k];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./notification.interface"), exports);
|
|
6
|
+
_export_star(require("./notification-module.interface"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./notification.module"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NotificationModule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NotificationModule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
+
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
13
|
+
const _common = require("@nestjs/common");
|
|
14
|
+
const _notificationconstants = require("../config/notification.constants");
|
|
15
|
+
const _controllers = require("../controllers");
|
|
16
|
+
const _adapters = require("../adapters");
|
|
17
|
+
const _services = require("../services");
|
|
18
|
+
const _gateways = require("../gateways");
|
|
19
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
20
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
+
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;
|
|
23
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
24
|
+
}
|
|
25
|
+
const CONTROLLERS = [
|
|
26
|
+
_controllers.NotificationController
|
|
27
|
+
];
|
|
28
|
+
const EXPORTED_SERVICES = [
|
|
29
|
+
_services.NotificationConfigService,
|
|
30
|
+
_services.NotificationDataSourceProvider,
|
|
31
|
+
_services.NotificationService,
|
|
32
|
+
_services.NotificationHelperService
|
|
33
|
+
];
|
|
34
|
+
const ADAPTER_PROVIDER = {
|
|
35
|
+
provide: _interfaces.NOTIFICATION_ADAPTER,
|
|
36
|
+
useClass: _adapters.NotificationAdapter
|
|
37
|
+
};
|
|
38
|
+
let NotificationModule = class NotificationModule {
|
|
39
|
+
static forRoot(options) {
|
|
40
|
+
const enableRealtime = options.config?.enableRealtime !== false;
|
|
41
|
+
const gatewayProviders = enableRealtime ? [
|
|
42
|
+
_gateways.NotificationGateway
|
|
43
|
+
] : [];
|
|
44
|
+
return {
|
|
45
|
+
module: NotificationModule,
|
|
46
|
+
global: options.global ?? false,
|
|
47
|
+
imports: [
|
|
48
|
+
_modules.CacheModule,
|
|
49
|
+
_modules.UtilsModule
|
|
50
|
+
],
|
|
51
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
52
|
+
providers: [
|
|
53
|
+
...this.buildProviders(options),
|
|
54
|
+
...gatewayProviders,
|
|
55
|
+
_adapters.NotificationAdapter,
|
|
56
|
+
ADAPTER_PROVIDER
|
|
57
|
+
],
|
|
58
|
+
exports: [
|
|
59
|
+
...EXPORTED_SERVICES,
|
|
60
|
+
...gatewayProviders,
|
|
61
|
+
_interfaces.NOTIFICATION_ADAPTER
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static forRootAsync(options) {
|
|
66
|
+
return {
|
|
67
|
+
module: NotificationModule,
|
|
68
|
+
global: options.global ?? false,
|
|
69
|
+
imports: [
|
|
70
|
+
...options.imports || [],
|
|
71
|
+
_modules.CacheModule,
|
|
72
|
+
_modules.UtilsModule
|
|
73
|
+
],
|
|
74
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
75
|
+
providers: [
|
|
76
|
+
...this.createAsyncProviders(options),
|
|
77
|
+
...this.buildProviders(),
|
|
78
|
+
_gateways.NotificationGateway,
|
|
79
|
+
_adapters.NotificationAdapter,
|
|
80
|
+
ADAPTER_PROVIDER
|
|
81
|
+
],
|
|
82
|
+
exports: [
|
|
83
|
+
...EXPORTED_SERVICES,
|
|
84
|
+
_gateways.NotificationGateway,
|
|
85
|
+
_interfaces.NOTIFICATION_ADAPTER
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
static buildProviders(options) {
|
|
90
|
+
const providers = [
|
|
91
|
+
...EXPORTED_SERVICES
|
|
92
|
+
];
|
|
93
|
+
if (options) {
|
|
94
|
+
providers.unshift({
|
|
95
|
+
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
96
|
+
useValue: options
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return providers;
|
|
100
|
+
}
|
|
101
|
+
static createAsyncProviders(options) {
|
|
102
|
+
if (options.useFactory) {
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
106
|
+
useFactory: async (...args)=>({
|
|
107
|
+
...options,
|
|
108
|
+
config: await options.useFactory(...args)
|
|
109
|
+
}),
|
|
110
|
+
inject: options.inject || []
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
const factoryClass = options.useClass || options.useExisting;
|
|
115
|
+
if (!factoryClass) return [];
|
|
116
|
+
const providers = [
|
|
117
|
+
{
|
|
118
|
+
provide: _notificationconstants.NOTIFICATION_MODULE_OPTIONS,
|
|
119
|
+
useFactory: async (factory)=>({
|
|
120
|
+
...options,
|
|
121
|
+
config: await factory.createNotificationOptions()
|
|
122
|
+
}),
|
|
123
|
+
inject: [
|
|
124
|
+
factoryClass
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
if (options.useClass) {
|
|
129
|
+
providers.push({
|
|
130
|
+
provide: options.useClass,
|
|
131
|
+
useClass: options.useClass
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return providers;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
NotificationModule = _ts_decorate([
|
|
138
|
+
(0, _common.Module)({})
|
|
139
|
+
], NotificationModule);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./notification-config.service"), exports);
|
|
6
|
+
_export_star(require("./notification-datasource.provider"), exports);
|
|
7
|
+
_export_star(require("./notification.service"), exports);
|
|
8
|
+
_export_star(require("./notification-helper.service"), exports);
|
|
9
|
+
function _export_star(from, to) {
|
|
10
|
+
Object.keys(from).forEach(function(k) {
|
|
11
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
+
Object.defineProperty(to, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return from[k];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return from;
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "NotificationConfigService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return NotificationConfigService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _interfaces = require("../interfaces");
|
|
13
|
+
const _notificationconstants = require("../config/notification.constants");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
28
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
+
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;
|
|
31
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
+
}
|
|
33
|
+
function _ts_metadata(k, v) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
+
}
|
|
36
|
+
function _ts_param(paramIndex, decorator) {
|
|
37
|
+
return function(target, key) {
|
|
38
|
+
decorator(target, key, paramIndex);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let NotificationConfigService = class NotificationConfigService {
|
|
42
|
+
isCompanyFeatureEnabled() {
|
|
43
|
+
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
44
|
+
}
|
|
45
|
+
getDatabaseMode() {
|
|
46
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
47
|
+
}
|
|
48
|
+
isMultiTenant() {
|
|
49
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
50
|
+
}
|
|
51
|
+
isRealtimeEnabled() {
|
|
52
|
+
return this.options.config?.enableRealtime !== false;
|
|
53
|
+
}
|
|
54
|
+
getJwtSecret() {
|
|
55
|
+
return this.options.config?.jwtSecret;
|
|
56
|
+
}
|
|
57
|
+
getOptions() {
|
|
58
|
+
return this.options;
|
|
59
|
+
}
|
|
60
|
+
constructor(options){
|
|
61
|
+
_define_property(this, "options", void 0);
|
|
62
|
+
this.options = options;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
NotificationConfigService = _ts_decorate([
|
|
66
|
+
(0, _common.Injectable)(),
|
|
67
|
+
_ts_param(0, (0, _common.Inject)(_notificationconstants.NOTIFICATION_MODULE_OPTIONS)),
|
|
68
|
+
_ts_metadata("design:type", Function),
|
|
69
|
+
_ts_metadata("design:paramtypes", [
|
|
70
|
+
typeof _interfaces.NotificationModuleOptions === "undefined" ? Object : _interfaces.NotificationModuleOptions
|
|
71
|
+
])
|
|
72
|
+
], NotificationConfigService);
|