@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.
- package/CHANGELOG.md +443 -1
- package/README.md +275 -108
- package/dist/client/index.cjs +49 -5
- package/dist/client/index.mjs +49 -5
- package/dist/nextjs/index.cjs +152 -51
- package/dist/nextjs/index.d.cts +164 -58
- package/dist/nextjs/index.d.ts +164 -58
- package/dist/nextjs/index.mjs +152 -51
- package/dist/react/index.cjs +85 -89
- package/dist/react/index.mjs +85 -89
- package/dist/server/index.cjs +6083 -1574
- package/dist/server/index.d.cts +2880 -180
- package/dist/server/index.d.ts +2880 -180
- package/dist/server/index.mjs +6062 -1560
- package/dist/shared/index.cjs +60 -9
- package/dist/shared/index.d.cts +126 -18
- package/dist/shared/index.d.ts +126 -18
- package/dist/shared/index.mjs +60 -9
- package/package.json +112 -43
package/dist/shared/index.mjs
CHANGED
|
@@ -20,13 +20,14 @@ var AUTH_ERROR_CODES = {
|
|
|
20
20
|
TOKEN_EXPIRED: "auth.token_expired",
|
|
21
21
|
TOKEN_REVOKED: "auth.token_revoked",
|
|
22
22
|
TOKEN_INVALID: "auth.token_invalid",
|
|
23
|
+
/** Internal-only: the request carried no credential. Never on the wire — see TOKEN_INVALID. */
|
|
24
|
+
TOKEN_MISSING: "auth.token_missing",
|
|
23
25
|
REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid",
|
|
24
|
-
SESSION_EXPIRED: "auth.session_expired",
|
|
25
|
-
SESSION_LIMIT_REACHED: "auth.session_limit_reached",
|
|
26
26
|
SESSION_NOT_FOUND: "auth.session_not_found",
|
|
27
27
|
// Registration and email
|
|
28
28
|
EMAIL_ALREADY_EXISTS: "auth.email_already_exists",
|
|
29
29
|
EMAIL_NOT_VERIFIED: "auth.email_not_verified",
|
|
30
|
+
EMAIL_CHANGE_TOKEN_INVALID: "auth.email_change_token_invalid",
|
|
30
31
|
// MFA
|
|
31
32
|
MFA_REQUIRED: "auth.mfa_required",
|
|
32
33
|
MFA_INVALID_CODE: "auth.mfa_invalid_code",
|
|
@@ -34,25 +35,55 @@ var AUTH_ERROR_CODES = {
|
|
|
34
35
|
MFA_NOT_ENABLED: "auth.mfa_not_enabled",
|
|
35
36
|
MFA_SETUP_REQUIRED: "auth.mfa_setup_required",
|
|
36
37
|
MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid",
|
|
37
|
-
|
|
38
|
+
MFA_STATE_CONFLICT: "auth.mfa_state_conflict",
|
|
38
39
|
// Password
|
|
39
|
-
|
|
40
|
+
/** The password appears in a known-breach corpus. */
|
|
41
|
+
PASSWORD_COMPROMISED: "auth.password_compromised",
|
|
40
42
|
PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
|
|
41
|
-
PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired",
|
|
42
43
|
// OTP (email verification, password reset via OTP)
|
|
44
|
+
/**
|
|
45
|
+
* The only code an OTP failure reaches a client with. A wrong code, a record that is not in
|
|
46
|
+
* Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
|
|
47
|
+
* answers the same whether or not the address exists, but only writes an OTP record when it
|
|
48
|
+
* does, so telling them apart made that uniform answer definitive after one extra request.
|
|
49
|
+
*/
|
|
43
50
|
OTP_INVALID: "auth.otp_invalid",
|
|
51
|
+
/** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
|
|
44
52
|
OTP_EXPIRED: "auth.otp_expired",
|
|
53
|
+
/** Internal-only: the attempt ceiling was hit. Never on the wire — see {@link OTP_INVALID}. */
|
|
45
54
|
OTP_MAX_ATTEMPTS: "auth.otp_max_attempts",
|
|
46
55
|
// Authorization
|
|
47
56
|
INSUFFICIENT_ROLE: "auth.insufficient_role",
|
|
48
57
|
FORBIDDEN: "auth.forbidden",
|
|
58
|
+
/**
|
|
59
|
+
* The request body or query failed DTO validation. Per-field failures serialize into
|
|
60
|
+
* `error.details` as `[{ field, message }]`.
|
|
61
|
+
*/
|
|
62
|
+
VALIDATION: "auth.validation",
|
|
63
|
+
/** The caller exceeded a per-IP rate limit on an auth route. */
|
|
64
|
+
TOO_MANY_REQUESTS: "auth.too_many_requests",
|
|
65
|
+
/**
|
|
66
|
+
* A state-changing request carrying the session cookie came from an origin the deployment
|
|
67
|
+
* does not trust.
|
|
68
|
+
*/
|
|
69
|
+
UNTRUSTED_ORIGIN: "auth.untrusted_origin",
|
|
70
|
+
/**
|
|
71
|
+
* A change to how the account authenticates was attempted without a recent authentication.
|
|
72
|
+
* The client should send the user back through sign-in and retry.
|
|
73
|
+
*/
|
|
74
|
+
REAUTHENTICATION_REQUIRED: "auth.reauthentication_required",
|
|
49
75
|
// Invitations
|
|
50
76
|
INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
|
|
51
77
|
// OAuth
|
|
52
78
|
OAUTH_FAILED: "auth.oauth_failed",
|
|
53
79
|
OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch",
|
|
54
80
|
// Platform admin
|
|
55
|
-
PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required"
|
|
81
|
+
PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required",
|
|
82
|
+
/**
|
|
83
|
+
* An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
|
|
84
|
+
* which gives unhandled failures the same envelope everything else answers with.
|
|
85
|
+
*/
|
|
86
|
+
INTERNAL: "auth.internal"
|
|
56
87
|
};
|
|
57
88
|
|
|
58
89
|
// src/shared/constants/routes.ts
|
|
@@ -117,11 +148,19 @@ var AUTH_SESSION_ROUTES = {
|
|
|
117
148
|
*/
|
|
118
149
|
revokeOne: "sessions/:id"
|
|
119
150
|
};
|
|
151
|
+
var AUTH_EMAIL_CHANGE_ROUTES = {
|
|
152
|
+
/** POST — request a change; mails a token to the new address. */
|
|
153
|
+
request: "email/change",
|
|
154
|
+
/** POST — confirm the change with that token. */
|
|
155
|
+
confirm: "email/change/confirm"
|
|
156
|
+
};
|
|
120
157
|
var AUTH_INVITATION_ROUTES = {
|
|
121
158
|
/** POST — create a new invitation (admin-only). */
|
|
122
159
|
create: "invitations",
|
|
123
160
|
/** POST — accept an invitation token and register the recipient. */
|
|
124
|
-
accept: "invitations/accept"
|
|
161
|
+
accept: "invitations/accept",
|
|
162
|
+
/** POST — withdraw a pending invitation before it is accepted (admin-only). */
|
|
163
|
+
revoke: "invitations/revoke"
|
|
125
164
|
};
|
|
126
165
|
var AUTH_ROUTES = {
|
|
127
166
|
dashboard: AUTH_DASHBOARD_ROUTES,
|
|
@@ -129,7 +168,8 @@ var AUTH_ROUTES = {
|
|
|
129
168
|
password: AUTH_PASSWORD_ROUTES,
|
|
130
169
|
platform: AUTH_PLATFORM_ROUTES,
|
|
131
170
|
sessions: AUTH_SESSION_ROUTES,
|
|
132
|
-
invitations: AUTH_INVITATION_ROUTES
|
|
171
|
+
invitations: AUTH_INVITATION_ROUTES,
|
|
172
|
+
emailChange: AUTH_EMAIL_CHANGE_ROUTES
|
|
133
173
|
};
|
|
134
174
|
var AUTH_PROXY_ROUTES = {
|
|
135
175
|
/** POST — same-domain refresh entry point (server-to-server). */
|
|
@@ -159,6 +199,9 @@ var AUTH_REFRESH_SKIP_CONTROLLER_PATHS = [
|
|
|
159
199
|
"mfa/disable",
|
|
160
200
|
// Invitation acceptance issues tokens
|
|
161
201
|
"invitations/accept",
|
|
202
|
+
// The address-change confirmation is public: the holder is proving control of a mailbox,
|
|
203
|
+
// not of a session.
|
|
204
|
+
"email/change/confirm",
|
|
162
205
|
// Platform endpoints
|
|
163
206
|
"platform/login",
|
|
164
207
|
"platform/refresh",
|
|
@@ -170,8 +213,16 @@ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
|
|
|
170
213
|
"/api/auth/client-refresh",
|
|
171
214
|
"/api/auth/silent-refresh"
|
|
172
215
|
];
|
|
216
|
+
function trimSlashes(value) {
|
|
217
|
+
let start = 0;
|
|
218
|
+
let end = value.length;
|
|
219
|
+
while (start < end && value[start] === "/") start += 1;
|
|
220
|
+
while (end > start && value[end - 1] === "/") end -= 1;
|
|
221
|
+
return value.slice(start, end);
|
|
222
|
+
}
|
|
223
|
+
__name(trimSlashes, "trimSlashes");
|
|
173
224
|
function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
|
|
174
|
-
const normalized = routePrefix
|
|
225
|
+
const normalized = trimSlashes(routePrefix);
|
|
175
226
|
const prefix = normalized.length > 0 ? `/${normalized}` : "";
|
|
176
227
|
return [
|
|
177
228
|
...AUTH_REFRESH_SKIP_CONTROLLER_PATHS.map((path) => `${prefix}/${path}`),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -22,30 +22,81 @@
|
|
|
22
22
|
],
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/server/index.d.ts",
|
|
27
|
+
"default": "./dist/server/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/server/index.d.cts",
|
|
31
|
+
"default": "./dist/server/index.cjs"
|
|
32
|
+
}
|
|
28
33
|
},
|
|
29
34
|
"./shared": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/shared/index.d.ts",
|
|
37
|
+
"default": "./dist/shared/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/shared/index.d.cts",
|
|
41
|
+
"default": "./dist/shared/index.cjs"
|
|
42
|
+
}
|
|
33
43
|
},
|
|
34
44
|
"./client": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/client/index.d.ts",
|
|
47
|
+
"default": "./dist/client/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/client/index.d.cts",
|
|
51
|
+
"default": "./dist/client/index.cjs"
|
|
52
|
+
}
|
|
38
53
|
},
|
|
39
54
|
"./react": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/react/index.d.ts",
|
|
57
|
+
"default": "./dist/react/index.mjs"
|
|
58
|
+
},
|
|
59
|
+
"require": {
|
|
60
|
+
"types": "./dist/react/index.d.cts",
|
|
61
|
+
"default": "./dist/react/index.cjs"
|
|
62
|
+
}
|
|
43
63
|
},
|
|
44
64
|
"./nextjs": {
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
"import": {
|
|
66
|
+
"types": "./dist/nextjs/index.d.ts",
|
|
67
|
+
"default": "./dist/nextjs/index.mjs"
|
|
68
|
+
},
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/nextjs/index.d.cts",
|
|
71
|
+
"default": "./dist/nextjs/index.cjs"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"./package.json": "./package.json"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "pnpm clean && tsup",
|
|
78
|
+
"check:exports": "node scripts/check-exports.mjs",
|
|
79
|
+
"check:published": "node scripts/check-published-surface.mjs",
|
|
80
|
+
"check:runtime": "node scripts/check-consumer-runtime.mjs",
|
|
81
|
+
"clean": "rm -rf dist coverage",
|
|
82
|
+
"format": "prettier --write .",
|
|
83
|
+
"format:check": "prettier --check .",
|
|
84
|
+
"lint": "eslint src",
|
|
85
|
+
"lint:fix": "eslint src --fix",
|
|
86
|
+
"mutation": "stryker run",
|
|
87
|
+
"mutation:dry-run": "stryker run --dryRunOnly",
|
|
88
|
+
"mutation:incremental": "stryker run --incremental",
|
|
89
|
+
"prepare": "husky",
|
|
90
|
+
"prepublishOnly": "pnpm clean && pnpm typecheck && pnpm lint && pnpm test:cov:all && pnpm build && pnpm size && pnpm check:exports && pnpm check:published && pnpm check:runtime",
|
|
91
|
+
"release": "npm publish --provenance --access public",
|
|
92
|
+
"size": "node scripts/check-size.mjs",
|
|
93
|
+
"test": "jest",
|
|
94
|
+
"test:all": "pnpm test && pnpm test:e2e",
|
|
95
|
+
"test:cov": "jest --coverage",
|
|
96
|
+
"test:cov:all": "jest --config jest.coverage.config.ts --coverage",
|
|
97
|
+
"test:e2e": "jest --config jest.e2e.config.ts",
|
|
98
|
+
"test:watch": "jest --watch",
|
|
99
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json"
|
|
49
100
|
},
|
|
50
101
|
"lint-staged": {
|
|
51
102
|
"*.{ts,tsx,js,mjs,cjs}": [
|
|
@@ -57,8 +108,8 @@
|
|
|
57
108
|
]
|
|
58
109
|
},
|
|
59
110
|
"peerDependencies": {
|
|
60
|
-
"@nestjs/common": "^11.0.
|
|
61
|
-
"@nestjs/core": "^11.
|
|
111
|
+
"@nestjs/common": "^11.0.16",
|
|
112
|
+
"@nestjs/core": "^11.1.18",
|
|
62
113
|
"@nestjs/jwt": "^11.0.0",
|
|
63
114
|
"@nestjs/throttler": "^6.0.0",
|
|
64
115
|
"@nestjs/websockets": "^11.0.0",
|
|
@@ -67,9 +118,10 @@
|
|
|
67
118
|
"class-validator": "^0.14.0 || ^0.15.0",
|
|
68
119
|
"express": "^5.0.0",
|
|
69
120
|
"ioredis": "^5.0.0",
|
|
70
|
-
"next": "^16.
|
|
121
|
+
"next": "^16.2.11",
|
|
71
122
|
"react": "^19.0.0",
|
|
72
|
-
"reflect-metadata": "^0.2.0"
|
|
123
|
+
"reflect-metadata": "^0.2.0",
|
|
124
|
+
"server-only": "^0.0.1"
|
|
73
125
|
},
|
|
74
126
|
"peerDependenciesMeta": {
|
|
75
127
|
"@nestjs/common": {
|
|
@@ -105,6 +157,9 @@
|
|
|
105
157
|
"reflect-metadata": {
|
|
106
158
|
"optional": true
|
|
107
159
|
},
|
|
160
|
+
"server-only": {
|
|
161
|
+
"optional": true
|
|
162
|
+
},
|
|
108
163
|
"react": {
|
|
109
164
|
"optional": true
|
|
110
165
|
},
|
|
@@ -113,8 +168,9 @@
|
|
|
113
168
|
}
|
|
114
169
|
},
|
|
115
170
|
"devDependencies": {
|
|
116
|
-
"@
|
|
117
|
-
"@commitlint/
|
|
171
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
172
|
+
"@commitlint/cli": "^21.2.1",
|
|
173
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
118
174
|
"@eslint/js": "^9.39.4",
|
|
119
175
|
"@nestjs/common": "^11.1.20",
|
|
120
176
|
"@nestjs/core": "^11.1.20",
|
|
@@ -126,6 +182,7 @@
|
|
|
126
182
|
"@stryker-mutator/core": "^9",
|
|
127
183
|
"@stryker-mutator/jest-runner": "^9",
|
|
128
184
|
"@stryker-mutator/typescript-checker": "^9",
|
|
185
|
+
"@swc/core": "1.15.40",
|
|
129
186
|
"@testing-library/react": "^16.3.2",
|
|
130
187
|
"@types/express": "^5.0.6",
|
|
131
188
|
"@types/jest": "^30.0.0",
|
|
@@ -149,8 +206,9 @@
|
|
|
149
206
|
"ioredis-mock": "^8.13.1",
|
|
150
207
|
"jest": "^30.4.2",
|
|
151
208
|
"jest-environment-jsdom": "^30.4.1",
|
|
152
|
-
"
|
|
153
|
-
"
|
|
209
|
+
"jest-environment-node": "^30.4.1",
|
|
210
|
+
"lint-staged": "^17.2.0",
|
|
211
|
+
"next": "^16.2.11",
|
|
154
212
|
"prettier": "^3.8.3",
|
|
155
213
|
"react": "^19.2.6",
|
|
156
214
|
"react-dom": "^19.2.6",
|
|
@@ -180,29 +238,40 @@
|
|
|
180
238
|
"password-reset",
|
|
181
239
|
"refresh-token"
|
|
182
240
|
],
|
|
241
|
+
"packageManager": "pnpm@11.20.0",
|
|
183
242
|
"engines": {
|
|
184
243
|
"node": ">=24.0.0"
|
|
185
244
|
},
|
|
186
245
|
"publishConfig": {
|
|
187
246
|
"access": "public",
|
|
247
|
+
"provenance": true,
|
|
188
248
|
"registry": "https://registry.npmjs.org/"
|
|
189
249
|
},
|
|
190
|
-
"
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
"
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
250
|
+
"main": "./dist/server/index.cjs",
|
|
251
|
+
"module": "./dist/server/index.mjs",
|
|
252
|
+
"types": "./dist/server/index.d.cts",
|
|
253
|
+
"typesVersions": {
|
|
254
|
+
"*": {
|
|
255
|
+
"dist/server/index.d.cts": [
|
|
256
|
+
"./dist/server/index.d.cts",
|
|
257
|
+
"./dist/server/index.d.ts"
|
|
258
|
+
],
|
|
259
|
+
"shared": [
|
|
260
|
+
"./dist/shared/index.d.cts",
|
|
261
|
+
"./dist/shared/index.d.ts"
|
|
262
|
+
],
|
|
263
|
+
"client": [
|
|
264
|
+
"./dist/client/index.d.cts",
|
|
265
|
+
"./dist/client/index.d.ts"
|
|
266
|
+
],
|
|
267
|
+
"react": [
|
|
268
|
+
"./dist/react/index.d.cts",
|
|
269
|
+
"./dist/react/index.d.ts"
|
|
270
|
+
],
|
|
271
|
+
"nextjs": [
|
|
272
|
+
"./dist/nextjs/index.d.cts",
|
|
273
|
+
"./dist/nextjs/index.d.ts"
|
|
274
|
+
]
|
|
275
|
+
}
|
|
207
276
|
}
|
|
208
|
-
}
|
|
277
|
+
}
|