@withwiz/toolkit 0.2.8 → 0.3.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 (122) hide show
  1. package/dist/auth/config.d.ts +16 -0
  2. package/dist/auth/config.js +13 -0
  3. package/dist/auth/index.js +18 -18
  4. package/dist/cache/cache-config.js +6 -3
  5. package/dist/cache/cache-env.d.ts +11 -20
  6. package/dist/cache/cache-env.js +5 -6
  7. package/dist/cache/cache-factory.js +15 -10
  8. package/dist/cache/cache-invalidation.js +15 -10
  9. package/dist/cache/cache-redis.js +8 -3
  10. package/dist/cache/cache-wrapper.js +15 -10
  11. package/dist/cache/cache.js +32 -24
  12. package/dist/cache/config.d.ts +116 -0
  13. package/dist/cache/config.js +13 -0
  14. package/dist/cache/hybrid-cache-manager.js +10 -5
  15. package/dist/cache/index.d.ts +2 -1
  16. package/dist/cache/index.js +32 -24
  17. package/dist/cache/inmemory-cache-manager.js +6 -2
  18. package/dist/cache/noop-cache-manager.js +7 -4
  19. package/dist/cache/redis-cache-manager.js +9 -4
  20. package/dist/{chunk-JWZSWMOM.js → chunk-2KDLKHTO.js} +1 -1
  21. package/dist/chunk-2QH66EVQ.js +11 -0
  22. package/dist/chunk-3CBGGMIY.js +39 -0
  23. package/dist/{chunk-67KRDPIH.js → chunk-4HBAPPB2.js} +2 -2
  24. package/dist/{chunk-QMZ75GBU.js → chunk-6MI4XLWC.js} +1 -1
  25. package/dist/{chunk-BX5CNRVS.js → chunk-6SOQUYOU.js} +2 -2
  26. package/dist/{chunk-YVF4RXOK.js → chunk-7IN4WRSO.js} +15 -15
  27. package/dist/{chunk-I5PCM2JQ.js → chunk-AXCB7SKY.js} +4 -4
  28. package/dist/chunk-AYZJN32D.js +45 -0
  29. package/dist/{chunk-74MSBKYW.js → chunk-BDY3AOX5.js} +14 -10
  30. package/dist/{chunk-IT43YQND.js → chunk-BYCFXGQL.js} +20 -5
  31. package/dist/{chunk-QF6FH4GZ.js → chunk-CUZPD3BF.js} +5 -5
  32. package/dist/{chunk-JOGXLVUZ.js → chunk-E54MAI4I.js} +1 -1
  33. package/dist/{chunk-WEDR5GJO.js → chunk-FD2TXDTO.js} +2 -2
  34. package/dist/{chunk-HOMWLK62.js → chunk-FDRIFPG6.js} +2 -2
  35. package/dist/{chunk-AOZVTVJG.js → chunk-FPESPW6P.js} +1 -1
  36. package/dist/{chunk-4NWJ3WCZ.js → chunk-G5OMETUS.js} +8 -1
  37. package/dist/chunk-GFWGLWTS.js +48 -0
  38. package/dist/{chunk-5A2L6TXD.js → chunk-GQVBWZLH.js} +34 -15
  39. package/dist/{chunk-DH2ZHGW2.js → chunk-HHCDMWEF.js} +14 -2
  40. package/dist/{chunk-Y6IHEA3Q.js → chunk-J4TTSXDN.js} +3 -3
  41. package/dist/{chunk-WZDS4QEC.js → chunk-JOM3N4EJ.js} +1 -1
  42. package/dist/{chunk-WSUFD4SO.js → chunk-JR7GVCQX.js} +11 -3
  43. package/dist/chunk-K25ICPU4.js +8 -0
  44. package/dist/{chunk-T3YUJYBX.js → chunk-K3HAYBWX.js} +1 -1
  45. package/dist/{chunk-WDJLAZCW.js → chunk-KGHWGLED.js} +18 -3
  46. package/dist/{chunk-XN4YP4XO.js → chunk-KZUBO2IL.js} +5 -5
  47. package/dist/{chunk-3GEQQ4VL.js → chunk-LD7POV6B.js} +10 -10
  48. package/dist/{chunk-7KCWVRPR.js → chunk-LFQ3IQQB.js} +2 -2
  49. package/dist/{chunk-RPWEGUUS.js → chunk-LX2EYD74.js} +8 -8
  50. package/dist/{chunk-HCTNZM7D.js → chunk-O7CK3CKJ.js} +1 -1
  51. package/dist/chunk-OHBAELPZ.js +46 -0
  52. package/dist/{chunk-M5LIX3TD.js → chunk-OIRAH57Y.js} +1 -1
  53. package/dist/chunk-OZE5KUS3.js +50 -0
  54. package/dist/{chunk-NJXCFTOE.js → chunk-QVWDWROP.js} +1 -1
  55. package/dist/{chunk-YMIDD4YE.js → chunk-RWVGJUON.js} +6 -6
  56. package/dist/{chunk-6WVKLXVT.js → chunk-S5UCZ2T3.js} +1 -1
  57. package/dist/chunk-SFPMFVSD.js +40 -0
  58. package/dist/{chunk-R5OFGX3C.js → chunk-SV7X6HEN.js} +6 -6
  59. package/dist/chunk-TFD3DSM2.js +110 -0
  60. package/dist/{chunk-GCZOXUDV.js → chunk-TO5CMMQC.js} +50 -10
  61. package/dist/{chunk-LEWQBXN6.js → chunk-VF4EVAMV.js} +1 -1
  62. package/dist/chunk-WNF2RKFA.js +122 -0
  63. package/dist/chunk-XI4MRH5P.js +156 -0
  64. package/dist/components/ui/DataTable.js +5 -5
  65. package/dist/components/ui/data-table/DataTable.js +5 -5
  66. package/dist/components/ui/data-table/DataTableFilters.js +2 -2
  67. package/dist/components/ui/data-table/DataTableSearch.js +2 -2
  68. package/dist/config/common.d.ts +12 -0
  69. package/dist/config/common.js +13 -0
  70. package/dist/config/errors.d.ts +3 -0
  71. package/dist/config/errors.js +7 -0
  72. package/dist/config/warn.d.ts +4 -0
  73. package/dist/config/warn.js +7 -0
  74. package/dist/constants/index.js +13 -13
  75. package/dist/error/error-handler.js +6 -2
  76. package/dist/error/index.js +6 -2
  77. package/dist/geolocation/batch-processor.js +6 -2
  78. package/dist/geolocation/config.d.ts +14 -0
  79. package/dist/geolocation/config.js +13 -0
  80. package/dist/geolocation/index.js +13 -8
  81. package/dist/geolocation/providers/index.js +9 -6
  82. package/dist/geolocation/providers/ipgeolocation-provider.js +4 -1
  83. package/dist/geolocation/providers/maxmind-provider.js +4 -1
  84. package/dist/initialize.d.ts +18 -0
  85. package/dist/initialize.js +41 -0
  86. package/dist/logger/config.d.ts +20 -0
  87. package/dist/logger/config.js +13 -0
  88. package/dist/logger/logger.js +5 -1
  89. package/dist/middleware/auth.js +7 -2
  90. package/dist/middleware/cors-config.d.ts +14 -0
  91. package/dist/middleware/cors-config.js +13 -0
  92. package/dist/middleware/cors.js +7 -2
  93. package/dist/middleware/error-handler.js +7 -3
  94. package/dist/middleware/index.js +19 -13
  95. package/dist/middleware/middleware-chain.js +6 -2
  96. package/dist/middleware/rate-limit.js +6 -2
  97. package/dist/middleware/response-logger.js +6 -2
  98. package/dist/middleware/security.js +6 -2
  99. package/dist/middleware/wrappers.js +16 -10
  100. package/dist/storage/config.d.ts +20 -0
  101. package/dist/storage/config.js +13 -0
  102. package/dist/storage/r2-storage.d.ts +4 -0
  103. package/dist/storage/r2-storage.js +19 -10
  104. package/dist/system/cpu.js +7 -3
  105. package/dist/system/disk.js +7 -3
  106. package/dist/system/environment.js +11 -3
  107. package/dist/system/health-check.js +9 -3
  108. package/dist/system/index.js +18 -10
  109. package/dist/system/memory.js +7 -3
  110. package/dist/system/network.js +7 -3
  111. package/dist/system/utils.js +6 -2
  112. package/dist/types/env.d.ts +12 -2
  113. package/dist/utils/cors.js +5 -1
  114. package/dist/utils/csv-export.js +6 -2
  115. package/dist/utils/error-processor.js +6 -2
  116. package/dist/utils/index.js +23 -18
  117. package/package.json +10 -1
  118. package/dist/chunk-N4XYQB2G.js +0 -193
  119. package/dist/chunk-OFPRBEO6.js +0 -93
  120. package/dist/{chunk-TH45RVP7.js → chunk-KHYY4KCV.js} +3 -3
  121. package/dist/{chunk-EBUEBEJX.js → chunk-QMCOX3DP.js} +0 -0
  122. package/dist/{chunk-X2UP5PNN.js → chunk-SEZJN4TC.js} +3 -3
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AUTH_ERROR_CODE_MAP
3
- } from "./chunk-JWZSWMOM.js";
3
+ } from "./chunk-2KDLKHTO.js";
4
4
  import {
5
5
  getErrorMessage
6
6
  } from "./chunk-Y2JYA2AR.js";
