@withwiz/toolkit 0.2.7 → 0.3.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 (128) hide show
  1. package/dist/auth/config.d.ts +13 -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 +14 -9
  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 +25 -17
  12. package/dist/cache/config.d.ts +113 -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 +25 -17
  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-2LCLLZME.js +122 -0
  21. package/dist/chunk-2QH66EVQ.js +11 -0
  22. package/dist/{chunk-YVF4RXOK.js → chunk-3GKJ763I.js} +12 -12
  23. package/dist/{chunk-XN4YP4XO.js → chunk-4CSSGCW5.js} +5 -5
  24. package/dist/{chunk-WZDS4QEC.js → chunk-576PAKLR.js} +1 -1
  25. package/dist/chunk-5MBKG2ZD.js +32 -0
  26. package/dist/{chunk-74MSBKYW.js → chunk-5P4E6SGV.js} +17 -13
  27. package/dist/{chunk-R5OFGX3C.js → chunk-6VNEAK73.js} +6 -6
  28. package/dist/{chunk-S73334QY.js → chunk-AWFY2HWG.js} +2 -2
  29. package/dist/{chunk-YMIDD4YE.js → chunk-BJWG3LH5.js} +6 -6
  30. package/dist/{chunk-BX5CNRVS.js → chunk-BY653UR3.js} +2 -2
  31. package/dist/{chunk-HCTNZM7D.js → chunk-C3WPAWID.js} +1 -1
  32. package/dist/{chunk-JOGXLVUZ.js → chunk-CZHFHEBG.js} +5 -5
  33. package/dist/{chunk-P6VSEFZE.js → chunk-DC2OFQ43.js} +18 -10
  34. package/dist/{chunk-HOMWLK62.js → chunk-FGA7VLYK.js} +2 -2
  35. package/dist/{chunk-T3YUJYBX.js → chunk-FIRLRKET.js} +1 -1
  36. package/dist/{chunk-LEWQBXN6.js → chunk-FO77EZCU.js} +1 -1
  37. package/dist/{chunk-WEDR5GJO.js → chunk-GRGOD3W5.js} +2 -2
  38. package/dist/{chunk-JWZSWMOM.js → chunk-HKJCBV3H.js} +6 -6
  39. package/dist/chunk-ITSXXSFN.js +42 -0
  40. package/dist/{chunk-6WVKLXVT.js → chunk-JGGGHEBC.js} +1 -1
  41. package/dist/chunk-JNB7MWG4.js +40 -0
  42. package/dist/chunk-JTPLPUI7.js +102 -0
  43. package/dist/chunk-K25ICPU4.js +8 -0
  44. package/dist/{chunk-IT43YQND.js → chunk-KAIGEZAL.js} +20 -5
  45. package/dist/{chunk-AOZVTVJG.js → chunk-L6M4DZV2.js} +1 -1
  46. package/dist/{chunk-GSUQE3SZ.js → chunk-LX2EYD74.js} +31 -16
  47. package/dist/{chunk-QMZ75GBU.js → chunk-M776IH4D.js} +3 -3
  48. package/dist/{chunk-DH2ZHGW2.js → chunk-MVH5ZPFD.js} +14 -2
  49. package/dist/{chunk-WDJLAZCW.js → chunk-NE33JZW3.js} +18 -3
  50. package/dist/{chunk-2NNLUXPF.js → chunk-NWAN2VRP.js} +12 -12
  51. package/dist/{chunk-I5PCM2JQ.js → chunk-PU2LFTI5.js} +4 -4
  52. package/dist/{chunk-4NWJ3WCZ.js → chunk-Q7NIAITA.js} +8 -1
  53. package/dist/chunk-RLXRDUBX.js +38 -0
  54. package/dist/{chunk-AZASEBSP.js → chunk-S54PFAEU.js} +1 -1
  55. package/dist/{chunk-5A2L6TXD.js → chunk-SNNXLA5F.js} +34 -15
  56. package/dist/{chunk-M5LIX3TD.js → chunk-STNIT65W.js} +1 -1
  57. package/dist/{chunk-MZRYR3UQ.js → chunk-TQJDNWBL.js} +4 -4
  58. package/dist/{chunk-NJXCFTOE.js → chunk-UD7YHLHI.js} +1 -1
  59. package/dist/{chunk-GCZOXUDV.js → chunk-USL5SQLZ.js} +50 -10
  60. package/dist/chunk-V33BEN6H.js +31 -0
  61. package/dist/chunk-X2QSMX3B.js +156 -0
  62. package/dist/{chunk-Y6IHEA3Q.js → chunk-XZ4HMXSK.js} +1 -1
  63. package/dist/chunk-YCIYDWJU.js +37 -0
  64. package/dist/{chunk-7KCWVRPR.js → chunk-ZBU2DYLD.js} +2 -2
  65. package/dist/{chunk-67KRDPIH.js → chunk-ZFFWKCHN.js} +2 -2
  66. package/dist/components/ui/DataTable.js +6 -6
  67. package/dist/components/ui/data-table/DataTable.js +6 -6
  68. package/dist/components/ui/data-table/DataTableFilters.js +2 -2
  69. package/dist/components/ui/data-table/DataTableSearch.js +2 -2
  70. package/dist/config/common.d.ts +9 -0
  71. package/dist/config/common.js +13 -0
  72. package/dist/config/errors.d.ts +3 -0
  73. package/dist/config/errors.js +7 -0
  74. package/dist/config/warn.d.ts +4 -0
  75. package/dist/config/warn.js +7 -0
  76. package/dist/constants/index.js +23 -23
  77. package/dist/error/error-display.js +5 -5
  78. package/dist/error/error-handler.js +7 -3
  79. package/dist/error/friendly-messages-v2.js +3 -3
  80. package/dist/error/index.js +20 -16
  81. package/dist/error/messages/index.js +2 -2
  82. package/dist/geolocation/batch-processor.js +6 -2
  83. package/dist/geolocation/config.d.ts +11 -0
  84. package/dist/geolocation/config.js +13 -0
  85. package/dist/geolocation/index.js +10 -5
  86. package/dist/geolocation/providers/index.js +6 -3
  87. package/dist/geolocation/providers/ipgeolocation-provider.js +4 -1
  88. package/dist/geolocation/providers/maxmind-provider.js +4 -1
  89. package/dist/initialize.d.ts +18 -0
  90. package/dist/initialize.js +41 -0
  91. package/dist/logger/config.d.ts +17 -0
  92. package/dist/logger/config.js +13 -0
  93. package/dist/logger/logger.js +5 -1
  94. package/dist/middleware/auth.js +8 -3
  95. package/dist/middleware/cors-config.d.ts +11 -0
  96. package/dist/middleware/cors-config.js +13 -0
  97. package/dist/middleware/cors.js +7 -2
  98. package/dist/middleware/error-handler.js +11 -7
  99. package/dist/middleware/index.js +25 -19
  100. package/dist/middleware/middleware-chain.js +6 -2
  101. package/dist/middleware/rate-limit.js +6 -2
  102. package/dist/middleware/response-logger.js +6 -2
  103. package/dist/middleware/security.js +6 -2
  104. package/dist/middleware/wrappers.js +20 -14
  105. package/dist/storage/config.d.ts +17 -0
  106. package/dist/storage/config.js +13 -0
  107. package/dist/storage/r2-storage.d.ts +4 -0
  108. package/dist/storage/r2-storage.js +19 -10
  109. package/dist/system/cpu.js +7 -3
  110. package/dist/system/disk.js +7 -3
  111. package/dist/system/environment.js +11 -3
  112. package/dist/system/health-check.js +9 -3
  113. package/dist/system/index.js +18 -10
  114. package/dist/system/memory.js +7 -3
  115. package/dist/system/network.js +7 -3
  116. package/dist/system/utils.js +6 -2
  117. package/dist/types/env.d.ts +12 -2
  118. package/dist/utils/cors.js +5 -1
  119. package/dist/utils/csv-export.js +6 -2
  120. package/dist/utils/error-processor.js +6 -2
  121. package/dist/utils/index.js +31 -26
  122. package/package.json +10 -1
  123. package/dist/chunk-N4XYQB2G.js +0 -193
  124. package/dist/chunk-OFPRBEO6.js +0 -93
  125. package/dist/{chunk-TH45RVP7.js → chunk-KHYY4KCV.js} +3 -3
  126. package/dist/{chunk-EBUEBEJX.js → chunk-QMCOX3DP.js} +0 -0
  127. package/dist/{chunk-LJEGM4OO.js → chunk-SEZJN4TC.js} +3 -3
  128. package/dist/{chunk-ASXZ2NZJ.js → chunk-Y2JYA2AR.js} +3 -3
