@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,223 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/shared/constants/cookie-defaults.ts
5
+ var AUTH_ACCESS_COOKIE_NAME = "access_token";
6
+ var AUTH_REFRESH_COOKIE_NAME = "refresh_token";
7
+ var AUTH_HAS_SESSION_COOKIE_NAME = "has_session";
8
+ var AUTH_REFRESH_COOKIE_PATH = "/auth";
9
+
10
+ // src/shared/constants/error-codes.ts
11
+ var AUTH_ERROR_CODES = {
12
+ // Credentials and account state
13
+ INVALID_CREDENTIALS: "auth.invalid_credentials",
14
+ ACCOUNT_LOCKED: "auth.account_locked",
15
+ ACCOUNT_INACTIVE: "auth.account_inactive",
16
+ ACCOUNT_SUSPENDED: "auth.account_suspended",
17
+ ACCOUNT_BANNED: "auth.account_banned",
18
+ PENDING_APPROVAL: "auth.pending_approval",
19
+ // Tokens and sessions
20
+ TOKEN_EXPIRED: "auth.token_expired",
21
+ TOKEN_REVOKED: "auth.token_revoked",
22
+ TOKEN_INVALID: "auth.token_invalid",
23
+ REFRESH_TOKEN_INVALID: "auth.refresh_token_invalid",
24
+ SESSION_EXPIRED: "auth.session_expired",
25
+ SESSION_LIMIT_REACHED: "auth.session_limit_reached",
26
+ SESSION_NOT_FOUND: "auth.session_not_found",
27
+ // Registration and email
28
+ EMAIL_ALREADY_EXISTS: "auth.email_already_exists",
29
+ EMAIL_NOT_VERIFIED: "auth.email_not_verified",
30
+ // MFA
31
+ MFA_REQUIRED: "auth.mfa_required",
32
+ MFA_INVALID_CODE: "auth.mfa_invalid_code",
33
+ MFA_ALREADY_ENABLED: "auth.mfa_already_enabled",
34
+ MFA_NOT_ENABLED: "auth.mfa_not_enabled",
35
+ MFA_SETUP_REQUIRED: "auth.mfa_setup_required",
36
+ MFA_TEMP_TOKEN_INVALID: "auth.mfa_temp_token_invalid",
37
+ RECOVERY_CODE_INVALID: "auth.recovery_code_invalid",
38
+ // Password
39
+ PASSWORD_TOO_WEAK: "auth.password_too_weak",
40
+ PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
41
+ PASSWORD_RESET_TOKEN_EXPIRED: "auth.password_reset_token_expired",
42
+ // OTP (email verification, password reset via OTP)
43
+ OTP_INVALID: "auth.otp_invalid",
44
+ OTP_EXPIRED: "auth.otp_expired",
45
+ OTP_MAX_ATTEMPTS: "auth.otp_max_attempts",
46
+ // Authorization
47
+ INSUFFICIENT_ROLE: "auth.insufficient_role",
48
+ FORBIDDEN: "auth.forbidden",
49
+ // Invitations
50
+ INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
51
+ // OAuth
52
+ OAUTH_FAILED: "auth.oauth_failed",
53
+ OAUTH_EMAIL_MISMATCH: "auth.oauth_email_mismatch",
54
+ // Platform admin
55
+ PLATFORM_AUTH_REQUIRED: "auth.platform_auth_required"
56
+ };
57
+
58
+ // src/shared/constants/routes.ts
59
+ var AUTH_DASHBOARD_ROUTES = {
60
+ /** POST — register a new local (email + password) user. */
61
+ register: "register",
62
+ /** POST — exchange credentials for an access token (or MFA challenge). */
63
+ login: "login",
64
+ /** POST — revoke the current access and refresh tokens. */
65
+ logout: "logout",
66
+ /** POST — rotate a valid refresh token for a fresh access token. */
67
+ refresh: "refresh",
68
+ /** GET — return the currently authenticated user. */
69
+ me: "me",
70
+ /** POST — submit the email-verification token returned by the verification email. */
71
+ verifyEmail: "verify-email",
72
+ /** POST — request a fresh email-verification token. */
73
+ resendVerification: "resend-verification"
74
+ };
75
+ var AUTH_MFA_ROUTES = {
76
+ /** POST — begin TOTP enrollment and return the secret + provisioning URI. */
77
+ setup: "mfa/setup",
78
+ /** POST — confirm TOTP enrollment by submitting the first valid code. */
79
+ verifyEnable: "mfa/verify-enable",
80
+ /** POST — exchange an MFA temp token + OTP for a full access token. */
81
+ challenge: "mfa/challenge",
82
+ /** POST — disable MFA after re-authenticating with a fresh OTP. */
83
+ disable: "mfa/disable"
84
+ };
85
+ var AUTH_PASSWORD_ROUTES = {
86
+ /** POST — request a password reset (email lookup is anti-enumeration). */
87
+ forgotPassword: "password/forgot-password",
88
+ /** POST — submit a new password using the reset token. */
89
+ resetPassword: "password/reset-password",
90
+ /** POST — verify the reset OTP (when `passwordReset.method = 'otp'`). */
91
+ verifyOtp: "password/verify-otp",
92
+ /** POST — request a fresh OTP after the previous one expired. */
93
+ resendOtp: "password/resend-otp"
94
+ };
95
+ var AUTH_PLATFORM_ROUTES = {
96
+ /** POST — exchange platform admin credentials for an access token. */
97
+ login: "platform/login",
98
+ /** POST — exchange an MFA temp token + OTP for a platform access token. */
99
+ mfaChallenge: "platform/mfa/challenge",
100
+ /** GET — return the currently authenticated platform administrator. */
101
+ me: "platform/me",
102
+ /** POST — revoke the platform access and refresh tokens. */
103
+ logout: "platform/logout",
104
+ /** POST — rotate a platform refresh token for a fresh access token. */
105
+ refresh: "platform/refresh",
106
+ /** DELETE — revoke every active session for the current platform admin. */
107
+ revokeAllSessions: "platform/sessions"
108
+ };
109
+ var AUTH_SESSION_ROUTES = {
110
+ /** GET — list every active session for the current user. */
111
+ list: "sessions",
112
+ /** DELETE — revoke every session belonging to the current user. */
113
+ revokeAll: "sessions/all",
114
+ /**
115
+ * DELETE — revoke a single session by id. The `:id` placeholder must be
116
+ * substituted with the session identifier before the request is issued.
117
+ */
118
+ revokeOne: "sessions/:id"
119
+ };
120
+ var AUTH_INVITATION_ROUTES = {
121
+ /** POST — create a new invitation (admin-only). */
122
+ create: "invitations",
123
+ /** POST — accept an invitation token and register the recipient. */
124
+ accept: "invitations/accept"
125
+ };
126
+ var AUTH_ROUTES = {
127
+ dashboard: AUTH_DASHBOARD_ROUTES,
128
+ mfa: AUTH_MFA_ROUTES,
129
+ password: AUTH_PASSWORD_ROUTES,
130
+ platform: AUTH_PLATFORM_ROUTES,
131
+ sessions: AUTH_SESSION_ROUTES,
132
+ invitations: AUTH_INVITATION_ROUTES
133
+ };
134
+ var AUTH_PROXY_ROUTES = {
135
+ /** POST — same-domain refresh entry point (server-to-server). */
136
+ clientRefresh: "/api/auth/client-refresh",
137
+ /** GET — invisible refresh used by the proxy to reissue tokens. */
138
+ silentRefresh: "/api/auth/silent-refresh",
139
+ /** POST — Next.js logout proxy (clears cookies + revokes server-side). */
140
+ logout: "/api/auth/logout"
141
+ };
142
+ var AUTH_REFRESH_SKIP_CONTROLLER_PATHS = [
143
+ // Dashboard auth-issuing endpoints
144
+ "register",
145
+ "login",
146
+ "refresh",
147
+ "logout",
148
+ "verify-email",
149
+ "resend-verification",
150
+ // Password reset endpoints
151
+ "password/forgot-password",
152
+ "password/reset-password",
153
+ "password/verify-otp",
154
+ "password/resend-otp",
155
+ // MFA endpoints
156
+ "mfa/setup",
157
+ "mfa/verify-enable",
158
+ "mfa/challenge",
159
+ "mfa/disable",
160
+ // Invitation acceptance issues tokens
161
+ "invitations/accept",
162
+ // Platform endpoints
163
+ "platform/login",
164
+ "platform/refresh",
165
+ "platform/logout",
166
+ "platform/mfa/challenge",
167
+ "platform/sessions"
168
+ ];
169
+ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
170
+ "/api/auth/client-refresh",
171
+ "/api/auth/silent-refresh"
172
+ ];
173
+ function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
174
+ const normalized = routePrefix.replace(/^\/+|\/+$/g, "");
175
+ const prefix = normalized.length > 0 ? `/${normalized}` : "";
176
+ return [
177
+ ...AUTH_REFRESH_SKIP_CONTROLLER_PATHS.map((path) => `${prefix}/${path}`),
178
+ ...AUTH_REFRESH_SKIP_PROXY_PATHS
179
+ ];
180
+ }
181
+ __name(buildAuthRefreshSkipSuffixes, "buildAuthRefreshSkipSuffixes");
182
+ var AUTH_REFRESH_SKIP_PATH_SUFFIXES = buildAuthRefreshSkipSuffixes();
183
+
184
+ // src/shared/types/auth-error.types.ts
185
+ var AuthClientError = class extends Error {
186
+ static {
187
+ __name(this, "AuthClientError");
188
+ }
189
+ /** The HTTP status code returned by the server. */
190
+ status;
191
+ /**
192
+ * The stable machine-readable error code from `AUTH_ERROR_CODES`,
193
+ * when the server provided one.
194
+ */
195
+ code;
196
+ /** The full parsed error body, if the response carried JSON. */
197
+ body;
198
+ constructor(message, status, body) {
199
+ super(message);
200
+ this.name = "AuthClientError";
201
+ this.status = status;
202
+ this.code = body?.code;
203
+ this.body = body;
204
+ }
205
+ /**
206
+ * Strips potentially sensitive request echoes from structured-logger output.
207
+ *
208
+ * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
209
+ * responses; without this override, `JSON.stringify(error)` would persist
210
+ * those fields verbatim into application logs. The serialized form keeps
211
+ * only the fields a log consumer actually needs to triage an auth failure.
212
+ */
213
+ toJSON() {
214
+ return {
215
+ name: this.name,
216
+ message: this.message,
217
+ status: this.status,
218
+ code: this.code
219
+ };
220
+ }
221
+ };
222
+
223
+ 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 };
package/package.json ADDED
@@ -0,0 +1,195 @@
1
+ {
2
+ "name": "@bymax-one/nest-auth",
3
+ "version": "1.0.0",
4
+ "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
+ "author": "Bymax One <contact@bymax.one>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/bymaxone/nest-auth#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/bymaxone/nest-auth.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/bymaxone/nest-auth/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/server/index.d.ts",
26
+ "import": "./dist/server/index.mjs",
27
+ "require": "./dist/server/index.cjs"
28
+ },
29
+ "./shared": {
30
+ "types": "./dist/shared/index.d.ts",
31
+ "import": "./dist/shared/index.mjs",
32
+ "require": "./dist/shared/index.cjs"
33
+ },
34
+ "./client": {
35
+ "types": "./dist/client/index.d.ts",
36
+ "import": "./dist/client/index.mjs",
37
+ "require": "./dist/client/index.cjs"
38
+ },
39
+ "./react": {
40
+ "types": "./dist/react/index.d.ts",
41
+ "import": "./dist/react/index.mjs",
42
+ "require": "./dist/react/index.cjs"
43
+ },
44
+ "./nextjs": {
45
+ "types": "./dist/nextjs/index.d.ts",
46
+ "import": "./dist/nextjs/index.mjs",
47
+ "require": "./dist/nextjs/index.cjs"
48
+ }
49
+ },
50
+ "peerDependencies": {
51
+ "@nestjs/common": "^11.0.0",
52
+ "@nestjs/core": "^11.0.0",
53
+ "@nestjs/jwt": "^11.0.0",
54
+ "@nestjs/throttler": "^6.0.0",
55
+ "@nestjs/websockets": "^11.0.0",
56
+ "@types/express": "^5.0.0",
57
+ "class-transformer": "^0.5.0",
58
+ "class-validator": "^0.14.0 || ^0.15.0",
59
+ "express": "^5.0.0",
60
+ "ioredis": "^5.0.0",
61
+ "next": "^16.0.0",
62
+ "react": "^19.0.0",
63
+ "reflect-metadata": "^0.2.0"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "@nestjs/common": {
67
+ "optional": true
68
+ },
69
+ "@nestjs/core": {
70
+ "optional": true
71
+ },
72
+ "@nestjs/jwt": {
73
+ "optional": true
74
+ },
75
+ "@nestjs/throttler": {
76
+ "optional": true
77
+ },
78
+ "@nestjs/websockets": {
79
+ "optional": true
80
+ },
81
+ "class-transformer": {
82
+ "optional": true
83
+ },
84
+ "class-validator": {
85
+ "optional": true
86
+ },
87
+ "express": {
88
+ "optional": true
89
+ },
90
+ "@types/express": {
91
+ "optional": true
92
+ },
93
+ "ioredis": {
94
+ "optional": true
95
+ },
96
+ "reflect-metadata": {
97
+ "optional": true
98
+ },
99
+ "react": {
100
+ "optional": true
101
+ },
102
+ "next": {
103
+ "optional": true
104
+ }
105
+ },
106
+ "devDependencies": {
107
+ "@eslint/js": "^9.39.4",
108
+ "@nestjs/common": "^11.1.20",
109
+ "@nestjs/core": "^11.1.20",
110
+ "@nestjs/jwt": "^11.0.2",
111
+ "@nestjs/platform-express": "^11.1.20",
112
+ "@nestjs/testing": "^11.1.20",
113
+ "@nestjs/throttler": "^6.5.0",
114
+ "@nestjs/websockets": "^11.1.20",
115
+ "@stryker-mutator/core": "^9",
116
+ "@stryker-mutator/jest-runner": "^9",
117
+ "@stryker-mutator/typescript-checker": "^9",
118
+ "@swc/core": "^1.15.33",
119
+ "@testing-library/react": "^16.3.2",
120
+ "@types/express": "^5.0.6",
121
+ "@types/jest": "^30.0.0",
122
+ "@types/node": "^25.7.0",
123
+ "@types/react": "^19.2.14",
124
+ "@types/react-dom": "^19.2.3",
125
+ "@types/supertest": "^7.2.0",
126
+ "@typescript-eslint/eslint-plugin": "^8.59.3",
127
+ "@typescript-eslint/parser": "^8.59.3",
128
+ "class-transformer": "^0.5.1",
129
+ "class-validator": "^0.15.1",
130
+ "eslint": "^9.39.4",
131
+ "eslint-config-prettier": "^10.1.8",
132
+ "eslint-import-resolver-typescript": "^4.4.4",
133
+ "eslint-plugin-import": "^2.32.0",
134
+ "eslint-plugin-prettier": "^5.5.5",
135
+ "eslint-plugin-security": "^4.0.0",
136
+ "globals": "^17.6.0",
137
+ "ioredis": "^5.10.1",
138
+ "ioredis-mock": "^8.13.1",
139
+ "jest": "^30.4.2",
140
+ "jest-environment-jsdom": "^30.4.1",
141
+ "next": "^16.2.6",
142
+ "prettier": "^3.8.3",
143
+ "react": "^19.2.6",
144
+ "react-dom": "^19.2.6",
145
+ "reflect-metadata": "^0.2.2",
146
+ "supertest": "^7.2.2",
147
+ "ts-jest": "^29.4.9",
148
+ "ts-node": "^10.9.2",
149
+ "tsup": "^8.5.1",
150
+ "typescript": "^5.9.3"
151
+ },
152
+ "keywords": [
153
+ "nestjs",
154
+ "auth",
155
+ "authentication",
156
+ "authorization",
157
+ "jwt",
158
+ "mfa",
159
+ "totp",
160
+ "oauth",
161
+ "saas",
162
+ "multi-tenant",
163
+ "nextjs",
164
+ "react",
165
+ "session",
166
+ "rbac",
167
+ "brute-force",
168
+ "password-reset",
169
+ "refresh-token"
170
+ ],
171
+ "engines": {
172
+ "node": ">=24.0.0"
173
+ },
174
+ "publishConfig": {
175
+ "access": "public",
176
+ "registry": "https://registry.npmjs.org/"
177
+ },
178
+ "scripts": {
179
+ "build": "pnpm clean && tsup",
180
+ "lint": "eslint src",
181
+ "lint:fix": "eslint src --fix",
182
+ "test": "jest",
183
+ "test:cov": "jest --coverage",
184
+ "test:watch": "jest --watch",
185
+ "test:e2e": "jest --config jest.e2e.config.ts",
186
+ "test:all": "pnpm test && pnpm test:e2e",
187
+ "test:cov:all": "jest --config jest.coverage.config.ts --coverage",
188
+ "mutation": "stryker run",
189
+ "mutation:incremental": "stryker run --incremental",
190
+ "mutation:dry-run": "stryker run --dryRunOnly",
191
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
192
+ "clean": "rm -rf dist coverage",
193
+ "release": "pnpm publish --provenance"
194
+ }
195
+ }