@@ -16,7 +16,10 @@ import {
16
16
  } from "./chunk-AIH3F7JV.js";
17
17
  import {
18
18
  logger
19
- } from "./chunk-5A2L6TXD.js";
19
+ } from "./chunk-GQVBWZLH.js";
20
+ import {
21
+ getCommonConfig
22
+ } from "./chunk-SFPMFVSD.js";
20
23
  import {
21
24
  __spreadValues
22
25
  } from "./chunk-ORMEWXMH.js";
@@ -73,7 +76,12 @@ var errorHandlerMiddleware = async (context, next) => {
73
76
  }
74
77
  const classified = error instanceof Error ? classifyError(error) : ERROR_CODES.INTERNAL_SERVER_ERROR;
75
78
  logger.error("[ErrorHandler] Unexpected error:", error);
76
- const isProduction = process.env.NODE_ENV === "production";
79
+ let isProduction = false;
80
+ try {
81
+ isProduction = getCommonConfig().nodeEnv === "production";
82
+ } catch (e) {
83
+ isProduction = false;
84
+ }
77
85
  const safeMessage = isProduction ? classified.message : error instanceof Error ? error.message : "Unknown error";
78
86
  return createErrorResponse(
79
87
  classified.code,
@@ -0,0 +1,8 @@
1
+ // src/config/warn.ts
2
+ function configWarn(module, message) {
3
+ console.warn(`[${module}] ${message}`);
4
+ }
5
+
6
+ export {
7
+ configWarn
8
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-GQVBWZLH.js";
4
4
  import {
5
5
  __spreadValues
6
6
  } from "./chunk-ORMEWXMH.js";
@@ -1,6 +1,9 @@
1
+ import {
2
+ getCorsConfig
3
+ } from "./chunk-GFWGLWTS.js";
1
4
  import {
2
5
  logger
3
- } from "./chunk-5A2L6TXD.js";
6
+ } from "./chunk-GQVBWZLH.js";
4
7
 
5
8
  // src/middleware/cors.ts
6
9
  import { NextResponse } from "next/server";
@@ -51,11 +54,23 @@ function createCorsMiddleware(config) {
51
54
  };
52
55
  }
