@withwiz/toolkit 0.5.1 → 0.6.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/dist/auth/adapters/prisma/index.js +24 -23
- package/dist/auth/config.d.ts +2 -0
- package/dist/auth/config.js +1 -1
- package/dist/auth/core/jwt/cookie.js +2 -2
- package/dist/auth/core/jwt/index.js +2 -2
- package/dist/auth/core/jwt/types.js +2 -1
- package/dist/auth/core/oauth/index.js +2 -1
- package/dist/auth/core/password/client-helper.js +2 -1
- package/dist/auth/core/password/index.js +2 -1
- package/dist/auth/email/index.d.ts +2 -0
- package/dist/auth/email/index.js +7 -0
- package/dist/auth/email/sender.d.ts +54 -0
- package/dist/auth/email/sender.js +7 -0
- package/dist/auth/handlers/forgot-password.handler.d.ts +3 -0
- package/dist/auth/handlers/forgot-password.handler.js +12 -0
- package/dist/auth/handlers/index.d.ts +25 -0
- package/dist/auth/handlers/index.js +79 -0
- package/dist/auth/handlers/login.handler.d.ts +3 -0
- package/dist/auth/handlers/login.handler.js +13 -0
- package/dist/auth/handlers/logout.handler.d.ts +3 -0
- package/dist/auth/handlers/logout.handler.js +11 -0
- package/dist/auth/handlers/me.handler.d.ts +3 -0
- package/dist/auth/handlers/me.handler.js +13 -0
- package/dist/auth/handlers/oauth-authorize.handler.d.ts +3 -0
- package/dist/auth/handlers/oauth-authorize.handler.js +15 -0
- package/dist/auth/handlers/oauth-callback.handler.d.ts +3 -0
- package/dist/auth/handlers/oauth-callback.handler.js +21 -0
- package/dist/auth/handlers/refresh.handler.d.ts +3 -0
- package/dist/auth/handlers/refresh.handler.js +14 -0
- package/dist/auth/handlers/register.handler.d.ts +3 -0
- package/dist/auth/handlers/register.handler.js +12 -0
- package/dist/auth/handlers/reset-password.handler.d.ts +3 -0
- package/dist/auth/handlers/reset-password.handler.js +12 -0
- package/dist/auth/handlers/verify-email.handler.d.ts +3 -0
- package/dist/auth/handlers/verify-email.handler.js +12 -0
- package/dist/auth/index.js +19 -18
- package/dist/auth/services/email-verification.service.d.ts +18 -0
- package/dist/auth/services/email-verification.service.js +11 -0
- package/dist/auth/services/index.d.ts +12 -0
- package/dist/auth/services/index.js +36 -0
- package/dist/auth/services/login.service.d.ts +19 -0
- package/dist/auth/services/login.service.js +13 -0
- package/dist/auth/services/oauth-callback.service.d.ts +32 -0
- package/dist/auth/services/oauth-callback.service.js +13 -0
- package/dist/auth/services/password-reset.service.d.ts +20 -0
- package/dist/auth/services/password-reset.service.js +11 -0
- package/dist/auth/services/register.service.d.ts +28 -0
- package/dist/auth/services/register.service.js +11 -0
- package/dist/auth/services/token-refresh.service.d.ts +25 -0
- package/dist/auth/services/token-refresh.service.js +13 -0
- package/dist/auth/types/handler-types.d.ts +68 -0
- package/dist/auth/types/handler-types.js +1 -0
- package/dist/auth/types/index.d.ts +1 -0
- package/dist/auth/types/index.js +2 -1
- package/dist/cache/cache-config.js +3 -3
- package/dist/cache/cache-env.js +2 -2
- package/dist/cache/cache-factory.js +10 -10
- package/dist/cache/cache-invalidation.js +11 -11
- package/dist/cache/cache-redis.js +4 -4
- package/dist/cache/cache-wrapper.js +11 -11
- package/dist/cache/cache.js +12 -12
- package/dist/cache/hybrid-cache-manager.js +6 -6
- package/dist/cache/index.js +12 -12
- package/dist/cache/inmemory-cache-manager.js +2 -3
- package/dist/cache/noop-cache-manager.js +4 -4
- package/dist/cache/redis-cache-manager.js +5 -5
- package/dist/{chunk-LFQ3IQQB.js → chunk-3AJHXCDG.js} +2 -2
- package/dist/{chunk-N3TAGJHR.js → chunk-3ECJUXLM.js} +2 -2
- package/dist/{chunk-WMQE2YK7.js → chunk-4BGAE7NU.js} +1 -1
- package/dist/chunk-4YQ6YBM7.js +50 -0
- package/dist/chunk-6B7VU6RZ.js +90 -0
- package/dist/chunk-6JY6NUR6.js +38 -0
- package/dist/{chunk-YSUL3SLC.js → chunk-77BJRPMN.js} +4 -4
- package/dist/{chunk-GGSFZP6T.js → chunk-7JKZBEVB.js} +8 -8
- package/dist/{chunk-KGHWGLED.js → chunk-7KZRPDQD.js} +1 -1
- package/dist/{chunk-OZE5KUS3.js → chunk-A2XAOU55.js} +3 -2
- package/dist/{chunk-7LJWRKDT.js → chunk-BEV7PQM3.js} +1 -1
- package/dist/{chunk-OIRAH57Y.js → chunk-CKK55QFQ.js} +1 -1
- package/dist/{chunk-MAATEX2R.js → chunk-CRMXLNLC.js} +1 -1
- package/dist/{chunk-J4TTSXDN.js → chunk-CW3INZMV.js} +1 -1
- package/dist/chunk-DFSNHVXF.js +54 -0
- package/dist/chunk-ETMTDHK2.js +53 -0
- package/dist/{chunk-FUDEEQR3.js → chunk-EXJQKCTN.js} +4 -4
- package/dist/chunk-FI46LV42.js +56 -0
- package/dist/{chunk-LX2EYD74.js → chunk-FNECYXI4.js} +10 -10
- package/dist/chunk-FRY3TNJ6.js +37 -0
- package/dist/{chunk-LLVIA4JX.js → chunk-G2Q4TI3Q.js} +5 -5
- package/dist/{chunk-X5RMDLLM.js → chunk-IHUQRVPV.js} +2 -2
- package/dist/chunk-JQFQT4S2.js +55 -0
- package/dist/{chunk-FPESPW6P.js → chunk-KF3O2DAV.js} +1 -1
- package/dist/chunk-KY7JZ54O.js +62 -0
- package/dist/{chunk-2F6KNGOD.js → chunk-L5WLPC2T.js} +1 -1
- package/dist/{chunk-ZBXSEQ6W.js → chunk-LFKPXF5E.js} +4 -4
- package/dist/{chunk-L6AU74EI.js → chunk-MDTID4D2.js} +1 -1
- package/dist/{chunk-KHYY4KCV.js → chunk-MEFZZE4M.js} +4 -4
- package/dist/chunk-MGQV723O.js +104 -0
- package/dist/chunk-N6TMHITU.js +49 -0
- package/dist/{chunk-NQQU6UFE.js → chunk-O35V6RIF.js} +3 -3
- package/dist/{chunk-4HBAPPB2.js → chunk-OCI7QCLM.js} +2 -2
- package/dist/{chunk-GFAD4UAT.js → chunk-ON7HZ3PW.js} +1 -1
- package/dist/{chunk-O3UR234Y.js → chunk-PAF5OGDU.js} +7 -7
- package/dist/{chunk-3J7FDOCU.js → chunk-PYVYYO4X.js} +5 -5
- package/dist/{chunk-CRWMULHR.js → chunk-Q6KXN7HL.js} +2 -2
- package/dist/chunk-Q7VFOUFI.js +68 -0
- package/dist/chunk-QYXI45KH.js +62 -0
- package/dist/chunk-R4SXQYIT.js +0 -0
- package/dist/chunk-S7OQWKUJ.js +83 -0
- package/dist/{chunk-FD2TXDTO.js → chunk-SR3SQL72.js} +2 -2
- package/dist/{chunk-JOM3N4EJ.js → chunk-SSS6XSEG.js} +1 -1
- package/dist/{chunk-GQVBWZLH.js → chunk-TEXVRHPF.js} +2 -13
- package/dist/chunk-TFZOOP3V.js +50 -0
- package/dist/{chunk-K3HAYBWX.js → chunk-VCOA6LMN.js} +1 -1
- package/dist/{chunk-6SOQUYOU.js → chunk-W2GBKW2T.js} +2 -2
- package/dist/chunk-WC2IYFGC.js +51 -0
- package/dist/{chunk-AQJAY5FA.js → chunk-WJSMXUZB.js} +1 -1
- package/dist/chunk-WNEXLSDB.js +17 -0
- package/dist/{chunk-3YUKCYHI.js → chunk-WRWWB2NU.js} +3 -13
- package/dist/{chunk-IPXPCBDO.js → chunk-WVDYHSHD.js} +1 -1
- package/dist/{chunk-S5UCZ2T3.js → chunk-X6MGVFT3.js} +1 -1
- package/dist/chunk-YZXGOOFC.js +0 -0
- package/dist/components/ui/DataTable.js +10 -9
- package/dist/components/ui/data-table/DataTable.js +9 -9
- package/dist/components/ui/data-table/DataTableBulkActions.js +2 -2
- package/dist/components/ui/data-table/DataTableFilters.js +3 -3
- package/dist/components/ui/data-table/DataTablePagination.js +2 -2
- package/dist/components/ui/data-table/DataTableSearch.js +3 -3
- package/dist/components/ui/data-table/index.js +42 -0
- package/dist/components/ui/data-table/types.js +9 -0
- package/dist/error/error-handler.js +2 -3
- package/dist/error/index.js +2 -3
- package/dist/geolocation/batch-processor.js +2 -3
- package/dist/geolocation/index.js +9 -10
- package/dist/geolocation/providers/index.js +7 -7
- package/dist/initialize.js +4 -4
- package/dist/logger/logger.js +1 -2
- package/dist/middleware/auth.js +4 -5
- package/dist/middleware/cors.js +2 -3
- package/dist/middleware/error-handler.js +3 -4
- package/dist/middleware/index.js +12 -13
- package/dist/middleware/middleware-chain.js +2 -3
- package/dist/middleware/rate-limit.js +2 -3
- package/dist/middleware/response-logger.js +2 -3
- package/dist/middleware/security.js +2 -3
- package/dist/middleware/wrappers.js +12 -13
- package/dist/system/cpu.js +3 -4
- package/dist/system/disk.js +3 -4
- package/dist/system/environment.js +5 -5
- package/dist/system/health-check.js +3 -4
- package/dist/system/index.js +10 -10
- package/dist/system/memory.js +3 -4
- package/dist/system/network.js +3 -4
- package/dist/system/utils.js +2 -3
- package/dist/utils/csv-export.js +2 -3
- package/dist/utils/error-processor.js +2 -3
- package/dist/utils/index.js +3 -3
- package/package.json +6 -2
- package/dist/{chunk-SEZJN4TC.js → chunk-5UVEOCRU.js} +6 -6
- package/dist/{chunk-CUZPD3BF.js → chunk-CMU52MEQ.js} +6 -6
- package/dist/{chunk-BJLLMVWW.js → chunk-DBHISLC6.js} +3 -3
- /package/dist/{chunk-NY5QXT33.js → chunk-I6Q3WUDT.js} +0 -0
- /package/dist/{chunk-QKC73SWB.js → chunk-ITGUSYUH.js} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RedisCacheManager
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-O35V6RIF.js";
|
|
4
|
+
import "../chunk-IHUQRVPV.js";
|
|
5
|
+
import "../chunk-TEXVRHPF.js";
|
|
6
6
|
import "../chunk-OHBAELPZ.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-UCIUAZQT.js";
|
|
7
|
+
import "../chunk-DBHISLC6.js";
|
|
9
8
|
import "../chunk-SFPMFVSD.js";
|
|
9
|
+
import "../chunk-UCIUAZQT.js";
|
|
10
10
|
import "../chunk-K25ICPU4.js";
|
|
11
11
|
import "../chunk-2QH66EVQ.js";
|
|
12
12
|
import "../chunk-57W32BFZ.js";
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-YUBXS7YI.js";
|
|
5
5
|
import {
|
|
6
6
|
getPlatform
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-X6MGVFT3.js";
|
|
8
8
|
import {
|
|
9
9
|
logger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TEXVRHPF.js";
|
|
11
11
|
import {
|
|
12
12
|
getResolvedCacheConfig
|
|
13
13
|
} from "./chunk-UCIUAZQT.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JWTService
|
|
3
|
+
} from "./chunk-3GAY2T2A.js";
|
|
4
|
+
import {
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-ORMEWXMH.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/handlers/me.handler.ts
|
|
9
|
+
import { NextResponse } from "next/server";
|
|
10
|
+
function createMeHandler(options) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const { dependencies, jwt, hooks } = options;
|
|
13
|
+
const jwtService = new JWTService({
|
|
14
|
+
secret: jwt.secret,
|
|
15
|
+
accessTokenExpiry: (_a = jwt.accessTokenExpiry) != null ? _a : "7d",
|
|
16
|
+
refreshTokenExpiry: (_b = jwt.refreshTokenExpiry) != null ? _b : "30d",
|
|
17
|
+
algorithm: "HS256"
|
|
18
|
+
});
|
|
19
|
+
return async (request) => {
|
|
20
|
+
var _a2, _b2, _c;
|
|
21
|
+
try {
|
|
22
|
+
const token = (_c = (_a2 = request.cookies.get("access_token")) == null ? void 0 : _a2.value) != null ? _c : jwtService.extractTokenFromHeader((_b2 = request.headers.get("authorization")) != null ? _b2 : void 0);
|
|
23
|
+
if (!token) {
|
|
24
|
+
return NextResponse.json({ success: false, error: "Not authenticated" }, { status: 401 });
|
|
25
|
+
}
|
|
26
|
+
const payload = await jwtService.verifyAccessToken(token);
|
|
27
|
+
const user = await dependencies.userRepository.findById(payload.userId);
|
|
28
|
+
if (!user || user.isActive === false) {
|
|
29
|
+
return NextResponse.json({ success: false, error: "User not found" }, { status: 401 });
|
|
30
|
+
}
|
|
31
|
+
let userResponse = {
|
|
32
|
+
id: user.id,
|
|
33
|
+
email: user.email,
|
|
34
|
+
name: user.name,
|
|
35
|
+
role: user.role,
|
|
36
|
+
emailVerified: user.emailVerified
|
|
37
|
+
};
|
|
38
|
+
if (hooks == null ? void 0 : hooks.extendUserResponse) {
|
|
39
|
+
userResponse = __spreadValues(__spreadValues({}, userResponse), await hooks.extendUserResponse(user));
|
|
40
|
+
}
|
|
41
|
+
return NextResponse.json({ success: true, user: userResponse });
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return NextResponse.json({ success: false, error: "Not authenticated" }, { status: 401 });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
createMeHandler
|
|
50
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JWTService
|
|
3
|
+
} from "./chunk-3GAY2T2A.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthError
|
|
6
|
+
} from "./chunk-AIH3F7JV.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/services/oauth-callback.service.ts
|
|
9
|
+
var OAuthCallbackService = class {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
this.userRepo = config.userRepository;
|
|
13
|
+
this.oauthRepo = config.oauthAccountRepository;
|
|
14
|
+
this.jwtService = new JWTService({
|
|
15
|
+
secret: config.jwtSecret,
|
|
16
|
+
accessTokenExpiry: (_a = config.accessTokenExpiry) != null ? _a : "7d",
|
|
17
|
+
refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d",
|
|
18
|
+
algorithm: "HS256"
|
|
19
|
+
}, config.logger);
|
|
20
|
+
this.logger = (_c = config.logger) != null ? _c : { debug() {
|
|
21
|
+
}, info() {
|
|
22
|
+
}, warn() {
|
|
23
|
+
}, error() {
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
async handleCallback(input) {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const existingAccount = await this.oauthRepo.findByProvider(input.provider, input.providerAccountId);
|
|
29
|
+
if (existingAccount) {
|
|
30
|
+
const user = await this.userRepo.findById(existingAccount.userId);
|
|
31
|
+
if (!user) {
|
|
32
|
+
throw new AuthError("User not found for OAuth account", "USER_NOT_FOUND", 404);
|
|
33
|
+
}
|
|
34
|
+
if (user.isActive === false) {
|
|
35
|
+
throw new AuthError("Account is disabled", "ACCOUNT_DISABLED", 403);
|
|
36
|
+
}
|
|
37
|
+
await this.oauthRepo.update(existingAccount.id, {
|
|
38
|
+
accessToken: input.accessToken,
|
|
39
|
+
refreshToken: (_a = input.refreshToken) != null ? _a : null
|
|
40
|
+
});
|
|
41
|
+
await this.userRepo.updateLastLoginAt(user.id);
|
|
42
|
+
const tokens2 = await this.createTokens(user);
|
|
43
|
+
return { user, tokens: tokens2, isNewUser: false };
|
|
44
|
+
}
|
|
45
|
+
const existingUser = await this.userRepo.findByEmail(input.email);
|
|
46
|
+
if (existingUser) {
|
|
47
|
+
await this.oauthRepo.create({
|
|
48
|
+
userId: existingUser.id,
|
|
49
|
+
provider: input.provider,
|
|
50
|
+
providerAccountId: input.providerAccountId,
|
|
51
|
+
accessToken: input.accessToken,
|
|
52
|
+
refreshToken: (_b = input.refreshToken) != null ? _b : null
|
|
53
|
+
});
|
|
54
|
+
await this.userRepo.updateLastLoginAt(existingUser.id);
|
|
55
|
+
const tokens2 = await this.createTokens(existingUser);
|
|
56
|
+
return { user: existingUser, tokens: tokens2, isNewUser: false };
|
|
57
|
+
}
|
|
58
|
+
const newUser = await this.userRepo.create({
|
|
59
|
+
email: input.email,
|
|
60
|
+
name: input.name,
|
|
61
|
+
image: input.image,
|
|
62
|
+
role: "USER",
|
|
63
|
+
emailVerified: /* @__PURE__ */ new Date()
|
|
64
|
+
// OAuth users are auto-verified
|
|
65
|
+
});
|
|
66
|
+
await this.oauthRepo.create({
|
|
67
|
+
userId: newUser.id,
|
|
68
|
+
provider: input.provider,
|
|
69
|
+
providerAccountId: input.providerAccountId,
|
|
70
|
+
accessToken: input.accessToken,
|
|
71
|
+
refreshToken: (_c = input.refreshToken) != null ? _c : null
|
|
72
|
+
});
|
|
73
|
+
const tokens = await this.createTokens(newUser);
|
|
74
|
+
this.logger.info("New OAuth user created", { userId: newUser.id, provider: input.provider });
|
|
75
|
+
return { user: newUser, tokens, isNewUser: true };
|
|
76
|
+
}
|
|
77
|
+
async createTokens(user) {
|
|
78
|
+
var _a;
|
|
79
|
+
return this.jwtService.createTokenPair({
|
|
80
|
+
id: user.id,
|
|
81
|
+
email: user.email,
|
|
82
|
+
role: (_a = user.role) != null ? _a : "USER",
|
|
83
|
+
emailVerified: user.emailVerified
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
OAuthCallbackService
|
|
90
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OAuthManager
|
|
3
|
+
} from "./chunk-HZLJYEOO.js";
|
|
4
|
+
|
|
5
|
+
// src/auth/handlers/oauth-authorize.handler.ts
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
function createOAuthAuthorizeHandler(options) {
|
|
8
|
+
const { oauth } = options;
|
|
9
|
+
return async (request) => {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
const body = await request.json();
|
|
13
|
+
const provider = body.provider;
|
|
14
|
+
if (!provider || !(oauth == null ? void 0 : oauth[provider])) {
|
|
15
|
+
return NextResponse.json({ success: false, error: "Invalid provider" }, { status: 400 });
|
|
16
|
+
}
|
|
17
|
+
const providers = {};
|
|
18
|
+
for (const [name, config] of Object.entries(oauth)) {
|
|
19
|
+
providers[name] = config;
|
|
20
|
+
}
|
|
21
|
+
const noopLogger = { debug() {
|
|
22
|
+
}, info() {
|
|
23
|
+
}, warn() {
|
|
24
|
+
}, error() {
|
|
25
|
+
} };
|
|
26
|
+
const manager = new OAuthManager({ providers }, (_a = options.dependencies.logger) != null ? _a : noopLogger);
|
|
27
|
+
const state = crypto.randomUUID();
|
|
28
|
+
const loginUrl = manager.getLoginUrl(provider, state);
|
|
29
|
+
return NextResponse.json({ success: true, loginUrl, state });
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return NextResponse.json({ success: false, error: "OAuth initialization failed" }, { status: 500 });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
createOAuthAuthorizeHandler
|
|
38
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCacheManager,
|
|
3
3
|
getEffectiveCacheBackend
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7JKZBEVB.js";
|
|
5
5
|
import {
|
|
6
6
|
logger
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TEXVRHPF.js";
|
|
8
8
|
import {
|
|
9
9
|
getCacheConfig,
|
|
10
10
|
getCacheTTL
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-BEV7PQM3.js";
|
|
12
12
|
import {
|
|
13
13
|
isCacheEnabled
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-DBHISLC6.js";
|
|
15
15
|
|
|
16
16
|
// src/cache/cache-wrapper.ts
|
|
17
17
|
function getCacheBackendLabel() {
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoopCacheManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q6KXN7HL.js";
|
|
4
4
|
import {
|
|
5
5
|
RedisCacheManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-O35V6RIF.js";
|
|
7
7
|
import {
|
|
8
8
|
HybridCacheManager
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EXJQKCTN.js";
|
|
10
10
|
import {
|
|
11
11
|
isRedisAvailableNow,
|
|
12
12
|
isRedisGloballyDisabled
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-IHUQRVPV.js";
|
|
14
14
|
import {
|
|
15
15
|
InMemoryCacheManager
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CW3INZMV.js";
|
|
17
17
|
import {
|
|
18
18
|
logger
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-TEXVRHPF.js";
|
|
20
20
|
import {
|
|
21
21
|
getCacheConfig
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-BEV7PQM3.js";
|
|
23
23
|
import {
|
|
24
24
|
getENV,
|
|
25
25
|
isCacheEnabled
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-DBHISLC6.js";
|
|
27
27
|
|
|
28
28
|
// src/cache/cache-factory.ts
|
|
29
29
|
function getInMemoryConfig() {
|
|
@@ -15,7 +15,7 @@ function setConfig(config) {
|
|
|
15
15
|
globalThis[GLOBAL_KEY] = config;
|
|
16
16
|
}
|
|
17
17
|
function initializeAuth(config) {
|
|
18
|
-
var _a, _b;
|
|
18
|
+
var _a, _b, _c;
|
|
19
19
|
if (getConfig()) return;
|
|
20
20
|
if (!config.jwtSecret) {
|
|
21
21
|
throw new ConfigurationError("Auth", "jwtSecret is required");
|
|
@@ -29,7 +29,8 @@ function initializeAuth(config) {
|
|
|
29
29
|
setConfig({
|
|
30
30
|
jwtSecret: config.jwtSecret,
|
|
31
31
|
accessTokenExpiry: (_a = config.accessTokenExpiry) != null ? _a : "7d",
|
|
32
|
-
refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d"
|
|
32
|
+
refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d",
|
|
33
|
+
cookieSecure: (_c = config.cookieSecure) != null ? _c : false
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
function getAuthConfig() {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JWTService
|
|
3
|
+
} from "./chunk-3GAY2T2A.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthError
|
|
6
|
+
} from "./chunk-AIH3F7JV.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/services/login.service.ts
|
|
9
|
+
import { compare } from "bcryptjs";
|
|
10
|
+
var LoginService = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
this.userRepo = config.userRepository;
|
|
14
|
+
this.jwtService = new JWTService({
|
|
15
|
+
secret: config.jwtSecret,
|
|
16
|
+
accessTokenExpiry: (_a = config.accessTokenExpiry) != null ? _a : "7d",
|
|
17
|
+
refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d",
|
|
18
|
+
algorithm: "HS256"
|
|
19
|
+
}, config.logger);
|
|
20
|
+
this.logger = (_c = config.logger) != null ? _c : { debug() {
|
|
21
|
+
}, info() {
|
|
22
|
+
}, warn() {
|
|
23
|
+
}, error() {
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
async login(email, password, storedHash) {
|
|
27
|
+
var _a;
|
|
28
|
+
const user = await this.userRepo.findByEmail(email);
|
|
29
|
+
if (!user) {
|
|
30
|
+
throw new AuthError("Invalid credentials", "INVALID_CREDENTIALS", 401);
|
|
31
|
+
}
|
|
32
|
+
if (user.isActive === false) {
|
|
33
|
+
throw new AuthError("Account is disabled", "ACCOUNT_DISABLED", 403);
|
|
34
|
+
}
|
|
35
|
+
const isValid = await compare(password, storedHash);
|
|
36
|
+
if (!isValid) {
|
|
37
|
+
this.logger.warn("Failed login attempt", { email });
|
|
38
|
+
throw new AuthError("Invalid credentials", "INVALID_CREDENTIALS", 401);
|
|
39
|
+
}
|
|
40
|
+
const tokens = await this.jwtService.createTokenPair({
|
|
41
|
+
id: user.id,
|
|
42
|
+
email: user.email,
|
|
43
|
+
role: (_a = user.role) != null ? _a : "USER",
|
|
44
|
+
emailVerified: user.emailVerified
|
|
45
|
+
});
|
|
46
|
+
await this.userRepo.updateLastLoginAt(user.id);
|
|
47
|
+
this.logger.info("User logged in successfully", { userId: user.id });
|
|
48
|
+
return { user, tokens };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
LoginService
|
|
54
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TokenGenerator
|
|
3
|
+
} from "./chunk-GDWEDUHO.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthError
|
|
6
|
+
} from "./chunk-AIH3F7JV.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/services/register.service.ts
|
|
9
|
+
import { hash } from "bcryptjs";
|
|
10
|
+
var RegisterService = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
this.userRepo = config.userRepository;
|
|
14
|
+
this.tokenRepo = config.emailTokenRepository;
|
|
15
|
+
this.emailSender = config.emailSender;
|
|
16
|
+
this.emailVerificationRequired = (_a = config.emailVerificationRequired) != null ? _a : true;
|
|
17
|
+
this.bcryptRounds = (_b = config.bcryptRounds) != null ? _b : 12;
|
|
18
|
+
this.logger = (_c = config.logger) != null ? _c : { debug() {
|
|
19
|
+
}, info() {
|
|
20
|
+
}, warn() {
|
|
21
|
+
}, error() {
|
|
22
|
+
} };
|
|
23
|
+
}
|
|
24
|
+
async register(input) {
|
|
25
|
+
var _a;
|
|
26
|
+
const existing = await this.userRepo.findByEmail(input.email);
|
|
27
|
+
if (existing) {
|
|
28
|
+
throw new AuthError("Email already in use", "EMAIL_ALREADY_EXISTS", 409);
|
|
29
|
+
}
|
|
30
|
+
const hashedPassword = await hash(input.password, this.bcryptRounds);
|
|
31
|
+
const user = await this.userRepo.create({
|
|
32
|
+
email: input.email,
|
|
33
|
+
password: hashedPassword,
|
|
34
|
+
name: (_a = input.name) != null ? _a : null,
|
|
35
|
+
role: "USER",
|
|
36
|
+
emailVerified: this.emailVerificationRequired ? null : /* @__PURE__ */ new Date()
|
|
37
|
+
});
|
|
38
|
+
let verificationSent = false;
|
|
39
|
+
if (this.emailVerificationRequired && this.emailSender) {
|
|
40
|
+
const token = TokenGenerator.generate();
|
|
41
|
+
const expires = new Date(Date.now() + 24 * 60 * 60 * 1e3);
|
|
42
|
+
await this.tokenRepo.create(input.email, token, "EMAIL_VERIFICATION" /* EMAIL_VERIFICATION */, expires);
|
|
43
|
+
await this.emailSender.sendVerificationEmail(input.email, token);
|
|
44
|
+
verificationSent = true;
|
|
45
|
+
}
|
|
46
|
+
this.logger.info("User registered", { userId: user.id, email: input.email });
|
|
47
|
+
return { user, verificationSent };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
RegisterService
|
|
53
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isRedisGloballyDisabled,
|
|
3
3
|
notifyRedisError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IHUQRVPV.js";
|
|
5
5
|
import {
|
|
6
6
|
InMemoryCacheManager
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CW3INZMV.js";
|
|
8
8
|
import {
|
|
9
9
|
logger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TEXVRHPF.js";
|
|
11
11
|
import {
|
|
12
12
|
getCacheFallbackConfig
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-DBHISLC6.js";
|
|
14
14
|
import {
|
|
15
15
|
__spreadValues
|
|
16
16
|
} from "./chunk-ORMEWXMH.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TokenRefreshService
|
|
3
|
+
} from "./chunk-JQFQT4S2.js";
|
|
4
|
+
import {
|
|
5
|
+
setTokenCookies
|
|
6
|
+
} from "./chunk-G2Q4TI3Q.js";
|
|
7
|
+
import {
|
|
8
|
+
AuthError
|
|
9
|
+
} from "./chunk-AIH3F7JV.js";
|
|
10
|
+
|
|
11
|
+
// src/auth/handlers/refresh.handler.ts
|
|
12
|
+
import { NextResponse } from "next/server";
|
|
13
|
+
function createRefreshHandler(options) {
|
|
14
|
+
const { dependencies, jwt, hooks, cookie } = options;
|
|
15
|
+
const refreshService = new TokenRefreshService({
|
|
16
|
+
userRepository: dependencies.userRepository,
|
|
17
|
+
jwtSecret: jwt.secret,
|
|
18
|
+
accessTokenExpiry: jwt.accessTokenExpiry,
|
|
19
|
+
refreshTokenExpiry: jwt.refreshTokenExpiry,
|
|
20
|
+
isTokenBlacklisted: hooks == null ? void 0 : hooks.isTokenBlacklisted,
|
|
21
|
+
logger: dependencies.logger
|
|
22
|
+
});
|
|
23
|
+
return async (request) => {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
const refreshToken = (_a = request.cookies.get("refresh_token")) == null ? void 0 : _a.value;
|
|
27
|
+
if (!refreshToken) {
|
|
28
|
+
return NextResponse.json({ success: false, error: "No refresh token" }, { status: 401 });
|
|
29
|
+
}
|
|
30
|
+
if (hooks == null ? void 0 : hooks.onBeforeTokenRefresh) {
|
|
31
|
+
const hookResult = await hooks.onBeforeTokenRefresh(refreshToken);
|
|
32
|
+
if (hookResult instanceof Response) return hookResult;
|
|
33
|
+
}
|
|
34
|
+
const result = await refreshService.refresh(refreshToken);
|
|
35
|
+
const response = NextResponse.json({
|
|
36
|
+
success: true,
|
|
37
|
+
accessToken: result.accessToken,
|
|
38
|
+
user: result.user
|
|
39
|
+
});
|
|
40
|
+
setTokenCookies(response, { accessToken: result.accessToken, refreshToken }, { secure: cookie == null ? void 0 : cookie.secure });
|
|
41
|
+
return response;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof AuthError) {
|
|
44
|
+
return NextResponse.json(
|
|
45
|
+
{ success: false, error: error.message, code: error.code },
|
|
46
|
+
{ status: error.statusCode }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return NextResponse.json({ success: false, error: "Token refresh failed" }, { status: 401 });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
createRefreshHandler
|
|
56
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataTableBody
|
|
3
|
-
} from "./chunk-7IY3RQQL.js";
|
|
4
|
-
import {
|
|
5
|
-
DataTableBulkActions
|
|
6
|
-
} from "./chunk-MAATEX2R.js";
|
|
7
1
|
import {
|
|
8
2
|
DataTableFilters
|
|
9
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5UVEOCRU.js";
|
|
10
4
|
import {
|
|
11
5
|
DataTablePagination
|
|
12
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WVDYHSHD.js";
|
|
13
7
|
import {
|
|
14
8
|
DataTableSearch
|
|
15
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MEFZZE4M.js";
|
|
10
|
+
import {
|
|
11
|
+
DataTableBody
|
|
12
|
+
} from "./chunk-7IY3RQQL.js";
|
|
13
|
+
import {
|
|
14
|
+
DataTableBulkActions
|
|
15
|
+
} from "./chunk-CRMXLNLC.js";
|
|
16
16
|
import {
|
|
17
17
|
DEFAULT_LABELS
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-I6Q3WUDT.js";
|
|
19
19
|
import {
|
|
20
20
|
Alert,
|
|
21
21
|
AlertDescription
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PasswordResetService
|
|
3
|
+
} from "./chunk-WC2IYFGC.js";
|
|
4
|
+
|
|
5
|
+
// src/auth/handlers/forgot-password.handler.ts
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
var schema = z.object({ email: z.string().email() });
|
|
9
|
+
function createForgotPasswordHandler(options) {
|
|
10
|
+
const { dependencies } = options;
|
|
11
|
+
return async (request) => {
|
|
12
|
+
try {
|
|
13
|
+
const body = await request.json();
|
|
14
|
+
const parsed = schema.safeParse(body);
|
|
15
|
+
if (!parsed.success) {
|
|
16
|
+
return NextResponse.json({ success: false, error: "Invalid email" }, { status: 400 });
|
|
17
|
+
}
|
|
18
|
+
if (!dependencies.emailSender) {
|
|
19
|
+
return NextResponse.json({ success: false, error: "Email service not configured" }, { status: 500 });
|
|
20
|
+
}
|
|
21
|
+
const service = new PasswordResetService({
|
|
22
|
+
userRepository: dependencies.userRepository,
|
|
23
|
+
emailTokenRepository: dependencies.emailTokenRepository,
|
|
24
|
+
emailSender: dependencies.emailSender,
|
|
25
|
+
logger: dependencies.logger
|
|
26
|
+
});
|
|
27
|
+
await service.requestReset(parsed.data.email);
|
|
28
|
+
return NextResponse.json({ success: true });
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return NextResponse.json({ success: true });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
createForgotPasswordHandler
|
|
37
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
getAuthConfig
|
|
3
|
+
} from "./chunk-A2XAOU55.js";
|
|
4
4
|
import {
|
|
5
5
|
__spreadValues
|
|
6
6
|
} from "./chunk-ORMEWXMH.js";
|
|
7
7
|
|
|
8
8
|
// src/auth/core/jwt/cookie.ts
|
|
9
9
|
function getDefaultOptions() {
|
|
10
|
-
let
|
|
10
|
+
let secure = false;
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
secure = getAuthConfig().cookieSecure;
|
|
13
13
|
} catch (e) {
|
|
14
14
|
}
|
|
15
15
|
return {
|
|
16
|
-
secure
|
|
16
|
+
secure,
|
|
17
17
|
sameSite: "lax"
|
|
18
18
|
};
|
|
19
19
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TEXVRHPF.js";
|
|
4
4
|
import {
|
|
5
5
|
getCacheFallbackConfig,
|
|
6
6
|
getConfig,
|
|
7
7
|
getEnv,
|
|
8
8
|
isCacheEnabled,
|
|
9
9
|
validateRedisEnvironment
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-DBHISLC6.js";
|
|
11
11
|
|
|
12
12
|
// src/cache/cache-redis.ts
|
|
13
13
|
import { Redis } from "@upstash/redis";
|