@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.
@@ -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
- RECOVERY_CODE_INVALID: "auth.recovery_code_invalid",
38
+ MFA_STATE_CONFLICT: "auth.mfa_state_conflict",
38
39
  // Password
39
- PASSWORD_TOO_WEAK: "auth.password_too_weak",
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.replace(/^\/+|\/+$/g, "");
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.11",
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
- "types": "./dist/server/index.d.ts",
26
- "import": "./dist/server/index.mjs",
27
- "require": "./dist/server/index.cjs"
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
- "types": "./dist/shared/index.d.ts",
31
- "import": "./dist/shared/index.mjs",
32
- "require": "./dist/shared/index.cjs"
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
- "types": "./dist/client/index.d.ts",
36
- "import": "./dist/client/index.mjs",
37
- "require": "./dist/client/index.cjs"
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
- "types": "./dist/react/index.d.ts",
41
- "import": "./dist/react/index.mjs",
42
- "require": "./dist/react/index.cjs"
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
- "types": "./dist/nextjs/index.d.ts",
46
- "import": "./dist/nextjs/index.mjs",
47
- "require": "./dist/nextjs/index.cjs"
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.0",
61
- "@nestjs/core": "^11.0.0",
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.0.0",
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
- "@commitlint/cli": "^19.6.0",
117
- "@commitlint/config-conventional": "^19.6.0",
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
- "lint-staged": "^15.2.10",
153
- "next": "^16.2.6",
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
- "scripts": {
191
- "build": "pnpm clean && tsup",
192
- "lint": "eslint src",
193
- "lint:fix": "eslint src --fix",
194
- "test": "jest",
195
- "test:cov": "jest --coverage",
196
- "test:watch": "jest --watch",
197
- "test:e2e": "jest --config jest.e2e.config.ts",
198
- "test:all": "pnpm test && pnpm test:e2e",
199
- "test:cov:all": "jest --config jest.coverage.config.ts --coverage",
200
- "mutation": "stryker run",
201
- "mutation:incremental": "stryker run --incremental",
202
- "mutation:dry-run": "stryker run --dryRunOnly",
203
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
204
- "size": "node scripts/check-size.mjs",
205
- "clean": "rm -rf dist coverage",
206
- "release": "pnpm publish --provenance"
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
+ }