53
56
  var corsMiddleware = createCorsMiddleware({
54
- allowedOrigins: process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(",").map((s) => s.trim()) : []
57
+ allowedOrigins: (() => {
58
+ try {
59
+ return getCorsConfig().allowedOrigins;
60
+ } catch (e) {
61
+ return [];
62
+ }
63
+ })()
55
64
  });
56
65
  function validateCorsConfiguration(config) {
57
66
  var _a;
58
- const allowedOrigins = (_a = config == null ? void 0 : config.allowedOrigins) != null ? _a : process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(",").map((s) => s.trim()) : [];
67
+ let configuredOrigins = [];
68
+ try {
69
+ configuredOrigins = getCorsConfig().allowedOrigins;
70
+ } catch (e) {
71
+ configuredOrigins = [];
72
+ }
73
+ const allowedOrigins = (_a = config == null ? void 0 : config.allowedOrigins) != null ? _a : configuredOrigins;
59
74
  logger.info(
60
75
  `[CORS Middleware] Initialized - Allowed Origins: [${allowedOrigins.join(", ")}]`
61
76
  );
@@ -3,14 +3,14 @@ import {
3
3
  isRedisGloballyDisabled,
4
4
  notifyRedisError,
5
5
  resetRedisGlobalState
6
- } from "./chunk-I5PCM2JQ.js";
6
+ } from "./chunk-AXCB7SKY.js";
7
+ import {
8
+ logger
9
+ } from "./chunk-GQVBWZLH.js";
7
10
  import {
8
11
  getENV,
9
12
  isCacheEnabled
10
- } from "./chunk-N4XYQB2G.js";
11
- import {
12
- logger
13
- } from "./chunk-5A2L6TXD.js";
13
+ } from "./chunk-XI4MRH5P.js";
14
14
  import {
15
15
  __spreadValues
16
16
  } from "./chunk-ORMEWXMH.js";
@@ -1,29 +1,29 @@
1
+ import {
2
+ initRequestMiddleware
3
+ } from "./chunk-62Q7DN5G.js";
1
4
  import {
2
5
  MiddlewareChain
3
- } from "./chunk-AOZVTVJG.js";
6
+ } from "./chunk-FPESPW6P.js";
4
7
  import {
5
8
  rateLimitMiddleware
6
- } from "./chunk-QMZ75GBU.js";
9
+ } from "./chunk-6MI4XLWC.js";
7
10
  import {
8
11
  responseLoggerMiddleware
9
- } from "./chunk-M5LIX3TD.js";
12
+ } from "./chunk-OIRAH57Y.js";
10
13
  import {
11
14
  securityMiddleware
12
- } from "./chunk-NJXCFTOE.js";
15
+ } from "./chunk-QVWDWROP.js";
13
16
  import {
14
17
  adminMiddleware,
15
18
  authMiddleware,
16
19
  optionalAuthMiddleware
17
- } from "./chunk-74MSBKYW.js";
20
+ } from "./chunk-BDY3AOX5.js";
18
21
  import {
19
22
  corsMiddleware
20
- } from "./chunk-WDJLAZCW.js";
23
+ } from "./chunk-KGHWGLED.js";
21
24
  import {
22
25
  errorHandlerMiddleware
23
- } from "./chunk-WSUFD4SO.js";
24
- import {
25
- initRequestMiddleware
26
- } from "./chunk-62Q7DN5G.js";
26
+ } from "./chunk-JR7GVCQX.js";
27
27
 
