@bymax-one/nest-auth 1.4.2 → 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
  }
@@ -6120,7 +6139,7 @@ exports.AuthService = class _AuthService {
6120
6139
  */
6121
6140
  async refresh(oldRefreshToken, ip, userAgent) {
6122
6141
  const result = await this.tokenManager.reissueTokens(oldRefreshToken, ip, userAgent);
6123
- const user = await this.userRepo.findById(result.session.userId);
6142
+ const user = await this.userRepo.findById(result.session.userId, result.session.tenantId);
6124
6143
  if (!user) {
6125
6144
  await this.revokeAllSessions(result.session.userId);
6126
6145
  throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
@@ -10028,6 +10047,23 @@ var ChangePasswordDto = class {
10028
10047
  * Hashed immediately by the service layer — never persisted in plaintext.
10029
10048
  */
10030
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;
10031
10067
  };
10032
10068
  _ts_decorate37([
10033
10069
  classValidator.IsString(),
@@ -10041,6 +10077,12 @@ _ts_decorate37([
10041
10077
  classValidator.MaxLength(128),
10042
10078
  _ts_metadata36("design:type", String)
10043
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);
10044
10086
  function _ts_decorate38(decorators, target, key, desc) {
10045
10087
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10046
10088
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -12042,15 +12084,24 @@ var SessionController = class {
12042
12084
  return this.sessionService.listSessions(user.sub, currentHash);
12043
12085
  }
12044
12086
  // ---------------------------------------------------------------------------
12045
- // DELETE /sessions/all
12087
+ // POST /sessions/revoke-all
12046
12088
  // ---------------------------------------------------------------------------
12047
12089
  /**
12048
12090
  * Revokes all sessions for the authenticated user except the current one.
12049
12091
  *
12050
12092
  * Uses the refresh token from the request to determine which session to preserve.
12051
- * Throws `REFRESH_TOKEN_INVALID` if no refresh token is found — the current
12052
- * session cannot be determined without it, and revoking all sessions (including
12053
- * 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.
12054
12105
  *
12055
12106
  * @param user - Verified JWT payload from the access token.
12056
12107
  * @param req - Incoming request (used to extract the current session's refresh token).
@@ -12103,7 +12154,7 @@ _ts_decorate49([
12103
12154
  throttler.Throttle(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
12104
12155
  AuthRateLimit(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
12105
12156
  common.HttpCode(common.HttpStatus.NO_CONTENT),
12106
- common.Delete("all"),
12157
+ common.Post("revoke-all"),
12107
12158
  _ts_param28(0, CurrentUser()),
12108
12159
  _ts_param28(1, common.Req()),
12109
12160
  _ts_metadata48("design:type", Function),
@@ -12750,9 +12801,28 @@ var OAuthCallbackQueryDto = class {
12750
12801
  * is a safe upper bound that rejects clearly malformed payloads.
12751
12802
  *
12752
12803
  * Absent on the error callback RFC 6749 §4.1.2.1 defines — the response a provider sends
12753
- * when the user declines consent. Required whenever `error` is absent, so a callback
12754
- * carrying neither is still the malformed request it always was.
12755
- */
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.
12756
12826
  code;
12757
12827
  /**
12758
12828
  * The provider's error code (RFC 6749 §4.1.2.1) — `access_denied` when the user clicks
@@ -12818,7 +12888,8 @@ var OAuthCallbackQueryDto = class {
12818
12888
  hd;
12819
12889
  };
12820
12890
  _ts_decorate55([
12821
- classValidator.ValidateIf((query) => query.error === void 0),
12891
+ classValidator.ValidateIf((query) => query.error === void 0 || query.error === null),
12892
+ classValidator.IsOptional(),
12822
12893
  classValidator.IsString(),
12823
12894
  classValidator.IsNotEmpty(),
12824
12895
  classValidator.MaxLength(2048),
@@ -13446,6 +13517,350 @@ var OAuthModule = class _OAuthModule {
13446
13517
  OAuthModule = _ts_decorate58([
13447
13518
  common.Module({})
13448
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
13449
13864
  function _ts_decorate59(decorators, target, key, desc) {
13450
13865
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13451
13866
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -13472,6 +13887,62 @@ function _ts_param34(paramIndex, decorator) {
13472
13887
  };
13473
13888
  }
13474
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");
13475
13946
  var COMMON_BASE_WORDS = [
13476
13947
  // The perennial top of every published list.
13477
13948
  "password",
@@ -13777,16 +14248,16 @@ exports.CommonPasswordChecker = class CommonPasswordChecker {
13777
14248
  return false;
13778
14249
  }
13779
14250
  };
13780
- exports.CommonPasswordChecker = _ts_decorate59([
14251
+ exports.CommonPasswordChecker = _ts_decorate60([
13781
14252
  common.Injectable(),
13782
- _ts_param34(0, common.Inject(BYMAX_AUTH_OPTIONS)),
13783
- _ts_param34(0, common.Optional()),
13784
- _ts_metadata56("design:type", Function),
13785
- _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", [
13786
14257
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
13787
14258
  ])
13788
14259
  ], exports.CommonPasswordChecker);
13789
- function _ts_decorate60(decorators, target, key, desc) {
14260
+ function _ts_decorate61(decorators, target, key, desc) {
13790
14261
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13791
14262
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
13792
14263
  r = Reflect.decorate(decorators, target, key, desc);
@@ -13799,7 +14270,7 @@ function _ts_decorate60(decorators, target, key, desc) {
13799
14270
  }
13800
14271
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13801
14272
  }
13802
- __name(_ts_decorate60, "_ts_decorate");
14273
+ __name(_ts_decorate61, "_ts_decorate");
13803
14274
  exports.NoOpEmailProvider = class _NoOpEmailProvider {
13804
14275
  static {
13805
14276
  __name(this, "NoOpEmailProvider");
@@ -13834,12 +14305,12 @@ exports.NoOpEmailProvider = class _NoOpEmailProvider {
13834
14305
  this.logger.log(`sendInvitation \u2192 ${maskEmail(email)} (no-op)`);
13835
14306
  }
13836
14307
  };
13837
- exports.NoOpEmailProvider = _ts_decorate60([
14308
+ exports.NoOpEmailProvider = _ts_decorate61([
13838
14309
  common.Injectable()
13839
14310
  ], exports.NoOpEmailProvider);
13840
14311
 
13841
14312
  // src/server/bymax-auth.module.ts
13842
- function _ts_decorate61(decorators, target, key, desc) {
14313
+ function _ts_decorate62(decorators, target, key, desc) {
13843
14314
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13844
14315
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
13845
14316
  r = Reflect.decorate(decorators, target, key, desc);
@@ -13852,7 +14323,7 @@ function _ts_decorate61(decorators, target, key, desc) {
13852
14323
  }
13853
14324
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13854
14325
  }
13855
- __name(_ts_decorate61, "_ts_decorate");
14326
+ __name(_ts_decorate62, "_ts_decorate");
13856
14327
  function hasProviderToken(providers, token) {
13857
14328
  return providers.some((p) => {
13858
14329
  if (typeof p === "function") return false;
@@ -14027,6 +14498,30 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
14027
14498
  ...extraProviders,
14028
14499
  // Resolved options (depends on consumer's inject tokens).
14029
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,
14030
14525
  // Fallback NoOp providers (skipped if consumer already supplied them).
14031
14526
  ...emailProviders,
14032
14527
  ...breachCheckerProviders,
@@ -14152,7 +14647,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
14152
14647
  };
14153
14648
  }
14154
14649
  };
14155
- exports.BymaxAuthModule = _ts_decorate61([
14650
+ exports.BymaxAuthModule = _ts_decorate62([
14156
14651
  common.Module({})
14157
14652
  ], exports.BymaxAuthModule);
14158
14653
  var CODE_VALIDITY_TEXT = "It expires shortly, so use it soon.";
@@ -14364,7 +14859,7 @@ var DefaultAuthEmailProvider = class _DefaultAuthEmailProvider {
14364
14859
  }
14365
14860
  }
14366
14861
  };
14367
- function _ts_decorate62(decorators, target, key, desc) {
14862
+ function _ts_decorate63(decorators, target, key, desc) {
14368
14863
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14369
14864
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14370
14865
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14377,13 +14872,13 @@ function _ts_decorate62(decorators, target, key, desc) {
14377
14872
  }
14378
14873
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14379
14874
  }
14380
- __name(_ts_decorate62, "_ts_decorate");
14381
- function _ts_metadata57(metadataKey, metadataValue) {
14875
+ __name(_ts_decorate63, "_ts_decorate");
14876
+ function _ts_metadata58(metadataKey, metadataValue) {
14382
14877
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14383
14878
  return Reflect.metadata(metadataKey, metadataValue);
14384
14879
  }
14385
14880
  }
14386
- __name(_ts_metadata57, "_ts_metadata");
14881
+ __name(_ts_metadata58, "_ts_metadata");
14387
14882
  var HIBP_RANGE_URL = "https://api.pwnedpasswords.com/range/";
14388
14883
  var PREFIX_LENGTH = 5;
14389
14884
  var DEFAULT_TIMEOUT_MS = 1500;
@@ -14440,10 +14935,10 @@ exports.HibpBreachChecker = class _HibpBreachChecker {
14440
14935
  }
14441
14936
  }
14442
14937
  };
14443
- exports.HibpBreachChecker = _ts_decorate62([
14938
+ exports.HibpBreachChecker = _ts_decorate63([
14444
14939
  common.Injectable(),
14445
- _ts_metadata57("design:type", Function),
14446
- _ts_metadata57("design:paramtypes", [
14940
+ _ts_metadata58("design:type", Function),
14941
+ _ts_metadata58("design:paramtypes", [
14447
14942
  Number
14448
14943
  ])
14449
14944
  ], exports.HibpBreachChecker);
@@ -14456,10 +14951,10 @@ exports.AllowAllBreachChecker = class AllowAllBreachChecker {
14456
14951
  return false;
14457
14952
  }
14458
14953
  };
14459
- exports.AllowAllBreachChecker = _ts_decorate62([
14954
+ exports.AllowAllBreachChecker = _ts_decorate63([
14460
14955
  common.Injectable()
14461
14956
  ], exports.AllowAllBreachChecker);
14462
- function _ts_decorate63(decorators, target, key, desc) {
14957
+ function _ts_decorate64(decorators, target, key, desc) {
14463
14958
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14464
14959
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14465
14960
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14472,7 +14967,7 @@ function _ts_decorate63(decorators, target, key, desc) {
14472
14967
  }
14473
14968
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14474
14969
  }
14475
- __name(_ts_decorate63, "_ts_decorate");
14970
+ __name(_ts_decorate64, "_ts_decorate");
14476
14971
  exports.OptionalAuthGuard = class OptionalAuthGuard extends exports.JwtAuthGuard {
14477
14972
  static {
14478
14973
  __name(this, "OptionalAuthGuard");
@@ -14487,10 +14982,10 @@ exports.OptionalAuthGuard = class OptionalAuthGuard extends exports.JwtAuthGuard
14487
14982
  return super.canActivate(context);
14488
14983
  }
14489
14984
  };
14490
- exports.OptionalAuthGuard = _ts_decorate63([
14985
+ exports.OptionalAuthGuard = _ts_decorate64([
14491
14986
  common.Injectable()
14492
14987
  ], exports.OptionalAuthGuard);
14493
- function _ts_decorate64(decorators, target, key, desc) {
14988
+ function _ts_decorate65(decorators, target, key, desc) {
14494
14989
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14495
14990
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14496
14991
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14503,19 +14998,19 @@ function _ts_decorate64(decorators, target, key, desc) {
14503
14998
  }
14504
14999
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14505
15000
  }
14506
- __name(_ts_decorate64, "_ts_decorate");
14507
- function _ts_metadata58(metadataKey, metadataValue) {
15001
+ __name(_ts_decorate65, "_ts_decorate");
15002
+ function _ts_metadata59(metadataKey, metadataValue) {
14508
15003
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14509
15004
  return Reflect.metadata(metadataKey, metadataValue);
14510
15005
  }
14511
15006
  }
14512
- __name(_ts_metadata58, "_ts_metadata");
14513
- function _ts_param35(paramIndex, decorator) {
15007
+ __name(_ts_metadata59, "_ts_metadata");
15008
+ function _ts_param36(paramIndex, decorator) {
14514
15009
  return function(target, key) {
14515
15010
  decorator(target, key, paramIndex);
14516
15011
  };
14517
15012
  }
14518
- __name(_ts_param35, "_ts_param");
15013
+ __name(_ts_param36, "_ts_param");
14519
15014
  exports.SelfOrAdminGuard = class SelfOrAdminGuard {
14520
15015
  static {
14521
15016
  __name(this, "SelfOrAdminGuard");
@@ -14545,11 +15040,11 @@ exports.SelfOrAdminGuard = class SelfOrAdminGuard {
14545
15040
  throw new AuthException(AUTH_ERROR_CODES.INSUFFICIENT_ROLE);
14546
15041
  }
14547
15042
  };
14548
- exports.SelfOrAdminGuard = _ts_decorate64([
15043
+ exports.SelfOrAdminGuard = _ts_decorate65([
14549
15044
  common.Injectable(),
14550
- _ts_param35(0, common.Inject(BYMAX_AUTH_OPTIONS)),
14551
- _ts_metadata58("design:type", Function),
14552
- _ts_metadata58("design:paramtypes", [
15045
+ _ts_param36(0, common.Inject(BYMAX_AUTH_OPTIONS)),
15046
+ _ts_metadata59("design:type", Function),
15047
+ _ts_metadata59("design:paramtypes", [
14553
15048
  typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
14554
15049
  ])
14555
15050
  ], exports.SelfOrAdminGuard);
@@ -14562,7 +15057,7 @@ function isHexLooking(value) {
14562
15057
  return value.length === 64 && /^[a-fA-F0-9]{64}$/.test(value);
14563
15058
  }
14564
15059
  __name(isHexLooking, "isHexLooking");
14565
- function _ts_decorate65(decorators, target, key, desc) {
15060
+ function _ts_decorate66(decorators, target, key, desc) {
14566
15061
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14567
15062
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14568
15063
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14575,19 +15070,19 @@ function _ts_decorate65(decorators, target, key, desc) {
14575
15070
  }
14576
15071
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14577
15072
  }
14578
- __name(_ts_decorate65, "_ts_decorate");
14579
- function _ts_metadata59(metadataKey, metadataValue) {
15073
+ __name(_ts_decorate66, "_ts_decorate");
15074
+ function _ts_metadata60(metadataKey, metadataValue) {
14580
15075
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
14581
15076
  return Reflect.metadata(metadataKey, metadataValue);
14582
15077
  }
14583
15078
  }
14584
- __name(_ts_metadata59, "_ts_metadata");
14585
- function _ts_param36(paramIndex, decorator) {
15079
+ __name(_ts_metadata60, "_ts_metadata");
15080
+ function _ts_param37(paramIndex, decorator) {
14586
15081
  return function(target, key) {
14587
15082
  decorator(target, key, paramIndex);
14588
15083
  };
14589
15084
  }
14590
- __name(_ts_param36, "_ts_param");
15085
+ __name(_ts_param37, "_ts_param");
14591
15086
  exports.WsJwtGuard = class WsJwtGuard {
14592
15087
  static {
14593
15088
  __name(this, "WsJwtGuard");
@@ -14615,14 +15110,18 @@ exports.WsJwtGuard = class WsJwtGuard {
14615
15110
  }
14616
15111
  async canActivate(context) {
14617
15112
  const client = context.switchToWs().getClient();
14618
- 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);
14619
15118
  if (ticket !== void 0) {
14620
15119
  const snapshot = await this.wsTickets.redeem(ticket);
14621
15120
  assertDashboardSnapshot(snapshot);
14622
15121
  client.data.user = snapshot;
14623
15122
  return true;
14624
15123
  }
14625
- const authHeader = client.handshake.headers["authorization"];
15124
+ const authHeader = handshake.headers["authorization"];
14626
15125
  const token = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : void 0;
14627
15126
  if (!token) {
14628
15127
  throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
@@ -14645,14 +15144,14 @@ exports.WsJwtGuard = class WsJwtGuard {
14645
15144
  return true;
14646
15145
  }
14647
15146
  };
14648
- exports.WsJwtGuard = _ts_decorate65([
15147
+ exports.WsJwtGuard = _ts_decorate66([
14649
15148
  common.Injectable(),
14650
- _ts_param36(0, common.Inject(jwt.JwtService)),
14651
- _ts_param36(1, common.Inject(exports.AuthRevocationService)),
14652
- _ts_param36(2, common.Inject(exports.WsTicketService)),
14653
- _ts_param36(3, common.Inject(BYMAX_AUTH_OPTIONS)),
14654
- _ts_metadata59("design:type", Function),
14655
- _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", [
14656
15155
  typeof jwt.JwtService === "undefined" ? Object : jwt.JwtService,
14657
15156
  typeof exports.AuthRevocationService === "undefined" ? Object : exports.AuthRevocationService,
14658
15157
  typeof exports.WsTicketService === "undefined" ? Object : exports.WsTicketService,
@@ -14668,11 +15167,11 @@ function assertDashboardSnapshot(snapshot) {
14668
15167
  }
14669
15168
  }
14670
15169
  __name(assertDashboardSnapshot, "assertDashboardSnapshot");
14671
- function readUpgradeTicket(client) {
14672
- const fromQuery = client.handshake.query?.["ticket"];
15170
+ function readUpgradeTicket(handshake) {
15171
+ const fromQuery = handshake.query?.["ticket"];
14673
15172
  if (typeof fromQuery === "string" && fromQuery !== "") return fromQuery;
14674
15173
  if (fromQuery !== void 0) return void 0;
14675
- const url = client.handshake.url;
15174
+ const url = handshake.url;
14676
15175
  if (typeof url !== "string") return void 0;
14677
15176
  if (url === "") return void 0;
14678
15177
  let params;
@@ -14685,7 +15184,7 @@ function readUpgradeTicket(client) {
14685
15184
  return all.length === 1 && all[0] !== "" ? all[0] : void 0;
14686
15185
  }
14687
15186
  __name(readUpgradeTicket, "readUpgradeTicket");
14688
- function _ts_decorate66(decorators, target, key, desc) {
15187
+ function _ts_decorate67(decorators, target, key, desc) {
14689
15188
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14690
15189
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
14691
15190
  r = Reflect.decorate(decorators, target, key, desc);
@@ -14698,7 +15197,7 @@ function _ts_decorate66(decorators, target, key, desc) {
14698
15197
  }
14699
15198
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14700
15199
  }
14701
- __name(_ts_decorate66, "_ts_decorate");
15200
+ __name(_ts_decorate67, "_ts_decorate");
14702
15201
  function isAuthEnvelope(body) {
14703
15202
  if (typeof body !== "object" || body === null) return false;
14704
15203
  const error = body.error;
@@ -14750,9 +15249,69 @@ exports.AuthExceptionFilter = class _AuthExceptionFilter {
14750
15249
  });
14751
15250
  }
14752
15251
  };
14753
- exports.AuthExceptionFilter = _ts_decorate66([
15252
+ exports.AuthExceptionFilter = _ts_decorate67([
14754
15253
  common.Catch()
14755
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);
14756
15315
 
14757
15316
  exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
14758
15317
  exports.AUTH_ERROR_MESSAGES = AUTH_ERROR_MESSAGES;