@bymax-one/nest-auth 1.0.11 → 1.1.1

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.
@@ -22,13 +22,14 @@ var AUTH_ERROR_CODES = {
22
22
  TOKEN_EXPIRED: "auth.token_expired",
23
23
  TOKEN_REVOKED: "auth.token_revoked",
24
24
  TOKEN_INVALID: "auth.token_invalid",
25
+ /** Internal-only: the request carried no credential. Never on the wire — see TOKEN_INVALID. */
26
+ TOKEN_MISSING: "auth.token_missing",
25
27
  REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid",
26
- SESSION_EXPIRED: "auth.session_expired",
27
- SESSION_LIMIT_REACHED: "auth.session_limit_reached",
28
28
  SESSION_NOT_FOUND: "auth.session_not_found",
29
29
  // Registration and email
30
30
  EMAIL_ALREADY_EXISTS: "auth.email_already_exists",
31
31
  EMAIL_NOT_VERIFIED: "auth.email_not_verified",
32
+ EMAIL_CHANGE_TOKEN_INVALID: "auth.email_change_token_invalid",
32
33
  // MFA
33
34
  MFA_REQUIRED: "auth.mfa_required",
34
35
  MFA_INVALID_CODE: "auth.mfa_invalid_code",
@@ -36,25 +37,55 @@ var AUTH_ERROR_CODES = {
36
37
  MFA_NOT_ENABLED: "auth.mfa_not_enabled",
37
38
  MFA_SETUP_REQUIRED: "auth.mfa_setup_required",
38
39
  MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid",
39
- RECOVERY_CODE_INVALID: "auth.recovery_code_invalid",
40
+ MFA_STATE_CONFLICT: "auth.mfa_state_conflict",
40
41
  // Password
41
- PASSWORD_TOO_WEAK: "auth.password_too_weak",
42
+ /** The password appears in a known-breach corpus. */
43
+ PASSWORD_COMPROMISED: "auth.password_compromised",
42
44
  PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
43
- PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired",
44
45
  // OTP (email verification, password reset via OTP)
46
+ /**
47
+ * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
48
+ * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
49
+ * answers the same whether or not the address exists, but only writes an OTP record when it
50
+ * does, so telling them apart made that uniform answer definitive after one extra request.
51
+ */
45
52
  OTP_INVALID: "auth.otp_invalid",
53
+ /** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
46
54
  OTP_EXPIRED: "auth.otp_expired",
55
+ /** Internal-only: the attempt ceiling was hit. Never on the wire — see {@link OTP_INVALID}. */
47
56
  OTP_MAX_ATTEMPTS: "auth.otp_max_attempts",
48
57
  // Authorization
49
58
  INSUFFICIENT_ROLE: "auth.insufficient_role",
50
59
  FORBIDDEN: "auth.forbidden",
60
+ /**
61
+ * The request body or query failed DTO validation. Per-field failures serialize into
62
+ * `error.details` as `[{ field, message }]`.
63
+ */
64
+ VALIDATION: "auth.validation",
65
+ /** The caller exceeded a per-IP rate limit on an auth route. */
66
+ TOO_MANY_REQUESTS: "auth.too_many_requests",
67
+ /**
68
+ * A state-changing request carrying the session cookie came from an origin the deployment
69
+ * does not trust.
70
+ */
71
+ UNTRUSTED_ORIGIN: "auth.untrusted_origin",
72
+ /**
73
+ * A change to how the account authenticates was attempted without a recent authentication.
74
+ * The client should send the user back through sign-in and retry.
75
+ */
76
+ REAUTHENTICATION_REQUIRED: "auth.reauthentication_required",
51
77
  // Invitations
52
78
  INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
53
79
  // OAuth
54
80
  OAUTH_FAILED: "auth.oauth_failed",
55
81
  OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch",
56
82
  // Platform admin
57
- PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required"
83
+ PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required",
84
+ /**
85
+ * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
86
+ * which gives unhandled failures the same envelope everything else answers with.
87
+ */
88
+ INTERNAL: "auth.internal"
58
89
  };
59
90
 
60
91
  // src/shared/constants/routes.ts
@@ -119,11 +150,19 @@ var AUTH_SESSION_ROUTES = {
119
150
  */
120
151
  revokeOne: "sessions/:id"
121
152
  };
153
+ var AUTH_EMAIL_CHANGE_ROUTES = {
154
+ /** POST — request a change; mails a token to the new address. */
155
+ request: "email/change",
156
+ /** POST — confirm the change with that token. */
157
+ confirm: "email/change/confirm"
158
+ };
122
159
  var AUTH_INVITATION_ROUTES = {
123
160
  /** POST — create a new invitation (admin-only). */
124
161
  create: "invitations",
125
162
  /** POST — accept an invitation token and register the recipient. */
126
- accept: "invitations/accept"
163
+ accept: "invitations/accept",
164
+ /** POST — withdraw a pending invitation before it is accepted (admin-only). */
165
+ revoke: "invitations/revoke"
127
166
  };
128
167
  var AUTH_ROUTES = {
129
168
  dashboard: AUTH_DASHBOARD_ROUTES,
@@ -131,7 +170,8 @@ var AUTH_ROUTES = {
131
170
  password: AUTH_PASSWORD_ROUTES,
132
171
  platform: AUTH_PLATFORM_ROUTES,
133
172
  sessions: AUTH_SESSION_ROUTES,
134
- invitations: AUTH_INVITATION_ROUTES
173
+ invitations: AUTH_INVITATION_ROUTES,
174
+ emailChange: AUTH_EMAIL_CHANGE_ROUTES
135
175
  };
136
176
  var AUTH_PROXY_ROUTES = {
137
177
  /** POST — same-domain refresh entry point (server-to-server). */
@@ -161,6 +201,9 @@ var AUTH_REFRESH_SKIP_CONTROLLER_PATHS = [
161
201
  "mfa/disable",
162
202
  // Invitation acceptance issues tokens
163
203
  "invitations/accept",
204
+ // The address-change confirmation is public: the holder is proving control of a mailbox,
205
+ // not of a session.
206
+ "email/change/confirm",
164
207
  // Platform endpoints
165
208
  "platform/login",
166
209
  "platform/refresh",
@@ -172,8 +215,16 @@ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
172
215
  "/api/auth/client-refresh",
173
216
  "/api/auth/silent-refresh"
174
217
  ];
218
+ function trimSlashes(value) {
219
+ let start = 0;
220
+ let end = value.length;
221
+ while (start < end && value[start] === "/") start += 1;
222
+ while (end > start && value[end - 1] === "/") end -= 1;
223
+ return value.slice(start, end);
224
+ }
225
+ __name(trimSlashes, "trimSlashes");
175
226
  function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
176
- const normalized = routePrefix.replace(/^\/+|\/+$/g, "");
227
+ const normalized = trimSlashes(routePrefix);
177
228
  const prefix = normalized.length > 0 ? `/${normalized}` : "";
178
229
  return [
179
230
  ...AUTH_REFRESH_SKIP_CONTROLLER_PATHS.map((path) => `${prefix}/${path}`),
@@ -78,31 +78,62 @@ declare const AUTH_ERROR_CODES: {
78
78
  readonly TOKEN_EXPIRED: "auth.token_expired";
79
79
  readonly TOKEN_REVOKED: "auth.token_revoked";
80
80
  readonly TOKEN_INVALID: "auth.token_invalid";
81
+ /** Internal-only: the request carried no credential. Never on the wire — see TOKEN_INVALID. */
82
+ readonly TOKEN_MISSING: "auth.token_missing";
81
83
  readonly REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid";
82
- readonly SESSION_EXPIRED: "auth.session_expired";
83
- readonly SESSION_LIMIT_REACHED: "auth.session_limit_reached";
84
84
  readonly SESSION_NOT_FOUND: "auth.session_not_found";
85
85
  readonly EMAIL_ALREADY_EXISTS: "auth.email_already_exists";
86
86
  readonly EMAIL_NOT_VERIFIED: "auth.email_not_verified";
87
+ readonly EMAIL_CHANGE_TOKEN_INVALID: "auth.email_change_token_invalid";
87
88
  readonly MFA_REQUIRED: "auth.mfa_required";
88
89
  readonly MFA_INVALID_CODE: "auth.mfa_invalid_code";
89
90
  readonly MFA_ALREADY_ENABLED: "auth.mfa_already_enabled";
90
91
  readonly MFA_NOT_ENABLED: "auth.mfa_not_enabled";
91
92
  readonly MFA_SETUP_REQUIRED: "auth.mfa_setup_required";
92
93
  readonly MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid";
93
- readonly RECOVERY_CODE_INVALID: "auth.recovery_code_invalid";
94
- readonly PASSWORD_TOO_WEAK: "auth.password_too_weak";
94
+ readonly MFA_STATE_CONFLICT: "auth.mfa_state_conflict";
95
+ /** The password appears in a known-breach corpus. */
96
+ readonly PASSWORD_COMPROMISED: "auth.password_compromised";
95
97
  readonly PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid";
96
- readonly PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired";
98
+ /**
99
+ * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
100
+ * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
101
+ * answers the same whether or not the address exists, but only writes an OTP record when it
102
+ * does, so telling them apart made that uniform answer definitive after one extra request.
103
+ */
97
104
  readonly OTP_INVALID: "auth.otp_invalid";
105
+ /** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
98
106
  readonly OTP_EXPIRED: "auth.otp_expired";
107
+ /** Internal-only: the attempt ceiling was hit. Never on the wire — see {@link OTP_INVALID}. */
99
108
  readonly OTP_MAX_ATTEMPTS: "auth.otp_max_attempts";
100
109
  readonly INSUFFICIENT_ROLE: "auth.insufficient_role";
101
110
  readonly FORBIDDEN: "auth.forbidden";
111
+ /**
112
+ * The request body or query failed DTO validation. Per-field failures serialize into
113
+ * `error.details` as `[{ field, message }]`.
114
+ */
115
+ readonly VALIDATION: "auth.validation";
116
+ /** The caller exceeded a per-IP rate limit on an auth route. */
117
+ readonly TOO_MANY_REQUESTS: "auth.too_many_requests";
118
+ /**
119
+ * A state-changing request carrying the session cookie came from an origin the deployment
120
+ * does not trust.
121
+ */
122
+ readonly UNTRUSTED_ORIGIN: "auth.untrusted_origin";
123
+ /**
124
+ * A change to how the account authenticates was attempted without a recent authentication.
125
+ * The client should send the user back through sign-in and retry.
126
+ */
127
+ readonly REAUTHENTICATION_REQUIRED: "auth.reauthentication_required";
102
128
  readonly INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token";
103
129
  readonly OAUTH_FAILED: "auth.oauth_failed";
104
130
  readonly OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch";
105
131
  readonly PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required";
132
+ /**
133
+ * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
134
+ * which gives unhandled failures the same envelope everything else answers with.
135
+ */
136
+ readonly INTERNAL: "auth.internal";
106
137
  };
107
138
  /**
108
139
  * String literal union of every `AUTH_ERROR_CODES` value.
@@ -228,6 +259,8 @@ declare const AUTH_INVITATION_ROUTES: {
228
259
  readonly create: "invitations";
229
260
  /** POST — accept an invitation token and register the recipient. */
230
261
  readonly accept: "invitations/accept";
262
+ /** POST — withdraw a pending invitation before it is accepted (admin-only). */
263
+ readonly revoke: "invitations/revoke";
231
264
  };
232
265
  /**
233
266
  * Aggregated route map grouped by domain.
@@ -302,6 +335,14 @@ declare const AUTH_ROUTES: {
302
335
  readonly create: "invitations";
303
336
  /** POST — accept an invitation token and register the recipient. */
304
337
  readonly accept: "invitations/accept";
338
+ /** POST — withdraw a pending invitation before it is accepted (admin-only). */
339
+ readonly revoke: "invitations/revoke";
340
+ };
341
+ readonly emailChange: {
342
+ /** POST — request a change; mails a token to the new address. */
343
+ readonly request: "email/change";
344
+ /** POST — confirm the change with that token. */
345
+ readonly confirm: "email/change/confirm";
305
346
  };
306
347
  };
307
348
  /**
@@ -338,10 +379,10 @@ declare function buildAuthRefreshSkipSuffixes(routePrefix?: string): readonly st
338
379
  /**
339
380
  * Default pathname-suffix skip list for the canonical `'auth'` prefix.
340
381
  *
341
- * Exported for backwards compatibility and for consumers who know they
342
- * use the default prefix. Non-default deployments should call
343
- * {@link buildAuthRefreshSkipSuffixes} directly or pass `routePrefix`
344
- * to `createAuthFetch`/`createAuthClient`.
382
+ * A convenience for the overwhelmingly common case — the default `routePrefix: 'auth'` —
383
+ * so a consumer on it does not have to call the builder to get the same array. Any other
384
+ * prefix must call {@link buildAuthRefreshSkipSuffixes} or pass `routePrefix` to
385
+ * `createAuthFetch` / `createAuthClient`: this list would silently skip the wrong paths.
345
386
  */
346
387
  declare const AUTH_REFRESH_SKIP_PATH_SUFFIXES: readonly string[];
347
388
 
@@ -502,7 +543,7 @@ interface MfaChallengeResult {
502
543
  * Discriminated union of all possible login responses.
503
544
  *
504
545
  * Use this type as the return type of any login method that may either
505
- * complete the auth flow or escalate to an MFA challenge step.
546
+ * complete the auth flow or escalate to an MFA challenge.
506
547
  */
507
548
  type LoginResult = AuthResult | MfaChallengeResult;
508
549
  /**
@@ -510,6 +551,12 @@ type LoginResult = AuthResult | MfaChallengeResult;
510
551
  */
511
552
  type PlatformLoginResult = PlatformAuthResult | MfaChallengeResult;
512
553
 
554
+ /**
555
+ * @fileoverview Shared error-related type definitions for `@bymax-one/nest-auth`.
556
+ *
557
+ * @layer Types
558
+ */
559
+
513
560
  /**
514
561
  * Discriminated error-code type carried by `AuthErrorResponse` and
515
562
  * `AuthClientError`.
@@ -522,19 +569,37 @@ type PlatformLoginResult = PlatformAuthResult | MfaChallengeResult;
522
569
  */
523
570
  type AuthResponseCode = AuthErrorCode | (string & {});
524
571
  /**
525
- * Shape of the error response body returned by the @bymax-one/nest-auth server.
572
+ * Normalized view of the error response body returned by an
573
+ * @bymax-one/nest-auth server.
526
574
  *
527
575
  * @remarks
528
- * Mirrors the JSON body emitted by `AuthException` after NestJS's exception
529
- * filter serializes it. The `code` field uses the `auth.<domain>_<action>`
530
- * convention defined by `AUTH_ERROR_CODES` and is the recommended branch
531
- * point for client-side error handling — `message` is meant for end-user
532
- * display and may be localized in the future.
576
+ * Two wire shapes reach a client and both are normalized into this one type:
577
+ *
578
+ * 1. The library's own envelope, emitted by `AuthException`:
579
+ * `{ error: { code, message, details } }`. The client lifts `code`,
580
+ * `message`, and `details` out of the envelope and fills `error` /
581
+ * `statusCode` from the HTTP response itself, since the envelope does
582
+ * not repeat them in the body.
583
+ * 2. A flat NestJS exception body (`{ message, error, statusCode }`), as
584
+ * produced by a `ValidationPipe` 400 or any built-in `HttpException`
585
+ * thrown outside the auth flow. Those pass through unchanged.
586
+ *
587
+ * The `code` field uses the `auth.<domain>_<action>` convention defined by
588
+ * `AUTH_ERROR_CODES` and is the recommended branch point for client-side
589
+ * error handling — `message` is meant for end-user display and may be
590
+ * localized in the future.
533
591
  */
534
592
  interface AuthErrorResponse {
535
593
  /** End-user-facing message (may be localized server-side in future versions). */
536
594
  message: string;
537
- /** HTTP status text (NestJS convention, e.g. `'Unauthorized'`). */
595
+ /**
596
+ * HTTP status text (NestJS convention, e.g. `'Unauthorized'`).
597
+ *
598
+ * For the `AuthException` envelope — which carries no status text — the
599
+ * client fills this from the response's `statusText`, falling back to
600
+ * `'Error'` when the transport omits it (HTTP/2 never sends a reason
601
+ * phrase).
602
+ */
538
603
  error: string;
539
604
  /** HTTP status code (e.g. `401`, `403`). */
540
605
  statusCode: number;
@@ -546,6 +611,14 @@ interface AuthErrorResponse {
546
611
  * (e.g. a `ValidationPipe` 400) may not carry it.
547
612
  */
548
613
  code?: AuthResponseCode;
614
+ /**
615
+ * Structured payload attached by the server under `error.details`
616
+ * (e.g. `{ retryAfterSeconds: 300 }` on a lockout).
617
+ *
618
+ * `null` when the server sent the envelope without details, and absent
619
+ * entirely for flat NestJS bodies, which have no equivalent field.
620
+ */
621
+ details?: Record<string, unknown> | null;
549
622
  }
550
623
  /**
551
624
  * Error thrown by the auth client when an HTTP response is not 2xx.
@@ -620,6 +693,16 @@ interface DashboardJwtPayload {
620
693
  mfaEnabled: boolean;
621
694
  /** Whether the user completed MFA verification before this token was issued. */
622
695
  mfaVerified: boolean;
696
+ /**
697
+ * The user's token **epoch** at issuance — a per-user generation counter the server bumps
698
+ * to invalidate every outstanding access token at once (a password reset). Verification
699
+ * rejects a token whose epoch is below the user's stored epoch.
700
+ *
701
+ * Optional: a token issued before the field existed carries none, which reads as `0` and is
702
+ * never rejected while the stored epoch is also `0` — the mechanism stays inert until the
703
+ * first bump.
704
+ */
705
+ epoch?: number;
623
706
  /** Issued-at timestamp (Unix seconds). */
624
707
  iat: number;
625
708
  /** Expiration timestamp (Unix seconds). */
@@ -645,13 +728,23 @@ interface PlatformJwtPayload {
645
728
  mfaEnabled: boolean;
646
729
  /** Whether the admin completed MFA verification before this token was issued. */
647
730
  mfaVerified: boolean;
731
+ /**
732
+ * The admin's token **epoch** at issuance — a per-user generation counter the server bumps
733
+ * to invalidate every outstanding access token at once (a password reset). Verification
734
+ * rejects a token whose epoch is below the admin's stored epoch.
735
+ *
736
+ * Optional: a token issued before the field existed carries none, which reads as `0` and is
737
+ * never rejected while the stored epoch is also `0` — the mechanism stays inert until the
738
+ * first bump.
739
+ */
740
+ epoch?: number;
648
741
  /** Issued-at timestamp (Unix seconds). */
649
742
  iat: number;
650
743
  /** Expiration timestamp (Unix seconds). */
651
744
  exp: number;
652
745
  }
653
746
  /**
654
- * Short-lived JWT payload issued during an MFA challenge step.
747
+ * Short-lived JWT payload issued during an MFA challenge.
655
748
  *
656
749
  * Grants no resource access on its own — exchanged for a full
657
750
  * {@link DashboardJwtPayload} or {@link PlatformJwtPayload} token after the
@@ -666,6 +759,21 @@ interface MfaTempPayload {
666
759
  type: 'mfa_challenge';
667
760
  /** Indicates which authentication context triggered the MFA challenge. */
668
761
  context: 'dashboard' | 'platform';
762
+ /**
763
+ * The subject's token **epoch** at issuance, in the plane named by `context`.
764
+ *
765
+ * The challenge token is a credential like any other — half of one, held by a caller who has
766
+ * already proved the password — and it must die with the rest when the account's credentials
767
+ * are rotated. Without this claim it did not: a password reset bumps the epoch and kills
768
+ * every access token, but nothing touched an outstanding challenge record, so a token minted
769
+ * before the reset stayed redeemable for its whole TTL and completing it issued a full
770
+ * session under the *new* epoch.
771
+ *
772
+ * Optional for the same reason the access-token epochs are: a token issued before the field
773
+ * existed carries none, which reads as `0` and is never rejected while the stored epoch is
774
+ * also `0`, so the mechanism stays inert until the first bump.
775
+ */
776
+ epoch?: number;
669
777
  /** Issued-at timestamp (Unix seconds). */
670
778
  iat: number;
671
779
  /** Expiration timestamp (Unix seconds). */
@@ -78,31 +78,62 @@ declare const AUTH_ERROR_CODES: {
78
78
  readonly TOKEN_EXPIRED: "auth.token_expired";
79
79
  readonly TOKEN_REVOKED: "auth.token_revoked";
80
80
  readonly TOKEN_INVALID: "auth.token_invalid";
81
+ /** Internal-only: the request carried no credential. Never on the wire — see TOKEN_INVALID. */
82
+ readonly TOKEN_MISSING: "auth.token_missing";
81
83
  readonly REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid";
82
- readonly SESSION_EXPIRED: "auth.session_expired";
83
- readonly SESSION_LIMIT_REACHED: "auth.session_limit_reached";
84
84
  readonly SESSION_NOT_FOUND: "auth.session_not_found";
85
85
  readonly EMAIL_ALREADY_EXISTS: "auth.email_already_exists";
86
86
  readonly EMAIL_NOT_VERIFIED: "auth.email_not_verified";
87
+ readonly EMAIL_CHANGE_TOKEN_INVALID: "auth.email_change_token_invalid";
87
88
  readonly MFA_REQUIRED: "auth.mfa_required";
88
89
  readonly MFA_INVALID_CODE: "auth.mfa_invalid_code";
89
90
  readonly MFA_ALREADY_ENABLED: "auth.mfa_already_enabled";
90
91
  readonly MFA_NOT_ENABLED: "auth.mfa_not_enabled";
91
92
  readonly MFA_SETUP_REQUIRED: "auth.mfa_setup_required";
92
93
  readonly MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid";
93
- readonly RECOVERY_CODE_INVALID: "auth.recovery_code_invalid";
94
- readonly PASSWORD_TOO_WEAK: "auth.password_too_weak";
94
+ readonly MFA_STATE_CONFLICT: "auth.mfa_state_conflict";
95
+ /** The password appears in a known-breach corpus. */
96
+ readonly PASSWORD_COMPROMISED: "auth.password_compromised";
95
97
  readonly PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid";
96
- readonly PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired";
98
+ /**
99
+ * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
100
+ * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
101
+ * answers the same whether or not the address exists, but only writes an OTP record when it
102
+ * does, so telling them apart made that uniform answer definitive after one extra request.
103
+ */
97
104
  readonly OTP_INVALID: "auth.otp_invalid";
105
+ /** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
98
106
  readonly OTP_EXPIRED: "auth.otp_expired";
107
+ /** Internal-only: the attempt ceiling was hit. Never on the wire — see {@link OTP_INVALID}. */
99
108
  readonly OTP_MAX_ATTEMPTS: "auth.otp_max_attempts";
100
109
  readonly INSUFFICIENT_ROLE: "auth.insufficient_role";
101
110
  readonly FORBIDDEN: "auth.forbidden";
111
+ /**
112
+ * The request body or query failed DTO validation. Per-field failures serialize into
113
+ * `error.details` as `[{ field, message }]`.
114
+ */
115
+ readonly VALIDATION: "auth.validation";
116
+ /** The caller exceeded a per-IP rate limit on an auth route. */
117
+ readonly TOO_MANY_REQUESTS: "auth.too_many_requests";
118
+ /**
119
+ * A state-changing request carrying the session cookie came from an origin the deployment
120
+ * does not trust.
121
+ */
122
+ readonly UNTRUSTED_ORIGIN: "auth.untrusted_origin";
123
+ /**
124
+ * A change to how the account authenticates was attempted without a recent authentication.
125
+ * The client should send the user back through sign-in and retry.
126
+ */
127
+ readonly REAUTHENTICATION_REQUIRED: "auth.reauthentication_required";
102
128
  readonly INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token";
103
129
  readonly OAUTH_FAILED: "auth.oauth_failed";
104
130
  readonly OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch";
105
131
  readonly PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required";
132
+ /**
133
+ * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
134
+ * which gives unhandled failures the same envelope everything else answers with.
135
+ */
136
+ readonly INTERNAL: "auth.internal";
106
137
  };
107
138
  /**
108
139
  * String literal union of every `AUTH_ERROR_CODES` value.
@@ -228,6 +259,8 @@ declare const AUTH_INVITATION_ROUTES: {
228
259
  readonly create: "invitations";
229
260
  /** POST — accept an invitation token and register the recipient. */
230
261
  readonly accept: "invitations/accept";
262
+ /** POST — withdraw a pending invitation before it is accepted (admin-only). */
263
+ readonly revoke: "invitations/revoke";
231
264
  };
232
265
  /**
233
266
  * Aggregated route map grouped by domain.
@@ -302,6 +335,14 @@ declare const AUTH_ROUTES: {
302
335
  readonly create: "invitations";
303
336
  /** POST — accept an invitation token and register the recipient. */
304
337
  readonly accept: "invitations/accept";
338
+ /** POST — withdraw a pending invitation before it is accepted (admin-only). */
339
+ readonly revoke: "invitations/revoke";
340
+ };
341
+ readonly emailChange: {
342
+ /** POST — request a change; mails a token to the new address. */
343
+ readonly request: "email/change";
344
+ /** POST — confirm the change with that token. */
345
+ readonly confirm: "email/change/confirm";
305
346
  };
306
347
  };
