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