@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.
Files changed (184) hide show
  1. package/dist/auth/adapters/prisma/index.js +24 -23
  2. package/dist/auth/config.js +2 -2
  3. package/dist/auth/core/jwt/cookie.js +3 -3
  4. package/dist/auth/core/jwt/index.js +3 -3
  5. package/dist/auth/core/jwt/types.js +2 -1
  6. package/dist/auth/core/oauth/index.js +2 -1
  7. package/dist/auth/core/password/client-helper.js +2 -1
  8. package/dist/auth/core/password/index.js +2 -1
  9. package/dist/auth/email/index.d.ts +2 -0
  10. package/dist/auth/email/index.js +7 -0
  11. package/dist/auth/email/sender.d.ts +54 -0
  12. package/dist/auth/email/sender.js +7 -0
  13. package/dist/auth/handlers/forgot-password.handler.d.ts +3 -0
  14. package/dist/auth/handlers/forgot-password.handler.js +12 -0
  15. package/dist/auth/handlers/index.d.ts +25 -0
  16. package/dist/auth/handlers/index.js +79 -0
  17. package/dist/auth/handlers/login.handler.d.ts +3 -0
  18. package/dist/auth/handlers/login.handler.js +13 -0
  19. package/dist/auth/handlers/logout.handler.d.ts +3 -0
  20. package/dist/auth/handlers/logout.handler.js +11 -0
  21. package/dist/auth/handlers/me.handler.d.ts +3 -0
  22. package/dist/auth/handlers/me.handler.js +13 -0
  23. package/dist/auth/handlers/oauth-authorize.handler.d.ts +3 -0
  24. package/dist/auth/handlers/oauth-authorize.handler.js +15 -0
  25. package/dist/auth/handlers/oauth-callback.handler.d.ts +3 -0
  26. package/dist/auth/handlers/oauth-callback.handler.js +21 -0
  27. package/dist/auth/handlers/refresh.handler.d.ts +3 -0
  28. package/dist/auth/handlers/refresh.handler.js +14 -0
  29. package/dist/auth/handlers/register.handler.d.ts +3 -0
  30. package/dist/auth/handlers/register.handler.js +12 -0
  31. package/dist/auth/handlers/reset-password.handler.d.ts +3 -0
  32. package/dist/auth/handlers/reset-password.handler.js +12 -0
  33. package/dist/auth/handlers/verify-email.handler.d.ts +3 -0
  34. package/dist/auth/handlers/verify-email.handler.js +12 -0
  35. package/dist/auth/index.js +21 -20
  36. package/dist/auth/services/email-verification.service.d.ts +18 -0
  37. package/dist/auth/services/email-verification.service.js +11 -0
  38. package/dist/auth/services/index.d.ts +12 -0
  39. package/dist/auth/services/index.js +36 -0
  40. package/dist/auth/services/login.service.d.ts +19 -0
  41. package/dist/auth/services/login.service.js +13 -0
  42. package/dist/auth/services/oauth-callback.service.d.ts +32 -0
  43. package/dist/auth/services/oauth-callback.service.js +13 -0
  44. package/dist/auth/services/password-reset.service.d.ts +20 -0
  45. package/dist/auth/services/password-reset.service.js +11 -0
  46. package/dist/auth/services/register.service.d.ts +28 -0
  47. package/dist/auth/services/register.service.js +11 -0
  48. package/dist/auth/services/token-refresh.service.d.ts +25 -0
  49. package/dist/auth/services/token-refresh.service.js +13 -0
  50. package/dist/auth/types/handler-types.d.ts +68 -0
  51. package/dist/auth/types/handler-types.js +1 -0
  52. package/dist/auth/types/index.d.ts +1 -0
  53. package/dist/auth/types/index.js +2 -1
  54. package/dist/cache/cache-config.js +6 -6
  55. package/dist/cache/cache-env.js +5 -5
  56. package/dist/cache/cache-factory.js +14 -14
  57. package/dist/cache/cache-invalidation.js +15 -15
  58. package/dist/cache/cache-redis.js +8 -8
  59. package/dist/cache/cache-wrapper.js +15 -15
  60. package/dist/cache/cache.js +22 -22
  61. package/dist/cache/config.js +2 -2
  62. package/dist/cache/hybrid-cache-manager.js +10 -10
  63. package/dist/cache/index.js +22 -22
  64. package/dist/cache/inmemory-cache-manager.js +4 -4
  65. package/dist/cache/noop-cache-manager.js +7 -7
  66. package/dist/cache/redis-cache-manager.js +9 -9
  67. package/dist/{chunk-7ZQQ6PJ4.js → chunk-2VMTIYLX.js} +2 -2
  68. package/dist/{chunk-ZX7PHFX3.js → chunk-3AJHXCDG.js} +2 -2
  69. package/dist/{chunk-6YQU2AIK.js → chunk-3ECJUXLM.js} +3 -3
  70. package/dist/{chunk-PEFRPADW.js → chunk-4BGAE7NU.js} +1 -1
  71. package/dist/chunk-4YQ6YBM7.js +50 -0
  72. package/dist/chunk-6B7VU6RZ.js +90 -0
  73. package/dist/chunk-6JY6NUR6.js +38 -0
  74. package/dist/{chunk-YIB6H6P7.js → chunk-77BJRPMN.js} +4 -4
  75. package/dist/{chunk-LTEXLSIE.js → chunk-7JKZBEVB.js} +12 -12
  76. package/dist/{chunk-3TD5OAQS.js → chunk-7KZRPDQD.js} +4 -4
  77. package/dist/{chunk-QHDOMDC6.js → chunk-BEV7PQM3.js} +1 -1
  78. package/dist/{chunk-ZRXE4WSP.js → chunk-CKK55QFQ.js} +1 -1
  79. package/dist/{chunk-PAYLVMZN.js → chunk-CMU52MEQ.js} +6 -6
  80. package/dist/{chunk-MAATEX2R.js → chunk-CRMXLNLC.js} +1 -1
  81. package/dist/{chunk-7GKSYCKZ.js → chunk-CW3INZMV.js} +1 -1
  82. package/dist/{chunk-5FSPXXNB.js → chunk-DBHISLC6.js} +4 -4
  83. package/dist/chunk-DFSNHVXF.js +54 -0
  84. package/dist/chunk-ETMTDHK2.js +53 -0
  85. package/dist/{chunk-HHJZTDXL.js → chunk-EXJQKCTN.js} +6 -6
  86. package/dist/chunk-FI46LV42.js +56 -0
  87. package/dist/{chunk-LX2EYD74.js → chunk-FNECYXI4.js} +10 -10
  88. package/dist/chunk-FRY3TNJ6.js +37 -0
  89. package/dist/{chunk-ZEIFD4OQ.js → chunk-G2Q4TI3Q.js} +1 -1
  90. package/dist/{chunk-LCKQOHXI.js → chunk-G5OMETUS.js} +1 -1
  91. package/dist/chunk-GTPUVHSV.js +30 -0
  92. package/dist/{chunk-GCR4PGRY.js → chunk-HHCDMWEF.js} +1 -1
  93. package/dist/{chunk-ENIKCCAV.js → chunk-IHUQRVPV.js} +2 -2
  94. package/dist/chunk-JQFQT4S2.js +55 -0
  95. package/dist/{chunk-5E66FUBP.js → chunk-KF3O2DAV.js} +1 -1
  96. package/dist/chunk-KY7JZ54O.js +62 -0
  97. package/dist/{chunk-33BG6FPO.js → chunk-L5WLPC2T.js} +1 -1
  98. package/dist/{chunk-YGJJIC6S.js → chunk-LFKPXF5E.js} +4 -4
  99. package/dist/{chunk-DCUQNXVP.js → chunk-MDTID4D2.js} +3 -3
  100. package/dist/{chunk-KHYY4KCV.js → chunk-MEFZZE4M.js} +4 -4
  101. package/dist/chunk-MGQV723O.js +104 -0
  102. package/dist/chunk-N6TMHITU.js +49 -0
  103. package/dist/{chunk-BYHP4EH3.js → chunk-O35V6RIF.js} +3 -3
  104. package/dist/{chunk-2B4EKCV6.js → chunk-OCI7QCLM.js} +2 -2
  105. package/dist/{chunk-XKWT6W4K.js → chunk-ON7HZ3PW.js} +1 -1
  106. package/dist/{chunk-OBNS4ADX.js → chunk-PAF5OGDU.js} +7 -7
  107. package/dist/{chunk-S2O22ULX.js → chunk-PYVYYO4X.js} +7 -7
  108. package/dist/{chunk-ORYZZD5P.js → chunk-Q6KXN7HL.js} +2 -2
  109. package/dist/chunk-Q7VFOUFI.js +68 -0
  110. package/dist/chunk-QYXI45KH.js +62 -0
  111. package/dist/chunk-R4SXQYIT.js +0 -0
  112. package/dist/chunk-S7OQWKUJ.js +83 -0
  113. package/dist/{chunk-UWD5AHWI.js → chunk-SR3SQL72.js} +2 -2
  114. package/dist/{chunk-D7OUX5VJ.js → chunk-SSS6XSEG.js} +1 -1
  115. package/dist/{chunk-L6OEQBOM.js → chunk-TEXVRHPF.js} +1 -1
  116. package/dist/chunk-TFZOOP3V.js +50 -0
  117. package/dist/{chunk-HW732FCA.js → chunk-VCOA6LMN.js} +1 -1
  118. package/dist/{chunk-QWAMNYUT.js → chunk-W2GBKW2T.js} +2 -2
  119. package/dist/chunk-WC2IYFGC.js +51 -0
  120. package/dist/{chunk-XIDMCDD3.js → chunk-WJSMXUZB.js} +1 -1
  121. package/dist/chunk-WNEXLSDB.js +17 -0
  122. package/dist/{chunk-TCQ2DA6Y.js → chunk-WRWWB2NU.js} +4 -4
  123. package/dist/{chunk-IPXPCBDO.js → chunk-WVDYHSHD.js} +1 -1
  124. package/dist/{chunk-4J4D27BV.js → chunk-X6MGVFT3.js} +1 -1
  125. package/dist/chunk-YZXGOOFC.js +0 -0
  126. package/dist/components/ui/DataTable.js +10 -9
  127. package/dist/components/ui/data-table/DataTable.js +9 -9
  128. package/dist/components/ui/data-table/DataTableBulkActions.js +2 -2
  129. package/dist/components/ui/data-table/DataTableFilters.js +3 -3
  130. package/dist/components/ui/data-table/DataTablePagination.js +2 -2
  131. package/dist/components/ui/data-table/DataTableSearch.js +3 -3
  132. package/dist/components/ui/data-table/index.js +42 -0
  133. package/dist/components/ui/data-table/types.js +9 -0
  134. package/dist/config/common.js +2 -2
  135. package/dist/config/registry.d.ts +8 -15
  136. package/dist/config/registry.js +1 -4
  137. package/dist/error/error-handler.js +4 -4
  138. package/dist/error/index.js +4 -4
  139. package/dist/geolocation/batch-processor.js +4 -4
  140. package/dist/geolocation/config.js +2 -2
  141. package/dist/geolocation/index.js +12 -12
  142. package/dist/geolocation/providers/index.js +9 -9
  143. package/dist/geolocation/providers/ipgeolocation-provider.js +3 -3
  144. package/dist/geolocation/providers/maxmind-provider.js +3 -3
  145. package/dist/initialize.d.ts +1 -1
  146. package/dist/initialize.js +15 -17
  147. package/dist/logger/config.js +2 -2
  148. package/dist/logger/logger.js +3 -3
  149. package/dist/middleware/auth.js +6 -6
  150. package/dist/middleware/cors-config.js +2 -2
  151. package/dist/middleware/cors.js +5 -5
  152. package/dist/middleware/error-handler.js +5 -5
  153. package/dist/middleware/index.js +15 -15
  154. package/dist/middleware/middleware-chain.js +4 -4
  155. package/dist/middleware/rate-limit.js +4 -4
  156. package/dist/middleware/response-logger.js +4 -4
  157. package/dist/middleware/security.js +4 -4
  158. package/dist/middleware/wrappers.js +15 -15
  159. package/dist/storage/config.js +2 -2
  160. package/dist/storage/r2-storage.js +2 -2
  161. package/dist/system/cpu.js +5 -5
  162. package/dist/system/disk.js +5 -5
  163. package/dist/system/environment.js +10 -10
  164. package/dist/system/health-check.js +7 -7
  165. package/dist/system/index.js +15 -15
  166. package/dist/system/memory.js +5 -5
  167. package/dist/system/network.js +5 -5
  168. package/dist/system/utils.js +4 -4
  169. package/dist/utils/cors.js +4 -4
  170. package/dist/utils/csv-export.js +4 -4
  171. package/dist/utils/error-processor.js +4 -4
  172. package/dist/utils/index.js +16 -16
  173. package/package.json +6 -2
  174. package/dist/chunk-6PGZTY4N.js +0 -30
  175. package/dist/{chunk-2VNDWG6P.js → chunk-3CBGGMIY.js} +3 -3
  176. package/dist/{chunk-SEZJN4TC.js → chunk-5UVEOCRU.js} +6 -6
  177. package/dist/{chunk-OSNQ3TUX.js → chunk-A2XAOU55.js} +3 -3
  178. package/dist/{chunk-PL33DK2X.js → chunk-AYZJN32D.js} +3 -3
  179. package/dist/{chunk-23LXAAMU.js → chunk-GFWGLWTS.js} +3 -3
  180. package/dist/{chunk-NY5QXT33.js → chunk-I6Q3WUDT.js} +0 -0
  181. package/dist/{chunk-QKC73SWB.js → chunk-ITGUSYUH.js} +0 -0
  182. package/dist/{chunk-6O3I4ORK.js → chunk-OHBAELPZ.js} +3 -3
  183. package/dist/{chunk-XICTHSUH.js → chunk-SFPMFVSD.js} +3 -3
  184. package/dist/{chunk-AN7GU7PF.js → chunk-UCIUAZQT.js} +3 -3
