@flusys/nestjs-notification 5.1.1 → 5.1.3

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.
@@ -26,7 +26,7 @@ function _ts_param(paramIndex, decorator) {
26
26
  };
27
27
  }
28
28
  import { LogAction } from '@flusys/nestjs-shared';
29
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
29
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
30
30
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
31
31
  import { UtilsService } from '@flusys/nestjs-shared/modules';
32
32
  import { applyCompanyFilter } from '@flusys/nestjs-shared/utils';
@@ -36,13 +36,10 @@ import { Notification, NotificationWithCompany } from '../entities';
36
36
  import { NotificationGateway } from '../gateways';
37
37
  import { NotificationConfigService } from './notification-config.service';
38
38
  import { NotificationDataSourceProvider } from './notification-datasource.provider';
39
- export class NotificationService extends RequestScopedApiService {
39
+ export class NotificationService extends ApiService {
40
40
  resolveEntity() {
41
41
  return this.notificationConfig.isCompanyFeatureEnabled() ? NotificationWithCompany : Notification;
42
42
  }
43
- getDataSourceProvider() {
44
- return this.dataSourceProvider;
45
- }
46
43
  async convertSingleDtoToEntity(dto, user) {
47
44
  let entity = {};
48
45
  if ('id' in dto && dto.id) {
@@ -115,11 +112,11 @@ export class NotificationService extends RequestScopedApiService {
115
112
  async afterInsertOperation(entities, _user, _qr) {
116
113
  for (const entity of entities){
117
114
  const ext = entity;
118
- this.emitToUserInCompanyIfRealtime(entity.userId, ext.companyId, 'notification:new', this.toPayload(entity));
115
+ this.emitToUser(entity.userId, ext.companyId, 'notification:new', this.toPayload(entity));
119
116
  }
120
117
  }
121
118
  async markAsRead(id, user) {
122
- await this.ensureRepositoryInitialized();
119
+ await this.ensureDataSourceRepository();
123
120
  const notification = await this.repository.findOne({
124
121
  where: {
125
122
  id,
@@ -143,13 +140,13 @@ export class NotificationService extends RequestScopedApiService {
143
140
  ]);
144
141
  // Emit to user's sockets in the same company context
145
142
  const ext = notification;
146
- this.emitToUserInCompanyIfRealtime(user.id, ext.companyId ?? user.companyId, 'notification:read', {
143
+ this.emitToUser(user.id, ext.companyId ?? user.companyId, 'notification:read', {
147
144
  id
148
145
  });
149
146
  return notification;
150
147
  }
151
148
  async markAllAsRead(user) {
152
- await this.ensureRepositoryInitialized();
149
+ await this.ensureDataSourceRepository();
153
150
  const where = {
154
151
  userId: user.id,
155
152
  isRead: false
@@ -163,11 +160,11 @@ export class NotificationService extends RequestScopedApiService {
163
160
  });
164
161
  await this.clearCacheForAll();
165
162
  // Emit to user's sockets in the current company context
166
- this.emitToUserInCompanyIfRealtime(user.id, user.companyId, 'notification:read-all', {});
163
+ this.emitToUser(user.id, user.companyId, 'notification:read-all', {});
167
164
  return result.affected ?? 0;
168
165
  }
169
166
  async getUnreadCount(user) {
170
- await this.ensureRepositoryInitialized();
167
+ await this.ensureDataSourceRepository();
171
168
  const where = {
172
169
  userId: user.id,
173
170
  isRead: false
@@ -189,24 +186,18 @@ export class NotificationService extends RequestScopedApiService {
189
186
  createdAt: entity.createdAt
190
187
  };
191
188
  }
192
- /**
193
- * Emit to user's sockets within a specific company context.
194
- * If company feature is enabled and companyId is provided, only sockets
195
- * connected with that company will receive the event.
196
- */ emitToUserInCompanyIfRealtime(userId, companyId, event, payload) {
197
- if (!this.notificationConfig.isRealtimeEnabled() || !this.gateway) {
189
+ emitToUser(userId, companyId, event, payload) {
190
+ if (!this.gateway) {
198
191
  return;
199
192
  }
200
193
  if (this.notificationConfig.isCompanyFeatureEnabled() && companyId) {
201
- // Company feature enabled - emit only to sockets in matching company context
202
194
  this.gateway.emitToUserInCompany(userId, companyId, event, payload);
203
195
  } else {
204
- // No company feature or no companyId - emit to all user's sockets
205
196
  this.gateway.emitToUser(userId, event, payload);
206
197
  }
207
198
  }
208
199
  constructor(cacheManager, utilsService, notificationConfig, dataSourceProvider, gateway){
209
- super('notification', null, cacheManager, utilsService, NotificationService.name, false, 'notification'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.dataSourceProvider = dataSourceProvider, this.gateway = gateway;
200
+ super('notification', cacheManager, utilsService, NotificationService.name, false, 'notification', undefined, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
210
201
  }
211
202
  }
212
203
  _ts_decorate([
@@ -1,7 +1,6 @@
1
1
  import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig, IModuleOptionsFactory } from '@flusys/nestjs-core';
2
2
  import { ModuleMetadata, Type } from '@nestjs/common';
3
3
  export interface INotificationModuleConfig extends IDataSourceServiceOptions {
4
- enableRealtime?: boolean;
5
4
  jwtSecret?: string;
6
5
  }
7
6
  export interface NotificationModuleOptions extends IDynamicModuleConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-notification",
3
- "version": "5.1.1",
3
+ "version": "5.1.3",
4
4
  "description": "Notification module with real-time Socket.IO support",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -77,23 +77,23 @@
77
77
  }
78
78
  },
79
79
  "peerDependencies": {
80
- "@nestjs/common": "^10.0.0 || ^11.0.0",
81
- "@nestjs/config": "^3.0.0 || ^4.0.0",
82
- "@nestjs/core": "^10.0.0 || ^11.0.0",
83
- "@nestjs/platform-express": "^10.0.0 || ^11.0.0",
84
- "@nestjs/swagger": "^7.0.0 || ^11.0.0",
85
- "@nestjs/typeorm": "^10.0.0 || ^11.0.0",
86
- "@nestjs/websockets": "^10.0.0 || ^11.0.0",
87
- "@nestjs/platform-socket.io": "^10.0.0 || ^11.0.0",
88
- "class-transformer": "^0.5.0",
89
- "class-validator": "^0.14.0",
90
- "socket.io": "^4.0.0",
80
+ "@nestjs/common": "^11.0.0",
81
+ "@nestjs/config": "^4.0.0",
82
+ "@nestjs/core": "^11.0.0",
83
+ "@nestjs/platform-express": "^11.0.0",
84
+ "@nestjs/swagger": "^11.0.0",
85
+ "@nestjs/typeorm": "^11.0.0",
86
+ "@nestjs/websockets": "^11.0.0",
87
+ "@nestjs/platform-socket.io": "^11.0.0",
88
+ "class-transformer": "^0.5.1",
89
+ "class-validator": "^0.14.0 || ^0.15.0",
90
+ "socket.io": "^4.8.0",
91
91
  "typeorm": "^0.3.0",
92
- "express": "^4.18.0"
92
+ "express": "^4.18.0 || ^5.0.0"
93
93
  },
94
94
  "dependencies": {
95
- "@flusys/nestjs-core": "5.1.1",
96
- "@flusys/nestjs-shared": "5.1.1",
95
+ "@flusys/nestjs-core": "5.1.3",
96
+ "@flusys/nestjs-shared": "5.1.3",
97
97
  "jsonwebtoken": "^9.0.0"
98
98
  }
99
99
  }
@@ -7,7 +7,6 @@ export declare class NotificationConfigService implements IModuleConfigService {
7
7
  isCompanyFeatureEnabled(): boolean;
8
8
  getDatabaseMode(): DatabaseMode;
9
9
  isMultiTenant(): boolean;
10
- isRealtimeEnabled(): boolean;
11
10
  getJwtSecret(): string | undefined;
12
11
  getOptions(): NotificationModuleOptions;
13
12
  }
@@ -16,6 +16,4 @@ export declare class NotificationDataSourceProvider extends MultiTenantDataSourc
16
16
  getEnableCompanyFeatureForTenant(tenant?: ITenantDatabaseConfig): boolean;
17
17
  getNotificationEntities(enableCompanyFeature?: boolean): Promise<any[]>;
18
18
  protected createDataSourceFromConfig(config: IDatabaseConfig): Promise<DataSource>;
19
- protected getSingleDataSource(): Promise<DataSource>;
20
- protected getOrCreateTenantConnection(tenant: ITenantDatabaseConfig): Promise<DataSource>;
21
19
  }
@@ -1,43 +1,26 @@
1
+ import { INotificationBulkSendOptions, INotificationSendOptions } from '@flusys/nestjs-shared';
1
2
  import { HybridCache } from '@flusys/nestjs-shared/classes';
2
3
  import { UtilsService } from '@flusys/nestjs-shared/modules';
4
+ import { NotificationBase } from '../entities';
5
+ import { NotificationGateway } from '../gateways';
3
6
  import { NotificationConfigService } from './notification-config.service';
4
7
  import { NotificationDataSourceProvider } from './notification-datasource.provider';
5
- import { NotificationGateway } from '../gateways';
6
- import { NotificationBase } from '../entities';
7
- import { NotificationType } from '@flusys/nestjs-shared/enums';
8
- export interface SendNotificationOptions {
9
- userId: string;
10
- title: string;
11
- message?: string | null;
12
- type?: NotificationType | string;
13
- data?: Record<string, unknown> | null;
14
- companyId?: string | null;
15
- }
16
- export interface SendBulkNotificationOptions {
17
- userIds: string[];
18
- title: string;
19
- message?: string | null;
20
- type?: NotificationType | string;
21
- data?: Record<string, unknown> | null;
22
- companyId?: string | null;
23
- }
24
8
  export declare class NotificationHelperService {
25
9
  private readonly cacheManager;
26
10
  private readonly utilsService;
27
11
  private readonly configService;
28
12
  private readonly dataSourceProvider;
29
13
  private readonly gateway?;
30
- private readonly entityName;
31
14
  private dataSource;
32
- constructor(cacheManager: HybridCache, utilsService: UtilsService, configService: NotificationConfigService, dataSourceProvider: NotificationDataSourceProvider, gateway?: NotificationGateway);
33
- private getDataSource;
34
- private getRepository;
35
- send(options: SendNotificationOptions): Promise<NotificationBase>;
36
- sendToMany(options: SendBulkNotificationOptions): Promise<NotificationBase[]>;
37
- sendToCompany(companyId: string, title: string, message?: string | null, type?: NotificationType | string, data?: Record<string, unknown> | null): Promise<void>;
15
+ constructor(cacheManager: HybridCache, utilsService: UtilsService, configService: NotificationConfigService, dataSourceProvider: NotificationDataSourceProvider, gateway?: NotificationGateway | undefined);
16
+ send(options: INotificationSendOptions): Promise<NotificationBase>;
17
+ sendToMany(options: INotificationBulkSendOptions): Promise<NotificationBase[]>;
38
18
  isUserOnline(userId: string): boolean;
39
19
  getOnlineUserCount(): number;
40
- private emitRealtime;
20
+ private getDataSource;
21
+ private getRepository;
22
+ private buildEntity;
23
+ private emitToUser;
41
24
  private toPayload;
42
25
  private clearCache;
43
26
  }
@@ -1,4 +1,4 @@
1
- import { HybridCache, RequestScopedApiService } from '@flusys/nestjs-shared/classes';
1
+ import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
2
2
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
3
  import { UtilsService } from '@flusys/nestjs-shared/modules';
4
4
  import { EntityTarget, QueryRunner, SelectQueryBuilder } from 'typeorm';
@@ -8,15 +8,13 @@ import { NotificationGateway } from '../gateways';
8
8
  import { INotification } from '../interfaces';
9
9
  import { NotificationConfigService } from './notification-config.service';
10
10
  import { NotificationDataSourceProvider } from './notification-datasource.provider';
11
- export declare class NotificationService extends RequestScopedApiService<CreateNotificationDto, UpdateNotificationDto, INotification, NotificationBase> {
11
+ export declare class NotificationService extends ApiService<CreateNotificationDto, UpdateNotificationDto, INotification, NotificationBase> {
12
12
  protected cacheManager: HybridCache;
13
13
  protected utilsService: UtilsService;
14
14
  private readonly notificationConfig;
15
- private readonly dataSourceProvider;
16
15
  private readonly gateway?;
17
- constructor(cacheManager: HybridCache, utilsService: UtilsService, notificationConfig: NotificationConfigService, dataSourceProvider: NotificationDataSourceProvider, gateway?: NotificationGateway);
16
+ constructor(cacheManager: HybridCache, utilsService: UtilsService, notificationConfig: NotificationConfigService, dataSourceProvider: NotificationDataSourceProvider, gateway?: NotificationGateway | undefined);
18
17
  protected resolveEntity(): EntityTarget<NotificationBase>;
19
- protected getDataSourceProvider(): NotificationDataSourceProvider;
20
18
  convertSingleDtoToEntity(dto: CreateNotificationDto | UpdateNotificationDto, user: ILoggedUserInfo | null): Promise<NotificationBase>;
21
19
  protected getFilterQuery(query: SelectQueryBuilder<NotificationBase>, filter: Record<string, unknown>, _user: ILoggedUserInfo | null): Promise<{
22
20
  query: SelectQueryBuilder<NotificationBase>;
@@ -31,5 +29,5 @@ export declare class NotificationService extends RequestScopedApiService<CreateN
31
29
  markAllAsRead(user: ILoggedUserInfo): Promise<number>;
32
30
  getUnreadCount(user: ILoggedUserInfo): Promise<number>;
33
31
  private toPayload;
34
- private emitToUserInCompanyIfRealtime;
32
+ private emitToUser;
35
33
  }