@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.
Files changed (161) hide show
  1. package/dist/auth/adapters/prisma/index.js +24 -23
  2. package/dist/auth/config.d.ts +2 -0
  3. package/dist/auth/config.js +1 -1
  4. package/dist/auth/core/jwt/cookie.js +2 -2
  5. package/dist/auth/core/jwt/index.js +2 -2
  6. package/dist/auth/core/jwt/types.js +2 -1
  7. package/dist/auth/core/oauth/index.js +2 -1
  8. package/dist/auth/core/password/client-helper.js +2 -1
  9. package/dist/auth/core/password/index.js +2 -1
  10. package/dist/auth/email/index.d.ts +2 -0
  11. package/dist/auth/email/index.js +7 -0
  12. package/dist/auth/email/sender.d.ts +54 -0
  13. package/dist/auth/email/sender.js +7 -0
  14. package/dist/auth/handlers/forgot-password.handler.d.ts +3 -0
  15. package/dist/auth/handlers/forgot-password.handler.js +12 -0
  16. package/dist/auth/handlers/index.d.ts +25 -0
  17. package/dist/auth/handlers/index.js +79 -0
  18. package/dist/auth/handlers/login.handler.d.ts +3 -0
  19. package/dist/auth/handlers/login.handler.js +13 -0
  20. package/dist/auth/handlers/logout.handler.d.ts +3 -0
  21. package/dist/auth/handlers/logout.handler.js +11 -0
  22. package/dist/auth/handlers/me.handler.d.ts +3 -0
  23. package/dist/auth/handlers/me.handler.js +13 -0
  24. package/dist/auth/handlers/oauth-authorize.handler.d.ts +3 -0
  25. package/dist/auth/handlers/oauth-authorize.handler.js +15 -0
  26. package/dist/auth/handlers/oauth-callback.handler.d.ts +3 -0
  27. package/dist/auth/handlers/oauth-callback.handler.js +21 -0
  28. package/dist/auth/handlers/refresh.handler.d.ts +3 -0
  29. package/dist/auth/handlers/refresh.handler.js +14 -0
  30. package/dist/auth/handlers/register.handler.d.ts +3 -0
  31. package/dist/auth/handlers/register.handler.js +12 -0
  32. package/dist/auth/handlers/reset-password.handler.d.ts +3 -0
  33. package/dist/auth/handlers/reset-password.handler.js +12 -0
  34. package/dist/auth/handlers/verify-email.handler.d.ts +3 -0
  35. package/dist/auth/handlers/verify-email.handler.js +12 -0
  36. package/dist/auth/index.js +19 -18
  37. package/dist/auth/services/email-verification.service.d.ts +18 -0
  38. package/dist/auth/services/email-verification.service.js +11 -0
  39. package/dist/auth/services/index.d.ts +12 -0
  40. package/dist/auth/services/index.js +36 -0
  41. package/dist/auth/services/login.service.d.ts +19 -0
  42. package/dist/auth/services/login.service.js +13 -0
  43. package/dist/auth/services/oauth-callback.service.d.ts +32 -0
  44. package/dist/auth/services/oauth-callback.service.js +13 -0
  45. package/dist/auth/services/password-reset.service.d.ts +20 -0
  46. package/dist/auth/services/password-reset.service.js +11 -0
  47. package/dist/auth/services/register.service.d.ts +28 -0
  48. package/dist/auth/services/register.service.js +11 -0
  49. package/dist/auth/services/token-refresh.service.d.ts +25 -0
  50. package/dist/auth/services/token-refresh.service.js +13 -0
  51. package/dist/auth/types/handler-types.d.ts +68 -0
  52. package/dist/auth/types/handler-types.js +1 -0
  53. package/dist/auth/types/index.d.ts +1 -0
  54. package/dist/auth/types/index.js +2 -1
  55. package/dist/cache/cache-config.js +3 -3
  56. package/dist/cache/cache-env.js +2 -2
  57. package/dist/cache/cache-factory.js +10 -10
  58. package/dist/cache/cache-invalidation.js +11 -11
  59. package/dist/cache/cache-redis.js +4 -4
  60. package/dist/cache/cache-wrapper.js +11 -11
  61. package/dist/cache/cache.js +12 -12
  62. package/dist/cache/hybrid-cache-manager.js +6 -6
  63. package/dist/cache/index.js +12 -12
  64. package/dist/cache/inmemory-cache-manager.js +2 -3
  65. package/dist/cache/noop-cache-manager.js +4 -4
  66. package/dist/cache/redis-cache-manager.js +5 -5
  67. package/dist/{chunk-LFQ3IQQB.js → chunk-3AJHXCDG.js} +2 -2
  68. package/dist/{chunk-N3TAGJHR.js → chunk-3ECJUXLM.js} +2 -2
  69. package/dist/{chunk-WMQE2YK7.js → chunk-4BGAE7NU.js} +1 -1
  70. package/dist/chunk-4YQ6YBM7.js +50 -0
  71. package/dist/chunk-6B7VU6RZ.js +90 -0
  72. package/dist/chunk-6JY6NUR6.js +38 -0
  73. package/dist/{chunk-YSUL3SLC.js → chunk-77BJRPMN.js} +4 -4
  74. package/dist/{chunk-GGSFZP6T.js → chunk-7JKZBEVB.js} +8 -8
  75. package/dist/{chunk-KGHWGLED.js → chunk-7KZRPDQD.js} +1 -1
  76. package/dist/{chunk-OZE5KUS3.js → chunk-A2XAOU55.js} +3 -2
  77. package/dist/{chunk-7LJWRKDT.js → chunk-BEV7PQM3.js} +1 -1
  78. package/dist/{chunk-OIRAH57Y.js → chunk-CKK55QFQ.js} +1 -1
  79. package/dist/{chunk-MAATEX2R.js → chunk-CRMXLNLC.js} +1 -1
  80. package/dist/{chunk-J4TTSXDN.js → chunk-CW3INZMV.js} +1 -1
  81. package/dist/chunk-DFSNHVXF.js +54 -0
  82. package/dist/chunk-ETMTDHK2.js +53 -0
  83. package/dist/{chunk-FUDEEQR3.js → chunk-EXJQKCTN.js} +4 -4
  84. package/dist/chunk-FI46LV42.js +56 -0
  85. package/dist/{chunk-LX2EYD74.js → chunk-FNECYXI4.js} +10 -10
  86. package/dist/chunk-FRY3TNJ6.js +37 -0
  87. package/dist/{chunk-LLVIA4JX.js → chunk-G2Q4TI3Q.js} +5 -5
  88. package/dist/{chunk-X5RMDLLM.js → chunk-IHUQRVPV.js} +2 -2
  89. package/dist/chunk-JQFQT4S2.js +55 -0
  90. package/dist/{chunk-FPESPW6P.js → chunk-KF3O2DAV.js} +1 -1
  91. package/dist/chunk-KY7JZ54O.js +62 -0
  92. package/dist/{chunk-2F6KNGOD.js → chunk-L5WLPC2T.js} +1 -1
  93. package/dist/{chunk-ZBXSEQ6W.js → chunk-LFKPXF5E.js} +4 -4
  94. package/dist/{chunk-L6AU74EI.js → chunk-MDTID4D2.js} +1 -1
  95. package/dist/{chunk-KHYY4KCV.js → chunk-MEFZZE4M.js} +4 -4
  96. package/dist/chunk-MGQV723O.js +104 -0
  97. package/dist/chunk-N6TMHITU.js +49 -0
  98. package/dist/{chunk-NQQU6UFE.js → chunk-O35V6RIF.js} +3 -3
  99. package/dist/{chunk-4HBAPPB2.js → chunk-OCI7QCLM.js} +2 -2
  100. package/dist/{chunk-GFAD4UAT.js → chunk-ON7HZ3PW.js} +1 -1
  101. package/dist/{chunk-O3UR234Y.js → chunk-PAF5OGDU.js} +7 -7
  102. package/dist/{chunk-3J7FDOCU.js → chunk-PYVYYO4X.js} +5 -5
  103. package/dist/{chunk-CRWMULHR.js → chunk-Q6KXN7HL.js} +2 -2
  104. package/dist/chunk-Q7VFOUFI.js +68 -0
  105. package/dist/chunk-QYXI45KH.js +62 -0
  106. package/dist/chunk-R4SXQYIT.js +0 -0
  107. package/dist/chunk-S7OQWKUJ.js +83 -0
  108. package/dist/{chunk-FD2TXDTO.js → chunk-SR3SQL72.js} +2 -2
  109. package/dist/{chunk-JOM3N4EJ.js → chunk-SSS6XSEG.js} +1 -1
  110. package/dist/{chunk-GQVBWZLH.js → chunk-TEXVRHPF.js} +2 -13
  111. package/dist/chunk-TFZOOP3V.js +50 -0
  112. package/dist/{chunk-K3HAYBWX.js → chunk-VCOA6LMN.js} +1 -1
  113. package/dist/{chunk-6SOQUYOU.js → chunk-W2GBKW2T.js} +2 -2
  114. package/dist/chunk-WC2IYFGC.js +51 -0
  115. package/dist/{chunk-AQJAY5FA.js → chunk-WJSMXUZB.js} +1 -1
  116. package/dist/chunk-WNEXLSDB.js +17 -0
  117. package/dist/{chunk-3YUKCYHI.js → chunk-WRWWB2NU.js} +3 -13
  118. package/dist/{chunk-IPXPCBDO.js → chunk-WVDYHSHD.js} +1 -1
  119. package/dist/{chunk-S5UCZ2T3.js → chunk-X6MGVFT3.js} +1 -1
  120. package/dist/chunk-YZXGOOFC.js +0 -0
  121. package/dist/components/ui/DataTable.js +10 -9
  122. package/dist/components/ui/data-table/DataTable.js +9 -9
  123. package/dist/components/ui/data-table/DataTableBulkActions.js +2 -2
  124. package/dist/components/ui/data-table/DataTableFilters.js +3 -3
  125. package/dist/components/ui/data-table/DataTablePagination.js +2 -2
  126. package/dist/components/ui/data-table/DataTableSearch.js +3 -3
  127. package/dist/components/ui/data-table/index.js +42 -0
  128. package/dist/components/ui/data-table/types.js +9 -0
  129. package/dist/error/error-handler.js +2 -3
  130. package/dist/error/index.js +2 -3
  131. package/dist/geolocation/batch-processor.js +2 -3
  132. package/dist/geolocation/index.js +9 -10
  133. package/dist/geolocation/providers/index.js +7 -7
  134. package/dist/initialize.js +4 -4
  135. package/dist/logger/logger.js +1 -2
  136. package/dist/middleware/auth.js +4 -5
  137. package/dist/middleware/cors.js +2 -3
  138. package/dist/middleware/error-handler.js +3 -4
  139. package/dist/middleware/index.js +12 -13
  140. package/dist/middleware/middleware-chain.js +2 -3
  141. package/dist/middleware/rate-limit.js +2 -3
  142. package/dist/middleware/response-logger.js +2 -3
  143. package/dist/middleware/security.js +2 -3
  144. package/dist/middleware/wrappers.js +12 -13
  145. package/dist/system/cpu.js +3 -4
  146. package/dist/system/disk.js +3 -4
  147. package/dist/system/environment.js +5 -5
  148. package/dist/system/health-check.js +3 -4
  149. package/dist/system/index.js +10 -10
  150. package/dist/system/memory.js +3 -4
  151. package/dist/system/network.js +3 -4
  152. package/dist/system/utils.js +2 -3
  153. package/dist/utils/csv-export.js +2 -3
  154. package/dist/utils/error-processor.js +2 -3
  155. package/dist/utils/index.js +3 -3
  156. package/package.json +6 -2
  157. package/dist/{chunk-SEZJN4TC.js → chunk-5UVEOCRU.js} +6 -6
  158. package/dist/{chunk-CUZPD3BF.js → chunk-CMU52MEQ.js} +6 -6
  159. package/dist/{chunk-BJLLMVWW.js → chunk-DBHISLC6.js} +3 -3
  160. /package/dist/{chunk-NY5QXT33.js → chunk-I6Q3WUDT.js} +0 -0
  161. /package/dist/{chunk-QKC73SWB.js → chunk-ITGUSYUH.js} +0 -0