@@ -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-YIB6H6P7.js";
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-LTEXLSIE.js";
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-ORYZZD5P.js";
17
+ } from "../chunk-Q6KXN7HL.js";
24
18
  import {
25
19
  RedisCacheManager
26
- } from "../chunk-BYHP4EH3.js";
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-ENIKCCAV.js";
37
- import "../chunk-L6OEQBOM.js";
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-6O3I4ORK.js";
39
+ import "../chunk-OHBAELPZ.js";
40
40
  import {
41
41
  getCacheConfig,
42
42
  getCacheTTL
43
- } from "../chunk-QHDOMDC6.js";
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-5FSPXXNB.js";
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-AN7GU7PF.js";
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-7GKSYCKZ.js";
4
- import "../chunk-L6OEQBOM.js";
3
+ } from "../chunk-CW3INZMV.js";
4
+ import "../chunk-TEXVRHPF.js";
5
5
  import "../chunk-SS56XFLI.js";
6
- import "../chunk-6O3I4ORK.js";
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-ORYZZD5P.js";
4
- import "../chunk-QHDOMDC6.js";
5
- import "../chunk-5FSPXXNB.js";
6
- import "../chunk-AN7GU7PF.js";
7
- import "../chunk-57W32BFZ.js";
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-BYHP4EH3.js";
4
- import "../chunk-ENIKCCAV.js";
5
- import "../chunk-L6OEQBOM.js";
6
- import "../chunk-6O3I4ORK.js";
7
- import "../chunk-5FSPXXNB.js";
8
- import "../chunk-AN7GU7PF.js";
9
- import "../chunk-57W32BFZ.js";
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
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getCorsConfig
3
- } from "./chunk-23LXAAMU.js";
3
+ } from "./chunk-GFWGLWTS.js";
4
4
  import {
5
5
  getCommonConfig
6
- } from "./chunk-XICTHSUH.js";
6
+ } from "./chunk-SFPMFVSD.js";
7
7
  import {
8
8
  __spreadValues
9
9
  } from "./chunk-ORMEWXMH.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  runCommand,
