@withwiz/toolkit 0.5.2 → 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.js +2 -2
- package/dist/auth/core/jwt/cookie.js +3 -3
- package/dist/auth/core/jwt/index.js +3 -3
- 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 +21 -20
- 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 +6 -6
- package/dist/cache/cache-env.js +5 -5
- package/dist/cache/cache-factory.js +14 -14
- package/dist/cache/cache-invalidation.js +15 -15
- package/dist/cache/cache-redis.js +8 -8
- package/dist/cache/cache-wrapper.js +15 -15
- package/dist/cache/cache.js +22 -22
- package/dist/cache/config.js +2 -2
- package/dist/cache/hybrid-cache-manager.js +10 -10
- package/dist/cache/index.js +22 -22
- package/dist/cache/inmemory-cache-manager.js +4 -4
- package/dist/cache/noop-cache-manager.js +7 -7
- package/dist/cache/redis-cache-manager.js +9 -9
- package/dist/{chunk-7ZQQ6PJ4.js → chunk-2VMTIYLX.js} +2 -2
- package/dist/{chunk-ZX7PHFX3.js → chunk-3AJHXCDG.js} +2 -2
- package/dist/{chunk-6YQU2AIK.js → chunk-3ECJUXLM.js} +3 -3
- package/dist/{chunk-PEFRPADW.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-YIB6H6P7.js → chunk-77BJRPMN.js} +4 -4
- package/dist/{chunk-LTEXLSIE.js → chunk-7JKZBEVB.js} +12 -12
- package/dist/{chunk-3TD5OAQS.js → chunk-7KZRPDQD.js} +4 -4
- package/dist/{chunk-QHDOMDC6.js → chunk-BEV7PQM3.js} +1 -1
- package/dist/{chunk-ZRXE4WSP.js → chunk-CKK55QFQ.js} +1 -1
- package/dist/{chunk-PAYLVMZN.js → chunk-CMU52MEQ.js} +6 -6
- package/dist/{chunk-MAATEX2R.js → chunk-CRMXLNLC.js} +1 -1
- package/dist/{chunk-7GKSYCKZ.js → chunk-CW3INZMV.js} +1 -1
- package/dist/{chunk-5FSPXXNB.js → chunk-DBHISLC6.js} +4 -4
- package/dist/chunk-DFSNHVXF.js +54 -0
- package/dist/chunk-ETMTDHK2.js +53 -0
- package/dist/{chunk-HHJZTDXL.js → chunk-EXJQKCTN.js} +6 -6
- 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-ZEIFD4OQ.js → chunk-G2Q4TI3Q.js} +1 -1
- package/dist/{chunk-LCKQOHXI.js → chunk-G5OMETUS.js} +1 -1
- package/dist/{chunk-GCR4PGRY.js → chunk-HHCDMWEF.js} +1 -1
- package/dist/{chunk-ENIKCCAV.js → chunk-IHUQRVPV.js} +2 -2
- package/dist/chunk-JQFQT4S2.js +55 -0
- package/dist/{chunk-5E66FUBP.js → chunk-KF3O2DAV.js} +1 -1
- package/dist/chunk-KY7JZ54O.js +62 -0
- package/dist/{chunk-33BG6FPO.js → chunk-L5WLPC2T.js} +1 -1
- package/dist/{chunk-YGJJIC6S.js → chunk-LFKPXF5E.js} +4 -4
- package/dist/{chunk-DCUQNXVP.js → chunk-MDTID4D2.js} +3 -3
- 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-BYHP4EH3.js → chunk-O35V6RIF.js} +3 -3
- package/dist/{chunk-2B4EKCV6.js → chunk-OCI7QCLM.js} +2 -2
- package/dist/{chunk-XKWT6W4K.js → chunk-ON7HZ3PW.js} +1 -1
- package/dist/{chunk-OBNS4ADX.js → chunk-PAF5OGDU.js} +7 -7
- package/dist/{chunk-S2O22ULX.js → chunk-PYVYYO4X.js} +7 -7
- package/dist/{chunk-ORYZZD5P.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-UWD5AHWI.js → chunk-SR3SQL72.js} +2 -2
- package/dist/{chunk-D7OUX5VJ.js → chunk-SSS6XSEG.js} +1 -1
- package/dist/{chunk-L6OEQBOM.js → chunk-TEXVRHPF.js} +1 -1
- package/dist/chunk-TFZOOP3V.js +50 -0
- package/dist/{chunk-HW732FCA.js → chunk-VCOA6LMN.js} +1 -1
- package/dist/{chunk-QWAMNYUT.js → chunk-W2GBKW2T.js} +2 -2
- package/dist/chunk-WC2IYFGC.js +51 -0
- package/dist/{chunk-XIDMCDD3.js → chunk-WJSMXUZB.js} +1 -1
- package/dist/chunk-WNEXLSDB.js +17 -0
- package/dist/{chunk-TCQ2DA6Y.js → chunk-WRWWB2NU.js} +4 -4
- package/dist/{chunk-IPXPCBDO.js → chunk-WVDYHSHD.js} +1 -1
- package/dist/{chunk-4J4D27BV.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/config/common.js +2 -2
- package/dist/error/error-handler.js +4 -4
- package/dist/error/index.js +4 -4
- package/dist/geolocation/batch-processor.js +4 -4
- package/dist/geolocation/config.js +2 -2
- package/dist/geolocation/index.js +12 -12
- package/dist/geolocation/providers/index.js +9 -9
- package/dist/geolocation/providers/ipgeolocation-provider.js +3 -3
- package/dist/geolocation/providers/maxmind-provider.js +3 -3
- package/dist/initialize.js +14 -14
- package/dist/logger/config.js +2 -2
- package/dist/logger/logger.js +3 -3
- package/dist/middleware/auth.js +6 -6
- package/dist/middleware/cors-config.js +2 -2
- package/dist/middleware/cors.js +5 -5
- package/dist/middleware/error-handler.js +5 -5
- package/dist/middleware/index.js +15 -15
- package/dist/middleware/middleware-chain.js +4 -4
- package/dist/middleware/rate-limit.js +4 -4
- package/dist/middleware/response-logger.js +4 -4
- package/dist/middleware/security.js +4 -4
- package/dist/middleware/wrappers.js +15 -15
- package/dist/storage/config.js +2 -2
- package/dist/storage/r2-storage.js +2 -2
- package/dist/system/cpu.js +5 -5
- package/dist/system/disk.js +5 -5
- package/dist/system/environment.js +10 -10
- package/dist/system/health-check.js +7 -7
- package/dist/system/index.js +15 -15
- package/dist/system/memory.js +5 -5
- package/dist/system/network.js +5 -5
- package/dist/system/utils.js +4 -4
- package/dist/utils/cors.js +4 -4
- package/dist/utils/csv-export.js +4 -4
- package/dist/utils/error-processor.js +4 -4
- package/dist/utils/index.js +8 -8
- package/package.json +6 -2
- package/dist/{chunk-2VNDWG6P.js → chunk-3CBGGMIY.js} +3 -3
- package/dist/{chunk-SEZJN4TC.js → chunk-5UVEOCRU.js} +6 -6
- package/dist/{chunk-OSNQ3TUX.js → chunk-A2XAOU55.js} +3 -3
- package/dist/{chunk-PL33DK2X.js → chunk-AYZJN32D.js} +3 -3
- package/dist/{chunk-23LXAAMU.js → chunk-GFWGLWTS.js} +3 -3
- package/dist/{chunk-NY5QXT33.js → chunk-I6Q3WUDT.js} +0 -0
- package/dist/{chunk-QKC73SWB.js → chunk-ITGUSYUH.js} +0 -0
- package/dist/{chunk-6O3I4ORK.js → chunk-OHBAELPZ.js} +3 -3
- package/dist/{chunk-XICTHSUH.js → chunk-SFPMFVSD.js} +3 -3
- package/dist/{chunk-AN7GU7PF.js → chunk-UCIUAZQT.js} +3 -3
package/dist/cache/index.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import "../chunk-EBUEBEJX.js";
|
|
2
|
-
import {
|
|
3
|
-
invalidateCache
|
|
4
|
-
} from "../chunk-XKWT6W4K.js";
|
|
5
2
|
import {
|
|
6
3
|
cacheMetrics,
|
|
7
4
|
withCache
|
|
8
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-77BJRPMN.js";
|
|
6
|
+
import {
|
|
7
|
+
invalidateCache
|
|
8
|
+
} from "../chunk-ON7HZ3PW.js";
|
|
9
9
|
import {
|
|
10
10
|
cache,
|
|
11
11
|
geoCache,
|
|
12
12
|
getCacheManager,
|
|
13
13
|
getEffectiveCacheBackend
|
|
14
|
-
} from "../chunk-
|
|
15
|
-
import {
|
|
16
|
-
HybridCacheManager
|
|
17
|
-
} from "../chunk-HHJZTDXL.js";
|
|
18
|
-
import {
|
|
19
|
-
InMemoryCacheManager
|
|
20
|
-
} from "../chunk-7GKSYCKZ.js";
|
|
14
|
+
} from "../chunk-7JKZBEVB.js";
|
|
21
15
|
import {
|
|
22
16
|
NoopCacheManager
|
|
23
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-Q6KXN7HL.js";
|
|
24
18
|
import {
|
|
25
19
|
RedisCacheManager
|
|
26
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-O35V6RIF.js";
|
|
21
|
+
import {
|
|
22
|
+
HybridCacheManager
|
|
23
|
+
} from "../chunk-EXJQKCTN.js";
|
|
27
24
|
import {
|
|
28
25
|
checkRedisConnection,
|
|
29
26
|
getRedisClient,
|
|
@@ -33,26 +30,32 @@ import {
|
|
|
33
30
|
logRedisInitialization,
|
|
34
31
|
notifyRedisError,
|
|
35
32
|
resetRedisGlobalState
|
|
36
|
-
} from "../chunk-
|
|
37
|
-
import
|
|
33
|
+
} from "../chunk-IHUQRVPV.js";
|
|
34
|
+
import {
|
|
35
|
+
InMemoryCacheManager
|
|
36
|
+
} from "../chunk-CW3INZMV.js";
|
|
37
|
+
import "../chunk-TEXVRHPF.js";
|
|
38
38
|
import "../chunk-SS56XFLI.js";
|
|
39
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-OHBAELPZ.js";
|
|
40
40
|
import {
|
|
41
41
|
getCacheConfig,
|
|
42
42
|
getCacheTTL
|
|
43
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-BEV7PQM3.js";
|
|
44
44
|
import {
|
|
45
45
|
getConfig,
|
|
46
46
|
getENV,
|
|
47
47
|
getEnv,
|
|
48
48
|
isCacheEnabled,
|
|
49
49
|
validateRedisEnvironment
|
|
50
|
-
} from "../chunk-
|
|
50
|
+
} from "../chunk-DBHISLC6.js";
|
|
51
|
+
import "../chunk-SFPMFVSD.js";
|
|
51
52
|
import {
|
|
52
53
|
getResolvedCacheConfig,
|
|
53
54
|
initializeCache,
|
|
54
55
|
resetCache
|
|
55
|
-
} from "../chunk-
|
|
56
|
+
} from "../chunk-UCIUAZQT.js";
|
|
57
|
+
import "../chunk-K25ICPU4.js";
|
|
58
|
+
import "../chunk-2QH66EVQ.js";
|
|
56
59
|
import {
|
|
57
60
|
CACHE_DURATION_DEFAULTS,
|
|
58
61
|
CACHE_ENV_VARS,
|
|
@@ -67,9 +70,6 @@ import {
|
|
|
67
70
|
THIRTY_DAYS,
|
|
68
71
|
THIRTY_MINUTES
|
|
69
72
|
} from "../chunk-57W32BFZ.js";
|
|
70
|
-
import "../chunk-XICTHSUH.js";
|
|
71
|
-
import "../chunk-2QH66EVQ.js";
|
|
72
|
-
import "../chunk-K25ICPU4.js";
|
|
73
73
|
import "../chunk-ORMEWXMH.js";
|
|
74
74
|
export {
|
|
75
75
|
CACHE_DURATION_DEFAULTS,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InMemoryCacheManager
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-CW3INZMV.js";
|
|
4
|
+
import "../chunk-TEXVRHPF.js";
|
|
5
5
|
import "../chunk-SS56XFLI.js";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-2QH66EVQ.js";
|
|
6
|
+
import "../chunk-OHBAELPZ.js";
|
|
8
7
|
import "../chunk-K25ICPU4.js";
|
|
8
|
+
import "../chunk-2QH66EVQ.js";
|
|
9
9
|
import "../chunk-ORMEWXMH.js";
|
|
10
10
|
export {
|
|
11
11
|
InMemoryCacheManager
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoopCacheManager
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-XICTHSUH.js";
|
|
9
|
-
import "../chunk-2QH66EVQ.js";
|
|
3
|
+
} from "../chunk-Q6KXN7HL.js";
|
|
4
|
+
import "../chunk-BEV7PQM3.js";
|
|
5
|
+
import "../chunk-DBHISLC6.js";
|
|
6
|
+
import "../chunk-SFPMFVSD.js";
|
|
7
|
+
import "../chunk-UCIUAZQT.js";
|
|
10
8
|
import "../chunk-K25ICPU4.js";
|
|
9
|
+
import "../chunk-2QH66EVQ.js";
|
|
10
|
+
import "../chunk-57W32BFZ.js";
|
|
11
11
|
import "../chunk-ORMEWXMH.js";
|
|
12
12
|
export {
|
|
13
13
|
NoopCacheManager
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RedisCacheManager
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-XICTHSUH.js";
|
|
11
|
-
import "../chunk-2QH66EVQ.js";
|
|
3
|
+
} from "../chunk-O35V6RIF.js";
|
|
4
|
+
import "../chunk-IHUQRVPV.js";
|
|
5
|
+
import "../chunk-TEXVRHPF.js";
|
|
6
|
+
import "../chunk-OHBAELPZ.js";
|
|
7
|
+
import "../chunk-DBHISLC6.js";
|
|
8
|
+
import "../chunk-SFPMFVSD.js";
|
|
9
|
+
import "../chunk-UCIUAZQT.js";
|
|
12
10
|
import "../chunk-K25ICPU4.js";
|
|
11
|
+
import "../chunk-2QH66EVQ.js";
|
|
12
|
+
import "../chunk-57W32BFZ.js";
|
|
13
13
|
import "../chunk-ORMEWXMH.js";
|
|
14
14
|
export {
|
|
15
15
|
RedisCacheManager
|
|
@@ -4,13 +4,13 @@ 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
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-UCIUAZQT.js";
|
|
14
14
|
|
|
15
15
|
// src/system/health-check.ts
|
|
16
16
|
async function checkServiceHealth(prismaClient) {
|
|
@@ -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
|
-
import {
|
|
2
|
-
HybridCacheManager
|
|
3
|
-
} from "./chunk-HHJZTDXL.js";
|
|
4
|
-
import {
|
|
5
|
-
InMemoryCacheManager
|
|
6
|
-
} from "./chunk-7GKSYCKZ.js";
|
|
7
1
|
import {
|
|
8
2
|
NoopCacheManager
|
|
9
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q6KXN7HL.js";
|
|
10
4
|
import {
|
|
11
5
|
RedisCacheManager
|
|
12
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-O35V6RIF.js";
|
|
7
|
+
import {
|
|
8
|
+
HybridCacheManager
|
|
9
|
+
} from "./chunk-EXJQKCTN.js";
|
|
13
10
|
import {
|
|
14
11
|
isRedisAvailableNow,
|
|
15
12
|
isRedisGloballyDisabled
|
|
16
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-IHUQRVPV.js";
|
|
14
|
+
import {
|
|
15
|
+
InMemoryCacheManager
|
|
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() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
logger
|
|
3
|
-
} from "./chunk-L6OEQBOM.js";
|
|
4
1
|
import {
|
|
5
2
|
getCorsConfig
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GFWGLWTS.js";
|
|
4
|
+
import {
|
|
5
|
+
logger
|
|
6
|
+
} from "./chunk-TEXVRHPF.js";
|
|
7
7
|
|
|
8
8
|
// src/middleware/cors.ts
|
|
9
9
|
import { NextResponse } from "next/server";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IPGeolocationProvider
|
|
3
|
+
} from "./chunk-HHCDMWEF.js";
|
|
4
|
+
import {
|
|
5
|
+
MaxMindProvider
|
|
6
|
+
} from "./chunk-G5OMETUS.js";
|
|
1
7
|
import {
|
|
2
8
|
IPApiProvider
|
|
3
9
|
} from "./chunk-DEEJBDJE.js";
|
|
4
10
|
import {
|
|
5
11
|
IPApiCoProvider
|
|
6
12
|
} from "./chunk-VSGKVZB4.js";
|
|
7
|
-
import {
|
|
8
|
-
IPGeolocationProvider
|
|
9
|
-
} from "./chunk-GCR4PGRY.js";
|
|
10
|
-
import {
|
|
11
|
-
MaxMindProvider
|
|
12
|
-
} from "./chunk-LCKQOHXI.js";
|
|
13
13
|
|
|
14
14
|
// src/geolocation/providers/index.ts
|
|
15
15
|
var GeoIPProviderFactory = class {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getResolvedCacheConfig
|
|
3
|
-
} from "./chunk-AN7GU7PF.js";
|
|
4
1
|
import {
|
|
5
2
|
getCommonConfig
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SFPMFVSD.js";
|
|
4
|
+
import {
|
|
5
|
+
getResolvedCacheConfig
|
|
6
|
+
} from "./chunk-UCIUAZQT.js";
|
|
7
7
|
|
|
8
8
|
// src/cache/cache-env.ts
|
|
9
9
|
function _getNodeEnv() {
|
|
@@ -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
|
-
import {
|
|
2
|
-
InMemoryCacheManager
|
|
3
|
-
} from "./chunk-7GKSYCKZ.js";
|
|
4
1
|
import {
|
|
5
2
|
isRedisGloballyDisabled,
|
|
6
3
|
notifyRedisError
|
|
7
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IHUQRVPV.js";
|
|
5
|
+
import {
|
|
6
|
+
InMemoryCacheManager
|
|
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";
|