@@ -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
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-GQVBWZLH.js";
3
+ } from "./chunk-TEXVRHPF.js";
4
4
  import {
5
5
  __spreadValues
6
6
  } from "./chunk-ORMEWXMH.js";
@@ -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
+ };
@@ -9,7 +9,7 @@ import {
9
9
  logApiRequest,
10
10
  logApiResponse,
11
11
  logger
12
- } from "./chunk-GQVBWZLH.js";
12
+ } from "./chunk-TEXVRHPF.js";
13
13
 
14
14
  // src/utils/error-processor.ts
15
15
  import { NextResponse } from "next/server";
@@ -4,15 +4,15 @@ import {
4
4
  import {
5
5
  ERROR_CODES
6
6
  } from "./chunk-SNTLJ646.js";
7
- import {
8
- getAuthConfig
9
- } from "./chunk-OZE5KUS3.js";
10
7
  import {
11
8
  JWTManager
12
9
  } from "./chunk-3GAY2T2A.js";
10
+ import {
11
+ getAuthConfig
12
+ } from "./chunk-A2XAOU55.js";
13
13
  import {
14
14
  logger
15
- } from "./chunk-GQVBWZLH.js";
15
+ } from "./chunk-TEXVRHPF.js";
16
16
 
17
17
  // src/middleware/auth.ts