307
348
  /**
@@ -338,10 +379,10 @@ declare function buildAuthRefreshSkipSuffixes(routePrefix?: string): readonly st
338
379
  /**
339
380
  * Default pathname-suffix skip list for the canonical `'auth'` prefix.
340
381
  *
341
- * Exported for backwards compatibility and for consumers who know they
342
- * use the default prefix. Non-default deployments should call
343
- * {@link buildAuthRefreshSkipSuffixes} directly or pass `routePrefix`
344
- * to `createAuthFetch`/`createAuthClient`.
382
+ * A convenience for the overwhelmingly common case — the default `routePrefix: 'auth'` —
383
+ * so a consumer on it does not have to call the builder to get the same array. Any other
384
+ * prefix must call {@link buildAuthRefreshSkipSuffixes} or pass `routePrefix` to
385
+ * `createAuthFetch` / `createAuthClient`: this list would silently skip the wrong paths.
345
386
  */
346
387
  declare const AUTH_REFRESH_SKIP_PATH_SUFFIXES: readonly string[];
347
388
 
@@ -502,7 +543,7 @@ interface MfaChallengeResult {
502
543
  * Discriminated union of all possible login responses.
503
544
  *
504
545
  * Use this type as the return type of any login method that may either
505
- * complete the auth flow or escalate to an MFA challenge step.
546
+ * complete the auth flow or escalate to an MFA challenge.
506
547
  */
507
548
  type LoginResult = AuthResult | MfaChallengeResult;
508
549
  /**
@@ -510,6 +551,12 @@ type LoginResult = AuthResult | MfaChallengeResult;
510
551
  */
511
552
  type PlatformLoginResult = PlatformAuthResult | MfaChallengeResult;
512
553
 
554
+ /**
555
+ * @fileoverview Shared error-related type definitions for `@bymax-one/nest-auth`.
556
+ *
557
+ * @layer Types
558
+ */
559
+
513
560
  /**
514
561
  * Discriminated error-code type carried by `AuthErrorResponse` and
515
562
  * `AuthClientError`.
@@ -522,19 +569,37 @@ type PlatformLoginResult = PlatformAuthResult | MfaChallengeResult;
522
569
  */
523
570
  type AuthResponseCode = AuthErrorCode | (string & {});
524
571
  /**
525
- * Shape of the error response body returned by the @bymax-one/nest-auth server.
572
+ * Normalized view of the error response body returned by an
573
+ * @bymax-one/nest-auth server.
526
574
  *
527
575
  * @remarks
528
- * Mirrors the JSON body emitted by `AuthException` after NestJS's exception
529
- * filter serializes it. The `code` field uses the `auth.<domain>_<action>`
530
- * convention defined by `AUTH_ERROR_CODES` and is the recommended branch
531
- * point for client-side error handling — `message` is meant for end-user
532
- * display and may be localized in the future.
576
+ * Two wire shapes reach a client and both are normalized into this one type:
577
+ *
578
+ * 1. The library's own envelope, emitted by `AuthException`:
579
+ * `{ error: { code, message, details } }`. The client lifts `code`,
580
+ * `message`, and `details` out of the envelope and fills `error` /
581
+ * `statusCode` from the HTTP response itself, since the envelope does
582
+ * not repeat them in the body.
583
+ * 2. A flat NestJS exception body (`{ message, error, statusCode }`), as
584
+ * produced by a `ValidationPipe` 400 or any built-in `HttpException`
585
+ * thrown outside the auth flow. Those pass through unchanged.
586
+ *
587
+ * The `code` field uses the `auth.<domain>_<action>` convention defined by
588
+ * `AUTH_ERROR_CODES` and is the recommended branch point for client-side
589
+ * error handling — `message` is meant for end-user display and may be
590
+ * localized in the future.
533
591
  */
534
592
  interface AuthErrorResponse {
535
593
  /** End-user-facing message (may be localized server-side in future versions). */
536
594
  message: string;
537
- /** HTTP status text (NestJS convention, e.g. `'Unauthorized'`). */
595
+ /**
596
+ * HTTP status text (NestJS convention, e.g. `'Unauthorized'`).
597
+ *
598
+ * For the `AuthException` envelope — which carries no status text — the
599
+ * client fills this from the response's `statusText`, falling back to
600
+ * `'Error'` when the transport omits it (HTTP/2 never sends a reason
601
+ * phrase).
602
+ */
538
603
  error: string;
539
604
  /** HTTP status code (e.g. `401`, `403`). */
540
605
  statusCode: number;
@@ -546,6 +611,14 @@ interface AuthErrorResponse {
546
611
  * (e.g. a `ValidationPipe` 400) may not carry it.
547
612
  */
548
613
  code?: AuthResponseCode;
614
+ /**
615
+ * Structured payload attached by the server under `error.details`
616
+ * (e.g. `{ retryAfterSeconds: 300 }` on a lockout).
617
+ *
618
+ * `null` when the server sent the envelope without details, and absent
619
+ * entirely for flat NestJS bodies, which have no equivalent field.
620
+ */
621
+ details?: Record<string, unknown> | null;
549
622
  }
550
623
  /**
551
624
  * Error thrown by the auth client when an HTTP response is not 2xx.
@@ -620,6 +693,16 @@ interface DashboardJwtPayload {
620
693
  mfaEnabled: boolean;
621
694
  /** Whether the user completed MFA verification before this token was issued. */
622
695
  mfaVerified: boolean;
696
+ /**
697
+ * The user's token **epoch** at issuance — a per-user generation counter the server bumps
698
+ * to invalidate every outstanding access token at once (a password reset). Verification
699
+ * rejects a token whose epoch is below the user's stored epoch.
700
+ *
701
+ * Optional: a token issued before the field existed carries none, which reads as `0` and is
702
+ * never rejected while the stored epoch is also `0` — the mechanism stays inert until the
703
+ * first bump.
704
+ */
705
+ epoch?: number;
623
706
  /** Issued-at timestamp (Unix seconds). */
624
707
  iat: number;
625
708
  /** Expiration timestamp (Unix seconds). */
@@ -645,13 +728,23 @@ interface PlatformJwtPayload {
645
728
  mfaEnabled: boolean;
646
729
  /** Whether the admin completed MFA verification before this token was issued. */
647
730
  mfaVerified: boolean;
731
+ /**
732
+ * The admin's token **epoch** at issuance — a per-user generation counter the server bumps
733
+ * to invalidate every outstanding access token at once (a password reset). Verification
734
+ * rejects a token whose epoch is below the admin's stored epoch.
735
+ *
736
+ * Optional: a token issued before the field existed carries none, which reads as `0` and is
737
+ * never rejected while the stored epoch is also `0` — the mechanism stays inert until the
738
+ * first bump.
739
+ */
740
+ epoch?: number;
648
741
  /** Issued-at timestamp (Unix seconds). */
649
742
  iat: number;
650
743
  /** Expiration timestamp (Unix seconds). */
651
744
  exp: number;
652
745
  }
653
746
  /**
654
- * Short-lived JWT payload issued during an MFA challenge step.
747
+ * Short-lived JWT payload issued during an MFA challenge.
655
748
  *
656
749
  * Grants no resource access on its own — exchanged for a full
657
750
  * {@link DashboardJwtPayload} or {@link PlatformJwtPayload} token after the
@@ -666,6 +759,21 @@ interface MfaTempPayload {
666
759
  type: 'mfa_challenge';
667
760
  /** Indicates which authentication context triggered the MFA challenge. */
668
761
  context: 'dashboard' | 'platform';
762
+ /**
763
+ * The subject's token **epoch** at issuance, in the plane named by `context`.
764
+ *
765
+ * The challenge token is a credential like any other — half of one, held by a caller who has
766
+ * already proved the password — and it must die with the rest when the account's credentials
767
+ * are rotated. Without this claim it did not: a password reset bumps the epoch and kills
768
+ * every access token, but nothing touched an outstanding challenge record, so a token minted
769
+ * before the reset stayed redeemable for its whole TTL and completing it issued a full
770
+ * session under the *new* epoch.
771
+ *
772
+ * Optional for the same reason the access-token epochs are: a token issued before the field
773
+ * existed carries none, which reads as `0` and is never rejected while the stored epoch is
774
+ * also `0`, so the mechanism stays inert until the first bump.
775
+ */
776
+ epoch?: number;
669
777
  /** Issued-at timestamp (Unix seconds). */
670
778
  iat: number;
671
779
  /** Expiration timestamp (Unix seconds). */