3
3
  runMacCommand
4
- } from "./chunk-4J4D27BV.js";
4
+ } from "./chunk-X6MGVFT3.js";
5
5
  import {
6
6
  logger
7
- } from "./chunk-L6OEQBOM.js";
7
+ } from "./chunk-TEXVRHPF.js";
8
8
 
9
9
  // src/system/memory.ts
10
10
  import os from "os";
@@ -4,13 +4,13 @@ import {
4
4
  } from "./chunk-YUBXS7YI.js";
5
5
  import {
6
6
  getPlatform
7
- } from "./chunk-4J4D27BV.js";
7
+ } from "./chunk-X6MGVFT3.js";
8
8
  import {
9
9
  logger
10
- } from "./chunk-L6OEQBOM.js";
10
+ } from "./chunk-TEXVRHPF.js";
11
11
  import {
12
12
  getResolvedCacheConfig
13
- } from "./chunk-AN7GU7PF.js";
13
+ } from "./chunk-UCIUAZQT.js";
14
14
 
15
15
  // src/system/health-check.ts
16
16
  async function checkServiceHealth(prismaClient) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-L6OEQBOM.js";
3
+ } from "./chunk-TEXVRHPF.js";
4
4
 
5
5
  // src/middleware/security.ts
6
6
  import { NextResponse } from "next/server";
