@flusys/nestjs-auth 3.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # Authentication Package Guide
2
2
 
3
3
  > **Package:** `@flusys/nestjs-auth`
4
- > **Version:** 3.0.0
4
+ > **Version:** 3.0.1
5
5
  > **Type:** Authentication system with JWT, email verification, multi-tenant, and company/branch support
6
6
 
7
7
  ## Table of Contents
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "AuthenticationService", {
9
9
  }
10
10
  });
11
11
  const _classes = require("@flusys/nestjs-shared/classes");
12
+ const _interfaces = require("@flusys/nestjs-shared/interfaces");
13
+ const _enums = require("@flusys/nestjs-shared/enums");
12
14
  const _utils = require("@flusys/nestjs-shared/utils");
13
15
  const _common = require("@nestjs/common");
14
16
  const _jwt = require("@nestjs/jwt");
@@ -19,7 +21,7 @@ const _companybranchentity = require("../entities/company-branch.entity");
19
21
  const _companyentity = require("../entities/company.entity");
20
22
  const _usercompanypermissionentity = require("../entities/user-company-permission.entity");
21
23
  const _userentity = require("../entities/user.entity");
22
- const _enums = require("../enums");
24
+ const _enums1 = require("../enums");
23
25
  const _authconfigservice = require("./auth-config.service");
24
26
  const _authdatasourceprovider = require("./auth-datasource.provider");
25
27
  const _authemailservice = require("./auth-email.service");
