@bymax-one/nest-auth 1.0.10 → 1.1.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.
- package/CHANGELOG.md +387 -1
- package/README.md +274 -108
- package/dist/client/index.cjs +41 -4
- package/dist/client/index.mjs +41 -4
- package/dist/nextjs/index.cjs +152 -51
- package/dist/nextjs/index.d.cts +149 -55
- package/dist/nextjs/index.d.ts +149 -55
- package/dist/nextjs/index.mjs +152 -51
- package/dist/react/index.cjs +77 -89
- package/dist/react/index.mjs +77 -89
- package/dist/server/index.cjs +5951 -1655
- package/dist/server/index.d.cts +2818 -188
- package/dist/server/index.d.ts +2818 -188
- package/dist/server/index.mjs +5933 -1644
- 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 +133 -45
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.0
|
|
3
|
+
"version": "1.1.0",
|
|
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,34 +22,94 @@
|
|
|
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"
|
|
100
|
+
},
|
|
101
|
+
"lint-staged": {
|
|
102
|
+
"*.{ts,tsx,js,mjs,cjs}": [
|
|
103
|
+
"eslint --fix",
|
|
104
|
+
"prettier --write"
|
|
105
|
+
],
|
|
106
|
+
"*.{json,md,yml,yaml}": [
|
|
107
|
+
"prettier --write"
|
|
108
|
+
]
|
|
49
109
|
},
|
|
50
110
|
"peerDependencies": {
|
|
51
|
-
"@nestjs/common": "^11.0.
|
|
52
|
-
"@nestjs/core": "^11.
|
|
111
|
+
"@nestjs/common": "^11.0.16",
|
|
112
|
+
"@nestjs/core": "^11.1.18",
|
|
53
113
|
"@nestjs/jwt": "^11.0.0",
|
|
54
114
|
"@nestjs/throttler": "^6.0.0",
|
|
55
115
|
"@nestjs/websockets": "^11.0.0",
|
|
@@ -58,9 +118,10 @@
|
|
|
58
118
|
"class-validator": "^0.14.0 || ^0.15.0",
|
|
59
119
|
"express": "^5.0.0",
|
|
60
120
|
"ioredis": "^5.0.0",
|
|
61
|
-
"next": "^16.
|
|
121
|
+
"next": "^16.2.11",
|
|
62
122
|
"react": "^19.0.0",
|
|
63
|
-
"reflect-metadata": "^0.2.0"
|
|
123
|
+
"reflect-metadata": "^0.2.0",
|
|
124
|
+
"server-only": "^0.0.1"
|
|
64
125
|
},
|
|
65
126
|
"peerDependenciesMeta": {
|
|
66
127
|
"@nestjs/common": {
|
|
@@ -96,6 +157,9 @@
|
|
|
96
157
|
"reflect-metadata": {
|
|
97
158
|
"optional": true
|
|
98
159
|
},
|
|
160
|
+
"server-only": {
|
|
161
|
+
"optional": true
|
|
162
|
+
},
|
|
99
163
|
"react": {
|
|
100
164
|
"optional": true
|
|
101
165
|
},
|
|
@@ -104,6 +168,9 @@
|
|
|
104
168
|
}
|
|
105
169
|
},
|
|
106
170
|
"devDependencies": {
|
|
171
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
172
|
+
"@commitlint/cli": "^21.2.1",
|
|
173
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
107
174
|
"@eslint/js": "^9.39.4",
|
|
108
175
|
"@nestjs/common": "^11.1.20",
|
|
109
176
|
"@nestjs/core": "^11.1.20",
|
|
@@ -112,15 +179,13 @@
|
|
|
112
179
|
"@nestjs/testing": "^11.1.20",
|
|
113
180
|
"@nestjs/throttler": "^6.5.0",
|
|
114
181
|
"@nestjs/websockets": "^11.1.20",
|
|
115
|
-
"@size-limit/preset-small-lib": "12.1.0",
|
|
116
182
|
"@stryker-mutator/core": "^9",
|
|
117
183
|
"@stryker-mutator/jest-runner": "^9",
|
|
118
184
|
"@stryker-mutator/typescript-checker": "^9",
|
|
119
|
-
"@swc/core": "^1.15.33",
|
|
120
185
|
"@testing-library/react": "^16.3.2",
|
|
121
186
|
"@types/express": "^5.0.6",
|
|
122
187
|
"@types/jest": "^30.0.0",
|
|
123
|
-
"@types/node": "^
|
|
188
|
+
"@types/node": "^24",
|
|
124
189
|
"@types/react": "^19.2.14",
|
|
125
190
|
"@types/react-dom": "^19.2.3",
|
|
126
191
|
"@types/supertest": "^7.2.0",
|
|
@@ -135,17 +200,18 @@
|
|
|
135
200
|
"eslint-plugin-prettier": "^5.5.5",
|
|
136
201
|
"eslint-plugin-security": "^4.0.0",
|
|
137
202
|
"globals": "^17.6.0",
|
|
203
|
+
"husky": "^9.1.7",
|
|
138
204
|
"ioredis": "^5.10.1",
|
|
139
205
|
"ioredis-mock": "^8.13.1",
|
|
140
206
|
"jest": "^30.4.2",
|
|
141
207
|
"jest-environment-jsdom": "^30.4.1",
|
|
142
|
-
"
|
|
143
|
-
"
|
|
208
|
+
"jest-environment-node": "^30.4.1",
|
|
209
|
+
"lint-staged": "^17.2.0",
|
|
210
|
+
"next": "^16.2.11",
|
|
144
211
|
"prettier": "^3.8.3",
|
|
145
212
|
"react": "^19.2.6",
|
|
146
213
|
"react-dom": "^19.2.6",
|
|
147
214
|
"reflect-metadata": "^0.2.2",
|
|
148
|
-
"size-limit": "12.1.0",
|
|
149
215
|
"supertest": "^7.2.2",
|
|
150
216
|
"ts-jest": "^29.4.9",
|
|
151
217
|
"ts-node": "^10.9.2",
|
|
@@ -171,29 +237,51 @@
|
|
|
171
237
|
"password-reset",
|
|
172
238
|
"refresh-token"
|
|
173
239
|
],
|
|
240
|
+
"packageManager": "pnpm@10.8.1",
|
|
174
241
|
"engines": {
|
|
175
242
|
"node": ">=24.0.0"
|
|
176
243
|
},
|
|
177
244
|
"publishConfig": {
|
|
178
245
|
"access": "public",
|
|
246
|
+
"provenance": true,
|
|
179
247
|
"registry": "https://registry.npmjs.org/"
|
|
180
248
|
},
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
"
|
|
197
|
-
|
|
249
|
+
"pnpm": {
|
|
250
|
+
"overrides": {
|
|
251
|
+
"brace-expansion@<5.0.6": ">=5.0.6",
|
|
252
|
+
"esbuild@>=0.27.3 <0.28.1": ">=0.28.1",
|
|
253
|
+
"postcss@<8.5.10": ">=8.5.10",
|
|
254
|
+
"qs@>=6.11.1 <=6.15.1": ">=6.15.2",
|
|
255
|
+
"sharp@<0.35.0": ">=0.35.0",
|
|
256
|
+
"tmp@<0.2.6": ">=0.2.6",
|
|
257
|
+
"ws@<8.20.1": ">=8.20.1"
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
"main": "./dist/server/index.cjs",
|
|
261
|
+
"module": "./dist/server/index.mjs",
|
|
262
|
+
"types": "./dist/server/index.d.cts",
|
|
263
|
+
"typesVersions": {
|
|
264
|
+
"*": {
|
|
265
|
+
"dist/server/index.d.cts": [
|
|
266
|
+
"./dist/server/index.d.cts",
|
|
267
|
+
"./dist/server/index.d.ts"
|
|
268
|
+
],
|
|
269
|
+
"shared": [
|
|
270
|
+
"./dist/shared/index.d.cts",
|
|
271
|
+
"./dist/shared/index.d.ts"
|
|
272
|
+
],
|
|
273
|
+
"client": [
|
|
274
|
+
"./dist/client/index.d.cts",
|
|
275
|
+
"./dist/client/index.d.ts"
|
|
276
|
+
],
|
|
277
|
+
"react": [
|
|
278
|
+
"./dist/react/index.d.cts",
|
|
279
|
+
"./dist/react/index.d.ts"
|
|
280
|
+
],
|
|
281
|
+
"nextjs": [
|
|
282
|
+
"./dist/nextjs/index.d.cts",
|
|
283
|
+
"./dist/nextjs/index.d.ts"
|
|
284
|
+
]
|
|
285
|
+
}
|
|
198
286
|
}
|
|
199
|
-
}
|
|
287
|
+
}
|