@@ -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-LTEXLSIE.js";
4
+ } from "./chunk-7JKZBEVB.js";
5
5
  import {
6
6
  logger
7
- } from "./chunk-L6OEQBOM.js";
7
+ } from "./chunk-TEXVRHPF.js";
8
8
  import {
9
9
  getCacheConfig,
10
10
  getCacheTTL
11
- } from "./chunk-QHDOMDC6.js";
11
+ } from "./chunk-BEV7PQM3.js";
12
12
  import {
13
13
  isCacheEnabled
14
- } from "./chunk-5FSPXXNB.js";
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-ORYZZD5P.js";
3
+ } from "./chunk-Q6KXN7HL.js";
10
4
  import {
11
5
  RedisCacheManager
12
- } from "./chunk-BYHP4EH3.js";
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-ENIKCCAV.js";
13
+ } from "./chunk-IHUQRVPV.js";
14
+ import {
15
+ InMemoryCacheManager
16
+ } from "./chunk-CW3INZMV.js";
17
17
  import {
18
18
  logger
19
- } from "./chunk-L6OEQBOM.js";
19
+ } from "./chunk-TEXVRHPF.js";
20
20
  import {
21
21
  getCacheConfig
22
- } from "./chunk-QHDOMDC6.js";
22
+ } from "./chunk-BEV7PQM3.js";
23
23
  import {
24
24
  getENV,
25
25
  isCacheEnabled
26
- } from "./chunk-5FSPXXNB.js";
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-23LXAAMU.js";
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,7 +1,7 @@
1
1
  import {
2
2
  getENV,
3
3
  isCacheEnabled
4
- } from "./chunk-5FSPXXNB.js";
4
+ } from "./chunk-DBHISLC6.js";
5
5
 
