@bymax-one/nest-auth 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +791 -1
- package/README.md +366 -41
- package/dist/client/index.cjs +26 -4
- package/dist/client/index.d.cts +30 -14
- package/dist/client/index.d.ts +30 -14
- package/dist/client/index.mjs +27 -5
- package/dist/server/index.cjs +642 -74
- package/dist/server/index.d.cts +124 -20
- package/dist/server/index.d.ts +124 -20
- package/dist/server/index.mjs +644 -76
- package/dist/shared/index.cjs +62 -10
- package/dist/shared/index.d.cts +112 -5
- package/dist/shared/index.d.ts +112 -5
- package/dist/shared/index.mjs +60 -11
- package/package.json +9 -2
package/dist/shared/index.mjs
CHANGED
|
@@ -17,8 +17,12 @@ var AUTH_ERROR_CODES = {
|
|
|
17
17
|
ACCOUNT_BANNED: "auth.account_banned",
|
|
18
18
|
PENDING_APPROVAL: "auth.pending_approval",
|
|
19
19
|
// Tokens and sessions
|
|
20
|
+
/** Internal-only: expiry. Never on the wire — collapsed onto TOKEN_INVALID, to deny an oracle
|
|
21
|
+
* separating a token that WAS valid from one that never was. */
|
|
20
22
|
TOKEN_EXPIRED: "auth.token_expired",
|
|
23
|
+
/** Internal-only: logout or epoch bump. Never on the wire — see TOKEN_EXPIRED. */
|
|
21
24
|
TOKEN_REVOKED: "auth.token_revoked",
|
|
25
|
+
/** What a client receives for EVERY unusable credential: expired, revoked, malformed, absent. */
|
|
22
26
|
TOKEN_INVALID: "auth.token_invalid",
|
|
23
27
|
/** Internal-only: the request carried no credential. Never on the wire — see TOKEN_INVALID. */
|
|
24
28
|
TOKEN_MISSING: "auth.token_missing",
|
|
@@ -98,6 +102,8 @@ var AUTH_DASHBOARD_ROUTES = {
|
|
|
98
102
|
refresh: "refresh",
|
|
99
103
|
/** GET — return the currently authenticated user. */
|
|
100
104
|
me: "me",
|
|
105
|
+
/** POST — mint a single-use ticket for a WebSocket upgrade. */
|
|
106
|
+
wsTicket: "ws-ticket",
|
|
101
107
|
/** POST — submit the email-verification token returned by the verification email. */
|
|
102
108
|
verifyEmail: "verify-email",
|
|
103
109
|
/** POST — request a fresh email-verification token. */
|
|
@@ -111,13 +117,22 @@ var AUTH_MFA_ROUTES = {
|
|
|
111
117
|
/** POST — exchange an MFA temp token + OTP for a full access token. */
|
|
112
118
|
challenge: "mfa/challenge",
|
|
113
119
|
/** POST — disable MFA after re-authenticating with a fresh OTP. */
|
|
114
|
-
disable: "mfa/disable"
|
|
120
|
+
disable: "mfa/disable",
|
|
121
|
+
/** POST — replace the recovery codes, re-authenticating with a fresh OTP. */
|
|
122
|
+
recoveryCodes: "mfa/recovery-codes"
|
|
115
123
|
};
|
|
116
124
|
var AUTH_PASSWORD_ROUTES = {
|
|
117
125
|
/** POST — request a password reset (email lookup is anti-enumeration). */
|
|
118
126
|
forgotPassword: "password/forgot-password",
|
|
119
127
|
/** POST — submit a new password using the reset token. */
|
|
120
128
|
resetPassword: "password/reset-password",
|
|
129
|
+
/**
|
|
130
|
+
* POST — change the password of the signed-in user, verifying the current one.
|
|
131
|
+
*
|
|
132
|
+
* The only route in this family behind the JWT guard: the rest are reached by a
|
|
133
|
+
* caller who has no session, which is what a reset is for.
|
|
134
|
+
*/
|
|
135
|
+
changePassword: "password/change",
|
|
121
136
|
/** POST — verify the reset OTP (when `passwordReset.method = 'otp'`). */
|
|
122
137
|
verifyOtp: "password/verify-otp",
|
|
123
138
|
/** POST — request a fresh OTP after the previous one expired. */
|
|
@@ -137,11 +152,29 @@ var AUTH_PLATFORM_ROUTES = {
|
|
|
137
152
|
/** DELETE — revoke every active session for the current platform admin. */
|
|
138
153
|
revokeAllSessions: "platform/sessions"
|
|
139
154
|
};
|
|
155
|
+
var AUTH_PLATFORM_MFA_ROUTES = {
|
|
156
|
+
/** POST — begin TOTP enrollment for a platform administrator. */
|
|
157
|
+
setup: "platform/mfa/setup",
|
|
158
|
+
/** POST — confirm enrollment by submitting the first valid code. */
|
|
159
|
+
verifyEnable: "platform/mfa/verify-enable",
|
|
160
|
+
/** POST — disable MFA after re-authenticating with a fresh OTP. */
|
|
161
|
+
disable: "platform/mfa/disable",
|
|
162
|
+
/** POST — replace the recovery codes, re-authenticating with a fresh OTP. */
|
|
163
|
+
recoveryCodes: "platform/mfa/recovery-codes"
|
|
164
|
+
};
|
|
140
165
|
var AUTH_SESSION_ROUTES = {
|
|
141
166
|
/** GET — list every active session for the current user. */
|
|
142
167
|
list: "sessions",
|
|
143
|
-
/**
|
|
144
|
-
|
|
168
|
+
/**
|
|
169
|
+
* POST — revoke every session belonging to the current user except the one
|
|
170
|
+
* making the call.
|
|
171
|
+
*
|
|
172
|
+
* POST rather than DELETE because the refresh token that names the current
|
|
173
|
+
* session travels in the body under `tokenDelivery: 'bearer'`, and OpenAPI 3.0.3
|
|
174
|
+
* defers to RFC 7231: a payload on DELETE has no defined semantics, so a
|
|
175
|
+
* generated client drops it.
|
|
176
|
+
*/
|
|
177
|
+
revokeAll: "sessions/revoke-all",
|
|
145
178
|
/**
|
|
146
179
|
* DELETE — revoke a single session by id. The `:id` placeholder must be
|
|
147
180
|
* substituted with the session identifier before the request is issued.
|
|
@@ -162,14 +195,22 @@ var AUTH_INVITATION_ROUTES = {
|
|
|
162
195
|
/** POST — withdraw a pending invitation before it is accepted (admin-only). */
|
|
163
196
|
revoke: "invitations/revoke"
|
|
164
197
|
};
|
|
198
|
+
var AUTH_OAUTH_ROUTES = {
|
|
199
|
+
/** GET — redirect the browser to the provider's consent screen. */
|
|
200
|
+
initiate: "oauth/:provider",
|
|
201
|
+
/** GET — the provider redirects back here with the authorization code. */
|
|
202
|
+
callback: "oauth/:provider/callback"
|
|
203
|
+
};
|
|
165
204
|
var AUTH_ROUTES = {
|
|
166
205
|
dashboard: AUTH_DASHBOARD_ROUTES,
|
|
167
206
|
mfa: AUTH_MFA_ROUTES,
|
|
168
207
|
password: AUTH_PASSWORD_ROUTES,
|
|
169
208
|
platform: AUTH_PLATFORM_ROUTES,
|
|
209
|
+
platformMfa: AUTH_PLATFORM_MFA_ROUTES,
|
|
170
210
|
sessions: AUTH_SESSION_ROUTES,
|
|
171
211
|
invitations: AUTH_INVITATION_ROUTES,
|
|
172
|
-
emailChange: AUTH_EMAIL_CHANGE_ROUTES
|
|
212
|
+
emailChange: AUTH_EMAIL_CHANGE_ROUTES,
|
|
213
|
+
oauth: AUTH_OAUTH_ROUTES
|
|
173
214
|
};
|
|
174
215
|
var AUTH_PROXY_ROUTES = {
|
|
175
216
|
/** POST — same-domain refresh entry point (server-to-server). */
|
|
@@ -192,22 +233,30 @@ var AUTH_REFRESH_SKIP_CONTROLLER_PATHS = [
|
|
|
192
233
|
"password/reset-password",
|
|
193
234
|
"password/verify-otp",
|
|
194
235
|
"password/resend-otp",
|
|
195
|
-
// MFA
|
|
196
|
-
|
|
197
|
-
|
|
236
|
+
// The MFA challenge issues the session — there is none to refresh. Its siblings
|
|
237
|
+
// (`mfa/setup`, `mfa/verify-enable`, `mfa/disable`) are NOT here: they are JWT-guarded, so a
|
|
238
|
+
// 401 there can be a genuine expiry, and their credential failures are recognised by code.
|
|
198
239
|
"mfa/challenge",
|
|
199
|
-
"mfa/disable",
|
|
200
240
|
// Invitation acceptance issues tokens
|
|
201
241
|
"invitations/accept",
|
|
202
242
|
// The address-change confirmation is public: the holder is proving control of a mailbox,
|
|
203
243
|
// not of a session.
|
|
204
244
|
"email/change/confirm",
|
|
205
|
-
//
|
|
245
|
+
// The platform surface, ALL of it. Every protected route here is JWT-PLATFORM-guarded, so an
|
|
246
|
+
// expired platform token answers `auth.token_invalid` — the code the client reads as "expired"
|
|
247
|
+
// — and a dashboard refresh cannot fix another plane's credential. Listing only some of them
|
|
248
|
+
// left the rest launching a refresh that spends the budget and can call `onSessionExpired` for
|
|
249
|
+
// a dashboard session that is perfectly healthy.
|
|
206
250
|
"platform/login",
|
|
207
251
|
"platform/refresh",
|
|
208
252
|
"platform/logout",
|
|
253
|
+
"platform/me",
|
|
254
|
+
"platform/sessions",
|
|
209
255
|
"platform/mfa/challenge",
|
|
210
|
-
"platform/
|
|
256
|
+
"platform/mfa/setup",
|
|
257
|
+
"platform/mfa/verify-enable",
|
|
258
|
+
"platform/mfa/disable",
|
|
259
|
+
"platform/mfa/recovery-codes"
|
|
211
260
|
];
|
|
212
261
|
var AUTH_REFRESH_SKIP_PROXY_PATHS = [
|
|
213
262
|
"/api/auth/client-refresh",
|
|
@@ -271,4 +320,4 @@ var AuthClientError = class extends Error {
|
|
|
271
320
|
}
|
|
272
321
|
};
|
|
273
322
|
|
|
274
|
-
export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_ERROR_CODES, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes };
|
|
323
|
+
export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_EMAIL_CHANGE_ROUTES, AUTH_ERROR_CODES, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_OAUTH_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_MFA_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"check:runtime": "node scripts/check-consumer-runtime.mjs",
|
|
81
81
|
"clean": "rm -rf dist coverage",
|
|
82
82
|
"format": "prettier --write .",
|
|
83
|
+
"gen:openapi-schemas": "UPDATE_OPENAPI_SCHEMAS=1 jest src/server/openapi/request-schemas.conformance.spec.ts",
|
|
83
84
|
"format:check": "prettier --check .",
|
|
84
85
|
"lint": "eslint src",
|
|
85
86
|
"lint:fix": "eslint src --fix",
|
|
@@ -176,6 +177,8 @@
|
|
|
176
177
|
"@nestjs/core": "^11.1.20",
|
|
177
178
|
"@nestjs/jwt": "^11.0.2",
|
|
178
179
|
"@nestjs/platform-express": "^11.1.20",
|
|
180
|
+
"@nestjs/platform-socket.io": "^11.1.29",
|
|
181
|
+
"@nestjs/platform-ws": "^11.1.29",
|
|
179
182
|
"@nestjs/testing": "^11.1.20",
|
|
180
183
|
"@nestjs/throttler": "^6.5.0",
|
|
181
184
|
"@nestjs/websockets": "^11.1.20",
|
|
@@ -190,6 +193,7 @@
|
|
|
190
193
|
"@types/react": "^19.2.14",
|
|
191
194
|
"@types/react-dom": "^19.2.3",
|
|
192
195
|
"@types/supertest": "^7.2.0",
|
|
196
|
+
"@types/ws": "^8.18.1",
|
|
193
197
|
"@typescript-eslint/eslint-plugin": "^8.59.3",
|
|
194
198
|
"@typescript-eslint/parser": "^8.59.3",
|
|
195
199
|
"class-transformer": "^0.5.1",
|
|
@@ -213,11 +217,14 @@
|
|
|
213
217
|
"react": "^19.2.6",
|
|
214
218
|
"react-dom": "^19.2.6",
|
|
215
219
|
"reflect-metadata": "^0.2.2",
|
|
220
|
+
"socket.io": "^4.8.3",
|
|
221
|
+
"socket.io-client": "^4.8.3",
|
|
216
222
|
"supertest": "^7.2.2",
|
|
217
223
|
"ts-jest": "^29.4.9",
|
|
218
224
|
"ts-node": "^10.9.2",
|
|
219
225
|
"tsup": "^8.5.1",
|
|
220
|
-
"typescript": "^5.9.3"
|
|
226
|
+
"typescript": "^5.9.3",
|
|
227
|
+
"ws": "^8.21.3"
|
|
221
228
|
},
|
|
222
229
|
"keywords": [
|
|
223
230
|
"nestjs",
|