28
28
  // src/middleware/wrappers.ts
29
29
  function withPublicApi(handler) {
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  runCommand,
3
3
  runMacCommand
4
- } from "./chunk-6WVKLXVT.js";
4
+ } from "./chunk-S5UCZ2T3.js";
5
5
  import {
6
6
  logger
7
- } from "./chunk-5A2L6TXD.js";
7
+ } from "./chunk-GQVBWZLH.js";
8
8
 
9
9
  // src/system/memory.ts
10
10
  import os from "os";
@@ -1,18 +1,18 @@
1
+ import {
2
+ DataTableBody
3
+ } from "./chunk-7IY3RQQL.js";
4
+ import {
5
+ DataTableBulkActions
6
+ } from "./chunk-MAATEX2R.js";
1
7
  import {
2
8
  DataTableFilters
3
- } from "./chunk-X2UP5PNN.js";
9
+ } from "./chunk-SEZJN4TC.js";
4
10
  import {
5
11
  DataTablePagination
6
12
  } from "./chunk-IPXPCBDO.js";
7
13
  import {
8
14
  DataTableSearch
9
- } from "./chunk-TH45RVP7.js";
10
- import {
11
- DataTableBody
12
- } from "./chunk-7IY3RQQL.js";
13
- import {
14
- DataTableBulkActions
15
- } from "./chunk-MAATEX2R.js";
15
+ } from "./chunk-KHYY4KCV.js";
16
16
  import {
17
17
  DEFAULT_LABELS
18
18
  } from "./chunk-NY5QXT33.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getENV,
3
3
  isCacheEnabled
4
- } from "./chunk-N4XYQB2G.js";
4
+ } from "./chunk-XI4MRH5P.js";
5
5
 
6
6
  // src/cache/cache-config.ts
7
7
  var getCacheConfig = {
@@ -0,0 +1,46 @@
1
+ import {
2
+ configWarn
3
+ } from "./chunk-K25ICPU4.js";
4
+ import {
5
+ ConfigurationError
6
+ } from "./chunk-2QH66EVQ.js";
7
+
8
+ // src/logger/config.ts
9
+ var GLOBAL_KEY = "__withwiz_logger_config";
10
+ function getConfig() {
11
+ var _a;
12
+ return (_a = globalThis[GLOBAL_KEY]) != null ? _a : null;
13
+ }
14
+ function setConfig(config) {
15
+ globalThis[GLOBAL_KEY] = config;
16
+ }
17
+ function initializeLogger(config) {
18
+ var _a, _b, _c, _d, _e;
19
+ if (getConfig()) return;
20
+ if (config.level === void 0) configWarn("Logger", "level not provided, using default: info");
21
+ if (config.dir === void 0) configWarn("Logger", "dir not provided, using default: ./logs");
22
+ if (config.file === void 0) configWarn("Logger", "file not provided, using default: app.log");
23
+ if (config.fileEnabled === void 0) configWarn("Logger", "fileEnabled not provided, using default: true");
24
+ if (config.consoleEnabled === void 0) configWarn("Logger", "consoleEnabled not provided, using default: true");
25
+ setConfig({
26
+ level: (_a = config.level) != null ? _a : "info",
27
+ dir: (_b = config.dir) != null ? _b : "./logs",
28
+ file: (_c = config.file) != null ? _c : "app.log",
29
+ fileEnabled: (_d = config.fileEnabled) != null ? _d : true,
30
+ consoleEnabled: (_e = config.consoleEnabled) != null ? _e : true
31
+ });
32
+ }
33
+ function getLoggerConfig() {
34
+ const config = getConfig();
35
+ if (!config) throw new ConfigurationError("Logger", "Not initialized. Call initializeLogger() first.");
36
+ return config;
37
+ }
38
+ function resetLogger() {
39
+ globalThis[GLOBAL_KEY] = void 0;
40
+ }
41
+
42
+ export {
43
+ initializeLogger,
44
+ getLoggerConfig,
45
+ resetLogger
46
+ };
@@ -2,7 +2,7 @@ import {
2
2
  logApiRequest,
3
3
  logApiResponse,
4
4
  logger
5
- } from "./chunk-5A2L6TXD.js";
5
+ } from "./chunk-GQVBWZLH.js";
6
6
 
