@bymax-one/nest-auth 1.0.0

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.
@@ -0,0 +1,240 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+
6
+ // src/shared/constants/cookie-defaults.ts
7
+ var AUTH_ACCESS_COOKIE_NAME = "access_token";
8
+ var AUTH_REFRESH_COOKIE_NAME = "refresh_token";
9
+ var AUTH_HAS_SESSION_COOKIE_NAME = "has_session";
10
+ var AUTH_REFRESH_COOKIE_PATH = "/auth";
11
+
12
+ // src/shared/constants/error-codes.ts
13
+ var AUTH_ERROR_CODES = {
14
+ // Credentials and account state
15
+ INVALID_CREDENTIALS: "auth.invalid_credentials",
16
+ ACCOUNT_LOCKED: "auth.account_locked",
17
+ ACCOUNT_INACTIVE: "auth.account_inactive",
18
+ ACCOUNT_SUSPENDED: "auth.account_suspended",
19
+ ACCOUNT_BANNED: "auth.account_banned",
20
+ PENDING_APPROVAL: "auth.pending_approval",
21
+ // Tokens and sessions
22
+ TOKEN_EXPIRED: "auth.token_expired",
23
+ TOKEN_REVOKED: "auth.token_revoked",
24
+ TOKEN_INVALID: "auth.token_invalid",
25
+ REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid",
26
+ SESSION_EXPIRED: "auth.session_expired",
27
+ SESSION_LIMIT_REACHED: "auth.session_limit_reached",
28
+ SESSION_NOT_FOUND: "auth.session_not_found",
29
+ // Registration and email
30
+ EMAIL_ALREADY_EXISTS: "auth.email_already_exists",
31
+ EMAIL_NOT_VERIFIED: "auth.email_not_verified",
32
+ // MFA
33
+ MFA_REQUIRED: "auth.mfa_required",
34
+ MFA_INVALID_CODE: "auth.mfa_invalid_code",
35
+ MFA_ALREADY_ENABLED: "auth.mfa_already_enabled",
36
+ MFA_NOT_ENABLED: "auth.mfa_not_enabled",
37
+ MFA_SETUP_REQUIRED: "auth.mfa_setup_required",
38
+ MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid",
39
+ RECOVERY_CODE_INVALID: "auth.recovery_code_invalid",
40
+ // Password
41
+ PASSWORD_TOO_WEAK: "auth.password_too_weak",
42
+ PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
43
+ PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired",
44
+ // OTP (email verification, password reset via OTP)
45
+ OTP_INVALID: "auth.otp_invalid",
46
+ OTP_EXPIRED: "auth.otp_expired",
47
+ OTP_MAX_ATTEMPTS: "auth.otp_max_attempts",
48
+ // Authorization
49
+ INSUFFICIENT_ROLE: "auth.insufficient_role",
50
+ FORBIDDEN: "auth.forbidden",
51
+ // Invitations
52
+ INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
53
+ // OAuth
54
+ OAUTH_FAILED: "auth.oauth_failed",
55
+ OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch",
56
+ // Platform admin
57
+ PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required"
58
+ };
59
+
60
+ // src/shared/constants/routes.ts
61
+ var AUTH_DASHBOARD_ROUTES = {
62
+ /** POST — register a new local (email + password) user. */
63
+ register: "register",
64
+ /** POST — exchange credentials for an access token (or MFA challenge). */
65
+ login: "login",
66
+ /** POST — revoke the current access and refresh tokens. */
67
+ logout: "logout",
68
+ /** POST — rotate a valid refresh token for a fresh access token. */
69
+ refresh: "refresh",
70
+ /** GET — return the currently authenticated user. */
71
+ me: "me",
72
+ /** POST — submit the email-verification token returned by the verification email. */
73
+ verifyEmail: "verify-email",
74
+ /** POST — request a fresh email-verification token. */
75
+ resendVerification: "resend-verification"
76
+ };
77
+ var AUTH_MFA_ROUTES = {
78
+ /** POST — begin TOTP enrollment and return the secret + provisioning URI. */
79
+ setup: "mfa/setup",
80
+ /** POST — confirm TOTP enrollment by submitting the first valid code. */
81
+ verifyEnable: "mfa/verify-enable",
82
+ /** POST — exchange an MFA temp token + OTP for a full access token. */
83
+ challenge: "mfa/challenge",
84
+ /** POST — disable MFA after re-authenticating with a fresh OTP. */
85
+ disable: "mfa/disable"
86
+ };
87
+ var AUTH_PASSWORD_ROUTES = {
88
+ /** POST — request a password reset (email lookup is anti-enumeration). */
89
+ forgotPassword: "password/forgot-password",
90
+ /** POST — submit a new password using the reset token. */
91
+ resetPassword: "password/reset-password",
92
+ /** POST — verify the reset OTP (when `passwordReset.method = 'otp'`). */
93
+ verifyOtp: "password/verify-otp",
94
+ /** POST — request a fresh OTP after the previous one expired. */
95
+ resendOtp: "password/resend-otp"
96
+ };
97
+ var AUTH_PLATFORM_ROUTES = {
98
+ /** POST — exchange platform admin credentials for an access token. */
99
+ login: "platform/login",
100
+ /** POST — exchange an MFA temp token + OTP for a platform access token. */
101
+ mfaChallenge: "platform/mfa/challenge",
102
+ /** GET — return the currently authenticated platform administrator. */
103
+ me: "platform/me",
104
+ /** POST — revoke the platform access and refresh tokens. */
105
+ logout: "platform/logout",
106
+ /** POST — rotate a platform refresh token for a fresh access token. */
107
+ refresh: "platform/refresh",
108
+ /** DELETE — revoke every active session for the current platform admin. */
109
+ revokeAllSessions: "platform/sessions"
110
+ };
111
+ var AUTH_SESSION_ROUTES = {
112
+ /** GET — list every active session for the current user. */
113
+ list: "sessions",
114
+ /** DELETE — revoke every session belonging to the current user. */
115
+ revokeAll: "sessions/all",
116
+ /**
117
+ * DELETE — revoke a single session by id. The `:id` placeholder must be
118
+ * substituted with the session identifier before the request is issued.
119
+ */
120
+ revokeOne: "sessions/:id"
121
+ };
122
+ var AUTH_INVITATION_ROUTES = {
123
+ /** POST — create a new invitation (admin-only). */
124
+ create: "invitations",
125
+ /** POST — accept an invitation token and register the recipient. */
126
+ accept: "invitations/accept"
127
+ };
128
+ var AUTH_ROUTES = {
129
+ dashboard: AUTH_DASHBOARD_ROUTES,
130
+ mfa: AUTH_MFA_ROUTES,
131
+ password: AUTH_PASSWORD_ROUTES,
132
+ platform: AUTH_PLATFORM_ROUTES,
133
+ sessions: AUTH_SESSION_ROUTES,
134
+ invitations: AUTH_INVITATION_ROUTES
135
+ };
136
+ var AUTH_PROXY_ROUTES = {
137
+ /** POST — same-domain refresh entry point (server-to-server). */
138
+ clientRefresh: "/api/auth/client-refresh",
139
+ /** GET — invisible refresh used by the proxy to reissue tokens. */
140
+ silentRefresh: "/api/auth/silent-refresh",
141
+ /** POST — Next.js logout proxy (clears cookies + revokes server-side). */
142
+ logout: "/api/auth/logout"
143
+ };
144
+ var AUTH_REFRESH_SKIP_CONTROLLER_PATHS = [
145
+ // Dashboard auth-issuing endpoints
146
+ "register",
147
+ "login",
148
+ "refresh",
149
+ "logout",
150
+ "verify-email",
151
+ "resend-verification",
152
+ // Password reset endpoints
153
+ "password/forgot-password",
154
+ "password/reset-password",
155
+ "password/verify-otp",
156
+ "password/resend-otp",
157
+ // MFA endpoints
158
+ "mfa/setup",
159
+ "mfa/verify-enable",
160
+ "mfa/challenge",
161
+ "mfa/disable",
162
+ // Invitation acceptance issues tokens
163
+ "invitations/accept",
164
+ // Platform endpoints
165
+ "platform/login",
166
+ "platform/refresh",
167
+ "platform/logout",
168
+ "platform/mfa/challenge",
169
+ "platform/sessions"
170
+ ];
171
+ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
172
+ "/api/auth/client-refresh",
173
+ "/api/auth/silent-refresh"
174
+ ];
175
+ function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
176
+ const normalized = routePrefix.replace(/^\/+|\/+$/g, "");
177
+ const prefix = normalized.length > 0 ? `/${normalized}` : "";
178
+ return [
179
+ ...AUTH_REFRESH_SKIP_CONTROLLER_PATHS.map((path) => `${prefix}/${path}`),
180
+ ...AUTH_REFRESH_SKIP_PROXY_PATHS
181
+ ];
182
+ }
183
+ __name(buildAuthRefreshSkipSuffixes, "buildAuthRefreshSkipSuffixes");
184
+ var AUTH_REFRESH_SKIP_PATH_SUFFIXES = buildAuthRefreshSkipSuffixes();
185
+
186
+ // src/shared/types/auth-error.types.ts
187
+ var AuthClientError = class extends Error {
188
+ static {
189
+ __name(this, "AuthClientError");
190
+ }
191
+ /** The HTTP status code returned by the server. */
192
+ status;
193
+ /**
194
+ * The stable machine-readable error code from `AUTH_ERROR_CODES`,
195
+ * when the server provided one.
196
+ */
197
+ code;
198
+ /** The full parsed error body, if the response carried JSON. */
199
+ body;
200
+ constructor(message, status, body) {
201
+ super(message);
202
+ this.name = "AuthClientError";
203
+ this.status = status;
204
+ this.code = body?.code;
205
+ this.body = body;
206
+ }
207
+ /**
208
+ * Strips potentially sensitive request echoes from structured-logger output.
209
+ *
210
+ * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
211
+ * responses; without this override, `JSON.stringify(error)` would persist
212
+ * those fields verbatim into application logs. The serialized form keeps
213
+ * only the fields a log consumer actually needs to triage an auth failure.
214
+ */
215
+ toJSON() {
216
+ return {
217
+ name: this.name,
218
+ message: this.message,
219
+ status: this.status,
220
+ code: this.code
221
+ };
222
+ }
223
+ };
224
+
225
+ exports.AUTH_ACCESS_COOKIE_NAME = AUTH_ACCESS_COOKIE_NAME;
226
+ exports.AUTH_DASHBOARD_ROUTES = AUTH_DASHBOARD_ROUTES;
227
+ exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
228
+ exports.AUTH_HAS_SESSION_COOKIE_NAME = AUTH_HAS_SESSION_COOKIE_NAME;
229
+ exports.AUTH_INVITATION_ROUTES = AUTH_INVITATION_ROUTES;
230
+ exports.AUTH_MFA_ROUTES = AUTH_MFA_ROUTES;
231
+ exports.AUTH_PASSWORD_ROUTES = AUTH_PASSWORD_ROUTES;
232
+ exports.AUTH_PLATFORM_ROUTES = AUTH_PLATFORM_ROUTES;
233
+ exports.AUTH_PROXY_ROUTES = AUTH_PROXY_ROUTES;
234
+ exports.AUTH_REFRESH_COOKIE_NAME = AUTH_REFRESH_COOKIE_NAME;
235
+ exports.AUTH_REFRESH_COOKIE_PATH = AUTH_REFRESH_COOKIE_PATH;
236
+ exports.AUTH_REFRESH_SKIP_PATH_SUFFIXES = AUTH_REFRESH_SKIP_PATH_SUFFIXES;
237
+ exports.AUTH_ROUTES = AUTH_ROUTES;
238
+ exports.AUTH_SESSION_ROUTES = AUTH_SESSION_ROUTES;
239
+ exports.AuthClientError = AuthClientError;
240
+ exports.buildAuthRefreshSkipSuffixes = buildAuthRefreshSkipSuffixes;