@@ -152,7 +154,7 @@ let AuthenticationService = class AuthenticationService {
152
154
  const companyPermissions = await permissionRepository.find({
153
155
  where: {
154
156
  userId: user.id,
155
- permissionType: _enums.PermissionType.COMPANY
157
+ permissionType: _enums1.PermissionType.COMPANY
156
158
  }
157
159
  });
158
160
  const companyRepository = await this.getCompanyRepository();
@@ -171,7 +173,7 @@ let AuthenticationService = class AuthenticationService {
171
173
  const branchPermissions = await permissionRepository.find({
172
174
  where: {
173
175
  userId: user.id,
174
- permissionType: _enums.PermissionType.BRANCH
176
+ permissionType: _enums1.PermissionType.BRANCH
175
177
  }
176
178
  });
177
179
  const branchIds = branchPermissions.map((p)=>p.targetId);
@@ -242,7 +244,7 @@ let AuthenticationService = class AuthenticationService {
242
244
  const existingPermission = await permissionRepository.findOne({
243
245
  where: {
244
246
  userId: existingUser.id,
245
- permissionType: _enums.PermissionType.COMPANY,
247
+ permissionType: _enums1.PermissionType.COMPANY,
246
248
  targetId: company.id
247
249
  }
248
250
  });
@@ -420,13 +422,13 @@ let AuthenticationService = class AuthenticationService {
420
422
  async assignUserPermissions(userId, companyId, branchId, permissionRepo) {
421
423
  await permissionRepo.save(permissionRepo.create({
422
424
  userId,
423
- permissionType: _enums.PermissionType.COMPANY,
425
+ permissionType: _enums1.PermissionType.COMPANY,
424
426
  targetId: companyId
425
427
  }));
426
428
  if (branchId) {
427
429
  await permissionRepo.save(permissionRepo.create({
428
430
  userId,
429
- permissionType: _enums.PermissionType.BRANCH,
431
+ permissionType: _enums1.PermissionType.BRANCH,
430
432
  targetId: branchId
431
433
  }));
432
434
  }
@@ -465,7 +467,7 @@ let AuthenticationService = class AuthenticationService {
465
467
  const hasCompanyAccess = await permissionRepository.findOne({
466
468
  where: {
467
469
  userId,
468
- permissionType: _enums.PermissionType.COMPANY,
470
+ permissionType: _enums1.PermissionType.COMPANY,
469
471
  targetId: companyId
470
472
  }
471
473
  });
@@ -484,7 +486,7 @@ let AuthenticationService = class AuthenticationService {
484
486
  const hasBranchAccess = await permissionRepository.findOne({
485
487
  where: {
486
488
  userId,
487
- permissionType: _enums.PermissionType.BRANCH,
489
+ permissionType: _enums1.PermissionType.BRANCH,
488
490
  targetId: branchId
489
491
  }
490
492
  });
@@ -602,7 +604,7 @@ let AuthenticationService = class AuthenticationService {
602
604
  const permissions = await permissionRepository.find({
603
605
  where: {
604
606
  userId,
605
- permissionType: _enums.PermissionType.COMPANY
607
+ permissionType: _enums1.PermissionType.COMPANY
606
608
  }
607
609
  });
608
610
  const companyIds = permissions.map((p)=>p.targetId);
@@ -623,7 +625,7 @@ let AuthenticationService = class AuthenticationService {
623
625
  const companyPermission = await permissionRepository.findOne({
624
626
  where: {
625
627
  userId,
626
- permissionType: _enums.PermissionType.COMPANY,
628
+ permissionType: _enums1.PermissionType.COMPANY,
627
629
  targetId: companyId
628
630
  }
629
631
  });
@@ -633,7 +635,7 @@ let AuthenticationService = class AuthenticationService {
633
635
  const branchPermissions = await permissionRepository.find({
634
636
  where: {
635
637
  userId,
636
- permissionType: _enums.PermissionType.BRANCH
638
+ permissionType: _enums1.PermissionType.BRANCH
637
639
  }
638
640
  });
639
641
  const branchIds = branchPermissions.map((p)=>p.targetId);
@@ -764,6 +766,7 @@ let AuthenticationService = class AuthenticationService {
764
766
  email: user.email,
765
767
  type: 'access'
766
768
  });
769
+ this.sendLoginNotification(user.id);
767
770
  return {
768
771
  accessToken,
769
772
  refreshToken,
@@ -778,6 +781,7 @@ let AuthenticationService = class AuthenticationService {
778
781
  companyId: company.id,
779
782
  branchId: branch?.id
780
783
  });
784
+ this.sendLoginNotification(user.id, company.id);
781
785
  return {
782
786
  accessToken,
783
787
  refreshToken,
@@ -786,6 +790,18 @@ let AuthenticationService = class AuthenticationService {
786
790
  branch: branch ? this.toBranchInfo(branch) : undefined
787
791
  };
788
792
  }
793
+ sendLoginNotification(userId, companyId) {
794
+ if (!this.notificationAdapter) return;
795
+ this.notificationAdapter.send({
796
+ userId,
797
+ title: 'Login successful',
798
+ message: 'You have successfully logged in to your account.',
799
+ type: _enums.NotificationType.INFO,
800
+ companyId
801
+ }).catch((error)=>{
802
+ this.logger.warn(`Failed to send login notification: ${error.message}`);
803
+ });
804
+ }
789
805
  async generateCompanySelectionResponse(user, companies, branches) {
790
806
  if (!this.sessionService) {
791
807
  throw new _common.BadRequestException('Session service not available');
@@ -820,7 +836,7 @@ let AuthenticationService = class AuthenticationService {
820
836
  };
821
837
  }
822
838
  // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
823
- constructor(jwtService, authConfig, cacheManager, dataSourceProvider, sessionService, authEmailService, userEnricher){
839
+ constructor(jwtService, authConfig, cacheManager, dataSourceProvider, sessionService, authEmailService, userEnricher, notificationAdapter){
824
840
  _define_property(this, "jwtService", void 0);
825
841
  _define_property(this, "authConfig", void 0);
826
842
  _define_property(this, "cacheManager", void 0);
@@ -828,6 +844,7 @@ let AuthenticationService = class AuthenticationService {
828
844
  _define_property(this, "sessionService", void 0);
829
845
  _define_property(this, "authEmailService", void 0);
830
846
  _define_property(this, "userEnricher", void 0);
847
+ _define_property(this, "notificationAdapter", void 0);
831
848
  _define_property(this, "logger", void 0);
832
849
  this.jwtService = jwtService;
833
850
  this.authConfig = authConfig;
@@ -836,6 +853,7 @@ let AuthenticationService = class AuthenticationService {
836
853
  this.sessionService = sessionService;
837
854
  this.authEmailService = authEmailService;
838
855
  this.userEnricher = userEnricher;
856
+ this.notificationAdapter = notificationAdapter;
839
857
  this.logger = new _common.Logger(AuthenticationService.name);
840
858
  }
841
859
  };
@@ -855,6 +873,8 @@ AuthenticationService = _ts_decorate([
855
873
  _ts_param(5, (0, _common.Inject)(_authemailservice.AuthEmailService)),
856
874
  _ts_param(6, (0, _common.Optional)()),
857
875
  _ts_param(6, (0, _common.Inject)(_config.USER_ENRICHER)),
876
+ _ts_param(7, (0, _common.Optional)()),
877
+ _ts_param(7, (0, _common.Inject)(_interfaces.NOTIFICATION_ADAPTER)),
858
878
  _ts_metadata("design:type", Function),
859
879
  _ts_metadata("design:paramtypes", [
860
880
  typeof _jwt.JwtService === "undefined" ? Object : _jwt.JwtService,
@@ -863,6 +883,7 @@ AuthenticationService = _ts_decorate([
863
883
  typeof _authdatasourceprovider.AuthDataSourceProvider === "undefined" ? Object : _authdatasourceprovider.AuthDataSourceProvider,
864
884
  typeof _companyselectionsessionservice.CompanySelectionSessionService === "undefined" ? Object : _companyselectionsessionservice.CompanySelectionSessionService,
865
885
  typeof _authemailservice.AuthEmailService === "undefined" ? Object : _authemailservice.AuthEmailService,
866
- typeof _userenricherinterface.IUserEnricher === "undefined" ? Object : _userenricherinterface.IUserEnricher
886
+ typeof _userenricherinterface.IUserEnricher === "undefined" ? Object : _userenricherinterface.IUserEnricher,
887
+ typeof _interfaces.INotificationAdapter === "undefined" ? Object : _interfaces.INotificationAdapter
867
888
  ])
868
889
  ], AuthenticationService);
@@ -26,6 +26,8 @@ function _ts_param(paramIndex, decorator) {
26
26
  };
27
27
  }
28
28
  import { HybridCache } from '@flusys/nestjs-shared/classes';
29
+ import { INotificationAdapter, NOTIFICATION_ADAPTER } from '@flusys/nestjs-shared/interfaces';
30
+ import { NotificationType } from '@flusys/nestjs-shared/enums';
29
31
  import { ErrorHandler, generateUniqueSlug } from '@flusys/nestjs-shared/utils';
30
32
  import { BadRequestException, Inject, Injectable, Logger, NotFoundException, Optional, Scope, UnauthorizedException } from '@nestjs/common';
31
33
  import { JwtService } from '@nestjs/jwt';
@@ -713,6 +715,7 @@ export class AuthenticationService {
713
715
  email: user.email,
714
716
  type: 'access'
715
717
  });
718
+ this.sendLoginNotification(user.id);
716
719
  return {
717
720
  accessToken,
718
721
  refreshToken,
@@ -727,6 +730,7 @@ export class AuthenticationService {
727
730
  companyId: company.id,
728
731
  branchId: branch?.id
729
732
  });
733
+ this.sendLoginNotification(user.id, company.id);
730
734
  return {
731
735
  accessToken,
732
736
  refreshToken,
@@ -735,6 +739,18 @@ export class AuthenticationService {
735
739
  branch: branch ? this.toBranchInfo(branch) : undefined
736
740
  };
737
741
  }
742
+ sendLoginNotification(userId, companyId) {
743
+ if (!this.notificationAdapter) return;
744
+ this.notificationAdapter.send({
745
+ userId,
746
+ title: 'Login successful',
747
+ message: 'You have successfully logged in to your account.',
748
+ type: NotificationType.INFO,
749
+ companyId
750
+ }).catch((error)=>{
751
+ this.logger.warn(`Failed to send login notification: ${error.message}`);
752
+ });
753
+ }
738
754
  async generateCompanySelectionResponse(user, companies, branches) {
739
755
  if (!this.sessionService) {
740
756
  throw new BadRequestException('Session service not available');
@@ -769,7 +785,7 @@ export class AuthenticationService {
769
785
  };
770
786
  }
771
787
  // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
772
- constructor(jwtService, authConfig, cacheManager, dataSourceProvider, sessionService, authEmailService, userEnricher){
788
+ constructor(jwtService, authConfig, cacheManager, dataSourceProvider, sessionService, authEmailService, userEnricher, notificationAdapter){
773
789
  _define_property(this, "jwtService", void 0);
774
790
  _define_property(this, "authConfig", void 0);
775
791
  _define_property(this, "cacheManager", void 0);
@@ -777,6 +793,7 @@ export class AuthenticationService {
777
793
  _define_property(this, "sessionService", void 0);
778
794
  _define_property(this, "authEmailService", void 0);
779
795
  _define_property(this, "userEnricher", void 0);
796
+ _define_property(this, "notificationAdapter", void 0);
780
797
  _define_property(this, "logger", void 0);
781
798
  this.jwtService = jwtService;
782
799
  this.authConfig = authConfig;
@@ -785,6 +802,7 @@ export class AuthenticationService {
785
802
  this.sessionService = sessionService;
786
803
  this.authEmailService = authEmailService;
787
804
  this.userEnricher = userEnricher;
805
+ this.notificationAdapter = notificationAdapter;
788
806
  this.logger = new Logger(AuthenticationService.name);
789
807
  }
790
808
  }
@@ -804,6 +822,8 @@ AuthenticationService = _ts_decorate([
804
822
  _ts_param(5, Inject(AuthEmailService)),
805
823
  _ts_param(6, Optional()),
806
824
  _ts_param(6, Inject(USER_ENRICHER)),
825
+ _ts_param(7, Optional()),
826
+ _ts_param(7, Inject(NOTIFICATION_ADAPTER)),
807
827
  _ts_metadata("design:type", Function),
808
828
  _ts_metadata("design:paramtypes", [
809
829
  typeof JwtService === "undefined" ? Object : JwtService,
@@ -812,6 +832,7 @@ AuthenticationService = _ts_decorate([
812
832
  typeof AuthDataSourceProvider === "undefined" ? Object : AuthDataSourceProvider,
813
833
  typeof CompanySelectionSessionService === "undefined" ? Object : CompanySelectionSessionService,
814
834
  typeof AuthEmailService === "undefined" ? Object : AuthEmailService,
815
- typeof IUserEnricher === "undefined" ? Object : IUserEnricher
835
+ typeof IUserEnricher === "undefined" ? Object : IUserEnricher,
836
+ typeof INotificationAdapter === "undefined" ? Object : INotificationAdapter
816
837
  ])
817
838
  ], AuthenticationService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-auth",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Authentication and authorization infrastructure for NestJS applications",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -91,7 +91,7 @@
91
91
  "typeorm": "^0.3.0"
92
92
  },
93
93
  "dependencies": {
94
- "@flusys/nestjs-core": "3.0.0",
95
- "@flusys/nestjs-shared": "3.0.0"
94
+ "@flusys/nestjs-core": "3.0.1",
95
+ "@flusys/nestjs-shared": "3.0.1"
96
96
  }
97
97
  }
@@ -1,4 +1,5 @@
1
1
  import { HybridCache } from '@flusys/nestjs-shared/classes';
2
+ import { INotificationAdapter } from '@flusys/nestjs-shared/interfaces';
2
3
  import { JwtService } from '@nestjs/jwt';
3
4
  import { IUserEnricher } from '../interfaces/user-enricher.interface';
4
5
  import { RegistrationDto } from '../dtos/authentication.dto';
@@ -18,8 +19,9 @@ export declare class AuthenticationService {
18
19
  private readonly sessionService?;
19
20
  private readonly authEmailService?;
20
21
  private readonly userEnricher?;
22
+ private readonly notificationAdapter?;
21
23
  private readonly logger;
22
- constructor(jwtService: JwtService, authConfig: AuthConfigService, cacheManager?: HybridCache, dataSourceProvider?: AuthDataSourceProvider, sessionService?: CompanySelectionSessionService, authEmailService?: AuthEmailService, userEnricher?: IUserEnricher);
24
+ constructor(jwtService: JwtService, authConfig: AuthConfigService, cacheManager?: HybridCache, dataSourceProvider?: AuthDataSourceProvider, sessionService?: CompanySelectionSessionService, authEmailService?: AuthEmailService, userEnricher?: IUserEnricher, notificationAdapter?: INotificationAdapter);
23
25
  private isCompanyFeatureEnabled;
24
26
  private isEmailVerificationEnabled;
25
27
  private getUserRepository;
@@ -62,6 +64,7 @@ export declare class AuthenticationService {
62
64
  private generateTokens;
63
65
  private generateLoginResponse;
64
66
  private generateLoginResponseWithCompany;
67
+ private sendLoginNotification;
65
68
  private generateCompanySelectionResponse;
66
69
  private generateRegistrationResponse;
67
70
  private generateRegistrationResponseWithCompany;