7
7
  // src/middleware/response-logger.ts
8
8
  var responseLoggerMiddleware = async (context, next) => {
@@ -0,0 +1,50 @@
1
+ import {
2
+ configWarn
3
+ } from "./chunk-K25ICPU4.js";
4
+ import {
5
+ ConfigurationError
6
+ } from "./chunk-2QH66EVQ.js";
7
+
8
+ // src/auth/config.ts
9
+ var GLOBAL_KEY = "__withwiz_auth_config";
10
+ function getConfig() {
11
+ var _a;
12
+ return (_a = globalThis[GLOBAL_KEY]) != null ? _a : null;
13
+ }
14
+ function setConfig(config) {
15
+ globalThis[GLOBAL_KEY] = config;
16
+ }
17
+ function initializeAuth(config) {
18
+ var _a, _b;
19
+ if (getConfig()) return;
20
+ if (!config.jwtSecret) {
21
+ throw new ConfigurationError("Auth", "jwtSecret is required");
22
+ }
23
+ if (!config.accessTokenExpiry) {
24
+ configWarn("Auth", "accessTokenExpiry not provided, using default: 7d");
25
+ }
26
+ if (!config.refreshTokenExpiry) {
27
+ configWarn("Auth", "refreshTokenExpiry not provided, using default: 30d");
28
+ }
29
+ setConfig({
30
+ jwtSecret: config.jwtSecret,
31
+ accessTokenExpiry: (_a = config.accessTokenExpiry) != null ? _a : "7d",
32
+ refreshTokenExpiry: (_b = config.refreshTokenExpiry) != null ? _b : "30d"
33
+ });
34
+ }
35
+ function getAuthConfig() {
36
+ const config = getConfig();
37
+ if (!config) {
38
+ throw new ConfigurationError("Auth", "Not initialized. Call initializeAuth() first.");
39
+ }
40
+ return config;
41
+ }
42
+ function resetAuth() {
43
+ globalThis[GLOBAL_KEY] = void 0;
44
+ }
45
+
46
+ export {
47
+ initializeAuth,
48
+ getAuthConfig,
49
+ resetAuth
50
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-GQVBWZLH.js";
4
4
 
5
5
  // src/middleware/security.ts
6
6
  import { NextResponse } from "next/server";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  getCacheManager,
3
3
  getEffectiveCacheBackend
4
- } from "./chunk-YVF4RXOK.js";
4
+ } from "./chunk-7IN4WRSO.js";
5
+ import {
6
+ logger
7
+ } from "./chunk-GQVBWZLH.js";
5
8
  import {
6
9
  getCacheConfig,
7
10
  getCacheTTL
8
- } from "./chunk-HCTNZM7D.js";
11
+ } from "./chunk-O7CK3CKJ.js";
9
12
  import {
10
13
  isCacheEnabled
11
- } from "./chunk-N4XYQB2G.js";
12
- import {
13
- logger
14
- } from "./chunk-5A2L6TXD.js";
14
+ } from "./chunk-XI4MRH5P.js";
15
15
 
16
16
  // src/cache/cache-wrapper.ts
17
17
  function getCacheBackendLabel() {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-GQVBWZLH.js";
4
4
 
5
5
  // src/system/utils.ts
6
6
  import { exec } from "child_process";
@@ -0,0 +1,40 @@
1
+ import {
2
+ configWarn
3
+ } from "./chunk-K25ICPU4.js";
4
+ import {
5
+ ConfigurationError
6
+ } from "./chunk-2QH66EVQ.js";
7
+
8
+ // src/config/common.ts
9
+ var GLOBAL_KEY = "__withwiz_common_config";
10
+ function getConfig() {
11
+ var _a;
12
+ return (_a = globalThis[GLOBAL_KEY]) != null ? _a : null;
13
+ }
14
+ function setConfig(config) {
15
+ globalThis[GLOBAL_KEY] = config;
16
+ }
17
+ function initializeCommon(config) {
18
+ var _a;
19
+ if (getConfig()) return;
20
+ if (!config.nodeEnv) {
21
+ configWarn("Common", "nodeEnv not provided, using default: development");
22
+ }
23
+ setConfig({ nodeEnv: (_a = config.nodeEnv) != null ? _a : "development" });
24
+ }
25
+ function getCommonConfig() {
26
+ const config = getConfig();
27
+ if (!config) {
28
+ throw new ConfigurationError("Common", "Not initialized. Call initializeCommon() first.");
29
+ }
30
+ return config;
31
+ }
32
+ function resetCommon() {
33
+ globalThis[GLOBAL_KEY] = void 0;
34
+ }
35
+
36
+ export {
37
+ initializeCommon,
38
+ getCommonConfig,
39
+ resetCommon
40
+ };
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  InMemoryCacheManager
3
- } from "./chunk-Y6IHEA3Q.js";
3
+ } from "./chunk-J4TTSXDN.js";
4
4
  import {
5
5
  isRedisGloballyDisabled,
6
6
  notifyRedisError
7
- } from "./chunk-I5PCM2JQ.js";
8
- import {
9
- getCacheFallbackConfig
10
- } from "./chunk-N4XYQB2G.js";
7
+ } from "./chunk-AXCB7SKY.js";
11
8
  import {
12
9
  logger
13
- } from "./chunk-5A2L6TXD.js";
10
+ } from "./chunk-GQVBWZLH.js";
11
+ import {
12
+ getCacheFallbackConfig
13
+ } from "./chunk-XI4MRH5P.js";
14
14
  import {
15
15
  __spreadValues
16
16
  } from "./chunk-ORMEWXMH.js";
