@bymax-one/nest-auth 1.4.1 → 1.4.3

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.
@@ -21,6 +21,7 @@ var BYMAX_AUTH_EMAIL_PROVIDER = /* @__PURE__ */ Symbol("BYMAX_AUTH_EMAIL_PROVIDE
21
21
  var BYMAX_AUTH_HOOKS = /* @__PURE__ */ Symbol("BYMAX_AUTH_HOOKS");
22
22
  var BYMAX_AUTH_BREACH_CHECKER = /* @__PURE__ */ Symbol("BYMAX_AUTH_BREACH_CHECKER");
23
23
  var BYMAX_AUTH_REDIS_CLIENT = /* @__PURE__ */ Symbol("BYMAX_AUTH_REDIS_CLIENT");
24
+ var BYMAX_AUTH_REGISTERED_CONTROLLERS = /* @__PURE__ */ Symbol("BYMAX_AUTH_REGISTERED_CONTROLLERS");
24
25
 
25
26
  // src/server/config/default-options.ts
26
27
  var DEFAULT_OPTIONS = {
@@ -1078,7 +1079,7 @@ var AUTH_THROTTLE_CONFIGS = {
1078
1079
  ttl: 6e4
1079
1080
  }
1080
1081
  },
1081
- /** DELETE /auth/sessions/all — 5 requests per minute per IP. */
1082
+ /** POST /auth/sessions/revoke-all — 5 requests per minute per IP. */
1082
1083
  revokeAllSessions: {
1083
1084
  default: {
1084
1085
  limit: 5,
@@ -5338,7 +5339,21 @@ var TokenManagerService = class _TokenManagerService {
5338
5339
  * The `status` claim in the issued access token is intentionally empty during
5339
5340
  * rotation — the Redis session does not store full user data. Guards that enforce
5340
5341
  * status checks must read from the user repository or a status cache, not the
5341
- * JWT `status` claim.
5342
+ * JWT `status` claim. `rust-auth` stamps the same empty string at the same point, with a
5343
+ * test pinning it, so this is a shared contract rather than a local shortcut.
5344
+ *
5345
+ * **What that means for a consumer, which is where the cost lands.** `issueTokens` stamps the
5346
+ * account's value at that moment, this path stamps nothing, and `AuthService.refresh` re-stamps
5347
+ * it from the account when `role`, `tenantId` or `mfaEnabled` changed — so a session's tokens
5348
+ * carry a populated claim, then an empty one, then possibly a populated one again, with no
5349
+ * signal a client can read. A derived backend reading `request.user.status` is wrong in both
5350
+ * directions: `!== 'active'` refuses everyone whose session refreshed ordinarily, and
5351
+ * `=== 'suspended'` refuses nobody, ever.
5352
+ *
5353
+ * Backfilling it here would be worse than leaving it empty: the claim would become *usually*
5354
+ * true, which is the failure mode that survives testing, since status can still change under an
5355
+ * unexpired token. The claim cannot be authoritative, so it is not made to look like it — and
5356
+ * the empty string is the one state that cannot be mistaken for an answer.
5342
5357
  *
5343
5358
  * `mfaVerified` is always `false` after rotation because the Redis session does not
5344
5359
  * persist MFA verification state. A user who authenticated with MFA will lose the
@@ -5630,13 +5645,17 @@ var TokenManagerService = class _TokenManagerService {
5630
5645
  * @param token - The MFA temp JWT issued by {@link issueMfaTempToken}.
5631
5646
  * @returns The `userId`, `context`, and `jti` from the token. Pass the
5632
5647
  * `jti` to {@link consumeMfaTempToken} after TOTP validation succeeds.
5633
- * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` if the
5634
- * Redis entry is missing (already consumed, expired, or never issued).
5635
- * @throws {Error} When JWT signature or expiry validation fails (propagated
5636
- * directly from `JwtService.verify()` — not wrapped in {@link AuthException}).
5648
+ * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` for every way the token can be
5649
+ * unusable — a bad signature, an expired one, a shape no secret accepts, or a missing Redis
5650
+ * entry (already consumed, expired, or never issued).
5637
5651
  */
5638
5652
  async verifyMfaTempToken(token) {
5639
- const payload = verifyWithRotation(this.jwtService, this.options, token);
5653
+ let payload;
5654
+ try {
5655
+ payload = verifyWithRotation(this.jwtService, this.options, token);
5656
+ } catch {
5657
+ throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
5658
+ }
5640
5659
  if (payload.context === "dashboard" && payload.tenantId === void 0 || payload.context === "platform" && payload.tenantId !== void 0) {
5641
5660
  throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
5642
5661
  }
@@ -5710,6 +5729,14 @@ __name(normalizeEmail, "normalizeEmail");
5710
5729
  // src/server/utils/resolve-tenant-id.ts
5711
5730
  async function resolveTenantId(dtoTenantId, req, resolver) {
5712
5731
  if (resolver) {
5732
+ if (dtoTenantId !== void 0 && dtoTenantId !== null) {
5733
+ throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
5734
+ {
5735
+ field: "tenantId",
5736
+ message: "tenantId is decided by this deployment and must not be sent"
5737
+ }
5738
+ ]);
5739
+ }
5713
5740
  return await resolver(req);
5714
5741
  }
5715
5742
  if (dtoTenantId === void 0 || dtoTenantId === null) {
@@ -6112,7 +6139,7 @@ exports.AuthService = class _AuthService {
6112
6139
  */
6113
6140
  async refresh(oldRefreshToken, ip, userAgent) {
6114
6141
  const result = await this.tokenManager.reissueTokens(oldRefreshToken, ip, userAgent);
6115
- const user = await this.userRepo.findById(result.session.userId);
6142
+ const user = await this.userRepo.findById(result.session.userId, result.session.tenantId);
6116
6143
  if (!user) {
6117
6144
  await this.revokeAllSessions(result.session.userId);
6118
6145
  throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
@@ -10020,6 +10047,23 @@ var ChangePasswordDto = class {
10020
10047
  * Hashed immediately by the service layer — never persisted in plaintext.
10021
10048
  */
10022
10049
  newPassword;
10050
+ /**
10051
+ * The caller's own refresh token, so the device making the change stays signed in.
10052
+ *
10053
+ * Declared because the handler reads it. `TokenDeliveryService.extractRefreshToken` takes it
10054
+ * from the refresh cookie under `tokenDelivery: 'cookie'` and from **this body field** under
10055
+ * `'bearer'`, cookie-first-then-body under `'both'` — and the controller pipe runs
10056
+ * `forbidNonWhitelisted: true`, so an undeclared property is refused. A bearer-mode caller
10057
+ * therefore could not send the field the endpoint needs: the request was answered
10058
+ * `auth.validation` naming `refreshToken`, and the only way to change a password was to give
10059
+ * up every other session.
10060
+ *
10061
+ * It stayed invisible because the E2E harness installed a global `ValidationPipe` with
10062
+ * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
10063
+ * it — so the suite exercised a request production never sees. Optional, because under cookie
10064
+ * delivery the credential arrives in the cookie and no body field exists to declare.
10065
+ */
10066
+ refreshToken;
10023
10067
  };
10024
10068
  _ts_decorate37([
10025
10069
  classValidator.IsString(),
@@ -10033,6 +10077,12 @@ _ts_decorate37([
10033
10077
  classValidator.MaxLength(128),
10034
10078
  _ts_metadata36("design:type", String)
10035
10079
  ], ChangePasswordDto.prototype, "newPassword", void 0);
10080
+ _ts_decorate37([
10081
+ classValidator.IsOptional(),
10082
+ classValidator.IsString(),
10083
+ classValidator.MaxLength(512),
10084
+ _ts_metadata36("design:type", String)
10085
+ ], ChangePasswordDto.prototype, "refreshToken", void 0);
10036
10086
  function _ts_decorate38(decorators, target, key, desc) {
10037
10087
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10038
10088
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -12034,15 +12084,24 @@ var SessionController = class {
12034
12084
  return this.sessionService.listSessions(user.sub, currentHash);
12035
12085
  }
12036
12086
  // ---------------------------------------------------------------------------
12037
- // DELETE /sessions/all
12087
+ // POST /sessions/revoke-all
12038
12088
  // ---------------------------------------------------------------------------
12039
12089
  /**
12040
12090
  * Revokes all sessions for the authenticated user except the current one.
12041
12091
  *
12042
12092
  * Uses the refresh token from the request to determine which session to preserve.
12043
- * Throws `REFRESH_TOKEN_INVALID` if no refresh token is found — the current
12044
- * session cannot be determined without it, and revoking all sessions (including
12045
- * the caller's own) would force an immediate logout.
12093
+ * Throws `SESSION_NOT_FOUND` if no refresh token is found — the current session
12094
+ * cannot be determined without it, and revoking all sessions (including the
12095
+ * caller's own) would force an immediate logout.
12096
+ *
12097
+ * **POST, not DELETE, and the method is load-bearing.** Under
12098
+ * `tokenDelivery: 'bearer'` the refresh token this handler needs arrives in the
12099
+ * request body, and OpenAPI 3.0.3 defers to RFC 7231: a payload on DELETE has no
12100
+ * defined semantics, so `requestBody` there **SHALL be ignored by consumers**. A
12101
+ * generated client therefore dropped the body and every call answered
12102
+ * `SESSION_NOT_FOUND` — an operation the document could not describe and a client
12103
+ * could not reach. POST is the method whose body semantics are defined, so the
12104
+ * contributed fragment describes what the server actually reads.
12046
12105
  *
12047
12106
  * @param user - Verified JWT payload from the access token.
12048
12107
  * @param req - Incoming request (used to extract the current session's refresh token).
@@ -12095,7 +12154,7 @@ _ts_decorate49([
12095
12154
  throttler.Throttle(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
12096
12155
  AuthRateLimit(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
12097
12156
  common.HttpCode(common.HttpStatus.NO_CONTENT),
12098
- common.Delete("all"),
12157
+ common.Post("revoke-all"),
12099
12158
  _ts_param28(0, CurrentUser()),
12100
12159
  _ts_param28(1, common.Req()),
12101
12160
  _ts_metadata48("design:type", Function),
@@ -12485,10 +12544,11 @@ exports.OAuthService = class _OAuthService {
12485
12544
  * 5. Issues a 302 redirect via the Express `res` object.
12486
12545
  *
12487
12546
  * @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
12488
- * @param tenantId - Tenant the user will join on successful login, as named by the caller.
12489
- * Superseded by the configured `tenantIdResolver` when there is one, and never validated
12490
- * against the database — implement `onOAuthLogin` to enforce tenant membership. Without
12491
- * the hook, OAuth sign-in is disabled.
12547
+ * @param tenantId - Tenant the user will join on successful login, as named by the caller in
12548
+ * the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
12549
+ * configured, since the deployment decides the tenant and a value it discards would only
12550
+ * mislead the caller. Never validated against the database — implement `onOAuthLogin` to
12551
+ * enforce tenant membership. Without the hook, OAuth sign-in is disabled.
12492
12552
  * @param req - Incoming Express request, read by the configured `tenantIdResolver`.
12493
12553
  * @param res - Express response in passthrough mode (used for the 302 redirect).
12494
12554
  * @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
@@ -12741,9 +12801,28 @@ var OAuthCallbackQueryDto = class {
12741
12801
  * is a safe upper bound that rejects clearly malformed payloads.
12742
12802
  *
12743
12803
  * Absent on the error callback RFC 6749 §4.1.2.1 defines — the response a provider sends
12744
- * when the user declines consent. Required whenever `error` is absent, so a callback
12745
- * carrying neither is still the malformed request it always was.
12746
- */
12804
+ * when the user declines consent. Never required here: a callback carrying neither `code`
12805
+ * nor `error` is an OAuth failure rather than a malformed request, and the handler is what
12806
+ * says so — `OAuthController.callback` answers `auth.oauth_failed`, which is also what
12807
+ * rust-auth answers for the same callback. Requiring it here made the handler's branch
12808
+ * unreachable and split one behaviour across two libraries.
12809
+ */
12810
+ // Two conditionals, and they compose conjunctively — class-validator's `ValidationExecutor`
12811
+ // reduces every `CONDITIONAL_VALIDATION` predicate with `&&` before running any validator.
12812
+ // So `code` is validated only when `error` is absent AND `code` is present:
12813
+ //
12814
+ // - `error` present → skipped entirely, whatever `code` carries. That is what keeps a
12815
+ // provider's error callback out of the validation envelope even when it arrives with an
12816
+ // empty or oversized `code` beside it, which is the reason `@ValidateIf` is here at all.
12817
+ // - `code` absent → skipped, and the request reaches the handler. This is the change:
12818
+ // the refusal moved from the pipe to the handler, where the behaviour lives.
12819
+ // - `code` present → the bounds below apply, unchanged.
12820
+ //
12821
+ // Both predicates read `null` as absent, matching `@IsOptional()`'s own
12822
+ // (`value !== null && value !== undefined`). A query string cannot carry `null`, so no
12823
+ // callback reaches this with one; the alignment matters because the declared overlay models
12824
+ // presence with one rule for every DTO, and a predicate that read `null` as *present* would
12825
+ // make this the single field the overlay describes wrongly.
12747
12826
  code;
12748
12827
  /**
12749
12828
  * The provider's error code (RFC 6749 §4.1.2.1) — `access_denied` when the user clicks
@@ -12809,7 +12888,8 @@ var OAuthCallbackQueryDto = class {
12809
12888
  hd;
12810
12889
  };
12811
12890
  _ts_decorate55([
12812
- classValidator.ValidateIf((query) => query.error === void 0),
12891
+ classValidator.ValidateIf((query) => query.error === void 0 || query.error === null),
12892
+ classValidator.IsOptional(),
12813
12893
  classValidator.IsString(),
12814
12894
  classValidator.IsNotEmpty(),
12815
12895
  classValidator.MaxLength(2048),
@@ -13437,6 +13517,350 @@ var OAuthModule = class _OAuthModule {
13437
13517
  OAuthModule = _ts_decorate58([
13438
13518
  common.Module({})
13439
13519
  ], OAuthModule);
13520
+
13521
+ // src/server/openapi/auth-openapi-fragment.ts
13522
+ var OPENAPI_CONTRACT_VERSION = 1;
13523
+ var OPENAPI_CONTRIBUTOR_METADATA = "bymax-one:openapi-contributor";
13524
+ var AUTH_SECURITY_SCHEMES = {
13525
+ accessCookie: "bymaxAuthAccessCookie",
13526
+ accessBearer: "bymaxAuthAccessBearer",
13527
+ refreshCookie: "bymaxAuthRefreshCookie",
13528
+ platformBearer: "bymaxPlatformAccessBearer"
13529
+ };
13530
+ var OPERATIONS = {
13531
+ auth: {
13532
+ "AuthController.register": "none",
13533
+ "AuthController.login": "none",
13534
+ // Both read the refresh credential, and neither is behind a guard: they are `@Public()`
13535
+ // because an expired access token must not stop a caller from ending or renewing a
13536
+ // session. What authorises them is the refresh token itself.
13537
+ // Measured, and the two differ: `logout` answers 204 with no credential at all, while
13538
+ // `refresh` 401s. Describing them alike would tell a generated client that one demands
13539
+ // something it does not, or that the other tolerates something it will refuse.
13540
+ //
13541
+ // `logout` reads the ACCESS token too, and a document that omitted it caused a weaker
13542
+ // logout than the server performs: the handler blacklists that token's `jti` for whatever
13543
+ // life it has left, so a generated client sending no `Authorization` header revokes the
13544
+ // refresh session and leaves a valid access token in circulation until it expires. Neither
13545
+ // credential is required — this is the operation a signed-out-by-expiry user reaches — so
13546
+ // every form is an alternative beside the empty one.
13547
+ "AuthController.logout": "optionalAccessAndRefresh",
13548
+ "AuthController.refresh": "refreshRequired",
13549
+ "AuthController.me": "access",
13550
+ "AuthController.wsTicket": "access",
13551
+ "AuthController.verifyEmail": "none",
13552
+ "AuthController.resendVerification": "none"
13553
+ },
13554
+ passwordReset: {
13555
+ "PasswordResetController.forgotPassword": "none",
13556
+ "PasswordResetController.resetPassword": "none",
13557
+ // Reads the refresh token to spare the caller's own session when it revokes the others, and
13558
+ // succeeds without it — a password change from a client that sent none simply signs every
13559
+ // session out, including the one that asked.
13560
+ "PasswordResetController.changePassword": "accessWithOptionalRefresh",
13561
+ "PasswordResetController.verifyOtp": "none",
13562
+ "PasswordResetController.resendOtp": "none"
13563
+ },
13564
+ mfa: {
13565
+ "MfaController.setup": "access",
13566
+ "MfaController.verifyEnable": "access",
13567
+ // The challenge is reached with a temp token, not a session — by definition the caller has
13568
+ // no access token yet, which is what the challenge exists to earn.
13569
+ "MfaController.challenge": "none",
13570
+ "MfaController.disable": "access",
13571
+ "MfaController.regenerateRecoveryCodes": "access"
13572
+ },
13573
+ sessions: {
13574
+ // Measured against the controller rather than inferred from the guard stack, and the three
13575
+ // differ. `listSessions` reads the refresh token to mark which session is the caller's own
13576
+ // and answers 200 without it (every `isCurrent` reads false). `revokeAllSessions` refuses
13577
+ // without it — it revokes everything EXCEPT the current session, so a request that cannot
13578
+ // name the current one would sign the caller out, and it answers `auth.session_not_found`
13579
+ // instead. `revokeSession` names its target in the path and reads no refresh token at all.
13580
+ "SessionController.listSessions": "accessWithOptionalRefreshCookie",
13581
+ "SessionController.revokeAllSessions": "accessAndRefreshRequired",
13582
+ "SessionController.revokeSession": "access"
13583
+ },
13584
+ platform: {
13585
+ "PlatformAuthController.login": "none",
13586
+ "PlatformAuthController.mfaChallenge": "none",
13587
+ "PlatformAuthController.me": "platform",
13588
+ // The access token authorises the logout; the refresh token in the body names the session
13589
+ // to end. Both are read, so both are described.
13590
+ "PlatformAuthController.logout": "platformLogout",
13591
+ // Refresh is the one platform operation with no access token at all: the refresh token in
13592
+ // the body is the whole credential.
13593
+ "PlatformAuthController.refresh": "platformRefresh",
13594
+ "PlatformAuthController.revokeSessions": "platform"
13595
+ },
13596
+ platformMfa: {
13597
+ "PlatformMfaController.setup": "platform",
13598
+ "PlatformMfaController.verifyEnable": "platform",
13599
+ "PlatformMfaController.disable": "platform",
13600
+ "PlatformMfaController.regenerateRecoveryCodes": "platform"
13601
+ },
13602
+ invitations: {
13603
+ "InvitationController.invite": "access",
13604
+ "InvitationController.revoke": "access",
13605
+ // Accepting is how an invitee gets their first credential, so it cannot require one.
13606
+ "InvitationController.accept": "none"
13607
+ },
13608
+ emailChange: {
13609
+ "EmailChangeController.requestChange": "access",
13610
+ // Public because the holder is proving control of a mailbox, not of a session.
13611
+ "EmailChangeController.confirmChange": "none"
13612
+ },
13613
+ oauth: {
13614
+ "OAuthController.initiate": "none",
13615
+ "OAuthController.callback": "none"
13616
+ }
13617
+ };
13618
+ var OPERATION_DESCRIPTIONS = /* @__PURE__ */ new Map([
13619
+ [
13620
+ // Measured by a consumer against a running deployment, and the reason this entry exists: a
13621
+ // logout called with no credential answers `204` and revokes NOTHING — the same access token
13622
+ // still gets `200` from `/me` afterwards. Every other imprecision in this fragment costs a
13623
+ // caller one rejected request; this one hands them a success while they stay signed in.
13624
+ //
13625
+ // The operation requires nothing, deliberately, so `security` cannot express any of that: an
13626
+ // empty requirement and an optional one render identically to a reader who is skimming. The
13627
+ // sentence is therefore the only place a person building a sign-out learns that the credential
13628
+ // they omitted was the one doing the work.
13629
+ "AuthController.logout",
13630
+ "Revokes the session and blacklists the access token, using whichever credentials the request carries. NEITHER is required \u2014 an operator whose access token has expired must still be able to sign out \u2014 but a call that carries none succeeds without revoking anything. Under `tokenDelivery: bearer` the refresh token in the request body is the only channel there is, so omitting it makes this a silent no-op."
13631
+ ]
13632
+ ]);
13633
+ var REFRESH_BODY = {
13634
+ required: false,
13635
+ content: {
13636
+ "application/json": {
13637
+ schema: {
13638
+ type: "object",
13639
+ properties: {
13640
+ refreshToken: {
13641
+ type: "string",
13642
+ description: "The refresh token, when it is not delivered as a cookie."
13643
+ }
13644
+ }
13645
+ }
13646
+ }
13647
+ }
13648
+ };
13649
+ var REQUIRED_REFRESH_BODY = {
13650
+ required: true,
13651
+ content: {
13652
+ "application/json": {
13653
+ schema: {
13654
+ type: "object",
13655
+ required: [
13656
+ "refreshToken"
13657
+ ],
13658
+ properties: {
13659
+ refreshToken: {
13660
+ type: "string",
13661
+ description: "The refresh token, when it is not delivered as a cookie."
13662
+ }
13663
+ }
13664
+ }
13665
+ }
13666
+ }
13667
+ };
13668
+ var PLATFORM_REFRESH_BODY = {
13669
+ required: true,
13670
+ content: {
13671
+ "application/json": {
13672
+ schema: {
13673
+ type: "object",
13674
+ required: [
13675
+ "refreshToken"
13676
+ ],
13677
+ properties: {
13678
+ refreshToken: {
13679
+ type: "string",
13680
+ description: "The platform refresh token."
13681
+ }
13682
+ }
13683
+ }
13684
+ }
13685
+ }
13686
+ };
13687
+ function buildAuthOpenApiFragment(options, registered) {
13688
+ const cookieDelivery = options.tokenDelivery === "cookie" || options.tokenDelivery === "both";
13689
+ const bearerDelivery = options.tokenDelivery === "bearer" || options.tokenDelivery === "both";
13690
+ const operations = {};
13691
+ for (const [controller, handlers] of Object.entries(OPERATIONS)) {
13692
+ if (!registered[controller]) continue;
13693
+ for (const [handler, credential] of Object.entries(handlers)) {
13694
+ const described = describe(credential, cookieDelivery, bearerDelivery);
13695
+ const note = OPERATION_DESCRIPTIONS.get(handler);
13696
+ operations[handler] = note === void 0 ? described : {
13697
+ ...described,
13698
+ description: note
13699
+ };
13700
+ }
13701
+ }
13702
+ return {
13703
+ contractVersion: OPENAPI_CONTRACT_VERSION,
13704
+ operations,
13705
+ components: {
13706
+ securitySchemes: schemesFor(options, registered, cookieDelivery, bearerDelivery)
13707
+ }
13708
+ };
13709
+ }
13710
+ __name(buildAuthOpenApiFragment, "buildAuthOpenApiFragment");
13711
+ function describe(credential, cookieDelivery, bearerDelivery) {
13712
+ switch (credential) {
13713
+ case "none":
13714
+ return {
13715
+ security: []
13716
+ };
13717
+ case "access":
13718
+ return {
13719
+ security: [
13720
+ ...cookieDelivery ? [
13721
+ {
13722
+ [AUTH_SECURITY_SCHEMES.accessCookie]: []
13723
+ }
13724
+ ] : [],
13725
+ ...bearerDelivery ? [
13726
+ {
13727
+ [AUTH_SECURITY_SCHEMES.accessBearer]: []
13728
+ }
13729
+ ] : []
13730
+ ]
13731
+ };
13732
+ case "refreshRequired":
13733
+ return {
13734
+ security: cookieDelivery ? bearerDelivery ? [
13735
+ {
13736
+ [AUTH_SECURITY_SCHEMES.refreshCookie]: []
13737
+ },
13738
+ {}
13739
+ ] : [
13740
+ {
13741
+ [AUTH_SECURITY_SCHEMES.refreshCookie]: []
13742
+ }
13743
+ ] : [],
13744
+ ...bearerDelivery ? {
13745
+ requestBody: cookieDelivery ? REFRESH_BODY : REQUIRED_REFRESH_BODY
13746
+ } : {}
13747
+ };
13748
+ case "accessAndRefreshRequired":
13749
+ case "accessWithOptionalRefresh":
13750
+ case "accessWithOptionalRefreshCookie":
13751
+ case "optionalAccessAndRefresh":
13752
+ return describeTwoCredentials(credential, cookieDelivery, bearerDelivery);
13753
+ case "platform":
13754
+ return {
13755
+ security: [
13756
+ {
13757
+ [AUTH_SECURITY_SCHEMES.platformBearer]: []
13758
+ }
13759
+ ]
13760
+ };
13761
+ case "platformLogout":
13762
+ return {
13763
+ security: [
13764
+ {
13765
+ [AUTH_SECURITY_SCHEMES.platformBearer]: []
13766
+ },
13767
+ {}
13768
+ ],
13769
+ requestBody: {
13770
+ ...PLATFORM_REFRESH_BODY,
13771
+ required: false
13772
+ }
13773
+ };
13774
+ case "platformRefresh":
13775
+ return {
13776
+ security: [],
13777
+ requestBody: PLATFORM_REFRESH_BODY
13778
+ };
13779
+ }
13780
+ }
13781
+ __name(describe, "describe");
13782
+ function describeTwoCredentials(credential, cookieDelivery, bearerDelivery) {
13783
+ const required = {
13784
+ access: credential !== "optionalAccessAndRefresh",
13785
+ refresh: credential === "accessAndRefreshRequired"
13786
+ };
13787
+ const bodyChannel = bearerDelivery && credential !== "accessWithOptionalRefreshCookie";
13788
+ const accessSchemes = [
13789
+ ...cookieDelivery ? [
13790
+ AUTH_SECURITY_SCHEMES.accessCookie
13791
+ ] : [],
13792
+ ...bearerDelivery ? [
13793
+ AUTH_SECURITY_SCHEMES.accessBearer
13794
+ ] : []
13795
+ ];
13796
+ const withRefreshCookie = cookieDelivery ? accessSchemes.map((access) => ({
13797
+ [access]: [],
13798
+ [AUTH_SECURITY_SCHEMES.refreshCookie]: []
13799
+ })) : [];
13800
+ const accessAlone = bearerDelivery || !required.refresh ? accessSchemes.map((access) => ({
13801
+ [access]: []
13802
+ })) : [];
13803
+ const refreshAlone = !required.access && cookieDelivery ? [
13804
+ {
13805
+ [AUTH_SECURITY_SCHEMES.refreshCookie]: []
13806
+ }
13807
+ ] : [];
13808
+ const nothing = !required.access && !required.refresh ? [
13809
+ {}
13810
+ ] : [];
13811
+ return {
13812
+ security: [
13813
+ ...withRefreshCookie,
13814
+ ...accessAlone,
13815
+ ...refreshAlone,
13816
+ ...nothing
13817
+ ],
13818
+ ...bodyChannel ? {
13819
+ requestBody: cookieDelivery || !required.refresh ? REFRESH_BODY : REQUIRED_REFRESH_BODY
13820
+ } : {}
13821
+ };
13822
+ }
13823
+ __name(describeTwoCredentials, "describeTwoCredentials");
13824
+ function schemesFor(options, registered, cookieDelivery, bearerDelivery) {
13825
+ const schemes = {};
13826
+ const dashboardMounted = registered.auth || registered.passwordReset || registered.mfa || registered.sessions || registered.invitations || registered.emailChange;
13827
+ if (dashboardMounted && cookieDelivery) {
13828
+ schemes[AUTH_SECURITY_SCHEMES.accessCookie] = {
13829
+ type: "apiKey",
13830
+ in: "cookie",
13831
+ name: options.cookies.accessTokenName,
13832
+ description: "Access token, delivered as an HttpOnly cookie."
13833
+ };
13834
+ }
13835
+ if (dashboardMounted && bearerDelivery) {
13836
+ schemes[AUTH_SECURITY_SCHEMES.accessBearer] = {
13837
+ type: "http",
13838
+ scheme: "bearer",
13839
+ bearerFormat: "JWT",
13840
+ description: "Access token, delivered in the Authorization header."
13841
+ };
13842
+ }
13843
+ if ((registered.auth || registered.sessions || registered.passwordReset) && cookieDelivery) {
13844
+ schemes[AUTH_SECURITY_SCHEMES.refreshCookie] = {
13845
+ type: "apiKey",
13846
+ in: "cookie",
13847
+ name: options.cookies.refreshTokenName,
13848
+ description: "Refresh token, delivered as an HttpOnly cookie scoped to the auth prefix."
13849
+ };
13850
+ }
13851
+ if (registered.platform || registered.platformMfa) {
13852
+ schemes[AUTH_SECURITY_SCHEMES.platformBearer] = {
13853
+ type: "http",
13854
+ scheme: "bearer",
13855
+ bearerFormat: "JWT",
13856
+ description: "Platform administrator access token, always delivered in the Authorization header regardless of tokenDelivery."
13857
+ };
13858
+ }
13859
+ return schemes;
13860
+ }
13861
+ __name(schemesFor, "schemesFor");
13862
+
13863
+ // src/server/openapi/auth-openapi.contributor.ts
13440
13864
  function _ts_decorate59(decorators, target, key, desc) {
13441
13865
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13442
13866
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -13463,6 +13887,62 @@ function _ts_param34(paramIndex, decorator) {
13463
13887
  };
13464
13888
  }
13465
13889
  __name(_ts_param34, "_ts_param");
13890
+ var AuthOpenApiContributor = class {
13891
+ static {
13892
+ __name(this, "AuthOpenApiContributor");
13893
+ }
13894
+ options;
13895
+ registered;
13896
+ constructor(options, registered) {
13897
+ this.options = options;
13898
+ this.registered = registered;
13899
+ }
13900
+ /**
13901
+ * Produces the fragments for this deployment.
13902
+ *
13903
+ * @returns Operations keyed by handler identity, and the security schemes they reference.
13904
+ */
13905
+ contributeOpenApi() {
13906
+ return buildAuthOpenApiFragment(this.options, this.registered);
13907
+ }
13908
+ };
13909
+ AuthOpenApiContributor = _ts_decorate59([
13910
+ common.Injectable(),
13911
+ common.SetMetadata(OPENAPI_CONTRIBUTOR_METADATA, true),
13912
+ _ts_param34(0, common.Inject(BYMAX_AUTH_OPTIONS)),
13913
+ _ts_param34(1, common.Inject(BYMAX_AUTH_REGISTERED_CONTROLLERS)),
13914
+ _ts_metadata56("design:type", Function),
13915
+ _ts_metadata56("design:paramtypes", [
13916
+ typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
13917
+ typeof RegisteredControllers === "undefined" ? Object : RegisteredControllers
13918
+ ])
13919
+ ], AuthOpenApiContributor);
13920
+ function _ts_decorate60(decorators, target, key, desc) {
13921
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13922
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
13923
+ r = Reflect.decorate(decorators, target, key, desc);
13924
+ } else {
13925
+ for (var i = decorators.length - 1; i >= 0; i--) {
13926
+ if (d = decorators[i]) {
13927
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13928
+ }
13929
+ }
13930
+ }
13931
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
13932
+ }
13933
+ __name(_ts_decorate60, "_ts_decorate");
13934
+ function _ts_metadata57(metadataKey, metadataValue) {
13935
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
13936
+ return Reflect.metadata(metadataKey, metadataValue);
13937
+ }
13938
+ }
13939
+ __name(_ts_metadata57, "_ts_metadata");
13940
+ function _ts_param35(paramIndex, decorator) {
13941
+ return function(target, key) {
13942
+ decorator(target, key, paramIndex);
13943
+ };
13944
+ }
13945
+ __name(_ts_param35, "_ts_param");
13466
13946
  var COMMON_BASE_WORDS = [
13467
13947
  // The perennial top of every published list.
13468
13948
  "password",
@@ -13768,16 +14248,16 @@ exports.CommonPasswordChecker = class CommonPasswordChecker {
13768
14248
  return false;
13769
14249
  }
13770
14250
  };
13771
- exports.CommonPasswordChecker = _ts_decorate59([
14251
+ exports.CommonPasswordChecker = _ts_decorate60([
13772
14252
  common.Injectable(),
13773
- _ts_param34(0, common.Inject(BYMAX_AUTH_OPTIONS)),
13774
- _ts_param34(0, common.Optional()),
13775
- _ts_metadata56("design:type", Function),
13776
- _ts_metadata56("design:paramtypes", [
14253
+ _ts_param35(0, common.Inject(BYMAX_AUTH_OPTIONS)),
14254
+ _ts_param35(0, common.Optional()),
14255
+ _ts_metadata57("design:type", Function),
14256
+ _ts_metadata57("design:paramtypes", [
13777
14257
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
13778
14258
  ])
13779
14259
  ], exports.CommonPasswordChecker);
13780
- function _ts_decorate60(decorators, target, key, desc) {
14260
+ function _ts_decorate61(decorators, target, key, desc) {
13781
14261
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13782
14262
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
13783
14263
  r = Reflect.decorate(decorators, target, key, desc);
@@ -13790,7 +14270,7 @@ function _ts_decorate60(decorators, target, key, desc) {
13790
14270
  }
13791
14271
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13792
14272
  }
13793
- __name(_ts_decorate60, "_ts_decorate");
14273
+ __name(_ts_decorate61, "_ts_decorate");
13794
14274
  exports.NoOpEmailProvider = class _NoOpEmailProvider {
13795
14275
  static {
13796
14276
  __name(this, "NoOpEmailProvider");
@@ -13825,12 +14305,12 @@ exports.NoOpEmailProvider = class _NoOpEmailProvider {
13825
14305
  this.logger.log(`sendInvitation \u2192 ${maskEmail(email)} (no-op)`);
13826
14306
  }
13827
14307
  };
13828
- exports.NoOpEmailProvider = _ts_decorate60([
14308
+ exports.NoOpEmailProvider = _ts_decorate61([
13829
14309
  common.Injectable()
13830
14310
  ], exports.NoOpEmailProvider);
13831
14311
 
13832
14312
  // src/server/bymax-auth.module.ts
13833
- function _ts_decorate61(decorators, target, key, desc) {
14313
+ function _ts_decorate62(decorators, target, key, desc) {
13834
14314
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13835
14315
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
13836
14316
  r = Reflect.decorate(decorators, target, key, desc);
@@ -13843,7 +14323,7 @@ function _ts_decorate61(decorators, target, key, desc) {
13843
14323
  }
13844
14324
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13845
14325
  }
13846
- __name(_ts_decorate61, "_ts_decorate");
14326
+ __name(_ts_decorate62, "_ts_decorate");
13847
14327
  function hasProviderToken(providers, token) {
13848
14328
  return providers.some((p) => {
13849
14329
  if (typeof p === "function") return false;
@@ -14018,6 +14498,30 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
14018
14498
  ...extraProviders,
14019
14499
  // Resolved options (depends on consumer's inject tokens).
14020
14500
  resolvedOptionsProvider,
14501
+ // Which controllers this registration mounted, and the contributor that reads it.
14502
+ //
14503
+ // The flags are computed above from the `controllers` argument, which Nest reads
14504
+ // synchronously — before any factory runs — so they cannot travel inside the resolved
14505
+ // options. The contributor needs them because a fragment naming a handler the document
14506
+ // does not contain FAILS a consumer's document build: a library that described its
14507
+ // platform routes on a deployment that never mounted them would break the build it was
14508
+ // supposed to describe.
14509
+ {
14510
+ provide: BYMAX_AUTH_REGISTERED_CONTROLLERS,
14511
+ useValue: {
14512
+ auth: includeAuth,
14513
+ passwordReset: includePasswordReset,
14514
+ mfa: includeMfa,
14515
+ sessions: includeSessions,
14516
+ platform: includePlatform,
14517
+ // One switch mounts both platform controllers, so they cannot disagree.
14518
+ platformMfa: includePlatform,
14519
+ invitations: includeInvitations,
14520
+ emailChange: includeEmailChange,
14521
+ oauth: includeOAuth
14522
+ }
14523
+ },
14524
+ AuthOpenApiContributor,
14021
14525
  // Fallback NoOp providers (skipped if consumer already supplied them).
14022
14526
  ...emailProviders,
14023
14527
  ...breachCheckerProviders,
@@ -14143,7 +14647,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
14143
14647
  };
14144
14648
  }
14145
14649
  };
14146
- exports.BymaxAuthModule = _ts_decorate61([
14650
+ exports.BymaxAuthModule = _ts_decorate62([
14147
14651
  common.Module({})
14148
14652
  ], exports.BymaxAuthModule);
14149
14653
  var CODE_VALIDITY_TEXT = "It expires shortly, so use it soon.";
@@ -14355,7 +14859,7 @@ var DefaultAuthEmailProvider = class _DefaultAuthEmailProvider {
14355
14859
  }
14356
14860
  }
14357
14861
  };
14358
- function _ts_decorate62(decorators, target, key, desc) {
14862
+ function _ts_decorate63(decorators, target, key, desc) {
14359
14863
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14360
14864
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14361
14865
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14368,13 +14872,13 @@ function _ts_decorate62(decorators, target, key, desc) {
14368
14872
  }
14369
14873
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14370
14874
  }
14371
- __name(_ts_decorate62, "_ts_decorate");
14372
- function _ts_metadata57(metadataKey, metadataValue) {
14875
+ __name(_ts_decorate63, "_ts_decorate");
14876
+ function _ts_metadata58(metadataKey, metadataValue) {
14373
14877
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14374
14878
  return Reflect.metadata(metadataKey, metadataValue);
14375
14879
  }
14376
14880
  }
14377
- __name(_ts_metadata57, "_ts_metadata");
14881
+ __name(_ts_metadata58, "_ts_metadata");
14378
14882
  var HIBP_RANGE_URL = "https://api.pwnedpasswords.com/range/";
14379
14883
  var PREFIX_LENGTH = 5;
14380
14884
  var DEFAULT_TIMEOUT_MS = 1500;
@@ -14431,10 +14935,10 @@ exports.HibpBreachChecker = class _HibpBreachChecker {
14431
14935
  }
14432
14936
  }
14433
14937
  };
14434
- exports.HibpBreachChecker = _ts_decorate62([
14938
+ exports.HibpBreachChecker = _ts_decorate63([
14435
14939
  common.Injectable(),
14436
- _ts_metadata57("design:type", Function),
14437
- _ts_metadata57("design:paramtypes", [
14940
+ _ts_metadata58("design:type", Function),
14941
+ _ts_metadata58("design:paramtypes", [
14438
14942
  Number
14439
14943
  ])
14440
14944
  ], exports.HibpBreachChecker);
@@ -14447,10 +14951,10 @@ exports.AllowAllBreachChecker = class AllowAllBreachChecker {
14447
14951
  return false;
14448
14952
  }
14449
14953
  };
14450
- exports.AllowAllBreachChecker = _ts_decorate62([
14954
+ exports.AllowAllBreachChecker = _ts_decorate63([
14451
14955
  common.Injectable()
14452
14956
  ], exports.AllowAllBreachChecker);
14453
- function _ts_decorate63(decorators, target, key, desc) {
14957
+ function _ts_decorate64(decorators, target, key, desc) {
14454
14958
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14455
14959
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14456
14960
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14463,7 +14967,7 @@ function _ts_decorate63(decorators, target, key, desc) {
14463
14967
  }
14464
14968
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14465
14969
  }
14466
- __name(_ts_decorate63, "_ts_decorate");
14970
+ __name(_ts_decorate64, "_ts_decorate");
14467
14971
  exports.OptionalAuthGuard = class OptionalAuthGuard extends exports.JwtAuthGuard {
14468
14972
  static {
14469
14973
  __name(this, "OptionalAuthGuard");
@@ -14478,10 +14982,10 @@ exports.OptionalAuthGuard = class OptionalAuthGuard extends exports.JwtAuthGuard
14478
14982
  return super.canActivate(context);
14479
14983
  }
14480
14984
  };
14481
- exports.OptionalAuthGuard = _ts_decorate63([
14985
+ exports.OptionalAuthGuard = _ts_decorate64([
14482
14986
  common.Injectable()
14483
14987
  ], exports.OptionalAuthGuard);
14484
- function _ts_decorate64(decorators, target, key, desc) {
14988
+ function _ts_decorate65(decorators, target, key, desc) {
14485
14989
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14486
14990
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14487
14991
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14494,19 +14998,19 @@ function _ts_decorate64(decorators, target, key, desc) {
14494
14998
  }
14495
14999
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14496
15000
  }
14497
- __name(_ts_decorate64, "_ts_decorate");
14498
- function _ts_metadata58(metadataKey, metadataValue) {
15001
+ __name(_ts_decorate65, "_ts_decorate");
15002
+ function _ts_metadata59(metadataKey, metadataValue) {
14499
15003
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14500
15004
  return Reflect.metadata(metadataKey, metadataValue);
14501
15005
  }
14502
15006
  }
14503
- __name(_ts_metadata58, "_ts_metadata");
14504
- function _ts_param35(paramIndex, decorator) {
15007
+ __name(_ts_metadata59, "_ts_metadata");
15008
+ function _ts_param36(paramIndex, decorator) {
14505
15009
  return function(target, key) {
14506
15010
  decorator(target, key, paramIndex);
14507
15011
  };
14508
15012
  }
14509
- __name(_ts_param35, "_ts_param");
15013
+ __name(_ts_param36, "_ts_param");
14510
15014
  exports.SelfOrAdminGuard = class SelfOrAdminGuard {
14511
15015
  static {
14512
15016
  __name(this, "SelfOrAdminGuard");
@@ -14536,11 +15040,11 @@ exports.SelfOrAdminGuard = class SelfOrAdminGuard {
14536
15040
  throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
14537
15041
  }
14538
15042
  };
14539
- exports.SelfOrAdminGuard = _ts_decorate64([
15043
+ exports.SelfOrAdminGuard = _ts_decorate65([
14540
15044
  common.Injectable(),
14541
- _ts_param35(0, common.Inject(BYMAX_AUTH_OPTIONS)),
14542
- _ts_metadata58("design:type", Function),
14543
- _ts_metadata58("design:paramtypes", [
15045
+ _ts_param36(0, common.Inject(BYMAX_AUTH_OPTIONS)),
15046
+ _ts_metadata59("design:type", Function),
15047
+ _ts_metadata59("design:paramtypes", [
14544
15048
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
14545
15049
  ])
14546
15050
  ], exports.SelfOrAdminGuard);
@@ -14553,7 +15057,7 @@ function isHexLooking(value) {
14553
15057
  return value.length === 64 && /^[a-fA-F0-9]{64}$/.test(value);
14554
15058
  }
14555
15059
  __name(isHexLooking, "isHexLooking");
14556
- function _ts_decorate65(decorators, target, key, desc) {
15060
+ function _ts_decorate66(decorators, target, key, desc) {
14557
15061
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14558
15062
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14559
15063
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14566,19 +15070,19 @@ function _ts_decorate65(decorators, target, key, desc) {
14566
15070
  }
14567
15071
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14568
15072
  }
14569
- __name(_ts_decorate65, "_ts_decorate");
14570
- function _ts_metadata59(metadataKey, metadataValue) {
15073
+ __name(_ts_decorate66, "_ts_decorate");
15074
+ function _ts_metadata60(metadataKey, metadataValue) {
14571
15075
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14572
15076
  return Reflect.metadata(metadataKey, metadataValue);
14573
15077
  }
14574
15078
  }
14575
- __name(_ts_metadata59, "_ts_metadata");
14576
- function _ts_param36(paramIndex, decorator) {
15079
+ __name(_ts_metadata60, "_ts_metadata");
15080
+ function _ts_param37(paramIndex, decorator) {
14577
15081
  return function(target, key) {
14578
15082
  decorator(target, key, paramIndex);
14579
15083
  };
14580
15084
  }
14581
- __name(_ts_param36, "_ts_param");
15085
+ __name(_ts_param37, "_ts_param");
14582
15086
  exports.WsJwtGuard = class WsJwtGuard {
14583
15087
  static {
14584
15088
  __name(this, "WsJwtGuard");
@@ -14606,14 +15110,18 @@ exports.WsJwtGuard = class WsJwtGuard {
14606
15110
  }
14607
15111
  async canActivate(context) {
14608
15112
  const client = context.switchToWs().getClient();
14609
- const ticket = readUpgradeTicket(client);
15113
+ const handshake = client.handshake;
15114
+ if (handshake === void 0 || handshake === null) {
15115
+ throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
15116
+ }
15117
+ const ticket = readUpgradeTicket(handshake);
14610
15118
  if (ticket !== void 0) {
14611
15119
  const snapshot = await this.wsTickets.redeem(ticket);
14612
15120
  assertDashboardSnapshot(snapshot);
14613
15121
  client.data.user = snapshot;
14614
15122
  return true;
14615
15123
  }
14616
- const authHeader = client.handshake.headers["authorization"];
15124
+ const authHeader = handshake.headers["authorization"];
14617
15125
  const token = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : void 0;
14618
15126
  if (!token) {
14619
15127
  throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
@@ -14636,14 +15144,14 @@ exports.WsJwtGuard = class WsJwtGuard {
14636
15144
  return true;
14637
15145
  }
14638
15146
  };
14639
- exports.WsJwtGuard = _ts_decorate65([
15147
+ exports.WsJwtGuard = _ts_decorate66([
14640
15148
  common.Injectable(),
14641
- _ts_param36(0, common.Inject(jwt.JwtService)),
14642
- _ts_param36(1, common.Inject(exports.AuthRevocationService)),
14643
- _ts_param36(2, common.Inject(exports.WsTicketService)),
14644
- _ts_param36(3, common.Inject(BYMAX_AUTH_OPTIONS)),
14645
- _ts_metadata59("design:type", Function),
14646
- _ts_metadata59("design:paramtypes", [
15149
+ _ts_param37(0, common.Inject(jwt.JwtService)),
15150
+ _ts_param37(1, common.Inject(exports.AuthRevocationService)),
15151
+ _ts_param37(2, common.Inject(exports.WsTicketService)),
15152
+ _ts_param37(3, common.Inject(BYMAX_AUTH_OPTIONS)),
15153
+ _ts_metadata60("design:type", Function),
15154
+ _ts_metadata60("design:paramtypes", [
14647
15155
  typeof jwt.JwtService === "undefined" ? Object : jwt.JwtService,
14648
15156
  typeof exports.AuthRevocationService === "undefined" ? Object : exports.AuthRevocationService,
14649
15157
  typeof exports.WsTicketService === "undefined" ? Object : exports.WsTicketService,
@@ -14659,11 +15167,11 @@ function assertDashboardSnapshot(snapshot) {
14659
15167
  }
14660
15168
  }
14661
15169
  __name(assertDashboardSnapshot, "assertDashboardSnapshot");
14662
- function readUpgradeTicket(client) {
14663
- const fromQuery = client.handshake.query?.["ticket"];
15170
+ function readUpgradeTicket(handshake) {
15171
+ const fromQuery = handshake.query?.["ticket"];
14664
15172
  if (typeof fromQuery === "string" && fromQuery !== "") return fromQuery;
14665
15173
  if (fromQuery !== void 0) return void 0;
14666
- const url = client.handshake.url;
15174
+ const url = handshake.url;
14667
15175
  if (typeof url !== "string") return void 0;
14668
15176
  if (url === "") return void 0;
14669
15177
  let params;
@@ -14676,7 +15184,7 @@ function readUpgradeTicket(client) {
14676
15184
  return all.length === 1 && all[0] !== "" ? all[0] : void 0;
14677
15185
  }
14678
15186
  __name(readUpgradeTicket, "readUpgradeTicket");
14679
- function _ts_decorate66(decorators, target, key, desc) {
15187
+ function _ts_decorate67(decorators, target, key, desc) {
14680
15188
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14681
15189
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14682
15190
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14689,7 +15197,7 @@ function _ts_decorate66(decorators, target, key, desc) {
14689
15197
  }
14690
15198
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14691
15199
  }
14692
- __name(_ts_decorate66, "_ts_decorate");
15200
+ __name(_ts_decorate67, "_ts_decorate");
14693
15201
  function isAuthEnvelope(body) {
14694
15202
  if (typeof body !== "object" || body === null) return false;
14695
15203
  const error = body.error;
@@ -14741,9 +15249,69 @@ exports.AuthExceptionFilter = class _AuthExceptionFilter {
14741
15249
  });
14742
15250
  }
14743
15251
  };
14744
- exports.AuthExceptionFilter = _ts_decorate66([
15252
+ exports.AuthExceptionFilter = _ts_decorate67([
14745
15253
  common.Catch()
14746
15254
  ], exports.AuthExceptionFilter);
15255
+ function _ts_decorate68(decorators, target, key, desc) {
15256
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15257
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
15258
+ r = Reflect.decorate(decorators, target, key, desc);
15259
+ } else {
15260
+ for (var i = decorators.length - 1; i >= 0; i--) {
15261
+ if (d = decorators[i]) {
15262
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
15263
+ }
15264
+ }
15265
+ }
15266
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15267
+ }
15268
+ __name(_ts_decorate68, "_ts_decorate");
15269
+ function isEmittingClient(client) {
15270
+ return typeof client?.emit === "function";
15271
+ }
15272
+ __name(isEmittingClient, "isEmittingClient");
15273
+ var WS_OPEN = 1;
15274
+ function isSendingClient(client) {
15275
+ const candidate = client;
15276
+ return typeof candidate?.readyState === "number" && typeof candidate.send === "function";
15277
+ }
15278
+ __name(isSendingClient, "isSendingClient");
15279
+ exports.WsAuthExceptionFilter = class _WsAuthExceptionFilter {
15280
+ static {
15281
+ __name(this, "WsAuthExceptionFilter");
15282
+ }
15283
+ logger = new common.Logger(_WsAuthExceptionFilter.name);
15284
+ /**
15285
+ * Delivers the library envelope to the client whose request was refused.
15286
+ *
15287
+ * @param exception - The `AuthException` a guard, pipe or handler raised.
15288
+ * @param host - The arguments host, used to reach the connected client.
15289
+ */
15290
+ catch(exception, host) {
15291
+ const client = host.switchToWs().getClient();
15292
+ const payload = {
15293
+ status: "error",
15294
+ ...exception.getResponse()
15295
+ };
15296
+ if (isSendingClient(client)) {
15297
+ if (client.readyState === WS_OPEN) {
15298
+ client.send(JSON.stringify({
15299
+ event: "exception",
15300
+ data: payload
15301
+ }));
15302
+ }
15303
+ return;
15304
+ }
15305
+ if (isEmittingClient(client)) {
15306
+ client.emit("exception", payload);
15307
+ return;
15308
+ }
15309
+ this.logger.error("refused a request on a client this filter cannot answer", exception);
15310
+ }
15311
+ };
15312
+ exports.WsAuthExceptionFilter = _ts_decorate68([
15313
+ common.Catch(AuthException)
15314
+ ], exports.WsAuthExceptionFilter);
14747
15315
 
14748
15316
  exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
14749
15317
  exports.AUTH_ERROR_MESSAGES = AUTH_ERROR_MESSAGES;