18
18
  function setAccessTokenBlacklistChecker(checker) {
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-AIH3F7JV.js";
13
13
  import {
14
14
  logger
15
- } from "./chunk-GQVBWZLH.js";
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-NY5QXT33.js";
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-X5RMDLLM.js";
6
+ } from "./chunk-IHUQRVPV.js";
7
7
  import {
8
8
  logger
9
- } from "./chunk-GQVBWZLH.js";
9
+ } from "./chunk-TEXVRHPF.js";
10
10
  import {
11
11
  getENV,
12
12
  isCacheEnabled
13
- } from "./chunk-BJLLMVWW.js";
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-S5UCZ2T3.js";
6
+ } from "./chunk-X6MGVFT3.js";
7
7
  import {
8
8
  logger
9
- } from "./chunk-GQVBWZLH.js";
9
+ } from "./chunk-TEXVRHPF.js";
10
10
 
11
11
  // src/system/network.ts
12
12
  async function getNetworkInfo() {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cache,
3
3
  geoCache
4
- } from "./chunk-GGSFZP6T.js";
4
+ } from "./chunk-7JKZBEVB.js";
5
5
 
6
6
  // src/cache/cache-invalidation.ts
7
7
  var invalidateCache = {
@@ -3,27 +3,27 @@ import {
3
3
  } from "./chunk-62Q7DN5G.js";
4
4
  import {
5
5
  MiddlewareChain
6
- } from "./chunk-FPESPW6P.js";
6
+ } from "./chunk-KF3O2DAV.js";
7
7
  import {
8
8
  rateLimitMiddleware
9
- } from "./chunk-AQJAY5FA.js";
9
+ } from "./chunk-WJSMXUZB.js";
10
10
  import {
11
11
  responseLoggerMiddleware
12
- } from "./chunk-OIRAH57Y.js";
12
+ } from "./chunk-CKK55QFQ.js";
13
13
  import {
14
14
  securityMiddleware
15
- } from "./chunk-WMQE2YK7.js";
15
+ } from "./chunk-4BGAE7NU.js";
16
16
  import {
17
17
  adminMiddleware,
18
18
  authMiddleware,
19
19
  optionalAuthMiddleware
20
- } from "./chunk-ZBXSEQ6W.js";
20
+ } from "./chunk-LFKPXF5E.js";
21
21
  import {
22
22
  corsMiddleware
23
- } from "./chunk-KGHWGLED.js";
23
+ } from "./chunk-7KZRPDQD.js";
24
24
  import {
25
25
  errorHandlerMiddleware
26
- } from "./chunk-3YUKCYHI.js";
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-S5UCZ2T3.js";
3
+ } from "./chunk-X6MGVFT3.js";
4
4
  import {
5
5
  getGeolocationConfig
6
6
  } from "./chunk-3CBGGMIY.js";