@@ -0,0 +1,110 @@
1
+ import {
2
+ ConfigurationError
3
+ } from "./chunk-2QH66EVQ.js";
4
+ import {
5
+ CACHE_DURATION_DEFAULTS,
6
+ CACHE_FALLBACK_DEFAULTS,
7
+ CACHE_HEALTH_DEFAULTS,
8
+ CACHE_TTL_DEFAULTS,
9
+ INMEMORY_CACHE_DEFAULTS
10
+ } from "./chunk-IQQKKUAV.js";
11
+ import {
12
+ __spreadValues
13
+ } from "./chunk-ORMEWXMH.js";
14
+
15
+ // src/cache/config.ts
16
+ var GLOBAL_KEY = "__withwiz_cache_config";
17
+ function getConfig() {
18
+ var _a;
19
+ return (_a = globalThis[GLOBAL_KEY]) != null ? _a : null;
20
+ }
21
+ function setConfig(config) {
22
+ globalThis[GLOBAL_KEY] = config;
23
+ }
24
+ function initializeCache(input) {
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa;
26
+ if (getConfig()) return;
27
+ if (input.redis !== void 0) {
28
+ if (!input.redis.url) {
29
+ throw new ConfigurationError("cache", "redis.url is required");
30
+ }
31
+ if (!input.redis.token) {
32
+ throw new ConfigurationError("cache", "redis.token is required");
33
+ }
34
+ }
35
+ const defaultCategories = {};
36
+ for (const [key, duration] of Object.entries(CACHE_DURATION_DEFAULTS)) {
37
+ defaultCategories[key] = { enabled: true, duration };
38
+ }
39
+ const mergedCategories = __spreadValues({}, defaultCategories);
40
+ if (input.categories) {
41
+ for (const [key, value] of Object.entries(input.categories)) {
42
+ if (value !== void 0) {
43
+ mergedCategories[key] = {
44
+ enabled: (_a = value.enabled) != null ? _a : true,
45
+ duration: (_d = (_c = value.duration) != null ? _c : (_b = defaultCategories[key]) == null ? void 0 : _b.duration) != null ? _d : CACHE_TTL_DEFAULTS.DEFAULT
46
+ };
47
+ }
48
+ }
49
+ }
50
+ setConfig({
51
+ enabled: (_e = input.enabled) != null ? _e : true,
52
+ redis: input.redis ? {
53
+ url: input.redis.url,
54
+ token: input.redis.token,
55
+ enabled: (_f = input.redis.enabled) != null ? _f : true
56
+ } : void 0,
57
+ inmemory: {
58
+ enabled: (_h = (_g = input.inmemory) == null ? void 0 : _g.enabled) != null ? _h : true,
59
+ maxSize: (_j = (_i = input.inmemory) == null ? void 0 : _i.maxSize) != null ? _j : INMEMORY_CACHE_DEFAULTS.MAX_SIZE,
60
+ maxMb: (_l = (_k = input.inmemory) == null ? void 0 : _k.maxMb) != null ? _l : INMEMORY_CACHE_DEFAULTS.MAX_MB,
61
+ eviction: (_n = (_m = input.inmemory) == null ? void 0 : _m.eviction) != null ? _n : INMEMORY_CACHE_DEFAULTS.EVICTION,
62
+ cleanupInterval: (_p = (_o = input.inmemory) == null ? void 0 : _o.cleanupInterval) != null ? _p : INMEMORY_CACHE_DEFAULTS.CLEANUP_INTERVAL
63
+ },
64
+ ttl: {
65
+ DEFAULT: (_r = (_q = input.ttl) == null ? void 0 : _q.DEFAULT) != null ? _r : CACHE_TTL_DEFAULTS.DEFAULT,
66
+ SHORT: (_t = (_s = input.ttl) == null ? void 0 : _s.SHORT) != null ? _t : CACHE_TTL_DEFAULTS.SHORT,
67
+ LONG: (_v = (_u = input.ttl) == null ? void 0 : _u.LONG) != null ? _v : CACHE_TTL_DEFAULTS.LONG,
68
+ GEOIP: (_x = (_w = input.ttl) == null ? void 0 : _w.GEOIP) != null ? _x : CACHE_TTL_DEFAULTS.GEOIP,
69
+ SETTINGS: (_z = (_y = input.ttl) == null ? void 0 : _y.SETTINGS) != null ? _z : CACHE_TTL_DEFAULTS.SETTINGS,
70
+ ANALYTICS: (_B = (_A = input.ttl) == null ? void 0 : _A.ANALYTICS) != null ? _B : CACHE_TTL_DEFAULTS.ANALYTICS,
71
+ USER: (_D = (_C = input.ttl) == null ? void 0 : _C.USER) != null ? _D : CACHE_TTL_DEFAULTS.USER,
72
+ LINK: (_F = (_E = input.ttl) == null ? void 0 : _E.LINK) != null ? _F : CACHE_TTL_DEFAULTS.LINK,
73
+ ALIAS: (_H = (_G = input.ttl) == null ? void 0 : _G.ALIAS) != null ? _H : CACHE_TTL_DEFAULTS.ALIAS,
74
+ COMMUNITY: (_J = (_I = input.ttl) == null ? void 0 : _I.COMMUNITY) != null ? _J : CACHE_TTL_DEFAULTS.COMMUNITY,
75
+ RESERVED_WORDS: (_L = (_K = input.ttl) == null ? void 0 : _K.RESERVED_WORDS) != null ? _L : CACHE_TTL_DEFAULTS.RESERVED_WORDS
76
+ },
77
+ categories: mergedCategories,
78
+ fallback: {
79
+ redisErrorThresholdGlobal: (_N = (_M = input.fallback) == null ? void 0 : _M.redisErrorThresholdGlobal) != null ? _N : CACHE_FALLBACK_DEFAULTS.REDIS_ERROR_THRESHOLD_GLOBAL,
80
+ redisErrorThresholdLocal: (_P = (_O = input.fallback) == null ? void 0 : _O.redisErrorThresholdLocal) != null ? _P : CACHE_FALLBACK_DEFAULTS.REDIS_ERROR_THRESHOLD_LOCAL,
81
+ redisReconnectInterval: (_R = (_Q = input.fallback) == null ? void 0 : _Q.redisReconnectInterval) != null ? _R : CACHE_FALLBACK_DEFAULTS.REDIS_RECONNECT_INTERVAL,
82
+ fallbackOnRedisError: (_T = (_S = input.fallback) == null ? void 0 : _S.fallbackOnRedisError) != null ? _T : CACHE_FALLBACK_DEFAULTS.FALLBACK_ON_REDIS_ERROR,
83
+ writeToMemory: (_V = (_U = input.fallback) == null ? void 0 : _U.writeToMemory) != null ? _V : CACHE_FALLBACK_DEFAULTS.WRITE_TO_MEMORY
84
+ },
85
+ health: {
86
+ errorRateThreshold: (_X = (_W = input.health) == null ? void 0 : _W.errorRateThreshold) != null ? _X : CACHE_HEALTH_DEFAULTS.ERROR_RATE_THRESHOLD,
87
+ hitRateThreshold: (_Z = (_Y = input.health) == null ? void 0 : _Y.hitRateThreshold) != null ? _Z : CACHE_HEALTH_DEFAULTS.HIT_RATE_THRESHOLD,
88
+ reportHitRateThreshold: (_$ = (__ = input.health) == null ? void 0 : __.reportHitRateThreshold) != null ? _$ : CACHE_HEALTH_DEFAULTS.REPORT_HIT_RATE_THRESHOLD,
89
+ reportResponseTimeThreshold: (_ba = (_aa = input.health) == null ? void 0 : _aa.reportResponseTimeThreshold) != null ? _ba : CACHE_HEALTH_DEFAULTS.REPORT_RESPONSE_TIME_THRESHOLD,
90
+ reportInvalidationThreshold: (_da = (_ca = input.health) == null ? void 0 : _ca.reportInvalidationThreshold) != null ? _da : CACHE_HEALTH_DEFAULTS.REPORT_INVALIDATION_THRESHOLD,
91
+ reportMinRequests: (_fa = (_ea = input.health) == null ? void 0 : _ea.reportMinRequests) != null ? _fa : CACHE_HEALTH_DEFAULTS.REPORT_MIN_REQUESTS
92
+ }
93
+ });
94
+ }
95
+ function getResolvedCacheConfig() {
96
+ const config = getConfig();
97
+ if (!config) {
98
+ throw new ConfigurationError("cache", "Cache config not initialized. Call initializeCache() first.");
99
+ }
100
+ return config;
101
+ }
102
+ function resetCache() {
103
+ globalThis[GLOBAL_KEY] = void 0;
104
+ }
105
+
106
+ export {
107
+ initializeCache,
108
+ getResolvedCacheConfig,
109
+ resetCache
110
+ };
@@ -1,16 +1,28 @@
1
+ import {
2
+ getCorsConfig
3
+ } from "./chunk-GFWGLWTS.js";
4
+ import {
5
+ getCommonConfig
6
+ } from "./chunk-SFPMFVSD.js";
1
7
  import {
2
8
  __spreadValues
3
9
  } from "./chunk-ORMEWXMH.js";
