@withwiz/toolkit 0.5.2 → 0.6.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.
- 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-GTPUVHSV.js +30 -0
- 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/config/registry.d.ts +8 -15
- package/dist/config/registry.js +1 -4
- 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.d.ts +1 -1
- package/dist/initialize.js +15 -17
- 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 +16 -16
- package/package.json +6 -2
- package/dist/chunk-6PGZTY4N.js +0 -30
- 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
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/config/registry.ts
|
|
2
|
+
var MODULE_KEYS = {
|
|
3
|
+
common: "__withwiz_common_config",
|
|
4
|
+
auth: "__withwiz_auth_config",
|
|
5
|
+
logger: "__withwiz_logger_config",
|
|
6
|
+
cache: "__withwiz_cache_config",
|
|
7
|
+
storage: "__withwiz_storage_config",
|
|
8
|
+
geolocation: "__withwiz_geolocation_config",
|
|
9
|
+
cors: "__withwiz_cors_config"
|
|
10
|
+
};
|
|
11
|
+
var config = new Proxy({}, {
|
|
12
|
+
get(_target, prop) {
|
|
13
|
+
const globalKey = MODULE_KEYS[prop];
|
|
14
|
+
if (!globalKey) return void 0;
|
|
15
|
+
return globalThis[globalKey];
|
|
16
|
+
},
|
|
17
|
+
set() {
|
|
18
|
+
throw new TypeError("config is read-only");
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function resetConfig() {
|
|
22
|
+
for (const globalKey of Object.values(MODULE_KEYS)) {
|
|
23
|
+
globalThis[globalKey] = void 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
config,
|
|
29
|
+
resetConfig
|
|
30
|
+
};
|
|
@@ -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";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JWTService
|
|
3
|
+
} from "./chunk-3GAY2T2A.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthError
|
|
6
|
+
} from "./chunk-AIH3F7JV.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/services/token-refresh.service.ts
|
|
9
|
+
var TokenRefreshService = class {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
this.userRepo = config.userRepository;
|
|
13
|
+
this.jwtService = new JWTService({
|
|
14
|
+
secret: config.jwtSecret,
|
|
15
|
+
accessTokenExpiry: (_a = config.accessTokenExpiry) != null ? _a : "7d",
|
|
16
|
+
refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d",
|
|
17
|
+
algorithm: "HS256"
|
|
18
|
+
}, config.logger);
|
|
19
|
+
this.isTokenBlacklisted = config.isTokenBlacklisted;
|
|
20
|
+
this.logger = (_c = config.logger) != null ? _c : { debug() {
|
|
21
|
+
}, info() {
|
|
22
|
+
}, warn() {
|
|
23
|
+
}, error() {
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
async refresh(refreshToken) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (this.isTokenBlacklisted) {
|
|
29
|
+
const blacklisted = await this.isTokenBlacklisted(refreshToken);
|
|
30
|
+
if (blacklisted) {
|
|
31
|
+
throw new AuthError("Token has been revoked", "TOKEN_REVOKED", 401);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const { userId } = await this.jwtService.verifyRefreshToken(refreshToken);
|
|
35
|
+
const user = await this.userRepo.findById(userId);
|
|
36
|
+
if (!user) {
|
|
37
|
+
throw new AuthError("User not found", "USER_NOT_FOUND", 401);
|
|
38
|
+
}
|
|
39
|
+
if (user.isActive === false) {
|
|
40
|
+
throw new AuthError("Account is disabled", "ACCOUNT_DISABLED", 403);
|
|
41
|
+
}
|
|
42
|
+
const accessToken = await this.jwtService.createAccessToken({
|
|
43
|
+
id: user.id,
|
|
44
|
+
userId: user.id,
|
|
45
|
+
email: user.email,
|
|
46
|
+
role: (_a = user.role) != null ? _a : "USER",
|
|
47
|
+
emailVerified: user.emailVerified
|
|
48
|
+
});
|
|
49
|
+
return { accessToken, user: { id: user.id, email: user.email, role: (_b = user.role) != null ? _b : "USER" } };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
TokenRefreshService
|
|
55
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-ORMEWXMH.js";
|
|
4
|
+
|
|
5
|
+
// src/auth/email/sender.ts
|
|
6
|
+
var SmtpEmailSender = class {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.templates = __spreadValues(__spreadValues({}, getDefaultTemplates()), config.templates);
|
|
10
|
+
}
|
|
11
|
+
async sendVerificationEmail(email, token) {
|
|
12
|
+
const { subject, html } = this.templates.verification({ email, token, baseUrl: this.config.baseUrl });
|
|
13
|
+
await this.send(email, subject, html);
|
|
14
|
+
}
|
|
15
|
+
async sendPasswordResetEmail(email, token) {
|
|
16
|
+
const { subject, html } = this.templates.passwordReset({ email, token, baseUrl: this.config.baseUrl });
|
|
17
|
+
await this.send(email, subject, html);
|
|
18
|
+
}
|
|
19
|
+
async sendMagicLinkEmail(email, token) {
|
|
20
|
+
const { subject, html } = this.templates.magicLink({ email, token, baseUrl: this.config.baseUrl });
|
|
21
|
+
await this.send(email, subject, html);
|
|
22
|
+
}
|
|
23
|
+
async sendWelcomeEmail(email, name) {
|
|
24
|
+
const { subject, html } = this.templates.welcome({ email, name });
|
|
25
|
+
await this.send(email, subject, html);
|
|
26
|
+
}
|
|
27
|
+
async send(to, subject, html) {
|
|
28
|
+
var _a;
|
|
29
|
+
const nodemailer = await import("nodemailer");
|
|
30
|
+
const transport = nodemailer.createTransport({
|
|
31
|
+
host: this.config.host,
|
|
32
|
+
port: this.config.port,
|
|
33
|
+
secure: (_a = this.config.secure) != null ? _a : this.config.port === 465,
|
|
34
|
+
auth: { user: this.config.user, pass: this.config.pass }
|
|
35
|
+
});
|
|
36
|
+
await transport.sendMail({ from: this.config.from, to, subject, html });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function getDefaultTemplates() {
|
|
40
|
+
return {
|
|
41
|
+
verification: ({ email, token, baseUrl }) => ({
|
|
42
|
+
subject: "Verify your email",
|
|
43
|
+
html: `<p>Click the link to verify your email:</p><a href="${baseUrl}/verify-email?email=${encodeURIComponent(email)}&token=${token}">Verify Email</a>`
|
|
44
|
+
}),
|
|
45
|
+
passwordReset: ({ email, token, baseUrl }) => ({
|
|
46
|
+
subject: "Reset your password",
|
|
47
|
+
html: `<p>Click the link to reset your password:</p><a href="${baseUrl}/reset-password?email=${encodeURIComponent(email)}&token=${token}">Reset Password</a>`
|
|
48
|
+
}),
|
|
49
|
+
magicLink: ({ email, token, baseUrl }) => ({
|
|
50
|
+
subject: "Your login link",
|
|
51
|
+
html: `<p>Click the link to sign in:</p><a href="${baseUrl}/auth/magic-link?email=${encodeURIComponent(email)}&token=${token}">Sign In</a>`
|
|
52
|
+
}),
|
|
53
|
+
welcome: ({ name }) => ({
|
|
54
|
+
subject: "Welcome!",
|
|
55
|
+
html: `<p>Hi ${name}, welcome to our platform!</p>`
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
SmtpEmailSender
|
|
62
|
+
};
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
ERROR_CODES
|
|
6
6
|
} from "./chunk-SNTLJ646.js";
|
|
7
|
-
import {
|
|
8
|
-
logger
|
|
9
|
-
} from "./chunk-L6OEQBOM.js";
|
|
10
7
|
import {
|
|
11
8
|
JWTManager
|
|
12
9
|
} from "./chunk-3GAY2T2A.js";
|
|
13
10
|
import {
|
|
14
11
|
getAuthConfig
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-A2XAOU55.js";
|
|
13
|
+
import {
|
|
14
|
+
logger
|
|
15
|
+
} from "./chunk-TEXVRHPF.js";
|
|
16
16
|
|
|
17
17
|
// src/middleware/auth.ts
|
|
18
18
|
function setAccessTokenBlacklistChecker(checker) {
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
formatErrorMessage,
|
|
8
8
|
getHttpStatus
|
|
9
9
|
} from "./chunk-SNTLJ646.js";
|
|
10
|
-
import {
|
|
11
|
-
logger
|
|
12
|
-
} from "./chunk-L6OEQBOM.js";
|
|
13
10
|
import {
|
|
14
11
|
AuthError
|
|
15
12
|
} from "./chunk-AIH3F7JV.js";
|
|
13
|
+
import {
|
|
14
|
+
logger
|
|
15
|
+
} from "./chunk-TEXVRHPF.js";
|
|
16
16
|
import {
|
|
17
17
|
__spreadProps,
|
|
18
18
|
__spreadValues
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatLabel
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
Input
|
|
6
|
-
} from "./chunk-RJUVBBZG.js";
|
|
3
|
+
} from "./chunk-I6Q3WUDT.js";
|
|
7
4
|
import {
|
|
8
5
|
Button
|
|
9
6
|
} from "./chunk-L25BNU3E.js";
|
|
7
|
+
import {
|
|
8
|
+
Input
|
|
9
|
+
} from "./chunk-RJUVBBZG.js";
|
|
10
10
|
|
|
11
11
|
// src/components/ui/data-table/DataTableSearch.tsx
|
|
12
12
|
import { isValidElement } from "react";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JWTService
|
|
3
|
+
} from "./chunk-3GAY2T2A.js";
|
|
4
|
+
import {
|
|
5
|
+
setTokenCookies
|
|
6
|
+
} from "./chunk-G2Q4TI3Q.js";
|
|
7
|
+
import {
|
|
8
|
+
AuthError
|
|
9
|
+
} from "./chunk-AIH3F7JV.js";
|
|
10
|
+
import {
|
|
11
|
+
__spreadValues
|
|
12
|
+
} from "./chunk-ORMEWXMH.js";
|
|
13
|
+
|
|
14
|
+
// src/auth/handlers/login.handler.ts
|
|
15
|
+
import { NextResponse } from "next/server";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { compare } from "bcryptjs";
|
|
18
|
+
var loginSchema = z.object({
|
|
19
|
+
email: z.string().email(),
|
|
20
|
+
password: z.string().min(1)
|
|
21
|
+
});
|
|
22
|
+
function createLoginHandler(options) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const { dependencies, jwt, hooks, features, cookie } = options;
|
|
25
|
+
const jwtService = new JWTService({
|
|
26
|
+
secret: jwt.secret,
|
|
27
|
+
accessTokenExpiry: (_a = jwt.accessTokenExpiry) != null ? _a : "7d",
|
|
28
|
+
refreshTokenExpiry: (_b = jwt.refreshTokenExpiry) != null ? _b : "30d",
|
|
29
|
+
algorithm: "HS256"
|
|
30
|
+
});
|
|
31
|
+
return async (request) => {
|
|
32
|
+
var _a2;
|
|
33
|
+
try {
|
|
34
|
+
const body = await request.json();
|
|
35
|
+
const parsed = loginSchema.safeParse(body);
|
|
36
|
+
if (!parsed.success) {
|
|
37
|
+
return NextResponse.json({ success: false, error: "Invalid input" }, { status: 400 });
|
|
38
|
+
}
|
|
39
|
+
const { email, password } = parsed.data;
|
|
40
|
+
if (hooks == null ? void 0 : hooks.allowEmail) {
|
|
41
|
+
const allowed = await hooks.allowEmail(email);
|
|
42
|
+
if (!allowed) return NextResponse.json({ success: false, error: "Email not allowed" }, { status: 403 });
|
|
43
|
+
}
|
|
44
|
+
if (hooks == null ? void 0 : hooks.onBeforeLogin) {
|
|
45
|
+
const hookResult = await hooks.onBeforeLogin(email, request);
|
|
46
|
+
if (hookResult instanceof Response) return hookResult;
|
|
47
|
+
}
|
|
48
|
+
const user = await dependencies.userRepository.findByEmail(email);
|
|
49
|
+
if (!user) {
|
|
50
|
+
return NextResponse.json({ success: false, error: "Invalid credentials" }, { status: 401 });
|
|
51
|
+
}
|
|
52
|
+
if (user.isActive === false) {
|
|
53
|
+
return NextResponse.json({ success: false, error: "Account disabled" }, { status: 403 });
|
|
54
|
+
}
|
|
55
|
+
const userRecord = user;
|
|
56
|
+
if (!userRecord.password) {
|
|
57
|
+
return NextResponse.json({ success: false, error: "Invalid credentials" }, { status: 401 });
|
|
58
|
+
}
|
|
59
|
+
const isValid = await compare(password, userRecord.password);
|
|
60
|
+
if (!isValid) {
|
|
61
|
+
return NextResponse.json({ success: false, error: "Invalid credentials" }, { status: 401 });
|
|
62
|
+
}
|
|
63
|
+
if ((features == null ? void 0 : features.emailVerificationRequired) && !user.emailVerified) {
|
|
64
|
+
return NextResponse.json(
|
|
65
|
+
{ success: false, error: "Email not verified", code: "EMAIL_NOT_VERIFIED" },
|
|
66
|
+
{ status: 403 }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const tokens = await jwtService.createTokenPair({
|
|
70
|
+
id: user.id,
|
|
71
|
+
email: user.email,
|
|
72
|
+
role: (_a2 = user.role) != null ? _a2 : "USER",
|
|
73
|
+
emailVerified: user.emailVerified
|
|
74
|
+
});
|
|
75
|
+
await dependencies.userRepository.updateLastLoginAt(user.id);
|
|
76
|
+
if (hooks == null ? void 0 : hooks.onAfterLogin) await hooks.onAfterLogin(user, request);
|
|
77
|
+
let userResponse = {
|
|
78
|
+
id: user.id,
|
|
79
|
+
email: user.email,
|
|
80
|
+
name: user.name,
|
|
81
|
+
role: user.role,
|
|
82
|
+
emailVerified: user.emailVerified
|
|
83
|
+
};
|
|
84
|
+
if (hooks == null ? void 0 : hooks.extendUserResponse) {
|
|
85
|
+
userResponse = __spreadValues(__spreadValues({}, userResponse), await hooks.extendUserResponse(user));
|
|
86
|
+
}
|
|
87
|
+
const response = NextResponse.json({ success: true, user: userResponse, tokens });
|
|
88
|
+
setTokenCookies(response, tokens, { secure: cookie == null ? void 0 : cookie.secure });
|
|
89
|
+
return response;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof AuthError) {
|
|
92
|
+
return NextResponse.json(
|
|
93
|
+
{ success: false, error: error.message, code: error.code },
|
|
94
|
+
{ status: error.statusCode }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return NextResponse.json({ success: false, error: "Internal server error" }, { status: 500 });
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
createLoginHandler
|
|
104
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TokenGenerator
|
|
3
|
+
} from "./chunk-GDWEDUHO.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthError
|
|
6
|
+
} from "./chunk-AIH3F7JV.js";
|
|
7
|
+
|
|
8
|
+
// src/auth/services/email-verification.service.ts
|
|
9
|
+
var EmailVerificationService = class {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
this.userRepo = config.userRepository;
|
|
13
|
+
this.tokenRepo = config.emailTokenRepository;
|
|
14
|
+
this.emailSender = config.emailSender;
|
|
15
|
+
this.tokenExpiryHours = (_a = config.tokenExpiryHours) != null ? _a : 24;
|
|
16
|
+
this.logger = (_b = config.logger) != null ? _b : { debug() {
|
|
17
|
+
}, info() {
|
|
18
|
+
}, warn() {
|
|
19
|
+
}, error() {
|
|
20
|
+
} };
|
|
21
|
+
}
|
|
22
|
+
async verify(email, token) {
|
|
23
|
+
const tokenRecord = await this.tokenRepo.findByEmailAndToken(email, token, "EMAIL_VERIFICATION" /* EMAIL_VERIFICATION */);
|
|
24
|
+
if (!tokenRecord || tokenRecord.expires < /* @__PURE__ */ new Date()) {
|
|
25
|
+
throw new AuthError("Invalid or expired verification token", "TOKEN_INVALID", 400);
|
|
26
|
+
}
|
|
27
|
+
await this.userRepo.verifyEmail(email);
|
|
28
|
+
await this.tokenRepo.delete(email, token, "EMAIL_VERIFICATION" /* EMAIL_VERIFICATION */);
|
|
29
|
+
this.logger.info("Email verified", { email });
|
|
30
|
+
}
|
|
31
|
+
async resend(email) {
|
|
32
|
+
const user = await this.userRepo.findByEmail(email);
|
|
33
|
+
if (!user) {
|
|
34
|
+
throw new AuthError("User not found", "USER_NOT_FOUND", 404);
|
|
35
|
+
}
|
|
36
|
+
if (user.emailVerified) {
|
|
37
|
+
throw new AuthError("Email already verified", "EMAIL_ALREADY_VERIFIED", 400);
|
|
38
|
+
}
|
|
39
|
+
const token = TokenGenerator.generate();
|
|
40
|
+
const expires = new Date(Date.now() + this.tokenExpiryHours * 60 * 60 * 1e3);
|
|
41
|
+
await this.tokenRepo.create(email, token, "EMAIL_VERIFICATION" /* EMAIL_VERIFICATION */, expires);
|
|
42
|
+
await this.emailSender.sendVerificationEmail(email, token);
|
|
43
|
+
this.logger.info("Verification email resent", { email });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
EmailVerificationService
|
|
49
|
+
};
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
isRedisGloballyDisabled,
|
|
4
4
|
notifyRedisError,
|
|
5
5
|
resetRedisGlobalState
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-IHUQRVPV.js";
|
|
7
7
|
import {
|
|
8
8
|
logger
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TEXVRHPF.js";
|
|
10
10
|
import {
|
|
11
11
|
getENV,
|
|
12
12
|
isCacheEnabled
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-DBHISLC6.js";
|
|
14
14
|
import {
|
|
15
15
|
__spreadValues
|
|
16
16
|
} from "./chunk-ORMEWXMH.js";
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
formatBytesPerSec,
|
|
4
4
|
runCommand,
|
|
5
5
|
runMacCommand
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-X6MGVFT3.js";
|
|
7
7
|
import {
|
|
8
8
|
logger
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TEXVRHPF.js";
|
|
10
10
|
|
|
11
11
|
// src/system/network.ts
|
|
12
12
|
async function getNetworkInfo() {
|
|
@@ -3,27 +3,27 @@ import {
|
|
|
3
3
|
} from "./chunk-62Q7DN5G.js";
|
|
4
4
|
import {
|
|
5
5
|
MiddlewareChain
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KF3O2DAV.js";
|
|
7
7
|
import {
|
|
8
8
|
rateLimitMiddleware
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WJSMXUZB.js";
|
|
10
10
|
import {
|
|
11
11
|
responseLoggerMiddleware
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CKK55QFQ.js";
|
|
13
13
|
import {
|
|
14
14
|
securityMiddleware
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4BGAE7NU.js";
|
|
16
16
|
import {
|
|
17
17
|
adminMiddleware,
|
|
18
18
|
authMiddleware,
|
|
19
19
|
optionalAuthMiddleware
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LFKPXF5E.js";
|
|
21
21
|
import {
|
|
22
22
|
corsMiddleware
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-7KZRPDQD.js";
|
|
24
24
|
import {
|
|
25
25
|
errorHandlerMiddleware
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WRWWB2NU.js";
|
|
27
27
|
|
|
28
28
|
// src/middleware/wrappers.ts
|
|
29
29
|
function withPublicApi(handler) {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPlatform
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-X6MGVFT3.js";
|
|
4
4
|
import {
|
|
5
5
|
getGeolocationConfig
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3CBGGMIY.js";
|
|
7
7
|
import {
|
|
8
8
|
getAuthConfig
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import {
|
|
11
|
-
getResolvedCacheConfig
|
|
12
|
-
} from "./chunk-AN7GU7PF.js";
|
|
9
|
+
} from "./chunk-A2XAOU55.js";
|
|
13
10
|
import {
|
|
14
11
|
getCommonConfig
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-SFPMFVSD.js";
|
|
13
|
+
import {
|
|
14
|
+
getResolvedCacheConfig
|
|
15
|
+
} from "./chunk-UCIUAZQT.js";
|
|
16
16
|
|
|
17
17
|
// src/system/environment.ts
|
|
18
18
|
import os from "os";
|