@flusys/nestjs-auth 9.1.1 → 9.2.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/fesm/360.js CHANGED
@@ -621,6 +621,12 @@ class JwtStrategy extends (0,passport_.PassportStrategy)(Strategy, 'jwt') {
621
621
  }), this.authConfig = authConfig, this.moduleRef = moduleRef;
622
622
  }
623
623
  async validate(_req, payload) {
624
+ if (payload.type !== 'access') {
625
+ throw new common_.UnauthorizedException({
626
+ message: 'Invalid access token',
627
+ messageKey: message_keys/* .AUTH_MESSAGES.TOKEN_INVALID */.mK.TOKEN_INVALID
628
+ });
629
+ }
624
630
  const userRepo = await this.resolveUserRepository();
625
631
  await this.checkTokenRevocation(payload);
626
632
  const user = await userRepo.findOne({
@@ -664,12 +670,12 @@ class JwtStrategy extends (0,passport_.PassportStrategy)(Strategy, 'jwt') {
664
670
  });
665
671
  }
666
672
  async checkTokenRevocation(payload) {
667
- if (!payload.iat) return;
673
+ if (!payload.iat && typeof payload.iatMs !== 'number') return;
668
674
  try {
669
675
  const authService = await this.moduleRef.resolve(authentication_service/* .AuthenticationService */.k, undefined, {
670
676
  strict: false
671
677
  });
672
- if (authService && await authService.isTokenRevoked(payload.id, payload.iat)) {
678
+ if (authService && await authService.isTokenRevoked(payload.id, payload.iat, payload.iatMs)) {
673
679
  throw new common_.UnauthorizedException({
674
680
  message: 'Token has been revoked',
675
681
  messageKey: message_keys/* .AUTH_MESSAGES.TOKEN_REVOKED */.mK.TOKEN_REVOKED
package/fesm/370.js CHANGED
@@ -174,6 +174,7 @@ _ts_decorate([
174
174
  description: 'Additional fields for profile extension (handled by USER_ENRICHER)'
175
175
  }),
176
176
  (0,class_validator__rspack_import_1.IsOptional)(),
177
+ (0,class_validator__rspack_import_1.IsObject)(),
177
178
  _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
178
179
  ], RegistrationDto.prototype, "additionalFields", void 0);
179
180
  class RefreshTokenDto {
@@ -88,16 +88,18 @@ __webpack_require__.d(__webpack_exports__, {
88
88
 
89
89
 
90
90
  },
91
- 334(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
91
+ 5634(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
92
92
 
93
93
  // EXPORTS
94
94
  __webpack_require__.d(__webpack_exports__, {
95
- Vg: () => (/* reexport */ generateAccessToken),
96
- e: () => (/* reexport */ generateTokens),
95
+ Vg: () => (/* reexport */ token_helper/* .generateAccessToken */.Vg),
96
+ e: () => (/* reexport */ token_helper/* .generateTokens */.e),
97
+ PV: () => (/* reexport */ token_helper/* .getSessionsRevokedAtMs */.PV),
98
+ lL: () => (/* reexport */ token_helper/* .isIssuedBeforeRevocation */.lL),
97
99
  vR: () => (/* reexport */ branch_ancestry_helper/* .loadCompanyBranchNodes */.v),
98
100
  xu: () => (/* reexport */ branch_ancestry_helper/* .loadDisplayParentIds */.x),
99
- om: () => (/* reexport */ parseExpiryToMs),
100
- XP: () => (/* reexport */ revokeUserSessions),
101
+ om: () => (/* reexport */ token_helper/* .parseExpiryToMs */.om),
102
+ XP: () => (/* reexport */ token_helper/* .revokeUserSessions */.XP),
101
103
  QH: () => (/* reexport */ toBranchInfo),
102
104
  $C: () => (/* reexport */ toCompanyInfo),
103
105
  FV: () => (/* reexport */ toUserInfo)
@@ -132,14 +134,23 @@ function toBranchInfo(branch) {
132
134
 
133
135
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/branch-ancestry.helper.ts
134
136
  var branch_ancestry_helper = __webpack_require__(7526);
135
- // EXTERNAL MODULE: ./projects/nestjs-auth/src/config/auth.constants.ts
136
- var auth_constants = __webpack_require__(5588);
137
- ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/token.helper.ts
137
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/token.helper.ts
138
+ var token_helper = __webpack_require__(1379);
139
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/index.ts
140
+
141
+
142
+
143
+
138
144
 
139
- function generateAccessToken(jwtService, authConfig, payload) {
145
+ },
146
+ 1379(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
147
+ /* import */ var _config_auth_constants_js__rspack_import_0 = __webpack_require__(5588);
148
+
149
+ function generateAccessToken(jwtService, authConfig, payload, issuedAtMs = Date.now()) {
140
150
  return jwtService.sign({
141
151
  ...payload,
142
- type: 'access'
152
+ type: 'access',
153
+ iatMs: issuedAtMs
143
154
  }, {
144
155
  secret: authConfig.getJwtSecret(),
145
156
  expiresIn: authConfig.getJwtExpiration(),
@@ -147,10 +158,12 @@ function generateAccessToken(jwtService, authConfig, payload) {
147
158
  });
148
159
  }
149
160
  function generateTokens(jwtService, authConfig, payload) {
150
- const accessToken = generateAccessToken(jwtService, authConfig, payload);
161
+ const issuedAtMs = Date.now();
162
+ const accessToken = generateAccessToken(jwtService, authConfig, payload, issuedAtMs);
151
163
  const refreshToken = jwtService.sign({
152
164
  ...payload,
153
- type: 'refresh'
165
+ type: 'refresh',
166
+ iatMs: issuedAtMs
154
167
  }, {
155
168
  secret: authConfig.getRefreshTokenSecret(),
156
169
  expiresIn: authConfig.getRefreshTokenExpiration(),
@@ -179,15 +192,41 @@ function parseExpiryToMs(expiry) {
179
192
  return 7 * 24 * 60 * 60 * 1000;
180
193
  }
181
194
  }
195
+ // Markers written before millisecond precision hold epoch seconds
196
+ const LEGACY_SECONDS_LIMIT = 1e11;
197
+ function revocationKey(userId) {
198
+ return `${_config_auth_constants_js__rspack_import_0/* .TOKEN_REVOKED_PREFIX */.EV}:${userId}`;
199
+ }
200
+ /**
201
+ * When the user's sessions were last revoked, in epoch ms. Read past the in-process cache layer:
202
+ * the marker changes in place, and another instance's L1 copy would hold an older value.
203
+ */ async function getSessionsRevokedAtMs(cache, userId) {
204
+ const revokedAt = await cache.get(revocationKey(userId), {
205
+ skipMemory: true
206
+ });
207
+ if (!revokedAt) return undefined;
208
+ return revokedAt < LEGACY_SECONDS_LIMIT ? revokedAt * 1000 : revokedAt;
209
+ }
210
+ /** True when a token or session issued at `issuedAtMs` predates the user's last revocation */ async function isIssuedBeforeRevocation(cache, userId, issuedAtMs) {
211
+ const revokedAtMs = await getSessionsRevokedAtMs(cache, userId);
212
+ return revokedAtMs !== undefined && issuedAtMs < revokedAtMs;
213
+ }
182
214
  /** Rejects every token the user holds that was issued before now: checked on refresh and, by JwtStrategy, on every request. */ async function revokeUserSessions(cache, authConfig, userId) {
183
- const revokedAt = Math.floor(Date.now() / 1000);
184
- await cache.set(`${auth_constants/* .TOKEN_REVOKED_PREFIX */.EV}:${userId}`, revokedAt, parseExpiryToMs(authConfig.getRefreshTokenExpiration()));
215
+ // Never move the marker back (an instance whose clock lags would otherwise un-revoke tokens)
216
+ const revokedAtMs = Math.max(Date.now(), await getSessionsRevokedAtMs(cache, userId) ?? 0);
217
+ await cache.set(revocationKey(userId), revokedAtMs, parseExpiryToMs(authConfig.getRefreshTokenExpiration()), {
218
+ skipMemory: true
219
+ });
185
220
  }
186
221
 
187
- ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/index.ts
188
-
189
-
190
-
222
+ __webpack_require__.d(__webpack_exports__, {
223
+ PV: () => (getSessionsRevokedAtMs),
224
+ Vg: () => (generateAccessToken),
225
+ XP: () => (revokeUserSessions),
226
+ e: () => (generateTokens),
227
+ lL: () => (isIssuedBeforeRevocation),
228
+ om: () => (parseExpiryToMs)
229
+ });
191
230
 
192
231
 
193
232
  },
@@ -215,8 +254,10 @@ import { __webpack_require__ } from '../runtime.js';
215
254
  var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
216
255
  import * as __rspack_chunk_1 from './index.js';
217
256
  __webpack_require__.C(__rspack_chunk_1);
218
- var __webpack_exports__ = __webpack_exec__(334);var __webpack_exports__generateAccessToken = __webpack_exports__.Vg;
257
+ var __webpack_exports__ = __webpack_exec__(5634);var __webpack_exports__generateAccessToken = __webpack_exports__.Vg;
219
258
  var __webpack_exports__generateTokens = __webpack_exports__.e;
259
+ var __webpack_exports__getSessionsRevokedAtMs = __webpack_exports__.PV;
260
+ var __webpack_exports__isIssuedBeforeRevocation = __webpack_exports__.lL;
220
261
  var __webpack_exports__loadCompanyBranchNodes = __webpack_exports__.vR;
221
262
  var __webpack_exports__loadDisplayParentIds = __webpack_exports__.xu;
222
263
  var __webpack_exports__parseExpiryToMs = __webpack_exports__.om;
@@ -224,4 +265,4 @@ var __webpack_exports__revokeUserSessions = __webpack_exports__.XP;
224
265
  var __webpack_exports__toBranchInfo = __webpack_exports__.QH;
225
266
  var __webpack_exports__toCompanyInfo = __webpack_exports__.$C;
226
267
  var __webpack_exports__toUserInfo = __webpack_exports__.FV;
227
- export { __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__loadCompanyBranchNodes as loadCompanyBranchNodes, __webpack_exports__loadDisplayParentIds as loadDisplayParentIds, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__revokeUserSessions as revokeUserSessions, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
268
+ export { __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__getSessionsRevokedAtMs as getSessionsRevokedAtMs, __webpack_exports__isIssuedBeforeRevocation as isIssuedBeforeRevocation, __webpack_exports__loadCompanyBranchNodes as loadCompanyBranchNodes, __webpack_exports__loadDisplayParentIds as loadDisplayParentIds, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__revokeUserSessions as revokeUserSessions, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
package/fesm/index.js CHANGED
@@ -707,7 +707,9 @@ __webpack_require__.d(__webpack_exports__, {
707
707
  Vg: () => (/* reexport */ helpers/* .generateAccessToken */.Vg),
708
708
  e: () => (/* reexport */ helpers/* .generateTokens */.e),
709
709
  QB: () => (/* reexport */ entities.getAuthEntitiesByConfig),
710
+ PV: () => (/* reexport */ helpers/* .getSessionsRevokedAtMs */.PV),
710
711
  V8: () => (/* reexport */ social_provider_registry/* .getSocialProvider */.V),
712
+ lL: () => (/* reexport */ helpers/* .isIssuedBeforeRevocation */.lL),
711
713
  vR: () => (/* reexport */ helpers/* .loadCompanyBranchNodes */.vR),
712
714
  xu: () => (/* reexport */ helpers/* .loadDisplayParentIds */.xu),
713
715
  om: () => (/* reexport */ helpers/* .parseExpiryToMs */.om),
@@ -729,8 +731,8 @@ var dtos = __webpack_require__(9029);
729
731
  var entities = __webpack_require__(5180);
730
732
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/enums/index.ts
731
733
  var enums = __webpack_require__(8351);
732
- // EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/index.ts + 2 modules
733
- var helpers = __webpack_require__(334);
734
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/index.ts + 1 modules
735
+ var helpers = __webpack_require__(5634);
734
736
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/interceptors/index.ts
735
737
  var interceptors = __webpack_require__(1867);
736
738
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/interfaces/index.ts
@@ -923,7 +925,9 @@ var __webpack_exports__authSwaggerConfig = __webpack_exports__.aL;
923
925
  var __webpack_exports__generateAccessToken = __webpack_exports__.Vg;
924
926
  var __webpack_exports__generateTokens = __webpack_exports__.e;
925
927
  var __webpack_exports__getAuthEntitiesByConfig = __webpack_exports__.QB;
928
+ var __webpack_exports__getSessionsRevokedAtMs = __webpack_exports__.PV;
926
929
  var __webpack_exports__getSocialProvider = __webpack_exports__.V8;
930
+ var __webpack_exports__isIssuedBeforeRevocation = __webpack_exports__.lL;
927
931
  var __webpack_exports__loadCompanyBranchNodes = __webpack_exports__.vR;
928
932
  var __webpack_exports__loadDisplayParentIds = __webpack_exports__.xu;
929
933
  var __webpack_exports__parseExpiryToMs = __webpack_exports__.om;
@@ -931,4 +935,4 @@ var __webpack_exports__revokeUserSessions = __webpack_exports__.XP;
931
935
  var __webpack_exports__toBranchInfo = __webpack_exports__.QH;
932
936
  var __webpack_exports__toCompanyInfo = __webpack_exports__.$C;
933
937
  var __webpack_exports__toUserInfo = __webpack_exports__.FV;
934
- export { __webpack_exports__AUTH_EMAIL_PROVIDER as AUTH_EMAIL_PROVIDER, __webpack_exports__AUTH_EVENT_ACTIONS as AUTH_EVENT_ACTIONS, __webpack_exports__AUTH_EVENT_ENTITIES as AUTH_EVENT_ENTITIES, __webpack_exports__AUTH_EVENT_MODULE as AUTH_EVENT_MODULE, __webpack_exports__AUTH_MESSAGES as AUTH_MESSAGES, __webpack_exports__AUTH_MODULE_OPTIONS as AUTH_MODULE_OPTIONS, __webpack_exports__AppUser as AppUser, __webpack_exports__AssignUserBranchDto as AssignUserBranchDto, __webpack_exports__AssignUserCompanyDto as AssignUserCompanyDto, __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthModule as AuthModule, __webpack_exports__AuthenticationController as AuthenticationController, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BCRYPT_SALT_ROUNDS as BCRYPT_SALT_ROUNDS, __webpack_exports__BRANCH_MESSAGES as BRANCH_MESSAGES, __webpack_exports__BranchController as BranchController, __webpack_exports__BranchHierarchyResolverAdapter as BranchHierarchyResolverAdapter, __webpack_exports__BranchInfoDto as BranchInfoDto, __webpack_exports__BranchPermittedUserDto as BranchPermittedUserDto, __webpack_exports__BranchPermittedUsersResponseDto as BranchPermittedUsersResponseDto, __webpack_exports__BranchSelectionInfoDto as BranchSelectionInfoDto, __webpack_exports__BranchService as BranchService, __webpack_exports__COMPANY_MESSAGES as COMPANY_MESSAGES, __webpack_exports__ChangePasswordDto as ChangePasswordDto, __webpack_exports__ClearToken as ClearToken, __webpack_exports__Company as Company, __webpack_exports__CompanyAccessResolverAdapter as CompanyAccessResolverAdapter, __webpack_exports__CompanyBranch as CompanyBranch, __webpack_exports__CompanyBranchResponseDto as CompanyBranchResponseDto, __webpack_exports__CompanyController as CompanyController, __webpack_exports__CompanyInfoDto as CompanyInfoDto, __webpack_exports__CompanyPermittedUserDto as CompanyPermittedUserDto, __webpack_exports__CompanyPermittedUsersResponseDto as CompanyPermittedUsersResponseDto, __webpack_exports__CompanyResponseDto as CompanyResponseDto, __webpack_exports__CompanySelectionController as CompanySelectionController, __webpack_exports__CompanySelectionResponseDto as CompanySelectionResponseDto, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__CompanyWithBranchesDto as CompanyWithBranchesDto, __webpack_exports__CreateCompanyBranchDto as CreateCompanyBranchDto, __webpack_exports__CreateCompanyDto as CreateCompanyDto, __webpack_exports__CreateSocialAuthConfigDto as CreateSocialAuthConfigDto, __webpack_exports__CreateUserDto as CreateUserDto, __webpack_exports__DEFAULT_COOKIE_NAME as DEFAULT_COOKIE_NAME, __webpack_exports__EMAIL_VERIFICATION_MESSAGES as EMAIL_VERIFICATION_MESSAGES, __webpack_exports__EmailVerificationController as EmailVerificationController, __webpack_exports__ForgotPasswordDto as ForgotPasswordDto, __webpack_exports__GetBranchUsersDto as GetBranchUsersDto, __webpack_exports__GetCompanyUsersDto as GetCompanyUsersDto, __webpack_exports__JwtStrategy as JwtStrategy, __webpack_exports__LoginDto as LoginDto, __webpack_exports__LoginResponseDto as LoginResponseDto, __webpack_exports__LoginResponseRequiresEmailVerificationDto as LoginResponseRequiresEmailVerificationDto, __webpack_exports__MAX_COOKIE_BYTES as MAX_COOKIE_BYTES, __webpack_exports__MeResponseDto as MeResponseDto, __webpack_exports__PendingRegistration as PendingRegistration, __webpack_exports__PermissionItemDto as PermissionItemDto, __webpack_exports__PermissionType as PermissionType, __webpack_exports__RefreshTokenDto as RefreshTokenDto, __webpack_exports__RegistrationDto as RegistrationDto, __webpack_exports__RegistrationResponseDto as RegistrationResponseDto, __webpack_exports__ResendVerificationDto as ResendVerificationDto, __webpack_exports__ResetPasswordDto as ResetPasswordDto, __webpack_exports__SESSION_CACHE_PREFIX as SESSION_CACHE_PREFIX, __webpack_exports__SOCIAL_AUTH_CONFIG_MESSAGES as SOCIAL_AUTH_CONFIG_MESSAGES, __webpack_exports__SOCIAL_AUTH_MESSAGES as SOCIAL_AUTH_MESSAGES, __webpack_exports__SOCIAL_STATE_PREFIX as SOCIAL_STATE_PREFIX, __webpack_exports__SOCIAL_STATE_TTL_MS as SOCIAL_STATE_TTL_MS, __webpack_exports__SelectDto as SelectDto, __webpack_exports__SetToken as SetToken, __webpack_exports__SocialAuthConfig as SocialAuthConfig, __webpack_exports__SocialAuthConfigController as SocialAuthConfigController, __webpack_exports__SocialAuthConfigResponseDto as SocialAuthConfigResponseDto, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthController as SocialAuthController, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__SocialAuthorizeDto as SocialAuthorizeDto, __webpack_exports__SocialAuthorizeResponseDto as SocialAuthorizeResponseDto, __webpack_exports__SocialCallbackDto as SocialCallbackDto, __webpack_exports__SocialProviderInfoDto as SocialProviderInfoDto, __webpack_exports__SocialProviderTypeEnum as SocialProviderTypeEnum, __webpack_exports__SocialProvidersDto as SocialProvidersDto, __webpack_exports__SwitchCompanyDto as SwitchCompanyDto, __webpack_exports__TOKEN_REVOKED_PREFIX as TOKEN_REVOKED_PREFIX, __webpack_exports__TokenType as TokenType, __webpack_exports__USER_ENRICHER as USER_ENRICHER, __webpack_exports__USER_MESSAGES as USER_MESSAGES, __webpack_exports__USER_PERMISSION_MESSAGES as USER_PERMISSION_MESSAGES, __webpack_exports__UpdateCompanyBranchDto as UpdateCompanyBranchDto, __webpack_exports__UpdateCompanyDto as UpdateCompanyDto, __webpack_exports__UpdateSocialAuthConfigDto as UpdateSocialAuthConfigDto, __webpack_exports__UpdateUserDto as UpdateUserDto, __webpack_exports__UserBranchPermissionDto as UserBranchPermissionDto, __webpack_exports__UserBranchesResponseDto as UserBranchesResponseDto, __webpack_exports__UserCompaniesResponseDto as UserCompaniesResponseDto, __webpack_exports__UserCompanyPermission as UserCompanyPermission, __webpack_exports__UserCompanyPermissionDto as UserCompanyPermissionDto, __webpack_exports__UserController as UserController, __webpack_exports__UserInfoDto as UserInfoDto, __webpack_exports__UserLookupResponseDto as UserLookupResponseDto, __webpack_exports__UserPermissionController as UserPermissionController, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserResponseDto as UserResponseDto, __webpack_exports__UserService as UserService, __webpack_exports__UserToken as UserToken, __webpack_exports__VerifyEmailDto as VerifyEmailDto, __webpack_exports__authSwaggerConfig as authSwaggerConfig, __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__getAuthEntitiesByConfig as getAuthEntitiesByConfig, __webpack_exports__getSocialProvider as getSocialProvider, __webpack_exports__loadCompanyBranchNodes as loadCompanyBranchNodes, __webpack_exports__loadDisplayParentIds as loadDisplayParentIds, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__revokeUserSessions as revokeUserSessions, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
938
+ export { __webpack_exports__AUTH_EMAIL_PROVIDER as AUTH_EMAIL_PROVIDER, __webpack_exports__AUTH_EVENT_ACTIONS as AUTH_EVENT_ACTIONS, __webpack_exports__AUTH_EVENT_ENTITIES as AUTH_EVENT_ENTITIES, __webpack_exports__AUTH_EVENT_MODULE as AUTH_EVENT_MODULE, __webpack_exports__AUTH_MESSAGES as AUTH_MESSAGES, __webpack_exports__AUTH_MODULE_OPTIONS as AUTH_MODULE_OPTIONS, __webpack_exports__AppUser as AppUser, __webpack_exports__AssignUserBranchDto as AssignUserBranchDto, __webpack_exports__AssignUserCompanyDto as AssignUserCompanyDto, __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthModule as AuthModule, __webpack_exports__AuthenticationController as AuthenticationController, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BCRYPT_SALT_ROUNDS as BCRYPT_SALT_ROUNDS, __webpack_exports__BRANCH_MESSAGES as BRANCH_MESSAGES, __webpack_exports__BranchController as BranchController, __webpack_exports__BranchHierarchyResolverAdapter as BranchHierarchyResolverAdapter, __webpack_exports__BranchInfoDto as BranchInfoDto, __webpack_exports__BranchPermittedUserDto as BranchPermittedUserDto, __webpack_exports__BranchPermittedUsersResponseDto as BranchPermittedUsersResponseDto, __webpack_exports__BranchSelectionInfoDto as BranchSelectionInfoDto, __webpack_exports__BranchService as BranchService, __webpack_exports__COMPANY_MESSAGES as COMPANY_MESSAGES, __webpack_exports__ChangePasswordDto as ChangePasswordDto, __webpack_exports__ClearToken as ClearToken, __webpack_exports__Company as Company, __webpack_exports__CompanyAccessResolverAdapter as CompanyAccessResolverAdapter, __webpack_exports__CompanyBranch as CompanyBranch, __webpack_exports__CompanyBranchResponseDto as CompanyBranchResponseDto, __webpack_exports__CompanyController as CompanyController, __webpack_exports__CompanyInfoDto as CompanyInfoDto, __webpack_exports__CompanyPermittedUserDto as CompanyPermittedUserDto, __webpack_exports__CompanyPermittedUsersResponseDto as CompanyPermittedUsersResponseDto, __webpack_exports__CompanyResponseDto as CompanyResponseDto, __webpack_exports__CompanySelectionController as CompanySelectionController, __webpack_exports__CompanySelectionResponseDto as CompanySelectionResponseDto, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__CompanyWithBranchesDto as CompanyWithBranchesDto, __webpack_exports__CreateCompanyBranchDto as CreateCompanyBranchDto, __webpack_exports__CreateCompanyDto as CreateCompanyDto, __webpack_exports__CreateSocialAuthConfigDto as CreateSocialAuthConfigDto, __webpack_exports__CreateUserDto as CreateUserDto, __webpack_exports__DEFAULT_COOKIE_NAME as DEFAULT_COOKIE_NAME, __webpack_exports__EMAIL_VERIFICATION_MESSAGES as EMAIL_VERIFICATION_MESSAGES, __webpack_exports__EmailVerificationController as EmailVerificationController, __webpack_exports__ForgotPasswordDto as ForgotPasswordDto, __webpack_exports__GetBranchUsersDto as GetBranchUsersDto, __webpack_exports__GetCompanyUsersDto as GetCompanyUsersDto, __webpack_exports__JwtStrategy as JwtStrategy, __webpack_exports__LoginDto as LoginDto, __webpack_exports__LoginResponseDto as LoginResponseDto, __webpack_exports__LoginResponseRequiresEmailVerificationDto as LoginResponseRequiresEmailVerificationDto, __webpack_exports__MAX_COOKIE_BYTES as MAX_COOKIE_BYTES, __webpack_exports__MeResponseDto as MeResponseDto, __webpack_exports__PendingRegistration as PendingRegistration, __webpack_exports__PermissionItemDto as PermissionItemDto, __webpack_exports__PermissionType as PermissionType, __webpack_exports__RefreshTokenDto as RefreshTokenDto, __webpack_exports__RegistrationDto as RegistrationDto, __webpack_exports__RegistrationResponseDto as RegistrationResponseDto, __webpack_exports__ResendVerificationDto as ResendVerificationDto, __webpack_exports__ResetPasswordDto as ResetPasswordDto, __webpack_exports__SESSION_CACHE_PREFIX as SESSION_CACHE_PREFIX, __webpack_exports__SOCIAL_AUTH_CONFIG_MESSAGES as SOCIAL_AUTH_CONFIG_MESSAGES, __webpack_exports__SOCIAL_AUTH_MESSAGES as SOCIAL_AUTH_MESSAGES, __webpack_exports__SOCIAL_STATE_PREFIX as SOCIAL_STATE_PREFIX, __webpack_exports__SOCIAL_STATE_TTL_MS as SOCIAL_STATE_TTL_MS, __webpack_exports__SelectDto as SelectDto, __webpack_exports__SetToken as SetToken, __webpack_exports__SocialAuthConfig as SocialAuthConfig, __webpack_exports__SocialAuthConfigController as SocialAuthConfigController, __webpack_exports__SocialAuthConfigResponseDto as SocialAuthConfigResponseDto, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthController as SocialAuthController, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__SocialAuthorizeDto as SocialAuthorizeDto, __webpack_exports__SocialAuthorizeResponseDto as SocialAuthorizeResponseDto, __webpack_exports__SocialCallbackDto as SocialCallbackDto, __webpack_exports__SocialProviderInfoDto as SocialProviderInfoDto, __webpack_exports__SocialProviderTypeEnum as SocialProviderTypeEnum, __webpack_exports__SocialProvidersDto as SocialProvidersDto, __webpack_exports__SwitchCompanyDto as SwitchCompanyDto, __webpack_exports__TOKEN_REVOKED_PREFIX as TOKEN_REVOKED_PREFIX, __webpack_exports__TokenType as TokenType, __webpack_exports__USER_ENRICHER as USER_ENRICHER, __webpack_exports__USER_MESSAGES as USER_MESSAGES, __webpack_exports__USER_PERMISSION_MESSAGES as USER_PERMISSION_MESSAGES, __webpack_exports__UpdateCompanyBranchDto as UpdateCompanyBranchDto, __webpack_exports__UpdateCompanyDto as UpdateCompanyDto, __webpack_exports__UpdateSocialAuthConfigDto as UpdateSocialAuthConfigDto, __webpack_exports__UpdateUserDto as UpdateUserDto, __webpack_exports__UserBranchPermissionDto as UserBranchPermissionDto, __webpack_exports__UserBranchesResponseDto as UserBranchesResponseDto, __webpack_exports__UserCompaniesResponseDto as UserCompaniesResponseDto, __webpack_exports__UserCompanyPermission as UserCompanyPermission, __webpack_exports__UserCompanyPermissionDto as UserCompanyPermissionDto, __webpack_exports__UserController as UserController, __webpack_exports__UserInfoDto as UserInfoDto, __webpack_exports__UserLookupResponseDto as UserLookupResponseDto, __webpack_exports__UserPermissionController as UserPermissionController, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserResponseDto as UserResponseDto, __webpack_exports__UserService as UserService, __webpack_exports__UserToken as UserToken, __webpack_exports__VerifyEmailDto as VerifyEmailDto, __webpack_exports__authSwaggerConfig as authSwaggerConfig, __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__getAuthEntitiesByConfig as getAuthEntitiesByConfig, __webpack_exports__getSessionsRevokedAtMs as getSessionsRevokedAtMs, __webpack_exports__getSocialProvider as getSocialProvider, __webpack_exports__isIssuedBeforeRevocation as isIssuedBeforeRevocation, __webpack_exports__loadCompanyBranchNodes as loadCompanyBranchNodes, __webpack_exports__loadDisplayParentIds as loadDisplayParentIds, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__revokeUserSessions as revokeUserSessions, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
@@ -216,6 +216,7 @@ class ClearToken {
216
216
  ClearToken = _ts_decorate([
217
217
  (0,_nestjs_common__rspack_import_1.Injectable)(),
218
218
  _ts_param(0, (0,_nestjs_common__rspack_import_1.Optional)()),
219
+ _ts_param(0, (0,_nestjs_common__rspack_import_1.Inject)(_services_auth_config_service_js__rspack_import_3/* .AuthConfigService */.W)),
219
220
  _ts_metadata("design:type", Function),
220
221
  _ts_metadata("design:paramtypes", [
221
222
  typeof _services_auth_config_service_js__rspack_import_3/* .AuthConfigService */.W === "undefined" ? Object : _services_auth_config_service_js__rspack_import_3/* .AuthConfigService */.W
@@ -0,0 +1,3 @@
1
+ import { type HybridCache } from '@flusys/nestjs-shared/classes';
2
+ import { cacheTenantId } from '@flusys/nestjs-shared/utils';
3
+ export declare function invalidateEntityCaches(cache: HybridCache | undefined, dataSourceProvider: Parameters<typeof cacheTenantId>[0], entityNames: string[]): Promise<void>;
@@ -2,10 +2,12 @@ import { type HybridCache } from '@flusys/nestjs-shared/classes';
2
2
  import { JwtService } from '@nestjs/jwt';
3
3
  import { type TokenPayload, type TokenPayloadWithCompany } from '../interfaces/authentication.interface.js';
4
4
  import { AuthConfigService } from '../services/auth-config.service.js';
5
- export declare function generateAccessToken(jwtService: JwtService, authConfig: AuthConfigService, payload: TokenPayload | TokenPayloadWithCompany): string;
5
+ export declare function generateAccessToken(jwtService: JwtService, authConfig: AuthConfigService, payload: TokenPayload | TokenPayloadWithCompany, issuedAtMs?: number): string;
6
6
  export declare function generateTokens(jwtService: JwtService, authConfig: AuthConfigService, payload: TokenPayload | TokenPayloadWithCompany): {
7
7
  accessToken: string;
8
8
  refreshToken: string;
9
9
  };
10
10
  export declare function parseExpiryToMs(expiry: string): number;
11
- export declare function revokeUserSessions(cache: Pick<HybridCache, 'set'>, authConfig: Pick<AuthConfigService, 'getRefreshTokenExpiration'>, userId: string): Promise<void>;
11
+ export declare function getSessionsRevokedAtMs(cache: Pick<HybridCache, 'get'>, userId: string): Promise<number | undefined>;
12
+ export declare function isIssuedBeforeRevocation(cache: Pick<HybridCache, 'get'>, userId: string, issuedAtMs: number): Promise<boolean>;
13
+ export declare function revokeUserSessions(cache: Pick<HybridCache, 'get' | 'set'>, authConfig: Pick<AuthConfigService, 'getRefreshTokenExpiration'>, userId: string): Promise<void>;
@@ -8,6 +8,7 @@ export interface TokenPayload {
8
8
  profilePictureId?: string;
9
9
  tenantId?: string;
10
10
  iat?: number;
11
+ iatMs?: number;
11
12
  exp?: number;
12
13
  }
13
14
  export interface TokenPayloadWithCompany extends TokenPayload {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-auth",
3
- "version": "9.1.1",
3
+ "version": "9.2.0",
4
4
  "description": "Authentication and authorization infrastructure for NestJS applications",
5
5
  "type": "module",
6
6
  "main": "./fesm/index.js",
@@ -92,7 +92,7 @@
92
92
  "rxjs": "^7.8.0"
93
93
  },
94
94
  "dependencies": {
95
- "@flusys/nestjs-core": "9.1.1",
96
- "@flusys/nestjs-shared": "9.1.1"
95
+ "@flusys/nestjs-core": "9.2.0",
96
+ "@flusys/nestjs-shared": "9.2.0"
97
97
  }
98
98
  }
@@ -1,12 +1,17 @@
1
+ import { HybridCache } from '@flusys/nestjs-shared/classes';
1
2
  import { PendingRegistration } from '../entities/pending-registration.entity.js';
2
3
  import { type IAuthEmailProvider } from '../interfaces/index.js';
4
+ import { AuthConfigService } from './auth-config.service.js';
3
5
  import { AuthDataSourceProvider } from './auth-datasource.provider.js';
4
6
  export declare class AuthEmailService {
5
7
  private readonly dataSourceProvider?;
6
8
  private readonly emailProvider?;
9
+ private readonly cacheManager?;
10
+ private readonly authConfig?;
7
11
  private readonly PASSWORD_RESET_EXPIRY;
8
12
  private readonly EMAIL_VERIFICATION_EXPIRY;
9
- constructor(dataSourceProvider?: AuthDataSourceProvider | undefined, emailProvider?: IAuthEmailProvider | undefined);
13
+ private readonly logger;
14
+ constructor(dataSourceProvider?: AuthDataSourceProvider | undefined, emailProvider?: IAuthEmailProvider | undefined, cacheManager?: HybridCache | undefined, authConfig?: AuthConfigService | undefined);
10
15
  isEmailEnabled(): boolean;
11
16
  private getRepository;
12
17
  private generateToken;
@@ -14,7 +19,7 @@ export declare class AuthEmailService {
14
19
  private assertEmailEnabled;
15
20
  private sendVerificationEmailSafe;
16
21
  private validateTokenNotExpiredOrUsed;
17
- hasPendingRegistration(email: string): Promise<boolean>;
22
+ hasPendingRegistration(email: string, password?: string): Promise<boolean>;
18
23
  createPendingRegistration(data: {
19
24
  email: string;
20
25
  name?: string;
@@ -27,6 +27,7 @@ export declare class AuthenticationService {
27
27
  private isSignUpEnabled;
28
28
  private getUserRepository;
29
29
  private getCompanyScopedRepository;
30
+ private invalidateCaches;
30
31
  login(email: string, password: string): Promise<LoginResponse | LoginResponseRequiresSelection | LoginResponseRequiresEmailVerification>;
31
32
  issueLoginForUser(user: AppUser): Promise<LoginResponse | LoginResponseRequiresSelection>;
32
33
  private ensureUserActive;
@@ -50,7 +51,8 @@ export declare class AuthenticationService {
50
51
  }>;
51
52
  changePassword(userId: string, currentPassword: string, newPassword: string): Promise<void>;
52
53
  logout(userId: string): Promise<void>;
53
- isTokenRevoked(userId: string, tokenIssuedAt?: number): Promise<boolean>;
54
+ isTokenRevoked(userId: string, tokenIssuedAt?: number, tokenIssuedAtMs?: number): Promise<boolean>;
55
+ private isRevokedSince;
54
56
  getUserCompanies(userId: string): Promise<Company[]>;
55
57
  getUserBranches(userId: string, companyId: string): Promise<Array<CompanyBranch & {
56
58
  displayParentId: string | null;
@@ -19,6 +19,7 @@ export declare class BranchService extends ApiService<CreateCompanyBranchDto, Up
19
19
  protected beforeUpdateOperation(dto: UpdateCompanyBranchDto | UpdateCompanyBranchDto[], _user: ILoggedUserInfo | null, queryRunner: QueryRunner): Promise<void>;
20
20
  private validateParent;
21
21
  protected beforeDeleteOperation(dto: DeleteDto, user: ILoggedUserInfo | null, queryRunner: QueryRunner): Promise<void>;
22
+ delete(option: DeleteDto, user: ILoggedUserInfo | null): Promise<null>;
22
23
  getDescendantIds(branchIds: string | string[], options?: IBranchHierarchyOptions): Promise<string[]>;
23
24
  getAncestorIds(branchId: string, options?: IBranchHierarchyOptions): Promise<string[]>;
24
25
  isWithinBranch(branchId: string, ancestorId: string): Promise<boolean>;
@@ -2,16 +2,17 @@ import { HybridCache } from '@flusys/nestjs-shared/classes';
2
2
  interface StoredSession {
3
3
  sessionId: string;
4
4
  userId: string;
5
- createdAt: Date;
6
- expiresAt: Date;
5
+ createdAt: number;
6
+ expiresAt: number;
7
7
  }
8
8
  export declare class CompanySelectionSessionService {
9
9
  protected cacheManager: HybridCache;
10
10
  constructor(cacheManager: HybridCache);
11
- createSession(userId: string): Promise<string>;
12
- getSession(sessionId: string): Promise<StoredSession | null>;
13
- consumeSession(sessionId: string): Promise<StoredSession | null>;
14
- deleteSession(sessionId: string): Promise<void>;
11
+ createSession(userId: string, tenantId?: string): Promise<string>;
12
+ getSession(sessionId: string, tenantId?: string): Promise<StoredSession | null>;
13
+ consumeSession(sessionId: string, tenantId?: string): Promise<StoredSession | null>;
14
+ deleteSession(sessionId: string, tenantId?: string): Promise<void>;
15
+ private unexpired;
15
16
  private getKey;
16
17
  }
17
18
  export {};
@@ -13,6 +13,7 @@ export declare class CompanyService extends ApiService<CreateCompanyDto, UpdateC
13
13
  private readonly permissionSyncAdapter?;
14
14
  constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, permissionSyncAdapter?: IPermissionSyncAdapter | undefined);
15
15
  protected beforeDeleteOperation(dto: DeleteDto, user: ILoggedUserInfo | null, queryRunner: QueryRunner): Promise<void>;
16
+ delete(option: DeleteDto, user: ILoggedUserInfo | null): Promise<null>;
16
17
  getSelectQuery(query: SelectQueryBuilder<Company>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
17
18
  query: SelectQueryBuilder<Company>;
18
19
  isRaw: boolean;
@@ -14,6 +14,7 @@ export declare class SocialAuthConfigService extends ApiService<CreateSocialAuth
14
14
  protected beforeInsertOperation(dto: CreateSocialAuthConfigDto | CreateSocialAuthConfigDto[], _user: ILoggedUserInfo | null, _queryRunner: QueryRunner): Promise<void>;
15
15
  protected beforeUpdateOperation(dto: UpdateSocialAuthConfigDto | UpdateSocialAuthConfigDto[], _user: ILoggedUserInfo | null, _queryRunner: QueryRunner): Promise<void>;
16
16
  private ensureProviderUnclaimed;
17
+ protected convertEntityToResponseDto(entity: SocialAuthConfig, _isRaw: boolean): ISocialAuthConfig;
17
18
  protected getExtraManipulateQuery(query: SelectQueryBuilder<SocialAuthConfig>, filterDto: FilterAndPaginationDto, user: ILoggedUserInfo | null): Promise<{
18
19
  query: SelectQueryBuilder<SocialAuthConfig>;
19
20
  isRaw: boolean;
@@ -2,17 +2,20 @@ import { HybridCache } from '@flusys/nestjs-shared/classes';
2
2
  import { SocialProviderTypeEnum } from '../enums/social-provider-type.enum.js';
3
3
  import { type LoginResponse, type LoginResponseRequiresSelection } from '../interfaces/authentication.interface.js';
4
4
  import { type ISocialAuthorization, type ISocialProviderInfo } from '../interfaces/social-auth.interface.js';
5
+ import { AuthConfigService } from './auth-config.service.js';
5
6
  import { AuthDataSourceProvider } from './auth-datasource.provider.js';
6
7
  import { AuthenticationService } from './authentication.service.js';
7
8
  export declare class SocialAuthService {
8
9
  private readonly authService;
9
10
  private readonly dataSourceProvider;
10
11
  private readonly cacheManager?;
11
- constructor(authService: AuthenticationService, dataSourceProvider: AuthDataSourceProvider, cacheManager?: HybridCache | undefined);
12
+ private readonly authConfig?;
13
+ constructor(authService: AuthenticationService, dataSourceProvider: AuthDataSourceProvider, cacheManager?: HybridCache | undefined, authConfig?: AuthConfigService | undefined);
12
14
  listEnabledProviders(redirectUri: string): Promise<ISocialProviderInfo[]>;
13
15
  createAuthorization(provider: SocialProviderTypeEnum, redirectUri: string): Promise<ISocialAuthorization>;
14
16
  completeLogin(code: string, state: string, redirectUri: string): Promise<LoginResponse | LoginResponseRequiresSelection>;
15
17
  private resolveUser;
18
+ private claimUnverifiedAccount;
16
19
  private ensureVerifiedEmail;
17
20
  private registerUser;
18
21
  private getUsableConfig;
@@ -1,13 +1,14 @@
1
+ import { type HybridCache } from '@flusys/nestjs-shared/classes';
1
2
  import { type IPermissionSyncAdapter } from '@flusys/nestjs-shared/interfaces';
2
3
  import { PermissionType, UserCompanyPermission } from '../entities/user-company-permission.entity.js';
3
- import { AuthConfigService } from './auth-config.service.js';
4
4
  import { AuthDataSourceProvider } from './auth-datasource.provider.js';
5
5
  export declare class UserPermissionService {
6
6
  private readonly dataSourceProvider;
7
- private readonly authConfig;
8
7
  private readonly permissionSyncAdapter?;
8
+ private readonly cacheManager?;
9
9
  private _repository;
10
- constructor(dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService, permissionSyncAdapter?: IPermissionSyncAdapter | undefined);
10
+ constructor(dataSourceProvider: AuthDataSourceProvider, permissionSyncAdapter?: IPermissionSyncAdapter | undefined, cacheManager?: HybridCache | undefined);
11
+ private invalidateGrantCache;
11
12
  private getRepository;
12
13
  findUserPermissions(userId: string, type: PermissionType): Promise<UserCompanyPermission[]>;
13
14
  assignPermission(userId: string, targetId: string, type: PermissionType): Promise<void>;
@@ -19,6 +19,8 @@ export declare class UserService extends ApiService<CreateUserDto, UpdateUserDto
19
19
  private readonly logAdapter;
20
20
  constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService, userEnricher?: IUserEnricher | undefined);
21
21
  protected ensureDataSourceRepository(): Promise<void>;
22
+ protected cacheDependencies(): string[];
23
+ private invalidateUserAndGrants;
22
24
  private getUserForProfile;
23
25
  verifyEmail(id: string): Promise<void>;
24
26
  verifyPhone(id: string): Promise<void>;
@@ -49,6 +51,7 @@ export declare class UserService extends ApiService<CreateUserDto, UpdateUserDto
49
51
  data: Array<IUser>;
50
52
  total: number;
51
53
  }>;
54
+ protected bypassListCache(filterAndPaginationDto: FilterAndPaginationDto): boolean;
52
55
  getEnrichedList(users: IUser[], user: ILoggedUserInfo | null): Promise<IEnrichedUser[]>;
53
56
  getProfileSections(): Promise<IProfileSection[]>;
54
57
  getProfileSectionData(userId: string, sectionId: string, user: ILoggedUserInfo): Promise<IProfileSectionData | null>;