4
10
 
5
11
  // src/utils/cors.ts
6
12
  import { NextResponse } from "next/server";
13
+ var _isDevelopment = false;
14
+ try {
15
+ _isDevelopment = getCommonConfig().nodeEnv === "development";
16
+ } catch (e) {
17
+ _isDevelopment = false;
18
+ }
7
19
  var globalCorsConfig = {
8
- isDevelopment: process.env.NODE_ENV === "development"
20
+ isDevelopment: _isDevelopment
9
21
  };
10
22
  function initCorsConfig(config) {
11
23
  globalCorsConfig = __spreadValues(__spreadValues({}, globalCorsConfig), config);
12
24
  }
13
- function getCorsConfig() {
25
+ function getCorsConfig2() {
14
26
  return globalCorsConfig;
15
27
  }
16
28
  function extractDomainsFromUrl(url) {
@@ -29,13 +41,25 @@ function extractDomainsFromUrl(url) {
29
41
  }
30
42
  }
31
43
  function getBaseUrl() {
32
- return globalCorsConfig.baseUrl || process.env.BASE_URL || process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
44
+ if (globalCorsConfig.baseUrl) {
45
+ return globalCorsConfig.baseUrl;
46
+ }
47
+ try {
48
+ const middlewareCorsConfig = getCorsConfig();
49
+ if (middlewareCorsConfig.baseUrl) {
50
+ return middlewareCorsConfig.baseUrl;
51
+ }
52
+ } catch (e) {
53
+ }
54
+ return "http://localhost:3000";
33
55
  }
34
56
  function getAllowedOrigins() {
57
+ var _a;
35
58
  const origins = /* @__PURE__ */ new Set();
36
- if (process.env.ALLOWED_ORIGINS) {
37
- const envOrigins = process.env.ALLOWED_ORIGINS.split(",").map((origin) => origin.trim()).filter(Boolean);
38
- envOrigins.forEach((origin) => origins.add(origin));
59
+ try {
60
+ const middlewareCorsConfig = getCorsConfig();
61
+ middlewareCorsConfig.allowedOrigins.forEach((origin) => origins.add(origin));
62
+ } catch (e) {
39
63
  }
40
64
  const baseUrl = getBaseUrl();
41
65
  if (baseUrl && baseUrl !== "http://localhost:3000") {
@@ -45,16 +69,32 @@ function getAllowedOrigins() {
45
69
  if (globalCorsConfig.additionalOrigins) {
46
70
  globalCorsConfig.additionalOrigins.forEach((origin) => origins.add(origin));
47
71
  }
48
- if (globalCorsConfig.isDevelopment || process.env.NODE_ENV === "development") {
72
+ let isDev = (_a = globalCorsConfig.isDevelopment) != null ? _a : false;
73
+ if (!isDev) {
74
+ try {
75
+ isDev = getCommonConfig().nodeEnv === "development";
76
+ } catch (e) {
77
+ isDev = false;
78
+ }
79
+ }
80
+ if (isDev) {
49
81
  origins.add("http://localhost:3000");
50
82
  origins.add("http://127.0.0.1:3000");
51
83
  }
52
84
  return Array.from(origins).filter(Boolean);
53
85
  }
54
86
  function isOriginAllowed(origin) {
87
+ var _a;
55
88
  if (!origin) return true;
56
- const isDev = globalCorsConfig.isDevelopment || process.env.NODE_ENV === "development";
57
- if (isDev && origin.includes("localhost")) {
89
+ let isDevEnv = (_a = globalCorsConfig.isDevelopment) != null ? _a : false;
90
+ if (!isDevEnv) {
91
+ try {
92
+ isDevEnv = getCommonConfig().nodeEnv === "development";
93
+ } catch (e) {
94
+ isDevEnv = false;
95
+ }
96
+ }
97
+ if (isDevEnv && origin.includes("localhost")) {
58
98
  return true;
59
99
  }
60
100
  return getAllowedOrigins().includes(origin);
@@ -122,7 +162,7 @@ function withPublicCORS(handler) {
122
162
 
123
163
  export {
124
164
  initCorsConfig,
125
- getCorsConfig,
165
+ getCorsConfig2 as getCorsConfig,
126
166
  getAllowedOrigins,
127
167
  isOriginAllowed,
128
168
  setCorsHeaders,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cache,
3
3
  geoCache
4
- } from "./chunk-YVF4RXOK.js";
4
+ } from "./chunk-7IN4WRSO.js";
5
5
 
6
6
  // src/cache/cache-invalidation.ts
7
7
  var invalidateCache = {