@bymax-one/nest-auth 1.0.5 → 1.0.7

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.
@@ -147,6 +147,8 @@ function resolveOptions(userOptions) {
147
147
  validatePasswordCostFactor(userOptions.password);
148
148
  validateOAuthProviders(userOptions.oauth);
149
149
  validateOAuthSuccessRedirectUrl(userOptions);
150
+ validateOAuthMfaRedirectUrl(userOptions);
151
+ validateOAuthErrorRedirectUrl(userOptions);
150
152
  validateRefreshCookiePath(userOptions.routePrefix, userOptions.cookies);
151
153
  validateSameSiteNoneRequiresSecure(userOptions);
152
154
  validateRefreshGraceWindow(userOptions.jwt);
@@ -311,7 +313,7 @@ var REQUIRED_OAUTH_FIELDS = [
311
313
  function validateOAuthProviders(oauth) {
312
314
  if (!oauth) return;
313
315
  for (const [providerOrField, rawConfig] of Object.entries(oauth)) {
314
- if (providerOrField === "successRedirectUrl") continue;
316
+ if (providerOrField === "successRedirectUrl" || providerOrField === "mfaRedirectUrl" || providerOrField === "errorRedirectUrl") continue;
315
317
  const provider = providerOrField;
316
318
  const config = rawConfig;
317
319
  for (const field of REQUIRED_OAUTH_FIELDS) {
@@ -342,6 +344,32 @@ function validateOAuthSuccessRedirectUrl(userOptions) {
342
344
  }
343
345
  }
344
346
  __name(validateOAuthSuccessRedirectUrl, "validateOAuthSuccessRedirectUrl");
347
+ function validateOAuthMfaRedirectUrl(userOptions) {
348
+ const url = userOptions.oauth?.mfaRedirectUrl;
349
+ if (url === void 0) return;
350
+ if (typeof url !== "string" || url.length === 0) {
351
+ throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must be a non-empty string when set.`);
352
+ }
353
+ const isProduction = process.env["NODE_ENV"] === "production";
354
+ const isSafe = url.startsWith("/") || url.startsWith("https://");
355
+ if (isProduction && !isSafe) {
356
+ throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (got: '${url}').`);
357
+ }
358
+ }
359
+ __name(validateOAuthMfaRedirectUrl, "validateOAuthMfaRedirectUrl");
360
+ function validateOAuthErrorRedirectUrl(userOptions) {
361
+ const url = userOptions.oauth?.errorRedirectUrl;
362
+ if (url === void 0) return;
363
+ if (typeof url !== "string" || url.length === 0) {
364
+ throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must be a non-empty string when set.`);
365
+ }
366
+ const isProduction = process.env["NODE_ENV"] === "production";
367
+ const isSafe = url.startsWith("/") || url.startsWith("https://");
368
+ if (isProduction && !isSafe) {
369
+ throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (got: '${url}').`);
370
+ }
371
+ }
372
+ __name(validateOAuthErrorRedirectUrl, "validateOAuthErrorRedirectUrl");
345
373
  function validateRefreshCookiePath(routePrefix, cookies) {
346
374
  const prefix = routePrefix ?? DEFAULT_OPTIONS.routePrefix;
347
375
  if (prefix !== "auth" && !cookies?.refreshCookiePath) {
@@ -4132,6 +4160,10 @@ InvitationController = _ts_decorate18([
4132
4160
  typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService
4133
4161
  ])
4134
4162
  ], InvitationController);
4163
+
4164
+ // src/server/constants/mfa-temp-cookie.ts
4165
+ var MFA_TEMP_COOKIE_NAME = "mfa_temp_token";
4166
+ var MFA_TEMP_COOKIE_MAX_AGE_SECONDS = 300;
4135
4167
  var SKIP_MFA_KEY = /* @__PURE__ */ Symbol("skipMfa");
4136
4168
  var SkipMfa = /* @__PURE__ */ __name(() => SetMetadata(SKIP_MFA_KEY, true), "SkipMfa");
4137
4169
  function _ts_decorate19(decorators, target, key, desc) {
@@ -4150,11 +4182,17 @@ var MfaChallengeDto = class {
4150
4182
  __name(this, "MfaChallengeDto");
4151
4183
  }
4152
4184
  /**
4153
- * The short-lived MFA temporary JWT issued after a successful password login.
4185
+ * The short-lived MFA temporary JWT issued after a successful password login
4186
+ * or OAuth callback.
4154
4187
  *
4155
4188
  * This token is single-use and expires in 5 minutes. It encodes the user ID
4156
4189
  * and the authentication context (`'dashboard'` or `'platform'`).
4157
4190
  *
4191
+ * Optional at the DTO layer because the controller also accepts the token from
4192
+ * the HttpOnly `mfa_temp_token` cookie planted by the OAuth callback. When
4193
+ * neither source carries a token, the controller surfaces
4194
+ * `MFA_TEMP_TOKEN_INVALID`.
4195
+ *
4158
4196
  * `@MaxLength(512)` prevents oversized payloads from reaching `jwtService.verify()`
4159
4197
  * on this public (unauthenticated) endpoint. A compact HS256 JWT is ~200 chars;
4160
4198
  * 512 is a safe upper bound.
@@ -4175,6 +4213,7 @@ var MfaChallengeDto = class {
4175
4213
  code;
4176
4214
  };
4177
4215
  _ts_decorate19([
4216
+ IsOptional(),
4178
4217
  IsString(),
4179
4218
  IsNotEmpty(),
4180
4219
  MaxLength(512),
@@ -4233,6 +4272,39 @@ function _ts_metadata21(k, v) {
4233
4272
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4234
4273
  }
4235
4274
  __name(_ts_metadata21, "_ts_metadata");
4275
+ var MfaRegenerateRecoveryCodesDto = class {
4276
+ static {
4277
+ __name(this, "MfaRegenerateRecoveryCodesDto");
4278
+ }
4279
+ /**
4280
+ * The 6-digit TOTP code generated by the user's authenticator app.
4281
+ *
4282
+ * Must be exactly 6 decimal digits. Recovery codes are not accepted by design.
4283
+ * Alphabetic characters, spaces, or other symbols are rejected before reaching
4284
+ * the service layer.
4285
+ */
4286
+ code;
4287
+ };
4288
+ _ts_decorate21([
4289
+ MaxLength(6),
4290
+ Matches(/^\d{6}$/, {
4291
+ message: "code must be exactly 6 digits"
4292
+ }),
4293
+ IsString(),
4294
+ IsNotEmpty(),
4295
+ _ts_metadata21("design:type", String)
4296
+ ], MfaRegenerateRecoveryCodesDto.prototype, "code", void 0);
4297
+ function _ts_decorate22(decorators, target, key, desc) {
4298
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4299
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4300
+ 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;
4301
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4302
+ }
4303
+ __name(_ts_decorate22, "_ts_decorate");
4304
+ function _ts_metadata22(k, v) {
4305
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4306
+ }
4307
+ __name(_ts_metadata22, "_ts_metadata");
4236
4308
  var MfaVerifyDto = class {
4237
4309
  static {
4238
4310
  __name(this, "MfaVerifyDto");
@@ -4245,14 +4317,14 @@ var MfaVerifyDto = class {
4245
4317
  */
4246
4318
  code;
4247
4319
  };
4248
- _ts_decorate21([
4320
+ _ts_decorate22([
4249
4321
  MaxLength(6),
4250
4322
  Matches(/^\d{6}$/, {
4251
4323
  message: "code must be exactly 6 digits"
4252
4324
  }),
4253
4325
  IsString(),
4254
4326
  IsNotEmpty(),
4255
- _ts_metadata21("design:type", String)
4327
+ _ts_metadata22("design:type", String)
4256
4328
  ], MfaVerifyDto.prototype, "code", void 0);
4257
4329
  var IV_LENGTH = 12;
4258
4330
  var AUTH_TAG_BYTE_LENGTH = 16;
@@ -4409,17 +4481,17 @@ function verifyTotp(secretBase32, code, window = 1) {
4409
4481
  __name(verifyTotp, "verifyTotp");
4410
4482
 
4411
4483
  // src/server/services/mfa.service.ts
4412
- function _ts_decorate22(decorators, target, key, desc) {
4484
+ function _ts_decorate23(decorators, target, key, desc) {
4413
4485
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4414
4486
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4415
4487
  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;
4416
4488
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4417
4489
  }
4418
- __name(_ts_decorate22, "_ts_decorate");
4419
- function _ts_metadata22(k, v) {
4490
+ __name(_ts_decorate23, "_ts_decorate");
4491
+ function _ts_metadata23(k, v) {
4420
4492
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4421
4493
  }
4422
- __name(_ts_metadata22, "_ts_metadata");
4494
+ __name(_ts_metadata23, "_ts_metadata");
4423
4495
  function _ts_param12(paramIndex, decorator) {
4424
4496
  return function(target, key) {
4425
4497
  decorator(target, key, paramIndex);
@@ -4610,7 +4682,7 @@ var MfaService = class _MfaService {
4610
4682
  // setup — TOTP secret generation, idempotent key reservation, recovery codes
4611
4683
  // ---------------------------------------------------------------------------
4612
4684
  /**
4613
- * Initiates the MFA setup flow for a dashboard user.
4685
+ * Initiates the MFA setup flow for a dashboard user or platform administrator.
4614
4686
  *
4615
4687
  * Generates a TOTP secret and 8 recovery codes, stores them temporarily in
4616
4688
  * Redis (10 minutes), and returns the data needed to display the QR code and
@@ -4621,12 +4693,19 @@ var MfaService = class _MfaService {
4621
4693
  * requests cannot generate different secrets.
4622
4694
  *
4623
4695
  * @param userId - Internal ID of the user enabling MFA.
4696
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4624
4697
  * @returns Setup result containing the secret, QR URI, and plain recovery codes.
4625
4698
  * @throws `MFA_ALREADY_ENABLED` if MFA is already active on the account.
4699
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4700
+ * repository was not configured at module registration. The error code is
4701
+ * reused (rather than introducing a new one) because the consumer-facing
4702
+ * meaning is the same: "platform MFA cannot operate".
4626
4703
  */
4627
- async setup(userId) {
4628
- const user = await this.userRepo.findById(userId);
4629
- if (!user) throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
4704
+ async setup(userId, context = "dashboard") {
4705
+ if (context === "platform" && !this.platformUserRepo) {
4706
+ throw new AuthException(AUTH_ERROR_CODES.MFA_NOT_ENABLED);
4707
+ }
4708
+ const user = await this.fetchUserForContext(context, userId);
4630
4709
  if (user.mfaEnabled) throw new AuthException(AUTH_ERROR_CODES.MFA_ALREADY_ENABLED);
4631
4710
  const setupKey = `mfa_setup:${hmacSha256(userId, this.options.hmacKey)}`;
4632
4711
  const existingFast = await this.redis.get(setupKey);
@@ -4671,7 +4750,7 @@ var MfaService = class _MfaService {
4671
4750
  await this.redis.set(setupKey, payload, MFA_SETUP_TTL_SECONDS);
4672
4751
  }
4673
4752
  const qrCodeUri = buildTotpUri(secretBase32, user.email, this.mfaOptions.issuer);
4674
- this.logger.log(`setup: MFA setup initiated userId=${userId}`);
4753
+ this.logger.log(`setup: MFA setup initiated userId=${userId} context=${context}`);
4675
4754
  return {
4676
4755
  secret: secretBase32,
4677
4756
  qrCodeUri,
@@ -4694,12 +4773,17 @@ var MfaService = class _MfaService {
4694
4773
  * @param code - 6-digit TOTP code from the authenticator app.
4695
4774
  * @param ip - Client IP address (forwarded to hooks).
4696
4775
  * @param userAgent - User-Agent header (forwarded to hooks).
4776
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4697
4777
  * @throws `MFA_SETUP_REQUIRED` if no pending setup data is found in Redis.
4698
4778
  * @throws `MFA_INVALID_CODE` if the submitted TOTP code is invalid.
4779
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4780
+ * repository was not configured at module registration.
4699
4781
  */
4700
- async verifyAndEnable(userId, code, ip, userAgent) {
4701
- const user = await this.userRepo.findById(userId);
4702
- if (!user) throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
4782
+ async verifyAndEnable(userId, code, ip, userAgent, context = "dashboard") {
4783
+ if (context === "platform" && !this.platformUserRepo) {
4784
+ throw new AuthException(AUTH_ERROR_CODES.MFA_NOT_ENABLED);
4785
+ }
4786
+ const user = await this.fetchUserForContext(context, userId);
4703
4787
  if (user.mfaEnabled) throw new AuthException(AUTH_ERROR_CODES.MFA_ALREADY_ENABLED);
4704
4788
  const setupKey = `mfa_setup:${hmacSha256(userId, this.options.hmacKey)}`;
4705
4789
  const raw = await this.redis.get(setupKey);
@@ -4717,16 +4801,22 @@ var MfaService = class _MfaService {
4717
4801
  this.logger.warn(`verifyAndEnable: setup key consumed by concurrent request userId=${userId}`);
4718
4802
  throw new AuthException(AUTH_ERROR_CODES.MFA_SETUP_REQUIRED);
4719
4803
  }
4720
- await this.userRepo.updateMfa(userId, {
4804
+ const enableData = {
4721
4805
  mfaEnabled: true,
4722
4806
  mfaSecret: data.encryptedSecret,
4723
4807
  mfaRecoveryCodes: data.hashedCodes
4724
- });
4808
+ };
4809
+ if (context === "platform" && this.platformUserRepo) {
4810
+ await this.platformUserRepo.updateMfa(userId, enableData);
4811
+ } else {
4812
+ await this.userRepo.updateMfa(userId, enableData);
4813
+ }
4725
4814
  await this.redis.invalidateUserSessions(userId);
4726
- this.logger.log(`verifyAndEnable: MFA enabled userId=${userId}`);
4815
+ this.logger.log(`verifyAndEnable: MFA enabled userId=${userId} context=${context}`);
4727
4816
  await this.emailProvider.sendMfaEnabledNotification(user.email);
4728
4817
  if (this.hooks.afterMfaEnabled) {
4729
- void Promise.resolve(this.hooks.afterMfaEnabled(this.toSafeUser(user), {
4818
+ const safeUser = context === "platform" ? this.platformUserAsSafeUser(user) : this.toSafeUser(user);
4819
+ void Promise.resolve(this.hooks.afterMfaEnabled(safeUser, {
4730
4820
  userId,
4731
4821
  ip,
4732
4822
  userAgent,
@@ -4905,6 +4995,95 @@ var MfaService = class _MfaService {
4905
4995
  }
4906
4996
  }
4907
4997
  // ---------------------------------------------------------------------------
4998
+ // regenerateRecoveryCodes — rotate the recovery code set for an MFA-enabled user
4999
+ // ---------------------------------------------------------------------------
5000
+ /**
5001
+ * Regenerates the user's MFA recovery codes after verifying a current TOTP code.
5002
+ *
5003
+ * Mirrors {@link disable} in its security posture: only TOTP codes are accepted
5004
+ * (recovery codes cannot rotate themselves by design), the brute-force counter
5005
+ * is checked, and the regeneration is fired against the correct repository for
5006
+ * the supplied `context`. The TOTP secret on the user record is unchanged — only
5007
+ * the recovery code list is replaced.
5008
+ *
5009
+ * Returns the plain-text codes once. They are NOT persisted in plain form; only
5010
+ * scrypt hashes go into the database. The caller is responsible for showing the
5011
+ * codes to the user exactly once and warning them to save them safely.
5012
+ *
5013
+ * @remarks
5014
+ * **Sessions are intentionally NOT invalidated after this call.** Unlike
5015
+ * {@link verifyAndEnable} (which flips `mfaEnabled` from `false` to `true`) and
5016
+ * {@link disable} (which flips it back to `false`), this method does not change
5017
+ * the verification credential — the TOTP secret stays the same and existing
5018
+ * `mfaVerified: true` access tokens remain valid. Invalidating sessions here
5019
+ * would force a redundant re-auth on every recovery-code rotation, which is a
5020
+ * routine hygiene action a user might perform several times over the lifetime
5021
+ * of an account.
5022
+ *
5023
+ * @param userId - Internal ID of the user rotating recovery codes.
5024
+ * @param totpCode - 6-digit TOTP code from the authenticator app.
5025
+ * @param ip - Client IP address (forwarded to hooks).
5026
+ * @param userAgent - User-Agent header (forwarded to hooks).
5027
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
5028
+ * @throws `TOKEN_INVALID` if the user is not found or `mfaSecret` is missing
5029
+ * when `mfaEnabled` is `true` (database inconsistency).
5030
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active, or if
5031
+ * `context === 'platform'` and the platform user repository was not
5032
+ * configured at module registration.
5033
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
5034
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
5035
+ * @returns The freshly generated plain-text recovery codes, one-time display.
5036
+ */
5037
+ async regenerateRecoveryCodes(userId, totpCode, ip, userAgent, context = "dashboard") {
5038
+ if (context === "platform" && !this.platformUserRepo) {
5039
+ throw new AuthException(AUTH_ERROR_CODES.MFA_NOT_ENABLED);
5040
+ }
5041
+ const user = await this.fetchUserForContext(context, userId);
5042
+ if (!user.mfaEnabled) throw new AuthException(AUTH_ERROR_CODES.MFA_NOT_ENABLED);
5043
+ const bfIdentifier = hmacSha256(`disable:${userId}`, this.options.hmacKey);
5044
+ if (await this.bruteForce.isLockedOut(bfIdentifier)) {
5045
+ this.logger.warn(`regenerateRecoveryCodes: account locked userId=${userId} context=${context}`);
5046
+ throw new AuthException(AUTH_ERROR_CODES.ACCOUNT_LOCKED);
5047
+ }
5048
+ if (!user.mfaSecret) {
5049
+ throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
5050
+ }
5051
+ const secretBase32 = this.decryptSecret(user.mfaSecret);
5052
+ const totpWindow = this.mfaOptions.totpWindow;
5053
+ const codeValid = await this.verifyTotpWithAntiReplay(userId, secretBase32, totpCode, totpWindow);
5054
+ if (!codeValid) {
5055
+ await this.bruteForce.recordFailure(bfIdentifier);
5056
+ this.logger.warn(`regenerateRecoveryCodes: invalid MFA code userId=${userId} context=${context}`);
5057
+ throw new AuthException(AUTH_ERROR_CODES.MFA_INVALID_CODE);
5058
+ }
5059
+ await this.bruteForce.resetFailures(bfIdentifier);
5060
+ const recoveryCount = this.mfaOptions.recoveryCodeCount ?? DEFAULT_RECOVERY_CODE_COUNT;
5061
+ const { plainCodes, hashedCodes } = await this.hashRecoveryCodes(recoveryCount);
5062
+ const updateData = {
5063
+ mfaEnabled: true,
5064
+ mfaSecret: user.mfaSecret,
5065
+ mfaRecoveryCodes: hashedCodes
5066
+ };
5067
+ if (context === "platform" && this.platformUserRepo) {
5068
+ await this.platformUserRepo.updateMfa(userId, updateData);
5069
+ } else {
5070
+ await this.userRepo.updateMfa(userId, updateData);
5071
+ }
5072
+ this.logger.log(`regenerateRecoveryCodes: recovery codes regenerated userId=${userId} context=${context}`);
5073
+ if (this.hooks.afterMfaRecoveryCodesRegenerated) {
5074
+ const safeUser = context === "platform" ? this.platformUserAsSafeUser(user) : this.toSafeUser(user);
5075
+ void Promise.resolve(this.hooks.afterMfaRecoveryCodesRegenerated(safeUser, {
5076
+ userId,
5077
+ ip,
5078
+ userAgent,
5079
+ sanitizedHeaders: {}
5080
+ })).catch(() => void 0);
5081
+ }
5082
+ return {
5083
+ recoveryCodes: plainCodes
5084
+ };
5085
+ }
5086
+ // ---------------------------------------------------------------------------
4908
5087
  // Private helpers
4909
5088
  // ---------------------------------------------------------------------------
4910
5089
  /**
@@ -4943,7 +5122,7 @@ var MfaService = class _MfaService {
4943
5122
  return admin;
4944
5123
  }
4945
5124
  };
4946
- MfaService = _ts_decorate22([
5125
+ MfaService = _ts_decorate23([
4947
5126
  Injectable(),
4948
5127
  _ts_param12(0, Inject(BYMAX_AUTH_OPTIONS)),
4949
5128
  _ts_param12(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
@@ -4951,8 +5130,8 @@ MfaService = _ts_decorate22([
4951
5130
  _ts_param12(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
4952
5131
  _ts_param12(8, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
4953
5132
  _ts_param12(9, Inject(BYMAX_AUTH_HOOKS)),
4954
- _ts_metadata22("design:type", Function),
4955
- _ts_metadata22("design:paramtypes", [
5133
+ _ts_metadata23("design:type", Function),
5134
+ _ts_metadata23("design:paramtypes", [
4956
5135
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
4957
5136
  typeof IUserRepository === "undefined" ? Object : IUserRepository,
4958
5137
  Object,
@@ -4967,17 +5146,17 @@ MfaService = _ts_decorate22([
4967
5146
  ], MfaService);
4968
5147
 
4969
5148
  // src/server/controllers/mfa.controller.ts
4970
- function _ts_decorate23(decorators, target, key, desc) {
5149
+ function _ts_decorate24(decorators, target, key, desc) {
4971
5150
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4972
5151
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4973
5152
  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;
4974
5153
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4975
5154
  }
4976
- __name(_ts_decorate23, "_ts_decorate");
4977
- function _ts_metadata23(k, v) {
5155
+ __name(_ts_decorate24, "_ts_decorate");
5156
+ function _ts_metadata24(k, v) {
4978
5157
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4979
5158
  }
4980
- __name(_ts_metadata23, "_ts_metadata");
5159
+ __name(_ts_metadata24, "_ts_metadata");
4981
5160
  function _ts_param13(paramIndex, decorator) {
4982
5161
  return function(target, key) {
4983
5162
  decorator(target, key, paramIndex);
@@ -4988,15 +5167,24 @@ function isPlatformResult(result) {
4988
5167
  return "admin" in result;
4989
5168
  }
4990
5169
  __name(isPlatformResult, "isPlatformResult");
5170
+ function readMfaTempCookie(req) {
5171
+ const cookies = req.cookies;
5172
+ if (cookies === void 0) return void 0;
5173
+ const { mfa_temp_token: value } = cookies;
5174
+ return typeof value === "string" && value.length > 0 ? value : void 0;
5175
+ }
5176
+ __name(readMfaTempCookie, "readMfaTempCookie");
4991
5177
  var MfaController = class {
4992
5178
  static {
4993
5179
  __name(this, "MfaController");
4994
5180
  }
4995
5181
  mfaService;
4996
5182
  tokenDelivery;
4997
- constructor(mfaService, tokenDelivery) {
5183
+ options;
5184
+ constructor(mfaService, tokenDelivery, options) {
4998
5185
  this.mfaService = mfaService;
4999
5186
  this.tokenDelivery = tokenDelivery;
5187
+ this.options = options;
5000
5188
  }
5001
5189
  /**
5002
5190
  * Initiates the MFA setup flow for the authenticated user.
@@ -5033,24 +5221,51 @@ var MfaController = class {
5033
5221
  * Exchanges a valid MFA temp token + TOTP or recovery code for full auth tokens.
5034
5222
  *
5035
5223
  * This endpoint is public — it is called with the short-lived temp token
5036
- * issued after a successful password login. `@SkipMfa()` ensures that
5224
+ * issued after a successful password login OR after the OAuth callback when
5225
+ * the resolved user has MFA enabled. `@SkipMfa()` ensures that
5037
5226
  * `MfaRequiredGuard` does not block this route when applied globally.
5038
5227
  *
5228
+ * The temp token is read from `dto.mfaTempToken` (password-login flow / SPA
5229
+ * OAuth flow that copies the cookie into sessionStorage) OR from the
5230
+ * HttpOnly `mfa_temp_token` cookie (browser-driven OAuth flow). When both
5231
+ * are present, the body value wins — that matches the historical contract
5232
+ * for the password-login path. When the cookie is consumed, it is cleared
5233
+ * on the response so the temp token is not left around if the user closes
5234
+ * the tab mid-challenge.
5235
+ *
5039
5236
  * Returns either a standard auth response (dashboard) or a
5040
5237
  * {@link PlatformChallengeResponse} for platform admin sessions (cookie
5041
5238
  * delivery is not applied for the platform context — tokens are in the body).
5042
5239
  *
5043
- * @param dto - Contains the MFA temp token and the TOTP or recovery code.
5240
+ * @param dto - Contains the optional MFA temp token and the TOTP / recovery code.
5044
5241
  * @param req - Incoming request (provides IP, User-Agent, and cookie context).
5045
5242
  * @param res - Response object in passthrough mode (used for cookie delivery).
5046
- * @throws `MFA_TEMP_TOKEN_INVALID` if the token is invalid or already consumed.
5243
+ * @throws `MFA_TEMP_TOKEN_INVALID` if no token is supplied (neither body nor cookie),
5244
+ * the token is invalid, or it has already been consumed.
5047
5245
  * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
5048
5246
  * @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
5049
5247
  */
5050
5248
  async challenge(dto, req, res) {
5051
5249
  const ip = req.ip ?? "";
5052
5250
  const userAgent = String(req.headers["user-agent"] ?? "");
5053
- const result = await this.mfaService.challenge(dto.mfaTempToken, dto.code, ip, userAgent);
5251
+ const cookieToken = readMfaTempCookie(req);
5252
+ const mfaTempToken = dto.mfaTempToken ?? cookieToken;
5253
+ if (mfaTempToken === void 0 || mfaTempToken.length === 0) {
5254
+ throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
5255
+ }
5256
+ let result;
5257
+ try {
5258
+ result = await this.mfaService.challenge(mfaTempToken, dto.code, ip, userAgent);
5259
+ } finally {
5260
+ if (cookieToken !== void 0) {
5261
+ res.clearCookie(MFA_TEMP_COOKIE_NAME, {
5262
+ path: `/${this.options.routePrefix}/mfa`,
5263
+ httpOnly: true,
5264
+ secure: this.options.secureCookies,
5265
+ sameSite: this.options.cookies.sameSite
5266
+ });
5267
+ }
5268
+ }
5054
5269
  if (isPlatformResult(result)) {
5055
5270
  return this.tokenDelivery.deliverPlatformAuthResponse(result);
5056
5271
  }
@@ -5076,19 +5291,44 @@ var MfaController = class {
5076
5291
  const context = user.type === "platform" ? "platform" : "dashboard";
5077
5292
  await this.mfaService.disable(user.sub, dto.code, ip, userAgent, context);
5078
5293
  }
5294
+ /**
5295
+ * Regenerates the user's MFA recovery codes after verifying a current TOTP code.
5296
+ *
5297
+ * Requires a valid TOTP code (recovery codes are not accepted by design — see
5298
+ * {@link MfaRegenerateRecoveryCodesDto} for the rationale). The freshly
5299
+ * generated plain-text codes are returned in the response body and are shown
5300
+ * once. Only their scrypt hashes are persisted.
5301
+ *
5302
+ * Shares the disable throttle config because the security posture is identical
5303
+ * (authenticated, TOTP-gated, MFA-affecting state change).
5304
+ *
5305
+ * @param user - JWT payload of the authenticated user.
5306
+ * @param dto - Contains the 6-digit TOTP code confirming the action.
5307
+ * @param req - Incoming request (provides IP and User-Agent for hooks).
5308
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active on the account.
5309
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
5310
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
5311
+ * @returns The fresh plain-text recovery codes, one-time display.
5312
+ */
5313
+ async regenerateRecoveryCodes(user, dto, req) {
5314
+ const ip = req.ip ?? "";
5315
+ const userAgent = String(req.headers["user-agent"] ?? "");
5316
+ const context = user.type === "platform" ? "platform" : "dashboard";
5317
+ return this.mfaService.regenerateRecoveryCodes(user.sub, dto.code, ip, userAgent, context);
5318
+ }
5079
5319
  };
5080
- _ts_decorate23([
5320
+ _ts_decorate24([
5081
5321
  UseGuards(JwtAuthGuard),
5082
5322
  Throttle(AUTH_THROTTLE_CONFIGS.mfaSetup),
5083
5323
  Post("setup"),
5084
5324
  _ts_param13(0, CurrentUser()),
5085
- _ts_metadata23("design:type", Function),
5086
- _ts_metadata23("design:paramtypes", [
5325
+ _ts_metadata24("design:type", Function),
5326
+ _ts_metadata24("design:paramtypes", [
5087
5327
  typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload
5088
5328
  ]),
5089
- _ts_metadata23("design:returntype", Promise)
5329
+ _ts_metadata24("design:returntype", Promise)
5090
5330
  ], MfaController.prototype, "setup", null);
5091
- _ts_decorate23([
5331
+ _ts_decorate24([
5092
5332
  UseGuards(JwtAuthGuard),
5093
5333
  Throttle(AUTH_THROTTLE_CONFIGS.mfaVerifyEnable),
5094
5334
  HttpCode(HttpStatus.NO_CONTENT),
@@ -5096,15 +5336,15 @@ _ts_decorate23([
5096
5336
  _ts_param13(0, CurrentUser()),
5097
5337
  _ts_param13(1, Body()),
5098
5338
  _ts_param13(2, Req()),
5099
- _ts_metadata23("design:type", Function),
5100
- _ts_metadata23("design:paramtypes", [
5339
+ _ts_metadata24("design:type", Function),
5340
+ _ts_metadata24("design:paramtypes", [
5101
5341
  typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
5102
5342
  typeof MfaVerifyDto === "undefined" ? Object : MfaVerifyDto,
5103
5343
  typeof Request === "undefined" ? Object : Request
5104
5344
  ]),
5105
- _ts_metadata23("design:returntype", Promise)
5345
+ _ts_metadata24("design:returntype", Promise)
5106
5346
  ], MfaController.prototype, "verifyEnable", null);
5107
- _ts_decorate23([
5347
+ _ts_decorate24([
5108
5348
  Public(),
5109
5349
  SkipMfa(),
5110
5350
  Throttle(AUTH_THROTTLE_CONFIGS.mfaChallenge),
@@ -5115,15 +5355,15 @@ _ts_decorate23([
5115
5355
  _ts_param13(2, Res({
5116
5356
  passthrough: true
5117
5357
  })),
5118
- _ts_metadata23("design:type", Function),
5119
- _ts_metadata23("design:paramtypes", [
5358
+ _ts_metadata24("design:type", Function),
5359
+ _ts_metadata24("design:paramtypes", [
5120
5360
  typeof MfaChallengeDto === "undefined" ? Object : MfaChallengeDto,
5121
5361
  typeof Request === "undefined" ? Object : Request,
5122
5362
  typeof Response === "undefined" ? Object : Response
5123
5363
  ]),
5124
- _ts_metadata23("design:returntype", Promise)
5364
+ _ts_metadata24("design:returntype", Promise)
5125
5365
  ], MfaController.prototype, "challenge", null);
5126
- _ts_decorate23([
5366
+ _ts_decorate24([
5127
5367
  UseGuards(JwtAuthGuard),
5128
5368
  Throttle(AUTH_THROTTLE_CONFIGS.mfaDisable),
5129
5369
  HttpCode(HttpStatus.NO_CONTENT),
@@ -5131,38 +5371,56 @@ _ts_decorate23([
5131
5371
  _ts_param13(0, CurrentUser()),
5132
5372
  _ts_param13(1, Body()),
5133
5373
  _ts_param13(2, Req()),
5134
- _ts_metadata23("design:type", Function),
5135
- _ts_metadata23("design:paramtypes", [
5374
+ _ts_metadata24("design:type", Function),
5375
+ _ts_metadata24("design:paramtypes", [
5136
5376
  Object,
5137
5377
  typeof MfaDisableDto === "undefined" ? Object : MfaDisableDto,
5138
5378
  typeof Request === "undefined" ? Object : Request
5139
5379
  ]),
5140
- _ts_metadata23("design:returntype", Promise)
5380
+ _ts_metadata24("design:returntype", Promise)
5141
5381
  ], MfaController.prototype, "disable", null);
5142
- MfaController = _ts_decorate23([
5382
+ _ts_decorate24([
5383
+ UseGuards(JwtAuthGuard),
5384
+ Throttle(AUTH_THROTTLE_CONFIGS.mfaDisable),
5385
+ HttpCode(HttpStatus.OK),
5386
+ Post("recovery-codes"),
5387
+ _ts_param13(0, CurrentUser()),
5388
+ _ts_param13(1, Body()),
5389
+ _ts_param13(2, Req()),
5390
+ _ts_metadata24("design:type", Function),
5391
+ _ts_metadata24("design:paramtypes", [
5392
+ Object,
5393
+ typeof MfaRegenerateRecoveryCodesDto === "undefined" ? Object : MfaRegenerateRecoveryCodesDto,
5394
+ typeof Request === "undefined" ? Object : Request
5395
+ ]),
5396
+ _ts_metadata24("design:returntype", Promise)
5397
+ ], MfaController.prototype, "regenerateRecoveryCodes", null);
5398
+ MfaController = _ts_decorate24([
5143
5399
  Controller("mfa"),
5144
5400
  UsePipes(new ValidationPipe({
5145
5401
  whitelist: true,
5146
5402
  forbidNonWhitelisted: true,
5147
5403
  forbidUnknownValues: true
5148
5404
  })),
5149
- _ts_metadata23("design:type", Function),
5150
- _ts_metadata23("design:paramtypes", [
5405
+ _ts_param13(2, Inject(BYMAX_AUTH_OPTIONS)),
5406
+ _ts_metadata24("design:type", Function),
5407
+ _ts_metadata24("design:paramtypes", [
5151
5408
  typeof MfaService === "undefined" ? Object : MfaService,
5152
- typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService
5409
+ typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService,
5410
+ typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
5153
5411
  ])
5154
5412
  ], MfaController);
5155
- function _ts_decorate24(decorators, target, key, desc) {
5413
+ function _ts_decorate25(decorators, target, key, desc) {
5156
5414
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5157
5415
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5158
5416
  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;
5159
5417
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5160
5418
  }
5161
- __name(_ts_decorate24, "_ts_decorate");
5162
- function _ts_metadata24(k, v) {
5419
+ __name(_ts_decorate25, "_ts_decorate");
5420
+ function _ts_metadata25(k, v) {
5163
5421
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5164
5422
  }
5165
- __name(_ts_metadata24, "_ts_metadata");
5423
+ __name(_ts_metadata25, "_ts_metadata");
5166
5424
  var ForgotPasswordDto = class {
5167
5425
  static {
5168
5426
  __name(this, "ForgotPasswordDto");
@@ -5178,29 +5436,29 @@ var ForgotPasswordDto = class {
5178
5436
  */
5179
5437
  tenantId;
5180
5438
  };
5181
- _ts_decorate24([
5439
+ _ts_decorate25([
5182
5440
  Transform(({ value }) => typeof value === "string" ? value.trim().toLowerCase() : value),
5183
5441
  IsEmail(),
5184
5442
  MaxLength(255),
5185
- _ts_metadata24("design:type", String)
5443
+ _ts_metadata25("design:type", String)
5186
5444
  ], ForgotPasswordDto.prototype, "email", void 0);
5187
- _ts_decorate24([
5445
+ _ts_decorate25([
5188
5446
  IsString(),
5189
5447
  IsNotEmpty(),
5190
5448
  MaxLength(128),
5191
- _ts_metadata24("design:type", String)
5449
+ _ts_metadata25("design:type", String)
5192
5450
  ], ForgotPasswordDto.prototype, "tenantId", void 0);
5193
- function _ts_decorate25(decorators, target, key, desc) {
5451
+ function _ts_decorate26(decorators, target, key, desc) {
5194
5452
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5195
5453
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5196
5454
  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;
5197
5455
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5198
5456
  }
5199
- __name(_ts_decorate25, "_ts_decorate");
5200
- function _ts_metadata25(k, v) {
5457
+ __name(_ts_decorate26, "_ts_decorate");
5458
+ function _ts_metadata26(k, v) {
5201
5459
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5202
5460
  }
5203
- __name(_ts_metadata25, "_ts_metadata");
5461
+ __name(_ts_metadata26, "_ts_metadata");
5204
5462
  var ResendOtpDto = class {
5205
5463
  static {
5206
5464
  __name(this, "ResendOtpDto");
@@ -5215,29 +5473,29 @@ var ResendOtpDto = class {
5215
5473
  */
5216
5474
  tenantId;
5217
5475
  };
5218
- _ts_decorate25([
5476
+ _ts_decorate26([
5219
5477
  Transform(({ value }) => typeof value === "string" ? value.trim().toLowerCase() : value),
5220
5478
  IsEmail(),
5221
5479
  MaxLength(255),
5222
- _ts_metadata25("design:type", String)
5480
+ _ts_metadata26("design:type", String)
5223
5481
  ], ResendOtpDto.prototype, "email", void 0);
5224
- _ts_decorate25([
5482
+ _ts_decorate26([
5225
5483
  IsString(),
5226
5484
  IsNotEmpty(),
5227
5485
  MaxLength(128),
5228
- _ts_metadata25("design:type", String)
5486
+ _ts_metadata26("design:type", String)
5229
5487
  ], ResendOtpDto.prototype, "tenantId", void 0);
5230
- function _ts_decorate26(decorators, target, key, desc) {
5488
+ function _ts_decorate27(decorators, target, key, desc) {
5231
5489
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5232
5490
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5233
5491
  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;
5234
5492
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5235
5493
  }
5236
- __name(_ts_decorate26, "_ts_decorate");
5237
- function _ts_metadata26(k, v) {
5494
+ __name(_ts_decorate27, "_ts_decorate");
5495
+ function _ts_metadata27(k, v) {
5238
5496
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5239
5497
  }
5240
- __name(_ts_metadata26, "_ts_metadata");
5498
+ __name(_ts_metadata27, "_ts_metadata");
5241
5499
  var ResetPasswordDto = class {
5242
5500
  static {
5243
5501
  __name(this, "ResetPasswordDto");
@@ -5277,54 +5535,54 @@ var ResetPasswordDto = class {
5277
5535
  */
5278
5536
  tenantId;
5279
5537
  };
5280
- _ts_decorate26([
5538
+ _ts_decorate27([
5281
5539
  Transform(({ value }) => typeof value === "string" ? value.trim().toLowerCase() : value),
5282
5540
  IsEmail(),
5283
5541
  MaxLength(255),
5284
- _ts_metadata26("design:type", String)
5542
+ _ts_metadata27("design:type", String)
5285
5543
  ], ResetPasswordDto.prototype, "email", void 0);
5286
- _ts_decorate26([
5544
+ _ts_decorate27([
5287
5545
  IsString(),
5288
5546
  MinLength(8),
5289
5547
  MaxLength(128),
5290
- _ts_metadata26("design:type", String)
5548
+ _ts_metadata27("design:type", String)
5291
5549
  ], ResetPasswordDto.prototype, "newPassword", void 0);
5292
- _ts_decorate26([
5550
+ _ts_decorate27([
5293
5551
  IsOptional(),
5294
5552
  IsString(),
5295
5553
  IsNotEmpty(),
5296
5554
  MaxLength(2048),
5297
- _ts_metadata26("design:type", String)
5555
+ _ts_metadata27("design:type", String)
5298
5556
  ], ResetPasswordDto.prototype, "token", void 0);
5299
- _ts_decorate26([
5557
+ _ts_decorate27([
5300
5558
  IsOptional(),
5301
5559
  IsString(),
5302
5560
  Length(4, 8),
5303
- _ts_metadata26("design:type", String)
5561
+ _ts_metadata27("design:type", String)
5304
5562
  ], ResetPasswordDto.prototype, "otp", void 0);
5305
- _ts_decorate26([
5563
+ _ts_decorate27([
5306
5564
  IsOptional(),
5307
5565
  IsString(),
5308
5566
  Length(64, 64),
5309
- _ts_metadata26("design:type", String)
5567
+ _ts_metadata27("design:type", String)
5310
5568
  ], ResetPasswordDto.prototype, "verifiedToken", void 0);
5311
- _ts_decorate26([
5569
+ _ts_decorate27([
5312
5570
  IsString(),
5313
5571
  IsNotEmpty(),
5314
5572
  MaxLength(128),
5315
- _ts_metadata26("design:type", String)
5573
+ _ts_metadata27("design:type", String)
5316
5574
  ], ResetPasswordDto.prototype, "tenantId", void 0);
5317
- function _ts_decorate27(decorators, target, key, desc) {
5575
+ function _ts_decorate28(decorators, target, key, desc) {
5318
5576
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5319
5577
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5320
5578
  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;
5321
5579
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5322
5580
  }
5323
- __name(_ts_decorate27, "_ts_decorate");
5324
- function _ts_metadata27(k, v) {
5581
+ __name(_ts_decorate28, "_ts_decorate");
5582
+ function _ts_metadata28(k, v) {
5325
5583
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5326
5584
  }
5327
- __name(_ts_metadata27, "_ts_metadata");
5585
+ __name(_ts_metadata28, "_ts_metadata");
5328
5586
  var VerifyOtpDto = class {
5329
5587
  static {
5330
5588
  __name(this, "VerifyOtpDto");
@@ -5346,34 +5604,34 @@ var VerifyOtpDto = class {
5346
5604
  */
5347
5605
  tenantId;
5348
5606
  };
5349
- _ts_decorate27([
5607
+ _ts_decorate28([
5350
5608
  Transform(({ value }) => typeof value === "string" ? value.trim().toLowerCase() : value),
5351
5609
  IsEmail(),
5352
5610
  MaxLength(255),
5353
- _ts_metadata27("design:type", String)
5611
+ _ts_metadata28("design:type", String)
5354
5612
  ], VerifyOtpDto.prototype, "email", void 0);
5355
- _ts_decorate27([
5613
+ _ts_decorate28([
5356
5614
  IsString(),
5357
5615
  Length(4, 8),
5358
- _ts_metadata27("design:type", String)
5616
+ _ts_metadata28("design:type", String)
5359
5617
  ], VerifyOtpDto.prototype, "otp", void 0);
5360
- _ts_decorate27([
5618
+ _ts_decorate28([
5361
5619
  IsString(),
5362
5620
  IsNotEmpty(),
5363
5621
  MaxLength(128),
5364
- _ts_metadata27("design:type", String)
5622
+ _ts_metadata28("design:type", String)
5365
5623
  ], VerifyOtpDto.prototype, "tenantId", void 0);
5366
- function _ts_decorate28(decorators, target, key, desc) {
5624
+ function _ts_decorate29(decorators, target, key, desc) {
5367
5625
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5368
5626
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5369
5627
  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;
5370
5628
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5371
5629
  }
5372
- __name(_ts_decorate28, "_ts_decorate");
5373
- function _ts_metadata28(k, v) {
5630
+ __name(_ts_decorate29, "_ts_decorate");
5631
+ function _ts_metadata29(k, v) {
5374
5632
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5375
5633
  }
5376
- __name(_ts_metadata28, "_ts_metadata");
5634
+ __name(_ts_metadata29, "_ts_metadata");
5377
5635
  function _ts_param14(paramIndex, decorator) {
5378
5636
  return function(target, key) {
5379
5637
  decorator(target, key, paramIndex);
@@ -5730,7 +5988,7 @@ var PasswordResetService = class _PasswordResetService {
5730
5988
  return parsed;
5731
5989
  }
5732
5990
  };
5733
- PasswordResetService = _ts_decorate28([
5991
+ PasswordResetService = _ts_decorate29([
5734
5992
  Injectable(),
5735
5993
  _ts_param14(0, Inject(BYMAX_AUTH_OPTIONS)),
5736
5994
  _ts_param14(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
@@ -5738,8 +5996,8 @@ PasswordResetService = _ts_decorate28([
5738
5996
  _ts_param14(2, Optional()),
5739
5997
  _ts_param14(3, Inject(BYMAX_AUTH_HOOKS)),
5740
5998
  _ts_param14(3, Optional()),
5741
- _ts_metadata28("design:type", Function),
5742
- _ts_metadata28("design:paramtypes", [
5999
+ _ts_metadata29("design:type", Function),
6000
+ _ts_metadata29("design:paramtypes", [
5743
6001
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
5744
6002
  typeof IUserRepository === "undefined" ? Object : IUserRepository,
5745
6003
  Object,
@@ -5756,17 +6014,17 @@ function toSafeUser3(user) {
5756
6014
  __name(toSafeUser3, "toSafeUser");
5757
6015
 
5758
6016
  // src/server/controllers/password-reset.controller.ts
5759
- function _ts_decorate29(decorators, target, key, desc) {
6017
+ function _ts_decorate30(decorators, target, key, desc) {
5760
6018
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5761
6019
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5762
6020
  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;
5763
6021
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5764
6022
  }
5765
- __name(_ts_decorate29, "_ts_decorate");
5766
- function _ts_metadata29(k, v) {
6023
+ __name(_ts_decorate30, "_ts_decorate");
6024
+ function _ts_metadata30(k, v) {
5767
6025
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5768
6026
  }
5769
- __name(_ts_metadata29, "_ts_metadata");
6027
+ __name(_ts_metadata30, "_ts_metadata");
5770
6028
  function _ts_param15(paramIndex, decorator) {
5771
6029
  return function(target, key) {
5772
6030
  decorator(target, key, paramIndex);
@@ -5850,73 +6108,73 @@ var PasswordResetController = class {
5850
6108
  await this.passwordResetService.resendOtp(dto);
5851
6109
  }
5852
6110
  };
5853
- _ts_decorate29([
6111
+ _ts_decorate30([
5854
6112
  Throttle(AUTH_THROTTLE_CONFIGS.forgotPassword),
5855
6113
  HttpCode(HttpStatus.OK),
5856
6114
  Post("forgot-password"),
5857
6115
  _ts_param15(0, Body()),
5858
- _ts_metadata29("design:type", Function),
5859
- _ts_metadata29("design:paramtypes", [
6116
+ _ts_metadata30("design:type", Function),
6117
+ _ts_metadata30("design:paramtypes", [
5860
6118
  typeof ForgotPasswordDto === "undefined" ? Object : ForgotPasswordDto
5861
6119
  ]),
5862
- _ts_metadata29("design:returntype", Promise)
6120
+ _ts_metadata30("design:returntype", Promise)
5863
6121
  ], PasswordResetController.prototype, "forgotPassword", null);
5864
- _ts_decorate29([
6122
+ _ts_decorate30([
5865
6123
  Throttle(AUTH_THROTTLE_CONFIGS.resetPassword),
5866
6124
  HttpCode(HttpStatus.NO_CONTENT),
5867
6125
  Post("reset-password"),
5868
6126
  _ts_param15(0, Body()),
5869
- _ts_metadata29("design:type", Function),
5870
- _ts_metadata29("design:paramtypes", [
6127
+ _ts_metadata30("design:type", Function),
6128
+ _ts_metadata30("design:paramtypes", [
5871
6129
  typeof ResetPasswordDto === "undefined" ? Object : ResetPasswordDto
5872
6130
  ]),
5873
- _ts_metadata29("design:returntype", Promise)
6131
+ _ts_metadata30("design:returntype", Promise)
5874
6132
  ], PasswordResetController.prototype, "resetPassword", null);
5875
- _ts_decorate29([
6133
+ _ts_decorate30([
5876
6134
  Throttle(AUTH_THROTTLE_CONFIGS.verifyOtp),
5877
6135
  HttpCode(HttpStatus.OK),
5878
6136
  Post("verify-otp"),
5879
6137
  _ts_param15(0, Body()),
5880
- _ts_metadata29("design:type", Function),
5881
- _ts_metadata29("design:paramtypes", [
6138
+ _ts_metadata30("design:type", Function),
6139
+ _ts_metadata30("design:paramtypes", [
5882
6140
  typeof VerifyOtpDto === "undefined" ? Object : VerifyOtpDto
5883
6141
  ]),
5884
- _ts_metadata29("design:returntype", Promise)
6142
+ _ts_metadata30("design:returntype", Promise)
5885
6143
  ], PasswordResetController.prototype, "verifyOtp", null);
5886
- _ts_decorate29([
6144
+ _ts_decorate30([
5887
6145
  Throttle(AUTH_THROTTLE_CONFIGS.resendPasswordOtp),
5888
6146
  HttpCode(HttpStatus.OK),
5889
6147
  Post("resend-otp"),
5890
6148
  _ts_param15(0, Body()),
5891
- _ts_metadata29("design:type", Function),
5892
- _ts_metadata29("design:paramtypes", [
6149
+ _ts_metadata30("design:type", Function),
6150
+ _ts_metadata30("design:paramtypes", [
5893
6151
  typeof ResendOtpDto === "undefined" ? Object : ResendOtpDto
5894
6152
  ]),
5895
- _ts_metadata29("design:returntype", Promise)
6153
+ _ts_metadata30("design:returntype", Promise)
5896
6154
  ], PasswordResetController.prototype, "resendOtp", null);
5897
- PasswordResetController = _ts_decorate29([
6155
+ PasswordResetController = _ts_decorate30([
5898
6156
  Public(),
5899
6157
  Controller("password"),
5900
6158
  UsePipes(new ValidationPipe({
5901
6159
  whitelist: true,
5902
6160
  forbidNonWhitelisted: true
5903
6161
  })),
5904
- _ts_metadata29("design:type", Function),
5905
- _ts_metadata29("design:paramtypes", [
6162
+ _ts_metadata30("design:type", Function),
6163
+ _ts_metadata30("design:paramtypes", [
5906
6164
  typeof PasswordResetService === "undefined" ? Object : PasswordResetService
5907
6165
  ])
5908
6166
  ], PasswordResetController);
5909
- function _ts_decorate30(decorators, target, key, desc) {
6167
+ function _ts_decorate31(decorators, target, key, desc) {
5910
6168
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5911
6169
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5912
6170
  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;
5913
6171
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5914
6172
  }
5915
- __name(_ts_decorate30, "_ts_decorate");
5916
- function _ts_metadata30(k, v) {
6173
+ __name(_ts_decorate31, "_ts_decorate");
6174
+ function _ts_metadata31(k, v) {
5917
6175
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5918
6176
  }
5919
- __name(_ts_metadata30, "_ts_metadata");
6177
+ __name(_ts_metadata31, "_ts_metadata");
5920
6178
  var PlatformLoginDto = class {
5921
6179
  static {
5922
6180
  __name(this, "PlatformLoginDto");
@@ -5938,14 +6196,14 @@ var PlatformLoginDto = class {
5938
6196
  */
5939
6197
  password;
5940
6198
  };
5941
- _ts_decorate30([
6199
+ _ts_decorate31([
5942
6200
  Transform(({ value }) => typeof value === "string" ? value.trim().toLowerCase() : value),
5943
6201
  IsEmail(),
5944
6202
  IsNotEmpty(),
5945
6203
  MaxLength(255),
5946
- _ts_metadata30("design:type", String)
6204
+ _ts_metadata31("design:type", String)
5947
6205
  ], PlatformLoginDto.prototype, "email", void 0);
5948
- _ts_decorate30([
6206
+ _ts_decorate31([
5949
6207
  IsString(),
5950
6208
  IsNotEmpty(),
5951
6209
  Matches(/\S/, {
@@ -5953,19 +6211,19 @@ _ts_decorate30([
5953
6211
  }),
5954
6212
  MinLength(12),
5955
6213
  MaxLength(128),
5956
- _ts_metadata30("design:type", String)
6214
+ _ts_metadata31("design:type", String)
5957
6215
  ], PlatformLoginDto.prototype, "password", void 0);
5958
- function _ts_decorate31(decorators, target, key, desc) {
6216
+ function _ts_decorate32(decorators, target, key, desc) {
5959
6217
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5960
6218
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5961
6219
  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;
5962
6220
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5963
6221
  }
5964
- __name(_ts_decorate31, "_ts_decorate");
5965
- function _ts_metadata31(k, v) {
6222
+ __name(_ts_decorate32, "_ts_decorate");
6223
+ function _ts_metadata32(k, v) {
5966
6224
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5967
6225
  }
5968
- __name(_ts_metadata31, "_ts_metadata");
6226
+ __name(_ts_metadata32, "_ts_metadata");
5969
6227
  function _ts_param16(paramIndex, decorator) {
5970
6228
  return function(target, key) {
5971
6229
  decorator(target, key, paramIndex);
@@ -6022,11 +6280,11 @@ var JwtPlatformGuard = class {
6022
6280
  return true;
6023
6281
  }
6024
6282
  };
6025
- JwtPlatformGuard = _ts_decorate31([
6283
+ JwtPlatformGuard = _ts_decorate32([
6026
6284
  Injectable(),
6027
6285
  _ts_param16(4, Inject(BYMAX_AUTH_OPTIONS)),
6028
- _ts_metadata31("design:type", Function),
6029
- _ts_metadata31("design:paramtypes", [
6286
+ _ts_metadata32("design:type", Function),
6287
+ _ts_metadata32("design:paramtypes", [
6030
6288
  typeof JwtService === "undefined" ? Object : JwtService,
6031
6289
  typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService,
6032
6290
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
@@ -6034,17 +6292,17 @@ JwtPlatformGuard = _ts_decorate31([
6034
6292
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
6035
6293
  ])
6036
6294
  ], JwtPlatformGuard);
6037
- function _ts_decorate32(decorators, target, key, desc) {
6295
+ function _ts_decorate33(decorators, target, key, desc) {
6038
6296
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6039
6297
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6040
6298
  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;
6041
6299
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6042
6300
  }
6043
- __name(_ts_decorate32, "_ts_decorate");
6044
- function _ts_metadata32(k, v) {
6301
+ __name(_ts_decorate33, "_ts_decorate");
6302
+ function _ts_metadata33(k, v) {
6045
6303
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6046
6304
  }
6047
- __name(_ts_metadata32, "_ts_metadata");
6305
+ __name(_ts_metadata33, "_ts_metadata");
6048
6306
  function _ts_param17(paramIndex, decorator) {
6049
6307
  return function(target, key) {
6050
6308
  decorator(target, key, paramIndex);
@@ -6203,12 +6461,12 @@ var PlatformAuthService = class _PlatformAuthService {
6203
6461
  await this.redis.invalidateUserSessions(userId);
6204
6462
  }
6205
6463
  };
6206
- PlatformAuthService = _ts_decorate32([
6464
+ PlatformAuthService = _ts_decorate33([
6207
6465
  Injectable(),
6208
6466
  _ts_param17(0, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
6209
6467
  _ts_param17(5, Inject(BYMAX_AUTH_OPTIONS)),
6210
- _ts_metadata32("design:type", Function),
6211
- _ts_metadata32("design:paramtypes", [
6468
+ _ts_metadata33("design:type", Function),
6469
+ _ts_metadata33("design:paramtypes", [
6212
6470
  typeof IPlatformUserRepository === "undefined" ? Object : IPlatformUserRepository,
6213
6471
  typeof PasswordService === "undefined" ? Object : PasswordService,
6214
6472
  typeof TokenManagerService === "undefined" ? Object : TokenManagerService,
@@ -6219,17 +6477,17 @@ PlatformAuthService = _ts_decorate32([
6219
6477
  ], PlatformAuthService);
6220
6478
 
6221
6479
  // src/server/controllers/platform-auth.controller.ts
6222
- function _ts_decorate33(decorators, target, key, desc) {
6480
+ function _ts_decorate34(decorators, target, key, desc) {
6223
6481
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6224
6482
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6225
6483
  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;
6226
6484
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6227
6485
  }
6228
- __name(_ts_decorate33, "_ts_decorate");
6229
- function _ts_metadata33(k, v) {
6486
+ __name(_ts_decorate34, "_ts_decorate");
6487
+ function _ts_metadata34(k, v) {
6230
6488
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6231
6489
  }
6232
- __name(_ts_metadata33, "_ts_metadata");
6490
+ __name(_ts_metadata34, "_ts_metadata");
6233
6491
  function _ts_param18(paramIndex, decorator) {
6234
6492
  return function(target, key) {
6235
6493
  decorator(target, key, paramIndex);
@@ -6301,6 +6559,9 @@ var PlatformAuthController = class {
6301
6559
  async mfaChallenge(dto, req) {
6302
6560
  const ip = req.ip ?? "";
6303
6561
  const userAgent = String(req.headers["user-agent"] ?? "").slice(0, 512);
6562
+ if (dto.mfaTempToken === void 0 || dto.mfaTempToken.length === 0) {
6563
+ throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
6564
+ }
6304
6565
  const result = await this.mfaService.challenge(dto.mfaTempToken, dto.code, ip, userAgent);
6305
6566
  if (!isPlatformResult2(result)) {
6306
6567
  throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
@@ -6390,111 +6651,277 @@ var PlatformAuthController = class {
6390
6651
  await this.platformAuthService.revokeAllPlatformSessions(user.sub);
6391
6652
  }
6392
6653
  };
6393
- _ts_decorate33([
6654
+ _ts_decorate34([
6394
6655
  Public(),
6395
6656
  Throttle(AUTH_THROTTLE_CONFIGS.platformLogin),
6396
6657
  HttpCode(HttpStatus.OK),
6397
6658
  Post("login"),
6398
6659
  _ts_param18(0, Body()),
6399
6660
  _ts_param18(1, Req()),
6400
- _ts_metadata33("design:type", Function),
6401
- _ts_metadata33("design:paramtypes", [
6661
+ _ts_metadata34("design:type", Function),
6662
+ _ts_metadata34("design:paramtypes", [
6402
6663
  typeof PlatformLoginDto === "undefined" ? Object : PlatformLoginDto,
6403
6664
  typeof Request === "undefined" ? Object : Request
6404
6665
  ]),
6405
- _ts_metadata33("design:returntype", Promise)
6666
+ _ts_metadata34("design:returntype", Promise)
6406
6667
  ], PlatformAuthController.prototype, "login", null);
6407
- _ts_decorate33([
6668
+ _ts_decorate34([
6408
6669
  Public(),
6409
6670
  Throttle(AUTH_THROTTLE_CONFIGS.mfaChallenge),
6410
6671
  HttpCode(HttpStatus.OK),
6411
6672
  Post("mfa/challenge"),
6412
6673
  _ts_param18(0, Body()),
6413
6674
  _ts_param18(1, Req()),
6414
- _ts_metadata33("design:type", Function),
6415
- _ts_metadata33("design:paramtypes", [
6675
+ _ts_metadata34("design:type", Function),
6676
+ _ts_metadata34("design:paramtypes", [
6416
6677
  typeof MfaChallengeDto === "undefined" ? Object : MfaChallengeDto,
6417
6678
  typeof Request === "undefined" ? Object : Request
6418
6679
  ]),
6419
- _ts_metadata33("design:returntype", Promise)
6680
+ _ts_metadata34("design:returntype", Promise)
6420
6681
  ], PlatformAuthController.prototype, "mfaChallenge", null);
6421
- _ts_decorate33([
6682
+ _ts_decorate34([
6422
6683
  UseGuards(JwtPlatformGuard),
6423
6684
  Get("me"),
6424
6685
  _ts_param18(0, CurrentUser()),
6425
- _ts_metadata33("design:type", Function),
6426
- _ts_metadata33("design:paramtypes", [
6686
+ _ts_metadata34("design:type", Function),
6687
+ _ts_metadata34("design:paramtypes", [
6427
6688
  typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload
6428
6689
  ]),
6429
- _ts_metadata33("design:returntype", Promise)
6690
+ _ts_metadata34("design:returntype", Promise)
6430
6691
  ], PlatformAuthController.prototype, "me", null);
6431
- _ts_decorate33([
6692
+ _ts_decorate34([
6432
6693
  UseGuards(JwtPlatformGuard),
6433
6694
  HttpCode(HttpStatus.NO_CONTENT),
6434
6695
  Post("logout"),
6435
6696
  _ts_param18(0, CurrentUser()),
6436
6697
  _ts_param18(1, Req()),
6437
- _ts_metadata33("design:type", Function),
6438
- _ts_metadata33("design:paramtypes", [
6698
+ _ts_metadata34("design:type", Function),
6699
+ _ts_metadata34("design:paramtypes", [
6439
6700
  typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
6440
6701
  typeof Request === "undefined" ? Object : Request
6441
6702
  ]),
6442
- _ts_metadata33("design:returntype", Promise)
6703
+ _ts_metadata34("design:returntype", Promise)
6443
6704
  ], PlatformAuthController.prototype, "logout", null);
6444
- _ts_decorate33([
6705
+ _ts_decorate34([
6445
6706
  Public(),
6446
6707
  Throttle(AUTH_THROTTLE_CONFIGS.refresh),
6447
6708
  HttpCode(HttpStatus.OK),
6448
6709
  Post("refresh"),
6449
6710
  _ts_param18(0, Req()),
6450
- _ts_metadata33("design:type", Function),
6451
- _ts_metadata33("design:paramtypes", [
6711
+ _ts_metadata34("design:type", Function),
6712
+ _ts_metadata34("design:paramtypes", [
6452
6713
  typeof Request === "undefined" ? Object : Request
6453
6714
  ]),
6454
- _ts_metadata33("design:returntype", Promise)
6715
+ _ts_metadata34("design:returntype", Promise)
6455
6716
  ], PlatformAuthController.prototype, "refresh", null);
6456
- _ts_decorate33([
6717
+ _ts_decorate34([
6457
6718
  UseGuards(JwtPlatformGuard),
6458
6719
  Throttle(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
6459
6720
  HttpCode(HttpStatus.NO_CONTENT),
6460
6721
  Delete("sessions"),
6461
6722
  _ts_param18(0, CurrentUser()),
6462
- _ts_metadata33("design:type", Function),
6463
- _ts_metadata33("design:paramtypes", [
6723
+ _ts_metadata34("design:type", Function),
6724
+ _ts_metadata34("design:paramtypes", [
6464
6725
  typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload
6465
6726
  ]),
6466
- _ts_metadata33("design:returntype", Promise)
6727
+ _ts_metadata34("design:returntype", Promise)
6467
6728
  ], PlatformAuthController.prototype, "revokeSessions", null);
6468
- PlatformAuthController = _ts_decorate33([
6729
+ PlatformAuthController = _ts_decorate34([
6469
6730
  Controller("platform"),
6470
6731
  UsePipes(new ValidationPipe({
6471
6732
  whitelist: true,
6472
6733
  forbidNonWhitelisted: true
6473
6734
  })),
6474
- _ts_metadata33("design:type", Function),
6475
- _ts_metadata33("design:paramtypes", [
6735
+ _ts_metadata34("design:type", Function),
6736
+ _ts_metadata34("design:paramtypes", [
6476
6737
  typeof PlatformAuthService === "undefined" ? Object : PlatformAuthService,
6477
6738
  typeof MfaService === "undefined" ? Object : MfaService,
6478
6739
  typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService
6479
6740
  ])
6480
6741
  ], PlatformAuthController);
6481
- function _ts_decorate34(decorators, target, key, desc) {
6742
+ function _ts_decorate35(decorators, target, key, desc) {
6482
6743
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6483
6744
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6484
6745
  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;
6485
6746
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6486
6747
  }
6487
- __name(_ts_decorate34, "_ts_decorate");
6488
- function _ts_metadata34(k, v) {
6748
+ __name(_ts_decorate35, "_ts_decorate");
6749
+ function _ts_metadata35(k, v) {
6489
6750
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6490
6751
  }
6491
- __name(_ts_metadata34, "_ts_metadata");
6752
+ __name(_ts_metadata35, "_ts_metadata");
6492
6753
  function _ts_param19(paramIndex, decorator) {
6493
6754
  return function(target, key) {
6494
6755
  decorator(target, key, paramIndex);
6495
6756
  };
6496
6757
  }
6497
6758
  __name(_ts_param19, "_ts_param");
6759
+ var PlatformMfaController = class {
6760
+ static {
6761
+ __name(this, "PlatformMfaController");
6762
+ }
6763
+ mfaService;
6764
+ constructor(mfaService) {
6765
+ this.mfaService = mfaService;
6766
+ }
6767
+ /**
6768
+ * Initiates the MFA setup flow for the authenticated platform administrator.
6769
+ *
6770
+ * Returns a TOTP secret, QR code URI, and plain-text recovery codes (shown once).
6771
+ * Idempotent within the 10-minute setup window — repeated calls return the
6772
+ * same payload until the user completes or abandons the flow.
6773
+ *
6774
+ * @param user - JWT payload of the authenticated platform admin.
6775
+ * @throws `MFA_ALREADY_ENABLED` if MFA is already active on the account.
6776
+ */
6777
+ async setup(user) {
6778
+ return this.mfaService.setup(user.sub, "platform");
6779
+ }
6780
+ /**
6781
+ * Verifies the first TOTP code and permanently enables MFA on the platform
6782
+ * admin's account.
6783
+ *
6784
+ * After a successful call, all existing refresh sessions are invalidated so
6785
+ * the admin must re-authenticate through the MFA challenge endpoint.
6786
+ *
6787
+ * @param user - JWT payload of the authenticated platform admin.
6788
+ * @param dto - Contains the 6-digit TOTP code from the authenticator app.
6789
+ * @param req - Incoming request (provides IP and User-Agent for hooks).
6790
+ * @throws `MFA_SETUP_REQUIRED` if no pending setup data is found in Redis.
6791
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is invalid.
6792
+ */
6793
+ async verifyEnable(user, dto, req) {
6794
+ const ip = req.ip ?? "";
6795
+ const userAgent = String(req.headers["user-agent"] ?? "");
6796
+ await this.mfaService.verifyAndEnable(user.sub, dto.code, ip, userAgent, "platform");
6797
+ }
6798
+ /**
6799
+ * Disables MFA on the authenticated platform admin's account.
6800
+ *
6801
+ * Requires a valid TOTP code (recovery codes are not accepted by design).
6802
+ * All existing refresh sessions are invalidated after disabling.
6803
+ *
6804
+ * @param user - JWT payload of the authenticated platform admin.
6805
+ * @param dto - Contains the 6-digit TOTP code confirming the action.
6806
+ * @param req - Incoming request (provides IP and User-Agent for hooks).
6807
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active on the account.
6808
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
6809
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
6810
+ */
6811
+ async disable(user, dto, req) {
6812
+ const ip = req.ip ?? "";
6813
+ const userAgent = String(req.headers["user-agent"] ?? "");
6814
+ await this.mfaService.disable(user.sub, dto.code, ip, userAgent, "platform");
6815
+ }
6816
+ /**
6817
+ * Regenerates the platform admin's MFA recovery codes.
6818
+ *
6819
+ * Requires a valid TOTP code (recovery codes are not accepted by design).
6820
+ * Returns the fresh plain-text codes once — only their scrypt hashes are
6821
+ * persisted.
6822
+ *
6823
+ * @param user - JWT payload of the authenticated platform admin.
6824
+ * @param dto - Contains the 6-digit TOTP code confirming the action.
6825
+ * @param req - Incoming request (provides IP and User-Agent for hooks).
6826
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active on the account.
6827
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
6828
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
6829
+ * @returns The fresh plain-text recovery codes, one-time display.
6830
+ */
6831
+ async regenerateRecoveryCodes(user, dto, req) {
6832
+ const ip = req.ip ?? "";
6833
+ const userAgent = String(req.headers["user-agent"] ?? "");
6834
+ return this.mfaService.regenerateRecoveryCodes(user.sub, dto.code, ip, userAgent, "platform");
6835
+ }
6836
+ };
6837
+ _ts_decorate35([
6838
+ UseGuards(JwtPlatformGuard),
6839
+ Throttle(AUTH_THROTTLE_CONFIGS.mfaSetup),
6840
+ Post("setup"),
6841
+ _ts_param19(0, CurrentUser()),
6842
+ _ts_metadata35("design:type", Function),
6843
+ _ts_metadata35("design:paramtypes", [
6844
+ typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload
6845
+ ]),
6846
+ _ts_metadata35("design:returntype", Promise)
6847
+ ], PlatformMfaController.prototype, "setup", null);
6848
+ _ts_decorate35([
6849
+ UseGuards(JwtPlatformGuard),
6850
+ Throttle(AUTH_THROTTLE_CONFIGS.mfaVerifyEnable),
6851
+ HttpCode(HttpStatus.NO_CONTENT),
6852
+ Post("verify-enable"),
6853
+ _ts_param19(0, CurrentUser()),
6854
+ _ts_param19(1, Body()),
6855
+ _ts_param19(2, Req()),
6856
+ _ts_metadata35("design:type", Function),
6857
+ _ts_metadata35("design:paramtypes", [
6858
+ typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
6859
+ typeof MfaVerifyDto === "undefined" ? Object : MfaVerifyDto,
6860
+ typeof Request === "undefined" ? Object : Request
6861
+ ]),
6862
+ _ts_metadata35("design:returntype", Promise)
6863
+ ], PlatformMfaController.prototype, "verifyEnable", null);
6864
+ _ts_decorate35([
6865
+ UseGuards(JwtPlatformGuard),
6866
+ Throttle(AUTH_THROTTLE_CONFIGS.mfaDisable),
6867
+ HttpCode(HttpStatus.NO_CONTENT),
6868
+ Post("disable"),
6869
+ _ts_param19(0, CurrentUser()),
6870
+ _ts_param19(1, Body()),
6871
+ _ts_param19(2, Req()),
6872
+ _ts_metadata35("design:type", Function),
6873
+ _ts_metadata35("design:paramtypes", [
6874
+ typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
6875
+ typeof MfaDisableDto === "undefined" ? Object : MfaDisableDto,
6876
+ typeof Request === "undefined" ? Object : Request
6877
+ ]),
6878
+ _ts_metadata35("design:returntype", Promise)
6879
+ ], PlatformMfaController.prototype, "disable", null);
6880
+ _ts_decorate35([
6881
+ UseGuards(JwtPlatformGuard),
6882
+ Throttle(AUTH_THROTTLE_CONFIGS.mfaDisable),
6883
+ HttpCode(HttpStatus.OK),
6884
+ Post("recovery-codes"),
6885
+ _ts_param19(0, CurrentUser()),
6886
+ _ts_param19(1, Body()),
6887
+ _ts_param19(2, Req()),
6888
+ _ts_metadata35("design:type", Function),
6889
+ _ts_metadata35("design:paramtypes", [
6890
+ typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
6891
+ typeof MfaRegenerateRecoveryCodesDto === "undefined" ? Object : MfaRegenerateRecoveryCodesDto,
6892
+ typeof Request === "undefined" ? Object : Request
6893
+ ]),
6894
+ _ts_metadata35("design:returntype", Promise)
6895
+ ], PlatformMfaController.prototype, "regenerateRecoveryCodes", null);
6896
+ PlatformMfaController = _ts_decorate35([
6897
+ Controller("platform/mfa"),
6898
+ UsePipes(new ValidationPipe({
6899
+ whitelist: true,
6900
+ forbidNonWhitelisted: true,
6901
+ forbidUnknownValues: true
6902
+ })),
6903
+ _ts_metadata35("design:type", Function),
6904
+ _ts_metadata35("design:paramtypes", [
6905
+ typeof MfaService === "undefined" ? Object : MfaService
6906
+ ])
6907
+ ], PlatformMfaController);
6908
+ function _ts_decorate36(decorators, target, key, desc) {
6909
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6910
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6911
+ 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;
6912
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6913
+ }
6914
+ __name(_ts_decorate36, "_ts_decorate");
6915
+ function _ts_metadata36(k, v) {
6916
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6917
+ }
6918
+ __name(_ts_metadata36, "_ts_metadata");
6919
+ function _ts_param20(paramIndex, decorator) {
6920
+ return function(target, key) {
6921
+ decorator(target, key, paramIndex);
6922
+ };
6923
+ }
6924
+ __name(_ts_param20, "_ts_param");
6498
6925
  var STATUS_ERROR_MAP = {
6499
6926
  banned: AUTH_ERROR_CODES.ACCOUNT_BANNED,
6500
6927
  inactive: AUTH_ERROR_CODES.ACCOUNT_INACTIVE,
@@ -6542,12 +6969,12 @@ var UserStatusGuard = class {
6542
6969
  return true;
6543
6970
  }
6544
6971
  };
6545
- UserStatusGuard = _ts_decorate34([
6972
+ UserStatusGuard = _ts_decorate36([
6546
6973
  Injectable(),
6547
- _ts_param19(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
6548
- _ts_param19(2, Inject(BYMAX_AUTH_OPTIONS)),
6549
- _ts_metadata34("design:type", Function),
6550
- _ts_metadata34("design:paramtypes", [
6974
+ _ts_param20(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
6975
+ _ts_param20(2, Inject(BYMAX_AUTH_OPTIONS)),
6976
+ _ts_metadata36("design:type", Function),
6977
+ _ts_metadata36("design:paramtypes", [
6551
6978
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
6552
6979
  typeof IUserRepository === "undefined" ? Object : IUserRepository,
6553
6980
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
@@ -6555,23 +6982,23 @@ UserStatusGuard = _ts_decorate34([
6555
6982
  ], UserStatusGuard);
6556
6983
 
6557
6984
  // src/server/controllers/session.controller.ts
6558
- function _ts_decorate35(decorators, target, key, desc) {
6985
+ function _ts_decorate37(decorators, target, key, desc) {
6559
6986
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6560
6987
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6561
6988
  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;
6562
6989
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6563
6990
  }
6564
- __name(_ts_decorate35, "_ts_decorate");
6565
- function _ts_metadata35(k, v) {
6991
+ __name(_ts_decorate37, "_ts_decorate");
6992
+ function _ts_metadata37(k, v) {
6566
6993
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6567
6994
  }
6568
- __name(_ts_metadata35, "_ts_metadata");
6569
- function _ts_param20(paramIndex, decorator) {
6995
+ __name(_ts_metadata37, "_ts_metadata");
6996
+ function _ts_param21(paramIndex, decorator) {
6570
6997
  return function(target, key) {
6571
6998
  decorator(target, key, paramIndex);
6572
6999
  };
6573
7000
  }
6574
- __name(_ts_param20, "_ts_param");
7001
+ __name(_ts_param21, "_ts_param");
6575
7002
  var SessionController = class {
6576
7003
  static {
6577
7004
  __name(this, "SessionController");
@@ -6648,68 +7075,68 @@ var SessionController = class {
6648
7075
  await this.sessionService.revokeSession(user.sub, id);
6649
7076
  }
6650
7077
  };
6651
- _ts_decorate35([
7078
+ _ts_decorate37([
6652
7079
  Throttle(AUTH_THROTTLE_CONFIGS.listSessions),
6653
7080
  Get(),
6654
- _ts_param20(0, CurrentUser()),
6655
- _ts_param20(1, Req()),
6656
- _ts_metadata35("design:type", Function),
6657
- _ts_metadata35("design:paramtypes", [
7081
+ _ts_param21(0, CurrentUser()),
7082
+ _ts_param21(1, Req()),
7083
+ _ts_metadata37("design:type", Function),
7084
+ _ts_metadata37("design:paramtypes", [
6658
7085
  typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
6659
7086
  typeof Request === "undefined" ? Object : Request
6660
7087
  ]),
6661
- _ts_metadata35("design:returntype", Promise)
7088
+ _ts_metadata37("design:returntype", Promise)
6662
7089
  ], SessionController.prototype, "listSessions", null);
6663
- _ts_decorate35([
7090
+ _ts_decorate37([
6664
7091
  Throttle(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
6665
7092
  HttpCode(HttpStatus.NO_CONTENT),
6666
7093
  Delete("all"),
6667
- _ts_param20(0, CurrentUser()),
6668
- _ts_param20(1, Req()),
6669
- _ts_metadata35("design:type", Function),
6670
- _ts_metadata35("design:paramtypes", [
7094
+ _ts_param21(0, CurrentUser()),
7095
+ _ts_param21(1, Req()),
7096
+ _ts_metadata37("design:type", Function),
7097
+ _ts_metadata37("design:paramtypes", [
6671
7098
  typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
6672
7099
  typeof Request === "undefined" ? Object : Request
6673
7100
  ]),
6674
- _ts_metadata35("design:returntype", Promise)
7101
+ _ts_metadata37("design:returntype", Promise)
6675
7102
  ], SessionController.prototype, "revokeAllSessions", null);
6676
- _ts_decorate35([
7103
+ _ts_decorate37([
6677
7104
  Throttle(AUTH_THROTTLE_CONFIGS.revokeSession),
6678
7105
  HttpCode(HttpStatus.NO_CONTENT),
6679
7106
  Delete(":id"),
6680
- _ts_param20(0, CurrentUser()),
6681
- _ts_param20(1, Param("id")),
6682
- _ts_metadata35("design:type", Function),
6683
- _ts_metadata35("design:paramtypes", [
7107
+ _ts_param21(0, CurrentUser()),
7108
+ _ts_param21(1, Param("id")),
7109
+ _ts_metadata37("design:type", Function),
7110
+ _ts_metadata37("design:paramtypes", [
6684
7111
  typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
6685
7112
  String
6686
7113
  ]),
6687
- _ts_metadata35("design:returntype", Promise)
7114
+ _ts_metadata37("design:returntype", Promise)
6688
7115
  ], SessionController.prototype, "revokeSession", null);
6689
- SessionController = _ts_decorate35([
7116
+ SessionController = _ts_decorate37([
6690
7117
  Controller("sessions"),
6691
7118
  UseGuards(JwtAuthGuard, UserStatusGuard),
6692
7119
  UsePipes(new ValidationPipe({
6693
7120
  whitelist: true,
6694
7121
  forbidNonWhitelisted: true
6695
7122
  })),
6696
- _ts_metadata35("design:type", Function),
6697
- _ts_metadata35("design:paramtypes", [
7123
+ _ts_metadata37("design:type", Function),
7124
+ _ts_metadata37("design:paramtypes", [
6698
7125
  typeof SessionService === "undefined" ? Object : SessionService,
6699
7126
  typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService
6700
7127
  ])
6701
7128
  ], SessionController);
6702
- function _ts_decorate36(decorators, target, key, desc) {
7129
+ function _ts_decorate38(decorators, target, key, desc) {
6703
7130
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6704
7131
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6705
7132
  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;
6706
7133
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6707
7134
  }
6708
- __name(_ts_decorate36, "_ts_decorate");
6709
- function _ts_metadata36(k, v) {
7135
+ __name(_ts_decorate38, "_ts_decorate");
7136
+ function _ts_metadata38(k, v) {
6710
7137
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6711
7138
  }
6712
- __name(_ts_metadata36, "_ts_metadata");
7139
+ __name(_ts_metadata38, "_ts_metadata");
6713
7140
  var MfaRequiredGuard = class {
6714
7141
  static {
6715
7142
  __name(this, "MfaRequiredGuard");
@@ -6736,10 +7163,10 @@ var MfaRequiredGuard = class {
6736
7163
  return true;
6737
7164
  }
6738
7165
  };
6739
- MfaRequiredGuard = _ts_decorate36([
7166
+ MfaRequiredGuard = _ts_decorate38([
6740
7167
  Injectable(),
6741
- _ts_metadata36("design:type", Function),
6742
- _ts_metadata36("design:paramtypes", [
7168
+ _ts_metadata38("design:type", Function),
7169
+ _ts_metadata38("design:paramtypes", [
6743
7170
  typeof Reflector === "undefined" ? Object : Reflector
6744
7171
  ])
6745
7172
  ], MfaRequiredGuard);
@@ -6747,23 +7174,23 @@ var PLATFORM_ROLES_KEY = /* @__PURE__ */ Symbol("platformRoles");
6747
7174
  var PlatformRoles = /* @__PURE__ */ __name((...roles) => SetMetadata(PLATFORM_ROLES_KEY, roles), "PlatformRoles");
6748
7175
 
6749
7176
  // src/server/guards/platform-roles.guard.ts
6750
- function _ts_decorate37(decorators, target, key, desc) {
7177
+ function _ts_decorate39(decorators, target, key, desc) {
6751
7178
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6752
7179
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6753
7180
  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;
6754
7181
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6755
7182
  }
6756
- __name(_ts_decorate37, "_ts_decorate");
6757
- function _ts_metadata37(k, v) {
7183
+ __name(_ts_decorate39, "_ts_decorate");
7184
+ function _ts_metadata39(k, v) {
6758
7185
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6759
7186
  }
6760
- __name(_ts_metadata37, "_ts_metadata");
6761
- function _ts_param21(paramIndex, decorator) {
7187
+ __name(_ts_metadata39, "_ts_metadata");
7188
+ function _ts_param22(paramIndex, decorator) {
6762
7189
  return function(target, key) {
6763
7190
  decorator(target, key, paramIndex);
6764
7191
  };
6765
7192
  }
6766
- __name(_ts_param21, "_ts_param");
7193
+ __name(_ts_param22, "_ts_param");
6767
7194
  var PlatformRolesGuard = class {
6768
7195
  static {
6769
7196
  __name(this, "PlatformRolesGuard");
@@ -6797,11 +7224,11 @@ var PlatformRolesGuard = class {
6797
7224
  return true;
6798
7225
  }
6799
7226
  };
6800
- PlatformRolesGuard = _ts_decorate37([
7227
+ PlatformRolesGuard = _ts_decorate39([
6801
7228
  Injectable(),
6802
- _ts_param21(1, Inject(BYMAX_AUTH_OPTIONS)),
6803
- _ts_metadata37("design:type", Function),
6804
- _ts_metadata37("design:paramtypes", [
7229
+ _ts_param22(1, Inject(BYMAX_AUTH_OPTIONS)),
7230
+ _ts_metadata39("design:type", Function),
7231
+ _ts_metadata39("design:paramtypes", [
6805
7232
  typeof Reflector === "undefined" ? Object : Reflector,
6806
7233
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
6807
7234
  ])
@@ -6810,23 +7237,23 @@ var ROLES_KEY = "roles";
6810
7237
  var Roles = /* @__PURE__ */ __name((...roles) => SetMetadata(ROLES_KEY, roles), "Roles");
6811
7238
 
6812
7239
  // src/server/guards/roles.guard.ts
6813
- function _ts_decorate38(decorators, target, key, desc) {
7240
+ function _ts_decorate40(decorators, target, key, desc) {
6814
7241
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6815
7242
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6816
7243
  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;
6817
7244
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6818
7245
  }
6819
- __name(_ts_decorate38, "_ts_decorate");
6820
- function _ts_metadata38(k, v) {
7246
+ __name(_ts_decorate40, "_ts_decorate");
7247
+ function _ts_metadata40(k, v) {
6821
7248
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6822
7249
  }
6823
- __name(_ts_metadata38, "_ts_metadata");
6824
- function _ts_param22(paramIndex, decorator) {
7250
+ __name(_ts_metadata40, "_ts_metadata");
7251
+ function _ts_param23(paramIndex, decorator) {
6825
7252
  return function(target, key) {
6826
7253
  decorator(target, key, paramIndex);
6827
7254
  };
6828
7255
  }
6829
- __name(_ts_param22, "_ts_param");
7256
+ __name(_ts_param23, "_ts_param");
6830
7257
  var RolesGuard = class {
6831
7258
  static {
6832
7259
  __name(this, "RolesGuard");
@@ -6856,22 +7283,22 @@ var RolesGuard = class {
6856
7283
  return true;
6857
7284
  }
6858
7285
  };
6859
- RolesGuard = _ts_decorate38([
7286
+ RolesGuard = _ts_decorate40([
6860
7287
  Injectable(),
6861
- _ts_param22(1, Inject(BYMAX_AUTH_OPTIONS)),
6862
- _ts_metadata38("design:type", Function),
6863
- _ts_metadata38("design:paramtypes", [
7288
+ _ts_param23(1, Inject(BYMAX_AUTH_OPTIONS)),
7289
+ _ts_metadata40("design:type", Function),
7290
+ _ts_metadata40("design:paramtypes", [
6864
7291
  typeof Reflector === "undefined" ? Object : Reflector,
6865
7292
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
6866
7293
  ])
6867
7294
  ], RolesGuard);
6868
- function _ts_decorate39(decorators, target, key, desc) {
7295
+ function _ts_decorate41(decorators, target, key, desc) {
6869
7296
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6870
7297
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6871
7298
  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;
6872
7299
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6873
7300
  }
6874
- __name(_ts_decorate39, "_ts_decorate");
7301
+ __name(_ts_decorate41, "_ts_decorate");
6875
7302
  var NoOpAuthHooks = class {
6876
7303
  static {
6877
7304
  __name(this, "NoOpAuthHooks");
@@ -6911,29 +7338,29 @@ var NoOpAuthHooks = class {
6911
7338
  };
6912
7339
  }
6913
7340
  };
6914
- NoOpAuthHooks = _ts_decorate39([
7341
+ NoOpAuthHooks = _ts_decorate41([
6915
7342
  Injectable()
6916
7343
  ], NoOpAuthHooks);
6917
7344
 
6918
7345
  // src/server/oauth/oauth.constants.ts
6919
7346
  var OAUTH_PLUGINS = /* @__PURE__ */ Symbol("OAUTH_PLUGINS");
6920
- function _ts_decorate40(decorators, target, key, desc) {
7347
+ function _ts_decorate42(decorators, target, key, desc) {
6921
7348
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6922
7349
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6923
7350
  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;
6924
7351
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6925
7352
  }
6926
- __name(_ts_decorate40, "_ts_decorate");
6927
- function _ts_metadata39(k, v) {
7353
+ __name(_ts_decorate42, "_ts_decorate");
7354
+ function _ts_metadata41(k, v) {
6928
7355
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
6929
7356
  }
6930
- __name(_ts_metadata39, "_ts_metadata");
6931
- function _ts_param23(paramIndex, decorator) {
7357
+ __name(_ts_metadata41, "_ts_metadata");
7358
+ function _ts_param24(paramIndex, decorator) {
6932
7359
  return function(target, key) {
6933
7360
  decorator(target, key, paramIndex);
6934
7361
  };
6935
7362
  }
6936
- __name(_ts_param23, "_ts_param");
7363
+ __name(_ts_param24, "_ts_param");
6937
7364
  var OAUTH_STATE_TTL_SECONDS = 600;
6938
7365
  function isStoredOAuthState(value) {
6939
7366
  if (typeof value !== "object" || value === null) return false;
@@ -7038,7 +7465,10 @@ var OAuthService = class _OAuthService {
7038
7465
  * @param ip - Client IP for session audit (truncated to 64 chars).
7039
7466
  * @param userAgent - User-Agent string for session audit.
7040
7467
  * @param headers - Raw request headers passed to the `onOAuthLogin` hook context.
7041
- * @returns Full `AuthResult` with access token, refresh token, and safe user record.
7468
+ * @returns Full `AuthResult` with access token, refresh token, and safe user record,
7469
+ * OR an `OAuthMfaChallengeResult` with `mfaRequired: true` and a short-lived MFA
7470
+ * temp token when the resolved user has MFA enabled. The caller routes the two
7471
+ * shapes to different responses (session cookies vs MFA-challenge cookie/redirect).
7042
7472
  * @throws `AuthException(OAUTH_FAILED)` when state is invalid, expired, or the hook rejects.
7043
7473
  */
7044
7474
  async handleCallback(provider, code, state, ip, userAgent, headers) {
@@ -7109,6 +7539,14 @@ var OAuthService = class _OAuthService {
7109
7539
  throw new AuthException(AUTH_ERROR_CODES.OAUTH_FAILED);
7110
7540
  }
7111
7541
  }
7542
+ if (authUser.mfaEnabled) {
7543
+ const mfaTempToken = await this.tokenManager.issueMfaTempToken(authUser.id, "dashboard");
7544
+ this.logger.log(`handleCallback: OAuth MFA challenge issued provider=${provider} userId=${authUser.id} tenantId=${tenantId} action=${hookResult.action}`);
7545
+ return {
7546
+ mfaRequired: true,
7547
+ mfaTempToken
7548
+ };
7549
+ }
7112
7550
  const safeUser = toSafeUser4(authUser);
7113
7551
  const result = await this.tokenManager.issueTokens(safeUser, ip, userAgent);
7114
7552
  if (this.options.sessions.enabled) {
@@ -7143,15 +7581,15 @@ var OAuthService = class _OAuthService {
7143
7581
  return plugin;
7144
7582
  }
7145
7583
  };
7146
- OAuthService = _ts_decorate40([
7584
+ OAuthService = _ts_decorate42([
7147
7585
  Injectable(),
7148
- _ts_param23(0, Inject(OAUTH_PLUGINS)),
7149
- _ts_param23(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
7150
- _ts_param23(2, Inject(BYMAX_AUTH_HOOKS)),
7151
- _ts_param23(2, Optional()),
7152
- _ts_param23(6, Inject(BYMAX_AUTH_OPTIONS)),
7153
- _ts_metadata39("design:type", Function),
7154
- _ts_metadata39("design:paramtypes", [
7586
+ _ts_param24(0, Inject(OAUTH_PLUGINS)),
7587
+ _ts_param24(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
7588
+ _ts_param24(2, Inject(BYMAX_AUTH_HOOKS)),
7589
+ _ts_param24(2, Optional()),
7590
+ _ts_param24(6, Inject(BYMAX_AUTH_OPTIONS)),
7591
+ _ts_metadata41("design:type", Function),
7592
+ _ts_metadata41("design:paramtypes", [
7155
7593
  Array,
7156
7594
  typeof IUserRepository === "undefined" ? Object : IUserRepository,
7157
7595
  Object,
@@ -7161,17 +7599,17 @@ OAuthService = _ts_decorate40([
7161
7599
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
7162
7600
  ])
7163
7601
  ], OAuthService);
7164
- function _ts_decorate41(decorators, target, key, desc) {
7602
+ function _ts_decorate43(decorators, target, key, desc) {
7165
7603
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7166
7604
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7167
7605
  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;
7168
7606
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7169
7607
  }
7170
- __name(_ts_decorate41, "_ts_decorate");
7171
- function _ts_metadata40(k, v) {
7608
+ __name(_ts_decorate43, "_ts_decorate");
7609
+ function _ts_metadata42(k, v) {
7172
7610
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
7173
7611
  }
7174
- __name(_ts_metadata40, "_ts_metadata");
7612
+ __name(_ts_metadata42, "_ts_metadata");
7175
7613
  var OAuthCallbackQueryDto = class {
7176
7614
  static {
7177
7615
  __name(this, "OAuthCallbackQueryDto");
@@ -7225,59 +7663,59 @@ var OAuthCallbackQueryDto = class {
7225
7663
  */
7226
7664
  hd;
7227
7665
  };
7228
- _ts_decorate41([
7666
+ _ts_decorate43([
7229
7667
  IsString(),
7230
7668
  IsNotEmpty(),
7231
7669
  MaxLength(2048),
7232
- _ts_metadata40("design:type", String)
7670
+ _ts_metadata42("design:type", String)
7233
7671
  ], OAuthCallbackQueryDto.prototype, "code", void 0);
7234
- _ts_decorate41([
7672
+ _ts_decorate43([
7235
7673
  IsString(),
7236
7674
  IsNotEmpty(),
7237
7675
  MaxLength(128),
7238
- _ts_metadata40("design:type", String)
7676
+ _ts_metadata42("design:type", String)
7239
7677
  ], OAuthCallbackQueryDto.prototype, "state", void 0);
7240
- _ts_decorate41([
7678
+ _ts_decorate43([
7241
7679
  IsOptional(),
7242
7680
  IsString(),
7243
7681
  MaxLength(512),
7244
- _ts_metadata40("design:type", String)
7682
+ _ts_metadata42("design:type", String)
7245
7683
  ], OAuthCallbackQueryDto.prototype, "iss", void 0);
7246
- _ts_decorate41([
7684
+ _ts_decorate43([
7247
7685
  IsOptional(),
7248
7686
  IsString(),
7249
7687
  MaxLength(2048),
7250
- _ts_metadata40("design:type", String)
7688
+ _ts_metadata42("design:type", String)
7251
7689
  ], OAuthCallbackQueryDto.prototype, "scope", void 0);
7252
- _ts_decorate41([
7690
+ _ts_decorate43([
7253
7691
  IsOptional(),
7254
7692
  IsString(),
7255
7693
  MaxLength(16),
7256
- _ts_metadata40("design:type", String)
7694
+ _ts_metadata42("design:type", String)
7257
7695
  ], OAuthCallbackQueryDto.prototype, "authuser", void 0);
7258
- _ts_decorate41([
7696
+ _ts_decorate43([
7259
7697
  IsOptional(),
7260
7698
  IsString(),
7261
7699
  MaxLength(64),
7262
- _ts_metadata40("design:type", String)
7700
+ _ts_metadata42("design:type", String)
7263
7701
  ], OAuthCallbackQueryDto.prototype, "prompt", void 0);
7264
- _ts_decorate41([
7702
+ _ts_decorate43([
7265
7703
  IsOptional(),
7266
7704
  IsString(),
7267
7705
  MaxLength(253),
7268
- _ts_metadata40("design:type", String)
7706
+ _ts_metadata42("design:type", String)
7269
7707
  ], OAuthCallbackQueryDto.prototype, "hd", void 0);
7270
- function _ts_decorate42(decorators, target, key, desc) {
7708
+ function _ts_decorate44(decorators, target, key, desc) {
7271
7709
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7272
7710
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7273
7711
  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;
7274
7712
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7275
7713
  }
7276
- __name(_ts_decorate42, "_ts_decorate");
7277
- function _ts_metadata41(k, v) {
7714
+ __name(_ts_decorate44, "_ts_decorate");
7715
+ function _ts_metadata43(k, v) {
7278
7716
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
7279
7717
  }
7280
- __name(_ts_metadata41, "_ts_metadata");
7718
+ __name(_ts_metadata43, "_ts_metadata");
7281
7719
  var OAuthInitiateQueryDto = class {
7282
7720
  static {
7283
7721
  __name(this, "OAuthInitiateQueryDto");
@@ -7294,31 +7732,61 @@ var OAuthInitiateQueryDto = class {
7294
7732
  */
7295
7733
  tenantId;
7296
7734
  };
7297
- _ts_decorate42([
7735
+ _ts_decorate44([
7298
7736
  IsString(),
7299
7737
  IsNotEmpty(),
7300
7738
  MaxLength(128),
7301
- _ts_metadata41("design:type", String)
7739
+ _ts_metadata43("design:type", String)
7302
7740
  ], OAuthInitiateQueryDto.prototype, "tenantId", void 0);
7303
7741
 
7304
7742
  // src/server/oauth/oauth.controller.ts
7305
- function _ts_decorate43(decorators, target, key, desc) {
7743
+ function _ts_decorate45(decorators, target, key, desc) {
7306
7744
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7307
7745
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7308
7746
  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;
7309
7747
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7310
7748
  }
7311
- __name(_ts_decorate43, "_ts_decorate");
7312
- function _ts_metadata42(k, v) {
7749
+ __name(_ts_decorate45, "_ts_decorate");
7750
+ function _ts_metadata44(k, v) {
7313
7751
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
7314
7752
  }
7315
- __name(_ts_metadata42, "_ts_metadata");
7316
- function _ts_param24(paramIndex, decorator) {
7753
+ __name(_ts_metadata44, "_ts_metadata");
7754
+ function _ts_param25(paramIndex, decorator) {
7317
7755
  return function(target, key) {
7318
7756
  decorator(target, key, paramIndex);
7319
7757
  };
7320
7758
  }
7321
- __name(_ts_param24, "_ts_param");
7759
+ __name(_ts_param25, "_ts_param");
7760
+ function isOAuthMfaChallenge(result) {
7761
+ return "mfaRequired" in result && result.mfaRequired === true;
7762
+ }
7763
+ __name(isOAuthMfaChallenge, "isOAuthMfaChallenge");
7764
+ function extractErrorCode(exception) {
7765
+ const response = exception.getResponse();
7766
+ if (typeof response !== "object" || response === null) {
7767
+ return "oauth_failed";
7768
+ }
7769
+ const envelope = response;
7770
+ const code = envelope.error?.code;
7771
+ if (typeof code !== "string" || code.length === 0) {
7772
+ return "oauth_failed";
7773
+ }
7774
+ const dotIndex = code.indexOf(".");
7775
+ return dotIndex >= 0 ? code.slice(dotIndex + 1) : code;
7776
+ }
7777
+ __name(extractErrorCode, "extractErrorCode");
7778
+ function appendErrorQueryParam(url, errorCode) {
7779
+ if (url.startsWith("/")) {
7780
+ const dummyBase = "http://placeholder.invalid";
7781
+ const parsed2 = new URL(url, dummyBase);
7782
+ parsed2.searchParams.set("error", errorCode);
7783
+ return parsed2.pathname + parsed2.search + parsed2.hash;
7784
+ }
7785
+ const parsed = new URL(url);
7786
+ parsed.searchParams.set("error", errorCode);
7787
+ return parsed.toString();
7788
+ }
7789
+ __name(appendErrorQueryParam, "appendErrorQueryParam");
7322
7790
  var OAuthController = class {
7323
7791
  static {
7324
7792
  __name(this, "OAuthController");
@@ -7370,16 +7838,50 @@ var OAuthController = class {
7370
7838
  * `res.redirect()` and returning `undefined`, which Nest passes through
7371
7839
  * unchanged (passthrough mode is active).
7372
7840
  *
7841
+ * If the resolved user has MFA enabled, the controller plants a short-lived
7842
+ * HttpOnly `mfa_temp_token` cookie (path-scoped to `/auth/mfa`) and either
7843
+ * redirects to `oauth.mfaRedirectUrl` (when configured) or returns the temp
7844
+ * token in the JSON body. The user completes the MFA challenge via
7845
+ * `POST /auth/mfa/challenge` to obtain real session tokens.
7846
+ *
7847
+ * On `AuthException` errors, redirects to `oauth.errorRedirectUrl` (when
7848
+ * configured) with `?error=<code>` instead of propagating the exception.
7849
+ * Non-`AuthException` errors propagate so they surface to monitoring.
7850
+ *
7373
7851
  * @param provider - Provider name from the URL path (e.g. `'google'`).
7374
7852
  * @param query - Validated query parameters (contains `code` and `state`).
7375
7853
  * @param req - Incoming request (IP, User-Agent, and cookie context for token delivery).
7376
7854
  * @param res - Express response in passthrough mode (used for cookie delivery and the optional redirect).
7377
- * @returns The auth response shaped by `tokenDelivery`, or `undefined` when a `successRedirectUrl` redirect was issued.
7855
+ * @returns The auth response shaped by `tokenDelivery`, the MFA challenge
7856
+ * payload, or `undefined` when a redirect was issued.
7378
7857
  */
7379
7858
  async callback(provider, query, req, res) {
7380
7859
  const ip = (req.ip ?? "").slice(0, 64);
7381
7860
  const userAgent = String(req.headers["user-agent"] ?? "").slice(0, 512);
7382
- const result = await this.oauthService.handleCallback(provider, query.code, query.state, ip, userAgent, req.headers);
7861
+ let result;
7862
+ try {
7863
+ result = await this.oauthService.handleCallback(provider, query.code, query.state, ip, userAgent, req.headers);
7864
+ } catch (err) {
7865
+ if (err instanceof AuthException && this.options.oauth?.errorRedirectUrl !== void 0) {
7866
+ const errorCode = extractErrorCode(err);
7867
+ const redirectTo = appendErrorQueryParam(this.options.oauth.errorRedirectUrl, errorCode);
7868
+ res.redirect(redirectTo);
7869
+ return void 0;
7870
+ }
7871
+ throw err;
7872
+ }
7873
+ if (isOAuthMfaChallenge(result)) {
7874
+ this.setMfaTempCookie(res, result.mfaTempToken);
7875
+ const mfaRedirectUrl = this.options.oauth?.mfaRedirectUrl;
7876
+ if (mfaRedirectUrl !== void 0) {
7877
+ res.redirect(mfaRedirectUrl);
7878
+ return void 0;
7879
+ }
7880
+ return {
7881
+ mfaRequired: true,
7882
+ mfaTempToken: result.mfaTempToken
7883
+ };
7884
+ }
7383
7885
  const body = this.tokenDelivery.deliverAuthResponse(res, result, req);
7384
7886
  const redirectUrl = this.options.oauth?.successRedirectUrl;
7385
7887
  if (redirectUrl !== void 0) {
@@ -7388,43 +7890,73 @@ var OAuthController = class {
7388
7890
  }
7389
7891
  return body;
7390
7892
  }
7893
+ // ---------------------------------------------------------------------------
7894
+ // Private helpers
7895
+ // ---------------------------------------------------------------------------
7896
+ /**
7897
+ * Plants the short-lived `mfa_temp_token` HttpOnly cookie on the response.
7898
+ *
7899
+ * Cookie attributes:
7900
+ * - `HttpOnly`: not readable from JavaScript. The cookie is consumed by the
7901
+ * server-side challenge route, not by any client code.
7902
+ * - `Secure`: derived from `secureCookies` (true in production by default).
7903
+ * - `SameSite`: derived from `cookies.sameSite` (defaults to `'lax'`).
7904
+ * - `Path`: scoped to the MFA challenge endpoint so the cookie is never sent
7905
+ * on unrelated requests. Built by concatenating `routePrefix` and `/mfa`
7906
+ * so consumers with a custom prefix (e.g. `api/auth`) still get the right
7907
+ * scope.
7908
+ * - `Max-Age`: 300 seconds — exactly matches the underlying MFA temp JWT
7909
+ * TTL (`MFA_TEMP_TOKEN_TTL_SECONDS` in `token-manager.service.ts`).
7910
+ * Keeping the two TTLs identical avoids the failure mode where the
7911
+ * cookie survives the JWT and the user sees `MFA_TEMP_TOKEN_INVALID`
7912
+ * on a request that otherwise looked legitimate.
7913
+ */
7914
+ setMfaTempCookie(res, mfaTempToken) {
7915
+ res.cookie(MFA_TEMP_COOKIE_NAME, mfaTempToken, {
7916
+ httpOnly: true,
7917
+ secure: this.options.secureCookies,
7918
+ sameSite: this.options.cookies.sameSite,
7919
+ path: `/${this.options.routePrefix}/mfa`,
7920
+ maxAge: MFA_TEMP_COOKIE_MAX_AGE_SECONDS * 1e3
7921
+ });
7922
+ }
7391
7923
  };
7392
- _ts_decorate43([
7924
+ _ts_decorate45([
7393
7925
  Throttle(AUTH_THROTTLE_CONFIGS.oauthInitiate),
7394
7926
  Get(":provider"),
7395
- _ts_param24(0, Param("provider")),
7396
- _ts_param24(1, Query()),
7397
- _ts_param24(2, Res({
7927
+ _ts_param25(0, Param("provider")),
7928
+ _ts_param25(1, Query()),
7929
+ _ts_param25(2, Res({
7398
7930
  passthrough: true
7399
7931
  })),
7400
- _ts_metadata42("design:type", Function),
7401
- _ts_metadata42("design:paramtypes", [
7932
+ _ts_metadata44("design:type", Function),
7933
+ _ts_metadata44("design:paramtypes", [
7402
7934
  String,
7403
7935
  typeof OAuthInitiateQueryDto === "undefined" ? Object : OAuthInitiateQueryDto,
7404
7936
  typeof Response === "undefined" ? Object : Response
7405
7937
  ]),
7406
- _ts_metadata42("design:returntype", Promise)
7938
+ _ts_metadata44("design:returntype", Promise)
7407
7939
  ], OAuthController.prototype, "initiate", null);
7408
- _ts_decorate43([
7940
+ _ts_decorate45([
7409
7941
  Throttle(AUTH_THROTTLE_CONFIGS.oauthCallback),
7410
7942
  HttpCode(HttpStatus.OK),
7411
7943
  Get(":provider/callback"),
7412
- _ts_param24(0, Param("provider")),
7413
- _ts_param24(1, Query()),
7414
- _ts_param24(2, Req()),
7415
- _ts_param24(3, Res({
7944
+ _ts_param25(0, Param("provider")),
7945
+ _ts_param25(1, Query()),
7946
+ _ts_param25(2, Req()),
7947
+ _ts_param25(3, Res({
7416
7948
  passthrough: true
7417
7949
  })),
7418
- _ts_metadata42("design:type", Function),
7419
- _ts_metadata42("design:paramtypes", [
7950
+ _ts_metadata44("design:type", Function),
7951
+ _ts_metadata44("design:paramtypes", [
7420
7952
  String,
7421
7953
  typeof OAuthCallbackQueryDto === "undefined" ? Object : OAuthCallbackQueryDto,
7422
7954
  typeof Request === "undefined" ? Object : Request,
7423
7955
  typeof Response === "undefined" ? Object : Response
7424
7956
  ]),
7425
- _ts_metadata42("design:returntype", Promise)
7957
+ _ts_metadata44("design:returntype", Promise)
7426
7958
  ], OAuthController.prototype, "callback", null);
7427
- OAuthController = _ts_decorate43([
7959
+ OAuthController = _ts_decorate45([
7428
7960
  Public(),
7429
7961
  SkipMfa(),
7430
7962
  Controller("oauth"),
@@ -7433,9 +7965,9 @@ OAuthController = _ts_decorate43([
7433
7965
  forbidNonWhitelisted: true,
7434
7966
  forbidUnknownValues: true
7435
7967
  })),
7436
- _ts_param24(2, Inject(BYMAX_AUTH_OPTIONS)),
7437
- _ts_metadata42("design:type", Function),
7438
- _ts_metadata42("design:paramtypes", [
7968
+ _ts_param25(2, Inject(BYMAX_AUTH_OPTIONS)),
7969
+ _ts_metadata44("design:type", Function),
7970
+ _ts_metadata44("design:paramtypes", [
7439
7971
  typeof OAuthService === "undefined" ? Object : OAuthService,
7440
7972
  typeof TokenDeliveryService === "undefined" ? Object : TokenDeliveryService,
7441
7973
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
@@ -7571,13 +8103,13 @@ var GoogleOAuthPlugin = class {
7571
8103
  };
7572
8104
 
7573
8105
  // src/server/oauth/oauth.module.ts
7574
- function _ts_decorate44(decorators, target, key, desc) {
8106
+ function _ts_decorate46(decorators, target, key, desc) {
7575
8107
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7576
8108
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7577
8109
  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;
7578
8110
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7579
8111
  }
7580
- __name(_ts_decorate44, "_ts_decorate");
8112
+ __name(_ts_decorate46, "_ts_decorate");
7581
8113
  function buildOAuthPlugins(options) {
7582
8114
  const plugins = [];
7583
8115
  if (options.oauth?.google) {
@@ -7647,16 +8179,16 @@ var OAuthModule = class _OAuthModule {
7647
8179
  };
7648
8180
  }
7649
8181
  };
7650
- OAuthModule = _ts_decorate44([
8182
+ OAuthModule = _ts_decorate46([
7651
8183
  Module({})
7652
8184
  ], OAuthModule);
7653
- function _ts_decorate45(decorators, target, key, desc) {
8185
+ function _ts_decorate47(decorators, target, key, desc) {
7654
8186
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7655
8187
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7656
8188
  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;
7657
8189
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7658
8190
  }
7659
- __name(_ts_decorate45, "_ts_decorate");
8191
+ __name(_ts_decorate47, "_ts_decorate");
7660
8192
  var NoOpEmailProvider = class _NoOpEmailProvider {
7661
8193
  static {
7662
8194
  __name(this, "NoOpEmailProvider");
@@ -7691,18 +8223,18 @@ var NoOpEmailProvider = class _NoOpEmailProvider {
7691
8223
  this.logger.log(`sendInvitation \u2192 ${email} (no-op)`);
7692
8224
  }
7693
8225
  };
7694
- NoOpEmailProvider = _ts_decorate45([
8226
+ NoOpEmailProvider = _ts_decorate47([
7695
8227
  Injectable()
7696
8228
  ], NoOpEmailProvider);
7697
8229
 
7698
8230
  // src/server/bymax-auth.module.ts
7699
- function _ts_decorate46(decorators, target, key, desc) {
8231
+ function _ts_decorate48(decorators, target, key, desc) {
7700
8232
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7701
8233
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7702
8234
  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;
7703
8235
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7704
8236
  }
7705
- __name(_ts_decorate46, "_ts_decorate");
8237
+ __name(_ts_decorate48, "_ts_decorate");
7706
8238
  function hasProviderToken(providers, token) {
7707
8239
  return providers.some((p) => {
7708
8240
  if (typeof p === "function") return false;
@@ -7796,7 +8328,8 @@ var BymaxAuthModule = class _BymaxAuthModule {
7796
8328
  SessionController
7797
8329
  ] : [],
7798
8330
  ...includePlatform ? [
7799
- PlatformAuthController
8331
+ PlatformAuthController,
8332
+ PlatformMfaController
7800
8333
  ] : [],
7801
8334
  ...includeOAuth ? [
7802
8335
  OAuthController
@@ -7948,16 +8481,16 @@ var BymaxAuthModule = class _BymaxAuthModule {
7948
8481
  };
7949
8482
  }
7950
8483
  };
7951
- BymaxAuthModule = _ts_decorate46([
8484
+ BymaxAuthModule = _ts_decorate48([
7952
8485
  Module({})
7953
8486
  ], BymaxAuthModule);
7954
- function _ts_decorate47(decorators, target, key, desc) {
8487
+ function _ts_decorate49(decorators, target, key, desc) {
7955
8488
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7956
8489
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7957
8490
  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;
7958
8491
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7959
8492
  }
7960
- __name(_ts_decorate47, "_ts_decorate");
8493
+ __name(_ts_decorate49, "_ts_decorate");
7961
8494
  var OptionalAuthGuard = class extends JwtAuthGuard {
7962
8495
  static {
7963
8496
  __name(this, "OptionalAuthGuard");
@@ -7972,26 +8505,26 @@ var OptionalAuthGuard = class extends JwtAuthGuard {
7972
8505
  return super.canActivate(context);
7973
8506
  }
7974
8507
  };
7975
- OptionalAuthGuard = _ts_decorate47([
8508
+ OptionalAuthGuard = _ts_decorate49([
7976
8509
  Injectable()
7977
8510
  ], OptionalAuthGuard);
7978
- function _ts_decorate48(decorators, target, key, desc) {
8511
+ function _ts_decorate50(decorators, target, key, desc) {
7979
8512
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7980
8513
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7981
8514
  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;
7982
8515
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7983
8516
  }
7984
- __name(_ts_decorate48, "_ts_decorate");
7985
- function _ts_metadata43(k, v) {
8517
+ __name(_ts_decorate50, "_ts_decorate");
8518
+ function _ts_metadata45(k, v) {
7986
8519
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
7987
8520
  }
7988
- __name(_ts_metadata43, "_ts_metadata");
7989
- function _ts_param25(paramIndex, decorator) {
8521
+ __name(_ts_metadata45, "_ts_metadata");
8522
+ function _ts_param26(paramIndex, decorator) {
7990
8523
  return function(target, key) {
7991
8524
  decorator(target, key, paramIndex);
7992
8525
  };
7993
8526
  }
7994
- __name(_ts_param25, "_ts_param");
8527
+ __name(_ts_param26, "_ts_param");
7995
8528
  var SelfOrAdminGuard = class {
7996
8529
  static {
7997
8530
  __name(this, "SelfOrAdminGuard");
@@ -8021,11 +8554,11 @@ var SelfOrAdminGuard = class {
8021
8554
  throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE, HttpStatus.FORBIDDEN);
8022
8555
  }
8023
8556
  };
8024
- SelfOrAdminGuard = _ts_decorate48([
8557
+ SelfOrAdminGuard = _ts_decorate50([
8025
8558
  Injectable(),
8026
- _ts_param25(0, Inject(BYMAX_AUTH_OPTIONS)),
8027
- _ts_metadata43("design:type", Function),
8028
- _ts_metadata43("design:paramtypes", [
8559
+ _ts_param26(0, Inject(BYMAX_AUTH_OPTIONS)),
8560
+ _ts_metadata45("design:type", Function),
8561
+ _ts_metadata45("design:paramtypes", [
8029
8562
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
8030
8563
  ])
8031
8564
  ], SelfOrAdminGuard);
@@ -8038,23 +8571,23 @@ function isHexLooking(value) {
8038
8571
  return value.length === 64 && /^[a-fA-F0-9]{64}$/.test(value);
8039
8572
  }
8040
8573
  __name(isHexLooking, "isHexLooking");
8041
- function _ts_decorate49(decorators, target, key, desc) {
8574
+ function _ts_decorate51(decorators, target, key, desc) {
8042
8575
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8043
8576
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8044
8577
  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;
8045
8578
  return c > 3 && r && Object.defineProperty(target, key, r), r;
8046
8579
  }
8047
- __name(_ts_decorate49, "_ts_decorate");
8048
- function _ts_metadata44(k, v) {
8580
+ __name(_ts_decorate51, "_ts_decorate");
8581
+ function _ts_metadata46(k, v) {
8049
8582
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
8050
8583
  }
8051
- __name(_ts_metadata44, "_ts_metadata");
8052
- function _ts_param26(paramIndex, decorator) {
8584
+ __name(_ts_metadata46, "_ts_metadata");
8585
+ function _ts_param27(paramIndex, decorator) {
8053
8586
  return function(target, key) {
8054
8587
  decorator(target, key, paramIndex);
8055
8588
  };
8056
8589
  }
8057
- __name(_ts_param26, "_ts_param");
8590
+ __name(_ts_param27, "_ts_param");
8058
8591
  var WsJwtGuard = class {
8059
8592
  static {
8060
8593
  __name(this, "WsJwtGuard");
@@ -8103,15 +8636,15 @@ var WsJwtGuard = class {
8103
8636
  return true;
8104
8637
  }
8105
8638
  };
8106
- WsJwtGuard = _ts_decorate49([
8639
+ WsJwtGuard = _ts_decorate51([
8107
8640
  Injectable(),
8108
- _ts_param26(2, Inject(BYMAX_AUTH_OPTIONS)),
8109
- _ts_metadata44("design:type", Function),
8110
- _ts_metadata44("design:paramtypes", [
8641
+ _ts_param27(2, Inject(BYMAX_AUTH_OPTIONS)),
8642
+ _ts_metadata46("design:type", Function),
8643
+ _ts_metadata46("design:paramtypes", [
8111
8644
  typeof JwtService === "undefined" ? Object : JwtService,
8112
8645
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
8113
8646
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
8114
8647
  ])
8115
8648
  ], WsJwtGuard);
8116
8649
 
8117
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AuthException, AuthService, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BymaxAuthModule, CreateInvitationDto, CurrentUser, ForgotPasswordDto, IS_PUBLIC_KEY, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, SessionService, SkipMfa, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };
8650
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AuthException, AuthService, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BymaxAuthModule, CreateInvitationDto, CurrentUser, ForgotPasswordDto, IS_PUBLIC_KEY, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, SessionService, SkipMfa, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };