@breadstone/archipel-platform-authentication 0.0.20 → 0.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breadstone/archipel-platform-authentication",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "JWT and OAuth authentication, MFA, session management, and email verification for NestJS applications.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -81,9 +81,9 @@
81
81
  "README.md"
82
82
  ],
83
83
  "dependencies": {
84
- "@breadstone/archipel-platform-configuration": "0.0.20",
85
- "@breadstone/archipel-platform-core": "0.0.20",
86
- "@breadstone/archipel-platform-cryptography": "0.0.20",
84
+ "@breadstone/archipel-platform-configuration": "0.0.21",
85
+ "@breadstone/archipel-platform-core": "0.0.21",
86
+ "@breadstone/archipel-platform-cryptography": "0.0.21",
87
87
  "passport": "0.7.0",
88
88
  "passport-custom": "1.1.1",
89
89
  "passport-jwt": "4.0.1",
@@ -1,5 +1,5 @@
1
1
  import { NestMiddleware } from '@nestjs/common';
2
- import { Request, Response, NextFunction } from 'express';
2
+ import { NextFunction, Request, Response } from 'express';
3
3
  import { SessionService } from '../services/SessionService';
4
4
  /**
5
5
  * Middleware to automatically update the lastActive timestamp for authenticated sessions.
@@ -9,6 +9,7 @@ import { SessionService } from '../services/SessionService';
9
9
  */
10
10
  export declare class LastActiveMiddleware implements NestMiddleware {
11
11
  private readonly _sessionService;
12
+ private readonly _logger;
12
13
  /**
13
14
  * Constructs a new instance of the `LastActiveMiddleware` class.
14
15
  *
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  // #region Imports
3
+ var LastActiveMiddleware_1;
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
5
  exports.LastActiveMiddleware = void 0;
5
6
  const tslib_1 = require("tslib");
@@ -12,7 +13,7 @@ const SessionService_1 = require("../services/SessionService");
12
13
  *
13
14
  * @public
14
15
  */
15
- let LastActiveMiddleware = class LastActiveMiddleware {
16
+ let LastActiveMiddleware = LastActiveMiddleware_1 = class LastActiveMiddleware {
16
17
  // #endregion
17
18
  // #region Ctor
18
19
  /**
@@ -22,6 +23,7 @@ let LastActiveMiddleware = class LastActiveMiddleware {
22
23
  * @param sessionService - Session service instance
23
24
  */
24
25
  constructor(sessionService) {
26
+ this._logger = new common_1.Logger(LastActiveMiddleware_1.name);
25
27
  this._sessionService = sessionService;
26
28
  }
27
29
  // #endregion
@@ -40,15 +42,15 @@ let LastActiveMiddleware = class LastActiveMiddleware {
40
42
  if (authHeader?.startsWith('Bearer ')) {
41
43
  const token = authHeader.substring(7);
42
44
  // Update lastActive asynchronously without blocking the request
43
- this._sessionService.updateLastActive(token).catch(() => {
44
- // Silently fail - we don't want to break the request if session update fails
45
+ this._sessionService.updateLastActive(token).catch((e) => {
46
+ this._logger.debug(`Failed to update lastActive err=${e.message}`);
45
47
  });
46
48
  }
47
49
  next();
48
50
  }
49
51
  };
50
52
  exports.LastActiveMiddleware = LastActiveMiddleware;
51
- exports.LastActiveMiddleware = LastActiveMiddleware = tslib_1.__decorate([
53
+ exports.LastActiveMiddleware = LastActiveMiddleware = LastActiveMiddleware_1 = tslib_1.__decorate([
52
54
  (0, common_1.Injectable)(),
53
55
  tslib_1.__metadata("design:paramtypes", [SessionService_1.SessionService])
54
56
  ], LastActiveMiddleware);
@@ -1,3 +1,4 @@
1
+ import { OnModuleDestroy } from '@nestjs/common';
1
2
  import { ChallengeStorePort } from '../contracts/ChallengeStorePort';
2
3
  import type { IMfaChallengeState } from './ChallengeService';
3
4
  /**
@@ -8,9 +9,12 @@ import type { IMfaChallengeState } from './ChallengeService';
8
9
  *
9
10
  * @public
10
11
  */
11
- export declare class InMemoryChallengeStore extends ChallengeStorePort {
12
+ export declare class InMemoryChallengeStore extends ChallengeStorePort implements OnModuleDestroy {
13
+ private static readonly _MAX_ENTRIES;
14
+ private readonly _logger;
12
15
  private readonly _store;
13
16
  set(id: string, challenge: IMfaChallengeState): Promise<void>;
14
17
  get(id: string): Promise<IMfaChallengeState | undefined>;
15
18
  delete(id: string): Promise<void>;
19
+ onModuleDestroy(): void;
16
20
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  // #region Imports
3
+ var InMemoryChallengeStore_1;
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
5
  exports.InMemoryChallengeStore = void 0;
5
6
  const tslib_1 = require("tslib");
@@ -14,16 +15,21 @@ const ChallengeStorePort_1 = require("../contracts/ChallengeStorePort");
14
15
  *
15
16
  * @public
16
17
  */
17
- let InMemoryChallengeStore = class InMemoryChallengeStore extends ChallengeStorePort_1.ChallengeStorePort {
18
+ let InMemoryChallengeStore = InMemoryChallengeStore_1 = class InMemoryChallengeStore extends ChallengeStorePort_1.ChallengeStorePort {
18
19
  constructor() {
19
20
  // #region Fields
20
21
  super(...arguments);
22
+ this._logger = new common_1.Logger(InMemoryChallengeStore_1.name);
21
23
  this._store = new Map();
22
24
  // #endregion
23
25
  }
24
26
  // #endregion
25
27
  // #region Methods
26
28
  async set(id, challenge) {
29
+ if (this._store.size >= InMemoryChallengeStore_1._MAX_ENTRIES && !this._store.has(id)) {
30
+ this._logger.warn(`InMemoryChallengeStore reached max capacity of ${InMemoryChallengeStore_1._MAX_ENTRIES} entries`);
31
+ return;
32
+ }
27
33
  this._store.set(id, challenge);
28
34
  }
29
35
  async get(id) {
@@ -32,9 +38,13 @@ let InMemoryChallengeStore = class InMemoryChallengeStore extends ChallengeStore
32
38
  async delete(id) {
33
39
  this._store.delete(id);
34
40
  }
41
+ onModuleDestroy() {
42
+ this._store.clear();
43
+ }
35
44
  };
36
45
  exports.InMemoryChallengeStore = InMemoryChallengeStore;
37
- exports.InMemoryChallengeStore = InMemoryChallengeStore = tslib_1.__decorate([
46
+ InMemoryChallengeStore._MAX_ENTRIES = 10_000;
47
+ exports.InMemoryChallengeStore = InMemoryChallengeStore = InMemoryChallengeStore_1 = tslib_1.__decorate([
38
48
  (0, common_1.Injectable)()
39
49
  ], InMemoryChallengeStore);
40
50
  //# sourceMappingURL=InMemoryChallengeStore.js.map