6
6
  // src/cache/cache-config.ts
7
7
  var getCacheConfig = {
@@ -2,7 +2,7 @@ import {
2
2
  logApiRequest,
3
3
  logApiResponse,
4
4
  logger
5
- } from "./chunk-L6OEQBOM.js";
5
+ } from "./chunk-TEXVRHPF.js";
6
6
 
7
7
  // src/middleware/response-logger.ts
8
8
  var responseLoggerMiddleware = async (context, next) => {
@@ -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,6 +1,6 @@
1
1
  import {
2
2
  formatLabel
3
- } from "./chunk-NY5QXT33.js";
3
+ } from "./chunk-I6Q3WUDT.js";
4
4
  import {
5
5
  LoadingBar
6
6
  } from "./chunk-34WAGUT5.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-L6OEQBOM.js";
3
+ } from "./chunk-TEXVRHPF.js";
4
4
  import {
5
5
  DEFAULT_INMEMORY_CONFIG
6
6
  } from "./chunk-SS56XFLI.js";
@@ -1,9 +1,9 @@
1
- import {
2
- getResolvedCacheConfig
3
- } from "./chunk-AN7GU7PF.js";
4
1
  import {
5
2
  getCommonConfig
6
- } from "./chunk-XICTHSUH.js";
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-ENIKCCAV.js";
4
+ } from "./chunk-IHUQRVPV.js";
5
+ import {
6
+ InMemoryCacheManager
7
+ } from "./chunk-CW3INZMV.js";
8
8
  import {
9
9
  logger
10
- } from "./chunk-L6OEQBOM.js";
10
+ } from "./chunk-TEXVRHPF.js";
11
11
  import {
12
12
  getCacheFallbackConfig
13
- } from "./chunk-5FSPXXNB.js";
13
+ } from "./chunk-DBHISLC6.js";
14
14
  import {
15
15
  __spreadValues
16
16
  } from "./chunk-ORMEWXMH.js";