@@ -0,0 +1,102 @@
1
+ import {
2
+ CACHE_DURATION_DEFAULTS,
3
+ CACHE_FALLBACK_DEFAULTS,
4
+ CACHE_HEALTH_DEFAULTS,
5
+ CACHE_TTL_DEFAULTS,
6
+ INMEMORY_CACHE_DEFAULTS
7
+ } from "./chunk-IQQKKUAV.js";
8
+ import {
9
+ ConfigurationError
10
+ } from "./chunk-2QH66EVQ.js";
11
+ import {
12
+ __spreadValues
13
+ } from "./chunk-ORMEWXMH.js";
14
+
15
+ // src/cache/config.ts
16
+ var _config = null;
17
+ function initializeCache(input) {
18
+ 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;
19
+ if (_config) return;
20
+ if (input.redis !== void 0) {
21
+ if (!input.redis.url) {
22
+ throw new ConfigurationError("cache", "redis.url is required");
23
+ }
24
+ if (!input.redis.token) {
25
+ throw new ConfigurationError("cache", "redis.token is required");
26
+ }
27
+ }
28
+ const defaultCategories = {};
29
+ for (const [key, duration] of Object.entries(CACHE_DURATION_DEFAULTS)) {
30
+ defaultCategories[key] = { enabled: true, duration };
31
+ }
32
+ const mergedCategories = __spreadValues({}, defaultCategories);
33
+ if (input.categories) {
34
+ for (const [key, value] of Object.entries(input.categories)) {
35
+ if (value !== void 0) {
36
+ mergedCategories[key] = {
37
+ enabled: (_a = value.enabled) != null ? _a : true,
38
+ duration: (_d = (_c = value.duration) != null ? _c : (_b = defaultCategories[key]) == null ? void 0 : _b.duration) != null ? _d : CACHE_TTL_DEFAULTS.DEFAULT
39
+ };
40
+ }
41
+ }
42
+ }
43
+ _config = {
44
+ enabled: (_e = input.enabled) != null ? _e : true,
45
+ redis: input.redis ? {
46
+ url: input.redis.url,
47
+ token: input.redis.token,
48
+ enabled: (_f = input.redis.enabled) != null ? _f : true
49
+ } : void 0,
50
+ inmemory: {
51
+ enabled: (_h = (_g = input.inmemory) == null ? void 0 : _g.enabled) != null ? _h : true,
52
+ maxSize: (_j = (_i = input.inmemory) == null ? void 0 : _i.maxSize) != null ? _j : INMEMORY_CACHE_DEFAULTS.MAX_SIZE,
53
+ maxMb: (_l = (_k = input.inmemory) == null ? void 0 : _k.maxMb) != null ? _l : INMEMORY_CACHE_DEFAULTS.MAX_MB,
54
+ eviction: (_n = (_m = input.inmemory) == null ? void 0 : _m.eviction) != null ? _n : INMEMORY_CACHE_DEFAULTS.EVICTION,
55
+ cleanupInterval: (_p = (_o = input.inmemory) == null ? void 0 : _o.cleanupInterval) != null ? _p : INMEMORY_CACHE_DEFAULTS.CLEANUP_INTERVAL
56
+ },
57
+ ttl: {
58
+ DEFAULT: (_r = (_q = input.ttl) == null ? void 0 : _q.DEFAULT) != null ? _r : CACHE_TTL_DEFAULTS.DEFAULT,
59
+ SHORT: (_t = (_s = input.ttl) == null ? void 0 : _s.SHORT) != null ? _t : CACHE_TTL_DEFAULTS.SHORT,
60
+ LONG: (_v = (_u = input.ttl) == null ? void 0 : _u.LONG) != null ? _v : CACHE_TTL_DEFAULTS.LONG,
61
+ GEOIP: (_x = (_w = input.ttl) == null ? void 0 : _w.GEOIP) != null ? _x : CACHE_TTL_DEFAULTS.GEOIP,
62
+ SETTINGS: (_z = (_y = input.ttl) == null ? void 0 : _y.SETTINGS) != null ? _z : CACHE_TTL_DEFAULTS.SETTINGS,
63
+ ANALYTICS: (_B = (_A = input.ttl) == null ? void 0 : _A.ANALYTICS) != null ? _B : CACHE_TTL_DEFAULTS.ANALYTICS,
64
+ USER: (_D = (_C = input.ttl) == null ? void 0 : _C.USER) != null ? _D : CACHE_TTL_DEFAULTS.USER,
65
+ LINK: (_F = (_E = input.ttl) == null ? void 0 : _E.LINK) != null ? _F : CACHE_TTL_DEFAULTS.LINK,
66
+ ALIAS: (_H = (_G = input.ttl) == null ? void 0 : _G.ALIAS) != null ? _H : CACHE_TTL_DEFAULTS.ALIAS,
67
+ COMMUNITY: (_J = (_I = input.ttl) == null ? void 0 : _I.COMMUNITY) != null ? _J : CACHE_TTL_DEFAULTS.COMMUNITY,
68
+ RESERVED_WORDS: (_L = (_K = input.ttl) == null ? void 0 : _K.RESERVED_WORDS) != null ? _L : CACHE_TTL_DEFAULTS.RESERVED_WORDS
69
+ },
70
+ categories: mergedCategories,
71
+ fallback: {
72
+ redisErrorThresholdGlobal: (_N = (_M = input.fallback) == null ? void 0 : _M.redisErrorThresholdGlobal) != null ? _N : CACHE_FALLBACK_DEFAULTS.REDIS_ERROR_THRESHOLD_GLOBAL,
73
+ redisErrorThresholdLocal: (_P = (_O = input.fallback) == null ? void 0 : _O.redisErrorThresholdLocal) != null ? _P : CACHE_FALLBACK_DEFAULTS.REDIS_ERROR_THRESHOLD_LOCAL,
74
+ redisReconnectInterval: (_R = (_Q = input.fallback) == null ? void 0 : _Q.redisReconnectInterval) != null ? _R : CACHE_FALLBACK_DEFAULTS.REDIS_RECONNECT_INTERVAL,
75
+ fallbackOnRedisError: (_T = (_S = input.fallback) == null ? void 0 : _S.fallbackOnRedisError) != null ? _T : CACHE_FALLBACK_DEFAULTS.FALLBACK_ON_REDIS_ERROR,
76
+ writeToMemory: (_V = (_U = input.fallback) == null ? void 0 : _U.writeToMemory) != null ? _V : CACHE_FALLBACK_DEFAULTS.WRITE_TO_MEMORY
77
+ },
78
+ health: {
79
+ errorRateThreshold: (_X = (_W = input.health) == null ? void 0 : _W.errorRateThreshold) != null ? _X : CACHE_HEALTH_DEFAULTS.ERROR_RATE_THRESHOLD,
80
+ hitRateThreshold: (_Z = (_Y = input.health) == null ? void 0 : _Y.hitRateThreshold) != null ? _Z : CACHE_HEALTH_DEFAULTS.HIT_RATE_THRESHOLD,
81
+ reportHitRateThreshold: (_$ = (__ = input.health) == null ? void 0 : __.reportHitRateThreshold) != null ? _$ : CACHE_HEALTH_DEFAULTS.REPORT_HIT_RATE_THRESHOLD,
82
+ reportResponseTimeThreshold: (_ba = (_aa = input.health) == null ? void 0 : _aa.reportResponseTimeThreshold) != null ? _ba : CACHE_HEALTH_DEFAULTS.REPORT_RESPONSE_TIME_THRESHOLD,
83
+ reportInvalidationThreshold: (_da = (_ca = input.health) == null ? void 0 : _ca.reportInvalidationThreshold) != null ? _da : CACHE_HEALTH_DEFAULTS.REPORT_INVALIDATION_THRESHOLD,
84
+ reportMinRequests: (_fa = (_ea = input.health) == null ? void 0 : _ea.reportMinRequests) != null ? _fa : CACHE_HEALTH_DEFAULTS.REPORT_MIN_REQUESTS
85
+ }
86
+ };
87
+ }
88
+ function getResolvedCacheConfig() {
89
+ if (_config === null) {
90
+ throw new ConfigurationError("cache", "Cache config not initialized. Call initializeCache() first.");
91
+ }
92
+ return _config;
93
+ }
94
+ function resetCache() {
95
+ _config = null;
96
+ }
97
+
98
+ export {
99
+ initializeCache,
100
+ getResolvedCacheConfig,
101
+ resetCache
102
+ };
@@ -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
+ };
@@ -4,13 +4,17 @@ import {
4
4
  } from "./chunk-OIVXOT2X.js";