7
7
  import {
8
8
  getAuthConfig
9
- } from "./chunk-OZE5KUS3.js";
10
- import {
11
- getResolvedCacheConfig
12
- } from "./chunk-UCIUAZQT.js";
9
+ } from "./chunk-A2XAOU55.js";
13
10
  import {
14
11
  getCommonConfig
15
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";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getCacheConfig
3
- } from "./chunk-7LJWRKDT.js";
3
+ } from "./chunk-BEV7PQM3.js";
4
4
  import {
5
5
  getENV
6
- } from "./chunk-BJLLMVWW.js";
6
+ } from "./chunk-DBHISLC6.js";
7
7
 
8
8
  // src/cache/noop-cache-manager.ts
9
9
  var NoopCacheManager = class {
@@ -0,0 +1,68 @@
1
+ import {
2
+ RegisterService
3
+ } from "./chunk-ETMTDHK2.js";
4
+ import {
5
+ AuthError
6
+ } from "./chunk-AIH3F7JV.js";
7
+
8
+ // src/auth/handlers/register.handler.ts
9
+ import { NextResponse } from "next/server";
10
+ import { z } from "zod";
11
+ var registerSchema = z.object({
12
+ email: z.string().email(),
13
+ password: z.string().min(8),
14
+ name: z.string().min(1).optional()
15
+ });
16
+ function createRegisterHandler(options) {
17
+ var _a;
18
+ const { dependencies, hooks, features } = options;
19
+ const registerService = new RegisterService({
20
+ userRepository: dependencies.userRepository,
21
+ emailTokenRepository: dependencies.emailTokenRepository,
22
+ emailSender: dependencies.emailSender,
23
+ emailVerificationRequired: (_a = features == null ? void 0 : features.emailVerificationRequired) != null ? _a : true,
24
+ logger: dependencies.logger
25
+ });
26
+ return async (request) => {
27
+ try {
28
+ const body = await request.json();
29
+ const parsed = registerSchema.safeParse(body);
30
+ if (!parsed.success) {
31
+ return NextResponse.json(
32
+ { success: false, error: "Invalid input", details: parsed.error.flatten() },
33
+ { status: 400 }
34
+ );
35
+ }
36
+ if (hooks == null ? void 0 : hooks.allowEmail) {
37
+ const allowed = await hooks.allowEmail(parsed.data.email);
38
+ if (!allowed) return NextResponse.json({ success: false, error: "Email not allowed" }, { status: 403 });
39
+ }
40
+ if (hooks == null ? void 0 : hooks.onBeforeRegister) {
41
+ const hookResult = await hooks.onBeforeRegister({ email: parsed.data.email, name: parsed.data.name });
42
+ if (hookResult instanceof Response) return hookResult;
43
+ }
44
+ const result = await registerService.register(parsed.data);
45
+ if (hooks == null ? void 0 : hooks.onAfterRegister) await hooks.onAfterRegister(result.user);
46
+ return NextResponse.json(
47
+ {
48
+ success: true,
49
+ user: { id: result.user.id, email: result.user.email, name: result.user.name },
50
+ verificationSent: result.verificationSent
51
+ },
52
+ { status: 201 }
53
+ );
54
+ } catch (error) {
55
+ if (error instanceof AuthError) {
56
+ return NextResponse.json(
57
+ { success: false, error: error.message, code: error.code },
58
+ { status: error.statusCode }
59
+ );
60
+ }
61
+ return NextResponse.json({ success: false, error: "Internal server error" }, { status: 500 });
62
+ }
63
+ };
64
+ }
65
+
66
+ export {
67
+ createRegisterHandler
68
+ };
@@ -0,0 +1,62 @@
1
+ import {
2
+ EmailVerificationService
3
+ } from "./chunk-N6TMHITU.js";
4
+ import {
5
+ AuthError
6
+ } from "./chunk-AIH3F7JV.js";
7
+
8
+ // src/auth/handlers/verify-email.handler.ts
9
+ import { NextResponse } from "next/server";
10
+ import { z } from "zod";
11
+ var schema = z.object({
12
+ email: z.string().email(),
13
+ token: z.string().min(1)
14
+ });
15
+ function createVerifyEmailHandler(options) {
16
+ const { dependencies } = options;
17
+ return async (request) => {
18
+ var _a, _b;
19
+ try {
20
+ let email, token;
21
+ if (request.method === "GET") {
22
+ const url = new URL(request.url);
23
+ email = (_a = url.searchParams.get("email")) != null ? _a : "";
24
+ token = (_b = url.searchParams.get("token")) != null ? _b : "";
25
+ } else {
26
+ const body = await request.json();
27
+ const parsed = schema.safeParse(body);
28
+ if (!parsed.success) {
29
+ return NextResponse.json({ success: false, error: "Invalid input" }, { status: 400 });
30
+ }
31
+ email = parsed.data.email;
32
+ token = parsed.data.token;
33
+ }
34
+ if (!email || !token) {
35
+ return NextResponse.json({ success: false, error: "Missing email or token" }, { status: 400 });
36
+ }
37
+ if (!dependencies.emailSender) {
38
+ return NextResponse.json({ success: false, error: "Email service not configured" }, { status: 500 });
39
+ }
40
+ const service = new EmailVerificationService({
41
+ userRepository: dependencies.userRepository,
42
+ emailTokenRepository: dependencies.emailTokenRepository,
43
+ emailSender: dependencies.emailSender,
44
+ logger: dependencies.logger
45
+ });
46
+ await service.verify(email, token);
47
+ return NextResponse.json({ success: true });
48
+ } catch (error) {
49
+ if (error instanceof AuthError) {
50
+ return NextResponse.json(
51
+ { success: false, error: error.message },
52
+ { status: error.statusCode }
53
+ );
54
+ }
55
+ return NextResponse.json({ success: false, error: "Verification failed" }, { status: 500 });
56
+ }
57
+ };
58
+ }
59
+
60
+ export {
61
+ createVerifyEmailHandler
62
+ };
File without changes
@@ -0,0 +1,83 @@
1
+ import {
2
+ OAuthCallbackService
3
+ } from "./chunk-6B7VU6RZ.js";
4
+ import {
5
+ OAuthManager
6
+ } from "./chunk-HZLJYEOO.js";
7
+ import {
8
+ setTokenCookies
9
+ } from "./chunk-G2Q4TI3Q.js";
10
+ import {
11
+ AuthError
12
+ } from "./chunk-AIH3F7JV.js";
13
+
14
+ // src/auth/handlers/oauth-callback.handler.ts
15
+ import { NextResponse } from "next/server";
16
+ function createOAuthCallbackHandler(options) {
17
+ const { dependencies, jwt, oauth, hooks, cookie, urls } = options;
18
+ const callbackService = new OAuthCallbackService({
19
+ userRepository: dependencies.userRepository,
20
+ oauthAccountRepository: dependencies.oauthAccountRepository,
21
+ jwtSecret: jwt.secret,
22
+ accessTokenExpiry: jwt.accessTokenExpiry,
23
+ refreshTokenExpiry: jwt.refreshTokenExpiry,
24
+ logger: dependencies.logger
25
+ });
26
+ return async (request) => {
27
+ var _a, _b, _c, _d;
28
+ try {
29
+ const url = new URL(request.url);
30
+ const code = url.searchParams.get("code");
31
+ const provider = (_a = url.searchParams.get("provider")) != null ? _a : url.pathname.split("/").pop();
32
+ if (!code || !provider || !(oauth == null ? void 0 : oauth[provider])) {
33
+ return NextResponse.json({ success: false, error: "Invalid callback" }, { status: 400 });
34
+ }
35
+ const providers = {};
36
+ for (const [name, config] of Object.entries(oauth)) {
37
+ providers[name] = config;
38
+ }
39
+ const noopLogger = { debug() {
40
+ }, info() {
41
+ }, warn() {
42
+ }, error() {
43
+ } };
44
+ const manager = new OAuthManager({ providers }, (_b = dependencies.logger) != null ? _b : noopLogger);
45
+ const accessToken = await manager.exchangeCodeForToken(provider, code);
46
+ const userInfo = await manager.getUserInfo(provider, accessToken);
47
+ if (hooks == null ? void 0 : hooks.allowEmail) {
48
+ const allowed = await hooks.allowEmail(userInfo.email);
49
+ if (!allowed) return NextResponse.json({ success: false, error: "Email not allowed" }, { status: 403 });
50
+ }
51
+ const result = await callbackService.handleCallback({
52
+ provider,
53
+ providerAccountId: userInfo.id,
54
+ email: userInfo.email,
55
+ name: userInfo.name,
56
+ image: userInfo.image,
57
+ accessToken
58
+ });
59
+ if (hooks == null ? void 0 : hooks.onAfterOAuth) await hooks.onAfterOAuth(result.user, provider, result.isNewUser);
60
+ if (result.isNewUser && (hooks == null ? void 0 : hooks.onOAuthFirstLogin)) {
61
+ const redirect = await hooks.onOAuthFirstLogin(result.user, provider);
62
+ if (redirect) {
63
+ const response2 = NextResponse.redirect(redirect);
64
+ setTokenCookies(response2, result.tokens, { secure: cookie == null ? void 0 : cookie.secure });
65
+ return response2;
66
+ }
67
+ }
68
+ const redirectUrl = (_d = (_c = urls.afterOAuth) != null ? _c : urls.afterLogin) != null ? _d : "/";
69
+ const response = NextResponse.redirect(new URL(redirectUrl, urls.baseUrl));
70
+ setTokenCookies(response, result.tokens, { secure: cookie == null ? void 0 : cookie.secure });
71
+ return response;
72
+ } catch (error) {
73
+ if (error instanceof AuthError) {
74
+ return NextResponse.json({ success: false, error: error.message }, { status: error.statusCode });
75
+ }
76
+ return NextResponse.json({ success: false, error: "OAuth callback failed" }, { status: 500 });
77
+ }
78
+ };
79
+ }
80
+
81
+ export {
82
+ createOAuthCallbackHandler
83
+ };