5
5
  import {
6
6
  getPlatform
7
- } from "./chunk-6WVKLXVT.js";
7
+ } from "./chunk-JGGGHEBC.js";
8
8
  import {
9
9
  logger
10
- } from "./chunk-5A2L6TXD.js";
10
+ } from "./chunk-SNNXLA5F.js";
11
+ import {
12
+ getResolvedCacheConfig
13
+ } from "./chunk-JTPLPUI7.js";
11
14
 
12
15
  // src/system/health-check.ts
13
16
  async function checkServiceHealth(prismaClient) {
17
+ var _a, _b;
14
18
  const platform = getPlatform();
15
19
  const services = [];
16
20
  if (prismaClient) {
@@ -53,9 +57,20 @@ async function checkServiceHealth(prismaClient) {
53
57
  }
54
58
  try {
55
59
  const redisStart = Date.now();
56
- const cacheEnabled = process.env.CACHE_ENABLED !== "false";
57
- const redisUrl = process.env.UPSTASH_REDIS_REST_URL;
58
- const redisToken = process.env.UPSTASH_REDIS_REST_TOKEN;
60
+ let cacheEnabled = false;
61
+ try {
62
+ cacheEnabled = getResolvedCacheConfig().enabled;
63
+ } catch (e) {
64
+ cacheEnabled = false;
65
+ }
66
+ let redisUrl;
67
+ let redisToken;
68
+ try {
69
+ const cacheConfig = getResolvedCacheConfig();
70
+ redisUrl = (_a = cacheConfig.redis) == null ? void 0 : _a.url;
71
+ redisToken = (_b = cacheConfig.redis) == null ? void 0 : _b.token;
72
+ } catch (e) {
73
+ }
59
74
  if (!cacheEnabled) {
60
75
  services.push({
61
76
  name: "Redis",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-SNNXLA5F.js";
4
4
  import {
5
5
  __spreadValues
6
6
  } from "./chunk-ORMEWXMH.js";
@@ -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-LJEGM4OO.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";
@@ -28,8 +28,10 @@ import {
28
28
  } from "./chunk-ORMEWXMH.js";
29
29
 
30
30
  // src/components/ui/data-table/DataTable.tsx
31
- import { useState, useEffect, useMemo } from "react";
31
+ import { useState, useEffect, useMemo, useRef } from "react";
32
32
  import { jsx, jsxs } from "react/jsx-runtime";
33
+ var EMPTY_ARRAY = [];
34
+ var EMPTY_OBJECT = {};
33
35
  function DataTable({
34
36
  data,
35
37
  columns,
@@ -37,14 +39,14 @@ function DataTable({
37
39
  error = null,
38
40
  pagination,
39
41
  sort,
40
- bulkActions = [],
41
- filters = [],
42
- filterValues = {},
42
+ bulkActions = EMPTY_ARRAY,
43
+ filters = EMPTY_ARRAY,
44
+ filterValues = EMPTY_OBJECT,
43
45
  onFilterChange,
44
46
  onClearFilters,
45
47
  selectable = false,
46
48
  onSelectionChange,
47
- selectedIds = [],
49
+ selectedIds = EMPTY_ARRAY,
48
50
  getRowId,
49
51
  className,
50
52
  emptyMessage = "No data",
@@ -58,11 +60,24 @@ function DataTable({
58
60
  labels: customLabels,
59
61
  syncWithUrl = false
60
62
  }) {
61
- const labels = __spreadValues(__spreadValues({}, DEFAULT_LABELS), customLabels);
62
- const [localSelectedIds, setLocalSelectedIds] = useState(selectedIds);
63
+ const customLabelsRef = useRef(customLabels);
64
+ const labelsRef = useRef(__spreadValues(__spreadValues({}, DEFAULT_LABELS), customLabels));
65
+ if (customLabelsRef.current !== customLabels) {
66
+ customLabelsRef.current = customLabels;
67
+ labelsRef.current = __spreadValues(__spreadValues({}, DEFAULT_LABELS), customLabels);
68
+ }
69
+ const labels = labelsRef.current;
70
+ const [localSelectedIds, setLocalSelectedIds] = useState(
71
+ selectedIds
72
+ );
63
73
  const [bulkActionLoading, setBulkActionLoading] = useState(null);
74
+ const prevSelectedIdsRef = useRef(JSON.stringify(selectedIds));
64
75
  useEffect(() => {
65
- setLocalSelectedIds(selectedIds);
76
+ const serialized = JSON.stringify(selectedIds);
77
+ if (serialized !== prevSelectedIdsRef.current) {
78
+ prevSelectedIdsRef.current = serialized;
79
+ setLocalSelectedIds(selectedIds);
80
+ }
66
81
  }, [selectedIds]);
67
82
  const hasActiveFilters = useMemo(() => {
68
83
  if (searchValue && searchValue.trim()) return true;
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  AppError
3
3
  } from "./chunk-KXXROUA5.js";
4
+ import {
5
+ logger
6
+ } from "./chunk-SNNXLA5F.js";
4
7
  import {
5
8
  ERROR_CODES
6
9
  } from "./chunk-SNVGJPPX.js";
7
- import {
8
- logger
9
- } from "./chunk-5A2L6TXD.js";
10
10
 
11
11
  // src/middleware/rate-limit.ts
12
12
  var GLOBAL_KEY = "__withwiz_rateLimitAdapter__";
@@ -2,6 +2,9 @@ import {
2
2
  BaseGeoIPProvider,
3
3
  truncateString
4
4
  } from "./chunk-AHDPGRXS.js";
5
+ import {
6
+ getGeolocationConfig
7
+ } from "./chunk-V33BEN6H.js";
5
8
 
6
9
  // src/geolocation/providers/ipgeolocation-provider.ts
7
10
  var IPGeolocationProvider = class extends BaseGeoIPProvider {
@@ -14,7 +17,12 @@ var IPGeolocationProvider = class extends BaseGeoIPProvider {
14
17
  }
15
18
  // 3초 타임아웃
16
19
  url(ip) {
17
- const apiKey = process.env.IPGEOLOCATION_API_KEY;
20
+ let apiKey;
21
+ try {
22
+ apiKey = getGeolocationConfig().ipgeolocationApiKey;
23
+ } catch (e) {
24
+ return "";
25
+ }
18
26
  if (!apiKey) return "";
19
27
  return `https://api.ipgeolocation.io/ipgeo?apiKey=${apiKey}&ip=${ip}`;
20
28
  }
@@ -44,7 +52,11 @@ var IPGeolocationProvider = class extends BaseGeoIPProvider {
44
52
  return null;
45
53
  }
46
54
  isAvailable() {
47
- return !!process.env.IPGEOLOCATION_API_KEY;
55
+ try {
56
+ return !!getGeolocationConfig().ipgeolocationApiKey;
57
+ } catch (e) {
58
+ return false;
59
+ }
48
60
  }
49
61
  };
50
62
 
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-SNNXLA5F.js";
4
+ import {
5
+ getCorsConfig
6
+ } from "./chunk-JNB7MWG4.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
  );
@@ -1,29 +1,29 @@
1
+ import {
2
+ errorHandlerMiddleware
3
+ } from "./chunk-DC2OFQ43.js";
4
+ import {
5
+ initRequestMiddleware
6
+ } from "./chunk-62Q7DN5G.js";
1
7
  import {
2
8
  MiddlewareChain
3
- } from "./chunk-AOZVTVJG.js";
9
+ } from "./chunk-L6M4DZV2.js";
4
10
  import {
5
11
  rateLimitMiddleware
6
- } from "./chunk-QMZ75GBU.js";
12
+ } from "./chunk-M776IH4D.js";
7
13
  import {
8
14
  responseLoggerMiddleware
9
- } from "./chunk-M5LIX3TD.js";
15
+ } from "./chunk-STNIT65W.js";
10
16
  import {
11
17
  securityMiddleware
12
- } from "./chunk-NJXCFTOE.js";
18
+ } from "./chunk-UD7YHLHI.js";
13
19
  import {
14
20
  adminMiddleware,
15
21
  authMiddleware,
16
22
  optionalAuthMiddleware
17
- } from "./chunk-74MSBKYW.js";
23
+ } from "./chunk-5P4E6SGV.js";
18
24
  import {
19
25
  corsMiddleware
20
- } from "./chunk-WDJLAZCW.js";
21
- import {
22
- errorHandlerMiddleware
23
- } from "./chunk-P6VSEFZE.js";
24
- import {
25
- initRequestMiddleware
26
- } from "./chunk-62Q7DN5G.js";
26
+ } from "./chunk-NE33JZW3.js";
27
27
 
28
28
  // src/middleware/wrappers.ts
29
29
  function withPublicApi(handler) {
@@ -1,13 +1,13 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-SNNXLA5F.js";
1
4
  import {
2
5
  getCacheFallbackConfig,
3
6
  getConfig,
4
7
  getEnv,
5
8
  isCacheEnabled,
6
9
  validateRedisEnvironment
7
- } from "./chunk-N4XYQB2G.js";
8
- import {
9
- logger
10
- } from "./chunk-5A2L6TXD.js";
10
+ } from "./chunk-X2QSMX3B.js";
11
11
 
12
12
  // src/cache/cache-redis.ts
13
13
  import { Redis } from "@upstash/redis";
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  BaseGeoIPProvider
3
3
  } from "./chunk-AHDPGRXS.js";
4
+ import {
5
+ getGeolocationConfig
6
+ } from "./chunk-V33BEN6H.js";
4
7
 
5
8
  // src/geolocation/providers/maxmind-provider.ts
6
9
  var MaxMindProvider = class extends BaseGeoIPProvider {
@@ -19,7 +22,11 @@ var MaxMindProvider = class extends BaseGeoIPProvider {
19
22
  return null;
20
23
  }
21
24
  isAvailable() {
22
- return !!process.env.MAXMIND_LICENSE_KEY;
25
+ try {
26
+ return !!getGeolocationConfig().maxmindLicenseKey;
27
+ } catch (e) {
28
+ return false;
29
+ }
23
30
  }
24
31
  };
25
32
 
@@ -0,0 +1,38 @@
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 _config = null;
10
+ function initializeLogger(config) {
11
+ var _a, _b, _c, _d, _e;
12
+ if (_config) return;
13
+ if (config.level === void 0) configWarn("Logger", "level not provided, using default: info");
14
+ if (config.dir === void 0) configWarn("Logger", "dir not provided, using default: ./logs");
15
+ if (config.file === void 0) configWarn("Logger", "file not provided, using default: app.log");
16
+ if (config.fileEnabled === void 0) configWarn("Logger", "fileEnabled not provided, using default: true");
17
+ if (config.consoleEnabled === void 0) configWarn("Logger", "consoleEnabled not provided, using default: true");
18
+ _config = {
19
+ level: (_a = config.level) != null ? _a : "info",
20
+ dir: (_b = config.dir) != null ? _b : "./logs",
21
+ file: (_c = config.file) != null ? _c : "app.log",
22
+ fileEnabled: (_d = config.fileEnabled) != null ? _d : true,
23
+ consoleEnabled: (_e = config.consoleEnabled) != null ? _e : true
24
+ };
25
+ }
26
+ function getLoggerConfig() {
27
+ if (!_config) throw new ConfigurationError("Logger", "Not initialized. Call initializeLogger() first.");
28
+ return _config;
29
+ }
30
+ function resetLogger() {
31
+ _config = null;
32
+ }
33
+
34
+ export {
35
+ initializeLogger,
36
+ getLoggerConfig,
37
+ resetLogger
38
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getErrorMessage
3
- } from "./chunk-ASXZ2NZJ.js";
3
+ } from "./chunk-Y2JYA2AR.js";
4
4
  import {
5
5
  getErrorCategory
6
6
  } from "./chunk-SNVGJPPX.js";
@@ -1,3 +1,9 @@
1
+ import {
2
+ getLoggerConfig
3
+ } from "./chunk-RLXRDUBX.js";
4
+ import {
5
+ getCommonConfig
6
+ } from "./chunk-5MBKG2ZD.js";
1
7
  import {
2
8
  __spreadProps,
3
9
  __spreadValues
@@ -14,14 +20,19 @@ if (typeof process !== "undefined" && process.setMaxListeners) {
14
20
  }
15
21
  }
16
22
  var { combine, timestamp, printf, colorize } = winston.format;
17
- var {
18
- LOG_DIR = "./logs",
19
- LOG_FILE = "app.log",
20
- LOG_PATH = "",
21
- LOG_FILE_ENABLED = "true",
22
- LOG_CONSOLE_ENABLED = "true",
23
- LOG_LEVEL = "info"
24
- } = process.env;
23
+ function getLogConfig() {
24
+ try {
25
+ return getLoggerConfig();
26
+ } catch (e) {
27
+ return {
28
+ level: "info",
29
+ dir: "./logs",
30
+ file: "app.log",
31
+ fileEnabled: true,
32
+ consoleEnabled: true
33
+ };
34
+ }
35
+ }
25
36
  var colors = {
26
37
  error: "red",
27
38
  warn: "yellow",
@@ -30,12 +41,19 @@ var colors = {
30
41
  debug: "blue"
31
42
  };
32
43
  winston.addColors(colors);
33
- var isTestEnv = process.env.NODE_ENV === "test" || process.env.VITEST !== void 0 || process.env.JEST_WORKER_ID !== void 0;
44
+ var isTestEnv = (() => {
45
+ try {
46
+ return getCommonConfig().nodeEnv === "test";
47
+ } catch (e) {
48
+ return false;
49
+ }
50
+ })() || process.env.VITEST !== void 0 || process.env.JEST_WORKER_ID !== void 0;
34
51
  var isBuildTime = process.env.NEXT_PHASE === "phase-production-build" || process.argv.some((arg) => arg.includes("build"));
35
52
  var canWriteToLogDir = (() => {
36
53
  if (isTestEnv || isBuildTime) return false;
37
54
  try {
38
- const logDir = LOG_PATH || LOG_DIR;
55
+ const cfg = getLogConfig();
56
+ const logDir = cfg.dir;
39
57
  if (fs.existsSync(logDir)) {
40
58
  fs.accessSync(logDir, fs.constants.W_OK);
41
59
  return true;
@@ -46,10 +64,10 @@ var canWriteToLogDir = (() => {
46
64
  return false;
47
65
  }
48
66
  })();
49
- var fileLoggingEnabled = !isTestEnv && !isBuildTime && canWriteToLogDir && LOG_FILE_ENABLED === "true";
50
- var consoleLoggingEnabled = LOG_CONSOLE_ENABLED === "true";
67
+ var fileLoggingEnabled = !isTestEnv && !isBuildTime && canWriteToLogDir && getLogConfig().fileEnabled;
68
+ var consoleLoggingEnabled = getLogConfig().consoleEnabled;
51
69
  var datePatternString = "YYYY-MM-DD";
52
- var logLevel = LOG_LEVEL;
70
+ var logLevel = getLogConfig().level;
53
71
  var transports = [];
54
72
  var logFormat = combine(
55
73
  timestamp({ format: "YYYY-MM-DD HH:mm:ss:ms" }),
@@ -121,9 +139,10 @@ if (consoleLoggingEnabled) {
121
139
  );
122
140
  }
123
141
  if (fileLoggingEnabled) {
142
+ const cfg = getLogConfig();
124
143
  transports.push(
125
144
  new DailyRotateFile({
126
- filename: LOG_PATH || `${LOG_DIR}/${LOG_FILE.replace(/\.log$/, "")}-%DATE%.log`,
145
+ filename: `${cfg.dir}/${cfg.file.replace(/\.log$/, "")}-%DATE%.log`,
127
146
  zippedArchive: true,
128
147
  maxFiles: "14d",
129
148
  // Keep for 14 days
@@ -131,7 +150,7 @@ if (fileLoggingEnabled) {
131
150
  level: logLevel,
132
151
  handleExceptions: true,
133
152
  json: false,
134
- dirname: LOG_PATH ? void 0 : LOG_DIR
153
+ dirname: cfg.dir
135
154
  })
136
155
  );
137
156
  }
@@ -2,7 +2,7 @@ import {
2
2
  logApiRequest,
3
3
  logApiResponse,
4
4
  logger
5
- } from "./chunk-5A2L6TXD.js";
5
+ } from "./chunk-SNNXLA5F.js";
6
6
 
7
7
  // src/middleware/response-logger.ts
8
8
  var responseLoggerMiddleware = async (context, next) => {
@@ -1,10 +1,10 @@
1
- import {
2
- getErrorDisplayInfo,
3
- getFriendlyMessage
4
- } from "./chunk-AZASEBSP.js";
5
1
  import {
6
2
  AppError
7
3
  } from "./chunk-KXXROUA5.js";
4
+ import {
5
+ getErrorDisplayInfo,
6
+ getFriendlyMessage
7
+ } from "./chunk-S54PFAEU.js";
8
8
  import {
9
9
  getErrorCategory
10
10
  } from "./chunk-SNVGJPPX.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-5A2L6TXD.js";
3
+ } from "./chunk-SNNXLA5F.js";
4
4
 
5
5
  // src/middleware/security.ts
6
6
  import { NextResponse } from "next/server";